Skip to content

chore(build): add audit gate, size budget, and embed smoke tests - #110

Merged
Ardnived merged 9 commits into
mainfrom
chore/ci-audit-size-smoke
Aug 7, 2026
Merged

Ardnived merged 9 commits into
mainfrom
chore/ci-audit-size-smoke

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #99.

CI gated lint + typecheck + tests + build, and three real regressions accumulated behind that green check anyway: no dependency scan (64 advisories, 1 critical), no size budget (the eager payload reached ~477 KiB gz), and a smoke lane that never touched embed.js and could silently no-op. This adds the three missing gates, plus the accent workflows' runtime bump.

The theme throughout is that a passing check has to mean something. Two of the gates I wrote initially did not, and the review caught both — see "Gates that didn't check anything" below.

What landed

Gate Where Fails when
Size budget pnpm size in the gate job, after pnpm build The eager payload is over budget — or far under it
Dependency audit new Dependency Audit job (pnpm audit:check) A high/critical advisory isn't in scripts/audit-baseline.json
Weekly audit new .github/workflows/audit.yml (--strict) Same, plus stale baseline entries and an audit that can't run
Embed smoke tests/smoke/embed.smoke.test.ts embed.js is missing, isn't the widget, or references chunks the deploy doesn't serve
Loud smoke skip ci.yml No preview on a same-repo PR (forks still skip gracefully)

The size budget measures graphs, not chunks

