68 lines
5.6 KiB
TypeScript
68 lines
5.6 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/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-P1103-000";
|
|
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/mesh-object-operations-production.json`;
|
|
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[]") as string[];
|
|
|
|
test("WBV2 mesh object operations preserve join and separate Main transactions", async ({ page }) => {
|
|
test.setTimeout(240_000);
|
|
await page.goto("/");
|
|
const result = await page.evaluate(async (input) => {
|
|
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
|
|
const client = new WebEngineClient({ timeoutMs: 60_000 });
|
|
const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
|
|
const meshSummary = (snapshot: any, meshId: string) => {
|
|
const mesh = snapshot.meshes?.find((entry: any) => entry.id === meshId);
|
|
if (!mesh) throw new Error(`mesh missing: ${meshId}`);
|
|
return { vertexCount: mesh.vertexCount, edgeCount: mesh.edgeCount, faceCount: mesh.faceCount, triangleCount: mesh.triangleCount };
|
|
};
|
|
try {
|
|
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
|
|
const original = opened.snapshot.nodes?.find((node: any) => node.type === "MESH");
|
|
if (!original) throw new Error("basic fixture has no mesh object");
|
|
const created = await client.applyCommand({ type: "createPrimitive", primitive: "CUBE", name: "WebJoinCube", location: [3, 0, 0] } as any);
|
|
const joinTarget = created.snapshot.nodes?.find((node: any) => node.name === "WebJoinCube");
|
|
if (!joinTarget?.dataId) throw new Error("join source was not created");
|
|
const beforeJoin = meshSummary(created.snapshot, original.dataId);
|
|
const joined = await client.applyCommand({ type: "joinObjects", activeObjectId: original.id, objectIds: [original.id, joinTarget.id] } as any);
|
|
const joinedState = { nodes: joined.snapshot.nodes.length, mesh: meshSummary(joined.snapshot, original.dataId) };
|
|
const joinUndo = await client.applyCommand({ type: "undo" } as any);
|
|
const joinRedo = await client.applyCommand({ type: "redo" } as any);
|
|
const separate = await client.applyCommand({ type: "separateMeshFaces", objectId: original.id, faceIndices: [0, 1], name: "WebSeparated" } as any);
|
|
const separated = separate.snapshot.nodes?.find((node: any) => node.name === "WebSeparated");
|
|
if (!separated?.dataId) throw new Error("separated object was not created");
|
|
const separateState = { original: meshSummary(separate.snapshot, original.dataId), separated: meshSummary(separate.snapshot, separated.dataId), nodeCount: separate.snapshot.nodes.length };
|
|
const malformed = await client.applyCommand({ type: "separateMeshFaces", objectId: original.id, faceIndices: [999] } 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 reopened = await reopenedClient.openBlend(saved.slice(0));
|
|
return { fixtureSha256: input.fixtureSha256, originalId: original.id, originalMeshId: original.dataId, beforeJoin, joined: joinedState, joinUndo: { nodes: joinUndo.snapshot.nodes.length, mesh: meshSummary(joinUndo.snapshot, original.dataId) }, joinRedo: { nodes: joinRedo.snapshot.nodes.length, mesh: meshSummary(joinRedo.snapshot, original.dataId) }, separate: separateState, malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === separate.snapshot.revision, reopenedSeparated: Boolean(reopened.snapshot.nodes?.some((node: any) => node.name === "WebSeparated")), reopenedRevision: reopened.snapshot.revision, savedSha256: await crypto.subtle.digest("SHA-256", saved).then((hash) => Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("")) };
|
|
}
|
|
catch (error: any) { return { error: { code: error?.code, message: error?.message, detail: String(error) } } as any; }
|
|
finally { client.terminate(); reopenedClient.terminate(); }
|
|
}, { bytes: Array.from(fixture), fixtureSha256 });
|
|
fs.mkdirSync(path.dirname(path.join(root, productionPath)), { recursive: true });
|
|
fs.writeFileSync(path.join(root, productionPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "MESH_OBJECT_OPERATIONS_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, fixture: fixturePath, fixtureSha256, sourceUnits, ...result }, null, 2)}\n`);
|
|
expect(result.error).toBeUndefined();
|
|
expect(result.fixtureSha256).toBe(fixtureSha256);
|
|
expect(result.joined.mesh.vertexCount).toBeGreaterThan(result.beforeJoin.vertexCount);
|
|
expect(result.joinUndo.nodes).toBe(result.joined.nodes + 1);
|
|
expect(result.joinRedo.nodes).toBe(result.joined.nodes);
|
|
expect(result.joinRedo.mesh.vertexCount).toBe(result.joined.mesh.vertexCount);
|
|
expect(result.separate.nodeCount).toBeGreaterThan(result.joined.nodes);
|
|
expect(result.separate.original.faceCount).toBeLessThan(result.joined.mesh.faceCount);
|
|
expect(result.separate.separated.faceCount).toBeGreaterThan(0);
|
|
expect(result.malformed.code).not.toBe("NO_ERROR");
|
|
expect(result.malformedRevisionPreserved).toBe(true);
|
|
expect(result.reopenedSeparated).toBe(true);
|
|
expect(result.reopenedRevision).toBe(1);
|
|
expect(result.savedSha256).not.toBe(fixtureSha256);
|
|
});
|