Skip to content

feat(docs): add opt-in Typst content guards - #2019

Merged
gerchowl merged 29 commits into
devfrom
feature/1994-typst-content-guards
Nov 4, 2026
Merged

gerchowl merged 29 commits into
devfrom
feature/1994-typst-content-guards

Conversation

@gerchowl

@gerchowl gerchowl commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add docs-only content checks for missing figure captions, missing table headers, direct page/font overrides, and SVG lettering below 7 pt at its placed size. The shared hook supports skip globs and end-of-line suppression with source diagnostics.

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task
  • refactor -- Code restructuring
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style changes

Modifiers

  • Breaking change (!)

Changes Made

  • Add typst-content through the shared docs hook definition and portable asset; keep non-docs hook configuration unchanged.

  • Query compiled content once per entry in one shared ephemeral mirror, with source diagnostics and at most two compiler workers. Preserve native image values and validate a clean original compile before falling back from instrumentation failures or warnings.

  • Resolve literal and variable image paths relative to their containing source and retain generated assets. Honor table suppression without derived-table duplicates, detect multiline function/closure template overrides, and scope duplicate-label/fallback suppression to individual calls in dependency/document order.

  • Preserve markup and caption prose around inline expressions so grid/column measurements stay instrumented, while retaining multiline and imported closure checks.

  • Attribute logos only to direct document-template parameters and measure each logo/body placement independently; dictionary keys cannot supply logo attribution. Instrument only compiler-reported dependency sources with indexed scanning, linear edit assembly, and cached dependency-edge tokenization.

  • Measure SVG fit, nested SVG/symbol viewports, inherited font units, height-only sizing, visible text and used definitions. Resolve CSS font shorthand from Matplotlib 3.6–3.9 and the 3.10 font-size form with the normal cascade and !important; warn on unresolved sizes and bounded use expansion. Accept Matplotlib DOCTYPEs while blocking entities/external references; warn per placement for Typst scale transforms.

  • Ship package 0.2.1 with guard-only layout measurements for percentages, automatic sizing, grids, columns and figure bodies. Archive the exact shipped 0.2.0 source and retain historical imports and hashes.

  • Document fallback sizing, unresolved-size warnings, SVG limitations and suppression. Add a dedicated sandboxed compiler contract and a reproducible medium-document benchmark.

  • Track code and markup with one structural tokenizer, including multiline else chains, smart quotes, URLs, escaped hashes and qualified builtin calls. Reuse its modes, delimiters and comments for instrumentation.

  • Record effective paper, margins and font in guard-only package contexts at page starts and headings. Report runtime bypasses by page; document the entry-level runtime suppression marker.

  • Warn on incomplete CSS blocks and cap selector/node work at 1,000,000, including repeated reference visits.

Changelog Entry

Added

  • Opt-in Typst content guards (#1994)
    • Check figure captions, table headers, house-style overrides and SVG text below 7 pt at its placed size, with skip globs and source-line suppression.
    • Retain prior house-style imports and add 0.2.1 guard-only layout measurements without changing normal PDF output.

Testing

  • Full local suite (just test); delegated to CI as required by the task brief.
  • Targeted tests pass locally.
  • Manual testing performed.

Manual Testing Details

  • RED tests were committed before implementation. Scanner regressions, seven runtime alias cases, repeated-reference CSS work and replaced-header cases each failed before their fixes (pytest exit 1).
  • Targeted scanner, compiler contracts, guards, package integrity and docs scaffolding: 278 passed, exit 0. Final runtime and normal-output equality regressions after moving page probes into the background: 11 passed, exit 0.
  • Final nix build .#checks.x86_64-linux.typst-content .#checks.x86_64-linux.typst-house-style --no-link --max-jobs 1 --cores 2 -L: exit 0. Includes 115 content compiler contracts, 165 house-style tests, the remaining native/layout contracts and 21 killed style mutants.
  • Six content mutants killed: markup content inheriting code mode, logo closing-line suppression, reference-depth cap, inline-call adjacency, context introducer and direct template-logo attribution. Every mutant exits 1 on an explicit assertion or missing expected exception; the mutation harness exits 0.
  • Normal 0.2.1 PDFs are byte-identical to released 0.2.0; its archived package digest matches the unchanged release lock. Historical imports remain resolvable.
  • Prior review benchmark: uv run python packages/vig-utils/tests/benchmark_typst_content.py --entries 1 --figures-per-entry 4000 --unrelated-files 0 measured 60.567s before and 21.052s after, both exit 0. This round adds a source-tokenization count regression and caps CSS cascade work at 1,000,000 selector/node evaluations, including repeated references.
  • All 18 checks passed on pushed head 1490cf833f09e1d94c4902354f980f609b5eb759. CI including Test Summary, Home Matrix, and CodeQL completed successfully.

Current local pytest commands (each exit 0):

uv run --with pytest-xdist pytest packages/vig-utils/tests/test_typst_content_unit.py packages/vig-utils/tests/typst_content_contract.py packages/vig-utils/tests/test_typst_guard.py packages/vig-utils/tests/test_typst_packages.py tests/test_typst_docs.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1994f-r6-rebased -q
uv run --with pytest-xdist pytest packages/vig-utils/tests/typst_content_contract.py -k 'runtime or normal_output_unchanged' -n 4 --basetemp=$HOME/.cache/devkit-pytest/1994f-r6-header-green -q

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented hard-to-understand areas
  • I have updated the documentation accordingly
  • I have updated both CHANGELOGs and the generated changelog copy
  • My changes generate no new warnings or errors in normal builds
  • I have added tests that prove the feature works
  • New and relevant existing unit tests pass locally
  • Any dependent changes have been merged and published

Additional Notes

Relative and automatic sizing without package metadata uses the documented page-width fallback. Unresolved sizing/font shorthand, unsupported SVG styling, scale transforms and SVG use expansion limits emit named warnings. SVG traversal is capped at 32 reference levels and 32,768 visited nodes, including repeated reference contents. Unsupported uppercase font properties, declaration comments and spaced importance markers warn explicitly. Images from bytes have no inspectable source path and are documented as skipped. Raster images and lettering converted to outlines cannot be measured. Rebased onto #2017; retain the released 0.2.0 source and hash while shipping guard instrumentation in 0.2.1.

The retained 0.2.0 package is an unchanged archive of previously reviewed source from #2017. Shared defusedxml is retained so dynamically activated docs hooks and recipes always use the same hardened parser without a second Python environment; the dependency tradeoff is documented in both CHANGELOGs.

Refs: #1994

@gerchowl
gerchowl force-pushed the feature/1994-typst-content-guards branch from a2c773b to 7a7e97e Compare November 4, 2026 01:33
Archive the unchanged 0.2.0 package and verify normal 0.2.1 output against it.

Refs: #1994
@gerchowl
gerchowl force-pushed the feature/1994-typst-content-guards branch from 7a7e97e to 1490cf8 Compare November 4, 2026 03:18
@gerchowl
gerchowl merged commit f292184 into dev Nov 4, 2026
18 checks passed
@gerchowl
gerchowl deleted the feature/1994-typst-content-guards branch November 4, 2026 03:48
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