Repository navigation
chore(tests): audit suite — redundancy, gaps, and hook/CI tier alignment - #440
Merged
Merged
Conversation
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]>
Deploying with
|
| 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.claude/hooks/unit-test.mjs; registered in.claude/settings.jsonfor PostToolUse Edit/Write. Local runtime ~1.85 s.tests/COVERAGE.mdmapping every collection / global / endpoint / job to its int test.access-performance.int.spec.tsrole-based-access.COVERAGE.md..claude/rules/testing-reqs.md+AGENTS.md(theCLAUDE.mdsymlink target) name Tier 1 / Tier 2 / Tier 3 explicitly.SKILL.md+check.shrelabel the default mode as Tier 2 and--fullas Tier 3 local (minus smoke).framesByNarratorgaptests/int/frames-by-narrator.int.spec.tscovers param validation, 404, gender filter, mimeType sort, subtleSystemNode depth-1 hydration.seeds-lectures.int.spec.tsRemoved integration specs
tests/int/api-explorer.int.spec.tstests/int/app-cards.int.spec.tsapp-cardsfields; custom audience logic lives inapp-cards-for-audience.int.spec.ts.tests/int/frameFiltering.int.spec.tstests/int/subtle-system-nodes.int.spec.tscollections-smoke.tests/int/tableOfContents.int.spec.tstests/int/access-performance.int.spec.tstests/int/(nocreateTestEnvironment()); flaky wall-clock thresholds; functional coverage inrole-based-access.tests/int/seeds-lectures.int.spec.tsimportLectures), 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
framesByNarratorendpoint gap was closed in this PR with a dedicated spec.Three-tier speed contract
pnpm test:unitsrc/**/tests/unit/**pnpm lint && pnpm test:unit.claude/skills/pr-prep/check.shpnpm lint && pnpm test && pnpm test:smokeLint, Test & Smokejob on every PRAlso fixes an unrelated stale claim in
AGENTS.mdthat 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
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)Test plan
Lint, Test & Smokejob passes — full Vitest suite + Playwright smoke against CF PR previewunit-test.mjspost-Edit hook fires when editingsrc/**/*.ts(manual: edit any src file, observe no error → silent success or printed failure tail).claude/skills/pr-prep/check.sh --fullstill completes the local build path — only needed if debugging a red CI build🤖 Generated with Claude Code