feat: add reviewed Task Git delivery and verified evidence reports
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'].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'].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,63 @@
|
||||
import hashlib
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path, PurePosixPath
|
||||
import sys
|
||||
import uuid
|
||||
import zipfile
|
||||
|
||||
workspace = Path(__file__).resolve().parent.parent
|
||||
release_dir = (workspace / 'releases').resolve()
|
||||
release = json.loads((release_dir / 'latest.json').read_text(encoding='utf-8'))
|
||||
records = []
|
||||
extraction_root = None
|
||||
version = None
|
||||
|
||||
for kind, root_key in [('portable', 'portableRoot'), ('source', 'sourceRoot')]:
|
||||
root = Path(release[root_key]).resolve()
|
||||
archive = Path(release[kind]['path']).resolve()
|
||||
assert root.is_relative_to(release_dir) and archive.is_relative_to(release_dir)
|
||||
archive_bytes = archive.read_bytes()
|
||||
assert len(archive_bytes) == release[kind]['bytes']
|
||||
assert hashlib.sha256(archive_bytes).hexdigest() == release[kind]['sha256']
|
||||
manifest = json.loads((root / 'MANIFEST.json').read_text(encoding='utf-8'))
|
||||
version = version or manifest['version']
|
||||
assert manifest['version'] == version and manifest['kind'] == kind
|
||||
expected = {entry['path']: entry for entry in manifest['files']}
|
||||
assert len(expected) == len(manifest['files'])
|
||||
with zipfile.ZipFile(archive) as bundle:
|
||||
assert bundle.testzip() is None, 'CRC failure'
|
||||
actual = {}
|
||||
for entry in bundle.infolist():
|
||||
name = PurePosixPath(entry.filename.replace('\\', '/'))
|
||||
assert not name.is_absolute() and '..' not in name.parts and name.parts[0] == root.name
|
||||
if entry.is_dir():
|
||||
continue
|
||||
relative = str(PurePosixPath(*name.parts[1:]))
|
||||
assert relative not in actual, 'Duplicate archive entry'
|
||||
actual[relative] = entry
|
||||
assert set(actual) == set(expected) | {'MANIFEST.json'}
|
||||
for relative, entry in actual.items():
|
||||
contents = bundle.read(entry)
|
||||
target = (root / relative).resolve()
|
||||
assert target.is_relative_to(root) and contents == target.read_bytes(), relative
|
||||
if relative != 'MANIFEST.json':
|
||||
assert len(contents) == expected[relative]['bytes']
|
||||
assert hashlib.sha256(contents).hexdigest() == expected[relative]['sha256']
|
||||
if kind == 'source' and '--extract-source' in sys.argv:
|
||||
isolated = (workspace / '.qa' / ('source-check-' + uuid.uuid4().hex)).resolve()
|
||||
assert isolated.is_relative_to((workspace / '.qa').resolve())
|
||||
isolated.mkdir(parents=True, exist_ok=False)
|
||||
for entry in bundle.infolist():
|
||||
target = (isolated / entry.filename.replace('\\', '/')).resolve()
|
||||
assert target.is_relative_to(isolated)
|
||||
bundle.extractall(isolated)
|
||||
extraction_root = str(isolated / root.name)
|
||||
records.append({'kind': kind, 'path': str(archive), 'files': len(expected), 'crcPassed': True,
|
||||
'manifestAndDirectoryMatch': True, 'sha256': release[kind]['sha256']})
|
||||
|
||||
result = {'success': True, 'version': version, 'testedAt': datetime.now(timezone.utc).isoformat(),
|
||||
'archives': records, 'extractionRoot': extraction_root}
|
||||
(workspace / '.qa').mkdir(exist_ok=True)
|
||||
(workspace / '.qa/archives-validation.json').write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
print(json.dumps(result, ensure_ascii=True))
|
||||
@@ -0,0 +1,212 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
import { spawn, execFileSync } from 'node:child_process';
|
||||
import { chromium, expect } from 'playwright/test';
|
||||
import { Store } from '../src/server/store.mjs';
|
||||
import { GitDelivery } from '../src/core/git-delivery.mjs';
|
||||
import { gitEnvironment } from '../src/core/git-process.mjs';
|
||||
import { checkedDelivery } from '../tests/fixtures/delivery-project.mjs';
|
||||
|
||||
// Owns an independent host and synthetic projects. It never connects to 4318.
|
||||
const workspace = process.cwd(), root = path.resolve('.qa', 'delivery-ui-' + randomUUID()), data = path.join(root, 'data');
|
||||
const projectRoot = path.join(root, '四模块交付工程'), recoveryRoot = path.join(root, '提交恢复工程');
|
||||
const allowed = ['src/normalize.mjs', 'src/summary.mjs', 'src/render.mjs', 'src/cli.mjs'];
|
||||
const bytesHash = value => createHash('sha256').update(value).digest('hex');
|
||||
fs.mkdirSync(root, { recursive: true }); fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
fs.cpSync(path.join(workspace, 'benchmarks/node-delivery-v1/baseline'), projectRoot, { recursive: true });
|
||||
fs.writeFileSync(path.join(projectRoot, '.gitignore'), 'dist/\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'OWNER-NOTES.md'), 'Owner baseline notes\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'OWNER-STAGED.txt'), 'Owner baseline staged file\n');
|
||||
const git = args => execFileSync('git', ['--no-pager', '--no-optional-locks', '-C', projectRoot, ...args], { env: gitEnvironment(), encoding: 'utf8', windowsHide: true });
|
||||
const list = directory => fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => entry.isDirectory() ? list(path.join(directory, entry.name)) : [path.relative(projectRoot, path.join(directory, entry.name)).replaceAll('\\', '/')]);
|
||||
const baselineFiles = list(projectRoot);
|
||||
git(['init', '--initial-branch=main']); git(['config', 'core.autocrlf', 'false']); git(['config', 'user.name', 'Workbench UI QA']); git(['config', 'user.email', 'ui@workbench.invalid']);
|
||||
git(['add', '--', ...baselineFiles]); git(['commit', '--no-gpg-sign', '-m', 'Sealed four-module UI input']);
|
||||
const baselineHead = git(['rev-parse', 'HEAD']).trim();
|
||||
fs.appendFileSync(path.join(projectRoot, 'OWNER-NOTES.md'), 'Keep owner unstaged notes\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'OWNER-STAGED.txt'), 'Keep owner staged content\n'); git(['add', '--', 'OWNER-STAGED.txt']);
|
||||
fs.appendFileSync(path.join(projectRoot, 'OWNER-STAGED.txt'), 'Keep later owner working copy\n');
|
||||
fs.writeFileSync(path.join(projectRoot, 'OWNER-UNTRACKED.txt'), 'Keep owner untracked file\n');
|
||||
const protectedFiles = [...baselineFiles.filter(relative => !allowed.includes(relative)), 'OWNER-UNTRACKED.txt'];
|
||||
const protectedHashes = Object.fromEntries(protectedFiles.map(relative => [relative, bytesHash(fs.readFileSync(path.join(projectRoot, relative)))]));
|
||||
const initialHashes = Object.fromEntries(allowed.map(relative => [relative, bytesHash(fs.readFileSync(path.join(projectRoot, relative)))]));
|
||||
const repairs = Object.fromEntries(allowed.map(relative => [relative, fs.readFileSync(path.join(workspace, 'examples/delivery-report', relative), 'utf8')]));
|
||||
const store = new Store(data), primary = store.addProject(projectRoot);
|
||||
fs.mkdirSync(recoveryRoot);
|
||||
fs.writeFileSync(path.join(recoveryRoot, 'README.md'), '# Recovery UI fixture\n');
|
||||
const recoveryProject = store.addProject(recoveryRoot), recoverySession = store.createSession(recoveryProject.id), seedCleanup = [];
|
||||
const f = { root, projectRoot: recoveryRoot, data, store, project: recoveryProject, session: recoverySession, onCleanup: fn => seedCleanup.push(fn) };
|
||||
await checkedDelivery(f);
|
||||
recoverySession.title = 'Git中断核对样本'; store.save(recoverySession);
|
||||
const recoveryAdapter = new GitDelivery(store, { faultInjector: phase => { if (phase === 'committed') throw new Error('Controlled lost acknowledgement after actual publication'); } });
|
||||
const recoveryPlan = await recoveryAdapter.plan(recoverySession);
|
||||
for (const cleanup of seedCleanup) await cleanup(); store.close();
|
||||
const exited = spawn(process.execPath, [path.join(workspace, 'tests/fixtures/delivery-crash-worker.mjs'), data, recoverySession.id, recoveryPlan.id, 'committed'],
|
||||
{ windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let exitOutput = '', exitErrors = '';
|
||||
exited.stdout.on('data', bytes => { exitOutput += bytes.toString('utf8'); }); exited.stderr.on('data', bytes => { exitErrors += bytes.toString('utf8'); });
|
||||
assert.equal(await new Promise(resolve => exited.once('close', resolve)), 73, exitErrors);
|
||||
const crashed = JSON.parse(exitOutput.trim()), recoveredStore = new Store(data), recoveryJob = structuredClone(recoveredStore.owned('delivery_job', crashed.jobId, recoverySession.id));
|
||||
assert.equal(recoveryJob.status, 'unknown'); recoveredStore.close();
|
||||
|
||||
let modelMode = 'initial';
|
||||
const model = http.createServer(async (request, response) => {
|
||||
try {
|
||||
const chunks = []; for await (const chunk of request) chunks.push(chunk);
|
||||
const input = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
||||
const last = input.messages.findLastIndex(item => item.role === 'user');
|
||||
const results = input.messages.slice(last + 1).filter(item => item.role === 'tool').map(item => JSON.parse(item.content));
|
||||
const plan = results.find(value => value.checks && value.fingerprint);
|
||||
let calls = [];
|
||||
if (!results.length) calls = [['inspect_project', {}]];
|
||||
else if (results.length === 1) calls = [['plan_checks', {}]];
|
||||
else if (results.length === 2) calls = [['run_checks', { plan_id: plan.id }]];
|
||||
else if (results.length === 3 && modelMode === 'initial') calls = allowed.map(relative => ['propose_file', { path: relative, content: repairs[relative], base_sha256: initialHashes[relative], reason: 'Controlled four-module repair after actual failure logs' }]);
|
||||
else if (results.length === 3 && modelMode === 'final') calls = [['plan_delivery', { message: 'feat: prepare verified four-module delivery' }]];
|
||||
else if (results.length === 4 && modelMode === 'final') calls = [['delivery_report', {}]];
|
||||
response.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
response.end(JSON.stringify({ choices: [{ message: { role: 'assistant', content: calls.length ? '' : modelMode === 'initial' ? '四个文件已准备提案,等待审查。' : '实际14项测试和构建通过,Git预览已准备,等待确认。',
|
||||
...(calls.length ? { tool_calls: calls.map(([name, args]) => ({ id: randomUUID(), type: 'function', function: { name, arguments: JSON.stringify(args) } })) } : {}) },
|
||||
finish_reason: calls.length ? 'tool_calls' : 'stop' }], usage: { prompt_tokens: 40, completion_tokens: 20, total_tokens: 60 } }));
|
||||
} catch (error) { response.writeHead(500, { 'Content-Type': 'application/json' }); response.end(JSON.stringify({ error: { message: error.message } })); }
|
||||
});
|
||||
await new Promise(resolve => model.listen(0, '127.0.0.1', resolve));
|
||||
const env = { ...process.env, AGENT_WORKBENCH_APP_DIR: workspace, AGENT_WORKBENCH_DATA_DIR: data, AGENT_WORKBENCH_PORT: '0' }; delete env.AGENT_WORKBENCH_API_KEY;
|
||||
const host = spawn(process.execPath, ['dist-server/server.mjs'], { cwd: workspace, env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let url = '', hostOutput = '', hostErrors = '';
|
||||
host.stdout.on('data', bytes => { hostOutput += bytes.toString('utf8'); for (const line of hostOutput.split('\n')) { try { const value = JSON.parse(line); if (value.ready) url = value.url; } catch {} } });
|
||||
host.stderr.on('data', bytes => { hostErrors += bytes.toString('utf8'); });
|
||||
const until = async predicate => { const deadline = Date.now() + 20000; while (!(await predicate())) { if (Date.now() > deadline) throw new Error('QA host state timeout: ' + hostErrors); await new Promise(resolve => setTimeout(resolve, 20)); } };
|
||||
await until(() => url || host.exitCode !== null); assert.ok(url, hostErrors); assert.notEqual(new URL(url).port, '4318');
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
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, Connection: 'close' }, ...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const result = await response.json(); assert.ok(response.ok, result.error); return result;
|
||||
};
|
||||
await api('/config', { ...bootstrap.config, mode: 'compatible', model: 'delivery-ui-controlled-fixture', baseUrl: 'http://127.0.0.1:' + model.address().port + '/v1', apiKey: 'delivery-ui-volatile-fixture-key' });
|
||||
const browser = await chromium.launch({ executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', headless: true });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
|
||||
const page = await context.newPage(), passed = [], pageErrors = [], requestFailures = [], confirmations = [];
|
||||
page.on('pageerror', error => pageErrors.push(error.message));
|
||||
page.on('requestfailed', request => requestFailures.push(request.url() + ': ' + request.failure()?.errorText));
|
||||
page.on('request', request => { if (request.method() === 'POST' && /\/delivery-jobs$/.test(new URL(request.url()).pathname)) confirmations.push(request.postDataJSON().planId); });
|
||||
const mark = text => { passed.push(text); console.log('PASS ' + text); };
|
||||
const screenshot = name => page.screenshot({ path: '.qa/screenshots/' + name + '.png', scale: 'css' });
|
||||
const task = () => page.getByLabel('任务记录', { exact: true });
|
||||
const delivery = () => task().getByLabel('Git交付', { exact: true });
|
||||
const confirm = () => page.getByRole('dialog', { name: '确认本地Git提交', exact: true });
|
||||
const artifact = () => page.getByRole('dialog', { name: '执行结果工件', exact: true });
|
||||
let sessionId = '';
|
||||
const state = () => api('/sessions/' + sessionId);
|
||||
const waitStatus = status => expect.poll(async () => (await state()).status, { timeout: 30000 }).toBe(status);
|
||||
try {
|
||||
await page.goto(url); await page.waitForLoadState('networkidle');
|
||||
await page.getByLabel('当前项目').selectOption(primary.id);
|
||||
await page.getByRole('button', { name: '新建任务', exact: true }).click();
|
||||
await page.getByLabel('任务内容').fill('修复四模块并交付Git报告'); await page.getByRole('button', { name: '发送任务' }).click();
|
||||
await expect.poll(async () => (await api('/sessions')).find(value => value.title === '修复四模块并交付Git报告')?.id).toBeTruthy();
|
||||
sessionId = (await api('/sessions')).find(value => value.title === '修复四模块并交付Git报告').id;
|
||||
await waitStatus('awaiting_approval'); await page.getByRole('button', { name: '确认执行', exact: true }).click(); await waitStatus('needs_review');
|
||||
const reviewed = await state(); assert.equal(reviewed.execution.checks[0].results[0].tests.failed, 13);
|
||||
await page.getByRole('button', { name: '查看任务记录' }).click(); await expect(task()).toContainText('13');
|
||||
assert.equal(git(['rev-parse', 'HEAD']).trim(), baselineHead);
|
||||
mark('actual failing tests and four source proposals retain the original project and task');
|
||||
await page.locator('.inspector-tabs').getByRole('button', { name: /改动/ }).click();
|
||||
for (const relative of allowed) {
|
||||
await page.locator('.change-list').getByRole('button').filter({ hasText: relative }).click();
|
||||
await page.getByRole('button', { name: '应用这项改动', exact: true }).click();
|
||||
}
|
||||
await waitStatus('completed'); modelMode = 'final'; await page.getByRole('button', { name: '继续检查与交付', exact: true }).click();
|
||||
await waitStatus('awaiting_approval'); await page.getByRole('button', { name: '确认执行', exact: true }).click(); await waitStatus('completed');
|
||||
const verified = await state(); assert.equal(verified.execution.task.id, reviewed.execution.task.id); assert.equal(verified.execution.checks.at(-1).status, 'passed');
|
||||
assert.equal(verified.execution.checks.at(-1).results[0].tests.passed, 14); assert.equal(verified.execution.deliveries.length, 0);
|
||||
assert.equal(verified.execution.deliveryPlans.at(-1).preparedBy, 'agent');
|
||||
await page.getByRole('button', { name: '查看任务记录' }).click(); await expect(task()).toContainText('测试 14/14 通过');
|
||||
await page.locator('.session-select').filter({ hasText: '修复四模块并交付Git报告' }).click();
|
||||
await expect(task()).toContainText('测试 14/14 通过');
|
||||
mark('reviewed changes continue the same Task through 14 real tests and model-prepared Git review');
|
||||
|
||||
await delivery().getByLabel('提交说明', { exact: true }).fill('feat: ship the reviewed four-module delivery');
|
||||
await delivery().getByText('Git署名', { exact: true }).click(); await delivery().getByLabel('提交者姓名').fill('UI Reviewer'); await delivery().getByLabel('提交者邮箱').fill('reviewer@workbench.invalid');
|
||||
await delivery().getByRole('button', { name: '预览Git提交', exact: true }).click(); await expect(confirm()).toBeVisible();
|
||||
await expect(confirm()).toContainText('UI Reviewer'); await expect(confirm()).toContainText('14/14'); await expect(confirm()).toContainText(baselineHead.slice(0, 12)); await expect(confirm()).toContainText('不执行仓库hooks');
|
||||
for (const relative of allowed) { await confirm().locator('summary').filter({ hasText: relative }).click(); await expect(confirm().getByLabel('提交差异 ' + relative, { exact: true })).toBeVisible(); }
|
||||
await confirm().locator('.delivery-confirm').evaluate(element => { element.scrollTop = 0; });
|
||||
await screenshot('delivery-desktop-review');
|
||||
await page.keyboard.press('Escape'); await expect(confirm()).not.toBeVisible(); assert.equal(git(['rev-parse', 'HEAD']).trim(), baselineHead);
|
||||
mark('review shows actual paths, diffs, tests, author and policy; cancelling leaves Git unchanged');
|
||||
|
||||
await delivery().getByRole('button', { name: '预览Git提交', exact: true }).click(); await expect(confirm()).toBeVisible();
|
||||
git(['add', '--', 'OWNER-NOTES.md']); const protectedStage = git(['show', ':OWNER-STAGED.txt']), stagedNotes = git(['show', ':OWNER-NOTES.md']);
|
||||
await confirm().getByRole('button', { name: '确认创建本地提交', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.deliveries.at(-1)?.status, { timeout: 20000 }).toBe('stale');
|
||||
await expect(delivery()).toContainText('提交预览后'); assert.equal(git(['rev-parse', 'HEAD']).trim(), baselineHead);
|
||||
assert.equal(git(['show', ':OWNER-STAGED.txt']), protectedStage); assert.equal(git(['show', ':OWNER-NOTES.md']), stagedNotes);
|
||||
mark('an index change after confirmation preview refuses the stale job and preserves both staged owners');
|
||||
|
||||
await delivery().getByRole('button', { name: '预览Git提交', exact: true }).click(); await expect(confirm()).toBeVisible();
|
||||
await page.setViewportSize({ width: 390, height: 844 }); await expect(confirm()).toBeVisible();
|
||||
await confirm().locator('summary').filter({ hasText: 'src/normalize.mjs' }).click();
|
||||
await screenshot('delivery-mobile-review');
|
||||
const box = await confirm().boundingBox(), confirmButton = await confirm().getByRole('button', { name: '确认创建本地提交', exact: true }).boundingBox();
|
||||
assert.ok(box.x >= 0 && box.x + box.width <= 391 && box.y >= 0 && box.y + box.height <= 845);
|
||||
assert.ok(confirmButton.x >= 0 && confirmButton.x + confirmButton.width <= 391);
|
||||
assert.ok(await confirm().evaluate(element => element.scrollWidth <= element.clientWidth + 1));
|
||||
mark('390px confirmation keeps file hashes, diffs and actions inside the modal');
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await confirm().getByRole('button', { name: '确认创建本地提交', exact: true }).dblclick();
|
||||
await expect.poll(async () => (await state()).execution.deliveries.at(-1)?.status, { timeout: 25000 }).toBe('completed');
|
||||
const delivered = await state(), job = delivered.execution.deliveries.at(-1);
|
||||
assert.equal(confirmations.filter(value => value === job.planId).length, 1);
|
||||
assert.equal(job.workspacePreserved, true); assert.equal(job.indexPreserved, true); assert.equal(git(['rev-list', '--count', 'HEAD']).trim(), '2');
|
||||
assert.equal(git(['show', ':OWNER-STAGED.txt']), protectedStage); assert.equal(git(['show', ':OWNER-NOTES.md']), stagedNotes);
|
||||
for (const [relative, expected] of Object.entries(protectedHashes)) assert.equal(bytesHash(fs.readFileSync(path.join(projectRoot, relative))), expected);
|
||||
assert.deepEqual(git(['diff-tree', '--no-commit-id', '--name-only', '-r', 'HEAD']).trim().split('\n').sort(), allowed.slice().sort());
|
||||
await expect(delivery()).toContainText(job.commit); await expect(delivery()).toContainText('实际提交已核对'); await screenshot('delivery-desktop-result');
|
||||
mark('double confirmation creates one four-file commit, retains owner bytes and publishes report with completion');
|
||||
|
||||
const jobCard = delivery().locator('.delivery-job').filter({ hasText: job.commit });
|
||||
await jobCard.getByRole('button', { name: '查看交付报告', exact: true }).click(); await expect(artifact()).toContainText('检查通过并已提交'); await expect(artifact()).toContainText('14/14');
|
||||
await screenshot('delivery-desktop-report'); await artifact().getByRole('button', { name: '关闭窗口' }).click();
|
||||
for (const [label, id, extension] of [['下载Markdown', job.reportMarkdownArtifactId, '.md'], ['下载JSON', job.reportArtifactId, '.json']]) {
|
||||
const event = page.waitForEvent('download'); await jobCard.getByRole('button', { name: label, exact: true }).click(); const download = await event;
|
||||
const target = path.join(root, 'download' + extension); await download.saveAs(target);
|
||||
const meta = await api('/artifacts/' + id + '?session=' + sessionId); assert.equal(bytesHash(fs.readFileSync(target)), meta.sha256);
|
||||
if (extension === '.json') assert.equal(JSON.parse(fs.readFileSync(target, 'utf8')).status, 'verified_committed');
|
||||
}
|
||||
mark('report viewing and Markdown/JSON downloads preserve verified artifact bytes and truthful acceptance limits');
|
||||
|
||||
await page.setViewportSize({ width: 390, height: 844 }); await page.getByRole('button', { name: '查看任务记录' }).click();
|
||||
await delivery().getByRole('button', { name: '查看最新报告', exact: true }).click(); await expect(artifact()).toBeVisible(); await screenshot('delivery-mobile-report');
|
||||
await artifact().getByRole('button', { name: '关闭窗口' }).click(); await page.getByRole('button', { name: '关闭检视区' }).click();
|
||||
const composer = await page.getByLabel('任务内容').boundingBox(); assert.ok(composer.y >= 0 && composer.y + composer.height <= 844);
|
||||
assert.ok(await page.locator('body').evaluate(element => element.scrollWidth <= 390)); mark('mobile report preview closes cleanly and keeps the task input fixed');
|
||||
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
if (!await page.getByLabel('当前项目').isVisible()) await page.getByRole('button', { name: '展开项目栏' }).click();
|
||||
await page.getByLabel('当前项目').selectOption(recoveryProject.id); await page.locator('.session-select').filter({ hasText: 'Git中断核对样本' }).click();
|
||||
await page.getByRole('button', { name: '查看任务记录' }).click(); await expect(delivery()).toContainText('结果待核对');
|
||||
await expect(delivery().getByRole('button', { name: '预览Git提交', exact: true })).toBeDisabled(); await screenshot('delivery-unknown-result');
|
||||
await delivery().getByRole('button', { name: '核对提交结果', exact: true }).click();
|
||||
await expect.poll(async () => (await api('/sessions/' + recoverySession.id)).execution.deliveries[0].status, { timeout: 15000 }).toBe('completed');
|
||||
const recovered = await api('/sessions/' + recoverySession.id);
|
||||
assert.equal(recovered.execution.deliveries[0].commit, recoveryJob.expectedCommit); assert.equal(fs.existsSync(path.join(recoveryRoot, '.git/index.lock')), false);
|
||||
await expect(delivery()).toContainText('没有重新执行提交'); await screenshot('delivery-reconciled-result');
|
||||
mark('unknown Git results block new submission and the explicit reconcile action restores the existing commit');
|
||||
|
||||
assert.deepEqual(pageErrors, []); assert.deepEqual(requestFailures, []);
|
||||
const result = { success: true, version: bootstrap.version, testedAt: new Date().toISOString(), browser: browser.version(), passed, pageErrors, requestFailures,
|
||||
projectRoot, projectId: primary.id, sessionId, taskId: reviewed.execution.task.id, commit: job.commit, recoveryCommit: recoveryJob.expectedCommit,
|
||||
testCounts: { baselineFailed: 13, passed: 14 }, model: 'controlled local HTTP fixture', confirmations: confirmations.length };
|
||||
fs.writeFileSync('.qa/delivery-ui-validation.json', JSON.stringify(result, null, 2)); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
await screenshot('delivery-ui-failure').catch(() => {}); fs.writeFileSync('.qa/delivery-ui-failure-dom.html', await page.content().catch(() => ''));
|
||||
fs.writeFileSync('.qa/delivery-ui-validation.json', JSON.stringify({ success: false, error: error.message, passed, pageErrors, requestFailures, root, url }, null, 2));
|
||||
throw error;
|
||||
} finally {
|
||||
await browser.close(); await api('/shutdown', {}).catch(() => {}); await until(() => host.exitCode !== null).catch(() => host.kill());
|
||||
model.closeAllConnections(); await new Promise(resolve => model.close(resolve));
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
import { execFileSync, spawnSync } from 'node:child_process';
|
||||
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.
|
||||
@@ -11,7 +12,7 @@ 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();
|
||||
assert.equal(bootstrap.version, '1.1.0'); assert.equal(bootstrap.config.mode, 'compatible');
|
||||
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',
|
||||
@@ -30,19 +31,24 @@ fs.mkdirSync(caseRoot, { recursive: true });
|
||||
fs.cpSync(path.join(workspace, 'benchmarks/node-delivery-v1/baseline'), projectRoot, { recursive: true });
|
||||
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']);
|
||||
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');
|
||||
fs.appendFileSync(path.join(projectRoot, 'OWNER-STAGED.txt'), 'Existing staged owner edit: ' + randomUUID() + '\n');
|
||||
git(['add', '--', 'OWNER-STAGED.txt']);
|
||||
const sha = file => createHash('sha256').update(fs.readFileSync(path.join(projectRoot, file))).digest('hex');
|
||||
const protectedPaths = ['README.md', 'package.json', 'test/delivery.test.mjs', 'scripts/build.mjs', 'fixtures/tasks.json', 'fixtures/invalid.json', '.gitignore', 'OWNER-NOTES.md', 'UNTRACKED-OWNER.txt'];
|
||||
const protectedPaths = ['README.md', 'package.json', 'test/delivery.test.mjs', 'scripts/build.mjs', 'fixtures/tasks.json', 'fixtures/invalid.json', '.gitignore', 'OWNER-NOTES.md', 'OWNER-STAGED.txt', 'UNTRACKED-OWNER.txt'];
|
||||
const protectedHashes = Object.fromEntries(protectedPaths.map(file => [file, sha(file)]));
|
||||
const beforeSources = Object.fromEntries(allowed.map(file => [file, sha(file)]));
|
||||
const ownerDiff = git(['diff', '--', 'OWNER-NOTES.md']);
|
||||
const ownerStagedDiff = git(['diff', '--cached', '--', 'OWNER-STAGED.txt']);
|
||||
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.');
|
||||
};
|
||||
const project = await api('/projects', { root: projectRoot });
|
||||
const session = await api('/sessions', { projectId: project.id });
|
||||
@@ -60,7 +66,7 @@ try {
|
||||
'依据实际失败读取有关文件,使用 read_artifact 进一步核对失败日志。只能用 propose_file 修改 src/normalize.mjs、src/summary.mjs、src/render.mjs、src/cli.mjs;' +
|
||||
'测试、fixtures、构建脚本、package.json、README 和 OWNER 文件必须保留。四模块都需修复,不能修改验收来通过。' +
|
||||
'本工程没有第三方依赖,不用安装。不要使用 run_command、不要自己提交Git;本轮终端仅通过已识别的npm检查计划运行。' +
|
||||
'提案等待审查应用,随后继续同一目标并实际重新运行 test/build,依据日志修复直至通过;最后用中文报告实际测试数量、构建结果和改动。' });
|
||||
'提案等待审查应用,随后继续同一目标并实际重新运行 test/build,依据日志修复直至通过。检查通过后用 plan_delivery 准备本Task的四文件本地Git预览,等待用户独立确认;最后用中文报告实际测试数量、构建结果和改动。' });
|
||||
while (Date.now() - started < 720000) {
|
||||
state = await api('/sessions/' + session.id); originalTaskId ??= state.execution.task.id;
|
||||
assert.equal(state.execution.task.id, originalTaskId, 'Engineering delivery must retain the original Task.');
|
||||
@@ -118,8 +124,38 @@ try {
|
||||
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 });
|
||||
const diff = git(['diff', '--', ...allowed]); assert.ok(diff.length > 0); fs.writeFileSync(path.join(caseRoot, 'reviewed-changes.diff'), diff);
|
||||
git(['add', '--', ...allowed]); git(['commit', '--only', '-m', 'feat: repair delivery report with 14 verified acceptance cases', '--', ...allowed]);
|
||||
const deliveredCommit = git(['rev-parse', 'HEAD']).trim(); assert.notEqual(deliveredCommit, baselineCommit); assertProtected();
|
||||
let deliveryPlan = state.execution.deliveryPlans?.filter(plan => plan.status === 'planned' && plan.taskId === originalTaskId && plan.runId === state.runId).at(-1);
|
||||
if (!deliveryPlan) {
|
||||
state = await api('/sessions/' + session.id + '/delivery-plans', { message: 'feat: repair delivery report with 14 verified acceptance cases' });
|
||||
deliveryPlan = state.execution.deliveryPlans.at(-1);
|
||||
}
|
||||
assert.deepEqual(deliveryPlan.paths.slice().sort(), allowed.slice().sort());
|
||||
assert.equal(deliveryPlan.checkJobId, passedJob.id); assert.equal(deliveryPlan.sourceFingerprint, passedJob.sourceFingerprint);
|
||||
assert.equal(git(['rev-parse', 'HEAD']).trim(), baselineCommit); assertProtected();
|
||||
const queued = await api('/sessions/' + session.id + '/delivery-jobs', { planId: deliveryPlan.id });
|
||||
const deliveryJobId = queued.execution.deliveries.at(-1).id;
|
||||
let deliveryJob;
|
||||
for (let attempt = 0; attempt < 120; attempt++) {
|
||||
deliveryJob = await api('/sessions/' + session.id + '/delivery-jobs/' + deliveryJobId);
|
||||
if (!['queued', 'preparing', 'prepared', 'publishing', 'committed', 'reporting'].includes(deliveryJob.status)) break;
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
}
|
||||
assert.equal(deliveryJob.status, 'completed', deliveryJob.summary); assert.ok(deliveryJob.reportArtifactId); assert.ok(deliveryJob.reportMarkdownArtifactId);
|
||||
const deliveredCommit = git(['rev-parse', 'HEAD']).trim(); assert.equal(deliveredCommit, deliveryJob.commit);
|
||||
assert.notEqual(deliveredCommit, baselineCommit); assertProtected();
|
||||
assert.equal(git(['rev-list', '--count', 'HEAD']).trim(), '2');
|
||||
const readArtifact = async id => {
|
||||
let offset = 0, content = '', artifact;
|
||||
do { artifact = await api('/artifacts/' + id + '?session=' + session.id + '&offset=' + offset + '&limit=16000'); content += artifact.content; offset += artifact.content.length; } while (artifact.truncated && artifact.content.length);
|
||||
assert.equal(createHash('sha256').update(content).digest('hex'), artifact.sha256);
|
||||
return content;
|
||||
};
|
||||
const deliveryJson = await readArtifact(deliveryJob.reportArtifactId), deliveryMarkdown = await readArtifact(deliveryJob.reportMarkdownArtifactId);
|
||||
const report = JSON.parse(deliveryJson); assert.equal(report.status, 'verified_committed'); assert.equal(report.task.id, originalTaskId);
|
||||
assert.equal(report.verifiedCheckJobId, passedJob.id); assert.equal(report.deliveries.at(-1).commit, deliveredCommit);
|
||||
assert.equal(report.task.requirementsAcceptance, 'not_recorded'); assert.match(deliveryMarkdown, /14\/14/);
|
||||
fs.writeFileSync(path.join(caseRoot, 'delivery-report.json'), deliveryJson); fs.writeFileSync(path.join(caseRoot, 'delivery-report.md'), deliveryMarkdown);
|
||||
state = await api('/sessions/' + session.id);
|
||||
assert.deepEqual(git(['diff-tree', '--no-commit-id', '--name-only', '-r', 'HEAD']).trim().split(/\r?\n/).sort(), [...allowed].sort());
|
||||
const exported = await api('/sessions/' + session.id + '/export');
|
||||
fs.writeFileSync(path.join(caseRoot, 'session.json'), JSON.stringify(exported, null, 2));
|
||||
@@ -130,12 +166,12 @@ try {
|
||||
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,
|
||||
projectRoot, projectId: project.id, sessionId: session.id, taskId: originalTaskId, baselineCommit, deliveredCommit,
|
||||
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, buildOutput: JSON.parse(built.stdout), usage: state.execution.task.usage,
|
||||
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,
|
||||
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, checked four source proposals and applied them; implementation came from the configured model. The verifier saved a source-only local Git commit.',
|
||||
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.' };
|
||||
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));
|
||||
|
||||
@@ -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'].includes(bootstrap.version));
|
||||
assert.ok(['1.0.0', '1.1.0', '1.2.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) => {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
|
||||
const workspace = process.cwd();
|
||||
const evidence = JSON.parse(fs.readFileSync('.qa/archives-validation.json', 'utf8'));
|
||||
assert.equal(evidence.success, true);
|
||||
assert.ok(evidence.extractionRoot, 'Run python scripts/verify-archives.py --extract-source first.');
|
||||
const sourceRoot = fs.realpathSync.native(evidence.extractionRoot);
|
||||
assert.ok(sourceRoot.startsWith(path.resolve('.qa') + path.sep));
|
||||
const npmCli = path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js');
|
||||
assert.ok(fs.existsSync(npmCli), 'Use Node with its bundled npm.');
|
||||
const files = (root, relative = '') => fs.readdirSync(path.join(root, relative), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))
|
||||
.flatMap(entry => entry.isDirectory() ? files(root, path.join(relative, entry.name)) : [path.join(relative, entry.name)]);
|
||||
const digest = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
||||
const expected = Object.fromEntries(['dist-client', 'dist-server'].flatMap(folder => files(path.join(workspace, folder)).map(relative => [path.join(folder, relative), digest(path.join(workspace, folder, relative))])));
|
||||
const allowedEnv = /^(path|pathext|systemroot|systemdrive|windir|comspec|temp|tmp|userprofile|homedrive|homepath|home|appdata|localappdata|programfiles(?:\(x86\))?|commonprogramfiles(?:\(x86\))?|lang|lc_all)$/i;
|
||||
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => allowedEnv.test(key)));
|
||||
let stage = 'install';
|
||||
const resultFile = path.join(workspace, '.qa/source-package-validation.json');
|
||||
|
||||
function run(args, logName) {
|
||||
console.log('Source package: ' + stage);
|
||||
return new Promise((resolve, reject) => {
|
||||
const outputFile = fs.createWriteStream(path.join(sourceRoot, logName));
|
||||
const child = spawn(process.execPath, args, { cwd: sourceRoot, env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let tail = '';
|
||||
const capture = bytes => { outputFile.write(bytes); tail = (tail + bytes.toString('utf8')).slice(-12000); };
|
||||
child.stdout.on('data', capture); child.stderr.on('data', capture);
|
||||
const timer = setTimeout(() => child.kill(), 600000);
|
||||
child.once('error', error => { clearTimeout(timer); outputFile.end(); reject(error); });
|
||||
child.once('close', code => { clearTimeout(timer); outputFile.end(); code === 0 ? resolve(tail) : reject(new Error(stage + ' failed (' + code + '): ' + tail)); });
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await run([npmCli, 'ci', '--offline', '--no-audit', '--no-fund'], 'install.log');
|
||||
stage = 'build'; await run([npmCli, 'run', 'build'], 'build.log');
|
||||
const actualFiles = ['dist-client', 'dist-server'].flatMap(folder => files(path.join(sourceRoot, folder)).map(relative => path.join(folder, relative)));
|
||||
assert.deepEqual(actualFiles.slice().sort(), Object.keys(expected).sort());
|
||||
for (const [relative, sha256] of Object.entries(expected)) assert.equal(digest(path.join(sourceRoot, relative)), sha256, relative);
|
||||
stage = 'tests';
|
||||
const output = await run(['--test', '--test-concurrency=2', '--test-reporter=tap', ...files(path.join(sourceRoot, 'tests')).filter(file => !file.includes(path.sep) && file.endsWith('.test.mjs')).map(file => path.join('tests', file))], 'tests.tap');
|
||||
const stats = Object.fromEntries([...output.matchAll(/^# (tests|pass|fail|cancelled|skipped|todo) (\d+)\s*$/gm)].map(match => [match[1], Number(match[2])]));
|
||||
assert.ok(stats.tests > 0); assert.equal(stats.pass, stats.tests); for (const key of ['fail', 'cancelled', 'skipped', 'todo']) assert.equal(stats[key], 0);
|
||||
const result = { success: true, version: evidence.version, testedAt: new Date().toISOString(), sourceRoot, offlineInstall: true,
|
||||
buildMatchedFiles: Object.keys(expected).length, tests: stats, credentialsHandling: 'Only build/runtime environment paths are inherited; no model configuration or credentials are used.' };
|
||||
fs.writeFileSync(resultFile, JSON.stringify(result, null, 2)); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
fs.writeFileSync(resultFile, JSON.stringify({ success: false, version: evidence.version, stage, error: error.message, sourceRoot }, null, 2));
|
||||
throw error;
|
||||
}
|
||||
Reference in New Issue
Block a user