Skip to content

CI: fail build when audit-harness citation markers leak into compiled output - #1678

Open
marcin-kordas-hoc wants to merge 13 commits into
developfrom
feat/ci-audit-strip-check
Open

marcin-kordas-hoc wants to merge 13 commits into
developfrom
feat/ci-audit-strip-check

Conversation

@marcin-kordas-hoc

@marcin-kordas-hoc marcin-kordas-hoc commented May 25, 2026 •

Copy link
Copy Markdown
Collaborator

Context

The PR adds a CI check that fails when a citation marker from a draft document reaches the build output or the docs.

  • Why: a marker in a JSDoc comment reaches commonjs, es, typings and dist, and the API reference in docs/api.
  • What changed:
    • script/check-citation-markers.mjs: scans 7 directories: hyperformula/commonjs, dist, es, languages, typings, plus docs/api and docs/guide. Exits 1 on a marker and 2 when a directory is missing or empty.
    • package.json: npm run check:citation-markers, the script's only caller.
    • .github/workflows/build-docs.yml: one step after npm run docs:build, which builds both the engine and the docs.
    • dev-docs/BUILD.md, dev-docs/STRUCTURE.md, script/AGENTS.md: list the script and where it runs.
  • Result: a marker in any scanned file fails build-docs, and a moved output directory fails the check instead of passing it.

Before each scan, the script checks its pattern against marker and non-marker samples, so a broken pattern also fails.

How did you test your changes?

After npm run bundle-all and npm run typedoc:build-api, npm run check:citation-markers scanned 942 files and exited 0. For each of the 7 directories:

Control Exit code
A file with a marker added 1
That file removed 0
Directory moved away 2
Directory empty 2

In CI, the build-docs job ran the check on 943 files and passed.

A marker planted in one JSDoc comment in hyperformula/src, followed by a rebuild, gave 8 hits and exit 1. Also: all 9 marker forms appended to a source map exit 1, with 9 hits. Non-marker look-alikes exit 0. A pattern that matches nothing, or one that matches too much, fails the self-check with exit 2.

Compatibility with Excel and Google Sheets

Not applicable.

Public API changes

None.

Out of scope and follow-ups

  • The rendered portal (docs/.vuepress/dist) and the dev-docs/ site are not scanned.

Types of changes

  • Breaking change (existing functionality no longer works as before) – agreed with the maintainers
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues

None.

Checklist

… output

Adds a post-build scan step to `.github/workflows/build.yml` that
greps `dist/`, `commonjs/`, and `es/` for two internal-only marker
patterns:

- `\[V[0-9]+\]` — audit-harness citation markers used in spec drafts
- `§[[:space:]]*Sources` — section heading used in audit-harness footers

Both are conventions from the audit-harness tooling and belong in
internal docs/prompts only. If they ever appear in compiled JS it
means a comment or string literal slipped through from a spec draft
into shipped output — the scan fails the workflow with the offending
file path and line number.

The step runs after `npm run bundle-all` (which produces the three
output directories) and skips gracefully if a directory is missing,
so unrelated build failures aren't masked by this guardrail.

Manual verification:
- Synthesized `dist/foo.js` containing both markers — grep matched
  both lines and exited 1 with a clear message.
- Repeated with clean JS — grep exited 0.
- Repeated with no output dirs — step exited 0 (skip path).
@netlify

netlify Bot commented May 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hyperformula-docs ready!

Name Link
🔨 Latest commit 803f11a
🔍 Latest deploy log https://app.netlify.com/projects/hyperformula-docs/deploys/6a1406fc85be2a000849e0c8
😎 Deploy Preview https://deploy-preview-1678--hyperformula-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for hyperformula-dev-docs ready!

Name Link
🔨 Latest commit ccf4984
🔍 Latest deploy log https://app.netlify.com/projects/hyperformula-dev-docs/deploys/6a5b98aa91e92600080683fa
😎 Deploy Preview https://deploy-preview-1678--hyperformula-dev-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread .github/workflows/build.yml Outdated
@github-actions

