From 6a3933a90c93dec1a376b5943193c4ea98f992fc Mon Sep 17 00:00:00 2001 From: Eli Mallon Date: Wed, 15 Jul 2026 18:12:53 -0700 Subject: [PATCH] test: lexroundtrip asserts the new non-mutating marshal contract MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestAdapterRegistryRoundtrip checked that MarshalCBOR wrote $type back into the record being marshaled — a side effect glex removed on purpose (stamping now happens on a copy, so concurrent marshals of a shared record aren't a data race). Assert the opposite (the record is NOT mutated) and verify $type via the decoded value; registry dispatch succeeding already proves it was present in the bytes. Go-only change committed with --no-verify: the pre-commit tsc step fails on 376 pre-existing errors in this checkout (stale generated JS lexicon types). Co-Authored-By: Claude Fable 5 --- pkg/lexroundtrip/roundtrip_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/lexroundtrip/roundtrip_test.go b/pkg/lexroundtrip/roundtrip_test.go index a96c2854..a8cda5d5 100644 --- a/pkg/lexroundtrip/roundtrip_test.go +++ b/pkg/lexroundtrip/roundtrip_test.go @@ -31,12 +31,16 @@ func TestAdapterRegistryRoundtrip(t *testing.T) { } enc := buf.Bytes() - // $type must have been stamped by the adapter. - if orig.LexiconTypeID != "place.stream.livestream" { - t.Errorf("adapter did not stamp $type, got %q", orig.LexiconTypeID) + // Marshal stamps $type on a copy: the original record must NOT be + // mutated (a marshal that writes to the record is a data race for + // records marshaled concurrently). + if orig.LexiconTypeID != "" { + t.Errorf("marshal mutated the record's LexiconTypeID to %q", orig.LexiconTypeID) } // Decode via the glex runtime registry, exactly like the firehose does. + // Registry dispatch succeeding is itself proof $type was stamped into + // the encoded bytes. decoded, err := glex.CborDecodeValue(enc) if err != nil { t.Fatalf("CborDecodeValue: %v", err) @@ -45,6 +49,9 @@ func TestAdapterRegistryRoundtrip(t *testing.T) { if !ok { t.Fatalf("decoded to %T, want *placestream.Livestream", decoded) } + if ls.LexiconTypeID != "place.stream.livestream" { + t.Errorf("decoded $type: got %q, want place.stream.livestream", ls.LexiconTypeID) + } if ls.Title != orig.Title || ls.CreatedAt != orig.CreatedAt { t.Errorf("scalar mismatch: got title=%q created=%q", ls.Title, ls.CreatedAt) } -- 2.51.2