fix(verifier): tolerate out-of-range override indices

A single stale index from V8 aborted the entire override map, so any
valid entries alongside it were dropped and verification ran on stale
extractor values. V8 and goja register from the same bundle so a
mismatch is unusual but recoverable.

Skip out-of-range entries instead of erroring, and return the skipped
count so the runner logs the mismatch without losing valid overrides.
This commit is contained in:
pj committed 2026-05-03 11:04:38 +07:00
1 parent 3b204b75dc
commit d77f89aeb1
3 files changed
+39 -17

No files matched your search

+18 -8
View File
@@ -540,7 +540,7 @@ func TestOverrideExtractorValues_PreservesPrevious(t *testing.T) {
if err := verifier.PushSnapshot(SnapshotInput{Snapshots: Snapshots{"ledger.balance": json.RawMessage(`100`)}}); err != nil {
t.Fatal(err)
}
if err := verifier.OverrideExtractorValues(map[int]json.RawMessage{1: json.RawMessage(`777`)}); err != nil {
if _, err := verifier.OverrideExtractorValues(map[int]json.RawMessage{1: json.RawMessage(`777`)}); err != nil {
t.Fatal(err)
}
balance := verifier.runtime.GlobalObject().Get("balance").ToObject(verifier.runtime)
@@ -564,10 +564,10 @@ func TestOverrideExtractorValues_NilIsNoop(t *testing.T) {
if err := verifier.PushSnapshot(SnapshotInput{Snapshots: Snapshots{"ledger.balance": json.RawMessage(`42`)}}); err != nil {
t.Fatal(err)
}
if err := verifier.OverrideExtractorValues(nil); err != nil {
if _, err := verifier.OverrideExtractorValues(nil); err != nil {
t.Fatal(err)
}
if err := verifier.OverrideExtractorValues(map[int]json.RawMessage{}); err != nil {
if _, err := verifier.OverrideExtractorValues(map[int]json.RawMessage{}); err != nil {
t.Fatal(err)
}
balance := verifier.runtime.GlobalObject().Get("balance").ToObject(verifier.runtime)
@@ -576,14 +576,24 @@ func TestOverrideExtractorValues_NilIsNoop(t *testing.T) {
}
}
func TestOverrideExtractorValues_UnknownIndexErrors(t *testing.T) {
func TestOverrideExtractorValues_UnknownIndexSkipped(t *testing.T) {
verifier := newVerifier(t)
mustLoad(t, verifier, helloSpec)
if err := verifier.PushSnapshot(SnapshotInput{}); err != nil {
if err := verifier.PushSnapshot(SnapshotInput{Snapshots: Snapshots{"ledger.balance": json.RawMessage(`42`)}}); err != nil {
t.Fatal(err)
}
err := verifier.OverrideExtractorValues(map[int]json.RawMessage{99: json.RawMessage(`1`)})
if err == nil || !strings.Contains(err.Error(), "out of range") {
t.Errorf("expected out-of-range error, got %v", err)
skipped, err := verifier.OverrideExtractorValues(map[int]json.RawMessage{
1: json.RawMessage(`777`),
99: json.RawMessage(`1`),
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if skipped != 1 {
t.Errorf("expected 1 skipped entry, got %d", skipped)
}
balance := verifier.runtime.GlobalObject().Get("balance").ToObject(verifier.runtime)
if balance.Get("current").ToInteger() != 777 {
t.Errorf("valid override should still apply alongside skipped one, got current=%v", balance.Get("current"))
}
}