57 lines
4.0 KiB
TypeScript
57 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-P19-002";
|
|
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/object-parent-production.json`;
|
|
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[\"operator:OBJECT_OT_parent_set\"]") as string[];
|
|
|
|
test("WBV2-P19-002 binds setParent 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 });
|
|
try {
|
|
const opened = await client.openBlend(Uint8Array.from(bytes).buffer);
|
|
const objects = opened.snapshot.nodes.filter((node) => ["MESH", "EMPTY", "LIGHT", "CAMERA"].includes(node.type));
|
|
if (objects.length < 2) throw new Error(`basic scene needs two object nodes; got ${opened.snapshot.nodes.map((node) => `${node.type}:${node.id}`).join(",")}`);
|
|
const child = objects[0];
|
|
const parent = objects[1];
|
|
const baseRevision = opened.snapshot.revision;
|
|
const changed = await client.applyCommand({ type: "setParent", objectId: child.id, parentId: parent.id, keepTransform: true } as any);
|
|
const childAfter = changed.snapshot.nodes.find((node) => node.id === child.id);
|
|
const undone = await client.applyCommand({ type: "undo" });
|
|
const redone = await client.applyCommand({ type: "redo" });
|
|
const malformed = await client.applyCommand({ type: "setParent", objectId: child.id, parentId: "object:missing", keepTransform: true } 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);
|
|
const childReopened = reopen.snapshot.nodes.find((node) => node.id === child.id);
|
|
const digest = async (value: ArrayBuffer) => { const hash = await crypto.subtle.digest("SHA-256", value); return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""); };
|
|
return { browser: "chromium", baseRevision, childId: child.id, parentId: parent.id, parentAfter: childAfter?.parentId, createRevision: changed.snapshot.revision, undoRevision: undone.snapshot.revision, redoRevision: redone.snapshot.revision, malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redone.snapshot.revision, reopenedParent: childReopened?.parentId, 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_PARENT_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, fixture: fixturePath, fixtureSha256, sourceUnits, ...result }, null, 2)}\n`);
|
|
expect(result.browser).toBe("chromium");
|
|
expect(result.parentAfter).toBe(result.parentId);
|
|
expect(result.createRevision).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.reopenedParent).toBe(result.parentId);
|
|
expect(result.reopenedRevision).toBe(1);
|
|
});
|