feat: add project index and exact patch review
This commit is contained in:
@@ -64,7 +64,7 @@ export async function upgradeRunning({ url, pid, currentRoot, newRoot, handlerRo
|
||||
if (!fs.existsSync(originalScript) || !fs.existsSync(upgradeScript) || !fs.existsSync(path.join(next, 'dist-client', 'index.html'))) throw new Error('Upgrade bundles are incomplete.');
|
||||
if (!Number.isInteger(pid) || pid < 1 || pid === process.pid) throw new Error('Invalid target process.');
|
||||
const before = await readUpgradeJson(origin + '/api/bootstrap', 5000, 'Read original Workbench');
|
||||
if (!before.token || !['0.1.0', '1.0.0', '1.1.0', '1.2.0'].includes(before.version)) throw new Error('This migration accepts a supported existing Workbench.');
|
||||
if (!before.token || !['0.1.0', '1.0.0', '1.1.0', '1.2.0', '1.3.0'].includes(before.version)) throw new Error('This migration accepts a supported existing Workbench.');
|
||||
if (before.sessions.some(session => ['running', 'awaiting_approval', 'stopping'].includes(session.status))) throw new Error('Wait for existing tasks and approvals before upgrading.');
|
||||
let protocol, socket, enabledHere = false, paused = false;
|
||||
const breakpoints = [];
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { chromium, expect } from 'playwright/test';
|
||||
|
||||
const url = process.env.AGENT_WORKBENCH_URL;
|
||||
if (!url || !/^http:\/\/127\.0\.0\.1:(?!4318(?:\/|$))\d+\/?$/.test(url)) throw new Error('Set AGENT_WORKBENCH_URL to an independent local QA service.');
|
||||
const root = path.resolve('.qa', 'index-ui-' + randomUUID()), primaryRoot = path.join(root, 'index-ui-project'), otherRoot = path.join(root, 'index-ui-other');
|
||||
fs.mkdirSync(path.join(primaryRoot, 'src'), { recursive: true }); fs.mkdirSync(otherRoot, { recursive: true }); fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const sourcePath = path.join(primaryRoot, 'src', 'invoice.ts');
|
||||
const banner = Array.from({ length: 180 }, (_, line) => '// 保留的项目说明 ' + (line + 1) + ' · 原文🙂').join('\r\n') + '\r\n';
|
||||
const original = '\uFEFF' + banner + 'export function total(amount: number, discount: number) { return amount - discount; }\r\nexport const currency = "CNY";\r\n';
|
||||
fs.writeFileSync(sourcePath, original);
|
||||
fs.writeFileSync(path.join(primaryRoot, 'src', 'Card.tsx'), 'import { total } from "./invoice.js";\nexport const Card = () => <p>{total(10, 2)}</p>;\n');
|
||||
fs.writeFileSync(path.join(primaryRoot, 'legacy.py'), '# def FakeComment():\n"""def FakeString():"""\ndef repair():\n pass\n');
|
||||
fs.writeFileSync(path.join(primaryRoot, 'broken.js'), 'export function unfinished(');
|
||||
fs.writeFileSync(path.join(primaryRoot, 'package.json'), JSON.stringify({ name: 'index-ui-project', type: 'module' }));
|
||||
fs.writeFileSync(path.join(otherRoot, 'other.ts'), 'export function otherOnly() { return true; }\n');
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
assert.equal(bootstrap.version, '1.3.0'); assert.equal(bootstrap.config.mode, 'demo'); assert.equal(bootstrap.config.hasKey, false);
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token }, ...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const value = await response.json(); assert.ok(response.ok, value.error); return value;
|
||||
};
|
||||
const primary = await api('/projects', { root: primaryRoot }), other = await api('/projects', { root: otherRoot });
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } }), page = await context.newPage();
|
||||
const passed = [], pageErrors = [], requestFailures = []; let heldRelease;
|
||||
page.on('pageerror', cause => pageErrors.push(cause.message));
|
||||
page.on('requestfailed', request => { if (request.resourceType() !== 'eventsource') requestFailures.push(request.url() + ': ' + request.failure()?.errorText); });
|
||||
const panel = () => page.getByLabel('工程索引', { exact: true });
|
||||
const indexTab = () => page.locator('.inspector-tabs').getByRole('button', { name: '索引', exact: true });
|
||||
const screenshot = name => page.screenshot({ path: '.qa/screenshots/' + name + '.png', scale: 'css' });
|
||||
async function find(query, kind = 'symbols') {
|
||||
await panel().getByLabel('索引查询').fill(query);
|
||||
if (await panel().getByLabel('索引结果类型').inputValue() !== kind) await panel().getByLabel('索引结果类型').selectOption(kind);
|
||||
else await panel().getByRole('button', { name: '查找', exact: true }).click();
|
||||
await expect(panel().getByRole('button', { name: '查找', exact: true })).toBeEnabled();
|
||||
await expect(panel().getByRole('status')).toContainText('“' + query + '”');
|
||||
}
|
||||
async function checkPosition(line) {
|
||||
await expect(page.locator('.code-line-target')).toHaveAttribute('data-line', String(line));
|
||||
await expect.poll(() => page.evaluate(() => {
|
||||
const line = document.querySelector('.code-line-target').getBoundingClientRect(), area = document.querySelector('.code-view').getBoundingClientRect();
|
||||
return line.top >= area.top && line.bottom <= area.bottom;
|
||||
})).toBe(true);
|
||||
const layout = await page.evaluate(() => ({ scrollY, header: document.querySelector('.work-header').getBoundingClientRect().top,
|
||||
composerBottom: document.querySelector('.composer-wrap').getBoundingClientRect().bottom, height: innerHeight }));
|
||||
assert.equal(layout.scrollY, 0); assert.ok(layout.header >= 0); assert.ok(layout.composerBottom <= layout.height + 1);
|
||||
}
|
||||
try {
|
||||
await page.goto(url); await page.waitForLoadState('networkidle');
|
||||
await page.getByLabel('当前项目', { exact: true }).selectOption(primary.id);
|
||||
fs.writeFileSync(path.join(root, 'initial-dom.html'), await page.content());
|
||||
assert.ok((await page.locator('.inspector-tabs button').allTextContents()).some(value => value === '索引'));
|
||||
await indexTab().click(); await expect(panel()).toBeVisible();
|
||||
await expect(panel().getByRole('button', { name: '查找', exact: true })).toBeEnabled();
|
||||
await expect(panel()).toContainText('当前项目 · index-ui-project'); await expect(panel()).toContainText('部分结果');
|
||||
assert.equal((await api('/sessions')).filter(value => value.projectId === primary.id).length, 0);
|
||||
passed.push('工程索引可独立于任务使用,实际覆盖范围与损坏文件显示明确');
|
||||
|
||||
await find('total'); await expect(panel().locator('.index-result-location')).toContainText(':181');
|
||||
await screenshot('m2-index-desktop');
|
||||
await panel().getByRole('button', { name: '打开 src/invoice.ts 第 181 行 total', exact: true }).click();
|
||||
await checkPosition(181); await screenshot('m2-index-desktop-line');
|
||||
passed.push('真实AST查询打开原文件第181行并仅滚动代码容器,输入区和顶部保持可见');
|
||||
|
||||
await indexTab().click(); await expect(panel().getByLabel('索引查询')).toHaveValue('total');
|
||||
fs.writeFileSync(sourcePath, '\uFEFF// 新说明1\r\n// 新说明2\r\n// 新说明3\r\n' + original.slice(1));
|
||||
await panel().getByRole('button', { name: '打开 src/invoice.ts 第 181 行 total', exact: true }).click();
|
||||
await expect(page.getByText('文件在索引后已变化,已打开当前内容。请回到索引刷新后重新定位。', { exact: true })).toBeVisible();
|
||||
await expect(page.locator('.code-line-target')).toHaveCount(0); await expect(page.locator('.code-view')).toContainText('新说明3');
|
||||
await indexTab().click(); await panel().getByRole('button', { name: '刷新工程索引' }).click();
|
||||
await expect(panel().getByRole('button', { name: '查找', exact: true })).toBeEnabled();
|
||||
await panel().getByRole('button', { name: '打开 src/invoice.ts 第 184 行 total', exact: true }).click(); await checkPosition(184);
|
||||
passed.push('查询词保留;过期SHA不高亮旧位置,增量刷新后正确定位第184行');
|
||||
|
||||
await indexTab().click(); let held = false;
|
||||
const gate = new Promise(resolve => { heldRelease = resolve; });
|
||||
const routePattern = new RegExp('/api/projects/' + primary.id + '/code-query\\?');
|
||||
await page.route(routePattern, async route => { const response = await route.fetch(); held = true; await gate; await route.fulfill({ response }); });
|
||||
await panel().getByRole('button', { name: '刷新工程索引' }).click(); await expect.poll(() => held).toBe(true);
|
||||
await page.getByLabel('当前项目', { exact: true }).selectOption(other.id);
|
||||
await expect(panel()).toContainText('当前项目 · index-ui-other'); await expect(panel()).toContainText('otherOnly');
|
||||
heldRelease(); await page.waitForTimeout(300); await page.unroute(routePattern);
|
||||
await expect(panel()).not.toContainText('src/invoice.ts'); await expect(panel()).toContainText('otherOnly');
|
||||
passed.push('切换项目时延迟返回的旧索引不覆盖新项目结果');
|
||||
|
||||
await page.getByLabel('当前项目', { exact: true }).selectOption(primary.id);
|
||||
await expect(panel().getByRole('button', { name: '查找', exact: true })).toBeEnabled(); await find('repair');
|
||||
await expect(panel()).toContainText('Python 候选 · 需读源码核对'); await expect(panel().locator('.index-result-location')).toContainText('legacy.py');
|
||||
await find('FakeString'); await expect(panel().getByText('当前范围没有匹配', { exact: true })).toBeVisible();
|
||||
await find('invoice.js', 'imports'); await expect(panel()).toContainText('文件候选 → src/invoice.ts');
|
||||
await panel().getByText('查看索引范围与依据', { exact: true }).click(); await expect(panel()).toContainText('不证明实际运行时模块解析');
|
||||
passed.push('Python候选、字符串误报排除和局部导入文件候选保留真实证据标签');
|
||||
|
||||
const current = await api('/projects/' + primary.id + '/file?path=src%2Finvoice.ts'), before = fs.readFileSync(sourcePath);
|
||||
const session = await api('/sessions', { projectId: primary.id });
|
||||
const proposed = await api('/sessions/' + session.id + '/patch-proposals', { path: 'src/invoice.ts', base_sha256: current.sha256, reason: '精确调整金额与币种', edits: [
|
||||
{ old_text: 'return amount - discount;', new_text: 'return Math.max(0, amount - discount);' }, { old_text: 'currency = "CNY"', new_text: 'currency = "USD"' }] });
|
||||
assert.deepEqual(fs.readFileSync(sourcePath), before);
|
||||
await page.evaluate(id => localStorage.setItem('awb-session', id), session.id); await page.reload(); await page.waitForLoadState('networkidle');
|
||||
await page.locator('.inspector-tabs').getByRole('button', { name: /^改动/ }).click();
|
||||
await expect(page.locator('.patch-detail')).toHaveText('精确补丁 · 2 处替换 · 保留 CRLF 换行 · 保留 BOM');
|
||||
await expect.poll(() => page.evaluate(() => {
|
||||
const row = document.querySelector('.diff-removed').getBoundingClientRect(), area = document.querySelector('.diff-view').getBoundingClientRect();
|
||||
return row.top > area.top && row.bottom <= area.bottom;
|
||||
})).toBe(true);
|
||||
await page.evaluate(() => { document.querySelector('.diff-view').scrollTop = 0; });
|
||||
await page.getByRole('button', { name: '定位首处改动', exact: true }).click();
|
||||
await expect.poll(() => page.evaluate(() => document.querySelector('.diff-view').scrollTop > 0)).toBe(true);
|
||||
await screenshot('m2-index-patch-desktop'); await page.getByRole('button', { name: '应用这项改动', exact: true }).click();
|
||||
await expect(page.getByText('这项改动已写入项目。', { exact: true })).toBeVisible();
|
||||
const expected = before.toString('utf8').replace('return amount - discount;', 'return Math.max(0, amount - discount);').replace('currency = "CNY"', 'currency = "USD"');
|
||||
assert.deepEqual(fs.readFileSync(sourcePath), Buffer.from(expected)); assert.equal((await api('/sessions/' + proposed.id)).changes[0].status, 'applied');
|
||||
passed.push('两处唯一锚点成为待审核提案,真实界面应用后BOM/CRLF和未选择原字节保留');
|
||||
|
||||
await page.setViewportSize({ width: 390, height: 844 }); await expect(page.getByRole('button', { name: '查看文件', exact: true })).toBeVisible();
|
||||
await page.getByRole('button', { name: '查看文件', exact: true }).click(); await indexTab().click();
|
||||
await panel().getByRole('button', { name: '刷新工程索引' }).click(); await expect(panel().getByRole('button', { name: '查找', exact: true })).toBeEnabled();
|
||||
await find('total'); await panel().getByText('查看索引范围与依据', { exact: true }).click();
|
||||
const bounds = await page.evaluate(() => ({ page: document.documentElement.scrollWidth <= innerWidth,
|
||||
panel: document.querySelector('.code-index-panel').scrollWidth <= document.querySelector('.code-index-panel').clientWidth + 1,
|
||||
tabs: document.querySelector('.inspector-tabs').scrollWidth <= document.querySelector('.inspector-tabs').clientWidth + 1 }));
|
||||
assert.deepEqual(bounds, { page: true, panel: true, tabs: true }); await screenshot('m2-index-mobile');
|
||||
await panel().getByRole('button', { name: '打开 src/invoice.ts 第 184 行 total', exact: true }).click(); await checkPosition(184); await screenshot('m2-index-mobile-line');
|
||||
passed.push('390px索引查询、范围和完整指纹可读且无横向溢出,实际文件行定位通过');
|
||||
|
||||
await indexTab().click(); const errorPattern = new RegExp('/api/projects/' + primary.id + '/code-query\\?'); let failNext = true;
|
||||
await page.route(errorPattern, route => { if (failNext) { failNext = false; return route.fulfill({ status: 409, contentType: 'application/json', body: JSON.stringify({ error: '建立索引期间文件已变化,请刷新工程索引。' }) }); } return route.continue(); });
|
||||
await panel().getByRole('button', { name: '刷新工程索引' }).click(); await expect(panel().getByRole('alert')).toContainText('索引未刷新');
|
||||
await expect(panel().locator('.index-result').first()).toBeDisabled(); await panel().getByRole('button', { name: '重试索引' }).click();
|
||||
await expect(panel().getByRole('alert')).toHaveCount(0); await expect(panel().locator('.index-result').first()).toBeEnabled(); await page.unroute(errorPattern);
|
||||
passed.push('索引刷新失败保留归属和解释,旧结果禁用并可重试恢复');
|
||||
assert.deepEqual(pageErrors, []); assert.deepEqual(requestFailures, []);
|
||||
const result = { checkedAt: new Date().toISOString(), version: bootstrap.version, passed, pageErrors, requestFailures, root, primaryProjectId: primary.id, otherProjectId: other.id };
|
||||
fs.writeFileSync('.qa/index-ui-result.json', JSON.stringify(result, null, 2) + '\n'); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (cause) {
|
||||
fs.writeFileSync('.qa/index-ui-failure.json', JSON.stringify({ passed, pageErrors, requestFailures, message: cause.message, root }, null, 2));
|
||||
await screenshot('m2-index-failure').catch(() => {}); throw cause;
|
||||
} finally { heldRelease?.(); await browser.close(); }
|
||||
@@ -8,32 +8,43 @@ import { APP_VERSION } from '../src/server/diagnostics.mjs';
|
||||
// Operates only on a fresh synthetic project. The configured model remains in
|
||||
// the running host; bootstrap contains an API session token, never its model key.
|
||||
const workspace = process.cwd();
|
||||
const precision = process.argv.includes('--precision');
|
||||
const bannerLines = 420;
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4318';
|
||||
const origin = new URL(url);
|
||||
assert.equal(origin.hostname, '127.0.0.1'); assert.equal(origin.protocol, 'http:');
|
||||
const bootstrap = await (await fetch(origin.origin + '/api/bootstrap')).json();
|
||||
const bootstrap = await (await fetch(origin.origin + '/api/bootstrap', { headers: { Connection: 'close' } })).json();
|
||||
assert.equal(bootstrap.version, APP_VERSION); assert.equal(bootstrap.config.mode, 'compatible');
|
||||
assert.ok(bootstrap.config.model, 'Configure a model on the running Workbench first.');
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(origin.origin + '/api' + route, { method: input === undefined ? 'GET' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token },
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token, Connection: 'close' },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }), signal: AbortSignal.timeout(15000) });
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw Object.assign(new Error(result.error ?? 'Workbench HTTP ' + response.status), { status: response.status });
|
||||
return result;
|
||||
};
|
||||
|
||||
const caseRoot = path.resolve('.qa', 'live-delivery-' + randomUUID());
|
||||
const projectRoot = path.join(caseRoot, '交付报告工程');
|
||||
const caseRoot = path.resolve('.qa', (precision ? 'live-precision-' : 'live-delivery-') + randomUUID());
|
||||
const projectRoot = path.join(caseRoot, precision ? '精确补丁交付工程' : '交付报告工程');
|
||||
const allowed = ['src/normalize.mjs', 'src/summary.mjs', 'src/render.mjs', 'src/cli.mjs'];
|
||||
const scripts = { test: 'node --test test/*.test.mjs', build: 'node scripts/build.mjs' };
|
||||
fs.mkdirSync(caseRoot, { recursive: true });
|
||||
fs.cpSync(path.join(workspace, 'benchmarks/node-delivery-v1/baseline'), projectRoot, { recursive: true });
|
||||
const sourcePrefixes = {}, sourceFormats = {};
|
||||
if (precision) for (const file of allowed) {
|
||||
const target = path.join(projectRoot, file), body = fs.readFileSync(target, 'utf8').replaceAll('\r\n', '\n');
|
||||
const bom = ['src/normalize.mjs', 'src/cli.mjs'].includes(file), ending = bom ? '\r\n' : '\n';
|
||||
const banner = Array.from({ length: bannerLines }, (_, line) => '// 保留工程说明 ' + (line + 1) + ' · ' + file + ' · 原文🙂').join(ending) + ending;
|
||||
const prefix = (bom ? '\uFEFF' : '') + banner;
|
||||
sourcePrefixes[file] = Buffer.from(prefix); sourceFormats[file] = { bom, lineEnding: bom ? 'crlf' : 'lf', firstSourceLine: bannerLines + 1 };
|
||||
fs.writeFileSync(target, prefix + body.replaceAll('\n', ending));
|
||||
}
|
||||
fs.writeFileSync(path.join(projectRoot, '.gitignore'), 'dist/\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'OWNER-NOTES.md'), '# Owner notes\nBaseline owner content.\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'OWNER-STAGED.txt'), 'Baseline staged owner content.\n');
|
||||
const git = args => execFileSync('git', ['-c', 'core.autocrlf=false', '-c', 'user.name=Agent Workbench QA', '-c', 'user.email=qa@workbench.local', '-C', projectRoot, ...args], { encoding: 'utf8', windowsHide: true });
|
||||
git(['init', '--initial-branch=main']); git(['add', '.']); git(['commit', '-m', 'test: seal delivery-report acceptance baseline']);
|
||||
git(['init', '--initial-branch=main']); git(['config', 'core.autocrlf', 'false']); git(['add', '.']); git(['commit', '-m', 'test: seal delivery-report acceptance baseline']);
|
||||
const baselineCommit = git(['rev-parse', 'HEAD']).trim();
|
||||
fs.appendFileSync(path.join(projectRoot, 'OWNER-NOTES.md'), 'Existing owner edit: ' + randomUUID() + '\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'UNTRACKED-OWNER.txt'), 'Existing untracked owner file: ' + randomUUID() + '\n');
|
||||
@@ -49,6 +60,12 @@ const assertProtected = () => {
|
||||
for (const [file, hash] of Object.entries(protectedHashes)) assert.equal(sha(file), hash, 'Protected input changed: ' + file);
|
||||
assert.equal(git(['diff', '--', 'OWNER-NOTES.md']), ownerDiff, 'Existing owner edits changed.');
|
||||
assert.equal(git(['diff', '--cached', '--', 'OWNER-STAGED.txt']), ownerStagedDiff, 'Existing owner stage changed.');
|
||||
if (precision) for (const file of allowed) {
|
||||
const bytes = fs.readFileSync(path.join(projectRoot, file)); assert.deepEqual(bytes.subarray(0, sourcePrefixes[file].length), sourcePrefixes[file], 'Protected source banner changed: ' + file);
|
||||
const text = bytes.toString('utf8');
|
||||
if (sourceFormats[file].lineEnding === 'crlf') assert.ok(!/(^|[^\r])\n/.test(text), 'CRLF changed: ' + file);
|
||||
else assert.ok(!text.includes('\r'), 'LF changed: ' + file);
|
||||
}
|
||||
};
|
||||
const project = await api('/projects', { root: projectRoot });
|
||||
const session = await api('/sessions', { projectId: project.id });
|
||||
@@ -56,14 +73,17 @@ const started = Date.now(), applied = [], decisions = [], reviewLimit = 4;
|
||||
let reviewedRounds = 0, state, succeeded = false, lastProgress = '', originalTaskId;
|
||||
const saveEvidence = result => {
|
||||
fs.writeFileSync(path.join(caseRoot, 'result.json'), JSON.stringify(result, null, 2));
|
||||
fs.writeFileSync(path.join(workspace, '.qa/live-delivery-validation.json'), JSON.stringify(result, null, 2));
|
||||
fs.writeFileSync(path.join(workspace, precision ? '.qa/live-precision-validation.json' : '.qa/live-delivery-validation.json'), JSON.stringify(result, null, 2));
|
||||
};
|
||||
|
||||
try {
|
||||
await api('/sessions/' + session.id + '/messages', { content:
|
||||
'完成当前 Delivery Report 工程,严格实现 README.md 的七项要求。先用 inspect_project 识别工程,' +
|
||||
'再用 plan_checks 选择 test/build,并用 run_checks 实际运行封存输入,取得失败的测试和日志。' +
|
||||
'依据实际失败读取有关文件,使用 read_artifact 进一步核对失败日志。只能用 propose_file 修改 src/normalize.mjs、src/summary.mjs、src/render.mjs、src/cli.mjs;' +
|
||||
'依据实际失败读取有关文件,使用 read_artifact 进一步核对失败日志。' + (precision
|
||||
? '先用 index_project 建立工程索引,再用 query_code 的 symbols/imports 结果定位源码,特别是CLI入口的实际导入行。每个源码模块前420行都是须原字节保留的说明;用 read_file 指定start_line至少421的必要行范围,取得最新SHA256。已有源码只能用 propose_patch 及该SHA256、唯一old_text锚点精确修改;保留BOM及原LF/CRLF,不使用 propose_file,不读整个说明块。'
|
||||
: '只能用 propose_file 修改 src/normalize.mjs、src/summary.mjs、src/render.mjs、src/cli.mjs;') +
|
||||
'允许修改的源码仅为 src/normalize.mjs、src/summary.mjs、src/render.mjs、src/cli.mjs。' +
|
||||
'测试、fixtures、构建脚本、package.json、README 和 OWNER 文件必须保留。四模块都需修复,不能修改验收来通过。' +
|
||||
'本工程没有第三方依赖,不用安装。不要使用 run_command、不要自己提交Git;本轮终端仅通过已识别的npm检查计划运行。' +
|
||||
'提案等待审查应用,随后继续同一目标并实际重新运行 test/build,依据日志修复直至通过。检查通过后用 plan_delivery 准备本Task的四文件本地Git预览,等待用户独立确认;最后用中文报告实际测试数量、构建结果和改动。' });
|
||||
@@ -80,6 +100,12 @@ try {
|
||||
lastProgress = progress;
|
||||
}
|
||||
for (const proposal of state.changes.filter(change => ['pending', 'conflict'].includes(change.status))) assert.ok(allowed.includes(proposal.path), 'Out-of-scope proposal: ' + proposal.path);
|
||||
if (precision) {
|
||||
assert.ok(!state.events.some(event => event.tool === 'propose_file'), 'Precision sample must use exact patch proposals only.');
|
||||
for (const event of state.events.filter(event => event.tool === 'read_file' && allowed.includes(event.input?.path))) {
|
||||
assert.ok(event.input.start_line >= bannerLines + 1, 'Source reads must target indexed implementation lines: ' + event.input.path);
|
||||
}
|
||||
}
|
||||
for (const approval of state.approvals.filter(item => item.status === 'pending')) {
|
||||
const plan = state.execution.plans?.find(item => item.id === approval.checkPlanId);
|
||||
const allow = !!plan && plan.taskId === originalTaskId && plan.checks.length > 0 && plan.checks.length <= 2
|
||||
@@ -103,9 +129,15 @@ try {
|
||||
for (const proposal of pending) {
|
||||
assert.equal(sha(proposal.path), proposal.baseSha256, 'Proposal baseline changed.');
|
||||
assert.notEqual(proposal.content.trim(), '', 'Empty source proposal.');
|
||||
if (precision) {
|
||||
assert.equal(proposal.editKind, 'exact-patch'); assert.ok(proposal.patch.edits > 0);
|
||||
assert.ok(proposal.patch.ranges.every(range => range.startLine >= bannerLines + 1), 'Patch must not select the preserved banner.');
|
||||
assert.deepEqual(Buffer.from(proposal.content).subarray(0, sourcePrefixes[proposal.path].length), sourcePrefixes[proposal.path]);
|
||||
assert.equal(proposal.patch.preservedBom, sourceFormats[proposal.path].bom); assert.equal(proposal.patch.lineEnding, sourceFormats[proposal.path].lineEnding);
|
||||
}
|
||||
const beforeApply = await api('/sessions/' + session.id + '/changes/' + proposal.id + '/apply', {});
|
||||
assert.equal(sha(proposal.path), proposal.sha256, 'Applied bytes do not match the reviewed proposal.');
|
||||
applied.push({ id: proposal.id, path: proposal.path, sha256: proposal.sha256, taskId: originalTaskId });
|
||||
applied.push({ id: proposal.id, path: proposal.path, sha256: proposal.sha256, taskId: originalTaskId, ...(precision ? { editKind: proposal.editKind, patch: proposal.patch } : {}) });
|
||||
assert.ok(beforeApply.session ?? beforeApply, 'No apply response.'); assertProtected();
|
||||
}
|
||||
await api('/sessions/' + session.id + '/continue-reviewed', {}); continue;
|
||||
@@ -120,6 +152,16 @@ try {
|
||||
assert.deepEqual([...new Set(applied.map(item => item.path))].sort(), [...allowed].sort());
|
||||
for (const file of allowed) assert.notEqual(sha(file), beforeSources[file], 'Module was not repaired: ' + file);
|
||||
assertProtected();
|
||||
let precisionEvidence = null;
|
||||
if (precision) {
|
||||
const indexed = state.events.filter(event => event.tool === 'index_project' && event.phase === 'completed'), queries = state.events.filter(event => event.tool === 'query_code' && event.phase === 'completed');
|
||||
assert.ok(indexed.length > 0 && queries.length > 0, 'The model must use project index and symbol/import queries.');
|
||||
const sourceReads = state.events.filter(event => event.tool === 'read_file' && event.phase === 'completed' && allowed.includes(event.input?.path));
|
||||
for (const file of allowed) assert.ok(sourceReads.some(event => event.input.path === file), 'Each patched source must be read by its actual lines: ' + file);
|
||||
precisionEvidence = { bannerLines, formats: sourceFormats, preservedPrefixes: Object.fromEntries(allowed.map(file => [file, { bytes: sourcePrefixes[file].length, sha256: createHash('sha256').update(sourcePrefixes[file]).digest('hex') }])),
|
||||
indexCalls: indexed.length, queryCalls: queries.length, sourceReads: sourceReads.map(event => ({ path: event.input.path, startLine: event.input.start_line, endLine: event.input.end_line ?? null, runId: event.runId })),
|
||||
exactPatchesOnly: true, sourcePrefixesPreserved: true, formatPreserved: true };
|
||||
}
|
||||
const built = spawnSync(process.execPath, [path.join(projectRoot, 'dist/cli.mjs'), path.join(projectRoot, 'fixtures/tasks.json'), '--json'], { cwd: projectRoot, encoding: 'utf8', windowsHide: true });
|
||||
assert.equal(built.status, 0); assert.equal(built.stderr, '');
|
||||
assert.deepEqual(JSON.parse(built.stdout), { total: 4, counts: { todo: 0, doing: 1, done: 2, blocked: 1 }, completedPercent: 50, remainingMinutes: 50 });
|
||||
@@ -165,14 +207,14 @@ try {
|
||||
do { log = await api('/artifacts/' + result.logArtifactId + '?session=' + session.id + '&offset=' + offset + '&limit=16000'); text += log.content; offset += log.content.length; } while (log.truncated && log.content.length);
|
||||
fs.writeFileSync(path.join(caseRoot, job.id + '-' + result.name + '.log'), text);
|
||||
}
|
||||
const result = { success: true, version: bootstrap.version, testedAt: new Date().toISOString(), model: bootstrap.config.model,
|
||||
const result = { success: true, version: bootstrap.version, mode: precision ? 'indexed-exact-patch' : 'whole-file', testedAt: new Date().toISOString(), model: bootstrap.config.model,
|
||||
projectRoot, projectId: project.id, sessionId: session.id, taskId: originalTaskId, baselineCommit, deliveredCommit, deliveryPlan, deliveryJob,
|
||||
elapsedSeconds: Math.round((Date.now() - started) / 1000), runs: state.execution.runs.length, reviewRounds: reviewedRounds, applied,
|
||||
protectedHashes, ownerEditsPreserved: true, ownerStagePreserved: true, reportStatus: report.status, reportPath: path.join(caseRoot, 'delivery-report.md'), buildOutput: JSON.parse(built.stdout), usage: state.execution.task.usage,
|
||||
protectedHashes, ownerEditsPreserved: true, ownerStagePreserved: true, precisionEvidence, reportStatus: report.status, reportPath: path.join(caseRoot, 'delivery-report.md'), buildOutput: JSON.parse(built.stdout), usage: state.execution.task.usage,
|
||||
checks: state.execution.checks, decisions, diffPath: path.join(caseRoot, 'reviewed-changes.diff'), sessionPath: path.join(caseRoot, 'session.json'),
|
||||
credentialsHandling: 'Calls use the running host model configuration; no model key was read, copied or saved.',
|
||||
intervention: 'Verifier approved only sealed npm scripts, reviewed and applied four source proposals, and confirmed an owned Git preview through the Workbench API. Implementation came from the configured model; the Workbench generated and verified the commit and evidence reports.',
|
||||
scope: 'One synthetic Node engineering sample; does not establish M2 or M6 delivery success rates.' };
|
||||
scope: 'One synthetic Node engineering sample; does not establish all M2 engineering classes, ChangeSet/worktree or M6 delivery success rates.' };
|
||||
saveEvidence(result); succeeded = true;
|
||||
console.log(JSON.stringify({ success: true, model: result.model, testsPassed: 14, buildPassed: true, deliveredCommit, elapsedSeconds: result.elapsedSeconds, reviewRounds: reviewedRounds, projectRoot, sessionId: session.id }, null, 2));
|
||||
} catch (error) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { createHash } from 'node:crypto';
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4318';
|
||||
const sessionId = process.env.AGENT_WORKBENCH_SESSION || '569c9457-d399-46e6-b53e-4b1fdbb02109';
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
assert.ok(['1.0.0', '1.1.0', '1.2.0'].includes(bootstrap.version));
|
||||
assert.ok(['1.0.0', '1.1.0', '1.2.0', '1.3.0'].includes(bootstrap.version));
|
||||
assert.equal(bootstrap.config.mode, 'compatible');
|
||||
assert.ok(bootstrap.config.hasKey, 'The existing in-memory connection must be present.');
|
||||
const api = async (route, input) => {
|
||||
|
||||
Reference in New Issue
Block a user