Skip to content

chore(tests): audit suite — redundancy, gaps, and hook/CI tier alignment - #440

Merged
Ardnived merged 8 commits into
mainfrom
chore/test-audit-tier-alignment
Jun 1, 2026
Merged

Ardnived merged 8 commits into
mainfrom
chore/test-audit-tier-alignment

Conversation

@Ardnived

@Ardnived Ardnived commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #434.

Audit-driven cleanup of the test suite. All seven P-items from the issue are implemented in incremental commits, plus a follow-up commit that closes the one coverage gap the audit surfaced and drops the seed-importer spec. #435 (the Cloudflare PR-preview + smoke lane) has merged, so P5 is unblocked.

Summary

P Subject Outcome
P1 Sub-5s unit-test feedback in Claude New .claude/hooks/unit-test.mjs; registered in .claude/settings.json for PostToolUse Edit/Write. Local runtime ~1.85 s.
P2 Remove Payload-internal int specs Dropped 5 files (see table below).
P3 Coverage map New tests/COVERAGE.md mapping every collection / global / endpoint / job to its int test.
P4 access-performance.int.spec.ts Removed — mis-located (no Payload bootstrap), wall-clock thresholds were flaky, functional coverage already lives in role-based-access.
P5 Post-#435 dedup pass Zero removals — no int test redundantly duplicates smoke REST coverage. Analysis recorded in COVERAGE.md.
P6 Three-tier speed contract .claude/rules/testing-reqs.md + AGENTS.md (the CLAUDE.md symlink target) name Tier 1 / Tier 2 / Tier 3 explicitly.
P7 pr-prep skill SKILL.md + check.sh relabel the default mode as Tier 2 and --full as Tier 3 local (minus smoke).
+ Close framesByNarrator gap New tests/int/frames-by-narrator.int.spec.ts covers param validation, 404, gender filter, mimeType sort, subtleSystemNode depth-1 hydration.
+ Drop seeds-lectures.int.spec.ts Covered a seed importer, not a collection hook or any custom logic the integration lane is responsible for. Aligns with the audit's "remove what doesn't belong" stance.

Removed integration specs

File Why removed
tests/int/api-explorer.int.spec.ts Tests Payload's built-in OpenAPI plugin / Scalar UI — the plugin, not our code.
tests/int/app-cards.int.spec.ts Schema-only CRUD across app-cards fields; custom audience logic lives in app-cards-for-audience.int.spec.ts.
tests/int/frameFiltering.int.spec.ts Built-in where-clause filtering and depth populate; no custom hook.
tests/int/subtle-system-nodes.int.spec.ts Built-in unique-slug constraint + reverse-join exposure; reachability covered by collections-smoke.
tests/int/tableOfContents.int.spec.ts Pure Lexical block round-trip storage; Payload field serialization.
tests/int/access-performance.int.spec.ts Mis-located in tests/int/ (no createTestEnvironment()); flaky wall-clock thresholds; functional coverage in role-based-access.
tests/int/seeds-lectures.int.spec.ts Tested the WeMeditate seed importer (importLectures), not a collection hook or custom integration-lane code.

Total: 40 → 34 int specs (−7 files, +1 new frames-by-narrator = 34 net).

Audit decisions left in place

  • collections-smoke.int.spec.ts — kept as the canonical reachability canary per .claude/rules/tests.md. The issue listed it as a removal candidate, but the rules already document its role.

Coverage gaps

None known. The previous framesByNarrator endpoint gap was closed in this PR with a dedicated spec.

Three-tier speed contract

