62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestUnknownAndRefusedAreNotConfirmed(t *testing.T) {
|
|
cases := []struct{ effect, execution, side string }{{"confirmed", "completed", "confirmed"}, {"partial", "partial", "confirmed"}, {"unverifiable", "completed", "possible"}, {"suspected_noop", "completed", "possible"}, {"refused", "not_started", "none"}, {"", "unknown", "possible"}}
|
|
for _, c := range cases {
|
|
r := actionReceipt(obj{"structuredContent": obj{"effect": c.effect}}, true)
|
|
if r["execution"] != c.execution || r["side_effect"] != c.side || r["retryable"] != false {
|
|
t.Fatalf("%s: %v", c.effect, r)
|
|
}
|
|
}
|
|
}
|
|
func TestAttachmentCannotEscape(t *testing.T) {
|
|
for _, s := range []string{"../out.png", "..\\out.png", "C:out.png", "a.png:stream", "", "a.png ", "a.jpg"} {
|
|
if validFilename(s) {
|
|
t.Fatal(s)
|
|
}
|
|
}
|
|
if !validFilename("留档.png") {
|
|
t.Fatal("plain Unicode PNG rejected")
|
|
}
|
|
}
|
|
func TestUnexposedAndMissingTargetRejected(t *testing.T) {
|
|
a := newAdapter(nil)
|
|
for _, c := range []struct {
|
|
name string
|
|
args obj
|
|
}{{"run_script", obj{}}, {"click", obj{"pid": 1, "window_id": 2, "scope": "desktop"}}, {"get_window_state", obj{"pid": 1}}, {"click", obj{"pid": 0, "window_id": 2}}} {
|
|
if a.validate(c.name, c.args) == nil {
|
|
t.Fatal(c)
|
|
}
|
|
}
|
|
}
|
|
func TestSupportedArguments(t *testing.T) {
|
|
a := newAdapter(nil)
|
|
if err := a.validate("click", obj{"pid": 1, "window_id": 2, "element_token": "s00000001:0"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestBackgroundPreflightVsActuatorUncertainty(t *testing.T) {
|
|
r := obj{"isError": true, "structuredContent": obj{"code": "background_unavailable", "event_kind": "mouse_scroll"}}
|
|
if actionReceipt(r, true)["execution"] != "not_started" {
|
|
t.Fatal("preflight refusal must be explicit")
|
|
}
|
|
object(r["structuredContent"])["cause"] = "unknown actuator failure"
|
|
if actionReceipt(r, true)["execution"] != "unknown" {
|
|
t.Fatal("actuator uncertainty must not be hidden")
|
|
}
|
|
}
|
|
|
|
func TestClickModesAreDisjoint(t *testing.T) {
|
|
a := newAdapter(nil)
|
|
if a.validate("click", obj{"pid": 1, "window_id": 2, "element_token": "s1:0", "capture_id": "capture"}) == nil {
|
|
t.Fatal("mixed click modes")
|
|
}
|
|
if a.validate("click_at", obj{"pid": 1, "window_id": 2, "x": 5, "y": 5}) == nil {
|
|
t.Fatal("pixel action lacks capture")
|
|
}
|
|
}
|