From fe176dbfdd27da1150090893e5344558a7450073 Mon Sep 17 00:00:00 2001 From: Jeffrey Smith Date: Sat, 28 Mar 2026 13:23:57 +0000 Subject: [PATCH] Fix jsonEq to handle PG JSONB key reordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PG JSONB normalizes key order (alphabetical), so json.Compact alone wasn't sufficient — {"approved":true,"notes":"LGTM"} stored as {"notes":"LGTM","approved":true}. Unmarshal+remarshal normalizes both sides before comparison. Co-Authored-By: Claude Opus 4.6 (1M context) --- server/handlers/workflow_store_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/handlers/workflow_store_test.go b/server/handlers/workflow_store_test.go index adaaa89..84e2f6a 100644 --- a/server/handlers/workflow_store_test.go +++ b/server/handlers/workflow_store_test.go @@ -14,17 +14,19 @@ import ( "switchboard-core/store/sqlite" ) -// jsonEq compares two JSON byte slices ignoring whitespace differences -// (PG JSONB normalizes spacing, SQLite preserves it verbatim). +// jsonEq compares two JSON byte slices ignoring whitespace and key order +// (PG JSONB normalizes spacing and may reorder keys). func jsonEq(a, b json.RawMessage) bool { - var ca, cb bytes.Buffer - if err := json.Compact(&ca, a); err != nil { + var va, vb interface{} + if err := json.Unmarshal(a, &va); err != nil { return false } - if err := json.Compact(&cb, b); err != nil { + if err := json.Unmarshal(b, &vb); err != nil { return false } - return ca.String() == cb.String() + na, _ := json.Marshal(va) + nb, _ := json.Marshal(vb) + return bytes.Equal(na, nb) } // testStores returns an appropriate Stores for the current dialect.