pcbjam/tests/collab/build.mjs
Viktor Vaczi 4e92baf5d0
test(ysync): repro tests for review bugs 01-07 + v2 items-wire e2e port (miss 11)
The 2026-07-02 sync review (docs/features/ysync-review, ysync-review branch)
found 7 bugs and that the two-tab e2e only exercised the DEAD legacy scalar
wire. This lands plan doc 15 in full; results + empirical findings in doc 16.

- tests/collab/browser-entry-v2.ts (+build.mjs): the PRODUCTION v2 stack
  bundled for e2e (connectKicadDoc + attachKicadCollab, kdoc_* keys), with
  in-page renderActiveDoc/singleSeedRender/driftReport helpers and yjs forced
  to ONE copy (the two web pnpm workspaces otherwise bundle two
  instanceof-incompatible instances).
- tests/kicad/ysync-two-tab.spec.ts: pl_editor green baseline (A↔B edits,
  ITEM-level drift silence) + divergent-uuid adopt; bug-01 pcb/ee fresh-room
  repros (Chromium-only: two kicad_editor tabs exceed Firefox's per-process
  wasm budget); bug-06 concurrent-seed race; bug-03 Y-half.
- tests/kicad/ysync-repros-{pcbnew,eeschema}.spec.ts: bugs 02/03/05 + the
  bug-04 matrix (anchor-centred fp rotation, pad resize, endpoint drag,
  symbol rotation, Value-field edit), each with green landed-preconditions;
  the "local move emits" controls double as headless-emit probes — GREEN on
  both tools, so every emit-dependent repro is a live test.fail.
- wasm/bindings: 7 local-edit test hooks via real commits
  (CallAfter+COROUTINE) — TestRemoveItem/TestRotateItem (both tools,
  dispatched in the merged image), TestSetPadSize/TestMoveEndpoint (pcbnew),
  TestSetFieldText (eeschema).
- web/standalone ysync-repros.test.ts: bug-01 units (C++-faithful fake gating
  emit on ensureBridge) + bug-07a/b (stale DOWN hook, real sheet-manager gap).
- web/pcbjam-shared bump: bug-03/06 unit repros.

Convention: every repro asserts the CORRECT behavior and is expected-fail
(test.fail/it.fails) naming its bug doc; a fix flips it to "unexpected pass",
forcing marker removal — the repro becomes the regression test. Every
expected failure verified (JSON reporter) to fail at its documented assert.
Suite state: 39 passed / 0 failed / 0 flaky / 5 skipped (2 firefox guards,
2 pre-existing legacy two-tab skips, 1 pre-existing roundtrip fixme).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPfrVhfYgPPgtawjSssZfn
2026-07-06 08:57:01 +02:00

50 lines
2.3 KiB
JavaScript

// Bundle the collab browser entry (reconciler + Yjs + BroadcastChannel transport,
// sourced from the web frontend) into a single IIFE the pl_editor harness loads.
// nodePaths lets esbuild resolve `yjs` from tests/node_modules even though the
// reconciler lives under web/. Output: apps/kicad/collab-bundle.js (global KicadCollab).
import { build } from "esbuild";
import path from "node:path";
import { fileURLToPath } from "node:url";
const testsDir = path.resolve(fileURLToPath(new URL("..", import.meta.url)));
await build({
entryPoints: [path.join(testsDir, "collab/browser-entry.ts")],
bundle: true,
format: "iife",
outfile: path.join(testsDir, "apps/kicad/collab-bundle.js"),
nodePaths: [path.join(testsDir, "node_modules")],
// The e2e harness only exercises the BroadcastChannel transport; the server
// providers are reached via dynamic import() that never runs in tests, and
// their packages are only installed in the web/ pnpm workspace.
external: ["y-partyserver/provider", "@hocuspocus/provider"],
logLevel: "info",
target: "es2020",
});
console.log("collab bundle built → apps/kicad/collab-bundle.js");
// The V2 ("items") bundle — the PRODUCTION collab stack (see browser-entry-v2.ts).
await build({
entryPoints: [path.join(testsDir, "collab/browser-entry-v2.ts")],
bundle: true,
format: "iife",
outfile: path.join(testsDir, "apps/kicad/collab-bundle-v2.js"),
nodePaths: [path.join(testsDir, "node_modules")],
external: ["y-partyserver/provider", "@hocuspocus/provider"],
alias: {
// web/standalone and web/pcbjam-shared are separate pnpm workspaces, so
// their `yjs` imports resolve to two physical copies. The v2 binding hands
// Y types across that boundary (instanceof-checked), so force ONE copy —
// the tests devDep — exactly like the standalone vitest `dedupe: ["yjs"]`.
yjs: path.join(testsDir, "node_modules/yjs"),
// Lets this entry (which lives under tests/, outside the web workspaces)
// import the shared lib by name, resolving to the SAME source instance the
// standalone collab modules bundle.
"@pcbjam/shared": path.join(testsDir, "../web/pcbjam-shared/src/index.ts"),
},
logLevel: "info",
target: "es2020",
});
console.log("collab v2 bundle built → apps/kicad/collab-bundle-v2.js");