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>
85 lines
7.8 KiB
TypeScript
85 lines
7.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 fixture = fs.readFileSync(path.join(root, "tests/files/web/nonmesh_scene.blend"));
|
|
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
|
|
|
|
test("WBV2 curve and surface advanced commands preserve native Main state", 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 timings: { stage: string; seconds: number }[] = [];
|
|
const measured = async <T>(stage: string, action: () => Promise<T>) => {
|
|
const started = performance.now();
|
|
try { return await action(); } finally { timings.push({ stage, seconds: (performance.now() - started) / 1000 }); }
|
|
};
|
|
const hash = (value: unknown) => crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(value))).then((bytes) => Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join(""));
|
|
const summary = (snapshot: any) => snapshot.nonMeshData?.map((entry: any) => ({ id: entry.id, type: entry.type, pointCount: entry.pointCount, resolution: entry.resolution, bevelDepth: entry.bevelDepth, bevelResolution: entry.bevelResolution, taperObjectId: entry.taperObjectId, splineDimensions: entry.splineDimensions })).sort((a: any, b: any) => a.id.localeCompare(b.id));
|
|
const open = async () => {
|
|
const client = new WebEngineClient({ timeoutMs: 60_000 });
|
|
const opened = await measured("open", () => client.openBlend(Uint8Array.from(input.bytes).buffer));
|
|
return { client, opened, curve: opened.snapshot.nonMeshData?.find((entry: any) => entry.type === "CURVE"), surface: opened.snapshot.nonMeshData?.find((entry: any) => entry.type === "SURFACE") };
|
|
};
|
|
try {
|
|
const primary = await open();
|
|
if (!primary.curve || !primary.surface) throw new Error("fixture must contain both Curve and Surface data");
|
|
const before = summary(primary.opened.snapshot);
|
|
const curveId = primary.curve.id as string;
|
|
const surfaceId = primary.surface.id as string;
|
|
const beveled = await measured("setCurveBevel", () => primary.client.applyCommand({ type: "setCurveBevel", dataId: curveId, bevelDepth: 0.1, bevelResolution: 4, bevelFactorStart: 0, bevelFactorEnd: 1 } as any));
|
|
const tapered = await measured("setCurveTaper", () => primary.client.applyCommand({ type: "setCurveTaper", dataId: curveId, taperObjectId: null, taperRadiusMode: 0 } as any));
|
|
const converted = await measured("convertCurveType", () => primary.client.applyCommand({ type: "convertCurveType", dataId: curveId, targetType: "SURFACE" } as any));
|
|
const convertedId = converted.snapshot.nonMeshData?.find((entry: any) => entry.id === curveId)?.id ?? surfaceId;
|
|
const resolved = await measured("setSurfaceResolution", () => primary.client.applyCommand({ type: "setSurfaceResolution", dataId: convertedId, resolutionU: 16, resolutionV: 16 } as any));
|
|
const after = summary(resolved.snapshot);
|
|
const negative = await primary.client.applyCommand({ type: "setCurveBevel", dataId: curveId, bevelDepth: -1 } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
|
|
const afterNegative = summary((await primary.client.snapshot()).snapshot);
|
|
const undoClient = await open();
|
|
const undoBefore = summary(undoClient.opened.snapshot);
|
|
const undoEdit = await undoClient.client.applyCommand({ type: "setSurfaceResolution", dataId: undoClient.surface.id, resolutionU: 13, resolutionV: 13 } as any);
|
|
const undo = await undoClient.client.applyCommand({ type: "undo" } as any);
|
|
const redo = await undoClient.client.applyCommand({ type: "redo" } as any);
|
|
const save = await measured("save", () => undoClient.client.saveBlend());
|
|
const reopenClient = new WebEngineClient({ timeoutMs: 60_000 });
|
|
const reopened = await measured("reopen", () => reopenClient.openBlend(save.slice(0)));
|
|
const deterministicClient = await open();
|
|
const deterministicEdit = await deterministicClient.client.applyCommand({ type: "setCurveBevel", dataId: deterministicClient.curve.id, bevelDepth: 0.1, bevelResolution: 4, bevelFactorStart: 0, bevelFactorEnd: 1 } as any);
|
|
const observations = {
|
|
positive: { before: await hash(before), after: await hash(after) },
|
|
negative: { before: await hash(after), after: await hash(afterNegative) },
|
|
undo_redo: { before: await hash(undoBefore), after: await hash(summary(undoEdit.snapshot)), undo: await hash(summary(undo.snapshot)), redo: await hash(summary(redo.snapshot)) },
|
|
save_reopen: { saved: await hash(summary(undoEdit.snapshot)), reopened: await hash(summary(reopened.snapshot)) },
|
|
determinism: { first: await hash(summary(beveled.snapshot)), second: await hash(summary(deterministicEdit.snapshot)) },
|
|
};
|
|
return { fixtureSha256: input.fixtureSha256, timings, observations, negative, before, after, afterNegative, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, reopened: summary(reopened.snapshot), savedSha256: await hash(Array.from(new Uint8Array(save))) };
|
|
} catch (error: any) {
|
|
return { error: { code: error?.code, message: error?.message, detail: String(error) }, timings } as any;
|
|
}
|
|
}, { bytes: Array.from(fixture), fixtureSha256 });
|
|
const receiptDir = process.env.WBV2_RECEIPT_DIR;
|
|
const outputDir = receiptDir ?? path.join(root, "tests/golden/WBV2-P1424-001/curve-surface");
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
fs.writeFileSync(path.join(outputDir, "curve-surface-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1424-001", operation: "CURVE_SURFACE_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
|
|
if (receiptDir && !result.error) {
|
|
const artifacts = ["build_blender_native/bin/blender", "build_web_blender6/bin/web_engine.wasm", "tests/files/web/nonmesh_scene.blend"].map((file) => ({ path: file, sha256: crypto.createHash("sha256").update(fs.readFileSync(path.join(root, file))).digest("hex") }));
|
|
const units = {
|
|
positive: ["web-command:setCurveBevel", "web-command:setCurveTaper", "web-command:convertCurveType", "web-command:setSurfaceResolution"],
|
|
negative: ["web-command:setCurveBevel"], undo_redo: ["web-command:setSurfaceResolution"], save_reopen: ["web-command:setSurfaceResolution"], determinism: ["web-command:setCurveBevel"],
|
|
} as const;
|
|
for (const [kind, observations] of Object.entries(result.observations)) fs.writeFileSync(path.join(receiptDir, `curve-surface-${kind}.json`), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1424-001", operation: "CURVE_SURFACE_MAIN_CHROMIUM", browser: "chromium", runtime: "CHROMIUM_WEBENGINE", queueMutation: false, status: "PASS", caseId: `curve-surface-${kind}`, kind, unitIds: units[kind as keyof typeof units], observations, artifacts, timings: result.timings }, null, 2)}\n`);
|
|
}
|
|
expect(result.error).toBeUndefined();
|
|
expect(result.fixtureSha256).toBe(fixtureSha256);
|
|
expect(result.negative.code).not.toBe("NO_ERROR");
|
|
expect(result.observations.positive.after).not.toBe(result.observations.positive.before);
|
|
expect(result.observations.negative.after).toBe(result.observations.negative.before);
|
|
expect(result.observations.undo_redo.undo).toBe(result.observations.undo_redo.before);
|
|
expect(result.observations.undo_redo.redo).toBe(result.observations.undo_redo.after);
|
|
expect(result.observations.save_reopen.reopened).toBe(result.observations.save_reopen.saved);
|
|
expect(result.observations.determinism.first).toBe(result.observations.determinism.second);
|
|
});
|