Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-modifier-parameter-production.spec.ts
mes123456 f18f80d0b9
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
Continue WBV2 module parity through P11
2026-08-28 05:50:14 +08:00

66 lines
5.3 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 evidenceRoot = path.join(root, "tests/golden/WBV2-P11-002");
const fixturePath = path.join(root, "tests/files/web/generated/WBV2-P4-001-MODIFIER.DECLARED_SLICES.blend");
const fixture = fs.readFileSync(fixturePath);
const sourceSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P11-002 applies a bounded Modifier parameter through compiled WASM Main", async ({ page }) => {
test.setTimeout(180_000);
await page.goto("/");
const result = await page.evaluate(async (input) => {
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
const summary = (snapshot: any, meshId: string) => {
const mesh = snapshot.meshes.find((candidate: any) => candidate.id === meshId);
if (!mesh) throw new Error(`mesh missing: ${meshId}`);
return { id: mesh.id, vertexCount: mesh.vertexCount, edgeCount: mesh.edgeCount, faceCount: mesh.faceCount, triangleCount: mesh.triangleCount, modifierStack: mesh.modifierStack?.map((modifier: any) => ({ uuid: modifier.uuid, type: modifier.type, enabled: modifier.enabled, evaluationStatus: modifier.evaluationStatus })) ?? [] };
};
const errorShape = (error: any) => ({ code: error?.code, message: error?.message });
const client = new WebEngineClient({ timeoutMs: 60_000 });
const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const mesh: any = opened.snapshot.meshes.find((candidate: any) => candidate.id === "mesh:WBV2P4001ModifierMesh");
const decimate: any = mesh?.modifierStack?.find((candidate: any) => candidate.type === "DECIMATE");
if (!mesh || !decimate) throw new Error("modifier fixture missing DECIMATE stack entry");
const before = summary(opened.snapshot, mesh.id);
let disabled = { snapshot: opened } as any;
for (const activeModifier of mesh.modifierStack?.filter((candidate: any) => candidate.enabled) ?? []) {
disabled = await client.applyCommand({ type: "setModifierEnabled", meshId: mesh.id, modifierUuid: activeModifier.uuid, enabled: false, baseRevision: disabled.snapshot.revision } as any);
}
const profile = { schemaVersion: 1 as const, sourceMeshRevision: disabled.snapshot.revision, mode: "COLLAPSE" as const, ratio: 0.75, iterations: 1, attributePolicy: "PRESERVE" as const, triangulate: false, useSymmetry: false };
const applied = await client.applyCommand({ type: "decimateMesh", meshId: mesh.id, profile } as any);
const after = summary(applied.snapshot, mesh.id);
const stale = await client.applyCommand({ type: "decimateMesh", meshId: mesh.id, profile } as any).then(() => ({ code: "NO_ERROR" })).catch(errorShape);
const afterStale = summary((await client.snapshot()).snapshot, mesh.id);
const malformed = await client.applyCommand({ type: "decimateMesh", meshId: mesh.id, profile: { ...profile, sourceMeshRevision: applied.snapshot.revision, ratio: 2 } } as any).then(() => ({ code: "NO_ERROR" })).catch(errorShape);
const afterMalformed = summary((await client.snapshot()).snapshot, mesh.id);
const saved = await client.saveBlend();
const savedSha256 = await (async () => { const hash = await crypto.subtle.digest("SHA-256", saved.slice(0)); return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""); })();
const reopened = await reopenedClient.openBlend(saved.slice(0));
const reopenedSummary = summary(reopened.snapshot, mesh.id);
return { sourceSha256: input.sourceSha256, meshId: mesh.id, modifierUuid: decimate.uuid, before, disabledRevision: disabled.snapshot.revision, appliedRevision: applied.snapshot.revision, simplify: applied.simplify, after, afterStale, afterMalformed, stale, malformed, savedSha256, reopened: reopenedSummary, exactSaveReopen: JSON.stringify(after) === JSON.stringify(reopenedSummary) && JSON.stringify(after) === JSON.stringify(afterStale) && JSON.stringify(after) === JSON.stringify(afterMalformed) };
}
finally { client.terminate(); reopenedClient.terminate(); }
}, { bytes: Array.from(fixture), sourceSha256 });
fs.mkdirSync(evidenceRoot, { recursive: true });
const output = process.env.WBV2_MODIFIER_PARAMETER_REPORT ?? "modifier-parameter-production.json";
fs.writeFileSync(path.join(evidenceRoot, output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P11-002", operation: "MODIFIER_PARAMETER_APPLY_FAMILY_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
expect(result.sourceSha256).toBe(sourceSha256);
expect(result.disabledRevision).toBe(4);
expect(result.appliedRevision).toBe(5);
expect(result.simplify?.status).toBe("applied");
expect(result.after.vertexCount).toBeLessThan(result.before.vertexCount);
expect(result.after.triangleCount).toBeLessThan(result.before.triangleCount);
expect(result.exactSaveReopen).toBe(true);
expect(result.stale.code).not.toBe("NO_ERROR");
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.afterStale).toEqual(result.after);
expect(result.afterMalformed).toEqual(result.after);
expect(result.savedSha256).not.toBe(sourceSha256);
});