Skip to content

feat(docs): add opt-in Typst guards and reproducible builds - #2005

Merged
gerchowl merged 21 commits into
devfrom
feature/1994-typst-guards
Nov 3, 2026
Merged

gerchowl merged 21 commits into
devfrom
feature/1994-typst-guards

Conversation

@gerchowl

@gerchowl gerchowl commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Document projects can opt into formatting, compile, package-pin, and generated-PDF guards through the docs module. Scaffold upgrades reconcile committed hook configs and install reproducible build recipes while preserving consumer comments and exclusions.

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

Modifiers

  • Breaking change (!)

Changes Made

  • Define four opt-in guards in nix/hooks.nix and drift-check the portable scaffold asset against that definition.
  • Select entries with whitespace-tolerant // devkit: entry markers, warn about suspicious unmarked entries, smoke-compile templates, and support DEVKIT_TYPST_SKIP globs.
  • Add stamped/canonical recipes with dependency lists and fixed epoch/timezone. Use built-in fonts by default and explicit repo-relative DEVKIT_TYPST_FONT_PATHS for branding; always ignore system fonts. Report resolved tool binaries and their own versions as JSON.
  • Reconcile module-owned hooks inside the actual repos sequence using existing PyYAML source spans. Preserve indentation, CRLF, final-newline presence, comments, and original exclusions; ON/OFF restores original bytes. Validate staged and installed output with prek and roll back on failure. Skip existing hand-written document hooks with a notice.
  • Keep docs-only committed-config shells out of generated-hook installation. Explicit hooks = { }; still enables generated hooks.
  • Require ON lint findings to have no increased count for any rule/message under strict scaffold yamllint and consistent sequence indentation. Catch generated PDFs case-insensitively.

Reconciliation design decision

The docs hooks fit the existing exact feature-marker block model (#1654). Reversible per-fixer exclude merges do not fit its version-gated whole-block tables. Extract the existing hook_block_range, splice_lines, and delete_lines shell functions into assets/preserved-hooks.sh, used by both legacy folds/inserts and docs. Route docs through the central preserved-hook pass and its insert/fold/drift reporting. Remove typst_scaffold.py and its separate marker matcher and position-keyed base64 protocol.

The small YAML-aware extension stages edits around those shared primitives, uses marker-only docs lookup while retaining structural lookup for legacy hooks, validates with prek, and rolls back on expected or unexpected failures. Restore exclusions by repository/hook ID and compare parsed values, allowing formatter re-quoting. Bounded state comments preserve original field bytes; derive indentation from the consumer structure and reuse an existing local hook sequence where available to avoid multiplying existing lint findings. Write and restore bytes in place to preserve the inode. Decline hand edits anywhere in the owned block, including comments, using the existing fold ownership rule. Failures print manual advice and let the installer continue. Existing pre-release blocks with the old state format require manual cleanup; they are left intact with a warning.

The installer owns justfile.devkit-docs to avoid collisions with consumer justfile.docs files, which are never touched or imported. Only docs ON with a managed recipe file emits the import; unmanaged files at the reserved name are retained without importing them. Preview reports hook and recipe/import changes. Inline comments on injected exclusion fields are refused before any text is dropped; deleted fixers, changed repository URLs, and relocated excludes receive precise recovery advice. See docs/NIX.md. Extended regex comments cannot swallow the generated-directory alternative.

Changelog Entry

Added

  • Opt-in Typst guards and reproducible builds (#1994)
    • Enable module-gated formatting, warning-free compilation, package pins, and generated-PDF guards, with reversible scaffold reconciliation.
    • Add stamped/canonical just recipes, dependency lists, toolchain probing, and built-in-font deterministic builds.
    • Validate reversible hook edits across YAML layouts, retain hand-written hooks, and keep committed-config shell entry free of generated-hook installation.
    • Support explicit project branding fonts, flexible entry markers, resolved tool identities, and case-insensitive generated-PDF guards.
    • Preserve four-space indentation and file inodes; isolate managed docs recipe imports, report preview changes, and give safe edit-recovery advice.
    • Share preserved-hook reconciliation primitives, retain consumer recipe files and managed-block edits, and restore exclusions by repository/hook identity.

Testing

  • 133 targeted/shared tests: PYTHONPATH="$PWD/packages/vig-utils/src:$PYTHONPATH" uv run --with pytest-xdist pytest tests/test_typst_reconcile.py tests/test_typst_docs.py tests/test_scaffold_preserved_hooks.py packages/vig-utils/tests/test_typst_guard.py -n 2 --basetemp=$HOME/.cache/devkit-pytest/1994a-r5-final2 (exit 0). Initial RED: 18 failed, 86 passed (exit 1); failing regressions committed first. Five requested mutants M1/M6/M11/M12/M15 each produce pytest exit 1. Nix shell hooks pass on all commits.
  • Real-tool Nix canary for all four guards and all three recipes.
  • Manual testing performed: typstyle 0.15.2 CLI inspection confirms no config-file option.
  • Full suites passed in CI on 7f1ea5bb6894af6ca0ed6cfdf1d83fea6ac494fe, including Nix render/consumer fidelity gates, consumer matrix, BATS, image/integration tests, and Test Summary. gh pr checks 2005 --watch exited 0.

Manual Testing Details

The real Nix canary rejects unformatted sources, compile errors, compiler warnings, invalid package versions, and uppercase indexed generated PDFs while accepting PDFs elsewhere. It exercises the actual installer docs gate, discovered system-font exclusion with and without project branding fonts, resolved tool identities, revision stamps, dependency output, and canonical PDF hash stability with project branding fonts. Ambient TYPST_FONT_PATHS points at a real font directory. Regression cases cover the review findings and five requested mutations: reordered hooks, re-quoting, ownership, hand edits, indentation, extended regex comments, and unexpected rollback. A direct nix eval also verifies that docs-only shellHook emits no generated-config refusal or installation.

Checklist

  • Code follows project style guidelines
  • Self-review performed
  • Non-obvious reconciliation behavior documented
  • docs/NIX.md updated
  • Unreleased changelog and scaffold mirror updated
  • Tests prove the guards execute on bad samples
  • Targeted tests pass locally
  • Toolchain prerequisite fix(nix): track unstable Typst tooling in the docs module #1995 is merged

Additional Notes

Phase 1a only. The glossary, house-style package, content guards, and preview CI remain in their planned phases. Typstyle 0.15.2 uses its CLI default of 80 columns; no unsupported typstyle.toml is installed. The docs module retains the packages/env/shellHook contract: the scaffold owns committed configuration, and mkProjectShell owns generated configuration. Canonical documents must tolerate an absent revision input; preview-package downloading can require network access on first use.

Refs: #1994

@gerchowl
gerchowl force-pushed the feature/1994-typst-guards branch from 7624c18 to 19b53ef Compare November 3, 2026 10:57
@gerchowl
gerchowl force-pushed the feature/1994-typst-guards branch from 19b53ef to 76ff671 Compare November 3, 2026 12:03
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