Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-surface-topology-production.spec.ts
mes123456 f3e21c6b98
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: checkpoint web Blender migration source, tools and docs
Accumulated uncommitted work: GHOST Web backend, WebGL/GPU web layer,
web workflow engine and protocol, tooling, docs and task records.
Large generated evidence, user-testing archives, build snapshots and
imported test assets remain untracked.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-10 11:18:01 +08:00

95 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 fixture = fs.readFileSync(path.join(root, "tests/files/web/nonmesh_scene.blend"));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P1134-001 preserves Surface topology transactions through Main recovery and reopen", async ({ page }) => {
test.setTimeout(120_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 summary = (snapshot: any, dataId: string) => {
const surface = snapshot.nonMeshData?.find((entry: any) => entry.id === dataId);
if (!surface) throw new Error(`surface missing: ${dataId}`);
return {
revision: snapshot.revision,
geometryStatus: surface.geometryStatus,
pointCount: surface.pointCount,
splineTypes: surface.splineTypes ? [...surface.splineTypes] : null,
splineDimensions: surface.splineDimensions ? surface.splineDimensions.map((item: any) => ({ ...item })) : null,
cyclicU: surface.cyclicU ? [...surface.cyclicU] : null,
cyclicV: surface.cyclicV ? [...surface.cyclicV] : null,
};
};
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const surface = opened.snapshot.nonMeshData?.find((entry: any) => entry.type === "SURFACE" && entry.splineDimensions?.length);
if (!surface) throw new Error("fixture has no Surface topology metadata");
const dataId = surface.id as string;
const before = summary(opened.snapshot, dataId);
const dimensions = surface.splineDimensions.map((item: any) => ({ u: item.u, v: item.v, orderU: item.orderU, orderV: item.orderV }));
const pointCount = dimensions.reduce((total: number, item: any) => total + item.u * item.v, 0);
const controlPoints = Array.from({ length: pointCount * 3 }, (_, index) => (index % 3 === 0 ? index / 3 : 0));
const pointWeights = new Array(pointCount).fill(1);
const cyclicU = [...(surface.cyclicU ?? dimensions.map(() => false))];
const cyclicV = [...(surface.cyclicV ?? dimensions.map(() => false))];
cyclicU[0] = !cyclicU[0];
const command = { type: "setSurfaceTopology", dataId, baseRevision: opened.snapshot.revision, splineDimensions: dimensions, controlPoints, pointWeights, cyclicU, cyclicV } as any;
const edited = await client.applyCommand(command);
const afterEdit = summary(edited.snapshot, dataId);
const undo = await client.applyCommand({ type: "undo" } as any);
const afterUndo = summary(undo.snapshot, dataId);
const redo = await client.applyCommand({ type: "redo" } as any);
const afterRedo = summary(redo.snapshot, dataId);
const stale = await client.applyCommand({ ...command, baseRevision: redo.snapshot.revision - 1 }).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const malformed = await client.applyCommand({ ...command, baseRevision: redo.snapshot.revision, splineDimensions: [{ ...dimensions[0], u: 1 }] }).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const afterNegative = summary((await client.snapshot()).snapshot, dataId);
const saved = await client.saveBlend();
const reopened = await reopenedClient.openBlend(saved.slice(0));
const afterReopen = summary(reopened.snapshot, dataId);
return {
fixtureSha256: input.fixtureSha256,
dataId,
before,
afterEdit,
afterUndo,
afterRedo,
stale,
malformed,
afterNegative,
afterReopen,
savedSha256: await crypto.subtle.digest("SHA-256", saved).then((bytes) => Array.from(new Uint8Array(bytes), (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.join(root, "tests/golden/WBV2-P1134-001"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1134-001/surface-topology-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1134-001", operation: "SURFACE_TOPOLOGY_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
expect(result.error).toBeUndefined();
expect(result.fixtureSha256).toBe(fixtureSha256);
expect(result.afterEdit.revision).toBe(result.before.revision + 1);
expect(result.afterEdit.cyclicU).not.toEqual(result.before.cyclicU);
expect(result.afterUndo.cyclicU).toEqual(result.before.cyclicU);
expect(result.afterRedo.cyclicU).toEqual(result.afterEdit.cyclicU);
expect(result.stale.code).not.toBe("NO_ERROR");
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.afterNegative).toEqual(result.afterRedo);
expect(result.afterReopen.cyclicU).toEqual(result.afterRedo.cyclicU);
expect(result.afterReopen.cyclicV).toEqual(result.afterRedo.cyclicV);
expect(result.afterReopen.splineDimensions).toEqual(result.afterRedo.splineDimensions);
expect(result.afterReopen.revision).toBe(1);
expect(result.savedSha256).not.toBe(fixtureSha256);
});