feat(mock-e2e): browser E2E harness + createMockClient testing export#261
feat(mock-e2e): browser E2E harness + createMockClient testing export#261decrypto21 wants to merge 1 commit into
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning [Security] Socket has found a problem with the dependencies from this PR. Check the details below to solve the issue. If the affected dependency is unreachable, we still recommend you to use a patched version. Remember: according to Parity's Security Policy, you must resolve all "Block" alerts before proceeding. It is recommended to resolve "Warn" alerts too. Learn more about Socket for GitHub.
|
52e642f to
c68127e
Compare
feat(mock-e2e): browser E2E harness +
createMockClienttesting exportResolves #260 (the browser-E2E follow-up). Stacked on #258. Ported onto the current #104:
createMockClientand the harness use the newcreateWebWorkerPairingHostRuntime+createProviderruntime API; e2e is green (2/2).Suggested title
feat(mock-e2e): browser E2E harness + createMockClient testing exportSummary
On top of the mock host from #258, this adds the highest-fidelity proof and the ergonomic entry point that were left as follow-ups:
@parity/truapi-mock-e2e— a private workspace package that drives a product against the mock host in a real browser: the realtruapi-serverWASM core runs in aWeb Worker, the product runs in aniframeand connects via the SDK's realgetClientSync()sandbox path over a realMessageChannel, and Playwright drives it headless. This is a level above the headlesswasm-bridge.test.ts(which stops at the JS↔SCALE↔WASM boundary): it exercises the full production transport, with no mock code in the product.createMockClient— a@parity/truapi-host-wasm/testingsubpath export that collapsescreateMockHost+createWebWorkerPairingHostRuntime().createProvider()+createClientinto one call, returning the product client plus the mock for assertions.mock-e2eCI job that builds the WASM + workspace packages, installs Chromium, and runs the Playwright suite.The harness resolves its dependencies through the npm workspace, so it runs anywhere the repo does — no machine-specific paths.
What's in it
@parity/truapi-mock-e2e— new private (unpublished) packageA Vite + React browser harness with two topologies:
src/main.tsx): host + product in one page, wired with a singlecreateMockClient()call.src/host.tsx+src/product.tsx): mirrors production embedding — the host boots the core +createIframeHost; the product runs in aniframewith no mock code, connecting throughgetClientSync().Files:
package.json,tsconfig.json,vite.config.ts,playwright.config.ts,index.html/host.html/product.html,src/{main,host,product}.tsx,tests/e2e.spec.ts,README.md,.gitignore.@parity/truapi-host-wasm—src/testing.ts(new./testingexport)createMockClient(worker, config?)→{ client, mock }. ComposescreateMockHost+createWebWorkerProvider+createClient(createTransport(...)); the caller supplies the coreWorkerso their bundler owns how it's produced.clientis the exact object a product uses in production;mockexposes the recorded oracles for assertions.Public API:
createMockClient,MockClient.Why it's additive (and what it proves)
wasm-bridge.test.ts(feat: mock platform #258) proves the SCALE bridge decodes/dispatches, but with no realWeb Worker, noiframe, and no product transport. This harness closes that gap: a real product, in a real browser, over the production transport, reaching the real core only throughgetClientSync().createMockClientmakes "switch a product to mock mode" a one-liner. It is dogfooded by the single-page harness and has executing runtime coverage via test (2) below — not just typecheck.Verification
All green locally (this is the executed state, not aspiration):
codegen→ build@parity/truapi→ build@parity/truapi-host-wasm(compilescreateMockClient) — pass.tsctypecheck of the harness (@parity/truapi-mock-e2e) — pass.make wasm/build:wasm—truapi_server_bg.wasm≈ 1.96 MB.createMockClientat runtime.mock-e2ejob — not yet run in CI (branch verified locally only; CI runs it on first push).CI
A new
mock-e2ejob (needs: codegen): downloads the codegen artifact,npm ci, builds@parity/truapi, installswasm-pack 0.15.0, runsbuild:wasm, builds@parity/truapi-host-wasm, installs Chromium (npx playwright install --with-deps chromium), then runs the Playwright suite; the report is uploaded on failure.Deliberately not a required gate yet:
mock-e2eis omitted from theci-statusneedsand results (with an explaining comment) — it runs for signal but neither gates merges nor makes the aggregate status wait on its (up to 30-min) run. Promote it into the gate once it has a green CI baseline.Production safety
@parity/truapi-mock-e2eis private (unpublished) and dev/test-only.createMockClientlives under the/testingsubpath and only composes existing test helpers — it adds no production code path. Themockfeature andcreateMockHostremain dev-gated exactly as in feat: mock platform #258.Dependencies
react/react-dom/vite/@vitejs/plugin-react/@playwright/test/typescript/@types/*— all harness/dev scoped to the unpublished package and hoisted at the workspace root. No new runtime dependency for any shipped package.@parity/truapi-host-wasm: one new subpath export (./testing);createMockClientimportscreateClient/createTransportfrom@parity/truapi, already a dependency — no new host-wasm dep.package-lock.jsonrefreshed for the new workspace member.PR stack, draft status & breaking changes
This is a draft PR — the top of a three-PR draft stack. Review it against its base branch, not
main:The breaking changes live in #104, not in this PR. #104 is an in-flight port of the Rust core runtime that reshaped the host-facing API —
truapi-platform's capability traits moved to#[async_trait]and types moved totruapi::latest. Consequences for this stack:truapi-server,truapi-platform, andtruapi-host-wasmcrates in the form this depends on exist only on feat: port Rust core runtime #104. That is why feat: mock platform #258's — and therefore this PR's — base is the feat: port Rust core runtime #104 branch, and why the diff must be read againstfeat/mock-platform, notmain.fixup!commit, so it will be squashed when it merges. When that happens the whole stack force-rebases (feat: mock platform #258 ontomain, then this onto feat: mock platform #258). Expect at least one more forced rebase of this branch.This PR itself introduces no breaking changes. It is purely additive: a new private (unpublished)
@parity/truapi-mock-e2epackage and a new@parity/truapi-host-wasm/testingsubpath export. It touches no shipped runtime code path and changes no existing public API — the breaking surface is inherited entirely from the #104 base.Docs updated:
truapi-host-wasm/README.md(/testing), rootREADME.md,CLAUDE.mdlayout, and the new packageREADME.md.Diff
package-lock.jsonrefresh: 20 files, +2494 / −100 (the lockfile is ~1.98k of the insertions).Reviewer guide
js/packages/truapi-host-wasm/src/testing.ts—createMockClient(~30 lines); confirm the composition and the documentedas WebWorkerHostCallbackscast (safe: the mock builds aRequired<HostCallbacks>).js/packages/truapi-mock-e2e/src/{host,product,main}.tsx— the two topologies; note the product (product.tsx) reaches the core only throughgetClientSync()and contains no mock code.tests/e2e.spec.ts— two tests: the iframe round-trip and the single-pagecreateMockClientruntime coverage..github/workflows/ci.yml— themock-e2ejob, and confirm it is intentionally out of theci-statusgate/needs.vite.config.ts— confirm there are no machine-specific absolute paths (deps resolve via workspace symlinks); this portability is the point of moving the harness in-repo.What's next (follow-ups, not blockers)
playground/host-playground(product-sdk) apps against the mock host — the product-sdk conversion layer end to end (the earlier "Scenario B"); separate issue.mock-e2eto a required CI gate once it has a green baseline.MockHost.callbackstoRequired<HostCallbacks>so the twoas WebWorkerHostCallbackscasts can be dropped — fold into feat: mock platform #258's next required touch (the feat: port Rust core runtime #104 rebase).