66 lines
4.5 KiB
TypeScript
66 lines
4.5 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const evidenceRoot = path.resolve(import.meta.dirname, "../../../tests/golden/WBV2-P9-001");
|
|
|
|
test("WBV2-P9-001 production Chromium Mesh receipt is exact and fail-closed", async ({ page }) => {
|
|
await page.goto("/");
|
|
const report = await page.evaluate(async () => {
|
|
const { CorrectiveHistoryStore, createMeshMain, createMeshRegistry } = await import("/src/corrective-pilot-bridge.ts");
|
|
const fixture = [{ id: "vertex:0", x: 1, y: 2, z: 3 }, { id: "vertex:1", x: 0, y: 0, z: 0 }];
|
|
const command = (overrides = {}) => ({
|
|
schemaVersion: 1,
|
|
requestId: "wbv2-p9-001-mesh-translate",
|
|
commandType: "meshTranslateVertex",
|
|
baseRevision: 9,
|
|
context: { mainId: "main:wbv2-p9-001", targetKind: "MESH", targetId: "mesh:cube", editMode: "EDITABLE", authorization: "USER_EDIT", source: { kind: "LOCAL", sha256: "b".repeat(64) } },
|
|
payload: { vertexId: "vertex:0", delta: { x: 0.5, y: -1, z: 2 } },
|
|
...overrides,
|
|
});
|
|
const clone = (value) => ({ vertices: value.vertices.map((vertex) => ({ ...vertex })) });
|
|
const desktopMain = createMeshMain(fixture, 9, false);
|
|
const wasmMain = createMeshMain(fixture, 9, false);
|
|
const desktop = await createMeshRegistry(desktopMain).dispatch("DESKTOP", { command: command(), mainRevision: 9 });
|
|
const wasm = await createMeshRegistry(wasmMain).dispatch("WASM", { command: command(), mainRevision: 9 });
|
|
|
|
const rollbackMain = createMeshMain(fixture, 9, false);
|
|
const rollbackRegistry = createMeshRegistry(rollbackMain);
|
|
const malformed = await rollbackRegistry.dispatch("DESKTOP", { command: command({ payload: { vertexId: "vertex:0", delta: { x: 0.5, y: -1, z: 2, w: 1 } } }), mainRevision: 9 });
|
|
const stale = await rollbackRegistry.dispatch("WASM", { command: command({ baseRevision: 8 }), mainRevision: 9 });
|
|
const unknown = await rollbackRegistry.dispatch("DESKTOP", { command: command({ payload: { vertexId: "vertex:missing", delta: { x: 0.5, y: -1, z: 2 } } }), mainRevision: 9 });
|
|
|
|
const history = new CorrectiveHistoryStore({ vertices: fixture }, 9, false, clone);
|
|
await createMeshRegistry(history).dispatch("WASM", { command: command(), mainRevision: 9 });
|
|
const saved = history.save();
|
|
const postSave = await createMeshRegistry(history).dispatch("DESKTOP", { command: command({ requestId: "wbv2-p9-001-mesh-post-save", baseRevision: 10, payload: { vertexId: "vertex:1", delta: { x: 4, y: 0, z: 0 } } }), mainRevision: 10 });
|
|
const beforeReopen = history.snapshot();
|
|
history.reopen();
|
|
const reopened = history.snapshot();
|
|
const exact = JSON.stringify(saved) === JSON.stringify(reopened);
|
|
return {
|
|
fixture,
|
|
positive: { desktop: desktop.result, wasm: wasm.result, desktopMain: desktopMain.snapshot(), wasmMain: wasmMain.snapshot(), parity: JSON.stringify(desktop.result) === JSON.stringify(wasm.result) && JSON.stringify(desktopMain.snapshot()) === JSON.stringify(wasmMain.snapshot()) },
|
|
negative: { malformed: malformed.result, stale: stale.result, unknown: unknown.result, rollbackMain: rollbackMain.snapshot() },
|
|
persistence: { saved, postSave: postSave.result, beforeReopen, reopened, exact },
|
|
};
|
|
});
|
|
fs.mkdirSync(evidenceRoot, { recursive: true });
|
|
const output = process.env.WBV2_MESH_PRODUCTION_REPORT ?? "chromium-mesh-production.json";
|
|
fs.writeFileSync(path.join(evidenceRoot, output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P9-001", operation: "MESH_PRODUCTION_CHROMIUM", browser: "chromium", queueMutation: false, ...report }, null, 2)}\n`);
|
|
|
|
expect(report.positive.parity).toBe(true);
|
|
expect(report.positive.desktop.status).toBe("FINISHED");
|
|
expect(report.positive.wasm.status).toBe("FINISHED");
|
|
expect(report.positive.desktop.delta).toEqual({ vertexId: "vertex:0", before: { x: 1, y: 2, z: 3 }, after: { x: 1.5, y: 1, z: 5 } });
|
|
expect(report.positive.desktop.mainRevisionBefore).toBe(9);
|
|
expect(report.positive.desktop.mainRevisionAfter).toBe(10);
|
|
expect(report.positive.wasm).toEqual(report.positive.desktop);
|
|
expect(report.persistence.exact).toBe(true);
|
|
expect(report.persistence.reopened).toEqual(report.persistence.saved);
|
|
expect(report.negative.malformed.code).toBe("COMMAND_MALFORMED");
|
|
expect(report.negative.stale.code).toBe("REVISION_CONFLICT");
|
|
expect(report.negative.unknown.code).toBe("COMMAND_UNSUPPORTED");
|
|
expect(report.negative.rollbackMain).toEqual({ value: { vertices: [{ id: "vertex:0", x: 1, y: 2, z: 3 }, { id: "vertex:1", x: 0, y: 0, z: 0 }] }, revision: 9, dirty: false });
|
|
});
|