From 6f9a83646ab7083e88d3ed68371aea9f750be5b9 Mon Sep 17 00:00:00 2001 From: mesh-tools Date: Tue, 20 Oct 2026 18:22:58 +0000 Subject: [PATCH] Pin the json names of manifests, locks and inputs2 by the encoded bytes (issue 1442, review round 1) Go decodes keys case-insensitively, so a round trip could not see a dropped tag; the encoded bytes now name each field and an older message re-encodes to its own bytes. --- go/delivery/forge_inputs_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/go/delivery/forge_inputs_test.go b/go/delivery/forge_inputs_test.go index edc1bf2..e027ff7 100644 --- a/go/delivery/forge_inputs_test.go +++ b/go/delivery/forge_inputs_test.go @@ -21,6 +21,11 @@ func TestForgeMergedCarriesManifestsAndLocks(t *testing.T) { if err != nil { t.Fatal(err) } + for _, frag := range []string{`"manifests":{"a":`, `"locks":{"a":{"go.sum":`} { + if !strings.Contains(string(data), frag) { + t.Errorf("the encoding lacks %s: %s", frag, data) + } + } got, err := DecodeForge(data) if err != nil { t.Fatal(err) @@ -97,8 +102,9 @@ func TestForgeFromAnOlderBridge(t *testing.T) { t.Fatalf("%+v, %v", f, err) } data, err := EncodeForge(f) - if err != nil || strings.Contains(string(data), "manifests") || strings.Contains(string(data), "locks") { - t.Errorf("%s, %v", data, err) + // the older message is written with the struct's key order, so the bytes compare as they are + if err != nil || string(data) != old { + t.Errorf("%s, %v, want exactly %s", data, err, old) } } @@ -113,6 +119,9 @@ func TestModuleKeepsInputs2(t *testing.T) { if err != nil { t.Fatal(err) } + if !strings.Contains(string(data), `"inputs2":{"tree":"t1"`) { + t.Errorf("the encoding lacks inputs2: %s", data) + } got, err := DecodeModule(data) if err != nil { t.Fatal(err)