feat: use verified project memory within request budgets

This commit is contained in:
Agent Workbench Dev
2026-10-30 18:16:46 +08:00
parent f7292a9140
commit af0a42b610
18 changed files with 394 additions and 23 deletions
+41 -3
View File
@@ -3,12 +3,13 @@ import path from 'node:path';
import assert from 'node:assert/strict';
import { randomUUID } from 'node:crypto';
import { chromium, expect } from 'playwright/test';
import { fixture, launchWorkbench } from '../tests/helpers.mjs';
import { fixture, launchWorkbench, compatibleFixture, completion, until } from '../tests/helpers.mjs';
const evidenceDir = path.resolve('.qa', 'project-memory-ui-' + randomUUID());
fs.mkdirSync(evidenceDir, { recursive: true });
const disposers = [], t = { after: dispose => disposers.push(dispose) };
const f = fixture(t); f.store.close();
const model = await compatibleFixture(t, () => completion([], '本地HTTP验收:已核对本次记忆上下文。'));
const host = await launchWorkbench(t, f.data);
assert.notEqual(new URL(host.url).port, '4318');
const browser = await chromium.launch({ channel: 'msedge', headless: true });
@@ -63,10 +64,47 @@ try {
assert.ok(await page.locator('body').evaluate(node => node.scrollWidth <= 390), '390px viewport must not overflow horizontally');
await page.screenshot({ path: path.join(evidenceDir, 'mobile-incomplete-memory.png'), fullPage: false });
mark('390px memory review stays within the viewport with the incomplete-scan warning visible');
fs.rmSync(path.join(f.projectRoot, 'oversized-source.mjs'));
await dialog.getByRole('button', { name: '重新核对', exact: true }).click();
await expect(currentCard).toContainText('当前');
await page.keyboard.press('Escape');
await host.api('/config', { mode: 'compatible', baseUrl: model.baseUrl, model: 'owned-memory-ui', apiKey: 'owned-ui-fixture-key', contextLimit: 24000 });
await host.api('/sessions/' + session.id + '/messages', { content: '读取当前项目记忆,说明你获得的项目上下文。' });
await until(async () => (await host.api('/sessions/' + session.id)).status === 'completed');
assert.equal(model.requests.length, 1);
const actual = model.requests[0].input;
assert.ok(actual.messages.some(value => value.role === 'system' && value.content.includes('"project_memory":')));
assert.equal(JSON.stringify(actual).includes('owned-ui-fixture-key'), false);
await page.setViewportSize({ width: 1440, height: 1000 });
await page.reload(); await expect(page.getByRole('button', { name: '查看任务记录', exact: true })).toBeVisible();
await page.getByRole('button', { name: '查看任务记录', exact: true }).click();
const context = page.getByLabel('请求上下文', { exact: true });
await expect(context).toContainText('1 条来源已核对的记录');
await context.getByRole('button', { name: '查看本次项目记忆', exact: true }).click();
const artifact = page.getByRole('dialog', { name: '执行结果工件', exact: true });
await expect(artifact.locator('pre')).toContainText('扫描范围记忆');
await expect(artifact.locator('pre')).toContainText('sourceFingerprint');
await page.screenshot({ path: path.join(evidenceDir, 'desktop-sent-memory.png') });
await page.keyboard.press('Escape');
await page.setViewportSize({ width: 390, height: 844 });
await page.getByRole('button', { name: '查看任务记录', exact: true }).click();
await expect(context).toBeVisible();
await context.getByRole('button', { name: '查看本次项目记忆', exact: true }).click();
await expect(artifact.locator('pre')).toContainText('扫描范围记忆');
assert.ok(await page.locator('body').evaluate(node => node.scrollWidth <= 390));
await page.screenshot({ path: path.join(evidenceDir, 'mobile-sent-memory.png') });
mark('desktop and 390px request records expose the exact memory snapshot used by one owned local HTTP request');
assert.deepEqual(pageErrors, []); assert.deepEqual(requestFailures, []);
fs.writeFileSync(path.join(evidenceDir, 'result.json'), JSON.stringify({ url: host.url, viewportWidths: [1440, 390],
assertions: marks, pageErrors, requestFailures, screenshots: ['desktop-expired-memory.png', 'mobile-incomplete-memory.png'] }, null, 2));
fs.writeFileSync(path.join(evidenceDir, 'result.json'), JSON.stringify({ success: true, url: host.url, viewportWidths: [1440, 390],
assertions: marks, pageErrors, requestFailures, localFixtureModelRequests: model.requests.length, realModelRequests: 0,
screenshots: ['desktop-expired-memory.png', 'mobile-incomplete-memory.png', 'desktop-sent-memory.png', 'mobile-sent-memory.png'] }, null, 2));
console.log('EVIDENCE ' + evidenceDir);
} catch (error) {
await page.screenshot({ path: path.join(evidenceDir, 'failure.png') }).catch(() => {});
fs.writeFileSync(path.join(evidenceDir, 'result.json'), JSON.stringify({ success: false, error: error.message, assertions: marks, pageErrors, requestFailures }, null, 2));
console.log('EVIDENCE ' + evidenceDir);
throw error;
} finally {
await browser.close();
for (const dispose of disposers.reverse()) await dispose();