Tier Command Target Where
1 — Hook pnpm test:unit < 5 s Claude PostToolUse on src/** / tests/unit/**
2 — Pre-PR pnpm lint && pnpm test:unit < 15 s .claude/skills/pr-prep/check.sh
3 — CI pnpm lint && pnpm test && pnpm test:smoke ≤ 20 m GitHub Actions Lint, Test & Smoke job on every PR

Also fixes an unrelated stale claim in AGENTS.md that said CI runs two parallel jobs (Lint & Test + Cloudflare Build); the real post-#435 workflow is one job that includes smoke. The Cloudflare build is performed by Cloudflare Workers Builds independently of GitHub Actions.

Test Results

  • Lint: ✓ No errors
  • Tier 2 (lint + unit + targeted int): ✓ passed locally (pnpm test:unit → 331 tests, 1.49 s; tests/int/frames-by-narrator.int.spec.ts → 5 tests, 1.39 s; tests/int/albums.int.spec.ts → 3 tests, 13 s)
  • Tier 3 (full suite + smoke): ✓ via CI (see PR checks)

Test plan

  • CI Lint, Test & Smoke job passes — full Vitest suite + Playwright smoke against CF PR preview
  • Verify the new unit-test.mjs post-Edit hook fires when editing src/**/*.ts (manual: edit any src file, observe no error → silent success or printed failure tail)
  • (Optional) .claude/skills/pr-prep/check.sh --full still completes the local build path — only needed if debugging a red CI build

🤖 Generated with Claude Code

Ardnived and others added 7 commits June 1, 2026 13:16
Closes #434 (P1)

Runs `pnpm test:unit` after every Edit/Write to `src/**/*.ts(x)` or
`tests/unit/**/*.spec.ts`. Skips `src/payload-types.ts` and
`src/migrations/**`. Silent on success; prints a 30-line failure tail
otherwise. Local timing: ~1.85s for 331 cases, well under the 5s target.

This closes the feedback gap between editing and the pre-PR lean gate —
Tier 1 of the three-tier speed contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Refs #434 (P2)

