Skip to content

Deterministic output: DocumentId pin + determinism tests - #14

Merged
Tim81 merged 1 commit into
mainfrom
regression-safety-determinism
Jun 9, 2026
Merged

Tim81 merged 1 commit into
mainfrom
regression-safety-determinism

Conversation

@Tim81

@Tim81 Tim81 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Part of #5 (regression safety & test depth). Establishes the determinism foundation that
golden snapshots and reproducible builds depend on. Build clean; 280 Kernel + 122 Layout
tests pass; format-clean.

What

  • PdfDocument.DocumentId — an optional fixed /ID (the permanent element of the PDF
    /ID array). When null, the ID is derived from content + Timestamp exactly as before;
    when set, it takes precedence. Pin Timestamp + DocumentId for byte-identical output.
  • Wired into both Save paths (classic xref + object-stream) and the signing path.
  • DeterminismTests (4): identical content → identical bytes for a normal doc and for the
    PDF/A-2b path (which exercises the timestamp-dependent XMP + output-intent code); the pin
    demonstrably changes and stabilises the /ID; timestamp-only determinism still holds.

Why

The /ID was already deterministic when Timestamp is pinned (it is an MD5 over
content + timestamp), but there was no way to set it explicitly. An explicit pin is needed
for reproducible builds and lets golden tests assert a known, fixed /ID independent of the
hash derivation.

Next in #5 (follow-ups)

Golden snapshot tests (Verify), property-based tests (CsCheck), benchmarks (BenchmarkDotNet),
CI code-coverage, the Ghostscript render oracle, and Linux font-path detection — each a
separate focused PR. This PR unblocks the golden-snapshot work.

Adds PdfDocument.DocumentId — an optional fixed /ID (the permanent element of the
PDF /ID array). When null the ID is derived from content + Timestamp as before; when
set it takes precedence, so pinning Timestamp + DocumentId yields byte-identical output.
This is the determinism foundation for golden snapshots and reproducible builds.

Wired into both Save paths and the signing path. Adds DeterminismTests proving identical
content -> identical bytes (including the PDF/A-2b XMP/output-intent path).

Part of #5.
@Tim81
Tim81 merged commit 8cf63b2 into main Jun 9, 2026
@Tim81
Tim81 deleted the regression-safety-determinism branch June 9, 2026 17:48
Tim81 added a commit that referenced this pull request Sep 6, 2026
Deterministic output: DocumentId pin + determinism tests
Tim81 added a commit that referenced this pull request Sep 6, 2026
Follow-up to #14:
- Document that encrypted/signed output stays non-deterministic regardless of the pins
  (fresh random salts/IVs per save; signatures are time/key-dependent), and note the
  conventional 16-byte /ID length.
- Defensively copy DocumentId on get and set so mutating the array after assignment has
  no effect on the output.
- Add a PrepareForSigning determinism test covering the signing-path /ID wiring.
Tim81 added a commit that referenced this pull request Sep 6, 2026
Follow-up to #14:
- Document that encrypted/signed output stays non-deterministic regardless of the pins
  (fresh random salts/IVs per save; signatures are time/key-dependent), and note the
  conventional 16-byte /ID length.
- Defensively copy DocumentId on get and set so mutating the array after assignment has
  no effect on the output.
- Add a PrepareForSigning determinism test covering the signing-path /ID wiring.
Tim81 added a commit that referenced this pull request Nov 2, 2026
NormaliseWhitespace kept only U+00A0, so a paragraph could wrap at the narrow
no-break space French puts before ; ? ! and at the figure space. Treat all
three white-space characters in UAX #14 class GL as part of a word, in the
paragraph wrap and in ListRenderer's indent bound, from one definition.

Keeping them meant deciding how a font draws them. The Standard-14 encoder and
metrics now treat U+202F and U+2007 as U+00A0 instead of '?', and an embedded
font without the glyph falls back to U+00A0's, then a space's, instead of
.notdef.

Refs #562
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