fix: distinguish read-only evidence from file delivery requirements

This commit is contained in:
Agent Workbench Dev
2026-11-01 14:35:41 +08:00
parent ce18608582
commit 29c0e755b4
5 changed files with 50 additions and 7 deletions
+16 -4
View File
@@ -47,7 +47,9 @@ test('an isolated three-module Python Task repairs, checks and delivers a source
const latestResults = feedback ?? results, latest = latestResults.at(-1);
// Follow actual returned states: archived older groups change the number of
// visible tool messages and must not make this fixture repeat a call ID.
if (!latest) return completion([call('python-plan-' + mode, 'plan_checks', { names: ['python:test', 'python:compile'] })]);
// Review is now a system action, so the original user turn and completed
// tools remain visible. The applied batch starts a fresh check plan.
if (!latest || mode === 'delivery' && latest.change_set_id) return completion([call('python-plan-' + mode, 'plan_checks', { names: ['python:test', 'python:compile'] })]);
if (latest.id && Array.isArray(latest.checks)) return completion([call('python-check-' + mode, 'run_checks', { plan_id: latest.id })]);
if (latest.check_status === 'failed' && mode === 'repair') return completion(Object.entries(pythonFixes).map(([relative, content], index) => call('python-fix-' + index, 'propose_file', { path: relative, content, reason: 'Repair the actual sealed Python failure' })));
if (latest.change_id && mode === 'repair') return completion([call('python-batch', 'prepare_change_set', { change_ids: latestResults.filter(value => value.change_id).map(value => value.change_id) })]);
@@ -63,9 +65,17 @@ test('an isolated three-module Python Task repairs, checks and delivers a source
const opened = await host.api(parent + '/workspaces/' + workspace.id + '/open', {}), route = '/sessions/' + opened.session.id;
await host.api(route + '/messages', { content: 'Repair only the three Python workflow modules, preserve tests and declarations, execute Python tests and compilation and prepare a reviewed Git delivery.' });
let session;
const wait = async predicate => {
const wait = async (predicate, { allowAppliedPause = false } = {}) => {
try {
await until(async () => { session = await host.api(route); if (['failed', 'paused'].includes(session.status)) throw new Error('Unexpected Python Task state: ' + session.status + '/' + session.execution.run.stopReason); return predicate(session); }, 30000);
await until(async () => {
session = await host.api(route);
const appliedPause = allowAppliedPause && session.status === 'paused'
&& session.execution.changeSets.at(-1)?.status === 'completed'
&& session.execution.task.delivery?.status === 'files_applied'
&& session.execution.task.verification?.status === 'failed';
if (session.status === 'failed' || session.status === 'paused' && !appliedPause) throw new Error('Unexpected Python Task state: ' + session.status + '/' + session.execution.run.stopReason);
return predicate(session);
}, 30000);
} catch (error) {
fs.writeFileSync(path.resolve('.qa', 'python-api-state-failure.json'), JSON.stringify({ error: error.message, session,
requests: model.requests.map(request => request.input) }, null, 2) + '\n');
@@ -79,7 +89,9 @@ test('an isolated three-module Python Task repairs, checks and delivers a source
assert.equal(session.execution.checks[0].results[0].tests.failed, 5);
const taskId = session.execution.task.id, batch = session.execution.changeSets.at(-1);
await host.api(route + '/change-sets/' + batch.id + '/apply', { fingerprint: batch.fingerprint });
await wait(value => value.execution.changeSets.at(-1).status === 'completed');
await wait(value => value.execution.changeSets.at(-1).status === 'completed', { allowAppliedPause: true });
assert.equal(session.status, 'paused'); assert.equal(session.execution.task.verification.status, 'failed');
assert.equal(session.execution.task.delivery.status, 'files_applied');
mode = 'delivery'; await host.api(route + '/continue-reviewed', {});
await wait(value => value.status === 'awaiting_approval');
await host.api(route + '/approvals/' + session.approvals.at(-1).id, { allow: true });
+7 -1
View File
@@ -186,7 +186,10 @@ test('HTTP failure and explicit same-Task resume reuse exact completed results a
const record = [...f.store.core.context_plan.values()].at(-1); assert.equal(record.requestSha256, requestMetrics(input).sha256);
assert.ok(['prepared', 'requesting'].includes(record.status)); assertToolPairs(input.messages);
if (requests.length === 1) return completion([call('only-effect', 'run_command', { command: 'node -e "const fs=require(\'node:fs\'); const file=\'request-effects.txt\'; fs.writeFileSync(file,String(Number(fs.existsSync(file)?fs.readFileSync(file,\'utf8\'):0)+1));"', reason: 'Record one controlled fixture effect.' })]);
if (requests.length < 6) return completion([call('read-round-' + requests.length, 'read_file', { path: 'README.md' })]);
if (requests.length < 6) {
const start = (requests.length - 2) * 100 + 1;
return completion([call('read-round-' + requests.length, 'read_file', { path: 'README.md', start_line: start, end_line: start + 99 })]);
}
if (!failed) { failed = true; return { status: 503, body: { error: { message: 'controlled request failure' } } }; }
assert.ok(input.messages[0].content.includes('Do not replay the completed command.'));
return completion([], 'Original task completed from saved evidence.');
@@ -196,6 +199,9 @@ test('HTTP failure and explicit same-Task resume reuse exact completed results a
runtime.start(f.session.id, 'Read evidence. Do not replay the completed command.');
await until(() => f.session.approvals.some(value => value.status === 'pending')); runtime.decide(f.session.id, f.session.approvals.at(-1).id, true);
await runtime.active.get(f.session.id).promise; assert.equal(f.session.status, 'failed');
assert.equal(model.requests.length, 6); assert.equal(failed, true);
const pages = f.session.events.filter(event => event.tool === 'read_file');
assert.deepEqual(pages.map(event => [event.input.start_line, event.input.end_line]), [[1, 100], [101, 200], [201, 300], [301, 400]]);
const original = structuredClone(f.session.providerMessages), taskId = f.session.taskId, firstRun = f.session.runId;
assert.ok([...f.store.core.context_plan.values()].some(plan => plan.archivedGroups > 0));
assert.equal([...f.store.core.context_plan.values()].at(-1).status, 'failed');
+14 -1
View File
@@ -5,7 +5,7 @@ import path from 'node:path';
import { Runtime } from '../src/server/runtime.mjs';
import { Provider } from '../src/server/provider.mjs';
import { applyChange } from '../src/server/files.mjs';
import { isDiagnosticQuestion } from '../src/shared/contracts/task-control.mjs';
import { isDiagnosticQuestion, taskContract } from '../src/shared/contracts/task-control.mjs';
import { fixture, call, assertToolPairs } from './helpers.mjs';
const answer = content => ({ message: { role: 'assistant', content }, usage: { prompt_tokens: 11, completion_tokens: 3 } });
@@ -15,6 +15,19 @@ test('operational questions are diagnostic while explicit repair requests remain
for (const text of ['先修复系统', '为什么失败,请帮我修复', '这个错误怎么回事,然后修一下', 'fix this error', '继续完成']) assert.equal(isDiagnosticQuestion(text), false, text);
});
test('file delivery requires a positive instruction, not saved evidence or a prohibited write', () => {
for (const goal of ['读取保存的原工件,分段取得真实依据,不执行命令或修改文件。',
'读取保存过的 HTML 文件并解释内容', '不要创建文件,只分析结果', '读取工件,不执行命令或创建文件',
'Do not create a file; explain the evidence.', 'Read the saved file without creating HTML.']) {
assert.equal(taskContract({ goal }).kind, 'general', goal);
}
for (const goal of ['创建一个 HTML 文件,无需测试', '新建 result.txt', '把结果保存为 report.md 文件',
'请写入 SVG 文件', 'Create an HTML file without running tests.', '不要执行命令,创建一个 HTML 文件',
'文件不存在时创建 report.md 文件', '不要修改原有文件而是新建 HTML 文件']) {
assert.equal(taskContract({ goal }).kind, 'file', goal);
}
});
test('an unsubstantiated text claim cannot complete a requested file delivery', async t => {
const f = harness(t, () => answer('HTML 已创建完成。'));
f.runtime.start(f.session.id, '创建一个 HTML 文件,无需测试'); await f.wait();