Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-object-parent-production.spec.ts
mes123456 c21813334d
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
Advance deduplicated object parenting coverage
2026-08-28 14:58:10 +08:00

54 lines
3.7 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 fixture = fs.readFileSync(path.join(root, "tests/files/web/basic_scene.blend"));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
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.join(root, "tests/golden/WBV2-P19-002"), { recursive: true });
const output = process.env.WBV2_PARENT_REPORT ?? "object-parent-production.json";
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P19-002", output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P19-002", operation: "OBJECT_PARENT_ENGINE_CHROMIUM", queueMutation: false, fixtureSha256, ...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);
});