test(web): simplify suite console assertions filter the Emscripten syscall stub
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

__syscall_mprotect is a debug-libc stub returning success; record it as
consoleNoise and keep productConsoleErrors strict, with a reverse case.
Also align the suite with current entries: Outliner selection, the manual
下载 .blend download (OPFS saves no longer download), the ratio > 0
contract, and scene-only snapshot comparisons.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-29 05:10:19 +08:00
parent 390d487eb8
commit 68b19d37dc
3 changed files with 116 additions and 35 deletions

View File

@@ -468,3 +468,26 @@ Web 视图里在大纲中 Ctrl+点击选中两个对象后,原生选择被覆
**5. 声明**
- `acceptance: NOT_CLAIMED`:单次有头通过只代表该候选、该环境,不给出整体完成度。
---
### mesh-simplify 控制台断言残余关闭(回执 simplify-console-20261129)
**1. 归因(用历史回执代替重新编译的 A/B)**
- `tests/golden/WBV2-P1424-001/lod-recovery-20261021/` 的 10 份历史回执(早于 decimate 改动)全部 `status: failed`,`consoleErrors` 均为同样的两条 `warning: unsupported syscall: __syscall_mprotect`;`tests/golden/WBV2-P1424-001/mesh-simplify-20261020/` 无 console 失败。据此该失败早于本轮引擎改动,无需回退打标代码做 A/B。
- 该行来自 Emscripten 调试版 libc 的系统调用桩 `.emsdk/upstream/emscripten/system/lib/libc/emscripten_syscall_stubs.c`:`__syscall_mprotect` 只在非 NDEBUG 构建 `REPORT`,并 `return 0`(注释 "let's not and say we did")。调用方拿到成功,无可观察功能影响。
- 运行时探针(Playwright + 生产候选):两条消息分别出现在引擎 WASM 模块两次实例化期间、场景解析之前,与 Decimate 计算无关。
**2. 测试修正(`web/tests/e2e/mesh-simplify-production.spec.ts`)**
- 新增 `RUNTIME_STUB_NOISE` 窄过滤(仅 `warning: unsupported syscall: __syscall_<name>`),断言改用 `productErrors`;回执保留原始 `consoleErrors` 并新增 `consoleNoise` / `productConsoleErrors`。
- 新增反向用例 `console noise filter keeps real product errors`:桩消息被过滤,注入的真实 `console.error` 仍被捕获。
- 同批修正测试与当前产品入口的漂移:Outliner 树节点选择(视口侧栏同名节点引发 strict 冲突);保存改用「下载 .blend」入口(OPFS 保存不再自动下载,`saveBlend()` 仍先落 OPFS);COLLAPSE 比例 0 按 `protocol/simplify.ts:188` 与引擎 `ratio <= 0` 契约断言拒绝;快照比较剔除编辑器会话状态;项目动作锁未释放时按提示重试应用。
**3. 结果**
- `web/tests/e2e/mesh-simplify-production.spec.ts` 12 例全部通过;回执目录 `tests/golden/WBV2-P1424-001/simplify-console-20261129/`;候选 `web_engine.wasm` sha256 `f0a528ae44be8335d4c340bcc5d08ffb1e450b9e5420318dba50370d4fab8280`。
- 每份通过回执 `consoleNoise` 非空、`productConsoleErrors` 为空;反向用例回执含 2 条注入错误。
- 本批只跑该文件;配置内其余 3 个 spec(`mesh-lod-reader-production`、`object-hierarchy-production`、`hierarchy-simplify-combined`)未在本批运行。
- `acceptance: NOT_CLAIMED`:单次、单候选、单环境结果,不给整体完成度。

View File

@@ -118,4 +118,4 @@ node tools/web/generate-decimate-golden.mjs \
### 残余补充
- 用例证据 JSON 由运行器归档到回执 `artifacts/evidence/`;Playwright 仅对失败用例保留附件路径,运行器按本次运行时间过滤 `web/test-results/**/decimate-*.json` 复制。
- `web/tests/e2e/mesh-simplify-production.spec.ts` 当前失败于「控制台错误必须为空」断言(记录里只有 `warning: unsupported syscall: __syscall_mprotect`),几何断言通过;与本次改动的关系未做 A/B 归因,单独排查。
- `web/tests/e2e/mesh-simplify-production.spec.ts` 控制台断言残余**已关闭**(回执 `tests/golden/WBV2-P1424-001/simplify-console-20261129`,候选 wasm `f0a528ae…`,12 例通过):`__syscall_mprotect` 是 Emscripten 调试版 libc 的系统调用桩(`return 0`,仅非 NDEBUG 打印),按窄规则过滤且原始文本仍进回执;同批修正 Outliner 选择器、OPFS 保存改走「下载 .blend」入口、COLLAPSE 比例 0 契约与快照会话状态比较。

View File

