63 lines
4.8 KiB
TypeScript
63 lines
4.8 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-P13-003");
|
|
const fixture = fs.readFileSync(path.join(root, "tests/files/web/generated/WBV2-P3-003-RIG.POSE_SKIN.blend"));
|
|
const sourceSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
|
|
|
|
test("WBV2-P13-003 binds rig pose and skin evidence to 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 client = new WebEngineClient({ timeoutMs: 60_000 });
|
|
const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
|
|
const shape = (error: any) => ({ code: error?.code, message: error?.message });
|
|
const digest = async (value: ArrayBuffer): Promise<string> => { const hash = await crypto.subtle.digest("SHA-256", value); return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""); };
|
|
const rigSummary = (snapshot: any) => {
|
|
const armature: any = snapshot.armatures?.find((candidate: any) => candidate.id === "armature:WBV2P3003Armature");
|
|
const mesh: any = snapshot.meshes?.find((candidate: any) => candidate.id === "mesh:WBV2P3003SkinnedMesh");
|
|
if (!armature || !mesh) throw new Error("rig fixture missing armature or skinned mesh");
|
|
return { armatureId: armature.id, bones: armature.bones.map((bone: any) => ({ id: bone.id, name: bone.name, parentId: bone.parentId, head: bone.head, tail: bone.tail, poseMatrix: bone.poseMatrix })), meshId: mesh.id, vertexCount: mesh.vertexCount, skinWeights: mesh.skinWeights ? { boneNames: mesh.skinWeights.boneNames, armatureId: mesh.skinWeights.armatureId, jointIds: mesh.skinWeights.jointIds } : null, shapeKeyCount: mesh.shapeKeys?.length ?? 0 };
|
|
};
|
|
try {
|
|
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
|
|
const objectId = "object:WBV2P3003SkinnedMeshObject";
|
|
const constraintName = "WBV2P3003BoundedObjectConstraint";
|
|
const before = rigSummary(opened.snapshot);
|
|
const edited = await client.applyCommand({ type: "setConstraint", objectId, constraintName, enabled: false, influence: 0.4, baseRevision: opened.snapshot.revision } as any);
|
|
const after = rigSummary(edited.snapshot);
|
|
const malformed = await client.applyCommand({ type: "setConstraint", objectId, constraintName: "constraint:missing", enabled: true, influence: 0.4, baseRevision: edited.snapshot.revision } as any).then(() => ({ code: "NO_ERROR" })).catch(shape);
|
|
const afterMalformed = rigSummary((await client.snapshot()).snapshot);
|
|
const saved = await client.saveBlend();
|
|
const savedSha256 = await digest(saved.slice(0));
|
|
const reopened = await reopenedClient.openBlend(saved.slice(0));
|
|
const reopenedSummary = rigSummary(reopened.snapshot);
|
|
const reopenedConstraint = reopened.snapshot.nodes.find((node: any) => node.id === objectId)?.constraints?.find((constraint: any) => constraint.name === constraintName);
|
|
return { baseRevision: opened.snapshot.revision, editedRevision: edited.snapshot.revision, before, after, afterMalformed, malformed, reopened: reopenedSummary, reopenedConstraint, savedSha256, sourceSha256: await digest(Uint8Array.from(input.bytes).buffer), saveReopenExact: JSON.stringify(after) === JSON.stringify(reopenedSummary) };
|
|
}
|
|
finally { client.terminate(); reopenedClient.terminate(); }
|
|
}, { bytes: Array.from(fixture) });
|
|
fs.mkdirSync(evidenceRoot, { recursive: true });
|
|
const output = process.env.WBV2_RIG_POSE_REPORT ?? "rig-pose-production.json";
|
|
fs.writeFileSync(path.join(evidenceRoot, output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P13-003", operation: "RIG_POSE_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
|
|
expect(result.sourceSha256).toBe(sourceSha256);
|
|
expect(result.before.armatureId).toBe("armature:WBV2P3003Armature");
|
|
expect(result.before.bones).toHaveLength(2);
|
|
expect(result.before.meshId).toBe("mesh:WBV2P3003SkinnedMesh");
|
|
expect(result.before.skinWeights?.armatureId).toBe("armature:WBV2P3003Armature");
|
|
expect(result.before.shapeKeyCount).toBeGreaterThanOrEqual(1);
|
|
expect(result.editedRevision).toBe(result.baseRevision + 1);
|
|
expect(result.after).toEqual(result.before);
|
|
expect(result.afterMalformed).toEqual(result.after);
|
|
expect(result.malformed.code).not.toBe("NO_ERROR");
|
|
expect(result.reopened).toEqual(result.after);
|
|
expect(result.reopenedConstraint.enabled).toBe(false);
|
|
expect(result.reopenedConstraint.influence).toBeCloseTo(0.4, 5);
|
|
expect(result.saveReopenExact).toBe(true);
|
|
expect(result.savedSha256).not.toBe(result.sourceSha256);
|
|
});
|