Skip to content

test: executable invariant guards + JSON-LD golden snapshot#638

Merged
BreakableHoodie merged 1 commit into
mainfrom
chore/invariant-tests
Jul 18, 2026
Merged

test: executable invariant guards + JSON-LD golden snapshot#638
BreakableHoodie merged 1 commit into
mainfrom
chore/invariant-tests

Conversation

@BreakableHoodie

Copy link
Copy Markdown
Owner

Summary

Pilot of the "AGENTS.md, but executable" idea: three of the repo's prod-breaking invariants are currently guarded only by prose (CLAUDE.md) + the agent pre-PR hook — both catch new violations in a diff, but neither is a deterministic regression guard. This adds cheap, permanent tests for them. Additive only — zero production code changed (verified: git diff against tracked files is empty; all four files are new).

What's guarded

Test Invariant Bug class it prevents
frontend/src/utils/__tests__/invariants.test.js AFTER_MIDNIGHT_THRESHOLD_HOUR === 6, derived MINUTES stays consistent, bandUtils.js imports the constant (not a re-encoded 6) #550 after-midnight sort
functions/utils/__tests__/invariants.test.js toSqliteDateTime() output is space-separated, no T/Z/ms SEC-F1 invite-expiry bypass (the T-separator string-compare failure)
functions/event/__tests__/slug.jsonld-golden.test.js (+ .snap) The full /event/[slug] MusicEvent + BreadcrumbList JSON-LD shape SEO regression in crawler-facing structured data

The golden snapshot is the headline. That JSON-LD block churned across #615, #616, and the held #634 in a single week, and Vera hand-caught a missing Google-required location field. The snapshot locks the exact rendered shape (deterministic: created_at pinned so offers.validFrom is reproducible; bands seeded out of sort order to prove the article-strip re-sort governs performer). Any future edit to that block now surfaces as a reviewable snapshot diff — intentional changes land via vitest -u + review, never blind.

Notes from the build

  • Real drift found, not fixed: toSqliteDateTime() isn't exported, so the test reaches it through the real checkAuthRateLimit binding path rather than reimplementing it. Faithful, but a direct unit test would be cleaner — filed as chore: export toSqliteDateTime() for direct unit testing #637 (export it).
  • A jsdom new URL(relative, import.meta.url) gotcha in the frontend test is worked around with fileURLToPath + node:path, documented inline for the next person.

Security / correctness notes

None — test-only, additive. The snapshot reflects current main (no subEvent yet; when #634 merges, its snapshot update is the intentional, reviewed diff).

Verification

  • Tests: backend 797 pass | 6 todo (78 files, +2), frontend 564 pass (54 files, +3)
  • ESLint: 0 errors both stacks · Format check: clean both stacks
  • Snapshot .snap committed, not gitignored; determinism verified across reruns
  • git diff on pre-existing tracked files is empty (additive-only proof)

Built by Sonny · Reviewed by Theo · 🤖 Claude Code

Turns three of the repo's prose-and-agent-guarded invariants into
deterministic regression tests (additive only, zero production code
touched):

- frontend after-midnight threshold: AFTER_MIDNIGHT_THRESHOLD_HOUR
  === 6, the derived MINUTES constant stays consistent, and
  bandUtils.js still imports the constant rather than re-encoding 6
  (#550 bug class).
- SQLite datetime format: toSqliteDateTime()'s output is space-
  separated with no T/Z/ms — the exact shape whose T-separator caused
  the SEC-F1 invite-expiry bypass. Tested through the real
  checkAuthRateLimit path since the helper isn't exported.
- JSON-LD golden snapshot of /event/[slug]: a pinned, deterministic
  event (fixed created_at so offers.validFrom is reproducible) locks
  the crawler-facing MusicEvent + BreadcrumbList shape. Any future
  edit to that block — which churned across #615/#616/#634 this week —
  now surfaces as a reviewable snapshot diff; the location field Vera
  hand-caught can no longer silently regress. Intentional changes land
  via `vitest -u` + snapshot review, never blind.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@BreakableHoodie BreakableHoodie added priority:p3 Lower priority chore Maintenance, tooling, repo hygiene labels Jul 18, 2026
Copilot AI review requested due to automatic review settings July 18, 2026 18:31
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@BreakableHoodie
BreakableHoodie merged commit 9394461 into main Jul 18, 2026
22 checks passed
@BreakableHoodie
BreakableHoodie deleted the chore/invariant-tests branch July 18, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, tooling, repo hygiene priority:p3 Lower priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants