test(anatomy): R5.1 freeze of the TypeScript pipeline (oracles r5: intermediates, ids, fingerprint matrix) and the D-R5 study scripts; RUST.md §11
This commit is contained in:
1 parent
9c0117a692
commit
60cc0f5fa8
8 files changed
+33630
-1
No files matched your search
@@ -6,6 +6,10 @@ Versions follow [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed (2026-10-22, Rust R5.1: the TypeScript pipeline frozen, not yet ported)
|
||||
|
||||
- `packages/anatomy` and `packages/domain` are unchanged; their outputs are recorded as oracles under `crates/core/tests/oracles/r5/` (intermediate values, ids and slugs, the fingerprint of every generated JSON file under today's rule and the candidate rules of D-R5), generated by `packages/anatomy/tests/r5.pipeline-oracles.test.ts` with `MAKE_R5_ORACLES=1`. Study scripts `scripts/r5-fingerprints.mjs` and `packages/supabase/scripts/r5-jsonb-fingerprint.mjs` (read-only). `documentSha256` and the generated seed are untouched; the D-R5 decision is the owner's (`docs/development/RUST.md` §11). Known defect recorded, not fixed: the core's JavaScript number printing rounds an exact decimal tie upward where JavaScript rounds to even (no value of the curated draft is affected).
|
||||
|
||||
### Fixed (2026-10-21, R4 close)
|
||||
|
||||
- Sign-in redirects: a `next` value whose dot segments normalise into `//host` (`/..//host`, `/%2e%2e//host`) now falls back to the dashboard instead of being returned as a protocol-relative path. The worker image runs on `distroless/static-debian13:nonroot` (the Debian 12 tags are no longer updated). DEPLOY.md shows `http2 on;` for nginx 1.25.1 and later and keeps the `listen ... http2` form for nginx 1.24 (`docs/development/RUST.md` §10.14).
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
{
|
||||
"rules": {
|
||||
"today_file_bytes": "sha256 of the Prettier-formatted JSON text the pipeline writes (pipeline.ts sheetRef)",
|
||||
"a_js_pretty_newline": "sha256 of JSON.stringify(v, null, 2) + \"\\n\"",
|
||||
"a_js_pretty": "sha256 of JSON.stringify(v, null, 2)",
|
||||
"a_js_compact": "sha256 of JSON.stringify(v)",
|
||||
"b_rfc8785": "sha256 of the RFC 8785 canonical text",
|
||||
"a_js_pretty_validated": "document.json only: JSON.stringify(schema.parse(v), null, 2), the validated form (defaults filled)",
|
||||
"b_rfc8785_validated": "document.json only: RFC 8785 of the validated form"
|
||||
},
|
||||
"artifacts": [
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/legacy-import/document.json",
|
||||
"bytes": 224109,
|
||||
"today_file_bytes": "91e459f4c0ac8043831242c9fccde01f75f1023464db909f1c29571aa8a414c2",
|
||||
"a_js_pretty_newline": "8c94a464ae618ec98af165284db2b352b27850fac329aee0ae4224465fb0adc2",
|
||||
"a_js_pretty": "6fb3137199563dc99aaf08537613b08d1d5ae392147a83ed70bb91c070d27f66",
|
||||
"a_js_compact": "bf8d3a22a3b131f7cc3d05aea8afb82d684bd31b41ca94d8c7adb199cb28c522",
|
||||
"b_rfc8785": "d8b5f2cf0c8ebf68870296134eb2606a092726414d9175fbb983fb434b3881eb",
|
||||
"prettier_equals_js_pretty": false,
|
||||
"a_js_pretty_validated": "bd09fc71c4019e708e7bd1b8f402a7ed9406e0d23b7463889fbe4b0d7a72798a",
|
||||
"b_rfc8785_validated": "1217637ed9a6ce1e05cdf274a7edb110d00cac6d76bea311a7c66ea841c4c024",
|
||||
"validated_equals_input": false
|
||||
},
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/legacy-import/legacy-id-map.json",
|
||||
"bytes": 1323,
|
||||
"today_file_bytes": "4ec2b4e3a0ee7d901145ce45f9cc240d28e30997155a51c6d53ea1c1a36667b7",
|
||||
"a_js_pretty_newline": "4ec2b4e3a0ee7d901145ce45f9cc240d28e30997155a51c6d53ea1c1a36667b7",
|
||||
"a_js_pretty": "490508e704bc3852e9494b034d630327bb2f550f5b9a1e0ef8024014654f0691",
|
||||
"a_js_compact": "e028a65768f419d373869cc2bcbabbdef3285658db87619ec3908bb2e345d7d4",
|
||||
"b_rfc8785": "8e3b6038d8f05e0b528979d4049c82e8cbcfd0d3e3c49cedd42ce18e32fdaf1a",
|
||||
"prettier_equals_js_pretty": true
|
||||
},
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/legacy-import/assets.json",
|
||||
"bytes": 408,
|
||||
"today_file_bytes": "109b0e7b8a03d398ea89ef278021f73d4f387992bbfdb2196c9cb7bec4232f2f",
|
||||
"a_js_pretty_newline": "109b0e7b8a03d398ea89ef278021f73d4f387992bbfdb2196c9cb7bec4232f2f",
|
||||
"a_js_pretty": "4d6c0bb91b1f8519b958902989a09cd584a2234757c3272d7a957a9edd10dc28",
|
||||
"a_js_compact": "5f26484bbc984f4057355833d55372f9b8aecac7dd56982abd698d3f0d8bc478",
|
||||
"b_rfc8785": "b4a3bc03eae8e5d4c26faeacc434bf844b9443dd51d190f879a2229812ca399d",
|
||||
"prettier_equals_js_pretty": true
|
||||
},
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/draft/document.json",
|
||||
"bytes": 302794,
|
||||
"today_file_bytes": "27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660",
|
||||
"a_js_pretty_newline": "90f668a3eb697b33d233b412af6cef045939260229abe1bac610d0379637aa1d",
|
||||
"a_js_pretty": "79f143c0f4b41e639a0dfc48520c3e9c94a88d5552caebeba2c820a8148ceb51",
|
||||
"a_js_compact": "59adcbaf44c467fbe8a88318fcef55681389f56d996d9ead0b0e400dc959cfc0",
|
||||
"b_rfc8785": "a56e4a249eaaee82732eb4dd17b7c8be24fab548d776644cd5f7a4f0687e88a1",
|
||||
"prettier_equals_js_pretty": false,
|
||||
"a_js_pretty_validated": "ce4e940558b4cc4772cc1c719be5777a1ffb1517c3b4cf10d6d0830de385cd39",
|
||||
"b_rfc8785_validated": "12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2",
|
||||
"validated_equals_input": false
|
||||
},
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/draft/assets.json",
|
||||
"bytes": 203,
|
||||
"today_file_bytes": "c490dc758b330f372548a595826e2d4de73dcb935af1e39cb4883d5b31927cf5",
|
||||
"a_js_pretty_newline": "c490dc758b330f372548a595826e2d4de73dcb935af1e39cb4883d5b31927cf5",
|
||||
"a_js_pretty": "52fbadaf24eaae1a1c3ecb4e3122e7e1883c0950b6f3c8971e46b9543a533949",
|
||||
"a_js_compact": "91a9234d0c41faacc17c66a20f0ab69141688ff168169df0bc68f171f09b6466",
|
||||
"b_rfc8785": "c654010a95503c6377cd91569d3c54fcecb55a49c0bd398ae19605b6cf30168e",
|
||||
"prettier_equals_js_pretty": true
|
||||
},
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/draft/sheet-ref.json",
|
||||
"bytes": 217,
|
||||
"today_file_bytes": "2c0716f1536e4182cde9ffb0f183c7255d1ad6a1fc754d72011ff8090304b285",
|
||||
"a_js_pretty_newline": "2c0716f1536e4182cde9ffb0f183c7255d1ad6a1fc754d72011ff8090304b285",
|
||||
"a_js_pretty": "afe7698ff86171163796bde3308be96b9ac92998748340a9fa4f44ba49b4444b",
|
||||
"a_js_compact": "5a2a81a30a9fe80d1cb71c19404f8eee277b8fc12e67512dcb8c3c1e24c4201b",
|
||||
"b_rfc8785": "d972d029a310f75596e40188569cd23a02fd26e578bc1197f3b7dcbe6210b1ca",
|
||||
"prettier_equals_js_pretty": true
|
||||
},
|
||||
{
|
||||
"file": "supabase/seed/anatomical-sheets/equine/draft/report-migration-map.json",
|
||||
"bytes": 85627,
|
||||
"today_file_bytes": "4139c51d3acd69ba9ca0ee6bb7bd7ebe7be4eb818e330ff278b37e1d04b7fce9",
|
||||
"a_js_pretty_newline": "4139c51d3acd69ba9ca0ee6bb7bd7ebe7be4eb818e330ff278b37e1d04b7fce9",
|
||||
"a_js_pretty": "01fac788d45ca8d44b33920f72c6442caf41133ec5c614acb40af383b7763471",
|
||||
"a_js_compact": "97572130942dc0cb7538e7b4f7bd8eb71394e6604f08d1bc76214f186f3871c0",
|
||||
"b_rfc8785": "f082b66f9a36fc9ba384e4807a3684e9578ab3c53b018a8a3cf383be5fe52ca6",
|
||||
"prettier_equals_js_pretty": true
|
||||
}
|
||||
],
|
||||
"numbers": [
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[6].geometry.cx",
|
||||
"text": "743.0451049804688"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[9].geometry.cx",
|
||||
"text": "1424.2662353515625"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[10].geometry.cx",
|
||||
"text": "1117.97705078125"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[10].geometry.cy",
|
||||
"text": "469.1115417480469"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[11].geometry.cx",
|
||||
"text": "840.1692504882812"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[11].geometry.cy",
|
||||
"text": "399.0752258300781"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[13].geometry.points[1][0]",
|
||||
"text": "1418.5"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[13].geometry.points[1][1]",
|
||||
"text": "556.2"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[13].geometry.points[2][0]",
|
||||
"text": "1510.8"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[13].geometry.points[2][1]",
|
||||
"text": "539.5"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[13].geometry.points[3][1]",
|
||||
"text": "538.2"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[14].geometry.points[0][0]",
|
||||
"text": "1401.3"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[14].geometry.points[0][1]",
|
||||
"text": "457.1"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[14].geometry.points[4][0]",
|
||||
"text": "1131.4"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[14].geometry.points[4][1]",
|
||||
"text": "503.2"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[14].geometry.points[6][1]",
|
||||
"text": "454.4"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[0][0]",
|
||||
"text": "1109.9"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[0][1]",
|
||||
"text": "497.7"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[1][1]",
|
||||
"text": "558.9"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[2][0]",
|
||||
"text": "1010.3"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[2][1]",
|
||||
"text": "558.9"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[4][0]",
|
||||
"text": "873.9"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[4][1]",
|
||||
"text": "530.7"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[5][0]",
|
||||
"text": "826.8"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[15].geometry.points[5][1]",
|
||||
"text": "509.5"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[7][0]",
|
||||
"text": "695.1"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[7][1]",
|
||||
"text": "528.4"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[8][0]",
|
||||
"text": "728.9"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[8][1]",
|
||||
"text": "520.1"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[9][0]",
|
||||
"text": "765.3"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[9][1]",
|
||||
"text": "472.8"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[10][0]",
|
||||
"text": "816.8"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[11][0]",
|
||||
"text": "796.5"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[16].geometry.points[11][1]",
|
||||
"text": "543.7"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[23].geometry.cx",
|
||||
"text": "384.94287109375"
|
||||
},
|
||||
{
|
||||
"path": "legacy-import/document.json.annotations[23].geometry.cy",
|
||||
"text": "314.0172882080078"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[6].geometry.cx",
|
||||
"text": "743.0451049804688"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[14].geometry.points[1][0]",
|
||||
"text": "1418.5"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[14].geometry.points[1][1]",
|
||||
"text": "556.2"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[14].geometry.points[2][0]",
|
||||
"text": "1510.8"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[14].geometry.points[2][1]",
|
||||
"text": "539.5"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[14].geometry.points[3][1]",
|
||||
"text": "538.2"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[15].geometry.points[0][0]",
|
||||
"text": "1401.3"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[15].geometry.points[0][1]",
|
||||
"text": "457.1"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[15].geometry.points[4][0]",
|
||||
"text": "1131.4"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[15].geometry.points[4][1]",
|
||||
"text": "503.2"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[15].geometry.points[6][1]",
|
||||
"text": "454.4"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[0][0]",
|
||||
"text": "1109.9"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[0][1]",
|
||||
"text": "497.7"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[1][1]",
|
||||
"text": "558.9"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[2][0]",
|
||||
"text": "1010.3"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[2][1]",
|
||||
"text": "558.9"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[4][0]",
|
||||
"text": "873.9"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[4][1]",
|
||||
"text": "530.7"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[5][0]",
|
||||
"text": "826.8"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[16].geometry.points[5][1]",
|
||||
"text": "509.5"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[7][0]",
|
||||
"text": "695.1"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[7][1]",
|
||||
"text": "528.4"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[8][0]",
|
||||
"text": "728.9"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[8][1]",
|
||||
"text": "520.1"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[9][0]",
|
||||
"text": "765.3"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[9][1]",
|
||||
"text": "472.8"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[10][0]",
|
||||
"text": "816.8"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[11][0]",
|
||||
"text": "796.5"
|
||||
},
|
||||
{
|
||||
"path": "draft/document.json.annotations[17].geometry.points[11][1]",
|
||||
"text": "543.7"
|
||||
}
|
||||
],
|
||||
"rfc8785_vectors": [
|
||||
{
|
||||
"input": "{\"numbers\": [333333333.33333329, 1E30, 4.50, 2e-3, 0.000000000000000000000000001], \"string\": \"\\u20ac$\\u000F\\u000aA'\\u0042\\u0022\\u005c\\\\\\\"\\/\", \"literals\": [null, true, false]}",
|
||||
"canonical": "{\"literals\":[null,true,false],\"numbers\":[333333333.3333333,1e+30,4.5,0.002,1e-27],\"string\":\"€$\\u000f\\nA'B\\\"\\\\\\\\\\\"/\"}"
|
||||
},
|
||||
{
|
||||
"input": "{\"\\u20ac\": \"Euro Sign\", \"\\r\": \"Carriage Return\", \"\\ufb33\": \"Hebrew Letter Dalet With Dagesh\", \"1\": \"One\", \"\\ud83d\\ude00\": \"Emoji: Grinning Face\", \"\\u0080\": \"Control\", \"\\u00f6\": \"Latin Small Letter O With Diaeresis\"}",
|
||||
"canonical": "{\"\\r\":\"Carriage Return\",\"1\":\"One\",\"\":\"Control\",\"ö\":\"Latin Small Letter O With Diaeresis\",\"€\":\"Euro Sign\",\"😀\":\"Emoji: Grinning Face\",\"דּ\":\"Hebrew Letter Dalet With Dagesh\"}"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+203
-1
@@ -2089,7 +2089,7 @@ R5 prerequisites (the pipeline port): `packages/anatomy` (curation pipeline,
|
||||
importer, `render/`, the review drawings) and `packages/domain` are the last
|
||||
TypeScript business packages; their oracles (the seed golden, the 612-leaf
|
||||
semantics, the determinism and count suites, the R3 layer oracle) are in
|
||||
place; `documentSha256` will change once (D-R5) and every older archive will
|
||||
place; `documentSha256` will change once (D-R5 rev 2; revised by the R5.1 study, §11.4 to §11.6) and every older archive will
|
||||
rebase on import; `@xmldom/xmldom`, `tsx` and `prettier` on generated files
|
||||
leave with them.
|
||||
|
||||
@@ -2561,3 +2561,205 @@ branch, all in 0dc1ba2 (R4.8, authorised), none after. Merge: `gitflow
|
||||
finish` on `feature/rust-r4-pdf-core` (no-ff into develop, branch
|
||||
deleted local and remote), recorded in `.claude/memory/journal.md`.
|
||||
Release 0.2.0, faunosteo.com and R5 untouched.
|
||||
|
||||
## 11. R5: the anatomical pipeline in Rust (R5.1 freeze and study, 2026-10-22)
|
||||
|
||||
Plan: `.claude/tasks/plans/2026-10-22-rust-r5-pipeline-core.md`. Branch
|
||||
`feature/rust-r5-pipeline-core`, cut from develop 9c0117a (R4 merged). The
|
||||
owner's brief of 2026-10-22 authorises R5.1 only: characterise and freeze
|
||||
the TypeScript pipeline, study the fingerprint decision D-R5, stop before
|
||||
any Rust pipeline code and before any change to `documentSha256`.
|
||||
|
||||
### 11.1 Inventory of the TypeScript pipeline
|
||||
|
||||
`.claude/audits/R5_PIPELINE_INVENTORY.md`. `packages/anatomy`: 43 source
|
||||
files, 4,897 lines (legacy importer 1,842, curation 2,329, frozen renderer
|
||||
553, CLI 119), 131 test cases in 16 files, runtime libraries Prettier
|
||||
3.8.3, @xmldom/xmldom 0.9.12 and Zod 3.25.76 (the first two declared as
|
||||
devDependencies). It emits 18 generated files: 7 JSON and 3 Markdown
|
||||
through Prettier, 5 SVGs through xmldom's serialiser (the cleaned
|
||||
`horse.svg` and 4 review drawings), 1 raw SQL template, 2 byte copies of
|
||||
the legacy SVGs. The authored changeset holds 45 changes (14 A, 22 B, 9 C),
|
||||
687 ops (587 set, 45 cite, 33 rename, 18 add, 4 remove, 0 move) and 48
|
||||
references. `packages/domain` is imported by `packages/anatomy` only (5
|
||||
runtime symbols, each with its R2 counterpart); the crate tests read
|
||||
`packages/domain/tests/fixtures/report-v2.*.json`, and
|
||||
`r4.census.test.ts` pins xmldom under `packages/anatomy`: both move at
|
||||
the deletion slice. The upload tool (`upload-sheet-assets.ts`, 99 lines)
|
||||
depends on the `assets.json` contract only: bucket
|
||||
`anatomical-sheet-assets`, key `<sha256>.svg`, `upsert: false`, bytes
|
||||
re-hashed against the manifest, RPC `confirm_sheet_asset_upload`.
|
||||
|
||||
JavaScript facts a Rust port must reproduce or declare: key insertion
|
||||
order of the working document (`review_status` appended last, not the
|
||||
schema order a typed struct emits), `JSON.stringify(v, null, 2)` then
|
||||
Prettier (measured effect on today's data: short scalar arrays collapsed
|
||||
when they fit in 80 columns, a trailing LF; Markdown: table padding only,
|
||||
134, 863 and 52 lines in the three reports), xmldom's serialiser
|
||||
(declaration kept, `/>` without space, attributes in document order,
|
||||
namespace declared once), `deterministicUuid` (first 16 bytes of sha256 of
|
||||
the name, version nibble 5, variant 10xx), `slugify` (NFD, combining marks
|
||||
U+0300 to U+036F stripped, `toLowerCase`, `[^a-z0-9]+` → `-`, 64 chars;
|
||||
never fires on today's data), UTF-16 `<` sorting, `Math.round` toward +∞
|
||||
on −x.5, `Number('')` = 0, Unicode `\s`, `split(':', 2)`, fatal
|
||||
`TextDecoder` for the SVGs. No clock, no randomness, no localeCompare.
|
||||
|
||||
### 11.2 Oracles frozen (`crates/core/tests/oracles/r5/`)
|
||||
|
||||
Generator `packages/anatomy/tests/r5.pipeline-oracles.test.ts`
|
||||
(`MAKE_R5_ORACLES=1` writes; otherwise the pipeline must still match its
|
||||
freeze; 6 cases, among them a two-run determinism check of every artifact
|
||||
and the ledger check against the committed folders). Never regenerated
|
||||
without the owner.
|
||||
|
||||
| Oracle | Content | Size |
|
||||
|---|---|---|
|
||||
| `pipeline.json` | the ImportResult without the document (sheetId, viewBoxes, stats, source digests, assets, 27 anomalies, issues, region inferences, zone stats, annotation rows), the DraftResult without the documents (46 change summaries, 825 records with before and after, stats before and after, issues, migration stats 792 = 571 + 180 + 7 + 34), the ledger of the 16 text artifacts (folder, file, bytes, sha256; the 2 legacy SVG copies are pinned by the golden test; for the 3 Markdown files the sha256 before Prettier and `prettier_changed: true`) | 1.3 MB |
|
||||
| `ids.json` | `deterministicUuid` over the 3 pipeline names and 3 edges; `slugify` over 17 edge labels and every `name.fr` / `name.en` of both documents (801 rows) | 87 KB |
|
||||
| `fingerprints.json` | per JSON artifact: today's file-bytes sha256, A (`JSON.stringify(v, null, 2)` with and without LF, compact), B (RFC 8785); for the two documents also the validated form (defaults filled) under A and B; the ES6 text of the 65 non-integer numbers; the two RFC 8785 vectors | 13 KB |
|
||||
|
||||
The committed generated folders stay the byte oracle (`seed.golden.test.ts`
|
||||
pins them to a fresh run); the migration semantics stay pinned by
|
||||
`report-migration-map.json`, the 612-leaf suite and the R2 oracle
|
||||
`migration-map.draft.json`; the review drawings by their xmldom bytes and
|
||||
the R3 layer and highlight oracles. `pnpm import:equine` was not run (it
|
||||
rewrites the folders; the golden proves the same bytes).
|
||||
|
||||
### 11.3 Tests and results
|
||||
|
||||
`pnpm --filter @faunosteo/anatomy test:run`: 137 cases in 17 files (131 of
|
||||
the frozen pipeline plus the 6 of the generator), green;
|
||||
`@faunosteo/domain` 262, green; lint and typecheck of the anatomy
|
||||
package green; `git status` shows no change under `supabase/seed`, the
|
||||
goldens, the R2 to R4 oracles or the R4 digests.
|
||||
|
||||
### 11.4 Historical results: no gap, one defect found in the core
|
||||
|
||||
Every generated file reproduces byte for byte from a fresh run. One
|
||||
fingerprint has ever been produced, `27c7383c…2660`, unchanged since
|
||||
0a17e39 (2026-10-10), carried by 99 of the 216 committed PDFs, 8 JSON
|
||||
fixtures and 6 Rust oracle files (`.claude/audits/R5_DOCUMENT_SHA256_CENSUS.md`).
|
||||
|
||||
F1, found by the study (`crates/core/src/json.rs`, `js_number`): the
|
||||
shortest digits come from `format!("{:e}")`, which rounds an exact
|
||||
decimal tie upward, where ECMAScript, Python and `zmij` (serde_json's
|
||||
formatter, already locked) round to even. `840.1692504882812` (legacy
|
||||
annotation `cx`, from Horse.svg, a float32-exact value) prints
|
||||
`…813`. Measured: 1 of the 8 long decimals of the legacy SVGs, 7,401 of
|
||||
100,000 float32-exact values in 0..2000, 769 of 100,000 random doubles;
|
||||
`zmij` differs on none. Over the 134 JSON fixtures of the repository,
|
||||
Node and Rust `JSON.stringify(v, null, 2)` differ on 2 files, both the
|
||||
legacy baseline, both on that value. Invisible today: the curated draft
|
||||
holds no tie value, and the R2 contract test `sheet_contract.rs` re-prints
|
||||
its expected text through `to_js_pretty`, so it cannot see a
|
||||
number-printing difference. Reached by the canvas layer (R3), the PDF
|
||||
writer, the archive attachment and `report-compare`. Not fixed in R5.1:
|
||||
it changes core bytes for tie values (D-R11), so the fix (digits from
|
||||
`zmij`, the tie values as unit tests, `zod_oracle` compared against the
|
||||
recorded JS text) waits for the owner's go and precedes any Rust importer.
|
||||
|
||||
The §10.10 sentence "`documentSha256` will change once (D-R5) and every
|
||||
older archive will rebase on import" describes D-R5 rev 2; the owner's
|
||||
Annex C amendment (BDR-045) supersedes it, and §11.5 studies both.
|
||||
|
||||
### 11.5 D-R5: the fingerprint, facts and comparison
|
||||
|
||||
Today: `documentSha256 = sha256(Prettier(JSON.stringify(document, null,
|
||||
2)))`, the exact bytes of `draft/document.json` in its input form
|
||||
(defaults omitted), copied into `sheet-ref.json` and the migration map,
|
||||
compared and never recomputed by the rebase (fingerprint only), the
|
||||
envelope invariant and the export (sheetId and fingerprint). The database
|
||||
stores the document as `jsonb` and no fingerprint.
|
||||
|
||||
Matrix on the real data (`node scripts/r5-fingerprints.mjs`; cross-checked
|
||||
by a throwaway Rust experiment on the core crate: `to_js_pretty`,
|
||||
`to_js_compact` and a 40-line RFC 8785 canonicaliser over `js_number`,
|
||||
RFC vectors passed, idempotent):
|
||||
|
||||
| Artifact | Today | A `to_js_pretty` + LF | B RFC 8785, input form | B, validated form |
|
||||
|---|---|---|---|---|
|
||||
| draft/document.json | 27c7383c…2660 | 90f668a3…aa1d | a56e4a24…88a1 | 12d78872…74e2 |
|
||||
| legacy-import/document.json | 91e459f4…14c2 | 8c94a464…adc2 | d8b5f2cf…81eb | 1217637e…c024 |
|
||||
| draft/report-migration-map.json | 4139c51d…fce9 | 4139c51d…fce9 | f082b66f…2ca6 | |
|
||||
|
||||
Rust reproduces every draft digest byte for byte; the legacy digests
|
||||
differ through F1 only. The three columns of one row are three encodings
|
||||
of one value (parse and deep-compare); a content change moves every
|
||||
column. Keys: all ASCII in every artifact (UTF-16, code-point and byte
|
||||
order coincide; the Rust canonicaliser sorts by `encode_utf16()` and
|
||||
passes the RFC vector with U+0080, ö, €, 😀 and U+FB33). Numbers: 29 and
|
||||
36 non-integer tokens, none negative, no exponent, no `-0`, none beyond
|
||||
2^53, all already in ECMAScript `Number::toString` form (what JCS
|
||||
mandates). Unicode: 788 non-ASCII strings, all NFC, no control, no escape,
|
||||
no astral, no lone surrogate (I-JSON satisfied; a lone surrogate is
|
||||
refused by the core, L1). Cost: A costs nothing (`to_js_pretty` exists);
|
||||
B costs about 40 lines in `json.rs`, no crate (`serde_jcs` not needed;
|
||||
`sha2` would become a normal dependency of the core or stay in the tool).
|
||||
Determinism: B is a pure function of the parsed value and Node 24 and Rust
|
||||
1.99 agree on every draft artifact; A depends on the writer's layout
|
||||
rules. Database: a PostgreSQL 17 `jsonb` round trip
|
||||
(`packages/supabase/scripts/r5-jsonb-fingerprint.mjs`, PGlite) keeps B for
|
||||
both documents and breaks today's value and A (keys reordered, numeric
|
||||
scale kept): B is the only candidate a service could recompute from
|
||||
`anatomical_sheet_versions.content`.
|
||||
|
||||
| | A: bytes the Rust pipeline emits | B: RFC 8785 of the validated document | C: Rust reproduces Prettier's bytes |
|
||||
|---|---|---|---|
|
||||
| value at the switch | changes once | changes once | unchanged |
|
||||
| alias mechanism needed to avoid a visible migration | yes | yes | no |
|
||||
| survives a reformat, a writer change, a jsonb round trip | no | yes | no |
|
||||
| code | 0 lines | ~40 Rust + 15 Node, no crate | a Prettier-json subset printer, bound to a formatter's layout |
|
||||
| source | D-R5 rev 2 | Annex C, BDR-045 | rejected rev 1 (Node form) |
|
||||
|
||||
Recommendation to the owner: B over the validated form, the alias
|
||||
mechanism of §11.6, the convention named in `sheet-ref.json`, F1 fixed
|
||||
first. C is possible on this data (the only Prettier effect is the
|
||||
short-array collapse) but keeps the identity chained to a formatter.
|
||||
|
||||
### 11.6 Compatibility mechanism for the old fingerprints (proposal)
|
||||
|
||||
The sheet side carries the convention and the aliases; the report
|
||||
contract does not change. `sheet-ref.json`, the bundle payload `ref` and,
|
||||
at Step 13, the stored sheet version carry `document_sha256` (the current
|
||||
convention's value) plus a `fingerprint` block: `algorithm`
|
||||
(`rfc8785-sha256`) and `aliases`, the fingerprints of the same content
|
||||
under earlier conventions, computed once at the switch from the frozen
|
||||
`fingerprints.json` (`27c7383c…2660` for the current draft). The rebase,
|
||||
the envelope invariant and the export treat a fingerprint equal to the
|
||||
current value or to an alias as the same document (one membership test in
|
||||
`report/rebase.rs`, `archive/read.rs`, `session.rs`,
|
||||
`pdf/write/input.rs`: gated files, the owner's go per file). A new report
|
||||
is stamped with the current value; an archive stamped `27c7…` opens with
|
||||
no message and no rebase; an archive on an older content revision rebases
|
||||
as today; no archive, fixture or oracle is rewritten. Report v3 keeps
|
||||
`sheet.documentSha256` (64 hex): the N-1 reader and every fixture stay
|
||||
valid.
|
||||
|
||||
### 11.7 Residual risks of R5.1
|
||||
|
||||
F1 unfixed (declared, bounded: no tie value in the draft); the Rust
|
||||
canonicaliser exists as an experiment only (not in the crate);
|
||||
`validated_equals_input: false` in `fingerprints.json` records that the
|
||||
input and validated forms differ by the filled defaults, so the decided
|
||||
convention must name its form; `supabase/seed/**` is not in
|
||||
`.prettierignore` (a root `pnpm format` would reformat Rust-written
|
||||
files at the switch); the horse.svg asset bytes are xmldom's (re-cleaning
|
||||
with the R3 reader would change the asset sha, id, document, SQL and the
|
||||
Storage object); the slugify and region tables depend on ICU 78.3 (never
|
||||
exercised by today's data).
|
||||
|
||||
### 11.8 Recommended slicing (nothing started)
|
||||
|
||||
R5.1b F1 fix (owner's go). R5.2 legacy importer (`crates/core`
|
||||
curation/legacy, `import-equine` bin): document.json, legacy-id-map.json,
|
||||
assets.json byte-exact, IMPORT-REPORT by table padding or parsed tables.
|
||||
R5.3 changeset applier, migration map, stats, seed SQL: the draft JSON
|
||||
files and the SQL under the decided fingerprint, the 825 records equal,
|
||||
the 612-leaf suite ported. R5.4 review overlays and app drawings on the R3
|
||||
layer and compose (parsed-tree comparison), CHANGELOG and REVIEW-REPORT.
|
||||
R5.5 `upload-sheet-assets` bin, operator runbook. R5.6 the D-R5 switch
|
||||
(convention, aliases, the membership test in the gated readers, seed
|
||||
regenerated once by the Rust tool, `.prettierignore`, CHANGELOG). R5.7
|
||||
consumer census, fixtures moved, `packages/anatomy` and `packages/domain`
|
||||
deleted, xmldom and Prettier out of the anatomy lockfile, docs and ledger.
|
||||
R5.6 needs the D-R5 decision; R5.2 needs R5.1b.
|
||||
@@ -0,0 +1,365 @@
|
||||
/**
|
||||
* R5.1 freeze (plan 2026-10-22 §B.2): what the TypeScript pipeline computes
|
||||
* and emits today, recorded for the Rust pipeline to reproduce. Three
|
||||
* oracles under crates/core/tests/oracles/r5/:
|
||||
*
|
||||
* - pipeline.json: the intermediate values the generated files do not show
|
||||
* (import stats, anomalies, rows, region inferences, change records,
|
||||
* stats before and after, integrity warnings, migration stats) and the
|
||||
* ledger of every generated file (bytes, sha256, the sha256 of the
|
||||
* markdown before Prettier).
|
||||
* - ids.json: the deterministic uuid and slug functions over every name the
|
||||
* pipeline derives an id from, plus edge cases.
|
||||
* - fingerprints.json: the sheet fingerprint of every JSON artifact under
|
||||
* each D-R5 candidate rule, the ES6 printing of every non-integer number
|
||||
* of the two documents, and the RFC 8785 vectors.
|
||||
*
|
||||
* `MAKE_R5_ORACLES=1` writes the files; otherwise the pipeline still matches
|
||||
* its own freeze. The committed generated folders stay the byte oracle
|
||||
* (seed.golden.test.ts); nothing here rewrites them.
|
||||
*/
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { AnatomicalSheetDocumentSchema } from '@faunosteo/domain'
|
||||
import {
|
||||
buildReportMigrationMap,
|
||||
deterministicUuid,
|
||||
EQUINE_DRAFT_DIR,
|
||||
EQUINE_LEGACY_IMPORT_DIR,
|
||||
MAIN_VIEW_ID,
|
||||
renderArtifacts,
|
||||
renderChangelog,
|
||||
renderDraftArtifacts,
|
||||
renderImportReport,
|
||||
renderReviewReport,
|
||||
sha256Hex,
|
||||
slugify,
|
||||
type DraftResult,
|
||||
type ImportResult,
|
||||
} from '../src'
|
||||
import { runDraft } from './helpers'
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url))
|
||||
const REPO = resolve(HERE, '../../..')
|
||||
const OUT = resolve(REPO, 'crates/core/tests/oracles/r5')
|
||||
const MAKE = process.env.MAKE_R5_ORACLES === '1'
|
||||
|
||||
type Json = Record<string, unknown>
|
||||
|
||||
/** The uuid and slug inputs the pipeline derives ids from, plus edges. */
|
||||
const UUID_NAMES = [
|
||||
'faunosteo:sheet:equine:v1',
|
||||
'faunosteo:sheet:equine:v2',
|
||||
'faunosteo:asset:0ea5202fa3b95bac167b87c12ee969ab0272e085b60c2d34dbca6202c5f08541',
|
||||
'',
|
||||
'faunosteo:sheet:équin:v1',
|
||||
'faunosteo:asset:\u{1f40e}',
|
||||
]
|
||||
const SLUG_EDGES = [
|
||||
'',
|
||||
' ',
|
||||
'Cheval',
|
||||
'Épaule gauche',
|
||||
'Vertèbres thoraciques T1–T18',
|
||||
'Œil / orbite',
|
||||
'Straße',
|
||||
'Ørsted',
|
||||
"Rein d'un cheval",
|
||||
'ÀÉÎÕÜ ç ñ',
|
||||
'--déjà--',
|
||||
'a'.repeat(70),
|
||||
'é'.repeat(70),
|
||||
'DŽ Dž dž',
|
||||
'İstanbul',
|
||||
'12 côtes',
|
||||
'Ça (combining cedilla)',
|
||||
]
|
||||
|
||||
/** RFC 8785: UTF-16 member order, no whitespace, JSON.stringify scalars. */
|
||||
function canonicalize(value: unknown): string {
|
||||
if (value === null || typeof value !== 'object') return JSON.stringify(value)
|
||||
if (Array.isArray(value)) return `[${value.map(canonicalize).join(',')}]`
|
||||
const object = value as Json
|
||||
const keys = Object.keys(object).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
|
||||
const members = keys.map(
|
||||
(k) => `${JSON.stringify(k)}:${canonicalize(object[k])}`,
|
||||
)
|
||||
return `{${members.join(',')}}`
|
||||
}
|
||||
|
||||
/** RFC 8785 §3.2.3 examples: numbers and escapes, then member ordering. */
|
||||
const RFC_VECTORS: Array<[string, string]> = [
|
||||
[
|
||||
'{"numbers": [333333333.33333329, 1E30, 4.50, 2e-3, 0.000000000000000000000000001], ' +
|
||||
'"string": "\\u20ac$\\u000F\\u000aA\'\\u0042\\u0022\\u005c\\\\\\"\\/", "literals": [null, true, false]}',
|
||||
'{"literals":[null,true,false],"numbers":[333333333.3333333,1e+30,4.5,0.002,1e-27],' +
|
||||
'"string":"€$\\u000f\\nA\'B\\"\\\\\\\\\\"/"}',
|
||||
],
|
||||
[
|
||||
'{"\\u20ac": "Euro Sign", "\\r": "Carriage Return", "\\ufb33": "Hebrew Letter Dalet With Dagesh", ' +
|
||||
'"1": "One", "\\ud83d\\ude00": "Emoji: Grinning Face", "\\u0080": "Control", ' +
|
||||
'"\\u00f6": "Latin Small Letter O With Diaeresis"}',
|
||||
'{"\\r":"Carriage Return","1":"One","\u0080":"Control","ö":"Latin Small Letter O With Diaeresis",' +
|
||||
'"€":"Euro Sign","😀":"Emoji: Grinning Face","דּ":"Hebrew Letter Dalet With Dagesh"}',
|
||||
],
|
||||
]
|
||||
|
||||
/** Every number of a JSON value that is not an integer, with its JS text. */
|
||||
function nonIntegers(value: unknown, path: string, out: Json[]): void {
|
||||
if (typeof value === 'number') {
|
||||
if (!Number.isInteger(value)) out.push({ path, text: String(value) })
|
||||
} else if (Array.isArray(value)) {
|
||||
value.forEach((item, i) => nonIntegers(item, `${path}[${i}]`, out))
|
||||
} else if (value && typeof value === 'object') {
|
||||
for (const [k, v] of Object.entries(value as Json))
|
||||
nonIntegers(v, `${path}.${k}`, out)
|
||||
}
|
||||
}
|
||||
|
||||
/** Every `name.fr` / `name.en` of a document, unique, in document order. */
|
||||
function names(value: unknown, out: Set<string>): void {
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) names(item, out)
|
||||
} else if (value && typeof value === 'object') {
|
||||
const object = value as Json
|
||||
const name = object.name as Json | undefined
|
||||
if (name && typeof name.fr === 'string') out.add(name.fr)
|
||||
if (name && typeof name.en === 'string') out.add(name.en)
|
||||
for (const v of Object.values(object)) names(v, out)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The input form is what the file holds (defaults omitted); the validated
|
||||
* form is what every reader holds after the schema (defaults filled, Zod
|
||||
* output order). A document.json row carries both.
|
||||
*/
|
||||
function fingerprintRow(file: string, text: string): Json {
|
||||
const value = JSON.parse(text) as unknown
|
||||
const pretty = JSON.stringify(value, null, 2)
|
||||
const row: Json = {
|
||||
file,
|
||||
bytes: Buffer.byteLength(text),
|
||||
today_file_bytes: sha256Hex(text),
|
||||
a_js_pretty_newline: sha256Hex(`${pretty}\n`),
|
||||
a_js_pretty: sha256Hex(pretty),
|
||||
a_js_compact: sha256Hex(JSON.stringify(value)),
|
||||
b_rfc8785: sha256Hex(canonicalize(value)),
|
||||
prettier_equals_js_pretty: text === `${pretty}\n`,
|
||||
}
|
||||
if (file.endsWith('/document.json')) {
|
||||
const validated = AnatomicalSheetDocumentSchema.parse(value)
|
||||
row.a_js_pretty_validated = sha256Hex(JSON.stringify(validated, null, 2))
|
||||
row.b_rfc8785_validated = sha256Hex(canonicalize(validated))
|
||||
row.validated_equals_input = canonicalize(validated) === canonicalize(value)
|
||||
}
|
||||
return row
|
||||
}
|
||||
|
||||
interface Run {
|
||||
result: ImportResult
|
||||
draft: DraftResult
|
||||
legacyFiles: Record<string, string>
|
||||
draftFiles: Record<string, string>
|
||||
}
|
||||
|
||||
async function run(): Promise<Run> {
|
||||
const { result, draft } = await runDraft()
|
||||
return {
|
||||
result,
|
||||
draft,
|
||||
legacyFiles: await renderArtifacts(result),
|
||||
draftFiles: await renderDraftArtifacts(draft, result.anomalies),
|
||||
}
|
||||
}
|
||||
|
||||
function ledger(
|
||||
folder: string,
|
||||
files: Record<string, string>,
|
||||
raw: Record<string, string>,
|
||||
): Json[] {
|
||||
return Object.entries(files).map(([file, text]) => ({
|
||||
folder,
|
||||
file,
|
||||
bytes: Buffer.byteLength(text),
|
||||
sha256: sha256Hex(text),
|
||||
...(file in raw
|
||||
? {
|
||||
before_prettier_sha256: sha256Hex(raw[file]!),
|
||||
prettier_changed: raw[file] !== text,
|
||||
}
|
||||
: {}),
|
||||
}))
|
||||
}
|
||||
|
||||
function pipelineOracle(r: Run): Json {
|
||||
const { result, draft } = r
|
||||
const documentJson = r.draftFiles['document.json']!
|
||||
const migration = buildReportMigrationMap({
|
||||
baseline: draft.baseline as Json,
|
||||
final: draft.document as Json,
|
||||
legacyIdMap: draft.legacyIdMap,
|
||||
records: draft.records,
|
||||
sheet: {
|
||||
sheetId: draft.sheetId,
|
||||
versionId: null,
|
||||
documentSha256: sha256Hex(documentJson),
|
||||
},
|
||||
mainViewId: MAIN_VIEW_ID,
|
||||
})
|
||||
const rawLegacy = { 'IMPORT-REPORT.md': renderImportReport(result) }
|
||||
const rawDraft = {
|
||||
'CHANGELOG.md': renderChangelog(
|
||||
draft,
|
||||
draft.statsBefore,
|
||||
draft.statsAfter,
|
||||
migration.stats,
|
||||
),
|
||||
'REVIEW-REPORT.md': renderReviewReport({
|
||||
...draft,
|
||||
legacyAnomalies: result.anomalies,
|
||||
}),
|
||||
}
|
||||
return {
|
||||
frozen_from: 'packages/anatomy (TypeScript pipeline), R5.1',
|
||||
legacy: {
|
||||
sheetId: result.sheetId,
|
||||
viewBoxes: result.viewBoxes,
|
||||
stats: result.stats,
|
||||
sourceDigests: result.sourceDigests,
|
||||
assets: result.assets,
|
||||
anomalies: result.anomalies,
|
||||
issues: result.issues,
|
||||
regionInferences: result.regionInferences,
|
||||
zoneStats: result.zoneStats,
|
||||
annotationRows: result.annotationRows,
|
||||
},
|
||||
draft: {
|
||||
sheetId: draft.sheetId,
|
||||
changes: draft.changes,
|
||||
assets: draft.assets,
|
||||
statsBefore: draft.statsBefore,
|
||||
statsAfter: draft.statsAfter,
|
||||
issues: draft.issues,
|
||||
migrationStats: migration.stats,
|
||||
records: draft.records,
|
||||
},
|
||||
artifacts: [
|
||||
...ledger(EQUINE_LEGACY_IMPORT_DIR, r.legacyFiles, rawLegacy),
|
||||
...ledger(EQUINE_DRAFT_DIR, r.draftFiles, rawDraft),
|
||||
{
|
||||
folder: EQUINE_DRAFT_DIR,
|
||||
file: `assets/${draft.assets[0]!.file}`,
|
||||
bytes: Buffer.byteLength(draft.cleanedSvg),
|
||||
sha256: sha256Hex(draft.cleanedSvg),
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function idsOracle(r: Run): Json {
|
||||
const labels = new Set<string>()
|
||||
names(r.result.document, labels)
|
||||
names(r.draft.document, labels)
|
||||
const slugInputs = [...SLUG_EDGES, ...labels]
|
||||
return {
|
||||
uuid: UUID_NAMES.map((name) => ({ name, uuid: deterministicUuid(name) })),
|
||||
slug: slugInputs.map((label) => ({ label, slug: slugify(label) })),
|
||||
}
|
||||
}
|
||||
|
||||
function fingerprintsOracle(r: Run): Json {
|
||||
const jsonFiles = [
|
||||
...Object.entries(r.legacyFiles).map(
|
||||
([f, t]) => [`${EQUINE_LEGACY_IMPORT_DIR}/${f}`, t] as const,
|
||||
),
|
||||
...Object.entries(r.draftFiles).map(
|
||||
([f, t]) => [`${EQUINE_DRAFT_DIR}/${f}`, t] as const,
|
||||
),
|
||||
].filter(([file]) => file.endsWith('.json'))
|
||||
const numbers: Json[] = []
|
||||
nonIntegers(
|
||||
JSON.parse(r.legacyFiles['document.json']!),
|
||||
'legacy-import/document.json',
|
||||
numbers,
|
||||
)
|
||||
nonIntegers(
|
||||
JSON.parse(r.draftFiles['document.json']!),
|
||||
'draft/document.json',
|
||||
numbers,
|
||||
)
|
||||
return {
|
||||
rules: {
|
||||
today_file_bytes:
|
||||
'sha256 of the Prettier-formatted JSON text the pipeline writes (pipeline.ts sheetRef)',
|
||||
a_js_pretty_newline: 'sha256 of JSON.stringify(v, null, 2) + "\\n"',
|
||||
a_js_pretty: 'sha256 of JSON.stringify(v, null, 2)',
|
||||
a_js_compact: 'sha256 of JSON.stringify(v)',
|
||||
b_rfc8785: 'sha256 of the RFC 8785 canonical text',
|
||||
a_js_pretty_validated:
|
||||
'document.json only: JSON.stringify(schema.parse(v), null, 2), the validated form (defaults filled)',
|
||||
b_rfc8785_validated: 'document.json only: RFC 8785 of the validated form',
|
||||
},
|
||||
artifacts: jsonFiles.map(([file, text]) => fingerprintRow(file, text)),
|
||||
numbers,
|
||||
rfc8785_vectors: RFC_VECTORS.map(([input, canonical]) => ({
|
||||
input,
|
||||
canonical,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
function write(name: string, value: Json): string {
|
||||
const text = `${JSON.stringify(value, null, 2)}\n`
|
||||
if (MAKE) {
|
||||
mkdirSync(OUT, { recursive: true })
|
||||
writeFileSync(resolve(OUT, name), text)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
function frozen(name: string): string {
|
||||
return readFileSync(resolve(OUT, name), 'utf8')
|
||||
}
|
||||
|
||||
describe('R5.1 oracles (crates/core/tests/oracles/r5)', () => {
|
||||
it('the RFC 8785 canonicaliser passes the RFC vectors', () => {
|
||||
for (const [input, expected] of RFC_VECTORS) {
|
||||
expect(canonicalize(JSON.parse(input))).toBe(expected)
|
||||
}
|
||||
})
|
||||
|
||||
it('pipeline.json: intermediate values and the artifact ledger', async () => {
|
||||
const text = write('pipeline.json', pipelineOracle(await run()))
|
||||
expect(text).toBe(frozen('pipeline.json'))
|
||||
})
|
||||
|
||||
it('ids.json: deterministic uuids and slugs', async () => {
|
||||
const text = write('ids.json', idsOracle(await run()))
|
||||
expect(text).toBe(frozen('ids.json'))
|
||||
})
|
||||
|
||||
it('fingerprints.json: the D-R5 matrix and the number printing', async () => {
|
||||
const text = write('fingerprints.json', fingerprintsOracle(await run()))
|
||||
expect(text).toBe(frozen('fingerprints.json'))
|
||||
})
|
||||
|
||||
it('the ledger digests are the committed files (the golden folders)', async () => {
|
||||
const oracle = JSON.parse(frozen('pipeline.json')) as {
|
||||
artifacts: Array<{ folder: string; file: string; sha256: string }>
|
||||
}
|
||||
for (const row of oracle.artifacts) {
|
||||
const committed = readFileSync(resolve(REPO, row.folder, row.file))
|
||||
expect(sha256Hex(committed), `${row.folder}/${row.file}`).toBe(row.sha256)
|
||||
}
|
||||
})
|
||||
|
||||
it('two runs emit the same bytes for every artifact', async () => {
|
||||
const [first, second] = [await run(), await run()]
|
||||
expect(first.legacyFiles).toEqual(second.legacyFiles)
|
||||
expect(first.draftFiles).toEqual(second.draftFiles)
|
||||
expect(first.draft.cleanedSvg).toBe(second.draft.cleanedSvg)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* D-R5 study (R5.1): does a PostgreSQL `jsonb` round trip keep each candidate
|
||||
* fingerprint of the sheet document? `jsonb` drops the key order and the
|
||||
* whitespace and re-prints the numbers, so a fingerprint over the file bytes
|
||||
* cannot be recomputed from `anatomical_sheet_versions.content`; a canonical
|
||||
* one (RFC 8785) can if the values survive. PGlite 0.3 = PostgreSQL 17,
|
||||
* no Docker. Read-only on the repository.
|
||||
*
|
||||
* pnpm --filter @faunosteo/supabase exec node scripts/r5-jsonb-fingerprint.mjs
|
||||
*/
|
||||
import { PGlite } from '@electric-sql/pglite'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../../..')
|
||||
const SEED = 'supabase/seed/anatomical-sheets/equine'
|
||||
const FILES = [
|
||||
`${SEED}/draft/document.json`,
|
||||
`${SEED}/legacy-import/document.json`,
|
||||
]
|
||||
|
||||
const sha256 = (text) => createHash('sha256').update(text).digest('hex')
|
||||
|
||||
/** RFC 8785 canonical form (the same function as scripts/r5-fingerprints.mjs). */
|
||||
function canonicalize(value) {
|
||||
if (value === null || typeof value !== 'object') return JSON.stringify(value)
|
||||
if (Array.isArray(value)) return `[${value.map(canonicalize).join(',')}]`
|
||||
const keys = Object.keys(value).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
|
||||
const members = keys.map(
|
||||
(k) => `${JSON.stringify(k)}:${canonicalize(value[k])}`,
|
||||
)
|
||||
return `{${members.join(',')}}`
|
||||
}
|
||||
|
||||
async function roundTrip(db, file) {
|
||||
const text = readFileSync(resolve(REPO_ROOT, file), 'utf8')
|
||||
const value = JSON.parse(text)
|
||||
await db.query('delete from t')
|
||||
await db.query('insert into t values ($1::jsonb)', [text])
|
||||
const { rows } = await db.query('select d::text as text from t')
|
||||
const back = JSON.parse(rows[0].text)
|
||||
return {
|
||||
file: file.slice(SEED.length + 1),
|
||||
today: sha256(text),
|
||||
today_after_jsonb: sha256(rows[0].text),
|
||||
a_before: sha256(JSON.stringify(value, null, 2)),
|
||||
a_after_jsonb: sha256(JSON.stringify(back, null, 2)),
|
||||
b_before: sha256(canonicalize(value)),
|
||||
b_after_jsonb: sha256(canonicalize(back)),
|
||||
}
|
||||
}
|
||||
|
||||
const db = new PGlite()
|
||||
await db.query('create table t (d jsonb)')
|
||||
const results = []
|
||||
for (const file of FILES) results.push(await roundTrip(db, file))
|
||||
await db.close()
|
||||
|
||||
console.log(
|
||||
'| File | Today = after jsonb | A = after jsonb | B (RFC 8785) = after jsonb |',
|
||||
)
|
||||
console.log('|---|---|---|---|')
|
||||
for (const r of results) {
|
||||
console.log(
|
||||
`| ${r.file} | ${r.today === r.today_after_jsonb ? 'yes' : 'no'} | ${r.a_before === r.a_after_jsonb ? 'yes' : 'no'} | ${r.b_before === r.b_after_jsonb ? 'yes' : 'no'} (${r.b_before.slice(0, 16)}…) |`,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* D-R5 study (R5.1): the sheet fingerprint of every generated JSON artifact
|
||||
* under each candidate rule, from the committed bytes, read-only.
|
||||
*
|
||||
* node scripts/r5-fingerprints.mjs the markdown matrix
|
||||
* node scripts/r5-fingerprints.mjs --json the same as JSON
|
||||
*
|
||||
* Rules: today = sha256 of the file bytes (Prettier-formatted JSON written
|
||||
* by the TypeScript pipeline); A = sha256 of `JSON.stringify(v, null, 2)`,
|
||||
* which is what the core's `to_js_pretty` emits (option A of D-R5, bytes the
|
||||
* Rust pipeline would write), with and without a trailing newline, plus the
|
||||
* compact form; B = sha256 of the RFC 8785 canonical form (JCS). The RFC's
|
||||
* own vectors run first and stop the script if the canonicaliser fails them.
|
||||
*/
|
||||
import { createHash } from 'node:crypto'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const SEED = 'supabase/seed/anatomical-sheets/equine'
|
||||
const FILES = [
|
||||
`${SEED}/legacy-import/document.json`,
|
||||
`${SEED}/legacy-import/legacy-id-map.json`,
|
||||
`${SEED}/legacy-import/assets.json`,
|
||||
`${SEED}/draft/document.json`,
|
||||
`${SEED}/draft/assets.json`,
|
||||
`${SEED}/draft/sheet-ref.json`,
|
||||
`${SEED}/draft/report-migration-map.json`,
|
||||
]
|
||||
|
||||
const sha256 = (text) => createHash('sha256').update(text).digest('hex')
|
||||
|
||||
/**
|
||||
* RFC 8785: members sorted by the UTF-16 code units of their names (the
|
||||
* default `<` of JavaScript strings), no whitespace, numbers and strings as
|
||||
* `JSON.stringify` prints them (ES6 Number::toString, the JSON escape set).
|
||||
*/
|
||||
export function canonicalize(value) {
|
||||
if (value === null || typeof value !== 'object') return JSON.stringify(value)
|
||||
if (Array.isArray(value)) return `[${value.map(canonicalize).join(',')}]`
|
||||
const keys = Object.keys(value).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
|
||||
const members = keys.map(
|
||||
(k) => `${JSON.stringify(k)}:${canonicalize(value[k])}`,
|
||||
)
|
||||
return `{${members.join(',')}}`
|
||||
}
|
||||
|
||||
/** RFC 8785 §3.2.3 (numbers, string escapes) and the key-ordering example. */
|
||||
const RFC_VECTORS = [
|
||||
[
|
||||
'{"numbers": [333333333.33333329, 1E30, 4.50, 2e-3, 0.000000000000000000000000001], ' +
|
||||
'"string": "\\u20ac$\\u000F\\u000aA\'\\u0042\\u0022\\u005c\\\\\\"\\/", "literals": [null, true, false]}',
|
||||
'{"literals":[null,true,false],"numbers":[333333333.3333333,1e+30,4.5,0.002,1e-27],' +
|
||||
'"string":"€$\\u000f\\nA\'B\\"\\\\\\\\\\"/"}',
|
||||
],
|
||||
[
|
||||
'{"\\u20ac": "Euro Sign", "\\r": "Carriage Return", "\\ufb33": "Hebrew Letter Dalet With Dagesh", ' +
|
||||
'"1": "One", "\\ud83d\\ude00": "Emoji: Grinning Face", "\\u0080": "Control", ' +
|
||||
'"\\u00f6": "Latin Small Letter O With Diaeresis"}',
|
||||
'{"\\r":"Carriage Return","1":"One","\u0080":"Control","ö":"Latin Small Letter O With Diaeresis",' +
|
||||
'"€":"Euro Sign","😀":"Emoji: Grinning Face","דּ":"Hebrew Letter Dalet With Dagesh"}',
|
||||
],
|
||||
]
|
||||
|
||||
function checkVectors() {
|
||||
for (const [input, expected] of RFC_VECTORS) {
|
||||
const got = canonicalize(JSON.parse(input))
|
||||
if (got !== expected) {
|
||||
console.error(
|
||||
`RFC 8785 vector failed:\n got ${got}\n expected ${expected}`,
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function row(file) {
|
||||
const bytes = readFileSync(resolve(REPO_ROOT, file))
|
||||
const value = JSON.parse(bytes.toString('utf8'))
|
||||
const pretty = JSON.stringify(value, null, 2)
|
||||
const canonical = canonicalize(value)
|
||||
return {
|
||||
file,
|
||||
bytes: bytes.length,
|
||||
today: sha256(bytes),
|
||||
a_pretty_newline: sha256(`${pretty}\n`),
|
||||
a_pretty: sha256(pretty),
|
||||
a_compact: sha256(JSON.stringify(value)),
|
||||
b_jcs: sha256(canonical),
|
||||
jcs_bytes: Buffer.byteLength(canonical),
|
||||
prettier_equals_stringify: bytes.toString('utf8') === `${pretty}\n`,
|
||||
}
|
||||
}
|
||||
|
||||
checkVectors()
|
||||
const rows = FILES.map(row)
|
||||
if (process.argv.includes('--json')) {
|
||||
console.log(JSON.stringify(rows, null, 2))
|
||||
} else {
|
||||
console.log('RFC 8785 vectors: pass\n')
|
||||
console.log(
|
||||
'| File | Bytes | Today (file bytes) | A `JSON.stringify(v, null, 2)` + LF | A without LF | A compact | B RFC 8785 | JCS bytes | Prettier = stringify |',
|
||||
)
|
||||
console.log('|---|---|---|---|---|---|---|---|---|')
|
||||
for (const r of rows) {
|
||||
console.log(
|
||||
`| ${r.file.slice(SEED.length + 1)} | ${r.bytes} | ${r.today} | ${r.a_pretty_newline} | ${r.a_pretty} | ${r.a_compact} | ${r.b_jcs} | ${r.jcs_bytes} | ${r.prettier_equals_stringify ? 'yes' : 'no'} |`,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user