feat(templates): page-money uses SDK Harness + unit/e2e test boilerplate - #7
Merged
Conversation
The page-money scaffold now adopts the published mock host shipped in @civitai/[email protected] (the `/testing` export) and ships unit + component + e2e test boilerplate, so a freshly-created app runs locally and is tested out of the box. - Replace the ~250-line hand-rolled src/Harness.tsx with a ~15-line wrapper around the SDK's <Harness> (createMockHost under the hood). - Add src/dev-transport.ts: allowlists window.location.origin for the dev harness AND tests (the mock host replies from that origin and the SDK IframeTransport drops mismatched-origin messages). main.tsx calls installHarnessTransport() before render in harness mode. - Bump deps to @civitai/blocks-react ^0.8.0 + @civitai/app-sdk ^0.12.0 (the 0.8.0 peer requires >=0.10.0); add @testing-library/react, @testing-library/jest-dom, @testing-library/user-event devDeps. - Split vitest into two projects: node (*.test.ts pure logic) + jsdom (*.test.tsx component/e2e) via test.projects; add src/test-setup.ts (jest-dom matchers + per-test transport reset + cleanup). - Add src/App.test.tsx (component: anon -> sign-in, signed-in -> prompt) and src/e2e.test.tsx (full money path through the REAL SDK transport: estimate -> consent -> submit -> poll -> succeeded +cost; and the insufficient-Buzz Top-Up path). - Update README to document the new harness + the test split. - CI rot-guard: a new template-page-money job scaffolds page-money and runs npm install/typecheck/test/build/validate against the published SDK, so the template can't silently rot after an SDK bump. Verified by scaffolding: npm install, typecheck, npm test (14 passed: 9 node + 5 dom incl. the e2e money path), build, and `app validate` all green. `go test ./...` stays green (scaffold render tests unaffected). Co-Authored-By: Claude Opus 4.8 (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.
What
Phase 2 of the App Blocks DX work: the
page-moneyscaffold now adopts the published SDK mock host shipped in@civitai/[email protected](the/testingexport) and ships unit + component + e2e test boilerplate, so a freshly-created app runs locally and is tested out of the box.Templates-only change (plus a CI job). No CLI command code touched (that's #6 / the
app createPR #5/#6 — no overlap).Changes
src/Harness.tsxsimulator with a ~15-line wrapper around the SDK's<Harness>(createMockHostunder the hood). Net -232 lines of per-block boilerplate.src/dev-transport.tsthat allowlistswindow.location.originfor the dev harness AND tests — the mock host replies from that origin and the SDKIframeTransportdrops mismatched-origin messages.main.tsxcallsinstallHarnessTransport()before render in harness mode (prod still uses the baked-inVITE_BLOCK_ALLOWED_PARENT_ORIGINS).@civitai/blocks-react ^0.8.0+@civitai/app-sdk ^0.12.0(the 0.8.0 peer requires>=0.10.0). Add@testing-library/react+@testing-library/jest-dom+@testing-library/user-eventdevDeps.vitest run—node(*.test.ts, pure logic) +dom(*.test.tsx, jsdom) viatest.projects. Addsrc/test-setup.ts(jest-dom matchers + per-test transport reset + cleanup). Existinggeneration.test.tskept.src/App.test.tsx— component: anon → sign-in affordance, signed-in → prompt + Generate, loading state.src/e2e.test.tsx— the money-path proof, driving the FULL flow through the real SDK transport (no hook mocking): estimate → consent → submit → poll → succeeded (+cost), plus the insufficient-Buzz Top-Up path.template-page-moneyjob scaffolds the template and runsnpm install/typecheck/test/build/app validateagainst the published SDK, so the template can't silently rot after an SDK bump.Verification (real scaffolded project)
Scaffolded
page-moneyvia the built CLI, then on the rendered project:npm install→ resolved@civitai/[email protected]+@civitai/[email protected], 0 vulnerabilities.npm run typecheck→ clean.npm test→ 14 passed (3 files): 9node+ 5dom(3 component + 2 e2e). The full money-path e2e exercises the real transport round-trips (~2.1s).npm run build→ tsc + vite build OK (208 kB / 66 kB gzip).civitai app validate→OK — . is valid.go test ./...→ green (scaffold render tests unaffected; subset checks tolerate the new files).🤖 Generated with Claude Code