Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-audio-particle-production.spec.ts
mes123456 f3e21c6b98
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
chore: checkpoint web Blender migration source, tools and docs
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>
2026-11-10 11:18:01 +08:00

105 lines
5.8 KiB
TypeScript

import { expect, test } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
const root = path.resolve(import.meta.dirname, "../../..");
const cases = [
{ kind: "particle", fixture: path.join(root, "tests/files/web/generated/M16-GAP-00018-datablock-ParticleSettings.blend") },
{ kind: "speaker", fixture: path.join(root, "tests/files/web/generated/M16-GAP-00023-datablock-Speaker.blend") },
{ kind: "sound", fixture: path.join(root, "tests/files/web/generated/M16-GAP-00023-datablock-Speaker.blend") },
] as const;
test("WBV2 audio and particle settings mutate Blender Main and survive recovery", async ({ page }) => {
test.setTimeout(90_000);
await page.goto("/");
const inputs = cases.map((item) => ({ ...item, bytes: Array.from(fs.readFileSync(item.fixture)) }));
const result = await page.evaluate(async (items) => {
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
const client = new WebEngineClient({ timeoutMs: 30_000 });
const reopened = new WebEngineClient({ timeoutMs: 30_000 });
try {
const reports = [];
for (const item of items) {
const opened = await client.openBlend(Uint8Array.from(item.bytes).buffer);
const collection = item.kind === "sound" ? opened.snapshot.sounds : item.kind === "speaker" ? opened.snapshot.speakers : opened.snapshot.particleSettings;
const target = collection?.[0];
if (!target) throw new Error(`missing ${item.kind} Main resource`);
const beforeRevision = opened.snapshot.revision;
const before = JSON.stringify(target);
const properties = item.kind === "sound"
? { volume: 0.75, attenuation: 0.25, pitch: 1.1, minGain: 0.2, maxGain: 0.9, distance: 12, offsetTime: 0.5 }
: item.kind === "speaker"
? { volumeMax: 2.5, volumeMin: 0.1, distanceMax: 42, distanceReference: 3, attenuation: 1.5, coneAngleOuter: 2.2, coneAngleInner: 1.1, coneVolumeOuter: 0.4, volume: 0.8, pitch: 1.2 }
: { type: 0, from: 1, distribution: 1, physicsType: 0, totalParticles: 128, start: 2, end: 80, lifetime: 12, size: 0.2, drawSize: 0.05 };
const command = item.kind === "particle"
? { type: "setParticleSettings" as const, dataId: target.id, properties }
: item.kind === "sound"
? { type: "setSoundProperties" as const, dataId: target.id, properties }
: { type: "setSpeakerProperties" as const, dataId: target.id, properties };
let edited;
try {
edited = await client.applyCommand(command);
}
catch (error) {
throw new Error(`${item.kind} apply failed: ${JSON.stringify(error)}`);
}
const undo = await client.applyCommand({ type: "undo" });
const redo = await client.applyCommand({ type: "redo" });
const malformed = await client.applyCommand({ ...command, properties: { unsupported: 1 } } as any)
.then(() => ({ code: "NO_ERROR" }))
.catch((error: any) => ({ code: error?.code ?? "UNKNOWN" }));
const afterMalformed = (await client.snapshot()).snapshot;
const saved = await client.saveBlend();
const reopenedResult = await reopened.openBlend(saved);
const reopenedCollection = item.kind === "sound" ? reopenedResult.snapshot.sounds : item.kind === "speaker" ? reopenedResult.snapshot.speakers : reopenedResult.snapshot.particleSettings;
reports.push({
kind: item.kind,
before,
beforeRevision,
editedRevision: edited.snapshot.revision,
undoRevision: undo.snapshot.revision,
redoRevision: redo.snapshot.revision,
edited: JSON.stringify((item.kind === "sound" ? edited.snapshot.sounds : item.kind === "speaker" ? edited.snapshot.speakers : edited.snapshot.particleSettings)?.find((entry) => entry.id === target.id)),
undo: JSON.stringify((item.kind === "sound" ? undo.snapshot.sounds : item.kind === "speaker" ? undo.snapshot.speakers : undo.snapshot.particleSettings)?.find((entry) => entry.id === target.id)),
redo: JSON.stringify((item.kind === "sound" ? redo.snapshot.sounds : item.kind === "speaker" ? redo.snapshot.speakers : redo.snapshot.particleSettings)?.find((entry) => entry.id === target.id)),
reopened: JSON.stringify(reopenedCollection?.find((entry) => entry.id === target.id)),
malformed,
malformedRevisionPreserved: afterMalformed.revision === redo.snapshot.revision,
});
}
return reports;
}
finally {
client.terminate();
reopened.terminate();
}
}, inputs);
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1105-000"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1105-000/audio-particle-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1105-000", operation: "AUDIO_PARTICLE_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, reports: result }, null, 2)}\n`);
expect(result).toHaveLength(3);
for (const report of result) {
const edited = JSON.parse(report.edited!);
if (report.kind === "sound") {
expect(edited.volume).toBeCloseTo(0.75);
expect(edited.pitch).toBeCloseTo(1.1);
}
else if (report.kind === "speaker") {
expect(edited.volume).toBeCloseTo(0.8);
expect(edited.pitch).toBeCloseTo(1.2);
}
else {
expect(edited.totalParticles).toBe(128);
expect(edited.lifetime).toBeCloseTo(12);
}
expect(report.editedRevision).toBe(report.beforeRevision + 1);
expect(report.undoRevision).toBe(report.beforeRevision + 2);
expect(report.redoRevision).toBe(report.beforeRevision + 3);
expect(report.undo).toBe(report.before);
expect(report.redo).toBe(report.edited);
expect(report.reopened).toBe(report.edited);
expect(report.malformed.code).not.toBe("NO_ERROR");
expect(report.malformedRevisionPreserved).toBe(true);
}
});