Skip to content

Commit 7fd951d

Browse files
committed
chore: switch from gob to JSON encoding for digests
The gob encoder is dependent on the order in which it sees types. So, even encoding a completely new type could change the "digest" of a type with the same values. This is not in the flavor or producing a digest. This change switches to JSON, which will produce a consistent encoding. Signed-off-by: Donnie Adams <[email protected]>
1 parent b98000c commit 7fd951d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/hash/sha256.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package hash
22

33
import (
44
"crypto/sha256"
5-
"encoding/gob"
65
"encoding/hex"
6+
"encoding/json"
77
)
88

99
func ID(parts ...string) string {
@@ -26,7 +26,7 @@ func Digest(obj any) string {
2626
case string:
2727
hash.Write([]byte(v))
2828
default:
29-
if err := gob.NewEncoder(hash).Encode(obj); err != nil {
29+
if err := json.NewEncoder(hash).Encode(obj); err != nil {
3030
panic(err)
3131
}
3232
}

pkg/tests/runner2_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ name: mcp
313313
],
314314
"type": "object"
315315
},
316-
"instructions": "#!sys.mcp.invoke.append_insight c358c2eb93fa9a98631cd9e4f324d7b59f56aee11c7ae32a00984ad5844dc32c",
316+
"instructions": "#!sys.mcp.invoke.append_insight e592cc0c9483290685611ba70bd8595829cc794f7eae0419eabb3388bf0d3529",
317317
"id": "inline:append_insight",
318318
"localTools": {
319319
"append_insight": "inline:append_insight",
@@ -346,7 +346,7 @@ name: mcp
346346
],
347347
"type": "object"
348348
},
349-
"instructions": "#!sys.mcp.invoke.create_table c358c2eb93fa9a98631cd9e4f324d7b59f56aee11c7ae32a00984ad5844dc32c",
349+
"instructions": "#!sys.mcp.invoke.create_table e592cc0c9483290685611ba70bd8595829cc794f7eae0419eabb3388bf0d3529",
350350
"id": "inline:create_table",
351351
"localTools": {
352352
"append_insight": "inline:append_insight",
@@ -379,7 +379,7 @@ name: mcp
379379
],
380380
"type": "object"
381381
},
382-
"instructions": "#!sys.mcp.invoke.describe_table c358c2eb93fa9a98631cd9e4f324d7b59f56aee11c7ae32a00984ad5844dc32c",
382+
"instructions": "#!sys.mcp.invoke.describe_table e592cc0c9483290685611ba70bd8595829cc794f7eae0419eabb3388bf0d3529",
383383
"id": "inline:describe_table",
384384
"localTools": {
385385
"append_insight": "inline:append_insight",
@@ -403,7 +403,7 @@ name: mcp
403403
"arguments": {
404404
"type": "object"
405405
},
406-
"instructions": "#!sys.mcp.invoke.list_tables c358c2eb93fa9a98631cd9e4f324d7b59f56aee11c7ae32a00984ad5844dc32c",
406+
"instructions": "#!sys.mcp.invoke.list_tables e592cc0c9483290685611ba70bd8595829cc794f7eae0419eabb3388bf0d3529",
407407
"id": "inline:list_tables",
408408
"localTools": {
409409
"append_insight": "inline:append_insight",
@@ -505,7 +505,7 @@ name: mcp
505505
],
506506
"type": "object"
507507
},
508-
"instructions": "#!sys.mcp.invoke.read_query c358c2eb93fa9a98631cd9e4f324d7b59f56aee11c7ae32a00984ad5844dc32c",
508+
"instructions": "#!sys.mcp.invoke.read_query e592cc0c9483290685611ba70bd8595829cc794f7eae0419eabb3388bf0d3529",
509509
"id": "inline:read_query",
510510
"localTools": {
511511
"append_insight": "inline:append_insight",
@@ -538,7 +538,7 @@ name: mcp
538538
],
539539
"type": "object"
540540
},
541-
"instructions": "#!sys.mcp.invoke.write_query c358c2eb93fa9a98631cd9e4f324d7b59f56aee11c7ae32a00984ad5844dc32c",
541+
"instructions": "#!sys.mcp.invoke.write_query e592cc0c9483290685611ba70bd8595829cc794f7eae0419eabb3388bf0d3529",
542542
"id": "inline:write_query",
543543
"localTools": {
544544
"append_insight": "inline:append_insight",

0 commit comments

Comments
 (0)