github-actions Bot commented May 25, 2026 •

Copy link
Copy Markdown

Performance comparison of head (cd30d48) vs base (d143456)

                                     testName |    base |    head | change
--------------------------------------------------------------------------
                                      Sheet A |  494.61 |  503.99 | +1.90%
                                      Sheet B |  160.58 |  163.81 | +2.01%
                                      Sheet T |  140.86 |  146.08 | +3.71%
                                Column ranges |  475.64 |  481.46 | +1.22%
                                Sorted lookup | 14249.2 | 14174.7 | -0.52%
Sheet A:  change value, add/remove row/column |   15.91 |   14.75 | -7.29%
 Sheet B: change value, add/remove row/column |  135.14 |   129.6 | -4.10%
                   Column ranges - add column |  153.36 |  146.34 | -4.58%
                Column ranges - without batch |  463.15 |  446.28 | -3.64%
                        Column ranges - batch |  116.42 |  114.43 | -1.71%

Bugbot review #3296952334 flagged that the `if grep ...` form treats grep's
exit code 2 (scan/IO error) identically to exit code 1 (no matches) — so a
permission or read error on dist/, commonjs/, or es/ would silently green-
light the step. Split the rc into 0/1/other and fail the step explicitly on
any non-zero, non-1 result.
Validates the build.yml marker-scan step against synthetic fixtures: clean
build, marker in dist/*.js, marker in dist/*.js.map (sourcesContent), marker
in commonjs/*.js, marker in es/*.mjs. Wired as a single self-test step in
build.yml that runs once per OS (node 22, ci install).

Empirically confirmed (probed by planting a marker in src/index.ts and
running `npm run bundle-all`) that source comments survive into:
  - commonjs/index.js and es/index.mjs (babel preserves comments)
  - dist/hyperformula{,.full}.js (webpack development build preserves comments)
  - dist/hyperformula.js.map (`sourcesContent` embeds full original source)
All three surfaces are inside the existing `grep -rn dist commonjs es` scope,
so the scan already covers source-maps. The new self-test pins this behavior
so a future bundler/comment-stripping change cannot silently erode coverage.
@marcin-kordas-hoc

Copy link
Copy Markdown
Collaborator Author

Tier-2 hardening: integration test for marker scan + source-map coverage

Added scripts/test-marker-scan.sh (5 synthetic fixture cases) and wired it into build.yml as a single self-test step (node 22, ci install, runs once per OS, <1s).

Empirical answer to the SFDIPOT P0 question — do source-maps carry source comments?

Yes. Probed by planting // [V99] test marker — empirical sourcemap probe in src/index.ts and running npm run bundle-all. The marker survived into THREE distinct surfaces:

File Hit count
dist/hyperformula.js 3
dist/hyperformula.full.js 3
dist/hyperformula.js.map 1 (inside sourcesContent)
commonjs/index.js 3
es/index.mjs 3

The existing grep -rn dist commonjs es step already catches all three because .map files are plain JSON and grep treats them as text. So the scope was already correct — but it was untested. This PR pins that coverage with a self-test that asserts each surface (clean / dist-js / dist-map-sourcesContent / commonjs / es) reaches the expected branch of the scan logic.

Also added an inline comment block in build.yml documenting the three surfaces, so future bundler/comment-stripping changes can't silently erode coverage without someone reading the rationale.

Verification (local):

  • scripts/test-marker-scan.sh — 5 passed, 0 failed
  • npm run bundle-all end-to-end — completes, publish-check OK
  • Real-build scan on clean source — rc=1 (no markers)

New head SHA: 108396574

Comment thread .github/workflows/build.yml Outdated
…test cannot drift

The verify step in build.yml previously inlined the audit-marker grep logic
while scripts/test-marker-scan.sh kept its own duplicate copy. A workflow-only
edit could silently desynchronize the live scan from the self-test fixtures
that are supposed to guard it.

Move the scan into scripts/marker-scan.sh as a single parameterized entry
point (accepts paths as $@, exit 0=clean, 1=dirty, 2+=error). The workflow
step now invokes `bash scripts/marker-scan.sh dist commonjs es`, and the
self-test drives the SAME script against synthetic fixture roots.
…es output

marker-scan grepped only the legacy [V<n>] form, so current markers ([vrf_1],
[dec_3], ...) passed the gate; it also scanned only dist/commonjs/es, missing
the typings/ and languages/ bundle outputs (both preserve source comments).
Extend the grep to the lowercase prefix+_digits grammar, add typings+languages
to the CI invocation and the self-test dir list, and add fixtures for both gaps.
Comment thread scripts/test-marker-scan.sh Outdated
@marcin-kordas-hoc
marcin-kordas-hoc requested a review from sequba June 3, 2026 02:46
@marcin-kordas-hoc

Copy link
Copy Markdown
Collaborator Author

Good flag on the [V<n>] false-positive risk. Scoping it: the scan runs only over build output (dist/, commonjs/, es/, typings/, languages/), never source — so a false positive needs a literal [V<digits>] to survive into compiled JS/.d.ts. In a spreadsheet engine that's plausible in principle (a test string, a column-label fixture, [V1]-style notation), though we emit none today.

If it ever fires spuriously, two cheap fixes: (1) tighten the pattern to a standalone token / comment-context only (^\s*//, /* … */) — real leaks come from source comments; or (2) allowlist the specific occurrence. For now I've kept the broad form (\[V[0-9]+\] + lowercase [vrf_n] + §AuditSources) since it's build-output-only and we emit none — happy to narrow to comment-context if you'd rather pre-empt it.

