fix: account failed attempts and stop unchanged task loops in 1.20.1

This commit is contained in:
Agent Workbench Dev
2026-11-01 13:18:03 +08:00
parent 0736eca4cd
commit 441785a8b7
35 changed files with 579 additions and 106 deletions
+28
View File
@@ -5,10 +5,22 @@ 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 { fixture, call, assertToolPairs } from './helpers.mjs';
const answer = content => ({ message: { role: 'assistant', content }, usage: { prompt_tokens: 11, completion_tokens: 3 } });
const calls = (...tools) => ({ ...answer(''), message: { role: 'assistant', content: '', tool_calls: tools } });
test('operational questions are diagnostic while explicit repair requests remain execution instructions', () => {
for (const text of ['前面的错误是怎么回事?', '这个报错是什么意思', '解释下这个错误', '请解释刚才执行的错误', '你使用的是什么模型?', 'Why did your fix fail?']) assert.equal(isDiagnosticQuestion(text), true, text);
for (const text of ['先修复系统', '为什么失败,请帮我修复', '这个错误怎么回事,然后修一下', 'fix this error', '继续完成']) assert.equal(isDiagnosticQuestion(text), false, text);
});
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();
assert.equal(f.session.status, 'paused'); assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'delivery_incomplete');
assert.equal(f.session.changes.length, 0); assert.equal(f.session.approvals.length, 0);
});
function harness(t, respond) {
const f = fixture(t), provider = new Provider(); let round = 0;
provider.complete = async (config, messages, project, signal, progress, plan, tools) => respond(round++, { messages, tools, f });
@@ -86,3 +98,19 @@ test('a provider cannot execute tests against an explicit no-test task even if i
for (const id of ['blocked-check', 'blocked-command']) assert.match(JSON.parse(f.session.providerMessages.find(message => message.tool_call_id === id).content).message, /无需测试/);
assertToolPairs(f.session.providerMessages);
});
test('alternating duplicate file reads and listing files still pauses without treating new pages as duplicates', async t => {
const f = harness(t, round => calls(call('duplicate-read-' + round, 'read_file', { path: round % 2 ? 'README.md' : 'second.txt' }), call('list-between-' + round, 'list_files', { path: '' })));
fs.writeFileSync(path.join(f.projectRoot, 'second.txt'), 'another original source\n');
f.runtime.start(f.session.id, '查看两个文件'); await f.wait();
assert.equal(f.session.status, 'paused'); assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'no_progress');
assert.equal(f.store.core.run.get(f.session.runId).steps, 5); assertToolPairs(f.session.providerMessages);
f.runtime.resume(f.session.id); await f.wait();
assert.equal(f.store.core.task.get(f.session.taskId).stagnation.count, 2);
f.runtime.resume(f.session.id); await f.wait();
assert.equal(f.store.core.run.get(f.session.runId).usage.requests, 0);
assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'no_progress');
fs.appendFileSync(path.join(f.projectRoot, 'second.txt'), 'new owner input\n');
f.runtime.resume(f.session.id); await f.wait();
assert.ok(f.store.core.run.get(f.session.runId).usage.requests > 0);
});