Repository navigation
test(layout): add property coverage and content-stream readback - #467
Merged
Merged
Conversation
Tim81
force-pushed
the
test/layout-property-suite
branch
from
September 10, 2026 12:02
281275d to
88ed476
Compare
VellumPdf.Layout had no property-based testing: CsCheck was referenced by the Kernel, Reader and Barcodes test projects and not by this one, and Layout has fewer tests than Reader, Kernel, Conformance or Barcodes. That gap lines up with where an audit of the package found its defects, several of them on public members with no test anywhere in the repository. Two invariants cover the render itself, both read out of the emitted content stream rather than recomputed from the layout code's own arithmetic: a render escapes no declared exception contract, and a document places nothing outside its own page box. They are stated over the input range that holds today, so main stays green; widening either to a failing corner belongs in the commit that fixes that defect, where the property has to fail before and pass after. Text is bounded by its measured width rather than its baseline origin. Measured on a 200pt page with zero margins and a footer of 500 W at 12pt, the origin catches a centred band at x = -2732 and a right-aligned one at x = -5464, but a left-aligned band sits at x = 0 and only the width bound sees that its text ends at 5664. Three limits are written down rather than left to be found. The page-box property is containment, not placement: dropping the halving from the band's centre-alignment arm, or the header height from the content area, leaves every property green, and both were measured. It bounds geometry rather than ink, so a quarter point of border stroke outside a near-zero margin passes. And the generated table cell word is held at two characters because generating it turns #468 into a failing property, which belongs in the pull request that fixes it. That defect was found by reviewing this suite: an auto-width table of W followed by g's breaches its content box at six characters and the page at seven. The value-level properties close a coverage gap rather than a defect. LayoutBox is public and shipped and named by no test in the repository; no test read an EdgeInsets member, so Horizontal and Vertical, which the renderer's geometry check depends on, were unasserted. ColorRgb is the weaker case, since a Barcodes test already pinned FromHex and the kernel conversion together, so what is new is per-channel coverage. Every property is pinned by mutation rather than by assertion. Five that the first version of this suite missed are now caught, each confirmed by running it: MeasureString losing its point-size scale, IsEmpty testing the wrong side of zero, both colour operators swapping the same channels, and either the paragraph or the list renderer drawing nothing at all. That last one is why placements are counted per element: asserting merely that some text was shown left all fourteen properties green with the paragraph renderer stubbed, because the table cells and the bands still emit literals. Test-only; nothing ships. Refs #466, #468
Tim81
force-pushed
the
test/layout-property-suite
branch
from
September 10, 2026 12:47
88ed476 to
00eb46b
Compare
Tim81
added a commit
that referenced
this pull request
Sep 10, 2026
Three reviewers on the running-band change found twelve findings at medium or above, every one mine, and three of those were false sentences rather than code faults. This is the fix round. Code: The report could name a page present in no output. SaveAsync and PrepareForSigning collected between the layout and the write, so a second call on an already-written document ran a whole second layout, appending pages to the same PdfDocument, collected from it, and only then threw. All three save paths now collect after their write succeeds, which also makes the collector's Clear consistent rather than reachable through a failure on two paths out of three. The too-tall message's figures did not close. It showed a 200.0pt page and 18.4pt of bands and then reported 161.6pt, leaving out the 20.0pt of margins, which is the larger term, and omitting reducing the margins from the remedies. That is the same fault the commit accused the old message of. It now names both terms and the arithmetic closes. Consecutive spaces left a trailing space in the drawn text, so the width returned charged the alignment formula for ink that is not there and shifted a centred or right-aligned band by 2.78pt per space at 10pt. Only the first space of a run is a cut point now. The culture sweep was incomplete and the claim about it was false. The previous commit fixed four messages and said all four, while the same file held six and the assembly held twelve. Every exception message in VellumPdf.Layout that interpolates a floating-point figure is now invariant: six in DocumentRenderer, two in LayoutImageRenderer, four in PieChartRenderer. LayoutBox.ToString is left alone deliberately, being a shipped public member rather than a message, as are interpolations of integers and enumeration members, which carry no separator to vary. Claims: The byte-identity justification asserted a movement that does not happen. Substituting the running total for the whole-string measurement moved no text matrix across 360 banded documents; the drift is about 7e-13pt against a five-decimal output format, and a 120,000-sample replication found one formatted value differing. The line stays because it is the more accurate width and costs nothing, and the comment now says that no test defends it. "No layout renderer brackets its drawing in q/Q" was false in five places. LayoutImageRenderer and PieChartRenderer both do, and the chart's own comment says it brackets precisely to stop fill colour leaking. Narrowed to the two text renderers, which is what the argument needs. "Every banded document gains one colour operator per band per page" is false at the boundary this change introduces: a band that fits nothing returns before the colour is set and gains none. The surrogate comment claimed a cut can never leave a lone surrogate. True for well-formed input only. A lone surrogate is kept as one unit, and because the walk stops early the embedded path's throw now depends on whether it sits inside the fitted prefix, where before the whole template was always measured. Malformed UTF-16 is caller error either way, but the comment asserted a safety it does not have. The zero-advance hole now states its consequence and not just its mechanism: a band in Symbol or ZapfDingbats measures zero however long it is, is never cut, and is still positioned from a width of zero, so the defect this fixes survives for those two faces with no report. Measured: a 500-glyph Symbol footer emits all 500 glyphs. Filed as #470, and unfixable from here, which has no width to work from. Tests: Three paths had no test, each confirmed by deleting the code and watching the suite stay green. The embedded-font colour branch, the renderer's own BandTruncations property — whose documentation claimed a test that did not exist — and the width a word-boundary cut returns, where a mutation moved the band 2.78pt with every test passing. The property suite's band templates were short because truncation was broken, which is the exclusion PR #467 said belongs in the pull request that fixes the defect. Widened here, and removing truncation now turns the page-box property red. Widening also exposed a coupling of my own: a long template cutting at its first space drew exactly the cell word and inflated the per-element placement counts. Refs #365, #470
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.
Closes #466.
VellumPdf.Layouthad no property-based coverage.CsCheckis referenced by the Kernel, Reader andBarcodes projects and not by this one, and Layout has fewer tests than Reader, Kernel, Conformance
or Barcodes. That gap lines up with where an audit of the package found its defects, several of them
on public members with no test anywhere in the repository.
This is the net for the rest of the layout work, so it lands first.
The two invariants
Both are read out of the emitted content stream rather than recomputed from the layout code's own
arithmetic:
They are stated over the input range that holds today, so
mainstays green. Widening either to acorner where a defect lives belongs in the pull request that fixes it, where the property has to
fail before the fix and pass after. That is the only arrangement that shows it discriminates.
Text is bounded by width, not by origin
Measured on a 200pt page with zero margins carrying a footer of 500
Wat 12pt:The left-aligned run starts inside the page and escapes to the right, so an origin-only check misses
it entirely.
Two limits, stated in the code
The page-box property is containment, not placement. Any misplacement that stays inside the page
passes. Both of these were measured and leave every property green: dropping the halving from the
band's centre-alignment arm, which silently turns a centred band into a right-aligned one, and
dropping the header height from the renderer's content area, which drops content on top of the
header band.
The generated table cell word is held at two characters, because generating it turns #468 into a
failing property. That defect came out of reviewing this pull request:
TableGridResolver.AutoWidthfloors a column at its minimum content width and never caps the sum, so on a 400pt page with 60pt
margins the table breaches its content box at six characters and the page itself at seven, reaching
x = 1444.99 at thirty-three. Those figures are for the word family
Wfollowed bygs; alternatingWandgbreaches the content box at five and the page at seven.The readback helper
ContentStreamReadbackparses the operators the package emits, established by grepping it for everypublic
PdfCanvasmethod name. Every pattern is line-anchored, and the anchoring is load-bearing inthe opposite direction to the obvious one:
cis a prefix ofcm, so an unanchored six-number curvepattern matches every image matrix as well as every real Bézier. On a stream with two
cmlines andone
cline the unanchored pattern returns all three and the anchored one returns the curve alone.The four-number
repattern is safe either way.What review changed
Three reviewers with disjoint lenses. Findings that were confirmed and fixed:
n.PdfCanvas.WritePdfStringescapes fivebytes, not three: it also writes 0x0A and 0x0D as
\nand\r. Latent, since no generateddocument contains a newline, but it would have inflated every computed right edge.
plausible mutation and duplicated Kernel's suite exactly. It now pins widths against the shipped
advance table, which also breaks the circularity of computing the page-box right edge with the
same function that placed the text.
LayoutBox.IsEmpty's non-positive branch was unreachable: the extent generator drew from[0, 1000], and sampling CsCheck directly gave 42 exact zeros in 200,000 draws.involution. Channels are now pinned individually.
The first attempt at this, asserting merely that some text was shown, did not discriminate
either: with the paragraph renderer stubbed, all fourteen stayed green because the table cells
and bands still emit literals. Placements are now counted per element, derived from the
generated shape, and stubbing either the paragraph or the list renderer fails.
Five mutations the first version missed are now caught, each verified by running it:
MeasureStringlosing its point-size scale,
IsEmptytesting the wrong side of zero, the symmetric channel swap,and either the paragraph or the list renderer drawing nothing.
A confirmation round then re-ran every one of those mutations independently and found that four of
the five fixes held while the fifth, the drawing-nothing case, did not — which is the finding above.
It also corrected four statements: the stroke figure contradicted the tolerance in the same
sentence, a claim about Kernel's suite conflated two different tests, "safe either way" was a
universal that fails when a text literal contains four numbers and the token, and the sampling
figure came from a counter that lost updates because CsCheck samples in parallel.
One reviewer finding was not confirmed. The claim that the horizontal detection floor is around
0.5pt and flaky below assumed a uniform margin. Measured,
Gen.Double[0.0, 60.0]puts 123 of 410samples below 0.01pt and hits exact zero twice, so the zero-margin edge is sampled often and a 0.01pt
cell shift went red in three runs out of three.
Verification
dotnet build VellumPdf.slnxclean, warnings are errors.dotnet test VellumPdf.slnx -c Release6,839 total, 0 failed, 319 skipped.dotnet format --verify-no-changesandeng/clean-room-check.ps1clean.Test-only; nothing ships. No public API moves, so neither
PublicAPIfile is touched.