fix(runtime): advertise tools according to the existing task contract
This commit is contained in:
@@ -488,10 +488,12 @@ export class Runtime {
|
||||
{ name: 'browser_checks', definitions: browserToolDefinitions, assembled: !!browserResources.length, reason: 'missing_current_resource', resources: browserResources },
|
||||
];
|
||||
const availableTools = groups.filter(group => group.assembled).flatMap(group => group.definitions);
|
||||
const tools = openToolDefinitions(availableTools.filter(tool => unrestricted(config) || (!run.worker || WORKER_TOOLS.has(tool.function.name)) && taskToolAllowed(task, run.record, tool.function.name)), permissionConfig);
|
||||
// Task intent already controls execution, including open/full mode.
|
||||
// Advertise the same contract so a diagnostic does not invite writes.
|
||||
const tools = openToolDefinitions(availableTools.filter(tool => (unrestricted(config) || !run.worker || WORKER_TOOLS.has(tool.function.name)) && taskToolAllowed(task, run.record, tool.function.name)), permissionConfig);
|
||||
const toolSurface = observeToolSurface(groups, tools, { identity: { executionMode: config.executionMode ?? 'restricted', approvalMode: permissionConfig.approvalMode,
|
||||
purpose: run.record.purpose ?? 'execution', workerId: run.worker?.id ?? null },
|
||||
reason: name => run.worker && !WORKER_TOOLS.has(name) ? 'disabled_by_worker_contract'
|
||||
reason: name => run.worker && !unrestricted(config) && !WORKER_TOOLS.has(name) ? 'disabled_by_worker_contract'
|
||||
: !taskToolAllowed(task, run.record, name) ? 'disabled_by_task_contract' : 'disabled_by_execution_mode' });
|
||||
const projectMemory = await this.memoryManager().context(session, { redact: value => this.provider.redact(value) });
|
||||
signal.throwIfAborted();
|
||||
|
||||
@@ -12,8 +12,8 @@ import { Provider } from '../src/server/provider.mjs';
|
||||
import { fixture, until, compatibleFixture, completion, call, assertToolPairs } from './helpers.mjs';
|
||||
|
||||
const digest = text => createHash('sha256').update(text).digest('hex');
|
||||
function researchFixture(t, behavior = null, { deepStore = false } = {}) {
|
||||
let f = fixture(t);
|
||||
function researchFixture(t, behavior = null, { deepStore = false, modernDefaults = false } = {}) {
|
||||
let f = fixture(t, { modernDefaults });
|
||||
if (deepStore) {
|
||||
const parts = [];
|
||||
while (path.join(f.root, ...parts, 'data').length < 165) parts.push('用户资料-' + parts.length + '-'.repeat(12));
|
||||
@@ -163,7 +163,9 @@ test('research documents over the single-artifact limit preserve exact Unicode b
|
||||
});
|
||||
|
||||
test('research tools are only sent for registered Task artifacts and actual HTTP uses the sealed tool contract without replay', async t => {
|
||||
const f = researchFixture(t), runtime = new Runtime(f.store, new Provider()); runtime.research = f.manager;
|
||||
// This tests research and diagnostic ownership under the product defaults;
|
||||
// finite context and read-budget behavior have separate regression cases.
|
||||
const f = researchFixture(t, null, { modernDefaults: true }), runtime = new Runtime(f.store, new Provider()); runtime.research = f.manager;
|
||||
const target = await f.manager.register(f.session, { path: f.file });
|
||||
let requests = 0, jobId = null;
|
||||
const model = await compatibleFixture(t, (route, body) => {
|
||||
|
||||
@@ -48,8 +48,8 @@ test('an unsubstantiated text claim cannot complete a requested file delivery',
|
||||
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;
|
||||
function harness(t, respond, options = {}) {
|
||||
const f = fixture(t, options), provider = new Provider(); let round = 0;
|
||||
provider.complete = async (config, messages, project, signal, progress, plan, tools) => respond(round++, { messages, tools, f });
|
||||
const runtime = new Runtime(f.store, provider); f.onCleanup(() => runtime.stopAll());
|
||||
return { ...f, runtime, wait: () => runtime.active.get(f.session.id).promise };
|
||||
@@ -104,6 +104,40 @@ test('diagnostic answers retain the unfinished task, limits and check result, an
|
||||
assert.equal(f.store.core.run.get(f.session.runId).stopReason, 'verification_incomplete');
|
||||
});
|
||||
|
||||
test('open full-access requests advertise task intent while diagnostic history and the existing execution contract stay intact', async t => {
|
||||
const f = harness(t, (round, { tools }) => {
|
||||
if (round === 0) {
|
||||
assert.ok(!tools.some(tool => ['plan_checks', 'run_checks'].includes(tool.function.name)));
|
||||
assert.ok(tools.some(tool => tool.function.name === 'run_command'));
|
||||
return answer('尚未交付。');
|
||||
}
|
||||
if (round === 1) {
|
||||
assert.ok(tools.some(tool => tool.function.name === 'read_file'));
|
||||
assert.ok(!tools.some(tool => ['run_command', 'propose_file', 'prepare_change_set', 'run_checks', 'plan_delivery'].includes(tool.function.name)));
|
||||
return calls(call('open-diagnostic-write', 'propose_file', { path: 'unwanted.txt', content: 'wrong', reason: 'diagnostic must retain the original task' }), call('open-inspect-error', 'inspect_session', {}));
|
||||
}
|
||||
return answer('所属原记录已核对,未修改文件或重跑检查。');
|
||||
}, { modernDefaults: true });
|
||||
f.store.saveConfig({ approvalMode: 'full' });
|
||||
assert.equal(f.store.config.executionMode, 'unrestricted'); assert.equal(f.store.config.capacityMode, 'passthrough'); assert.equal(f.store.config.historyPolicy, 'preserve');
|
||||
f.runtime.start(f.session.id, '读取README.md并解释原记录,无需测试。'); await f.wait();
|
||||
const task = f.store.core.task.get(f.session.taskId), taskId = task.id;
|
||||
task.verification = { status: 'failed', checkJobId: null }; f.session.status = 'paused'; f.store.save(f.session);
|
||||
const instructions = structuredClone(task.instructions), budget = structuredClone(task.budget), history = structuredClone(f.session.providerMessages), original = fs.readFileSync(path.join(f.projectRoot, 'README.md'));
|
||||
f.runtime.start(f.session.id, '前面的错误是怎么回事?'); await f.wait();
|
||||
const run = f.store.core.run.get(f.session.runId);
|
||||
assert.equal(run.purpose, 'diagnostic'); assert.equal(run.status, 'completed'); assert.equal(run.stopReason, 'diagnostic_answered');
|
||||
assert.equal(run.budget.maxTokens, 0); assert.equal(run.budget.maxDurationMs, 0);
|
||||
assert.equal(f.session.taskId, taskId); assert.equal(task.status, 'paused'); assert.equal(f.session.status, 'paused');
|
||||
assert.deepEqual(task.instructions, instructions); assert.deepEqual(task.budget, budget); assert.equal(task.verification.status, 'failed');
|
||||
assert.deepEqual(f.session.providerMessages, history); assert.deepEqual(fs.readFileSync(path.join(f.projectRoot, 'README.md')), original);
|
||||
assert.equal(f.session.changes.length, 0); assert.equal(f.session.approvals.length, 0); assert.equal(fs.existsSync(path.join(f.projectRoot, 'unwanted.txt')), false);
|
||||
const denied = JSON.parse(run.diagnosticMessages.find(message => message.tool_call_id === 'open-diagnostic-write').content);
|
||||
assert.equal(denied.status, 'error'); assert.match(denied.message, /只读/);
|
||||
const inspected = JSON.parse(run.diagnosticMessages.find(message => message.tool_call_id === 'open-inspect-error').content);
|
||||
assert.equal(inspected.diagnosticContext.evidenceVerified, true); assert.equal(inspected.diagnosticContext.taskId, taskId); assertToolPairs(run.diagnosticMessages);
|
||||
});
|
||||
|
||||
test('review continuation is a system action and adds no testing demand or fake user instruction', async t => {
|
||||
let continued;
|
||||
const f = harness(t, (round, { messages }) => {
|
||||
|
||||
Reference in New Issue
Block a user