73 lines
5.6 KiB
JavaScript
73 lines
5.6 KiB
JavaScript
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
import assert from 'node:assert/strict';
|
||
import { chromium, expect } from 'playwright/test';
|
||
import { fixture, launchWorkbench } from '../tests/helpers.mjs';
|
||
import { Provider } from '../src/server/provider.mjs';
|
||
import { openWorkbenchTool } from './ui-navigation.mjs';
|
||
|
||
const evidence = path.resolve('.qa/claude-output-capacity-2026-11-06');
|
||
const disposers = [], t = { after: fn => disposers.push(fn) };
|
||
const f = fixture(t, { modernDefaults: true }), provider = new Provider(), hub = provider.modelHub(f.store);
|
||
const profile = { baseUrl: 'http://127.0.0.1:9/v1', protocol: 'anthropic-messages', requiresKey: false, maxOutputTokens: 2048 };
|
||
const official = hub.upsert({ ...profile, name: 'Owned official Claude', model: 'claude-opus-5-5' });
|
||
const gateway = hub.upsert({ ...profile, name: 'Owned gateway declaration', model: 'claude-opus-5-5' });
|
||
hub.connection(gateway.id).upstreamModel = { id: 'claude-opus-5-5', maxOutputTokens: 64000, contextLimit: 200000 };
|
||
const unknown = hub.upsert({ ...profile, name: 'Owned unknown model', model: 'owned-unknown' });
|
||
hub.save(); const before = structuredClone(hub.state); f.store.close();
|
||
let browser, host;
|
||
const errors = [], marks = [];
|
||
try {
|
||
host = await launchWorkbench(t, f.data); assert.notEqual(new URL(host.url).port, '4318');
|
||
browser = await chromium.launch({ channel: 'msedge', headless: true });
|
||
const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
|
||
page.on('pageerror', cause => errors.push(cause.message));
|
||
const open = async () => { await openWorkbenchTool(page, '打开模型中心'); await expect(page.getByRole('dialog', { name: '模型中心', exact: true })).toBeVisible(); };
|
||
const card = id => page.locator('.mc-connection[data-connection-id="' + id + '"]');
|
||
const mark = value => { marks.push(value); console.log('PASS ' + value); };
|
||
await page.goto(host.url); await open();
|
||
await expect(card(official.id)).toContainText('128,000 tokens · Anthropic 官方规格');
|
||
await expect(card(official.id)).toContainText('1,000,000 tokens · Anthropic 官方规格');
|
||
await expect(card(official.id)).toContainText('max_tokens = 128000 · Anthropic 官方同步输出规格');
|
||
await expect(card(gateway.id)).toContainText('64,000 tokens · 上游目录');
|
||
await expect(card(unknown.id)).toContainText('本地无限制 · 由上游决定');
|
||
mark('official model and gateway declarations are distinct; unknown model stays unknown');
|
||
await page.screenshot({ path: path.join(evidence, 'model-center-1280.png') });
|
||
await card(official.id).getByRole('button', { name: '编辑', exact: true }).click();
|
||
const editor = page.getByRole('form', { name: '编辑模型连接', exact: true });
|
||
await expect(editor.getByLabel('模型最大输出', { exact: true })).toContainText('128,000');
|
||
await expect(editor.getByLabel('模型最大上下文', { exact: true })).toContainText('1,000,000');
|
||
await expect(editor.getByLabel('连接容量策略')).toContainText('Messages 按协议带 max_tokens');
|
||
await editor.getByRole('button', { name: '取消', exact: true }).click();
|
||
await card(official.id).getByRole('button', { name: '推理与能力', exact: true }).click();
|
||
const native = page.getByRole('form', { name: '原生请求参数', exact: true });
|
||
await expect(native).toContainText('当前 128000(Anthropic 官方同步输出规格)');
|
||
await native.getByLabel('原生参数 JSON').fill('{"max_tokens":300000}');
|
||
await native.getByRole('button', { name: '保存原生参数', exact: true }).click();
|
||
await expect(native).not.toBeVisible();
|
||
await expect(card(official.id)).toContainText('max_tokens = 300000 · 显式原生参数');
|
||
await page.reload(); await open();
|
||
await expect(card(official.id)).toContainText('max_tokens = 300000 · 显式原生参数');
|
||
await expect(card(official.id)).toContainText('128,000 tokens · Anthropic 官方规格');
|
||
mark('capacity editor and native settings show the same source; explicit user output survives refresh without changing the official maximum');
|
||
await page.setViewportSize({ width: 390, height: 844 });
|
||
await card(official.id).scrollIntoViewIfNeeded();
|
||
await expect(card(official.id)).toContainText('128,000 tokens · Anthropic 官方规格');
|
||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1));
|
||
await page.screenshot({ path: path.join(evidence, 'model-center-390.png') });
|
||
mark('390px model source and output value remain readable without page overflow');
|
||
const after = await host.api('/model-center');
|
||
assert.equal(after.connections.find(value => value.id === official.id).maxOutputTokens, 2048);
|
||
assert.equal(after.connections.find(value => value.id === official.id).nativeParameters.max_tokens, 300000);
|
||
for (const id of [gateway.id, unknown.id]) assert.deepEqual(after.connections.find(value => value.id === id).upstreamModel, before.connections.find(value => value.id === id).upstreamModel);
|
||
assert.equal(after.attempts.length, 0); assert.deepEqual(errors, []);
|
||
mark('saved user declaration and other models are preserved; UI makes zero model requests');
|
||
fs.writeFileSync(path.join(evidence, 'ui-result.json'), JSON.stringify({ marks, errors, viewportWidths: [1280, 390], realModelRequests: 0,
|
||
appRoot: process.env.AGENT_WORKBENCH_TEST_APP_ROOT, officialDeclaredOutput: 128000, explicitOutput: 300000 }, null, 2) + '\n', { flag: 'wx' });
|
||
} catch (cause) {
|
||
fs.writeFileSync(path.join(evidence, 'ui-failure.txt'), cause.stack ?? String(cause), { flag: 'wx' }); throw cause;
|
||
} finally {
|
||
await browser?.close(); await host?.close();
|
||
for (const dispose of disposers.reverse()) await dispose();
|
||
}
|