Comment thread .github/workflows/build.yml Outdated
marcin-kordas-hoc and others added 2 commits July 1, 2026 11:30
Per review: extend the marker scan to the documentation surfaces.
docs/guide (hand-written markdown) was previously unscanned and is a
real leak path; it is present in the checkout and now covered. docs/api
is generated by a separate docs build, so marker-scan.sh scans it only
when present (it skips any missing path).
assert_scan wrote to a hardcoded /tmp/scan-out, bypassing the
`trap 'rm -rf "$TMP_ROOT"' EXIT` cleanup and racing on a shared path.
Redirect to "$TMP_ROOT/scan-out" so it lives under the per-run mktemp
dir and is cleaned up with the rest of the fixtures.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 077dcc1. Configure here.

Comment thread scripts/test-marker-scan.sh Outdated
marcin-kordas-hoc and others added 3 commits July 16, 2026 19:47
The live CI step (build.yml) scans docs/api and docs/guide, but the
self-test's run_marker_scan() mirror loop still omitted them, so the
anti-drift adapter had itself drifted and would not catch a docs-path
regression. Add both paths to the loop and a docs/guide/*.md fixture
case that exercises the surface.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
hyperformula-docs cd30d48 Commit Preview URL

Branch Preview URL
Oct 25 2026, 01:59 AM

…l on missing paths

The monorepo move put the engine's build output under hyperformula/, so the
check in build.yml scanned paths that no longer exist and passed. docs/api is
generated only by docs:build, so build.yml never scanned it.

- script/check-citation-markers.mjs replaces scripts/marker-scan.sh and its
  self-test; `npm run check:citation-markers` is its only caller
- one step in build-docs.yml after `npm run docs:build`, which builds both the
  engine and the docs, instead of a step in each of the 18 build jobs
- a missing or empty path fails the check instead of being skipped
- the pattern is checked against marker and non-marker samples before each scan
- dev-docs/STRUCTURE.md, dev-docs/BUILD.md and script/AGENTS.md list the script

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.28%. Comparing base (d143456) to head (cd30d48).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1678   +/-   ##
========================================
  Coverage    97.28%   97.28%           
========================================
  Files          207      207           
  Lines        16218    16218           
  Branches      3556     3588   +32     
========================================
  Hits         15777    15777           
  Misses         433      433           
  Partials         8        8           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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.

2 participants