From 31e7ed1bd7e98c045c972e393465281156d34cde Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 3 May 2026 11:05:10 +0700 Subject: [PATCH] test(verifier): cover object-shaped extractor overrides Existing tests only override scalars (777, 200), so a future jsonToJSValue regression around nested object propagation would slip through. Lock down the contract: a JSON object override should make {attrs.testTag, balance} readable from goja predicates. --- internal/verifier/verifier_test.go | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/verifier/verifier_test.go b/internal/verifier/verifier_test.go index ab5272a..449d59a 100644 --- a/internal/verifier/verifier_test.go +++ b/internal/verifier/verifier_test.go @@ -597,3 +597,41 @@ func TestOverrideExtractorValues_UnknownIndexSkipped(t *testing.T) { t.Errorf("valid override should still apply alongside skipped one, got current=%v", balance.Get("current")) } } + +const objectExtractorSpec = ` +const card = __sanderling__.extract(state => ({attrs: {testTag: "default"}, balance: 0})); +globalThis.card = card; + +globalThis.properties = { + hasTestTag: __sanderling__.always(() => typeof card.current.attrs.testTag === "string"), +}; + +globalThis.actions = __sanderling__.actions(() => []); +` + +func TestOverrideExtractorValues_PropagatesNestedObjectFields(t *testing.T) { + verifier := newVerifier(t) + mustLoad(t, verifier, objectExtractorSpec) + + if err := verifier.PushSnapshot(SnapshotInput{}); err != nil { + t.Fatal(err) + } + override := json.RawMessage(`{"attrs": {"testTag": "account-card"}, "balance": 12345}`) + skipped, err := verifier.OverrideExtractorValues(map[int]json.RawMessage{0: override}) + if err != nil { + t.Fatal(err) + } + if skipped != 0 { + t.Errorf("unexpected skipped count: %d", skipped) + } + + card := verifier.runtime.GlobalObject().Get("card").ToObject(verifier.runtime) + current := card.Get("current").ToObject(verifier.runtime) + attrs := current.Get("attrs").ToObject(verifier.runtime) + if got := attrs.Get("testTag").String(); got != "account-card" { + t.Errorf("nested override missing: card.current.attrs.testTag = %q, want %q", got, "account-card") + } + if got := current.Get("balance").ToInteger(); got != 12345 { + t.Errorf("scalar field missing: card.current.balance = %d, want 12345", got) + } +}