24 lines
4.0 KiB
TypeScript
24 lines
4.0 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
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-P17-002";
|
|
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/object-duplicate-production.json`;
|
|
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[\"operator:OBJECT_OT_duplicate\"]") as string[];
|
|
|
|
test("WBV2-P17-002 binds duplicateObject to compiled WASM Main", async ({ page }) => {
|
|
test.setTimeout(120_000); await page.goto("/");
|
|
const result = await page.evaluate(async (bytes) => {
|
|
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts"); const client = new WebEngineClient({ timeoutMs: 30_000 }); const reopened = new WebEngineClient({ timeoutMs: 30_000 });
|
|
const digest = async (value: ArrayBuffer): Promise<string> => { const hash = await crypto.subtle.digest("SHA-256", value); return Array.from(new Uint8Array(hash), (b) => b.toString(16).padStart(2, "0")).join(""); };
|
|
try { const opened = await client.openBlend(Uint8Array.from(bytes).buffer); const original = opened.snapshot.nodes.find((node) => node.id === opened.snapshot.activeObjectId && node.type === "MESH") ?? opened.snapshot.nodes.find((node) => node.type === "MESH"); if (!original) throw new Error("basic scene has no mesh object"); const beforeCount = opened.snapshot.nodes.length; const baseRevision = opened.snapshot.revision; const duplicated = await client.applyCommand({ type: "duplicateObject", objectId: original.id, offset: [2, 0, 0], linked: false } as any); const afterDuplicate = duplicated.snapshot; const duplicateNodes = afterDuplicate.nodes.filter((node) => node.type === "MESH"); const duplicate = duplicateNodes.find((node) => node.id !== original.id && Math.abs((node.translation?.[0] ?? 0) - ((original.translation?.[0] ?? 0) + 2)) < 1e-4); const undone = await client.applyCommand({ type: "undo" }); const redone = await client.applyCommand({ type: "redo" }); const malformed = await client.applyCommand({ type: "duplicateObject", objectId: "object:missing", offset: [1, 0, 0] } 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 reopen = await reopened.openBlend(saved); return { browser: "chromium", baseRevision, beforeCount, duplicateRevision: afterDuplicate.revision, undoRevision: undone.snapshot.revision, redoRevision: redone.snapshot.revision, afterCount: afterDuplicate.nodes.length, duplicateId: duplicate?.id, malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redone.snapshot.revision, reopenedCount: reopen.snapshot.nodes.length, reopenedRevision: reopen.snapshot.revision, savedSha256: await digest(saved) }; } 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_DUPLICATE_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.duplicateRevision).toBe(result.baseRevision + 1); expect(result.undoRevision).toBe(result.baseRevision + 2); expect(result.redoRevision).toBe(result.baseRevision + 3); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.malformedRevisionPreserved).toBe(true); expect(result.reopenedCount).toBe(result.afterCount); expect(result.reopenedRevision).toBe(1);
|
|
});
|