4.3 KiB
4.3 KiB
Tasks — testing-msw-carve-out
This proposal is deferred until activation. Activation = the first time a React/R3F-tier package legitimately needs MSW (likely Wave 7).
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
Phase 1: Activation trigger (do nothing until then)
- 1.1 A package author files an OpenSpec sub-change requesting MSW under this carve-out, citing the concrete blocker (e.g. "Playwright E2E needs slow-body 503 response that real-server setup can't reproduce in < 50 LOC").
- 1.2 Sub-change is reviewed against the carve-out's "Allowed / Forbidden" tables in
proposal.md. If it doesn't fit, the answer is "use injection / real server" and this carve-out stays dormant.
Phase 2: Build the testing-msw package
- 2.1 Create
packages/testing/testing-msw/with standard testing-infra package shape (zero@suaveplan/*runtime deps). - 2.2 Add
mswto root catalog under a newtesting-mswgroup key. - 2.3 Author
createMswServer(handlers, options?)— wrapssetupServerwith injectableClockandAbortSignalintegration. - 2.4 Author
createMswWorker(handlers, options?)— browser-tier equivalent for Storybook + Playwright. - 2.5 Author
expectRequest(server, predicate, opts?)— async wait-for-match helper with timeout + abort. - 2.6 Author
requestRecorder()— ordered-assertion harness. - 2.7 Author
runMswConformance(label, makeFactory)— shared conformance harness exposed under the./testingsubpath (mirrorsi18n-shared/testingpattern). - 2.8 100/100/100/100 coverage on the testing-msw surface itself.
Phase 3: Codify the rule
- 3.1 Add §1 #2a "MSW carve-out" to
CLAUDE.md, exact text fromproposal.md. - 3.2 Author
openspec/specs/testing/spec.md(or extend existing testing spec) with## ADDED Requirementscapturing:- MSW MAY be used only through
@suaveplan/testing-msw. - Tier restriction (React/R3F only).
- Conformance-test requirement.
- Handler co-location requirement.
- MSW MAY be used only through
- 3.3 Update
openspec/AGENTS.mdif any §0a parity checklist row would conflict.
Phase 4: Ship the first consumer
- 4.1 The triggering package (likely
react-network-libp2p-demoorr3f-networking) consumes@suaveplan/testing-mswfor its first MSW-backed test. - 4.2 That same package ships at least one Playwright E2E against a real protocol implementation (the conformance requirement).
- 4.3 Both tests demonstrably exercise the same component code path.
Phase 5: Verification
- 5.1
bunx turbo lint typecheck test:coverage --filter=@suaveplan/testing-mswgreen at 100/100/100/100. - 5.2 First consumer's tests green.
- 5.3
bun run docs:checkgreen on testing-msw. - 5.4
STATUS.mdrow added for@suaveplan/testing-msw(status❌-net-new →✅). - 5.5
CLAUDE.mdandopenspec/specs/testing/spec.mdreflect the new rule.
Pre-archive checklist
- Row 1 — Phase 5 green.
- Row 2 — A real consumer is using the carve-out (no theoretical adoption).
- Row 3 — Conformance-test requirement demonstrably enforced on the first consumer.
- Row 4 — Folder moved to
openspec/archive/<yyyy-mm-dd>-testing-msw-carve-out/.
Anti-tasks (DO NOT do)
- DO NOT add MSW to any universal-tier or server-tier package's test suite.
- DO NOT use MSW to work around an injectable-
fetchFndesign. If the package can be made injectable, do that instead. - DO NOT use MSW in production code paths.
- DO NOT re-introduce
vi.mock/jest.mockunder the cover of "but MSW is fine now". The two are different layers and the second remains banned. - DO NOT centralise MSW handlers in a top-level
mocks/directory. Handlers co-locate with tests.