feat: display upstream model maximums as read-only capacity facts

This commit is contained in:
Agent Workbench Dev
2026-11-06 09:31:24 +08:00
parent fda264e40a
commit 2a6554cdc8
7 changed files with 57 additions and 15 deletions
+20 -2
View File
@@ -12,9 +12,10 @@ import { openDefaults } from '../src/shared/contracts/execution-policy.mjs';
if (process.argv.includes('--help')) { console.log('node scripts/verify-open-formal-ui.mjs [--desktop] — read-only formal installed UI inspection; no model requests, permission edits or user project execution.'); process.exit(0); }
assert.ok(process.argv.slice(2).every(arg => arg === '--desktop'));
const desktop = process.argv.includes('--desktop'), url = 'http://127.0.0.1:4318';
const root = path.resolve('.qa/unrestricted-1.25.5', (desktop ? 'formal-electron-' : 'formal-web-') + randomUUID()); fs.mkdirSync(root, { recursive: true });
const expectedVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
const root = path.resolve('.qa/open-formal-ui-' + expectedVersion, (desktop ? 'formal-electron-' : 'formal-web-') + randomUUID()); fs.mkdirSync(root, { recursive: true });
const boot = await (await fetch(url + '/api/bootstrap', { headers: { Connection: 'close' } })).json();
assert.equal(boot.version, '1.25.5'); assert.equal(boot.config.approvalMode, 'full');
assert.equal(boot.version, expectedVersion); assert.equal(boot.config.approvalMode, 'full');
for (const [key, value] of Object.entries(openDefaults)) assert.equal(boot.config[key], value, key);
const host = await (await fetch(url + '/api/host/status', { headers: { 'X-Workbench-Token': boot.token, Connection: 'close' } })).json(); assert.equal(host.activity.active, false);
let browser, app, page, window, result; const screenshots = [], errors = [];
@@ -39,6 +40,23 @@ try {
await expect(dialog.getByLabel('额度策略', { exact: true })).toHaveValue('unrestricted');
await expect(dialog.getByLabel('输出上限', { exact: true })).toHaveCount(0);
const file = path.join(root, 'open-budget-390.png'); await page.screenshot({ path: file, fullPage: true }); screenshots.push(file);
await dialog.getByRole('button', { name: '模型连接', exact: true }).click();
const center = await (await fetch(url + '/api/model-center', { headers: { 'X-Workbench-Token': boot.token, Connection: 'close' } })).json();
const connection = center.connections.find(value => value.id !== 'legacy-default' && value.enabled);
if (connection) {
const card = dialog.locator('.mc-connection').filter({ has: page.getByRole('heading', { name: connection.name, exact: true }) });
await card.getByRole('button', { name: '编辑', exact: true }).click();
const editor = dialog.getByRole('form', { name: '编辑模型连接', exact: true });
await expect(editor.getByLabel('上下文上限', { exact: true })).toHaveCount(0);
await expect(editor.getByLabel('输出上限', { exact: true })).toHaveCount(0);
const upstream = connection.upstreamModel?.id === connection.model ? connection.upstreamModel : {};
for (const [field, label] of [['contextLimit', '模型最大上下文'], ['maxOutputTokens', '模型最大输出']]) {
await expect(editor.getByLabel(label, { exact: true })).toHaveText(upstream[field] ? Number(upstream[field]).toLocaleString() + ' tokens' : '本地无限制 · 由上游决定');
}
await editor.getByLabel('连接容量策略', { exact: true }).scrollIntoViewIfNeeded();
const capacityFile = path.join(root, 'model-capacity-390.png'); await page.screenshot({ path: capacityFile, fullPage: true }); screenshots.push(capacityFile);
await editor.getByRole('button', { name: '取消', exact: true }).click();
}
await dialog.getByRole('button', { name: '关闭窗口', exact: true }).click();
assert.deepEqual(errors, []); result = { success: true, version: boot.version, pid: host.identity.pid, runtimeRoot: boot.runtimeRoot, desktop, screenshots, errors, realModelRequests: 0, userProjectsExecuted: 0, writes: 0 };
} catch (error) { if (page) await page.screenshot({ path: path.join(root, 'failure.png'), fullPage: true }).catch(() => {}); result = { success: false, error: error.stack, desktop, screenshots, errors }; }