p1-4: snapshot + determinism tests

Add the integration snapshot test pinning the full `CanonicalDocument`
JSON for `fixtures/markdown/code-and-table.md` (run through the real
`kb-parse-md::parse_frontmatter` + `parse_blocks`, dev-dep only).
Non-deterministic `provenance.events[*].at` for the Parsed and
Normalized events is stripped before comparison; the Discovered
event's `at` is pinned by constructing the test `RawAsset` with a
fixed `discovered_at`. Run with `UPDATE_SNAPSHOTS=1` to regenerate.

Add the 1000-iteration determinism property: same inputs ⇒ byte-
identical JSON (modulo the same stripped timestamps), in under one
second of wall-clock time. A regression in canonical JSON, BLAKE3
hashing, ordinal counting, or any other deterministic field would
surface here immediately.

The integration test depends on `kb-parse-md` only as a dev-dep, so
`cargo tree -p kb-normalize --depth 1 --edges normal` confirms no
parser implementation appears in the production dep tree per design
§8.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-30 15:20:18 +00:00
parent 1cc0ba9f37
commit 5352bede5c
3 changed files with 315 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
{
"blocks": [
{
"common": {
"block_id": "dd1528c6e84d8a66087cbf6faafd67c6",
"heading_path": [],
"source_span": {
"end": 1,
"kind": "line",
"start": 1
}
},
"kind": "heading",
"level": 1,
"text": "Code And Table"
},
{
"code": "fn main() {\n println!(\"hi\");\n}",
"common": {
"block_id": "68ea34aca04b83413dd8556126ae4584",
"heading_path": [
"Code And Table"
],
"source_span": {
"end": 7,
"kind": "line",
"start": 3
}
},
"kind": "code",
"lang": "rust"
},
{
"common": {
"block_id": "b50a8e941b11f1834ae17adba9e08118",
"heading_path": [
"Code And Table"
],
"source_span": {
"end": 12,
"kind": "line",
"start": 9
}
},
"headers": [
"col a",
"col b"
],
"kind": "table",
"rows": [
[
"1",
"2"
],
[
"3",
"4"
]
]
}
],
"doc_id": "6a9ef317c9c097ff3f6aeb317559bd83",
"doc_version": 1,
"lang": "en",
"metadata": {
"aliases": [],
"created_at": "2023-11-14T22:13:20Z",
"source_type": "markdown",
"tags": [],
"trust_level": "primary",
"updated_at": "2023-11-14T22:13:20Z",
"user": {},
"user_id_alias": null
},
"parser_version": "kb-normalize-snapshot-test-0",
"provenance": {
"events": [
{
"agent": "kb-source-fs",
"at": "2023-11-14T22:13:20Z",
"kind": "discovered",
"note": null
},
{
"agent": "kb-parse-md",
"at": "<stripped>",
"kind": "parsed",
"note": "parser_version=kb-normalize-snapshot-test-0"
},
{
"agent": "kb-normalize",
"at": "<stripped>",
"kind": "normalized",
"note": null
}
]
},
"schema_version": 1,
"source_asset_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"title": "",
"workspace_path": "notes/code-and-table.md"
}