feat(web): authorize corrective smooth reader
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
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 = path.join(root, "tests/files/web/modifier_corrective_smooth_scene.blend");
|
||||
const fixture = fs.readFileSync(fixturePath);
|
||||
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
|
||||
|
||||
test("Corrective Smooth modifier metadata survives Blender Main save/reopen", async ({ page }) => {
|
||||
test.setTimeout(180_000);
|
||||
await page.goto("/");
|
||||
const result = await page.evaluate(async (bytes) => {
|
||||
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
|
||||
const canonical = (snapshot: any) => snapshot.meshes.flatMap((mesh: any) =>
|
||||
(mesh.modifierStack ?? []).map((modifier: any) => ({
|
||||
meshId: mesh.id,
|
||||
uuid: modifier.uuid,
|
||||
name: modifier.name,
|
||||
type: modifier.type,
|
||||
enabled: modifier.enabled,
|
||||
evaluationStatus: modifier.evaluationStatus,
|
||||
parameters: modifier.parameters ?? null,
|
||||
})));
|
||||
const client = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const deterministicClient = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const output: any = {};
|
||||
try {
|
||||
const opened = await client.openBlend(Uint8Array.from(bytes).buffer);
|
||||
output.before = canonical(opened.snapshot);
|
||||
output.target = output.before.find((modifier: any) => modifier.type === "CORRECTIVE_SMOOTH");
|
||||
const saved = await client.saveBlend();
|
||||
const reopened = await reopenedClient.openBlend(saved.slice(0));
|
||||
output.after = canonical(reopened.snapshot);
|
||||
const deterministic = await deterministicClient.openBlend(Uint8Array.from(bytes).buffer);
|
||||
output.deterministic = canonical(deterministic.snapshot);
|
||||
output.saveReopenExact = JSON.stringify(output.before) === JSON.stringify(output.after);
|
||||
output.deterministicExact = JSON.stringify(output.before) === JSON.stringify(output.deterministic);
|
||||
output.savedSha256 = await crypto.subtle.digest("SHA-256", saved).then((hash) =>
|
||||
Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""));
|
||||
try {
|
||||
await client.openBlend(Uint8Array.from([0x42, 0x4c, 0x45, 0x4e, 0x44]).buffer);
|
||||
output.malformed = { code: "ACCEPTED_MALFORMED" };
|
||||
} catch (error: any) {
|
||||
output.malformed = { code: error?.code, message: error?.message };
|
||||
}
|
||||
} catch (error: any) {
|
||||
output.error = { code: error?.code, message: error?.message, detail: String(error) };
|
||||
} finally {
|
||||
client.terminate();
|
||||
reopenedClient.terminate();
|
||||
deterministicClient.terminate();
|
||||
}
|
||||
return output;
|
||||
}, Array.from(fixture));
|
||||
|
||||
const report = {
|
||||
schemaVersion: 1,
|
||||
task: "WBV2-P1145-001",
|
||||
operation: "CORRECTIVE_SMOOTH_READER_CHROMIUM_SAVE_REOPEN",
|
||||
browser: "chromium",
|
||||
queueMutation: false,
|
||||
fixture: "tests/files/web/modifier_corrective_smooth_scene.blend",
|
||||
fixtureSha256,
|
||||
sourceUnits: ["modifier-source:MOD_correctivesmooth", "rna-struct:CorrectiveSmoothModifier"],
|
||||
...result,
|
||||
};
|
||||
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1145-001"), { recursive: true });
|
||||
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1145-001/corrective-smooth-production.json"), `${JSON.stringify(report, null, 2)}\n`);
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.target?.type).toBe("CORRECTIVE_SMOOTH");
|
||||
expect(result.saveReopenExact).toBe(true);
|
||||
expect(result.deterministicExact).toBe(true);
|
||||
expect(result.malformed?.code).not.toBe("ACCEPTED_MALFORMED");
|
||||
});
|
||||
Reference in New Issue
Block a user