Repository navigation
test(web): run page tests on the real app router - #343
Closed
BenSheridanEdwards wants to merge 3 commits into
Closed
BenSheridanEdwards wants to merge 3 commits into
BenSheridanEdwards wants to merge 3 commits into
Conversation
BenSheridanEdwards
force-pushed
the
test/page-tests-real-router
branch
from
November 8, 2026 23:40
295668b to
7ccbc30
Compare
createTodoUseCases() makes a new in-memory store and returns the use cases over it; createTodosRouter() and createAppRouter() build routers the same way. The server still builds appRouter once, so behaviour is unchanged, and a page test for issue 339 can now build an app router with an empty list of its own. Application tests call the factory instead of resetting modules, and a router test proves two app routers keep separate lists. The api reports gain createAppRouter and createTodosRouter.
TestApiProvider now serves a new app router per render, in memory through tRPC's local link, so a page test runs the feature's real procedures, application and domain code. seed adds data through the router before the page's first call is answered. A handler still answers its procedure: it can fail, hold or record a call, and its serve(input) passes the call on to the router. Web code imports the api by type only, so the web Jest project's setup, tooling/jest/serve-app-router.ts, hands the router factory of the result under test to that result's api client. No boundary, contract rule or bundle changes. The to-do page tests drop their 40-line fake api. They seed through the router and keep failure injection, the held list and setDone calls, and the recorded add, list, rename and clearDone calls.
The write-unit-tests skill (both copies), the component test template, ARCHITECTURE.md and TECH_STACK.md now say that TestApiProvider runs the real app router: seed data through it, write no fake api, and give a handler only to fail, hold or record one call. ARCHITECTURE.md names createTodoUseCases, createTodosRouter and createAppRouter in the api file roles and explains how the Jest setup hands the router over.
BenSheridanEdwards
force-pushed
the
test/page-tests-real-router
branch
from
November 9, 2026 00:15
7ccbc30 to
4ea68a9
Compare
This was referenced Nov 10, 2026
Owner
Author
|
Closing as superseded, per Ben's decision on 12 Nov 2026 ("Yes, restart from main and close both"). It was stacked on #335, which is also closed. The same change, page tests on the real app router (closes #339), will be re-cut from main in phase B as "test(web): run page tests on the real app router", once the to-do api is on main. The decision record is ADR 0123 in #359. This branch is kept as the source. |
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.
Why does this feature exist?
TodosPage.test.tsxcarried a 30 to 40 line in-memory api that re-codedreplace,filterandclearDone(SLOP finding R2), and in two the fake invented a blank to-do for a missing id (B2). The reference did the same. Those tests checked the fake, not the feature: a broken procedure, use case or domain rule could still pass them.Stacked PR: this is based on
feat/todo-example-app(#335) and merges after #335. Its diff is against #335's headf2ff9e6, which includes main (#340) and the final-check fixes (theaddTododouble-add guard, the filter-colour and re-read E2E tests, trial ports).Closes #339
What changed?
This is one idea above 400 lines: making
TestApiProviderrun the real router needs the api to build a router per test, the provider and its handlers to serve it, the page tests to drop their fake, and the guidance to say so; none of them works without the others.0b9e75d):createTodoUseCases()makes a new in-memory store and returns the use cases over it;createTodosRouter()andcreateAppRouter()build routers the same way. The server still buildsappRouteronce, so api behaviour is unchanged. Application tests call the factory instead ofjest.resetModules, and a new router test proves two app routers keep separate lists. Public API change:apps/api/etc/api.api.mdgainscreateAppRouter;features-todos.api.mdexportscreateTodosRouterin place oftodosRouter. The api-client export names are unchanged.TestApiProviderserves the real app router (a66b596): each render gets a new app router over empty stores, run in memory through tRPC'sunstable_localLink, so a page test runs the real procedures, input schemas, application and domain code, and outputs cross a JSON round trip as they would over HTTP.seedadds data through the router before the page's first call is answered. A handler inhandlersstill answers its procedure, so failure injection stays: it can fail, hold or record one call, and its new second argumentserve(input)passes the call on to the router.@repo/apiexport,contract/*), and route tests may import only their folder,@repo/uiand the api-client barrel. So the web Jest project gains one setup file,tooling/jest/serve-app-router.ts, which finds the result under test and hands itscreateAppRouterto that result's api client (serveAppRouterInTestsinapps/web/src/api-client/testAppRouter.ts). Tooling sits outside the role table. No boundary, contract rule, route co-location rule, budget or guarded file changes; the branch adds no web production code, and size-limit read 108.69 kB before and after ona26be0c.Todointerface (P3). They seed through the router and keep every failure case (todos.list,add,setDone,rename,delete,clearDonefailing), the held list and heldsetDone, and recordedadd,list,renameandclearDonecalls, now passed through to the router. Same test declarations as the base (11).4ea68a9): thewrite-unit-testsskill (.agentsand.claudecopies identical, viapnpm skills:sync),.agents/templates/component.test.tsx.template,ARCHITECTURE.md(api file roles, mounting, how page tests reach the router) andTECH_STACK.mdpoint to the router-backed provider and say to write no fake api.jest.config.tsadds the setup file to thewebproject only;tsconfig.node.jsontypechecks it.Behavioural Proof (with video and screenshots)
apps/web/src/api-client/TestApiProvider.test.tsx(real router answers, seed first, a new empty router per render, a handler passing a call on, a failed seed failing each call),testApiHandlers.test.ts,testAppRouter.test.ts(fresh router per call; names the Jest setup when none is served),apps/api/src/router.test.tsandapplication.test.ts(separate lists), and the rewrittenapps/web/src/routes/todos/TodosPage.test.tsx. Each new test failed first (api: 9 failed before the factories existed; api-client: 4 provider tests and 2 suites failed before the router-backed provider).todos.spec.ts, pass in the pre-push hook at4ea68a9.Verification Summary
a3c434dcf47d2373db530d3e206bd6a15e8b76ebpnpm verify,pnpm e2e):pnpm install --frozen-lockfile,pnpm test:coverageon the base and on this branch,pnpm lint:anti-slop, the real pre-commit hook on each commit, and the real pre-push hook (pnpm verifythenpnpm e2e) on the push of4ea68a9, withPACT_DIRin a private scratch folder.4ea68a9:pnpm verifypassed (81 suites, 3118 Jest tests, contract, integration, changed-file coverage, build, size: JS 108.72 kB of 110 kB, CSS 2.65 kB of 5 kB) andpnpm e2epassed 45 of 45. The branch was rebased three times as feat: replace the greeting with a to-do reference app #335 moved (tod10b37f,c19faad, thenf2ff9e6);pnpm verifyandpnpm e2epassed at each step. The last rebase had no conflicts: feat: replace the greeting with a to-do reference app #335's newuseTodosguard and E2E tests touch no file this branch changes, and the router-backed page tests pass against the guard. Coverage before (basea26be0c, 2878 tests) and after (this branch ona26be0c, 2888 tests; again in the pre-push at4ea68a9): 100% statements, branches, functions and lines for all files, and 100% inapps/api/src/features/todos,apps/web/src/api-clientandapps/web/src/routes/todos.TodosPage.test.tsxnow takes about 9 s instead of 5 s, because it runs the real router and Effect schemas..agents/project/PR_QUALITY.md) satisfied, or each gap named: satisfied locally; hosted checks run on this head.pnpm verifypnpm e2e.agents/project/ARCHITECTURE.mdandCONVENTIONS.md; new decisions recorded as ADRs.serveAppRouterInTestsstate in a module-levelMapinside the api client, which only Jest calls. The alternatives each needed a gate change: a boundary allowance for a web value import of the api, which would also put api code in the dev server's module graph, or a second import path for route tests, which needsoxlint.config.tsand an AGENTS.md change.TestApiHandlershandlers now receive a second argument,serve. Existing one-argument handlers still type-check.createAppRouter, which the scaffold-exports check now requires because the reference does..nvmrcpins 22; CI runs the pinned version.PRD Behaviours to Review
docs/prd/todos.md: Shows a loading message until the list arrives. Evidence:todos.spec.tstest "shows a loading message until the list arrives" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Opens on the All filter, with an empty message and a disabled Clear done when there are no to-dos. Evidence:todos.spec.tstest "starts on the All filter with an empty message when there are no to-dos";todos.spec.tstest "returns to the All filter when the page reloads" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Says so when the list fails to load. Evidence:todos.spec.tstest "says so when the list fails to load" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Shows only the parts listed above. Evidence:todos.spec.tstest "shows only the parts the PRD lists";todos.spec.tstest "shows a title message and a failure where the PRD puts them" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Adds a to-do to the end of the list. Evidence:todos.spec.tstest "adds a to-do to the end of the list" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Stores and shows each title normalised. Evidence:todos.spec.tstest "stores and shows a title with its whitespace normalised" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: The api normalises every title it receives. Evidence:todos.spec.tstest "the api normalises a title from any client" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Rejects a blank or over-long title and sends nothing. Evidence:todos.spec.tstest "asks for a title and sends nothing when the title is blank";todos.spec.tstest "rejects a title over 100 characters and sends nothing" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Clears the title message once the title is fixed. Evidence:todos.spec.tstest "clears the title message once the title is fixed" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Accepts a title of exactly 100 characters, counted after normalising. Evidence:todos.spec.tstest "accepts a title of exactly 100 characters after normalising" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: The api rejects an invalid title as a bad request. Evidence:todos.spec.tstest "the api rejects a blank or over-long title as a bad request" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: The api answers each procedure as The api table says. Evidence:todos.spec.tstest "the api lists to-dos oldest first";todos.spec.tstest "the api answers each change with its result";todos.spec.tstest "the api answers not found for an unknown to-do" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Shows an add only once the api has answered and the list is re-read. Evidence:todos.spec.tstest "shows an add only once the api has answered and the list is re-read" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Pressing Add or Enter again while an add waits sends nothing. Evidence:todos.spec.tstest "stores one to-do when Add is pressed twice quickly" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Keeps the typed title and says so when adding fails. Evidence:todos.spec.tstest "keeps the typed title and says so when adding fails" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Marks a to-do done and active again, in place. Evidence:todos.spec.tstest "marks a to-do done and active again in place" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Disables every change control while a change waits. Evidence:todos.spec.tstest "disables every change control while a change waits" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Leaves the to-do unchanged and says so when marking it fails. Evidence:todos.spec.tstest "leaves the to-do unchanged and says so when marking it fails" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Edits a title in place, normalised. Evidence:todos.spec.tstest "edits a title in place and normalises it" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Cancels an edit without saving. Evidence:todos.spec.tstest "cancels an edit without saving" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Checks an edited title like a new one. Evidence:todos.spec.tstest "checks an edited title like a new one" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Edits one to-do at a time. Evidence:todos.spec.tstest "edits one to-do at a time" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Keeps the edit open and says so when saving fails. Evidence:todos.spec.tstest "keeps the edit open with the typed title and says so when saving fails" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Deletes a to-do at once. Evidence:todos.spec.tstest "deletes a to-do at once" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Keeps the to-do and says so when deleting fails. Evidence:todos.spec.tstest "keeps the to-do and says so when deleting fails" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Filters to active or done to-dos and back to all, and shows which filter is selected. Evidence:todos.spec.tstest "filters to active or done to-dos and back to all";todos.spec.tstest "shows the selected filter in the focus colour";todos.spec.tstest "hides a to-do from the Active filter once it is marked done";todos.spec.tstest "shows the empty message when a filter matches nothing" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Clears every done to-do, whatever the filter, and only while one is done. Evidence:todos.spec.tstest "clears every done to-do whatever the filter";todos.spec.tstest "enables Clear done only while a to-do is done" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Keeps the done to-dos and says so when clearing fails. Evidence:todos.spec.tstest "keeps the done to-dos and says so when clearing fails" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Shows only the latest failure, until the next change starts. Evidence:todos.spec.tstest "shows only the latest failure and clears it when the next change starts" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Says so when the list fails to load after a change. Evidence:todos.spec.tstest "says so when the list fails to load after a change" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Reads the list when the page opens and after each successful change. Evidence:todos.spec.tstest "reads the list only when the page opens and after a successful change" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.docs/prd/todos.md: Passes the automated WCAG 2.1 A/AA scan. Evidence:accessibility.spec.tstest "the empty to-do page has no detectable WCAG A/AA violations";accessibility.spec.tstest "the to-do list has no detectable WCAG A/AA violations";accessibility.spec.tstest "the validation error state has no detectable WCAG A/AA violations";accessibility.spec.tstest "an open edit has no detectable WCAG A/AA violations" passes in the pre-push hook at4ea68a9(45 passed); this PR changes no page or api behaviour.PR Proof Law
.agents/project/PR_QUALITY.mdand.agents/skills/pr-quality-contract/SKILL.md; thePR qualitycheck verifies the proof format.