Skip to content

Mermaid: harden version pin (single home, floating-version warning, canary) - #2711

Merged
chalin merged 14 commits into
docsy:mainfrom
chalin:chalin-m24-mermaid-hardening-2026-0809
Aug 9, 2026
Merged

chalin merged 14 commits into
docsy:mainfrom
chalin:chalin-m24-mermaid-hardening-2026-0809

Conversation

@chalin

@chalin chalin commented Aug 9, 2026 •

Copy link
Copy Markdown
Collaborator
  • Contributes to Pin the default Mermaid version instead of @latest #2703
  • Single home for the version: moves the pin to theme/hugo.yaml params.mermaid.version; the partial and diagrams doc page both render it live, killing the 4-copy hand-sync
  • Fail-closed on missing config: an unset params.mermaid.version now errorfs instead of silently falling back to a duplicated default
  • warnidf on floating versions: a non-X.Y.Z version (e.g. latest) emits a suppressible mermaid-floating-version warning
  • Exact-version canary test: tests/mermaid-version.test.mjs fails the build if the pin regresses to a floating version, in the config or the partial; wired into test:full
  • Maintainer notes: bump note shrinks to the one yaml line; documents the emergency security-bump path (manual edit, bypasses the future Renovate age gate, ships via the patch-release flow)
  • Known limitation: the default baseof.html renders scripts.html through an unkeyed partialCached, which can skip the Mermaid partial for pages on that layout; the errorf/warnidf guards above are therefore only guaranteed on the docs, blog, and swagger layouts for now. That caching behavior predates this PR and will be addressed separately.

Follow-up to #2704.

@chalin chalin modified the milestones: Alpha launch, 0.17.0 Aug 9, 2026
chalin added 14 commits August 9, 2026 18:12
…anary)

- **Single home for the version**: moves the pin to `theme/hugo.yaml`
  `params.mermaid.version`; the partial and diagrams doc page both render it
  live, killing the 4-copy hand-sync
- **Fail-closed on missing config**: an unset `params.mermaid.version` now
  `errorf`s instead of silently falling back to a duplicated default
- **`warnidf` on floating versions**: a non-`X.Y.Z` version (e.g. `latest`)
  emits a suppressible `mermaid-floating-version` warning
- **Exact-version canary test**: `tests/mermaid-version.test.mjs` fails the
  build if the pin regresses to a floating version; wired into `ci:post`
- **Maintainer notes**: bump note shrinks to the one yaml line; documents the
  emergency security-bump path (manual edit, bypasses the future Renovate
  age gate, ships via the patch-release flow)

Follow-up to docsy#2704.
- Changelog entry shrinks to a ToC-style pointer instead of restating the
  errorf/warnidf/canary mechanism, which already lives at maintainer-notes.md
  § Default Mermaid version
- Adds a `test:mermaid-version` row to the Test suites table (previously
  undocumented) and cross-links it from § Default Mermaid version, matching
  the § Hugo versions pattern
Adds an evergreen line to the bump procedure (npm registry + OSV lookup)
rather than a version-specific comment in theme/hugo.yaml that would go
stale on the next bump.
- Guards mermaid.html so an unset-version errorf short-circuits the rest of
  the partial instead of falling through to build a garbled CDN URL and
  trigger a second, confusing GetRemote error
- Coerces params.mermaid.version to a trimmed string right after the
  unset-check, so a YAML-typed value (bool, float) stringifies sanely
  (`true`, `11.16`) instead of leaking Go's `%!s(bool=true)`-style fmt
  verbs into the CDN URL, and a trailing-whitespace typo doesn't break the
  URL either
- Tightens tests/mermaid-version.test.mjs's regex: scopes the version match
  inside the params: block (a decoy top-level mermaid: key could otherwise
  mask a floating params.mermaid.version and pass the canary) and strips
  optional quotes (a quoted "11.16.1" previously failed the semver check)
