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
+5 -2
View File
@@ -18,7 +18,11 @@ export function packageSource({ root = process.cwd(), outputRoot = path.join(roo
const sourceCommit = git(['rev-parse', 'HEAD']).toString().trim();
const version = JSON.parse(git(['show', sourceCommit + ':package.json'])).version;
if (!/^\d+\.\d+\.\d+(?:-[a-z0-9.-]+)?$/i.test(version)) throw new Error('Invalid committed program version.');
const tree = git(['ls-tree', '-r', '--long', '-z', sourceCommit]).toString('utf8').split('\0').filter(Boolean).map(line => {
const selectedPaths = git(['ls-tree', '-r', '--name-only', '-z', sourceCommit]).toString('utf8').split('\0').filter(name =>
files.includes(name) || directories.some(directory => name.startsWith(directory + '/')) || guide(name));
const roots = [...directories.filter(name => selectedPaths.some(file => file.startsWith(name + '/'))),
...files.filter(name => selectedPaths.includes(name)), ...selectedPaths.filter(guide)];
const tree = git(['ls-tree', '-r', '--long', '-z', sourceCommit, '--', ...roots]).toString('utf8').split('\0').filter(Boolean).map(line => {
const match = /^(\d+) (\w+) ([a-f0-9]+)\s+(\d+|-)\t([\s\S]+)$/.exec(line);
if (!match) throw new Error('Invalid committed source entry.');
return { mode: match[1], type: match[2], gitBlob: match[3], bytes: Number(match[4]), path: match[5] };
@@ -26,7 +30,6 @@ export function packageSource({ root = process.cwd(), outputRoot = path.join(roo
const entries = tree.filter(row => files.includes(row.path) || directories.some(name => row.path.startsWith(name + '/')) || guide(row.path));
if (!entries.some(row => row.path === 'package-lock.json') || !entries.some(row => row.path.startsWith('src/'))) throw new Error('Committed source and dependency lock are required.');
if (entries.some(row => row.type !== 'blob' || !['100644', '100755'].includes(row.mode))) throw new Error('Source release requires regular committed files, without links or submodules.');
const roots = [...directories.filter(name => entries.some(row => row.path.startsWith(name + '/'))), ...files.filter(name => entries.some(row => row.path === name)), ...entries.filter(row => guide(row.path)).map(row => row.path)];
const name = `Agent-Workbench-${version}-source-code-${sourceCommit.slice(0, 8)}-${randomUUID()}`;
fs.mkdirSync(outputRoot, { recursive: true });
const archive = path.join(outputRoot, name + '.zip'), fd = fs.openSync(archive, 'wx');
+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 }; }
+17 -7
View File
@@ -13,9 +13,9 @@ import { HostController } from '../src/core/desktop/host-controller.mjs';
import { desktopExecutableIdentity } from '../src/core/desktop/app-installation.mjs';
import { projectEnvironment } from '../src/core/process-environment.mjs';
if (process.argv.includes('--help')) { console.log('node scripts/verify-unrestricted-ui.mjs [--desktop] — isolated actual passthrough, permissions, automatic writes/rollback, upstream errors and cache UI. Optional AGENT_WORKBENCH_QA_APP_ROOT selects the immutable app. No real-model keys.'); process.exit(0); }
assert.ok(process.argv.slice(2).every(value => value === '--desktop'));
const desktop = process.argv.includes('--desktop'), appRoot = path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT || '.');
if (process.argv.includes('--help')) { console.log('node scripts/verify-unrestricted-ui.mjs [--desktop] [--capacity-only] — isolated passthrough, permissions, model capacity, writes/rollback, errors and cache UI. --capacity-only focuses on permissions and model-capacity display. Optional AGENT_WORKBENCH_QA_APP_ROOT selects the immutable app. No real-model keys.'); process.exit(0); }
assert.ok(process.argv.slice(2).every(value => ['--desktop', '--capacity-only'].includes(value)));
const desktop = process.argv.includes('--desktop'), capacityOnly = process.argv.includes('--capacity-only'), appRoot = path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT || '.');
const directory = path.resolve('.qa/unrestricted-1.25.5', (desktop ? 'open-electron-' : 'open-web-') + randomUUID());
fs.mkdirSync(directory, { recursive: true }); console.log('EVIDENCE ' + directory);
const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t, { modernDefaults: true }), checks = [], screenshots = [], errors = [];
@@ -114,14 +114,21 @@ try {
mark('open defaults save as real zeros, survive reload, hide local quotas and retain model selection at 1440 and 390 pixels');
await resize(1440); await dialog().getByRole('button', { name: '模型连接', exact: true }).click();
const connectedCard = () => dialog().locator('.mc-connection').filter({ has: page.getByRole('heading', { name: connection.name, exact: true }) });
await expect(connectedCard()).toContainText('默认透传 · 由上游决定');
await expect(connectedCard()).toContainText('模型最大上下文'); await expect(connectedCard()).toContainText('131,072 tokens');
await expect(connectedCard()).toContainText('32,768 tokens');
await connectedCard().getByRole('button', { name: '编辑', exact: true }).click();
const connectionEditor = () => dialog().getByRole('form', { name: '编辑模型连接', exact: true });
await expect(connectionEditor().getByLabel('上下文上限', { exact: true })).toHaveCount(0);
await expect(connectionEditor().getByLabel('输出上限', { exact: true })).toHaveCount(0);
await expect(connectionEditor().getByLabel('连接容量策略', { exact: true })).toContainText('默认透传 · 不设本地上限');
await expect(connectionEditor().getByLabel('模型最大上下文', { exact: true })).toHaveText('131,072 tokens');
await expect(connectionEditor().getByLabel('模型最大输出', { exact: true })).toHaveText('32,768 tokens');
assert.equal(await connectionEditor().evaluate(form => form.checkValidity()), true, 'An unlimited zero-concurrency connection must remain saveable.');
await expect(connectionEditor().getByRole('button', { name: '填入开发初始值', exact: true })).toHaveCount(0);
for (const width of [1440, 390]) { await resize(width); await connectionEditor().getByLabel('连接容量策略', { exact: true }).scrollIntoViewIfNeeded(); await shot('connection-passthrough-' + width); }
await connectionEditor().getByLabel('请求模型名称', { exact: true }).fill('owned-model-without-metadata');
await expect(connectionEditor().getByLabel('模型最大上下文', { exact: true })).toHaveText('本地无限制 · 由上游决定');
await expect(connectionEditor().getByLabel('模型最大输出', { exact: true })).toHaveText('本地无限制 · 由上游决定');
await connectionEditor().getByRole('button', { name: '取消', exact: true }).click();
await resize(1440); await dialog().locator('.mc-connection').filter({ has: page.getByRole('heading', { name: '原模型连接', exact: true }) }).getByRole('button', { name: '编辑', exact: true }).click();
const legacy = page.getByRole('dialog', { name: '原连接与演示设置', exact: true });
@@ -129,7 +136,8 @@ try {
await expect(legacy.getByLabel('上下文预算', { exact: true })).toHaveCount(0);
await expect(legacy.getByLabel('输出上限', { exact: true })).toHaveCount(0);
await legacy.getByRole('button', { name: '取消', exact: true }).click(); await open();
mark('connection list, editor and legacy settings display active passthrough without inactive 16000/2048 ceilings');
mark('proxy models display upstream maximums read-only; absent or different-model metadata shows unlimited local passthrough without 16000/2048 ceilings');
if (!capacityOnly) {
await resize(1440); await dialog().getByRole('button', { name: '等待时限', exact: true }).click();
const waits = () => dialog().getByRole('form', { name: '模型等待时限', exact: true });
await expect(waits().getByLabel('单次模型响应上限(秒)', { exact: true })).toHaveValue('0');
@@ -247,9 +255,11 @@ try {
await host.api('/sessions/' + browserSession.id + '/browsing/tabs/' + ownedTabId + '/close', { approved: true });
mark('actual Electron full access opens localhost, retains large DOM and 133 controls, fills password/select and navigates across origins without a manual approval');
}
}
assert.deepEqual(errors, []);
assert.equal(model.requests.filter(row => row.input).length, desktop ? 13 : 7);
result={success:true,version:host.bootstrap.version,appRoot,actualElectron:desktop,checks,screenshots,errors,realModelRequests:0,ownedModelRequests:desktop ? 13 : 7,directoryGets:model.requests.filter(row => !row.input).length,officialServiceTouched:false};
const expectedRequests = capacityOnly ? 2 : desktop ? 13 : 7;
assert.equal(model.requests.filter(row => row.input).length, expectedRequests);
result={success:true,version:host.bootstrap.version,appRoot,actualElectron:desktop,capacityOnly,checks,screenshots,errors,realModelRequests:0,ownedModelRequests:expectedRequests,directoryGets:model.requests.filter(row => !row.input).length,officialServiceTouched:false};
} catch(error) {if(page)await shot('failure').catch(()=>{});result={success:false,appRoot,actualElectron:desktop,checks,screenshots,errors,error:error.stack,realModelRequests:0};}
finally {if(application)await application.close();if(browser)await browser.close();if(controller&&await controller.health())await controller.stop();await host?.close?.();for(const dispose of disposers.reverse())await dispose();fs.writeFileSync(path.join(directory,'result.json'),JSON.stringify(result,null,2));}
console.log(JSON.stringify({directory,...result}));if(!result.success)process.exitCode=1;