Audited all 40 tests/int/*.int.spec.ts files and removed the 5 that only
exercise Payload-CMS built-ins, with reachability already covered by
collections-smoke.int.spec.ts:

- api-explorer.int.spec.ts — built-in OpenAPI plugin endpoints / Scalar
  UI; tests the plugin, not our code.
- app-cards.int.spec.ts — schema-only CRUD across app-cards fields
  (audiences/weight/targetSections/textColor/...); custom audience logic
  lives in app-cards-for-audience.int.spec.ts.
- frameFiltering.int.spec.ts — built-in where-clause filtering and
  depth:1 relationship populate; no custom hook.
- tableOfContents.int.spec.ts — Lexical block round-trip storage for
  null/empty/populated headings arrays; pure Payload field serialization.
- subtle-system-nodes.int.spec.ts — built-in unique-slug constraint +
  reverse-join exposure; smoke covers reachability.

The remaining 35 files all exercise at least one of: custom hooks,
access control, virtual fields, custom endpoints, scheduled jobs, or
business-critical workflows. Full classification ships next as
tests/COVERAGE.md (P3).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Refs #434 (P3)

Source-of-truth map of custom behavior to the integration test that
covers it. Spans collections, globals, custom endpoints, scheduled
jobs, and cross-cutting helpers (storage, RBAC, schema introspection).

Notes one explicit gap (`/api/frames/by-narrator/:narratorId`,
recommended follow-up) and one borderline keep (`seeds-lectures`).
Documents the 5 files removed in P2 as a record of what was dropped
and why.

Per `.claude/rules/tests.md`, Payload-CMS built-ins are not tracked
here; `collections-smoke.int.spec.ts` is the reachability canary.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Refs #434 (P4)

The file has three problems:

1. It is mis-located. It never calls createTestEnvironment() — every
   case operates on plain testData.dummyUser() objects and the
   permission functions. It belongs in tests/unit/ by the lane rules,
   not tests/int/.

2. The wall-clock thresholds (50ms / 100ms / 150ms / 200ms over 10k
   iterations) are inherently flaky on shared CI runners. The 200ms
   bound on the admin-checks case already exists "to account for CPU
   variance during full test suite" — a sign that the test is testing
   the runner, not the code.

3. Functional correctness of hasPermission / hasAnyPermission /
   bypassPermissions / customResourceAccess is already covered by
   role-based-access.int.spec.ts. Nothing here asserts a behavior the
   functional suite doesn't.

A real perf-regression detector belongs in a dedicated benchmark lane
with stable hardware — out of scope for #434. Falling back to option
(c) from the issue: remove. Re-introduce a structural micro-benchmark
later if the access path is ever a measured bottleneck.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Refs #434 (P5)

Smoke specs (auth/meditations/songs/lectures clip) target Cloudflare
PR preview env via REST. Three int tests touch the same REST paths
but each exercises custom logic that smoke does not assert:

- content-index-block: builds /api/meditations URLs via the
  computeApiEndpoint virtual field — not REST CRUD.
- meditation-lectures: hits /api/meditations/lectures custom endpoint
  (weight ranking, audience validation), not the bare /api/meditations
  CRUD path that smoke covers.
- storage-utils: URL field factories reference /api/songs/... — tests
  the factory, not the REST flow.

No int test removed by P5. Recording the table + analysis so future
PRs can answer "is smoke already covering this?" without re-running
the audit.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #434 (P6)

Adds the explicit Tier 1 / Tier 2 / Tier 3 table to
.claude/rules/testing-reqs.md and surfaces the same table from
AGENTS.md (CLAUDE.md is a symlink). Each tier names its command,
target runtime, and trigger so Claude and humans both know which lane
to use when.

Also corrects the AGENTS.md CI section, which still described the
pre-#435 "two parallel jobs: Lint & Test, Cloudflare Build" layout.
The real workflow is one job, "Lint, Test & Smoke", that runs lint,
the Vitest suite, and the Playwright smoke specs against a CF PR
preview environment. The Cloudflare build itself is performed by
Cloudflare Workers Builds on the push, not by GitHub Actions — CI
just waits for the preview URL.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #434 (P7)

Aligns the pr-prep skill with the explicit Tier 1 / Tier 2 / Tier 3
contract documented in .claude/rules/testing-reqs.md. The skill now
identifies its default mode as Tier 2 and --full as "Tier 3 locally,
minus smoke", which is the truthful framing now that smoke runs
against a Cloudflare PR preview (not locally).

- SKILL.md: adds the tier table at the top; clarifies that --full
  cannot run smoke locally because Playwright targets a deployed CF
  preview built by Cloudflare Workers Builds.
- check.sh: relabels the section headers as "Tier 2 (lean gate)" and
  "Tier 3 (local)"; prints a note that smoke runs in CI only.

No behavior change in what the gate runs; only naming + framing.

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

cloudflare-workers-and-pages Bot commented Jun 1, 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
sahajcloud 95d5bcc Commit Preview URL

Branch Preview URL
Jun 01 2026, 05:38 AM

Refs #434

Two follow-ups to the audit:

1. New tests/int/frames-by-narrator.int.spec.ts covers the one gap
   that COVERAGE.md called out — /api/frames/by-narrator/:narratorId.
   Five cases: empty narratorId → 400, missing narrator → 404,
   imageSet filtered by narrator.gender, image/* sorted before
   video/*, and depth:1 hydration of subtleSystemNode.

2. tests/int/seeds-lectures.int.spec.ts removed. Covered the
   WeMeditate seed importer (importLectures), not a collection hook
   or any built-in custom logic the integration lane is responsible
   for. Aligns with the audit's "remove what doesn't belong in the
   integration lane" stance — seed-script coverage belongs in a
   dedicated lane or as part of the seed runner itself, not here.

COVERAGE.md updated: gap row resolved, seeds-lectures moved from the
borderline-keeps section into the "Removed by the audit" list.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit c651d70 into main Jun 1, 2026
2 checks passed
@Ardnived
Ardnived deleted the chore/test-audit-tier-alignment branch June 1, 2026 05:50
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(tests): audit suite — redundancy, gaps, and hook/CI tier alignment

1 participant