@@ -18,6 +18,30 @@ type LODObservation = { manifest: { meshId: string; sourceMeshRevision: number }
type Wire = { requestId: string; ok: boolean; result?: { snapshot?: Snapshot; simplify?: SimplifyResult; lod?: LODObservation; projectId?: string; cacheKey?: string; bytes?: number; dataBase64?: string; manifest?: LODCacheRecord; manifests?: LODCacheRecord[]; remainingBytes?: number }; error?: unknown; errorCode?: string };
type Record = { started: number; chrome: string; failures: string[]; errors: string[]; modules: { url: string; sha256: string }[]; wire: Wire[]; fixture?: { path: string; sha256: string }; isolated?: boolean };
const records = new WeakMap<Page, Record>();
/* Emscripten's debug libc reports unimplemented syscalls on stderr, which the
* worker surfaces as a console error. __syscall_mprotect is a no-op returning
* success ("let's not and say we did", emscripten_system_stubs.c), so the line
* is runtime noise with no observable product effect. Raw text stays in the
* receipt under consoleErrors; only the assertion uses this filter. */
const RUNTIME_STUB_NOISE = /^warning: unsupported syscall: __syscall_[a-z0-9_]+$/;
const runtimeNoise = (record: Record) => record.errors.filter(text => RUNTIME_STUB_NOISE.test(text.trim()));
const productErrors = (record: Record) => record.errors.filter(text => !RUNTIME_STUB_NOISE.test(text.trim()));
/* Snapshots carry session bookkeeping -- revision counters on every datablock,
* editor focus, window-manager region flags -- that UI actions move without
* touching scene data. Scene comparisons drop those. */
const sceneState = (value: unknown) => {
const clone = JSON.parse(JSON.stringify(value ?? null));
const scrub = (node: unknown) => {
if (!node || typeof node !== 'object') return;
if (Array.isArray(node)) { node.forEach(scrub); return; }
const record = node as Record<string, unknown>;
delete record.revision;
for (const key of Object.keys(record)) scrub(record[key]);
};
scrub(clone);
if (clone && typeof clone === 'object' && !Array.isArray(clone)) { delete (clone as Record<string, unknown>).editorWorkflow; delete (clone as Record<string, unknown>).windowManager; }
return clone;
};
test.beforeEach(async ({ page, browser }) => {
const record: Record = { started: Date.now(), chrome: browser.version(), failures: [], errors: [], modules: [], wire: [] }; records.set(page, record);
page.on('requestfailed', request => record.failures.push(`${request.url()}: ${request.failure()?.errorText}`));
@@ -48,14 +72,14 @@ test.beforeEach(async ({ page, browser }) => {
const latest = (page: Page) => records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).at(-1)!.result!.snapshot!;
test('high triangle simplified GLB preserves corner normals', async ({ page }) => {
await openFixture(page,path.join(root,'tests/files/web/mesh_simplify_high.blend')); await selectFixtureObject(page); await page.getByRole('button',{name:'应用 Decimate',exact:true}).click(); await expect(page.getByTestId('simplify-triangle-counts')).toHaveText('三角形 16128 → 8064',{timeout:60_000}); const before=latest(page), downloads: {path:string;sha256:string}[]=[];
for (const [label,extension] of [['保存项目','blend'],['导出 GLB','glb']]) { const download=page.waitForEvent('download',{timeout:60_000}); await page.getByRole('button',{name:label,exact:true}).click(); const file=path.join(evidence,`${records.get(page)!.started}-high-normal.${extension}`); await (await download).saveAs(file); downloads.push({path:file,sha256:sha256(file)}); }
expect((await productionRequest(page,'engine','lod-high-glb-unchanged',{type:'snapshot'})).result?.snapshot).toEqual(before); Object.assign(records.get(page)!,{downloads,exportStatus:await page.getByTestId('engine-status').getAttribute('title')}); expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
for (const [label,extension] of [['下载 .blend','blend'],['导出 GLB','glb']]) { const download=page.waitForEvent('download',{timeout:60_000}); await page.getByRole('button',{name:label,exact:true}).click(); const file=path.join(evidence,`${records.get(page)!.started}-high-normal.${extension}`); await (await download).saveAs(file); downloads.push({path:file,sha256:sha256(file)}); }
expect((await productionRequest(page,'engine','lod-high-glb-unchanged',{type:'snapshot'})).result?.snapshot).toEqual(before); Object.assign(records.get(page)!,{downloads,exportStatus:await page.getByTestId('engine-status').getAttribute('title')}); expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
test('LOD cache survives Worker restart and rejects stale or corrupt recovery data', async ({ page }) => {
const oracle = JSON.parse(fs.readFileSync(path.join(lodBaseline, 'desktop-lod.json'), 'utf8')); const savedFiles: string[] = [];
await openFixture(page, path.join(root, 'tests/files/web/mesh_simplify_high.blend')); await selectFixtureObject(page);
await page.getByRole('button', { name: '应用 Decimate', exact: true }).click(); await expect(page.getByTestId('simplify-triangle-counts')).toHaveText('三角形 16128 → 8064', { timeout: 60_000 }); const source = latest(page);
const save = async (name: string) => { const download = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目', exact: true }).click(); const file = path.join(evidence, `${records.get(page)!.started}-${name}.blend`); await (await download).saveAs(file); savedFiles.push(file); return file; };
const save = async (name: string) => { const download = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click(); const file = path.join(evidence, `${records.get(page)!.started}-${name}.blend`); await (await download).saveAs(file); savedFiles.push(file); return file; };
await page.getByRole('button', { name: '生成 LOD', exact: true }).click(); await expect(page.getByTestId('simplify-cache-status')).toHaveText('LOD 缓存:已加载 3 级', { timeout: 90_000 });
const stored = records.get(page)!.wire.find(event=>event.result?.cacheKey && event.result?.bytes)!.result!, projectId = stored.projectId!, cacheKey = stored.cacheKey!;
const manifest = (await productionRequest(page,'storage','lod-recovery-manifest',{type:'getLODManifest',projectId,cacheKey})).result!.manifest!;
@@ -87,20 +111,20 @@ test('LOD cache survives Worker restart and rejects stale or corrupt recovery da
expect((await productionRequest(page,'storage','lod-recovery-pruned-list',{type:'listLODManifests',projectId})).result!.manifests).toEqual([]); expect((await productionRequest(page,'storage','lod-recovery-pruned-read',{type:'readLOD',projectId,cacheKey})).ok).toBe(false);
await recover(false); await save('lod-recovery-after');
delete cached.dataBase64; Object.assign(records.get(page)!,{ recoveries:recovery, staleAndLegacyRejected:true, parseableCorruptionRejected:true, cacheRestoredAfterRepair:true, prunedCacheMissing:true, downloads:savedFiles.map(file=>({path:file,sha256:sha256(file)})) });
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
test('pending preview cancellation discards a delayed native result', async ({ page }) => {
await page.addInitScript(() => { const NativeWorker = window.Worker; window.Worker = class extends NativeWorker { constructor(url: string | URL, options?: WorkerOptions) { super(url,options); const state = window as unknown as { __heldPreview?: unknown; __releasePreview?: () => void }; const worker = this; const hold = (event: MessageEvent) => { if (!event.data.result?.simplify) return; event.stopImmediatePropagation(); worker.removeEventListener('message',hold); state.__heldPreview = event.data; state.__releasePreview = () => worker.dispatchEvent(new MessageEvent('message',{data:state.__heldPreview})); }; worker.addEventListener('message',hold); } }; });
await openFixture(page, path.join(root, 'tests/files/web/mesh_simplify_high.blend')); await selectFixtureObject(page); const before = latest(page);
const beforeDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目', exact: true }).click(); const beforeFile = path.join(evidence, `${records.get(page)!.started}-pending-before.blend`); await (await beforeDownload).saveAs(beforeFile);
const beforeDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click(); const beforeFile = path.join(evidence, `${records.get(page)!.started}-pending-before.blend`); await (await beforeDownload).saveAs(beforeFile);
await page.getByRole('button', { name: '预览 Decimate', exact: true }).click(); await expect(page.getByRole('button', { name: '取消 Decimate 预览', exact: true })).toBeVisible();
await expect.poll(() => page.evaluate(() => Boolean((window as unknown as { __heldPreview?: unknown }).__heldPreview)), { timeout: 60_000 }).toBe(true);
await expect(page.getByTestId('simplify-report-empty')).toBeVisible(); await expect(page.getByTestId('engine-status')).not.toContainText('Preview');
await page.getByRole('button', { name: '取消 Decimate 预览', exact: true }).click(); await page.evaluate(() => (window as unknown as { __releasePreview: () => void }).__releasePreview());
const after = await productionRequest(page, 'engine', 'lod-cancel-delayed-after', { type: 'snapshot' }); expect(after.result?.snapshot).toEqual(before);
await expect(page.getByTestId('simplify-report-empty')).toBeVisible(); await expect(page.getByRole('button', { name: '取消 Decimate 预览', exact: true })).toHaveCount(0); await expect(page.getByTestId('engine-status')).not.toContainText('Preview');
const afterDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目', exact: true }).click(); const afterFile = path.join(evidence, `${records.get(page)!.started}-pending-after.blend`); await (await afterDownload).saveAs(afterFile); expect(sha256(afterFile)).toBe(sha256(beforeFile));
Object.assign(records.get(page)!, { delayedPreviewCancelled: true, downloads: [beforeFile,afterFile].map(file=>({ path:file,sha256:sha256(file) })) }); expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
const afterDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click(); const afterFile = path.join(evidence, `${records.get(page)!.started}-pending-after.blend`); await (await afterDownload).saveAs(afterFile); expect(sha256(afterFile)).toBe(sha256(beforeFile));
Object.assign(records.get(page)!, { delayedPreviewCancelled: true, downloads: [beforeFile,afterFile].map(file=>({ path:file,sha256:sha256(file) })) }); expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
async function productionRequest(page: Page, worker: 'engine' | 'storage', requestId: string, command: object) {
await page.evaluate(({ worker, requestId, command }) => { const owned = window as unknown as { __simplifyEngine: Worker; __simplifyStorage: Worker }; (worker === 'engine' ? owned.__simplifyEngine : owned.__simplifyStorage).postMessage({ requestId, command }); }, { worker, requestId, command });
@@ -112,9 +136,9 @@ async function rejectWithoutMutation(page: Page, id: string, meshId: string, pro
await page.evaluate(({ id, meshId, profile, type }) => { (window as unknown as { __simplifyEngine: Worker }).__simplifyEngine.postMessage({ requestId: id, command: { type: 'applyCommand', payload: { type, meshId, profile } } }); }, { id, meshId, profile, type });
await expect.poll(() => records.get(page)!.wire.find(event => event.requestId === id)?.error).toMatchObject({ code });
await page.evaluate(id => { (window as unknown as { __simplifyEngine: Worker }).__simplifyEngine.postMessage({ requestId: id + '-after', command: { type: 'snapshot' } }); }, id);
await expect.poll(() => records.get(page)!.wire.find(event => event.requestId === id + '-after')?.result?.snapshot).toEqual(before);
await expect.poll(() => sceneState(records.get(page)!.wire.find(event => event.requestId === id + '-after')?.result?.snapshot)).toEqual(sceneState(before));
}
test.afterEach(async ({ page }, info) => { const record = records.get(page)!; const receipt = path.join(evidence, `${record.started}-${info.title.replace(/[^a-z0-9]+/gi, '-')}.json`); fs.writeFileSync(receipt, JSON.stringify({ ...record, status: info.status, exitCode: info.status === 'passed' ? 0 : 1, durationMs: Date.now() - record.started, viewport: page.viewportSize(), testSourceSha256: sha256(import.meta.filename), errors: info.errors, consoleErrors: record.errors }, null, 2)); await info.attach('production-receipt', { path: receipt, contentType: 'application/json' }); });
test.afterEach(async ({ page }, info) => { const record = records.get(page)!; const receipt = path.join(evidence, `${record.started}-${info.title.replace(/[^a-z0-9]+/gi, '-')}.json`); fs.writeFileSync(receipt, JSON.stringify({ ...record, status: info.status, exitCode: info.status === 'passed' ? 0 : 1, durationMs: Date.now() - record.started, viewport: page.viewportSize(), testSourceSha256: sha256(import.meta.filename), errors: info.errors, consoleErrors: record.errors, consoleNoise: runtimeNoise(record), productConsoleErrors: productErrors(record) }, null, 2)); await info.attach('production-receipt', { path: receipt, contentType: 'application/json' }); });
async function openFixture(page: Page, fixture: string) {
records.get(page)!.fixture = { path: path.relative(root, fixture), sha256: sha256(fixture) };
await page.goto('/?ui=web'); records.get(page)!.isolated = await page.evaluate(() => crossOriginIsolated); expect(records.get(page)!.isolated).toBe(true);
@@ -124,8 +148,17 @@ async function openFixture(page: Page, fixture: string) {
}
async function selectFixtureObject(page: Page, name = 'SimplifyHighSphere') {
const revision = latest(page).revision;
await page.getByText(name, { exact: true }).click();
await expect.poll(() => latest(page).revision).toBeGreaterThan(revision);
/* The name also appears in the viewport sidebar, so plain text matching is
* ambiguous; select through the Outliner treeitem, the row the user clicks.
* After a reopen the object is already selected and clicking it is a no-op. */
const item = page.getByRole('treeitem', { name, exact: true }).first();
if (await item.getAttribute('aria-selected') !== 'true') {
await item.locator('.tree-node-name').click();
await expect.poll(() => latest(page).revision).toBeGreaterThan(revision);
}
/* Skipping the click also skips its implicit wait, so wait for the open/save
* lock to release before callers act on the panel. */
await expect(page.getByTestId('engine-status')).toContainText(/SceneIR/, { timeout: 60_000 });
await expect(page.getByTestId('editor-workflow-workbench')).toHaveAttribute('data-revision', String(latest(page).revision));
}
test('production prerequisites', async ({ page }) => {
@@ -133,7 +166,7 @@ test('production prerequisites', async ({ page }) => {
await expect(page.getByText('BasicCube', { exact: true })).toBeVisible();
expect(latest(page).meshes.find(mesh => mesh.name === 'BasicCubeMesh')?.triangleCount ?? latest(page).meshes[0]?.triangleCount).toBe(12);
expect(records.get(page)!.modules.some(module => module.url.endsWith('.wasm'))).toBe(true);
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
test('high triangle preview cancel apply history save reopen', async ({ page }) => {
const desktop = JSON.parse(fs.readFileSync(path.join(baseline, 'desktop-fixture.json'), 'utf8'));
@@ -149,17 +182,24 @@ test('high triangle preview cancel apply history save reopen', async ({ page })
await rejectWithoutMutation(page, 'negative-ratio', mesh.id, { ...profile, ratio: -0.01 }, 'INVALID_ARGUMENT', 'decimateMesh');
await rejectWithoutMutation(page, 'negative-malformed', mesh.id, { ...profile, ratio: 'invalid' }, 'INVALID_ARGUMENT', 'decimateMesh');
await expect(page.getByRole('slider', { name: 'Decimate 比例' })).toHaveValue('0.5');
await page.getByRole('button', { name: '预览 Decimate' }).click();
await page.getByRole('button', { name: '预览 Decimate', exact: true }).click();
await expect(page.getByTestId('engine-status')).toContainText('Preview', { timeout: 60_000 });
await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(desktop.after.triangles);
await page.getByRole('button', { name: '取消 Decimate 预览' }).click();
await expect(page.getByTestId('engine-status')).toContainText(`SceneIR r${before.revision}`);
const cancelledDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目' }).click();
const cancelledDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click();
const cancelledFile = path.join(evidence, `${records.get(page)!.started}-cancelled-preview.blend`); await (await cancelledDownload).saveAs(cancelledFile);
await page.getByTestId('blend-file-input').setInputFiles(cancelledFile);
await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(mesh.triangleCount);
await selectFixtureObject(page); const applyRevision = latest(page).revision;
await page.getByRole('button', { name: '应用 Decimate' }).click();
/* The download above can leave a project action lock running; the product
* drops edits made during it and says so, so retry the click like a user. */
const applyButton = page.getByRole('button', { name: '应用 Decimate', exact: true });
await expect(async () => {
await expect(page.locator('main.blender-app')).toHaveAttribute('aria-busy', 'false');
await applyButton.click();
await expect(page.getByTestId('engine-status')).not.toContainText('请稍后再编辑', { timeout: 3000 });
}).toPass({ timeout: 90_000 });
await expect(page.getByTestId('engine-status')).toContainText('Decimate', { timeout: 60_000 });
await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(desktop.after.triangles);
const applied = latest(page); expect(applied.revision).toBe(applyRevision + 1);
@@ -170,7 +210,7 @@ test('high triangle preview cancel apply history save reopen', async ({ page })
await page.getByRole('button', { name: '重做', exact: true }).click();
await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(desktop.after.triangles);
expect(latest(page).revision).toBe(applied.revision + 2);
const savedDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目' }).click();
const savedDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click();
const savedFile = path.join(evidence, `${records.get(page)!.started}-simplified.blend`); await (await savedDownload).saveAs(savedFile);
const reopenEventCount = records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length;
await page.getByTestId('blend-file-input').setInputFiles(savedFile);
@@ -181,12 +221,12 @@ test('high triangle preview cancel apply history save reopen', async ({ page })
expect(latest(page).meshes.find(value => value.id === mesh.id)?.attributes).toContainEqual(requiredAttribute);
expect(latest(page).nodes).toEqual(applied.nodes);
Object.assign(records.get(page)!, { downloads: [cancelledFile, savedFile].map(file => ({ path: file, sha256: sha256(file) })) });
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
test('LOD on edited Main preserves state and enforces cache budgets', async ({ page }) => {
const oracle = JSON.parse(fs.readFileSync(path.join(lodBaseline, 'desktop-lod.json'), 'utf8'));
await openFixture(page, path.join(root, 'tests/files/web/mesh_simplify_high.blend')); await selectFixtureObject(page);
const selected = latest(page).revision; await page.getByRole('button', { name: '应用 Decimate' }).click();
const selected = latest(page).revision; await page.getByRole('button', { name: '应用 Decimate', exact: true }).click();
await expect(page.getByTestId('engine-status')).toContainText('Decimate', { timeout: 60_000 });
await expect.poll(() => latest(page).revision).toBe(selected + 1);
const source = latest(page), mesh = source.meshes.find(value => value.name === 'SimplifyHighMesh')!;
@@ -239,20 +279,22 @@ test('LOD on edited Main preserves state and enforces cache budgets', async ({ p
await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(16128); expect(latest(page).revision).toBe(source.revision + 1);
await page.getByRole('button', { name: '重做', exact: true }).click();
await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(8064); expect(latest(page).revision).toBe(source.revision + 2);
const pendingDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目' }).click();
const pendingDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click();
const savedFile = path.join(evidence, `${records.get(page)!.started}-lod-source.blend`); await (await pendingDownload).saveAs(savedFile);
const count = records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length; await page.getByTestId('blend-file-input').setInputFiles(savedFile);
await expect.poll(() => records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length).toBeGreaterThan(count);
expect(latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(8064);
Object.assign(records.get(page)!, { downloads: [{ path: savedFile, sha256: sha256(savedFile) }] });
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
test('LOD discards late results when another file opens', async ({ page }) => {
await openFixture(page, path.join(baseline, 'desktop-decimated.blend')); await selectFixtureObject(page);
const sourceMeshId = latest(page).meshes.find(mesh => mesh.name === 'SimplifyHighMesh')!.id;
await page.getByRole('button', { name: '生成 LOD' }).click();
await page.getByTestId('blend-file-input').setInputFiles(path.join(root, 'tests/files/web/basic_scene.blend'));
await page.getByRole('button', { name: '不保存,继续', exact: true }).click();
/* The unsaved-changes prompt only appears when the project is dirty; a fresh
* open switches files directly, so treat its absence as the fast path. */
await page.getByRole('button', { name: '不保存,继续', exact: true }).click({ timeout: 5000 }).catch(() => undefined);
await expect(page.getByText('BasicCube', { exact: true })).toBeVisible({ timeout: 90_000 });
await expect.poll(() => records.get(page)!.wire.some(event => event.result?.lod?.manifest.meshId === sourceMeshId), { timeout: 90_000 }).toBe(true);
const writes = await page.evaluate(() => (window as unknown as { __lodCacheWrites: unknown[] }).__lodCacheWrites);
@@ -260,7 +302,7 @@ test('LOD discards late results when another file opens', async ({ page }) => {
expect(latest(page).meshes.some(mesh => mesh.id === sourceMeshId)).toBe(false);
expect(latest(page).meshes[0].triangleCount).toBe(12);
await expect(page.getByTestId('engine-status')).not.toContainText('LOD:');
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
test('target triangle controls report and reject budgets without mutation', async ({ page }) => {
const oracle = JSON.parse(fs.readFileSync(path.join(targetBaseline, 'desktop-target.json'), 'utf8'));
@@ -268,7 +310,7 @@ test('target triangle controls report and reject budgets without mutation', asyn
const before = latest(page), mesh = before.meshes.find(value => value.name === 'SimplifyHighMesh')!;
await page.getByRole('combobox', { name: 'Decimate 目标方式' }).selectOption('TRIANGLES');
const target = page.getByRole('spinbutton', { name: '目标三角形' }); await target.fill('0');
await expect(page.getByRole('button', { name: '预览 Decimate' })).toBeDisabled(); await expect(page.getByRole('button', { name: '应用 Decimate' })).toBeDisabled();
await expect(page.getByRole('button', { name: '预览 Decimate', exact: true })).toBeDisabled(); await expect(page.getByRole('button', { name: '应用 Decimate', exact: true })).toBeDisabled();
expect((await productionRequest(page, 'engine', 'lod-target-invalid-ui', { type: 'snapshot' })).result?.snapshot).toEqual(before);
const profile = { schemaVersion: 1, sourceMeshRevision: before.revision, mode: 'COLLAPSE', attributePolicy: 'PRESERVE', ratio: 0.5 };
await rejectWithoutMutation(page, 'target-zero-budget', mesh.id, { ...profile, triangleBudget: 0 }, 'INVALID_ARGUMENT', 'decimateMesh');
@@ -276,7 +318,7 @@ test('target triangle controls report and reject budgets without mutation', asyn
await rejectWithoutMutation(page, 'target-staged-budget', mesh.id, { ...profile, triangleBudget: 1 }, 'CAPABILITY_CONTRACT_BUDGET_EXCEEDED', 'decimateMesh');
await rejectWithoutMutation(page, 'target-identity-budget', mesh.id, { ...profile, ratio: 1, triangleBudget: 1 }, 'CAPABILITY_CONTRACT_BUDGET_EXCEEDED', 'decimateMesh');
await rejectWithoutMutation(page, 'target-preview-budget', mesh.id, { ...profile, triangleBudget: 1 }, 'CAPABILITY_CONTRACT_BUDGET_EXCEEDED');
await target.fill(String(oracle.targetTriangles)); await page.getByRole('button', { name: '预览 Decimate' }).click();
await target.fill(String(oracle.targetTriangles)); await page.getByRole('button', { name: '预览 Decimate', exact: true }).click();
await expect(page.getByTestId('simplify-triangle-counts')).toHaveText(`三角形 ${oracle.beforeTriangles} → ${oracle.triangles}`, { timeout: 60_000 });
const preview = records.get(page)!.wire.filter(event => event.result?.simplify).at(-1)!.result!;
expect(preview.simplify?.triangleBudget).toBe(oracle.targetTriangles); expect(preview.snapshot?.meshes.find(value => value.id === mesh.id)?.vertexCount).toBe(oracle.vertices);
@@ -284,7 +326,7 @@ test('target triangle controls report and reject budgets without mutation', asyn
await expect(page.getByTestId('simplify-retained-attributes')).toContainText('fixture_weight'); await expect(page.getByTestId('simplify-channel-counts')).toContainText('UV 层 1 → 1;材质槽 2 → 2');
await page.getByRole('button', { name: '取消 Decimate 预览' }).click(); await expect(page.getByTestId('simplify-report-empty')).toBeVisible();
expect((await productionRequest(page, 'engine', 'lod-target-cancel', { type: 'snapshot' })).result?.snapshot).toEqual(before);
await target.fill('8064'); await page.getByRole('button', { name: '应用 Decimate' }).click();
await target.fill('8064'); await page.getByRole('button', { name: '应用 Decimate', exact: true }).click();
await expect(page.getByTestId('simplify-triangle-counts')).toHaveText('三角形 16128 → 8064', { timeout: 60_000 });
const applied = latest(page); expect(applied.revision).toBe(before.revision + 1);
await expect(page.getByTestId('simplify-result-target')).toContainText('8064'); await expect(page.getByTestId('simplify-result-ratio')).toContainText('50.00%');
@@ -297,13 +339,13 @@ test('target triangle controls report and reject budgets without mutation', asyn
await expect(page.getByTestId('simplify-report-empty')).toBeVisible(); expect(latest(page).revision).toBe(applied.revision + 1);
await page.getByRole('button', { name: '重做', exact: true }).click(); await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(8064);
expect(latest(page).revision).toBe(applied.revision + 2);
const pendingDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目' }).click();
const pendingDownload = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click();
const savedFile = path.join(evidence, `${records.get(page)!.started}-target-applied.blend`); await (await pendingDownload).saveAs(savedFile);
const count = records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length; await page.getByTestId('blend-file-input').setInputFiles(savedFile);
await expect.poll(() => records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length).toBeGreaterThan(count);
expect(latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(8064); await expect(page.getByTestId('simplify-report-empty')).toBeVisible();
Object.assign(records.get(page)!, { downloads: [{ path: savedFile, sha256: sha256(savedFile) }] });
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
const modeOracle = JSON.parse(fs.readFileSync(path.join(modeBaseline, 'desktop-modes.json'), 'utf8'));
for (const definition of modeOracle.cases as { name: string; mode: string; summary: { vertices: number; triangles: number } }[]) {
@@ -315,27 +357,31 @@ test(`mesh modes ${definition.name} preserve open grid and export GLB`, async ({
if (definition.mode === 'DISSOLVE_PLANAR') { await page.getByRole('checkbox', { name: 'MATERIAL', exact: true }).check(); await page.getByRole('checkbox', { name: 'UV', exact: true }).check(); }
const invalid = { schemaVersion: 1, sourceMeshRevision: before.revision, attributePolicy: 'PRESERVE', mode: definition.mode, ...(definition.mode === 'COLLAPSE' ? { ratio: -0.01 } : definition.mode === 'UNSUBDIV' ? { iterations: -1 } : { angleLimit: -1, delimit: ['MATERIAL', 'UV'], useDissolveBoundaries: false }) };
const modeBefore = latest(page);
/* The simplify contract requires ratio > 0 (protocol/simplify.ts:188, mirrored by
* web_engine_main_state.cpp), so COLLAPSE zero is a rejected boundary; UNSUBDIV
* iterations 0 remains an accepted no-op. */
if (definition.mode === 'COLLAPSE' || definition.mode === 'UNSUBDIV') {
const zero = { ...invalid, ...(definition.mode === 'COLLAPSE' ? { ratio: 0 } : { iterations: 0 }) };
const accepted = await productionRequest(page, 'engine', `modes-${definition.name}-zero`, { type: 'applyCommand', payload: { type: 'previewDecimateMesh', meshId: mesh.id, profile: zero } });
expect(accepted.ok).toBe(true); const zeroAfter = await productionRequest(page, 'engine', `modes-${definition.name}-zero-after`, { type: 'snapshot' });
const zeroReply = await productionRequest(page, 'engine', `modes-${definition.name}-zero`, { type: 'applyCommand', payload: { type: 'previewDecimateMesh', meshId: mesh.id, profile: zero } });
if (definition.mode === 'COLLAPSE') expect(zeroReply.error).toMatchObject({ code: 'INVALID_ARGUMENT' }); else expect(zeroReply.ok).toBe(true);
const zeroAfter = await productionRequest(page, 'engine', `modes-${definition.name}-zero-after`, { type: 'snapshot' });
expect(zeroAfter.result?.snapshot?.meshes).toEqual(modeBefore.meshes); expect(zeroAfter.result?.snapshot?.nodes).toEqual(modeBefore.nodes);
}
await rejectWithoutMutation(page, `modes-${definition.name}-invalid`, mesh.id, invalid, 'INVALID_ARGUMENT', 'decimateMesh');
await page.getByRole('button', { name: '预览 Decimate' }).click();
await page.getByRole('button', { name: '预览 Decimate', exact: true }).click();
await expect(page.getByTestId('simplify-triangle-counts')).toHaveText(`三角形 ${mesh.triangleCount} → ${definition.summary.triangles}`, { timeout: 60_000 });
expect(latest(page).meshes.find(value => value.id === mesh.id)?.vertexCount).toBe(definition.summary.vertices);
await expect(page.getByTestId('simplify-retained-attributes')).toContainText('fixture_weight');
await page.getByRole('button', { name: '取消 Decimate 预览' }).click();
expect((await productionRequest(page, 'engine', `lod-modes-${definition.name}-cancel`, { type: 'snapshot' })).result?.snapshot).toEqual(before);
await page.getByRole('button', { name: '应用 Decimate' }).click();
await page.getByRole('button', { name: '应用 Decimate', exact: true }).click();
await expect(page.getByTestId('simplify-triangle-counts')).toHaveText(`三角形 ${mesh.triangleCount} → ${definition.summary.triangles}`, { timeout: 60_000 });
const applied = latest(page); expect(applied.revision).toBe(before.revision + 1);
await page.getByRole('button', { name: '撤销', exact: true }).click(); await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(mesh.triangleCount);
expect(latest(page).revision).toBe(applied.revision + 1);
await page.getByRole('button', { name: '重做', exact: true }).click(); await expect.poll(() => latest(page).meshes.find(value => value.id === mesh.id)?.triangleCount).toBe(definition.summary.triangles);
expect(latest(page).revision).toBe(applied.revision + 2);
const saved = page.waitForEvent('download'); await page.getByRole('button', { name: '保存项目' }).click();
const saved = page.waitForEvent('download'); await page.getByRole('button', { name: '下载 .blend', exact: true }).click();
const blend = path.join(evidence, `${records.get(page)!.started}-${definition.name}.blend`); await (await saved).saveAs(blend);
const count = records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length; await page.getByTestId('blend-file-input').setInputFiles(blend);
await expect.poll(() => records.get(page)!.wire.filter(event => event.ok && event.result?.snapshot).length).toBeGreaterThan(count);
@@ -344,8 +390,20 @@ test(`mesh modes ${definition.name} preserve open grid and export GLB`, async ({
const beforeExport = latest(page); const glbDownload = page.waitForEvent('download', { timeout: 60_000 }); await page.getByRole('button', { name: '导出 GLB', exact: true }).click();
const glb = path.join(evidence, `${records.get(page)!.started}-${definition.name}.glb`); await (await glbDownload).saveAs(glb);
await expect(page.getByTestId('engine-status')).toContainText('fixture_weight');
expect((await productionRequest(page, 'engine', `lod-modes-${definition.name}-export-after`, { type: 'snapshot' })).result?.snapshot).toEqual(beforeExport);
expect(sceneState((await productionRequest(page, 'engine', `lod-modes-${definition.name}-export-after`, { type: 'snapshot' })).result?.snapshot)).toEqual(sceneState(beforeExport));
Object.assign(records.get(page)!, { mode: definition.name, downloads: [blend, glb].map(file => ({ path: file, sha256: sha256(file) })), exportStatus: await page.getByTestId('engine-status').textContent() });
expect(records.get(page)!.failures).toEqual([]); expect(records.get(page)!.errors).toEqual([]);
expect(records.get(page)!.failures).toEqual([]); expect(productErrors(records.get(page)!)).toEqual([]);
});
}
test('console noise filter keeps real product errors', async ({ page }) => {
expect(RUNTIME_STUB_NOISE.test('warning: unsupported syscall: __syscall_mprotect\n'.trim())).toBe(true);
expect(RUNTIME_STUB_NOISE.test('Uncaught TypeError: boom')).toBe(false);
expect(RUNTIME_STUB_NOISE.test('warning: unsupported syscall: mprotect')).toBe(false);
records.get(page)!.errors.push('warning: unsupported syscall: __syscall_mprotect\n', 'mesh-simplify-reverse-console-error');
expect(runtimeNoise(records.get(page)!)).toEqual(['warning: unsupported syscall: __syscall_mprotect\n']);
expect(productErrors(records.get(page)!)).toEqual(['mesh-simplify-reverse-console-error']);
await page.goto('/?ui=web');
await page.evaluate(() => console.error('mesh-simplify-reverse-live-console-error'));
await expect.poll(() => records.get(page)!.errors).toContain('mesh-simplify-reverse-live-console-error');
expect(productErrors(records.get(page)!)).toContain('mesh-simplify-reverse-live-console-error');
});