Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-object-move-batch-production.spec.ts
mes123456 fe21be5f8b
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
chore(web): continuous handoff WBV2-P1274-001
2026-09-04 13:56:58 +08:00

50 lines
3.9 KiB
TypeScript

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/generated/WBV2-P24-001-OBJECT_OPERATIONS.MOVE_COLLECTION.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-P24-002";
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/object-move-production.json`;
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[\"operator:OBJECT_OT_move_to_collection\"]") as string[];
test("native object collection move 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 shape = (error: any) => ({ code: error?.code, message: error?.message });
try {
const opened = await client.openBlend(Uint8Array.from(bytes).buffer);
const source = opened.snapshot.collections.find((collection) => collection.name === "SourceCollection");
const target = opened.snapshot.collections.find((collection) => collection.name === "MoveTargetCollection");
const object = opened.snapshot.nodes.find((node) => node.name === "WBV2P2401Cube");
if (!source || !target || !object) throw new Error("move fixture is incomplete");
const changed = await client.applyCommand({ type: "moveObjectToCollection", objectId: object.id, collectionId: target.id } as any);
const undo = await client.applyCommand({ type: "undo" });
const redo = await client.applyCommand({ type: "redo" });
const malformed = await client.applyCommand({ type: "moveObjectToCollection", objectId: object.id, collectionId: "collection:missing" } as any).then(() => ({ code: "NO_ERROR" })).catch(shape);
const afterMalformed = await client.snapshot();
const saved = await client.saveBlend();
const restored = await reopened.openBlend(saved.slice(0));
return { browser: "chromium", baseRevision: opened.snapshot.revision, changedRevision: changed.snapshot.revision, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, moved: changed.snapshot.collections.find((collection) => collection.id === target.id)?.objectIds.includes(object.id), restoredTarget: restored.snapshot.collections.find((collection) => collection.id === target.id)?.objectIds.includes(object.id), restoredSource: restored.snapshot.collections.find((collection) => collection.id === source.id)?.objectIds.includes(object.id), 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: "OBJECT_MOVE_COLLECTION_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, fixture: fixturePath, fixtureSha256, sourceUnits, ...result }, null, 2)}\n`);
expect(result.browser).toBe("chromium");
expect(result.changedRevision).toBe(result.baseRevision + 1);
expect(result.undoRevision).toBe(result.baseRevision + 2);
expect(result.redoRevision).toBe(result.baseRevision + 3);
expect(result.moved).toBe(true);
expect(result.restoredTarget).toBe(true);
expect(result.restoredSource).toBe(false);
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.malformedRevisionPreserved).toBe(true);
expect(result.reopenedRevision).toBe(1);
});