pcbjam/tests/kicad/items-bridge.spec.ts

325 lines
13 KiB
TypeScript
Raw Normal View History

feat: v2 per-item s-expr collab bridge in all three tools (ysync 0008 Stage C) Add kicadCollabSnapshotItems / kicadCollabApplyItems / window.kicadCollab.onItems to pl_editor, eeschema, pcbnew — per-item native-blob payloads ({added/changed:[{sexpr,parent}], removed:[uuid]}) alongside the untouched scalar wire (legacy collab specs stay green). - pl_editor: itemBlob per item; apply = SetPageLayout(append) + replace-by-uuid (pointer-snapshot safe); bare payloads get the kicad_wks envelope. Snapshot + apply + emit verified headless. - eeschema: clipboard Format per item (symbols carry their lib_symbols); apply mirrors the native paste — LoadContent into a throwaway sheet → detach → replace-by-uuid → symbol lib relink (blob's lib_symbols first, live screen's second) → SCH_COMMIT, in the CallAfter+COROUTINE context. Snapshot + apply verified headless (a "lost" lone junction turned out to be correct connection cleanup — test uses text). - pcbnew: blobForItem per ROOT item with child→footprint lifting in flushDiff; apply = makeFromBlob + commit replace-by-uuid on the fiber; bare non-footprint payloads get wrapInBoardEnvelope (live board layer table). Snapshot + footprint replace/add WITH children (the 0004 containment gap, closed) + removal verified headless. Track/via/zone/text blob-apply hits the documented asyncify-fragile envelope parse (reconfirmed empirically — a verbatim SaveSelection segment envelope dies silently in the commit) and stays on the legacy scalar apply; tracked in ysync 0008 status. - eeschema/pcbnew scheduleFlush now runs flushDiff inside a COROUTINE: the per-item Format in the v2 emit needs the fiber stack (0007 lesson). Their emit remains unverifiable headless (both legacy two-tab tests are test.skip: "open=false → SCH_COMMIT no-ops" / "harness can't PAINT") — verify in the real app at Stage D; pl_editor's emit IS verified. - tests/kicad/items-bridge.spec.ts: per-tool suite (snapshot uuids → local-edit emit (where drivable) → apply changed/added/removed via save-readback → no apply echo). 3/3 pass; roundtrip + collab suites unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 13:55:15 +02:00
import type { Page } from "@playwright/test";
import { test, expect } from "./fixtures";
/**
* v2 "items" bridge (ysync 0008 Stage C): per-item s-expr payloads on
* kicadCollabSnapshotItems / kicadCollabApplyItems / window.kicadCollab.onItems.
*
* Per tool this drives the C++ exports directly (no reconciler/Y.Doc that's the
* Stage B binding, unit-tested in the standalone):
* 1. snapshotItems: every fixture item's uuid appears in some wire blob;
* 2. applyItems: changed (full/bare blob) + added (bare blob tool wraps in its
* envelope) + removed (uuid) land in the model verified via the save export;
* 3. onItems: a genuine local edit emits a wire whose blob carries the item.
*/
type Mod = {
kicadOpenFile(p: string): unknown;
kicadCollabSnapshotItems(): string;
kicadCollabApplyItems(j: string): unknown;
} & Record<string, (...a: never[]) => unknown>;
type FS = {
mkdirTree(p: string): void;
writeFile(p: string, d: string): void;
readFile(p: string, o: { encoding: "utf8" }): string;
};
interface ToolCfg {
tool: string;
html: string;
ext: string;
saveFn: string;
fixture: string;
/** uuids that must appear in the snapshot wire. */
uuids: string[];
/** applyItems payloads + the save-text markers proving they landed. Either a
* static sexpr, or derive it from the snapshot blob of `uuid` via replace
* for pcbnew, whose non-footprint envelopes are the known-fragile parse. */
changed:
| { sexpr: string; marker: string }
| { fromSnapshotUuid: string; replace: [string, string]; marker: string };
added: { sexpr: string; uuid: string };
removedUuid: string;
/** evaluate-able local edit that must trigger an onItems emit. Omitted for
* eeschema: the headless harness can't drive its emit (open=false
* SCH_COMMIT no-ops the documented reason eeschema-collab's two-tab test
* is skipped; verified working in the real web app). */
localEdit?: string;
}
const BOOT_TIMEOUT = 150000;
function hasAbort(l: { consoleLogs: string[]; errors: string[] }): boolean {
return [...l.consoleLogs, ...l.errors].some((s) => s.includes("Aborted("));
}
async function bootOpen(page: Page, cfg: ToolCfg): Promise<void> {
await page.goto(`/kicad/${cfg.html}`);
await expect(page.locator("#canvas")).toBeVisible({ timeout: BOOT_TIMEOUT });
await page.waitForFunction(() => !!window.wxElementRegistry, null, { timeout: BOOT_TIMEOUT });
await page.waitForFunction(
(saveFn) => {
const m = (window as unknown as { Module?: Mod }).Module;
return (
typeof m?.kicadOpenFile === "function" &&
typeof m?.kicadCollabSnapshotItems === "function" &&
typeof m?.kicadCollabApplyItems === "function" &&
typeof m?.[saveFn] === "function"
);
},
cfg.saveFn,
{ timeout: BOOT_TIMEOUT },
);
await page.waitForFunction(
() =>
!!window.wxElementRegistry &&
window.wxElementRegistry
.findAll({ visible: true })
.some((e) => /Frame$/.test(e.typeName) || (e.name || "").endsWith("Frame")),
null,
{ timeout: BOOT_TIMEOUT },
);
await page.evaluate(
({ content, ext }) => {
const w = window as unknown as { FS: FS; Module: Mod };
try {
w.FS.mkdirTree("/home/kicad/documents");
} catch {
/* exists */
}
const p = `/home/kicad/documents/rt.${ext}`;
w.FS.writeFile(p, content);
w.Module.kicadOpenFile(p);
},
{ content: cfg.fixture, ext: cfg.ext },
);
}
async function saveRead(page: Page, cfg: ToolCfg, name: string): Promise<string> {
return page.evaluate(
({ saveFn, ext, name }) => {
const w = window as unknown as { FS: FS; Module: Mod };
const out = `/home/kicad/documents/${name}.${ext}`;
(w.Module[saveFn] as (p: string) => unknown)(out);
return w.FS.readFile(out, { encoding: "utf8" });
},
{ saveFn: cfg.saveFn, ext: cfg.ext, name },
);
}
/** Poll the saved model until `marker` is present (apply is async for ee/pcb). */
async function pollSaved(page: Page, cfg: ToolCfg, marker: string, present = true): Promise<void> {
await expect
.poll(async () => (await saveRead(page, cfg, "probe")).includes(marker), {
timeout: 25000,
intervals: [400],
})
.toBe(present);
}
// ── Tool configurations ──────────────────────────────────────────────────────
const PL: ToolCfg = {
tool: "pl_editor",
html: "pl_editor.html",
ext: "kicad_wks",
saveFn: "kicadSaveDrawingSheet",
fixture: `(kicad_wks (version 20220228) (generator "pl_editor") (generator_version "9.0")
(setup (textsize 1.5 1.5)(linewidth 0.15)(textlinewidth 0.15)
(left_margin 10)(right_margin 10)(top_margin 10)(bottom_margin 10))
(rect (uuid "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb") (name border) (start 0 0 ltcorner) (end 0 0 rbcorner))
(tbtext "Title" (uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") (name title) (pos 100 20 ltcorner) (font (size 2 2)))
)
`,
uuids: ["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"],
changed: {
// Bare item (Y.Doc-rendered shape) — the tool must wrap it in its envelope.
sexpr: `(tbtext "Title" (uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") (name title) (pos 55 65 ltcorner) (font (size 2 2)))`,
marker: "(pos 55 65",
},
added: {
sexpr: `(tbtext "BareAdd" (uuid "dddddddd-dddd-dddd-dddd-dddddddddddd") (name bare) (pos 10 10 ltcorner) (font (size 2 2)))`,
uuid: "dddddddd-dddd-dddd-dddd-dddddddddddd",
},
removedUuid: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
localEdit: `window.Module.kicadCollabTestAddText("EmitMe", 40, 40)`,
};
const SCH: ToolCfg = {
tool: "eeschema",
html: "eeschema.html",
ext: "kicad_sch",
saveFn: "kicadSaveSchematic",
fixture: `(kicad_sch
(version 20250114)
(generator "eeschema")
(generator_version "9.0")
(uuid "11111111-1111-1111-1111-111111111111")
(paper "A4")
(lib_symbols)
(wire (pts (xy 50.8 50.8) (xy 101.6 50.8)) (stroke (width 0) (type default)) (uuid "22222222-0000-0000-0000-000000000001"))
(wire (pts (xy 50.8 76.2) (xy 101.6 76.2)) (stroke (width 0) (type default)) (uuid "22222222-0000-0000-0000-000000000002"))
(sheet_instances (path "/" (page "1")))
)
`,
uuids: ["22222222-0000-0000-0000-000000000001", "22222222-0000-0000-0000-000000000002"],
changed: {
sexpr: `(wire (pts (xy 25.4 25.4) (xy 76.2 25.4)) (stroke (width 0) (type default)) (uuid "22222222-0000-0000-0000-000000000001"))`,
marker: "(xy 25.4 25.4)",
},
added: {
// Connectivity-neutral: a lone junction would be deleted by SCH_COMMIT::Push's
// connection cleanup (it sits on no wire crossing) — that's correct editor
// behavior, not a bridge gap. Text survives.
sexpr: `(text "BareAdd" (exclude_from_sim no) (at 60.96 60.96 0) (effects (font (size 1.27 1.27))) (uuid "33333333-0000-0000-0000-000000000003"))`,
uuid: "33333333-0000-0000-0000-000000000003",
},
removedUuid: "22222222-0000-0000-0000-000000000002",
// no localEdit: headless harness cannot drive eeschema emit (see ToolCfg note)
};
const PCB: ToolCfg = {
tool: "pcbnew",
html: "pcbnew-collab.html",
ext: "kicad_pcb",
saveFn: "kicadSaveBoard",
fixture: `(kicad_pcb
(version 20241229)
(generator "pcbnew")
(generator_version "9.0")
(general (thickness 1.6))
(paper "A4")
(layers
(0 "F.Cu" signal)
(2 "B.Cu" signal)
(37 "F.SilkS" user)
(25 "Edge.Cuts" user)
)
(setup)
(net 0 "")
(footprint "TestLib:R"
(layer "F.Cu")
(uuid "66666666-0000-0000-0000-000000000001")
(at 100 100)
(attr smd)
(property "Reference" "R1" (at 0 -4.2 0) (layer "F.SilkS") (uuid "66666666-0000-0000-0000-0000000000aa") (effects (font (size 1 1) (thickness 0.15))))
(property "Value" "R" (at 0 4.6 0) (layer "F.Fab") (uuid "66666666-0000-0000-0000-0000000000bb") (effects (font (size 1 1) (thickness 0.15))))
(fp_text user "HELLO" (at 0 0 0) (layer "F.SilkS") (uuid "66666666-0000-0000-0000-0000000000cc") (effects (font (size 1 1) (thickness 0.15))))
)
(via (at 80 80) (size 1.4) (drill 0.6) (layers "F.Cu" "B.Cu") (net 0) (uuid "77777777-0000-0000-0000-000000000001"))
(segment (start 50.8 50.8) (end 101.6 50.8) (width 0.2) (layer "F.Cu") (net 0) (uuid "88888888-0000-0000-0000-000000000001"))
(segment (start 50.8 76.2) (end 101.6 76.2) (width 0.2) (layer "F.Cu") (net 0) (uuid "88888888-0000-0000-0000-000000000002"))
)
`,
uuids: [
"66666666-0000-0000-0000-000000000001",
"77777777-0000-0000-0000-000000000001",
"88888888-0000-0000-0000-000000000001",
],
// pcbnew v2-apply scope (ysync 0008 Stage C): FOOTPRINT blobs are the proven
// path (bare-footprint parse + replace-by-uuid with children — the 0004
// containment win). Track/via/zone/text APPLY via the (kicad_pcb …) envelope
jspi cleanup: remove the asyncify-era residue — dead code, conditionals, pipeline scaffolding, stale prose The runtime is JSPI-only; this removes everything that still pretended otherwise. Three exhaustive sweeps (C++/JS+build+CI/tests+docs) drove the inventory; every deletion verified by grep closure + full gates. Broken-right-now fixes: - deploy-staging.yml passed the retired opt_level input — the workflow could not even start. Removed. - env.sh carried dead exports with a live -sASYNCIFY=1 inside (WASM_LDFLAGS/PTHREAD_LDFLAGS, zero consumers). Removed; the WASM_LEGACY_EXCEPTIONS rationale rewritten to the real reason. - docker/build.sh exported PCBJAM_ASYNC_BACKEND (read nowhere). Gone. Dead weight removed: - binaryen submodule (nothing builds or invokes it), wasm-opt-bench workflow + scripts/bench/, get-wasm-opt.sh, diagnostics.js (242 lines of Asyncify-API-only code), the KICAD_PIPELINE background-postprocess scaffolding (existed to parallelize the deleted wasm-opt phase; the postprocess is a seconds-long node script and now runs inline), build-monitor's dead asyncify rows, sched-context orphan build output, dead .gitignore entries, the .jspi-assets spike dir (the two wf-result research JSONs moved to docs/features/async/migration-evidence/). - bindings: fiber_park.h + its 12 embind registrations (broken-if- called under JSPI), the kicadOpenFileStart/OPEN_JOB starter route, main_stack_runner.h + 5 includes, the always-null context-sleep weak hook in nanosleep_yield.c. - shim: the backend field (installed-flag idempotency instead), noteContextWait (dead both sides), the __wxAsyncifyDump alias (+ the WasmTool fallback and string-dump normalize branch). - web: the emscripten-6-ignored mainScriptUrlOrBlob option in boot.ts (gerber-demo keeps it: it loads the deployed CDN release, which predates emscripten 6 — noted inline). Conditionals: all 'backend === jspi' checks reduced to scheduler- presence checks; races_quiescent re-keyed from Asyncify.state (vacuous) to real backlog quiescence (resumeReady/mutatorQueue — NOT _windowLive, which is the probing activation's own window by definition). Renames (identifiers only, no file renames): ASYNC_LINK_FLAGS→ JSPI_LINK_FLAGS and Makefile ASYNC_LDFLAGS→JSPI_LDFLAGS, kicadCollabFiberBusy→kicadCollabBusy (embind + web + tests), collab_common.h fiber*→apply*/coroutine naming, asyncifySignatures→ wasmTrapSignatures (lists byte-identical). Tests: the two remaining vacuous [wx-asyncify]/fiber-resume-refused asserts re-keyed to live JSPI beacons; eeschema-load's failure message no longer sends the developer to a deleted script; wait-beacons' dead families/parser deleted; lane-0 legacy-glue guards removed (lane 0 is unconstructible); the embind test.fail re-gated with the JSPI reason (plain embind invokers cannot suspend — verified still failing); lint-determinism now scans tests/jspi (166 files clean); eeschema-collab local-move gated to chromium (~50% flaky on FF even solo; pcbnew twin covers both engines). Docs: DEBUG.md rewritten as the JSPI debugging guide; build.md describes the single-phase build; docs/features/async/README.md banner-marked historical and repointed at the NEW 23-jspi-runtime.md (current architecture: export census, turnstile, libcontext ownership + refusal contract, embind call shapes, the em-pthread service-wrapper trick, exception policy, known gaps). Gates on the cleaned tree: test:e2e 725 passed / 0 failed (after the quiescence-probe fix; the 3 other reds were verified contention flakes solo-green or the documented FF gate), web 76/0, jspi 18/18 both engines, vitest 295/295 + 17/17, all lints green, live-app census clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016X9eh1s5sTx1o9Em9KBuwR
2026-08-14 09:25:32 +02:00
// rode the parse that was asyncify-fragile in wasm (healthy under JSPI —
// roundtrip.spec.ts pins it); those types still ship on the legacy scalar
// apply (tracked in 0008 status).
feat: v2 per-item s-expr collab bridge in all three tools (ysync 0008 Stage C) Add kicadCollabSnapshotItems / kicadCollabApplyItems / window.kicadCollab.onItems to pl_editor, eeschema, pcbnew — per-item native-blob payloads ({added/changed:[{sexpr,parent}], removed:[uuid]}) alongside the untouched scalar wire (legacy collab specs stay green). - pl_editor: itemBlob per item; apply = SetPageLayout(append) + replace-by-uuid (pointer-snapshot safe); bare payloads get the kicad_wks envelope. Snapshot + apply + emit verified headless. - eeschema: clipboard Format per item (symbols carry their lib_symbols); apply mirrors the native paste — LoadContent into a throwaway sheet → detach → replace-by-uuid → symbol lib relink (blob's lib_symbols first, live screen's second) → SCH_COMMIT, in the CallAfter+COROUTINE context. Snapshot + apply verified headless (a "lost" lone junction turned out to be correct connection cleanup — test uses text). - pcbnew: blobForItem per ROOT item with child→footprint lifting in flushDiff; apply = makeFromBlob + commit replace-by-uuid on the fiber; bare non-footprint payloads get wrapInBoardEnvelope (live board layer table). Snapshot + footprint replace/add WITH children (the 0004 containment gap, closed) + removal verified headless. Track/via/zone/text blob-apply hits the documented asyncify-fragile envelope parse (reconfirmed empirically — a verbatim SaveSelection segment envelope dies silently in the commit) and stays on the legacy scalar apply; tracked in ysync 0008 status. - eeschema/pcbnew scheduleFlush now runs flushDiff inside a COROUTINE: the per-item Format in the v2 emit needs the fiber stack (0007 lesson). Their emit remains unverifiable headless (both legacy two-tab tests are test.skip: "open=false → SCH_COMMIT no-ops" / "harness can't PAINT") — verify in the real app at Stage D; pl_editor's emit IS verified. - tests/kicad/items-bridge.spec.ts: per-tool suite (snapshot uuids → local-edit emit (where drivable) → apply changed/added/removed via save-readback → no apply echo). 3/3 pass; roundtrip + collab suites unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 13:55:15 +02:00
changed: {
// Replace the footprint wholesale from its own snapshot blob, moved.
fromSnapshotUuid: "66666666-0000-0000-0000-000000000001",
replace: ["(at 100 100)", "(at 90 110)"],
marker: "(at 90 110",
},
added: {
// A bare footprint parses top-level (no envelope) — the proven add path.
sexpr: `(footprint "TestLib:C" (layer "F.Cu") (uuid "99999999-0000-0000-0000-000000000009") (at 50 50) (attr smd) (property "Reference" "C1" (at 0 -2 0) (layer "F.SilkS") (uuid "99999999-0000-0000-0000-0000000000aa") (effects (font (size 1 1) (thickness 0.15)))))`,
uuid: "99999999-0000-0000-0000-000000000009",
},
removedUuid: "88888888-0000-0000-0000-000000000002",
// no localEdit: pcbnew emit is likewise unverifiable headless (pcbnew-collab two-tab is test.skip)
};
// ── The per-tool suite ───────────────────────────────────────────────────────
for (const cfg of [PL, SCH, PCB]) {
test.describe(`${cfg.tool} items bridge (v2, per-item s-expr)`, () => {
test.describe.configure({ timeout: 420000 });
test(`${cfg.tool}: snapshot, apply (changed/added/removed), emit`, async ({
page,
testLogger,
}) => {
await bootOpen(page, cfg);
// 1. snapshotItems: every fixture uuid appears in some wire blob.
const snap = JSON.parse(
await page.evaluate(() => window.Module.kicadCollabSnapshotItems()),
) as { added: Array<{ sexpr: string; parent: string | null }> };
const allBlobs = snap.added.map((w) => w.sexpr).join("\n");
for (const uuid of cfg.uuids) {
expect(allBlobs, `snapshot blob for ${uuid}`).toContain(uuid);
}
// 2. Register the v2 emit hook.
await page.evaluate(() => {
(window as unknown as { __items: string[] }).__items = [];
(window as unknown as { kicadCollab: object }).kicadCollab = {
onItems: (j: string) => (window as unknown as { __items: string[] }).__items.push(j),
};
});
// 3. A genuine local edit emits an items wire carrying the touched item.
// Run this BEFORE the applies: TestMoveFirst moves the FIRST screen item,
jspi cleanup: remove the asyncify-era residue — dead code, conditionals, pipeline scaffolding, stale prose The runtime is JSPI-only; this removes everything that still pretended otherwise. Three exhaustive sweeps (C++/JS+build+CI/tests+docs) drove the inventory; every deletion verified by grep closure + full gates. Broken-right-now fixes: - deploy-staging.yml passed the retired opt_level input — the workflow could not even start. Removed. - env.sh carried dead exports with a live -sASYNCIFY=1 inside (WASM_LDFLAGS/PTHREAD_LDFLAGS, zero consumers). Removed; the WASM_LEGACY_EXCEPTIONS rationale rewritten to the real reason. - docker/build.sh exported PCBJAM_ASYNC_BACKEND (read nowhere). Gone. Dead weight removed: - binaryen submodule (nothing builds or invokes it), wasm-opt-bench workflow + scripts/bench/, get-wasm-opt.sh, diagnostics.js (242 lines of Asyncify-API-only code), the KICAD_PIPELINE background-postprocess scaffolding (existed to parallelize the deleted wasm-opt phase; the postprocess is a seconds-long node script and now runs inline), build-monitor's dead asyncify rows, sched-context orphan build output, dead .gitignore entries, the .jspi-assets spike dir (the two wf-result research JSONs moved to docs/features/async/migration-evidence/). - bindings: fiber_park.h + its 12 embind registrations (broken-if- called under JSPI), the kicadOpenFileStart/OPEN_JOB starter route, main_stack_runner.h + 5 includes, the always-null context-sleep weak hook in nanosleep_yield.c. - shim: the backend field (installed-flag idempotency instead), noteContextWait (dead both sides), the __wxAsyncifyDump alias (+ the WasmTool fallback and string-dump normalize branch). - web: the emscripten-6-ignored mainScriptUrlOrBlob option in boot.ts (gerber-demo keeps it: it loads the deployed CDN release, which predates emscripten 6 — noted inline). Conditionals: all 'backend === jspi' checks reduced to scheduler- presence checks; races_quiescent re-keyed from Asyncify.state (vacuous) to real backlog quiescence (resumeReady/mutatorQueue — NOT _windowLive, which is the probing activation's own window by definition). Renames (identifiers only, no file renames): ASYNC_LINK_FLAGS→ JSPI_LINK_FLAGS and Makefile ASYNC_LDFLAGS→JSPI_LDFLAGS, kicadCollabFiberBusy→kicadCollabBusy (embind + web + tests), collab_common.h fiber*→apply*/coroutine naming, asyncifySignatures→ wasmTrapSignatures (lists byte-identical). Tests: the two remaining vacuous [wx-asyncify]/fiber-resume-refused asserts re-keyed to live JSPI beacons; eeschema-load's failure message no longer sends the developer to a deleted script; wait-beacons' dead families/parser deleted; lane-0 legacy-glue guards removed (lane 0 is unconstructible); the embind test.fail re-gated with the JSPI reason (plain embind invokers cannot suspend — verified still failing); lint-determinism now scans tests/jspi (166 files clean); eeschema-collab local-move gated to chromium (~50% flaky on FF even solo; pcbnew twin covers both engines). Docs: DEBUG.md rewritten as the JSPI debugging guide; build.md describes the single-phase build; docs/features/async/README.md banner-marked historical and repointed at the NEW 23-jspi-runtime.md (current architecture: export census, turnstile, libcontext ownership + refusal contract, embind call shapes, the em-pthread service-wrapper trick, exception policy, known gaps). Gates on the cleaned tree: test:e2e 725 passed / 0 failed (after the quiescence-probe fix; the 3 other reds were verified contention flakes solo-green or the documented FF gate), web 76/0, jspi 18/18 both engines, vitest 295/295 + 17/17, all lints green, live-app census clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016X9eh1s5sTx1o9Em9KBuwR
2026-08-14 09:25:32 +02:00
// which must be a fixture wire/track (the proven off-coroutine move path) —
// an apply-added text would no-op the virtual Move (a quirk found asyncify-era).
feat: v2 per-item s-expr collab bridge in all three tools (ysync 0008 Stage C) Add kicadCollabSnapshotItems / kicadCollabApplyItems / window.kicadCollab.onItems to pl_editor, eeschema, pcbnew — per-item native-blob payloads ({added/changed:[{sexpr,parent}], removed:[uuid]}) alongside the untouched scalar wire (legacy collab specs stay green). - pl_editor: itemBlob per item; apply = SetPageLayout(append) + replace-by-uuid (pointer-snapshot safe); bare payloads get the kicad_wks envelope. Snapshot + apply + emit verified headless. - eeschema: clipboard Format per item (symbols carry their lib_symbols); apply mirrors the native paste — LoadContent into a throwaway sheet → detach → replace-by-uuid → symbol lib relink (blob's lib_symbols first, live screen's second) → SCH_COMMIT, in the CallAfter+COROUTINE context. Snapshot + apply verified headless (a "lost" lone junction turned out to be correct connection cleanup — test uses text). - pcbnew: blobForItem per ROOT item with child→footprint lifting in flushDiff; apply = makeFromBlob + commit replace-by-uuid on the fiber; bare non-footprint payloads get wrapInBoardEnvelope (live board layer table). Snapshot + footprint replace/add WITH children (the 0004 containment gap, closed) + removal verified headless. Track/via/zone/text blob-apply hits the documented asyncify-fragile envelope parse (reconfirmed empirically — a verbatim SaveSelection segment envelope dies silently in the commit) and stays on the legacy scalar apply; tracked in ysync 0008 status. - eeschema/pcbnew scheduleFlush now runs flushDiff inside a COROUTINE: the per-item Format in the v2 emit needs the fiber stack (0007 lesson). Their emit remains unverifiable headless (both legacy two-tab tests are test.skip: "open=false → SCH_COMMIT no-ops" / "harness can't PAINT") — verify in the real app at Stage D; pl_editor's emit IS verified. - tests/kicad/items-bridge.spec.ts: per-tool suite (snapshot uuids → local-edit emit (where drivable) → apply changed/added/removed via save-readback → no apply echo). 3/3 pass; roundtrip + collab suites unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 13:55:15 +02:00
// Skipped when the harness can't drive the tool's emit (see ToolCfg).
if (cfg.localEdit) {
const editedUuid = (await page.evaluate(cfg.localEdit)) as string;
await expect
.poll(
async () =>
await page.evaluate(
() => (window as unknown as { __items: string[] }).__items.join("\n"),
),
{ timeout: 20000, intervals: [400] },
)
.toContain(editedUuid);
}
const emitsAfterLocalEdit = await page.evaluate(
() => (window as unknown as { __items: string[] }).__items.length,
);
// 4. applyItems: changed + added (bare blobs) + removed.
let changedSexpr: string;
if ("fromSnapshotUuid" in cfg.changed) {
const blob = snap.added
.map((w) => w.sexpr)
.find((s) => s.includes((cfg.changed as { fromSnapshotUuid: string }).fromSnapshotUuid));
expect(blob, "snapshot blob for the changed item").toBeTruthy();
const [from, to] = cfg.changed.replace;
expect(blob!, `blob contains "${from}"`).toContain(from);
changedSexpr = blob!.replace(from, to);
} else {
changedSexpr = cfg.changed.sexpr;
}
await page.evaluate(
({ changed, added, removed }) => {
window.Module.kicadCollabApplyItems(
JSON.stringify({ added: [{ sexpr: added }], changed: [{ sexpr: changed }], removed: [removed] }),
);
},
{ changed: changedSexpr, added: cfg.added.sexpr, removed: cfg.removedUuid },
);
await pollSaved(page, cfg, cfg.changed.marker);
await pollSaved(page, cfg, cfg.added.uuid);
await pollSaved(page, cfg, cfg.removedUuid, false);
// Remote applies must not have echoed an onItems emit.
const echoed = await page.evaluate(
() => (window as unknown as { __items: string[] }).__items.length,
);
expect(echoed, "apply must not emit onItems").toBe(emitsAfterLocalEdit);
expect(hasAbort(testLogger), "no WASM abort").toBe(false);
});
});
}