Skip to content

Add file-hash and document-ID recompute conformance track (B1b-3a) - #101

Merged
gvonnessi merged 1 commit into
mainfrom
feat/conformance-b1b3a-hash-id-recompute
Jul 27, 2026
Merged

Add file-hash and document-ID recompute conformance track (B1b-3a)#101
gvonnessi merged 1 commit into
mainfrom
feat/conformance-b1b3a-hash-id-recompute

Conversation

@gvonnessi

Copy link
Copy Markdown
Collaborator

Summary

Tier 3 part 1 of the document/part conformance layer — the "declared vs computed" half of State Machine §5.4.2 row 319 ("File hash or document-ID mismatch"). Previously the document mapper loaded and type-classified parts but never verified that manifest.content.hash matched the stored content bytes, nor that manifest.id matched the recomputed canonical document ID, so a tampered or stale document loaded CLEAN.

The mapper now, inside the parseable-content branch:

  • File-hash mismatch — verifies the file-level content.hash against the exact stored content bytes (Document Hashing §5.1), via a new centralized hashBytes helper reusing the same algorithm allowlist as computeDocumentId.
  • Document-ID mismatch — for a document carrying a real (non-pending) id, recomputes the canonical document ID and compares it to manifest.id.

Both are WARNING in draft/review. The frozen/published INTEGRITY-ERROR escalation is state-keyed (§6.3) and, needing a projection-covering signature to trust the state (§5.4.2 note 3), is deferred to B3. An unresolvable Dublin Core reference or an uncomputable id algorithm (blake3) is treated as indeterminate, not a mismatch.

Also:

  • Two errors.json codes — CDX-E-FILE-HASH-MISMATCH, CDX-E-DOCUMENT-ID-MISMATCH (vocabulary v0.7).
  • part-loader exposes the raw decompressed bytes on a clean load (hashing the exact stored bytes, not the re-encoded text).
  • 4 new document fixtures + independent shared-nothing oracle confirmers (re-derive the file hash with hashlib, and — for transform-trivial content, under a whitelist guard — the canonical id).

Scope split: asset-hash (row 320) + presentation-file hash → 3b (shares fixture infra with the dangling-asset / missing-part rows); full content validity → 3c; frozen/published escalation → B3; MIME advisory (row 321) deferred.

Test plan

  • check:conformance274/274 (199 vectors + 75 fixtures)
  • check:document-oracle — 47 injected defects confirmed + 5 clean docs (independent, shared-nothing)
  • All 27 CI-parity gates green (tsc, check:*, generate:template)
  • 4 mutation tests — each new defense loses teeth when broken, restored on revert
  • /review-fix run to completion (2 cycles → PASS; one IMPORTANT false-positive fixed and re-verified)

Tier 3 part 1 of the document/part layer: the "declared vs computed"
half of State Machine section 5.4.2 row 319 ("File hash or document-ID
mismatch"). Until now the document mapper loaded and type-classified
parts but never checked that manifest.content.hash matched the stored
content bytes, nor that manifest.id matched the recomputed canonical
document ID, so a tampered or stale document loaded CLEAN.

The mapper now, inside the parseable-content branch:
  - verifies the file-level content.hash against the exact stored bytes
    (Document Hashing section 5.1), via a new centralized hashBytes helper
    that reuses the same algorithm allowlist as computeDocumentId; and
  - for a document carrying a real (non-pending) id, recomputes the
    canonical document ID and compares it to manifest.id.
Both are WARNING in draft/review; the frozen/published INTEGRITY-ERROR
escalation is state-keyed (section 6.3) and, needing a projection-covering
signature to trust the state (section 5.4.2 note 3), is deferred to B3.
An unresolvable Dublin Core reference or an uncomputable id algorithm
(blake3) is treated as indeterminate, not a mismatch. Asset-hash (row
320), presentation-file hash, and the reference/missing-part rows are
deferred to B1b-3b; full content validity to B1b-3c.

Adds two errors.json codes (CDX-E-FILE-HASH-MISMATCH,
CDX-E-DOCUMENT-ID-MISMATCH; vocabulary v0.7), exposes raw part bytes on
a clean load in part-loader, adds 4 document fixtures plus independent
shared-nothing oracle confirmers (re-deriving the file hash and, for
transform-trivial content, the canonical id under a whitelist guard).
check:conformance 274/274; all 27 gates green.
@gvonnessi
gvonnessi merged commit 63522ba into main Jul 27, 2026
2 checks passed
@gvonnessi
gvonnessi deleted the feat/conformance-b1b3a-hash-id-recompute branch July 27, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant