Repository navigation
fix(baseline): build the canonical corrections form as JSON.stringify does - #108
Merged
Merged
Conversation
… does The B2 port made the canonical bytes with encoding/json, which always escapes U+2028 and U+2029 and decodes a lone surrogate escape to U+FFFD. Core check-corrections.mjs writes U+2028 and U+2029 as themselves and a lone surrogate as a lowercase \udxxx escape (core ADR-0081), so the port refused canonical records that core accepts and accepted escaped forms that core refuses. The port now decodes strings to UTF-16 code units and writes the JSON.stringify bytes itself, and decodes member names the same way for the duplicate check.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Core check-corrections.mjs fails a symbolic link at .memory before it reads either form (linkedMemory). The B2 port checked links only at .memory/corrections and its entries, so it followed a linked .memory. Also add the cases for an escaped U+007F, an escaped required name, a duplicate written as a required name and its escaped form, and a nested non-string value.
This was referenced Nov 14, 2026
Merged
bketelsen
approved these changes
Nov 14, 2026
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The B2 baseline check (
internal/baseline/repository_baseline_test.go) ports core'sscripts/check-corrections.mjs(core ADR-0081). It built the canonical bytes withencoding/json, which breaks the ADR-0081 byte rules:encoding/jsonalways escapes U+2028 and U+2029;JSON.stringifywrites them as themselves. A canonical record with a raw U+2028 failed here, and an escaped\u2028passed.json.Unmarshaldecodes a lone surrogate escape (\ud800) to U+FFFD; core keeps the code unit and writes it as\udxxxin lowercase. A canonical record with\ud800failed here.The check now walks the top-level members itself (after
json.Valid), decodes each string to UTF-16 code units asJSON.parsedoes, and writes theJSON.stringifybytes by the ADR-0081 rules (only",\and characters below U+0020 escaped, a lone surrogate as\udxxx, everything else as UTF-8).encoding/jsonno longer makes the canonical form. Standard library only.Risk tier
Risk tier: 1 — test-only package (the baseline contract test) and its cases. No risk path is touched.
Verification
make checkgreen (fmt, vet, lint, docs, unit tests), andmake build.\ud800passes,\uD800fails), emoji raw and as an escaped pair,<>&/and\u003c,\/, U+007F,\^_and\^_,\nand\u000a,éand\u00e9; and 2 lone-surrogate names that give "unknown key(s)" and no "duplicate key".check-corrections.mjsat3d3d5c703fc24db3734408765171938a97840f4c(the same tree,node check-corrections.mjs --root <tree>). The 1 known difference is on purpose: B2 requires the folder; core passes a tree with no records.encoding/jsoncode, 7 new cases fail (raw and escaped U+2028 and U+2029,\ud800,\udc00, the 2 names)..memory/corrections/passes in Go and in core..memory/corrections/.make ci: CI runs it.Cross-review
openai/gpt-6.1-sol; coderanthropic/claude-opus-5-5. 1 batch review of the 5 ports of this fix (fix(baseline): build the canonical corrections form as JSON.stringify does #108, fix(baseline): build the canonical corrections form as JSON.stringify does clix#122, fix(baseline): build the canonical corrections form as JSON.stringify does std#109, fix(baseline): match the empty check of core check-corrections.mjs homebrew-tap#47, fix(baseline): match the empty check of core check-corrections.mjs flatpak-index#19), plus re-review 1 of the fixes.Blocking: none, at head4a64d5d8dc331f8121defc991d05e43e4dfdb959(first review ata5866961118c0b41512543a1a8f9ad9b84ffacca)..memory; core'scheck-corrections.mjsfails it before it reads either form (linkedMemory). This was there before this PR. Guard: the case ".memorylinks toinbox, which holds a good record" expects.memory: symbolic link, not followed(core gives exit 1 and the same message); it fails without the fix. Record:.memory/corrections/2026-11-14-pr-108-memory-link.json."d\u0061te"in place of"date",dateandd\u0061tetogether (duplicate), and a nested non-string value; each agrees with core.