mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix ltl semantics and unify action enumeration (#71)
* fix(ltl): give every thunk a construction identity Two distinct unnamed predicates both described as "Thunk(...)", so obligation collapse merged their residuals and could drop a live violation. Identity is assigned at construction and the fields are unexported, so a thunk cannot be built without one. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): reduce a thrown-predicate residual instead of panicking The verifier substitutes an ErrorFormula for the residual of a property whose predicate threw, and that residual is fed back in on the next step. reduce had no case for it, so the run crashed. It re-reports the same failure now. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): make a bounded always the dual of a bounded eventually G<=n(f) and not F<=n(not f) disagreed on traces where the inner was still pending when the window closed, so nnf's negation normal form was not semantics preserving. Both sides now range over the observations at which their inner can definitely resolve: the eventually keeps a pending inner as a disjunct, and the always discharges vacuously at window close. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): arm a one-shot root once per run A root that carries its own horizon is one obligation for the whole run, not one per observation. Re-instantiating a top-level eventually monitored G F<=n(p) instead of F<=n(p) and left one live obligation per step behind; a bounded always restarted its window every step and never closed. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): stop wrapping a top-level eventually in always `eventually(p).within(300, "seconds")` as a property meant "within 300 seconds of every step", which spawned an obligation per step with its own resolved deadline. A 553-step run carried 553 of them and serialized a 75 KB residual. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): serialize the resolved deadline of a bounded window Two obligations spawned at different steps from one duration-bounded formula differ only in the deadline the evaluator resolved for them, so they serialized identically and the trace erased a distinction the evaluator makes. The authored window stays in amount/unit; the resolved deadline rides alongside. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): split a witness's origin step from its detection step A deferred obligation spans two steps: the one that armed it and the one whose reduction failed. They were conflated under one index, so the extractor snapshot (which is the detecting step's state) was reported against the origin step. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(runner): record a witness's detection step in the trace Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * feat(replay-ui): show the step a violation was detected at The witness evidence is the detecting step's state, so say which step that is and let a reader jump to it. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): record the extractor state the predicates actually read On the web path extractor bodies are evaluated in V8 and injected here, but only the goja value was replaced. The trace diff and the violation witness therefore described a state no property ever saw. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * refactor(spec): one candidate producer over one target-eligibility rule Both hosts routed verbs themselves and both policies enumerated their own actions, and all four drifted. Web sent `swipes` to scrollable containers only, so swipe-to-dismiss on a list row was reachable on native and unreachable on web; the model policy folded gestures its own way and could not reach what the seeded picker drew. A host now reports facts about every element and never decides which verb may act on it: targets.ts acceptsTarget owns that for both. pick.ts builtinCandidates is the single enumeration, and the model policy reads it through __sanderlingEnumerateBuiltin__ instead of reimplementing it in Go. Gesture verbs change with it: scrolls stay vertical over scrollable containers, swipes go free-form in all four directions from any element with real bounds. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(runner): name a builtin scroll by its drag origin A builtin gesture carries endpoints and no selector, so every scroll rendered as "Scroll down " in the prompt's recent-action memory and two scrollable regions were indistinguishable. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(chrome): clear storage over cdp instead of scripting an opaque origin Launch runs while the tab is still on about:blank, whose opaque origin denies storage access, so localStorage.clear() threw SecurityError and every web run died at launch. Storage.clearDataForOrigin needs no navigation. The exception helper lands here because "Uncaught" is what hid this for so long. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(chrome): enable the swiftshader webgl fallback Headless Chrome runs with --disable-gpu, and without this flag it refuses the software WebGL backend: getContext returns null, so a canvas-rendered app paints nothing and every screenshot is identical black. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(web): resolve testTag through data-testid or id Compose Multiplatform emits its testTag into the element id, which the native table already accepts via the resource-id alias. The two web selector tables were the only place that rejected it. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * test(spec): type-check the spec api as part of make test The fake runtime in api.test.ts did not return a chainable handle from extract, so the file had not type-checked since named() was added. Wiring the check into make test stops it drifting again. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * docs(manual): one-shot eventually and the gesture verbs Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J
This commit is contained in:
48 files changed
+2604
-712
No files matched your search
+101
-23
@@ -105,30 +105,108 @@ func TestTyping_ExcludeOffAppPackage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSwipes_ExcludeOffAppPackage proves swipes anchor on app nodes only, so
|
||||
// exploration never scrolls the keyboard's emoji list instead of the app.
|
||||
func TestSwipes_ExcludeOffAppPackage(t *testing.T) {
|
||||
verifier := newVerifier(t, WithAppPackage("com.folio"))
|
||||
loadActionSpec(t, verifier, `
|
||||
import { swipes } from "@sanderling/spec";
|
||||
globalThis.actions = swipes;
|
||||
`)
|
||||
pushTree(t, verifier, scopedTreeJSON)
|
||||
// gestureTreeJSON gives each gesture verb a legal and an illegal anchor: an app
|
||||
// list holding a plain row, against the soft keyboard's own scrollable strip
|
||||
// holding one of its keys.
|
||||
const gestureTreeJSON = `{
|
||||
"attributes": {"resource-id": "root", "bounds": "[0,0,100,500]", "package": "com.folio"},
|
||||
"children": [
|
||||
{"attributes": {"testTag": "AppList", "scrollable": "true", "bounds": "[0,0,100,300]", "package": "com.folio"}, "children": [
|
||||
{"attributes": {"testTag": "Row", "bounds": "[0,0,100,60]", "package": "com.folio"}, "children": []}
|
||||
]},
|
||||
{"attributes": {"testTag": "EmojiStrip", "scrollable": "true", "bounds": "[0,400,100,440]", "package": "com.google.android.inputmethod.latin"}, "children": [
|
||||
{"attributes": {"testTag": "EmojiKey", "bounds": "[0,400,100,420]", "package": "com.google.android.inputmethod.latin"}, "children": []}
|
||||
]}
|
||||
]
|
||||
}`
|
||||
|
||||
// Both the root and SubmitButton (com.folio) are valid anchors; only the
|
||||
// keyboard key at center (50,420) must be excluded. Draw many times so the
|
||||
// invariant is not satisfied by a lucky seed.
|
||||
for i := range 200 {
|
||||
action, err := verifier.NextAction()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if action.Kind != ActionKindSwipe {
|
||||
t.Fatalf("kind = %v, want Swipe", action.Kind)
|
||||
}
|
||||
if action.FromX == 50 && action.FromY == 420 {
|
||||
t.Fatalf("draw %d anchored on the keyboard key (50,420); off-app node leaked into swipe targets", i)
|
||||
}
|
||||
// TestGestures_ExcludeOffAppPackage proves both gesture verbs anchor on app
|
||||
// nodes only, so exploration never drags the keyboard instead of the app, and
|
||||
// pins what each verb accepts within the app and which way it drags. Scrolls
|
||||
// anchor on the scrollable list alone and stay vertical, because every
|
||||
// scrollable container earns a candidate and scrolling a list means up and down.
|
||||
// Swipes anchor on any app element, the row and the root included, and drag in
|
||||
// all four directions, which is what puts swipe-to-dismiss on a list row inside
|
||||
// the action space.
|
||||
func TestGestures_ExcludeOffAppPackage(t *testing.T) {
|
||||
tests := []struct {
|
||||
verb string
|
||||
kind ActionKind
|
||||
anchors map[[2]int]bool
|
||||
directions map[string]bool
|
||||
}{
|
||||
{
|
||||
"scrolls",
|
||||
ActionKindScroll,
|
||||
map[[2]int]bool{{50, 150}: true},
|
||||
map[string]bool{"down": true, "up": true},
|
||||
},
|
||||
{
|
||||
"swipes",
|
||||
ActionKindSwipe,
|
||||
map[[2]int]bool{{50, 250}: true, {50, 150}: true, {50, 30}: true},
|
||||
map[string]bool{"down": true, "up": true, "left": true, "right": true},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.verb, func(t *testing.T) {
|
||||
verifier := newVerifier(t, WithAppPackage("com.folio"))
|
||||
loadActionSpec(t, verifier, `
|
||||
import { `+test.verb+` } from "@sanderling/spec";
|
||||
globalThis.actions = `+test.verb+`;
|
||||
`)
|
||||
pushTree(t, verifier, gestureTreeJSON)
|
||||
|
||||
// Draw many times so neither the exclusion nor the coverage below is
|
||||
// satisfied by a lucky seed. The keyboard strip (50,420) and its key
|
||||
// (50,410) are the anchors that must never appear.
|
||||
seen := map[[2]int]bool{}
|
||||
seenDirections := map[string]bool{}
|
||||
for i := range 400 {
|
||||
action, err := verifier.NextAction()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if action.Kind != test.kind {
|
||||
t.Fatalf("kind = %v, want %v", action.Kind, test.kind)
|
||||
}
|
||||
anchor := [2]int{action.FromX, action.FromY}
|
||||
if !test.anchors[anchor] {
|
||||
t.Fatalf("draw %d anchored at %v, outside %v", i, anchor, test.anchors)
|
||||
}
|
||||
direction := gestureDirection(action)
|
||||
if !test.directions[direction] {
|
||||
t.Fatalf("draw %d dragged %s, outside %v", i, direction, test.directions)
|
||||
}
|
||||
seen[anchor] = true
|
||||
seenDirections[direction] = true
|
||||
}
|
||||
if len(seen) != len(test.anchors) {
|
||||
t.Errorf("reached anchors %v, want all of %v", seen, test.anchors)
|
||||
}
|
||||
if len(seenDirections) != len(test.directions) {
|
||||
t.Errorf("reached directions %v, want all of %v", seenDirections, test.directions)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// gestureDirection names which way a drawn gesture drags. A scroll carries the
|
||||
// name it was enumerated under; a swipe carries only its endpoints, so the sign
|
||||
// of the drag is what says where the finger went.
|
||||
func gestureDirection(action Action) string {
|
||||
if action.Kind == ActionKindScroll {
|
||||
return action.Direction
|
||||
}
|
||||
switch {
|
||||
case action.ToX > action.FromX:
|
||||
return "right"
|
||||
case action.ToX < action.FromX:
|
||||
return "left"
|
||||
case action.ToY > action.FromY:
|
||||
return "down"
|
||||
default:
|
||||
return "up"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user