chore(web): continuous handoff WBV2-P1271-001
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
const root = path.resolve(import.meta.dirname, "../../..");
|
||||
const fixturePath = process.env.WBV2_BATCH_FIXTURE ?? "tests/files/web/basic_scene.blend";
|
||||
const fixture = fs.readFileSync(path.join(root, fixturePath));
|
||||
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
|
||||
const task = process.env.WBV2_BATCH_TASK ?? "WBV2-P20-002";
|
||||
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/collection-create-production.json`;
|
||||
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[\"operator:OBJECT_OT_collection_add\"]") as string[];
|
||||
|
||||
test("native collection create batch preserves Main recovery semantics", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
const result = await page.evaluate(async (bytes) => {
|
||||
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
|
||||
const client = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const reopened = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const name = "WBV2P2002Collection";
|
||||
try {
|
||||
const opened = await client.openBlend(Uint8Array.from(bytes).buffer);
|
||||
const baseRevision = opened.snapshot.revision;
|
||||
const beforeCount = opened.snapshot.collections.length;
|
||||
const parentCollectionId = opened.snapshot.scenes[0]?.rootCollectionId ?? null;
|
||||
const created = await client.applyCommand({ type: "createCollection", name, parentCollectionId } as any);
|
||||
const undo = await client.applyCommand({ type: "undo" });
|
||||
const redo = await client.applyCommand({ type: "redo" });
|
||||
const malformed = await client.applyCommand({ type: "createCollection", name: "", parentCollectionId: null } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
|
||||
const afterMalformed = await client.snapshot();
|
||||
const saved = await client.saveBlend();
|
||||
const restored = await reopened.openBlend(saved.slice(0));
|
||||
return { browser: "chromium", baseRevision, createRevision: created.snapshot.revision, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, beforeCount, afterCount: created.snapshot.collections.length, created: created.snapshot.collections.some((collection) => collection.name === name), restored: restored.snapshot.collections.some((collection) => collection.name === name), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, reopenedRevision: restored.snapshot.revision };
|
||||
} finally { client.terminate(); reopened.terminate(); }
|
||||
}, Array.from(fixture));
|
||||
fs.mkdirSync(path.dirname(path.join(root, productionPath)), { recursive: true });
|
||||
fs.writeFileSync(path.join(root, productionPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "COLLECTION_CREATE_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, fixture: fixturePath, fixtureSha256, sourceUnits, ...result }, null, 2)}\n`);
|
||||
expect(result.browser).toBe("chromium");
|
||||
expect(result.afterCount).toBe(result.beforeCount + 1);
|
||||
expect(result.createRevision).toBe(result.baseRevision + 1);
|
||||
expect(result.undoRevision).toBe(result.baseRevision + 2);
|
||||
expect(result.redoRevision).toBe(result.baseRevision + 3);
|
||||
expect(result.created).toBe(true);
|
||||
expect(result.restored).toBe(true);
|
||||
expect(result.malformed.code).not.toBe("NO_ERROR");
|
||||
expect(result.malformedRevisionPreserved).toBe(true);
|
||||
expect(result.reopenedRevision).toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user