Per-chunk numbers are meaningless here — the build re-chunks freely, so a chunk can shrink while the payload a visitor downloads is unchanged. It scores two eager graphs, gzipped: the standalone shell's entry + modulepreload closure, and embed.js's static import graph (walked, because the embed entry emits zero preload hints — a check reading only index.html would never see the product's cost).

Measured today: standalone 479.5 KiB, embed 480.4 KiB. Budget: 495 KiB each — one easily-edited constant, ~3% headroom.

#96 should ratchet this down. Lazy-loading the calendar/registration/share drawers is expected to take 150–250 KiB off both numbers. The budget fails when a graph runs >15% under, so that PR must lower BUDGET_KIB in the same commit — the ratchet is enforced, not requested in a comment.

Audit gate: hard, but scoped to what's new

The tradeoff, documented in ci.yml beside the job. A plain --audit-level high is red on day one (1 critical + 24 high are already in the lockfile) and would block every unrelated PR until #101/#104 land; a purely scheduled report can't stop a regression and is exactly the check that goes unread — which is how 64 advisories accumulated.

So known findings are pinned in scripts/audit-baseline.json, each naming the ticket that owns it, and the gate fails on anything not pinned. Green today, red the day a new one appears. Waiving costs a reviewable line, not a silent pass.

The softer states stay out of the PR gate so no PR is blocked by something it didn't cause — a fixed-but-unpruned entry, or an audit that couldn't run. audit.yml --strict enforces those weekly, where a failure interrupts nobody.

Gates that didn't check anything

Both found in review, both now covered by a reproduction:

  • The chunk check could not fail. public/_redirects is /* /index.html 200, so Cloudflare returns 200 text/html for any path that isn't a built asset — verified live: a made-up chunk name returns 200. A status assertion passed for precisely the missing-chunk deploy it was written to catch. Now content-type checked.
  • The size budget only caught a total walker failure. Half-break the regex and the graph shrinks, the total collapses, and it reports a comfortable pass on a payload it never measured. Simulated: the embed graph scoring 2.1 KiB now exits 1.

Also fixed: a memoized rejection made all three of vitest's smoke retries re-await the same failure instantly, and pick() in the preview discovery matched the project by substring with no comment-author filter — so evil-sahajatlas.pages.dev qualified, and on a public repo anyone who can comment could aim the smoke lane at a host they control. That mattered more once this PR made a missing preview hard-fail. Now a hostname match at a label boundary, bot authors only.

Accent workflows — version lines only

checkout@v3→v4, setup-node@v3→v4, node-version: 16→22. Six lines across two files, no logic touched, per CLAUDE.md and the ticket's AC.

⚠️ Follow-up worth a ticket, deliberately not done here. push-accent.yml declares no permissions: block, so it inherits the repo's write default, and runs an unpinned npm install -g accent-cli with ACCENT_API_KEY. Its last five runs all failed (accent-cli needs Node ≥ 18), so this bump revives it — turning a dormant exposure into a live one on a repo whose main auto-deploys to host pages. Fixing it means adding permissions: and pinning the CLI, which the AC here explicitly forbids. Recommend a follow-up before the next accent run.

Verification

  • pnpm lint, pnpm typecheck, pnpm test:run (577) — green
  • .claude/skills/pr-prep/check.sh --full — green, including the new size step
  • pnpm size → exit 0; simulated half-broken walker → exit 1 with the diagnostic
  • pnpm audit:check → exit 0 (0 new, 0 stale); dropping the swiper entry → exit 1; adding a fake entry under --strict → exit 1
  • pnpm test:smoke with no PREVIEW_URL → 4 skipped, no network
  • PREVIEW_URL=https://sahajatlas.pages.dev pnpm test:smoke → 4 passed against a real deploy
  • Swiper reachability re-verified by hand for the baseline note: it does ship in the eager payload (EventRegister, a static import of App), and is unreachable only because every Swiper param in ImageCarousel.tsx is a literal

Not verifiable until this runs on a PR: the loud-skip path and the annotations, which need real Actions context.

Known gaps, recorded rather than hidden

  • Audit scope is --prod, matching the readiness report. A full audit reports 8 further high advisories, all in the build toolchain — noted in audit.yml with what widening it would take.
  • GitHub disables scheduled workflows after 60 days of repo inactivity; noted in audit.yml.
  • Stretch axe-core pass: skipped as optional.

Readiness-report findings resolved

§3.6 / blocker #3 (no dependency scan), §1.1 + §1.6 item 6 (no size budget; embed's invisible graph), §4 + Appendix D (smoke lane never tests the embed; can self-skip; accent workflows on EOL Node 16).

🤖 Generated with Claude Code

Ardnived and others added 8 commits August 6, 2026 18:16
The embed grew to ~477 KiB gzipped before anyone noticed, because nothing
measured it. A per-chunk check would not have caught it either: this build
re-chunks freely, so a chunk can shrink while the payload a visitor
downloads is unchanged.

So the script scores the two eager GRAPHS instead — the standalone shell's
entry plus its modulepreload closure, and embed.js's static import graph,
walked here because the embed entry emits no preload hints at all. The
embed is the product a host installs, and a check that only read
index.html would never see its cost.

Budgets sit ~3% above today's 479.5 / 480.4 KiB: enough that a patch bump
doesn't red an unrelated PR, tight enough that a newly-eager view does.
They are one constant, meant to be ratcheted down as #96 lands.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Nothing in CI had ever run an audit, so the lockfile reached 64 advisories
— 1 critical, 24 high — with every gate green the whole way.

A plain `--audit-level high` cannot fix that from a standing start: it is
red on day one and blocks every unrelated PR until the dependency tickets
land, or it is loosened until it no longer catches anything. Neither is a
gate. So today's findings are pinned in audit-baseline.json, each named
with the ticket that owns it, and the check fails on a high/critical
advisory that ISN'T pinned — green today, red the day a new one appears.
Waiving one costs a reviewable line rather than a silent pass.

Two softer states stay out of the PR gate, so a PR is never blocked by
something it didn't cause: a baselined advisory since fixed but not
pruned, and an audit that couldn't run at all. Both still matter — an
unpruned baseline decays into a blanket allowlist, and a broken audit is a
green check that checks nothing — so the weekly workflow enforces them
with --strict, where a failure interrupts nobody.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Both existing specs fetch the standalone page. The product is the
`<sahaj-atlas>` element in embed.js, and nothing exercised it — a deploy
that broke the embed while leaving index.html healthy shipped past a green
Smoke check.

Asserting `customElements.define` and the tag name together, rather than a
bare 200, is what distinguishes the real bundle from an SPA-fallback HTML
page served with a 200.

The second spec walks embed.js's imports and asserts each chunk resolves.
embed.js is unhashed and mutable while its chunks are hashed, so a stale
copy can request names the CDN no longer serves — a hard 404 with no
fallback, and the widget never appears. This catches the deploy-side half
of that skew.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…loud

The size budget runs after the build; the audit runs as its own job so a
dependency finding doesn't read as "Lint, Typecheck & Build" failing, and
skips the install because `pnpm audit` resolves from the lockfile alone.
The hard-gate-vs-scheduled tradeoff is written down beside the job.

The smoke job's no-preview path was the quiet one: discovery exits 0 with
an empty URL and the specs skip themselves, so a green "Smoke" check could
equally mean nothing ran. Now green implies the specs executed. A same-repo
PR has the secrets and the Cloudflare integration, so a missing preview is
a failed deploy and fails the job; forks keep the graceful skip, annotated
rather than silent.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
checkout@v3 and setup-node@v3 run on a Node 16 runtime GitHub has
deprecated, and the jobs themselves ask for node-version 16.

Version lines only — six of them. CLAUDE.md says to leave these workflows
alone unless the task is about them, and this task is exactly and only
their runtime, so the accent-cli invocations, triggers and PR settings are
untouched.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Both new gates were writing the step summary and emitting annotations with
their own copy of the same two functions, and had already drifted — the
audit gate annotated on failure, the size gate only wrote to stderr, so one
breach was visible on the run and the other only by unfolding the log. One
`_ci-output.mjs` now owns both, and the size gate annotates.

Also from the pass: dropped the never-invoked `--print` mode; collapsed the
three-times-computed budget delta into one `spare`; replaced four
singular/plural branches (one of which had already given up and printed
"entr(y/ies)") with plain counts; and made both workflows call the same
`pnpm audit:check` alias rather than one going through package.json and the
other straight to node.

Two guards the pass argued for, both against the same failure: a gate that
passes because it measured nothing. The import walker is a regex over
minified output, so it now fails when a graph comes back with fewer than two
chunks instead of scoring a 2 KiB payload as comfortably under budget; and a
graph running >10% under budget says so, since a budget far above the real
payload is the green-check-that-checks-nothing this script exists to prevent.

The smoke spec fetches embed.js once instead of per test, and HEADs the
chunks rather than pulling ~440 KiB of bodies to read status codes — it also
now checks every relative .js reference, not only static-import shapes,
because a lazy chunk 404ing is the same broken deploy one interaction later.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Both reviews found the same class of defect this ticket was written to
remove, in the new gates themselves.

The chunk-existence assertion could not fail. `public/_redirects` is
`/* /index.html 200`, so Cloudflare serves the SPA shell with a 200 for any
path that isn't a built asset — verified against the live deploy, where a
made-up chunk name returns 200 text/html. A status check therefore passed
for exactly the missing-chunk deploy it was written to catch. It now
requires a JavaScript content type.

The size budget only caught a TOTAL walker failure. Half-breaking it — one
import shape stops matching — shrinks the graph, collapses the total, and
reports a comfortable pass on a payload it never measured; the embed graph
is the exposed one, since standalone is cross-checked against the HTML's
preload list. Running far UNDER budget is now a failure rather than a
notice, which also makes the ratchet machine-enforced instead of a comment
asking to be read. Simulated: the embed graph scoring 2.1 KiB now exits 1.

Also: a rejected or non-200 embed fetch is no longer memoized, because
caching it made all three of vitest's retries re-await the same failure
instantly — defeating the retry the memo was meant to economise on.

And the preview-URL discovery, which this PR turns into a signal CI hard-
fails on: `pick()` matched the project by substring, so
`evil-sahajatlas.pages.dev` qualified, and comment scanning had no author
filter. On a public repo that let anyone who can comment aim the smoke lane
at a host they control. Now a hostname match at a label boundary, bot
authors only.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
CLAUDE.md and .claude/rules/tests.md described a CI gate that no longer
matches, and pr-prep's `--full` claimed to mirror CI while omitting the one
new step that needs a build — so the local gate could go green on exactly
the change (a new eager import) the budget exists to catch. `--full` now
runs `pnpm size` after the build.

The tests rule also gains the two smoke-lane invariants, since both were
learned by getting them wrong here: a green Smoke check must mean the specs
ran, and a 200 proves nothing when `_redirects` serves the SPA shell for
every unmatched path.

Refs #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: a91cd2b
Status: ✅  Deploy successful!
Preview URL: https://f883ffcf.sahajatlas-design.pages.dev
Branch Preview URL: https://chore-ci-audit-size-smoke.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: a91cd2b
Status: ✅  Deploy successful!
Preview URL: https://e0ca79f4.sahajatlas.pages.dev
Branch Preview URL: https://chore-ci-audit-size-smoke.sahajatlas.pages.dev

View logs

Every run since 2026-06-22 failed on EOL Node 16, so the Accent sync was
already dead. Bumping it to Node 22 would have re-armed a push-to-main job
that inherits repo write access and runs an unpinned global install with
ACCENT_API_KEY in scope — reviving unwatched automation to no benefit.

Removed rather than upgraded, on the owner's call: the workflows are
outdated and no longer in use. accent.json is left in place; it is now
orphaned config and can go in a follow-up.

Closes #99

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit c2e6e70 into main Aug 7, 2026
5 checks passed
@Ardnived
Ardnived deleted the chore/ci-audit-size-smoke branch August 7, 2026 04:04
Ardnived added a commit that referenced this pull request Aug 7, 2026
Two conflicts, both keep-both:

- CLAUDE.md — this branch rewrote the Routing row for the two-router mount,
  main rewrote Build tool + Data in the same table. Kept all three.
- src/Widget.tsx — this branch restructured the wrapper (lang, role, the
  hash/memory branch), #113 added WIDGET_SCOPE_CLASS to its className.
  Kept the restructure and carried the scope class onto it: without that
  class the embed renders entirely unstyled.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

chore(build): add audit gate, size budget, and embed smoke tests

1 participant