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>
118 lines
6.0 KiB
TypeScript
118 lines
6.0 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/generated/WBV2-P4-003-SCULPT.NONMESH.PAINT_BOUNDED.blend"));
|
|
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
|
|
|
|
test("WBV2-P1133-001 preserves Curve spline 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 curve = snapshot.nonMeshData?.find((entry: any) => entry.id === dataId);
|
|
if (!curve) throw new Error(`curve missing: ${dataId}`);
|
|
return {
|
|
revision: snapshot.revision,
|
|
geometryStatus: curve.geometryStatus,
|
|
splineTypes: curve.splineTypes ? [...curve.splineTypes] : null,
|
|
splineOffsets: curve.splineOffsets ? [...curve.splineOffsets] : null,
|
|
pointWeights: curve.pointWeights ? [...curve.pointWeights] : null,
|
|
cyclicU: curve.cyclicU ? [...curve.cyclicU] : null,
|
|
};
|
|
};
|
|
try {
|
|
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
|
|
const curve = opened.snapshot.nonMeshData?.find((entry: any) => entry.type === "CURVE" && entry.splineTypes?.length && entry.pointCount >= 2);
|
|
if (!curve) throw new Error("fixture has no Curve spline metadata");
|
|
const dataId = curve.id as string;
|
|
const before = summary(opened.snapshot, dataId);
|
|
const pointCount = Number(curve.pointCount);
|
|
const splineTypes = [...curve.splineTypes];
|
|
const splineOffsets = [0, pointCount];
|
|
const ordersU = splineTypes.map(() => 0);
|
|
const controlPoints = Array.from({ length: pointCount * 3 }, (_, index) => (index % 3 === 0 ? index / 3 : 0));
|
|
const pointWeights = new Array(pointCount).fill(1);
|
|
const cyclicU = [...(curve.cyclicU ?? splineTypes.map(() => false))];
|
|
cyclicU[0] = !cyclicU[0];
|
|
const cyclicV = [...(curve.cyclicV ?? splineTypes.map(() => false))];
|
|
const edited = await client.applyCommand({
|
|
type: "setCurveSplines",
|
|
dataId,
|
|
baseRevision: opened.snapshot.revision,
|
|
splineTypes,
|
|
splineOffsets,
|
|
ordersU,
|
|
controlPoints,
|
|
pointWeights: [...pointWeights],
|
|
cyclicU,
|
|
cyclicV,
|
|
handleTypes: [...(curve.handleTypes ?? [])],
|
|
handlePoints: [...(curve.handlePoints ?? [])],
|
|
} as any);
|
|
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({
|
|
type: "setCurveSplines", dataId, baseRevision: redo.snapshot.revision - 1,
|
|
splineTypes, splineOffsets,
|
|
ordersU, controlPoints,
|
|
pointWeights: [...pointWeights], cyclicU, cyclicV,
|
|
handleTypes: [...(curve.handleTypes ?? [])], handlePoints: [...(curve.handlePoints ?? [])],
|
|
} as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
|
|
const malformed = await client.applyCommand({
|
|
type: "setCurveSplines", dataId, baseRevision: redo.snapshot.revision,
|
|
splineTypes, splineOffsets: [0, 1],
|
|
ordersU, controlPoints,
|
|
pointWeights: [...pointWeights], cyclicU, cyclicV,
|
|
handleTypes: [...(curve.handleTypes ?? [])], handlePoints: [...(curve.handlePoints ?? [])],
|
|
} as any).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-P1133-001"), { recursive: true });
|
|
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1133-001/curve-splines-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1133-001", operation: "CURVE_SPLINES_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
|
|
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.splineOffsets).toEqual(result.afterRedo.splineOffsets);
|
|
expect(result.afterReopen.revision).toBe(1);
|
|
expect(result.savedSha256).not.toBe(fixtureSha256);
|
|
});
|