From db331ca280c17f5685e620a2e6ab3317ffe211be Mon Sep 17 00:00:00 2001 From: Lev Neiman Date: Fri, 13 Nov 2026 07:24:55 +0000 Subject: [PATCH 1/2] test(rust): cover canonical bigint argument keys --- formal/catalogs/protocol-vectors.json | 72 +++++++++++++++++++++++++++ rust/tests/protocol_keys.rs | 46 +++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/formal/catalogs/protocol-vectors.json b/formal/catalogs/protocol-vectors.json index 290ff53b..a0d0b0ee 100644 --- a/formal/catalogs/protocol-vectors.json +++ b/formal/catalogs/protocol-vectors.json @@ -303,6 +303,78 @@ ] ] }, + { + "name": "bigint decimal text uses canonical numeric identity", + "input": { + "literalNegative": "-0001", + "literalPositive": "0001", + "literalZero": "-0" + }, + "bigintArgs": { + "negative": "-0001", + "negativeZero": "-0", + "paddedZero": "000", + "positive": "0001", + "signedPaddedZero": "-000", + "zero": "0" + }, + "expected": [ + [ + "literalNegative", + "-0001" + ], + [ + "literalPositive", + "0001" + ], + [ + "literalZero", + "-0" + ], + [ + "negative", + "-1" + ], + [ + "negativeZero", + "0" + ], + [ + "paddedZero", + "0" + ], + [ + "positive", + "1" + ], + [ + "signedPaddedZero", + "0" + ], + [ + "zero", + "0" + ] + ] + }, + { + "name": "bigint decimal text retains magnitudes beyond fixed-width integers", + "input": {}, + "bigintArgs": { + "negative": "-0001234567890123456789012345678901234567890123456789012345678901234567890", + "positive": "0001234567890123456789012345678901234567890123456789012345678901234567890" + }, + "expected": [ + [ + "negative", + "-1234567890123456789012345678901234567890123456789012345678901234567890" + ], + [ + "positive", + "1234567890123456789012345678901234567890123456789012345678901234567890" + ] + ] + }, { "name": "empty arguments", "input": {}, diff --git a/rust/tests/protocol_keys.rs b/rust/tests/protocol_keys.rs index 5afd540e..8b78c8e6 100644 --- a/rust/tests/protocol_keys.rs +++ b/rust/tests/protocol_keys.rs @@ -12,10 +12,56 @@ mod fixtures; #[path = "formal/key_vectors.rs"] mod key_vectors; +use dialcache::identity::{normalize_args, ArgValue, Identity}; use serde_json::{json, Value}; type Check = fn(&Value) -> Result<(), String>; +#[test] +fn bigint_text_uses_canonical_keys_but_strings_remain_literal() { + for (text, expected) in [ + ("1", "1"), + ("0001", "1"), + ("-1", "-1"), + ("-0001", "-1"), + ("0", "0"), + ("-0", "0"), + ("000", "0"), + ("-000", "0"), + ("0010200", "10200"), + ("-0010200", "-10200"), + ] { + let args = normalize_args([("n", ArgValue::BigInt(text.into()))]).unwrap(); + assert_eq!(args, vec![("n".into(), expected.into())], "{text}"); + for tracked in [false, true] { + let identity = Identity::new("id", text, "Get") + .namespace("urn") + .tracked(tracked); + let canonical = normalize_args([("n", ArgValue::Str(expected.into()))]).unwrap(); + assert_eq!( + identity.clone().args(args.clone()).keys().unwrap(), + identity.clone().args(canonical).keys().unwrap(), + "{text}, tracked={tracked}" + ); + assert_eq!(identity.id, text); + } + let literal = normalize_args([("n", ArgValue::Str(text.into()))]).unwrap(); + assert_eq!(literal, vec![("n".into(), text.into())]); + } +} + +#[test] +fn bigint_text_preserves_arbitrary_width_magnitudes() { + let magnitude = "12345678901234567890".repeat(100); + for sign in ["", "-"] { + let expected = format!("{sign}{magnitude}"); + for text in [expected.clone(), format!("{sign}000{magnitude}")] { + let actual = normalize_args([("n", ArgValue::BigInt(text))]).unwrap(); + assert_eq!(actual, vec![("n".into(), expected.clone())]); + } + } +} + #[test] fn key_assertions_distinguish_library_rejections_from_bad_fixtures() { let valid_shape = json!({ From dd2ff4f5c25583fe6237ecf5f6ed2c6af6499cf0 Mon Sep 17 00:00:00 2001 From: Lev Neiman Date: Fri, 13 Nov 2026 07:24:55 +0000 Subject: [PATCH 2/2] fix(rust): canonicalize bigint argument text Remove decimal padding and normalize signed zero before key construction. Keep validation and literal string handling unchanged. --- go/protocol_test.go | 2 +- python/tests/test_protocol_vectors.py | 2 +- rust/src/identity.rs | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/go/protocol_test.go b/go/protocol_test.go index 4ed40500..26e71b57 100644 --- a/go/protocol_test.go +++ b/go/protocol_test.go @@ -502,7 +502,7 @@ func TestProtocolRemainingVectors(t *testing.T) { selection := os.Getenv("DIALCACHE_PROTOCOL_CORPUS") expected := 0 if selection != "generated" { - expected = 191 + expected = 193 } if selection != "fixed" { for _, rows := range generatedProtocolGroups(t) { diff --git a/python/tests/test_protocol_vectors.py b/python/tests/test_protocol_vectors.py index 2778fcfb..08bbb568 100644 --- a/python/tests/test_protocol_vectors.py +++ b/python/tests/test_protocol_vectors.py @@ -61,7 +61,7 @@ def key_from(vector): def test_schemas_provenance_and_inventory(): assert all(corpus["schemaVersion"] == 3 for corpus in CORPORA) - expected_counts = [191, 457, 589, 297] + expected_counts = [193, 457, 589, 297] for corpus, expected in zip(CORPORA, expected_counts, strict=True): rows = [row for value in corpus.values() if isinstance(value, list) for row in value] assert len(rows) == expected diff --git a/rust/src/identity.rs b/rust/src/identity.rs index 1a1c88ce..c8ce61c0 100644 --- a/rust/src/identity.rs +++ b/rust/src/identity.rs @@ -201,7 +201,17 @@ impl ArgValue { "bigint text {text:?} is not a decimal integer" ))); } - text + let digits = text + .strip_prefix('-') + .unwrap_or(&text) + .trim_start_matches('0'); + if digits.is_empty() { + "0".to_owned() + } else if text.starts_with('-') { + format!("-{digits}") + } else { + digits.to_owned() + } } ArgValue::Str(text) => text, }))