- Swaps the maintainer-notes npm link from the bot-walled npmjs.com/package
  page (docsy.dev's own lychee.toml already excludes this URL pattern) to
  the machine-readable registry.npmjs.org/mermaid API
- Softens the maintainer-notes Renovate-gate wording so it can't be misread
  as describing an already-active mechanism (no renovate.json exists yet)
- Makes the diagrams page's ignoreLogs suppression mention format-neutral
  instead of YAML-only

Found by an independent adversarial review (Grok 4.5, high effort); full
report kept locally, not part of this commit.
- The CDN existence check (`with try (resources.GetRemote)`) only checked
  `.Err`, never `.Value`. A 404 (a version that doesn't exist on the CDN)
  returns Err=nil with an empty Value; Go's template `with` treats the
  returned struct as always-truthy regardless of its fields, so neither
  error branch ever fired and a broken script tag shipped silently
  (reproduced with 99.99.99: built green before, hard-fails after). Fixed
  by mirroring katex.html's three-way `with .Err / else with .Value /
  else` chain, which already handles this correctly.
- Restructures the partial around a positive top-level version check
  (`if $version`): the main logic reads first and an unset version's
  errorf no longer falls through to build a garbled CDN URL.
- Two adversarial rounds each produced decoy key shapes that fooled the
  regex extraction while Hugo resolved a different value (latest round: a
  nested `params.ui.mermaid.version` above the real key); parsing closes
  the class instead of the instance, and also accepts every legitimate
  YAML shape the regex mis-rejected (quoted scalars, comments between
  keys, inline maps, CRLF) -- verified against a 9-case matrix
- Declares `yaml` as a devDependency: it was already in the lockfile as a
  transitive dev dep at the same version, so node_modules content is
  unchanged
- Qualifies the mermaid.html CDN-check comment: GetRemote results are
  cached (default maxAge -1), so the existence check runs on a cold cache,
  not every build
- De-duplicates the floating-version rationale: the warnidf message now
  points at the diagrams page (the rationale's home) instead of restating
  it, following dark-mode-config.html's message-plus-docs-URL idiom --
  this PR kills a 4-copy hand-sync, so it shouldn't add a 2-copy one
- Prose tightening: diagrams-page suppression sentence, maintainer-notes
  emergency-bump tail, test header comment, changelog cross-reference
  phrasing, dash constructs in the partial comment and the fixture-site
  test-suites table row
Also reverts the changelog cross-ref to the file's short "See [X][]" idiom.
- A reintroduced template-level `default` fallback or a hardcoded
  `mermaid@<version>` CDN URL in the partial would ship a version the YAML
  assertion never sees; a second test now pins the partial to reading
  params.mermaid.version and interpolating it (`mermaid@%s`), proven
  red-first against both regression shapes
- Notes in the maintainer docs that the partial's unset/floating guards are
  layout-conditional until the scripts-caching fix lands (previously stated
  only in the PR body, which isn't a durable home)
- Comments the deliberate rejection of prerelease pins for the theme
  default, so future reviews don't re-litigate it
Round-6 follow-up: a post-read reassignment of $version to a literal would
evade the canary's source assertions (they pin the read and the URL
interpolation, not the middle); a structural guard isn't regex-tractable,
so the comment carries the intent at the edit site.
Hoists the string coercion + trim to the read line (the round-4 agreement
was "convert to string first"; it sat inside the if-branch only to dodge
printf's nil rendering, now handled by nil-normalizing with `or ... ""`).
Whitespace-only versions get the clean unset-or-empty error instead of a
confusing double-error path, and non-string values (bool, float) flow
through the same normalized checks -- a bool now correctly hard-fails at
the CDN existence check rather than warn-only. The canary's read-shape
assertion went red on the reshape and was updated with it.
Hugo's cast.ToString alias handles nil natively (empty string), so the
`or ... ""` nil-guard the printf form needed goes away; behavior matrix
(unset, whitespace-only, bool, trailing-space, happy) verified identical.
Also names the canary test file in the read-pinning comment.
…eview)

- Round 6's re-review found the read-pin regex relaxation (made for the
  TrimSpace wrapper) re-admitted `default` as a function call -- the exact
  false-clean the assertion exists to kill, resurrected via call syntax.
  The read now uses the repo's pipe idiom
  (`.Site.Params.mermaid.version | string | strings.TrimSpace`), putting
  the param first in the pipeline so the canary anchors on the expression
  front; nothing can wrap the read without going red. Negative assertion
  tightened to catch both pipe- and call-form `default` (argument-shaped,
  so the partial's own comment stays out of scope). All three injection
  shapes (pipe, call wrapping the read, trailing pipe) proven red-first.
@chalin
chalin force-pushed the chalin-m24-mermaid-hardening-2026-0809 branch from 4765a7d to 1b70b78 Compare August 9, 2026 22:14
@chalin
chalin merged commit fba514d into docsy:main Aug 9, 2026
16 checks passed
@chalin
chalin deleted the chalin-m24-mermaid-hardening-2026-0809 branch August 9, 2026 22:19
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