| index 54a58ce..c8cd2be 100644 |
| --- a/internal/core/core_test.go |
| +++ b/internal/core/core_test.go |
| @@ -221,11 +221,16 @@ func TestSnapshotRoundTripsThroughAFreshHandle(t *testing.T) { |
| } |
| } |
| |
| -// TestVerifySnapshotAcceptsItsOwnAndRejectsGarbage exercises the two |
| +// TestVerifySnapshotAcceptsItsOwnAndRejectsGarbage exercises all three |
| // outcomes VerifySnapshot returns without an error: a document's own |
| -// snapshot verifies true, and bytes that are not a decodable update at |
| -// all (ERR_DECODE) come back false with no error — a "no" answer, not a |
| -// failure of the call. |
| +// snapshot verifies true; a validly-decodable snapshot of a genuinely |
| +// different document verifies false (return code 1 — the verifier's |
| +// primary purpose, distinct from "not even a decodable update"); and |
| +// bytes that are not a decodable update at all (ERR_DECODE) also come |
| +// back false with no error — a "no" answer, not a failure of the call. |
| +// The middle case and the garbage case are different failures of the |
| +// candidate and must not be conflated: only the garbage case may ever |
| +// legitimately share its outcome with a rejected-but-valid document. |
| func TestVerifySnapshotAcceptsItsOwnAndRejectsGarbage(t *testing.T) { |
| ctx := context.Background() |
| rt, err := core.New(ctx) |
| @@ -258,6 +263,34 @@ func TestVerifySnapshotAcceptsItsOwnAndRejectsGarbage(t *testing.T) { |
| t.Error("a document refused its own snapshot") |
| } |
| |
| + // A genuinely different document's snapshot: a real, validly-decodable |
| + // update, but not a snapshot of h. This is not "simple" (also a |
| + // fixtures/vectors/fragment .bin, used elsewhere in this file via |
| + // os.ReadFile) reused as a second, unrelated document's content — the |
| + // point is that decode succeeds and the structural comparison still |
| + // says no. |
| + other, err := rt.NewDoc(ctx, "verify-test-other", 2) |
| + if err != nil { |
| + t.Fatalf("NewDoc other: %v", err) |
| + } |
| + defer other.Close(ctx) |
| + |
| + otherUpdate, err := os.ReadFile("../../fixtures/vectors/fragment/simple.bin") |
| + if err != nil { |
| + t.Fatalf("read fixture: %v", err) |
| + } |
| + if err := other.Apply(ctx, otherUpdate); err != nil { |
| + t.Fatalf("Apply other: %v", err) |
| + } |
| + otherSnap, err := other.Snapshot(ctx) |
| + if err != nil { |
| + t.Fatalf("Snapshot other: %v", err) |
| + } |
| + |
| + if ok, err := h.VerifySnapshot(ctx, otherSnap); err != nil || ok { |
| + t.Errorf("a different document's snapshot verified against h: ok=%v err=%v", ok, err) |
| + } |
| + |
| if ok, err := h.VerifySnapshot(ctx, []byte{0xff, 0x00}); err != nil || ok { |
| t.Errorf("garbage verified: ok=%v err=%v", ok, err) |
| } |