Files
Agent-Workbench/scripts/verify-official-model-registry-ui.mjs
Agent Workbench Dev e306f40cae
Official contracts and Windows source CI / windows-source (push) Has been cancelled
feat(memory): release Mnemo project bridge and schema2 recovery
2026-11-11 03:03:43 +08:00

245 lines
25 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import http from 'node:http';
import net from 'node:net';
import assert from 'node:assert/strict';
import { randomUUID, createHash } from 'node:crypto';
import { chromium, _electron } from 'playwright';
import { expect } from 'playwright/test';
import { fixture, launchWorkbench, until } from '../tests/helpers.mjs';
import { Provider } from '../src/server/provider.mjs';
import { Store } from '../src/server/store.mjs';
import { HostController } from '../src/core/desktop/host-controller.mjs';
import { desktopLaunchCommand } from './desktop-launch.mjs';
import { projectEnvironment } from '../src/core/process-environment.mjs';
import { catalogModel } from '../src/shared/contracts/model-catalog.mjs';
import { modelSnapshot } from '../src/shared/contracts/execution.mjs';
import { openWorkbenchTool } from './ui-navigation.mjs';
const desktop = process.argv.includes('--desktop');
assert.ok(process.argv.slice(2).every(value => value === '--desktop'));
assert.ok(process.env.AGENT_WORKBENCH_QA_APP_ROOT, 'Use an independent candidate build');
const appRoot = fs.realpathSync.native(process.env.AGENT_WORKBENCH_QA_APP_ROOT);
const directory = path.resolve(process.env.AGENT_WORKBENCH_QA_EVIDENCE_ROOT ?? '.qa/m2-official-registry-2026-11-07', (desktop ? 'electron-' : 'web-') + randomUUID());
fs.mkdirSync(directory, { recursive: true }); console.log('EVIDENCE ' + directory);
const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t, { modernDefaults: true });
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
const requests = [], checks = [], screenshots = [], errors = [], externalBlocked = [], contrast = [];
let listedOutput = 96000;
const raw = model => ({ id: model, context_window: 1000000, max_output_tokens: listedOutput, capabilities: { text: true, tools: true },
vendor_extension: { preserve: ['original', { detail: 'complete upstream declaration' }], api_key: 'owned-not-exported-secret' } });
const model = http.createServer(async (req, res) => {
const chunks = []; for await (const chunk of req) chunks.push(chunk);
const body = chunks.length ? JSON.parse(Buffer.concat(chunks)) : null;
requests.push({ method: req.method, route: req.url, body, hadCredential: !!req.headers['x-api-key'] || !!req.headers.authorization });
res.writeHead(200, { 'Content-Type': 'application/json' });
if (req.method === 'GET') {
res.end(JSON.stringify(req.url.includes('pageToken=') ? { data: [raw('claude-sonnet-5-5')] } : { data: [raw('claude-opus-5-5')], nextPageToken: 'owned-page-two' }));
} else if (req.url.endsWith('/messages')) {
res.end(JSON.stringify({ type: 'message', id: 'owned-msg', role: 'assistant', model: body.model, content: [{ type: 'text', text: 'OK' }], stop_reason: 'end_turn', usage: { input_tokens: 11, output_tokens: 1 } }));
} else if (req.url.endsWith('/responses')) {
res.end(JSON.stringify({ id: 'owned-resp', model: body.model, status: 'completed', output: [{ type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'OK' }] }], usage: { input_tokens: 11, output_tokens: 1 } }));
} else {
res.end(JSON.stringify({ id: 'owned-chat', model: body.model, choices: [{ message: { role: 'assistant', content: 'OK' }, finish_reason: 'stop' }], usage: { prompt_tokens: 11, completion_tokens: 1, total_tokens: 12 } }));
}
});
await new Promise(resolve => model.listen(0, '127.0.0.1', resolve));
const baseUrl = 'http://127.0.0.1:' + model.address().port + '/v1';
const legacyAttempt = { id: 'owned-old-request', status: 'unknown', model: 'owned-old', usage: null, legacy_extension: { preserve: ['failed network', 'repeated reads', 'unknown usage'] } };
f.store.storage.setMeta('modelAttempts', [legacyAttempt]);
const originalMetadata = f.store.storage.database.prepare("SELECT value FROM metadata WHERE key='modelAttempts'").get().value;
const provider = Object.assign(Object.create(Provider.prototype), { apiKey: '' }), hub = provider.modelHub(f.store);
const format = { type: 'json_schema', schema: { type: 'object', properties: { result: { type: 'string' } } } };
const claude = hub.upsert({ name: '自有验证 · Claude 规格', model: 'claude-opus-5-5', protocol: 'anthropic-messages', baseUrl, apiKey: 'owned-ui-key-only', persistKey: true,
nativeParameters: { thinking: { type: 'adaptive', display: 'summarized' }, output_config: { effort: 'high', format }, metadata: { preserve: ['owned'] } }, parameterProfile: 'auto' });
const declaration = catalogModel(raw(claude.model)); declaration.rawSha256 = sha(JSON.stringify(declaration.rawItem)); declaration.rawBytes = Buffer.byteLength(JSON.stringify(declaration.rawItem));
hub.connection(claude.id).upstreamModel = { ...declaration, endpoint: baseUrl, fetchedAt: '2026-11-07T00:00:00.000Z' };
const deepseek = hub.upsert({ name: '自有验证 · DeepSeek', model: 'deepseek-flash', protocol: 'anthropic-messages', baseUrl, requiresKey: false,
nativeParameters: { thinking: { type: 'enabled' }, output_config: { effort: 'max', opaque: { keep: true } } }, parameterProfile: 'auto' });
const responses = hub.upsert({ name: '自有验证 · Responses', model: 'gpt-6.1-sol', protocol: 'responses', baseUrl, requiresKey: false,
nativeParameters: { reasoning: { effort: 'high', summary: 'auto' }, metadata: { stable: 'owned' } }, parameterProfile: 'auto' });
const chat = hub.upsert({ name: '自有验证 · Chat', model: 'gpt-6-sol', protocol: 'chat-completions', baseUrl, requiresKey: false,
nativeParameters: { reasoning_effort: 'none', thinking: { type: 'enabled', opaque: ['unchanged'] } }, parameterProfile: 'auto' });
const unknown = hub.upsert({ name: '自有验证 · 未公布型号', model: 'claude-opus-5-5-custom', protocol: 'anthropic-messages', baseUrl, requiresKey: false,
nativeParameters: { thinking: { type: 'owned-custom-mode', display: 'summarized' }, output_config: { effort: 'owned-custom-effort' } }, parameterProfile: 'auto' });
hub.select({ type: 'connection', id: claude.id });
const originalCipher = structuredClone(hub.vault().state), originalNative = structuredClone(claude.nativeParameters), originalSnapshot = JSON.parse(JSON.stringify(modelSnapshot(hub.prepare(f.store.config))));
f.store.storage.setMeta('ownedModelSnapshot', originalSnapshot);
const originalSnapshotMetadata = f.store.storage.database.prepare("SELECT value FROM metadata WHERE key='ownedModelSnapshot'").get().value;
fs.writeFileSync(path.join(directory, 'retention-before.json'), JSON.stringify({ modelAttempts: originalMetadata, modelCredentials: originalCipher, modelSnapshot: originalSnapshotMetadata }, null, 2));
hub.save(); f.store.close();
let host, browser, application, controller, page, window, result, desktopStdout = '', desktopStderr = '';
const form = () => page.getByRole('form', { name: '原生请求参数', exact: true });
const center = () => page.getByRole('dialog', { name: '模型中心', exact: true });
const card = id => page.locator('.mc-connection[data-connection-id="' + id + '"]');
const field = label => form().getByLabel(label, { exact: true });
const parameters = async () => JSON.parse(await field('原生参数 JSON').inputValue());
const current = async id => (await host.api('/model-center')).connections.find(value => value.id === id);
const mark = name => { checks.push(name); console.log('PASS ' + name); };
async function resize(width, height = 960) {
if (window) { await window.evaluate((win, size) => win.setContentSize(size.width, size.height), { width, height }); await until(() => page.evaluate(w => innerWidth === w, width)); }
else await page.setViewportSize({ width, height });
}
async function open() { await openWorkbenchTool(page, '打开模型中心'); await expect(center()).toBeVisible(); }
async function edit(id) { if (!await center().count()) await open(); await card(id).getByRole('button', { name: '推理与能力', exact: true }).click(); await expect(form()).toBeVisible(); }
async function save(id, expected) { await form().getByRole('button', { name: '保存原生参数', exact: true }).click(); await expect(form()).toHaveCount(0); assert.deepEqual((await current(id)).nativeParameters, expected); }
async function capture(file) {
if (!window) { await page.screenshot({ path: file, scale: 'css' }); return { method: 'playwright-page' }; }
const captured = await window.evaluate(async win => {
const [width, height] = win.getContentSize(), picture = await win.capturePage({ x: 0, y: 0, width, height }, { stayHidden: true, stayAwake: true });
return { png: picture.toPNG().toString('base64'), empty: picture.isEmpty(), size: picture.getSize(), hidden: !win.isVisible() };
});
assert.equal(captured.empty, false); assert.equal(captured.hidden, true);
fs.writeFileSync(file, Buffer.from(captured.png, 'base64'));
return { method: 'electron-native-stay-hidden', size: captured.size };
}
async function shot(name, anchor) {
if (anchor) await anchor.scrollIntoViewIfNeeded();
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1), 'No page overflow');
const file = path.join(directory, name + '.png'), captured = await capture(file);
screenshots.push({ file: path.basename(file), sha256: sha(fs.readFileSync(file)), ...captured });
fs.writeFileSync(path.join(directory, name + '.txt'), await center().innerText(), { flag: 'wx' });
}
async function sampleContrast(locator, label) {
const sampled = await locator.evaluate(element => {
const style = getComputedStyle(element); let ancestor = element, background;
while (ancestor) { const color = getComputedStyle(ancestor).backgroundColor; if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') { background = color; break; } ancestor = ancestor.parentElement; }
return { color: style.color, background, fontSize: style.fontSize };
});
const luminance = value => value.match(/[\d.]+/g).slice(0, 3).map(Number).map(c => c / 255).map(c => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4).reduce((sum, c, i) => sum + c * [0.2126, 0.7152, 0.0722][i], 0);
const a = luminance(sampled.color), b = luminance(sampled.background), ratio = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
contrast.push({ label, ...sampled, ratio }); assert.ok(ratio >= 4.5, label + ' contrast ' + ratio);
}
try {
if (desktop) {
const socket = net.createServer(); await new Promise(resolve => socket.listen(0, '127.0.0.1', resolve)); const port = socket.address().port; await new Promise(resolve => socket.close(resolve));
assert.notEqual(port, 4318); controller = new HostController({ appRoot, dataRoot: f.data, port, nodePath: process.execPath, timeoutMs: 60000 }); await controller.start();
host = { url: controller.url, api: (route, input) => controller.api(route, input === undefined ? {} : { method: 'POST', input }) };
application = await _electron.launch({ ...desktopLaunchCommand(appRoot,
['--app-root', appRoot, '--data-root', f.data, '--node', process.execPath, '--port', String(port), '--hidden-window']), cwd: appRoot, env: projectEnvironment(), timeout: 60000 });
application.process().stdout?.on('data', bytes => { desktopStdout += bytes.toString('utf8'); }); application.process().stderr?.on('data', bytes => { desktopStderr += bytes.toString('utf8'); });
page = await application.firstWindow(); window = await application.browserWindow(page);
} else {
host = await launchWorkbench(t, f.data, {}, { appRoot }); assert.notEqual(new URL(host.url).port, '4318');
browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage();
}
page.on('pageerror', cause => errors.push(cause.message));
await page.route('**/*', route => {
const url = new URL(route.request().url());
if (url.origin === new URL(host.url).origin || ['data:', 'blob:'].includes(url.protocol)) return route.continue();
externalBlocked.push(url.origin); return route.abort();
});
await resize(1280); await page.goto(host.url); await page.waitForLoadState('networkidle'); await open();
await expect(card(claude.id)).toContainText('96,000 tokens · 上游目录'); await expect(card(responses.id)).toContainText('1,050,000 tokens · OpenAI 官方规格');
await expect(card(deepseek.id)).toContainText('393,216 tokens · DeepSeek 官方规格'); await expect(card(deepseek.id)).toContainText('默认省略 max_tokens');
await expect(card(unknown.id)).toContainText('本地无限制 · 由上游决定');
await edit(claude.id); await form().locator('.model-specification-details > summary').click();
const specification = form().locator('.model-specification-details'), row = key => specification.locator('[data-spec-field="' + key + '"]');
await expect(row('maxOutputTokens')).toContainText('96,000'); await expect(row('maxOutputTokens')).toContainText('上游目录声明');
await row('maxOutputTokens').locator('.model-spec-alternatives > summary').click(); await expect(row('maxOutputTokens')).toContainText('128,000');
await expect(specification).toContainText('规格 API 版本 2026-10-21'); await expect(specification).toContainText('实际发送版本以请求账本为准');
await specification.locator('.model-spec-raw > summary').click(); await expect(specification.locator('.model-spec-raw pre')).toContainText('complete upstream declaration');
await expect(specification.locator('.model-spec-raw pre')).toContainText('[redacted]'); assert.equal((await specification.innerText()).includes('owned-not-exported-secret'), false);
await shot('sources-1280', row('maxOutputTokens'));
mark('Known capacities, exact official versions, conflicts and full redacted catalog origin are visible; unknown model stays unknown');
await form().locator('.mc-model-overrides > summary').click(); await field('兼容规格 JSON').fill('{"maxOutputTokens":0}');
await form().getByRole('button', { name: '保存原生参数', exact: true }).click(); await expect(form().getByRole('alert')).toContainText('正安全整数');
assert.equal((await current(claude.id)).revision, claude.revision); assert.equal(await field('兼容规格 JSON').inputValue(), '{"maxOutputTokens":0}');
const overrides = { maxOutputTokens: 70000, efforts: ['low', 'custom'], modes: ['adaptive'], note: '自有代理显式兼容声明' };
await field('兼容规格 JSON').fill(JSON.stringify(overrides, null, 2)); await field('推理强度').selectOption('custom');
const expectedClaude = { ...originalNative, output_config: { ...originalNative.output_config, effort: 'custom' } };
assert.deepEqual(await parameters(), expectedClaude); await expect(row('maxOutputTokens')).toContainText('70,000');
await shot('override-1280', field('兼容规格 JSON')); await save(claude.id, expectedClaude);
await page.reload(); await open(); await edit(claude.id); assert.deepEqual(JSON.parse(await field('兼容规格 JSON').inputValue()), overrides); assert.deepEqual(await parameters(), expectedClaude);
await form().getByRole('button', { name: '取消', exact: true }).click();
mark('Invalid override saves nothing; valid explicit values persist with nested native siblings and current source conflicts');
listedOutput = 64000; await card(claude.id).getByRole('button', { name: '获取同源模型', exact: true }).click();
const catalogSection = center().locator('section[aria-label="上游模型目录"]');
await catalogSection.getByRole('button', { name: '获取上游模型', exact: true }).click(); await expect(catalogSection.getByLabel('选择模型 claude-sonnet-5-5', { exact: true })).toBeVisible();
await catalogSection.getByLabel('选择模型 claude-opus-5-5', { exact: true }).check(); await catalogSection.getByLabel('选择模型 claude-sonnet-5-5', { exact: true }).check();
await catalogSection.getByRole('button', { name: '保存所选 2 个模型', exact: true }).click(); await expect(catalogSection).toContainText('已新增 1 个模型,沿用 1 个已有模型');
const refreshed = await current(claude.id); assert.equal(refreshed.upstreamModel.maxOutputTokens, 64000); assert.deepEqual(refreshed.modelOverrides, overrides); assert.deepEqual(refreshed.nativeParameters, expectedClaude);
assert.equal(refreshed.revision, claude.revision + 1); assert.equal(requests.filter(value => value.method === 'GET').length, 2);
assert.equal(requests.filter(value => value.method === 'POST').length, 0);
await edit(claude.id); await form().locator('.model-specification-details > summary').click();
await shot('refreshed-source-1280', form().locator('[data-spec-field="maxOutputTokens"]'));
await form().getByRole('button', { name: '取消', exact: true }).click();
mark('Real UI catalog pageToken fetch and selection refresh metadata, retain explicit settings, share one credential and make zero model requests');
await edit(deepseek.id); await expect(field('推理模式')).toHaveValue('enabled'); await expect(form().getByLabel('推理预算 tokens')).toHaveCount(0);
await expect(form()).toContainText('允许省略 max_tokens');
const originalDeepSeekParameters = await parameters();
await field('原生参数 JSON').fill(JSON.stringify({ ...originalDeepSeekParameters, max_tokens: 65536 }));
await expect(form()).toContainText('允许省略 max_tokens'); await expect(form()).toContainText('当前 max_tokens=65536');
assert.equal((await form().innerText()).includes('Messages 协议需带 max_tokens'), false);
await field('原生参数 JSON').fill(JSON.stringify(originalDeepSeekParameters));
await field('推理模式').selectOption('adaptive');
const expectedDeepSeek = { ...deepseek.nativeParameters, thinking: { type: 'adaptive' } };
assert.deepEqual(await parameters(), expectedDeepSeek); await save(deepseek.id, expectedDeepSeek);
await host.api('/model-center/probe', { id: deepseek.id, scope: 'text' });
let sent = requests.filter(value => value.method === 'POST').at(-1).body;
assert.equal(Object.hasOwn(sent, 'max_tokens'), false); assert.deepEqual(sent.output_config, expectedDeepSeek.output_config); assert.deepEqual(sent.thinking, expectedDeepSeek.thinking);
await edit(responses.id); assert.equal(await field('推理模式').locator('option[value="disabled"]').count(), 0);
await field('推理强度').selectOption('max'); let expected = { ...responses.nativeParameters, reasoning: { effort: 'max', summary: 'auto' } };
assert.deepEqual(await parameters(), expected); await save(responses.id, expected); await host.api('/model-center/probe', { id: responses.id, scope: 'text' });
sent = requests.filter(value => value.method === 'POST').at(-1).body; assert.deepEqual(sent.reasoning, expected.reasoning); assert.equal(Object.hasOwn(sent, 'max_output_tokens'), false);
await edit(chat.id); await expect(field('推理模式')).toHaveValue('disabled'); await field('推理模式').selectOption('enabled'); await field('推理强度').selectOption('high');
expected = { ...chat.nativeParameters, reasoning_effort: 'high' }; assert.deepEqual(await parameters(), expected); await save(chat.id, expected);
await host.api('/model-center/probe', { id: chat.id, scope: 'text' }); sent = requests.filter(value => value.method === 'POST').at(-1).body;
assert.equal(sent.reasoning_effort, 'high'); assert.deepEqual(sent.thinking, chat.nativeParameters.thinking); assert.equal(Object.hasOwn(sent, 'max_tokens'), false);
mark('Exact provider reasoning switches preserve native objects on three actual loopback wires; optional limits and DeepSeek budgets are omitted');
await edit(unknown.id); await expect(form()).toContainText('未取得精确型号能力'); await expect(field('推理模式')).toHaveValue('owned-custom-mode');
await expect(field('推理强度')).toHaveValue('owned-custom-effort'); await resize(390, 844); await shot('unknown-390', field('推理模式'));
assert.deepEqual(await parameters(), unknown.nativeParameters); await form().getByRole('button', { name: '取消', exact: true }).click();
for (const [palette, name] of [['green', '深青绿'], ['blue', '雾蓝'], ['purple', '鸢尾紫']]) {
await page.keyboard.press('Escape'); await page.getByRole('button', { name: '外观', exact: true }).click();
await page.getByRole('dialog', { name: '外观', exact: true }).getByRole('radio', { name, exact: true }).check(); await page.keyboard.press('Escape');
await open(); await edit(claude.id); await form().locator('.model-specification-details > summary').click();
const heading = form().locator('.model-specification-details > summary');
await sampleContrast(heading, palette + ' specification summary'); await sampleContrast(form().locator('[data-spec-field="maxOutputTokens"] > th'), palette + ' specification field');
await sampleContrast(form().locator('.model-specification-details a').first(), palette + ' specification source link');
await shot('source-' + palette + '-390', form().locator('[data-spec-field="maxOutputTokens"]')); await form().getByRole('button', { name: '取消', exact: true }).click();
}
mark('390px custom values and source rows remain readable across three actual appearance selections with measured text contrast');
const finalCenter = await host.api('/model-center'); assert.equal(finalCenter.attemptCount, 4); assert.equal(requests.filter(value => value.method === 'POST').length, 3);
assert.deepEqual(finalCenter.attempts.find(value => value.id === legacyAttempt.id), legacyAttempt);
assert.deepEqual(errors, []); assert.deepEqual(externalBlocked, []);
fs.writeFileSync(path.join(directory, 'center-final.json'), JSON.stringify(finalCenter, null, 2));
if (application) { await application.close(); application = null; } if (browser) { await browser.close(); browser = null; }
if (controller) { await controller.stop(); controller = null; } await host.close?.(); host = null;
host = await launchWorkbench(t, f.data, {}, { appRoot });
const restored = await host.api('/model-center'), restoredClaude = restored.connections.find(value => value.id === claude.id);
assert.equal(restoredClaude.hasKey, true); assert.equal(restoredClaude.savedCredential.status, 'saved'); assert.deepEqual(restoredClaude.nativeParameters, expectedClaude); assert.deepEqual(restoredClaude.modelOverrides, overrides);
assert.equal(requests.filter(value => value.method === 'POST').length, 3); assert.equal(restored.attemptCount, 4);
const restoredHostUrl = host.url;
await host.close(); host = null;
const storage = new Store(f.data); try {
const retainedCipher = storage.storage.meta('modelCredentials'), retainedMetadata = storage.storage.database.prepare("SELECT value FROM metadata WHERE key='modelAttempts'").get().value;
const retainedSnapshotMetadata = storage.storage.database.prepare("SELECT value FROM metadata WHERE key='ownedModelSnapshot'").get().value;
fs.writeFileSync(path.join(directory, 'retention-after.json'), JSON.stringify({ modelAttempts: retainedMetadata, modelCredentials: retainedCipher, modelSnapshot: retainedSnapshotMetadata }, null, 2));
assert.deepEqual(retainedCipher, originalCipher); assert.equal(retainedMetadata, originalMetadata); assert.equal(retainedSnapshotMetadata, originalSnapshotMetadata);
const retained = storage.storage.meta('modelAttempts'); assert.equal(retained.length, 4); assert.deepEqual(retained.find(value => value.id === legacyAttempt.id), legacyAttempt);
assert.deepEqual(storage.storage.meta('ownedModelSnapshot'), originalSnapshot);
} finally { storage.close(); }
mark('Independent packaged host restart restores existing synthetic cipher and new options; original unknown ledger and frozen snapshot remain exact with no replay');
result = { success: true, appRoot, actualElectron: desktop, checks, screenshots, contrast, errors, externalBlocked, hostUrl: restoredHostUrl,
syntheticRequests: 3, catalogRequests: 2, originalUnknownAttempts: 1, originalMetadataExact: true, originalMetadataSha256: sha(originalMetadata), originalCipherExact: true, originalSnapshotExact: true, originalSnapshotSha256: sha(originalSnapshotMetadata),
realModelRequests: 0, realCredentialsRead: 0, productionWrites: 0, viewportWidths: [1280, 390] };
} catch (cause) {
if (page) { await capture(path.join(directory, 'failure.png')).catch(() => {}); fs.writeFileSync(path.join(directory, 'failure.txt'), await page.locator('body').innerText().catch(() => '')); }
result = { success: false, appRoot, actualElectron: desktop, checks, screenshots, contrast, errors, externalBlocked, error: cause.stack, syntheticRequests: requests.filter(value => value.method === 'POST').length, catalogRequests: requests.filter(value => value.method === 'GET').length, realModelRequests: 0 };
} finally {
fs.writeFileSync(path.join(directory, 'requests.json'), JSON.stringify(requests, null, 2));
if (application) await application.close(); if (browser) await browser.close();
if (controller && await controller.health()) await controller.stop(); await host?.close?.();
await new Promise(resolve => { model.closeAllConnections(); model.close(resolve); });
for (const dispose of disposers.reverse()) await dispose();
if (desktop) { fs.writeFileSync(path.join(directory, 'desktop-stdout.txt'), desktopStdout); fs.writeFileSync(path.join(directory, 'desktop-stderr.txt'), desktopStderr); }
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(result, null, 2));
}
console.log(JSON.stringify({ directory, ...result })); if (!result.success) process.exitCode = 1;