A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
test: cover the assemble scope and the relay's visible failure
Fei2411b5b531b5db61
diff --git a/ds-bot/test/agent-preset.test.js b/ds-bot/test/agent-preset.test.jsindex b354ab7f..e4347823 100644--- a/ds-bot/test/agent-preset.test.js+++ b/ds-bot/test/agent-preset.test.js@@ -3,6 +3,7 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { test } from 'node:test'+import { format } from 'node:util'import { createRuntime } from '../index.js'import { fakeContext } from './fake-ctx.js'@@ -46,11 +47,14 @@ function start({ presets } = {}) {})const rt = createRuntime(ctx, { home, github: false, diagnosticsFile: false })const relay = ctx.listeners.get('llm/stream').find(listener => /relayOrPass/.test(String(listener)))+ const warnings = []+ const warn = rt.warn+ rt.warn = (...args) => { warnings.push(format(...args)); return warn(...args) }const stop = async () => {await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}- return { rt, created, relay, stop }+ return { rt, created, relay, warnings, stop }}async function drain(stream) {@@ -107,3 +111,19 @@ test('a group made under the PTC preset relays through run_code', async (t) => {timeoutMs: 600_000,})})++test('a group Session without either relay tool ends visibly instead of calling nothing', async (t) => {+ // #826: the relay used to synthesize group_relay even when the Session did not+ // declare it, and the "unknown tool" failure left no trace.+ const { relay, warnings, stop } = start()+ t.after(stop)+ const chunks = await drain(relay({ provider: 'deepseek', model: 'v4', sessionId: 'room', messages: [userText('Hello team')], tools: declared('read', 'write') }, () => {+ throw new Error('a group round never reaches the model')+ }))+ assert.ok(!chunks.some(chunk => chunk.type === 'tool-call-delta' || chunk.block?.type === 'tool-call'))+ const text = chunks.find(chunk => chunk.type === 'text-delta')?.text+ assert.match(text ?? '', /relay tool is not available/)+ assert.equal(chunks.find(chunk => chunk.type === 'block-end')?.block?.type, 'text')+ assert.deepEqual(chunks.at(-1), { type: 'finish', reason: { kind: 'stop' } })+ assert.ok(warnings.some(line => line.includes('cannot relay')))+})diff --git a/ds-bot/test/blocking-question.test.js b/ds-bot/test/blocking-question.test.jsindex 6346ba77..7c84f2c2 100644--- a/ds-bot/test/blocking-question.test.js+++ b/ds-bot/test/blocking-question.test.js@@ -46,6 +46,7 @@ async function setup({ served = ['read', 'ask_user', QUESTION], goals, throwOn }session: { id },ctx: {tools: {+ register: () => () => {},restrict: (filter) => {if (throwOn !== undefined && filter.deny.includes(throwOn)) throw new Error(`"${throwOn}" is registered in this scope`)hidden.push([id, [...filter.deny]])diff --git a/ds-bot/test/install.test.js b/ds-bot/test/install.test.jsindex 2c675347..ccd41ae8 100644--- a/ds-bot/test/install.test.js+++ b/ds-bot/test/install.test.js@@ -55,6 +55,7 @@ test('apply registers listeners and effects in a fixed order', (t) => {'effect ds-bot: scoped team tools','tools guard','on agent/created',+ 'on system-prompt/assemble','on session/event','effect ds-bot: chat index','effect ds-bot: group step lines',diff --git a/ds-bot/test/scoped-tools-creation.test.js b/ds-bot/test/scoped-tools-creation.test.jsindex 65b1468c..cbdf932a 100644--- a/ds-bot/test/scoped-tools-creation.test.js+++ b/ds-bot/test/scoped-tools-creation.test.js@@ -7,6 +7,10 @@ import { createRuntime } from '../index.js'import { TEAM_TOOLS } from '../src/host/constants.js'import { fakeContext } from './fake-ctx.js'+// tools.js keeps the DSH names a Bot Session never serves in one place; the+// assemble must add none of them.+const HIDDEN = ['ask_user_question', 'subagent', 'list_subagent_models', 'send_message']+// A Bot-owned Session gets its Agent before ds-bot records the owner, so the// scoped show_view and the hidden-tool restrict used to wait for a later// resolveAgent that a held kickoff never ran. These tests drive each creation@@ -106,8 +110,17 @@ const start = (team = TEAM, services = {}, globals = [], shared = {}) => {liveAgents.set(sessionId, agent)return agent}- // ask_user_question is served, so the deny list is not empty in a Bot scope.- ctx.tools.schemas = () => [{ name: 'ask_user_question' }, { name: 'show_view' }]+ // ask_user_question is served, so the deny list is not empty in a Bot scope;+ // a Session's own registrations join its list and shadow globals of one name,+ // as DSH's scope view does.+ ctx.tools.schemas = (agent) => {+ const view = new Map()+ for (const name of ['ask_user_question', 'show_view']) view.set(name, { name })+ for (const entry of scoped.filter(entry => entry.sessionId === agent?.id)) {+ view.set(entry.name, { name: entry.name, description: entry.tool.description, parameters: entry.tool.parameters })+ }+ return [...view.values()]+ }Object.assign(ctx, {llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },workspaceRegistry: {@@ -326,6 +339,63 @@ test('a Session that becomes a Bot\'s again gets the scope back', async (t) => {assert.ok(hasShowView(host, 'b'))})+// #826: after a DSH restart the creation path can miss a live Agent and nothing+// scoped it again, so the Session ran its requests without the team tools. The+// step's assemble scopes an owned Session the creation path missed and adds the+// names the request list was already built without.+const assemble = (host, agent, assembly = { tools: [], sections: [] }) => {+ const listener = host.ctx.listeners.get('system-prompt/assemble')+ .find(listener => /scopeTeamTools/.test(String(listener)))+ return listener(assembly, { agent, signal: AbortSignal.timeout(60_000) }, async () => assembly)+}++test("a group Session the creation path missed is scoped at the step's assemble", async (t) => {+ const host = start()+ t.after(host.stop)+ await host.call('state', {})+ // The Agent is live but agent/created never ran for it and no save re-synced+ // the scopes — the state a restart left the reporter's group in.+ const agent = host.agentOf('r1')+ const assembled = await assemble(host, agent, { tools: [{ name: 'read' }], sections: [] })+ assert.deepEqual(scopedNames(host, 'r1'), ['group_relay'])+ assert.deepEqual(assembled.tools.map(tool => tool.name), ['read', 'group_relay'])+})++test("a Bot's own Session the creation path missed gets the whole scope at the assemble", async (t) => {+ const host = start()+ t.after(host.stop)+ await host.call('state', {})+ const agent = host.agentOf('a')+ const assembled = await assemble(host, agent, { tools: [{ name: 'read' }], sections: [] })+ const expected = [...TEAM_TOOLS].filter(name => name !== 'read_browser').sort()+ assert.deepEqual(scopedNames(host, 'a').sort(), expected)+ assert.deepEqual(assembled.tools.map(tool => tool.name).sort(), ['read', ...expected].sort())+ // The hidden DSH tools are masked and filtered as on the creation path: none+ // of their names joined the list the assemble added.+ assert.ok(denied(host, 'a'), 'the blocking question tool is denied')+ assert.ok(!HIDDEN.some(name => assembled.tools.some(tool => tool.name === name)))+})++test('the assemble registers nothing twice in an already scoped Session', async (t) => {+ const host = start()+ t.after(host.stop)+ await host.call('state', {})+ await host.agentCreated('a')+ const before = host.scoped.length+ const assembly = { tools: [{ name: 'read' }], sections: [] }+ assert.equal(await assemble(host, host.agentOf('a'), assembly), assembly)+ assert.equal(host.scoped.length, before)+})++test('the assemble passes an unowned Session through unchanged', async (t) => {+ const host = start()+ t.after(host.stop)+ await host.call('state', {})+ const assembly = { tools: [{ name: 'read' }], sections: [] }+ assert.equal(await assemble(host, host.agentOf('plain1'), assembly), assembly)+ assert.deepEqual(scopedNames(host, 'plain1'), [])+})+test('a live Bot Session gets its team tools back after a disable and re-enable', async (t) => {// A hot reload lifts the scope of Agents that are still live, and// agent/created does not fire again: the sync at the next load must scopediff --git a/ds-bot/test/session-identity.test.js b/ds-bot/test/session-identity.test.jsindex 4ac088fe..76757756 100644--- a/ds-bot/test/session-identity.test.js+++ b/ds-bot/test/session-identity.test.js@@ -82,7 +82,7 @@ function start() {},},sessionController: {- resolveAgent: async sessionId => ({ agent: { id: sessionId, session: { id: sessionId, seq: 2 } } }),+ resolveAgent: async sessionId => ({ agent: { id: sessionId, session: { id: sessionId, seq: 2 }, ctx: { tools: { register: () => () => {} } } } }),selectModel: async () => {},page: async () => ({records: [@@ -144,7 +144,7 @@ test('an image in a group is read for the group, and the group still relays itsassert.match(reading, /read by vision:\]\nA red triangle\./)assert.deepEqual(bench.requests.map(request => [request.model, request.sessionId]), [['vision', 'r1']])- const chunks = await drain(ctx.llm.stream({ provider: 'deepseek', model: 'v4', sessionId: 'r1', messages: [userText('Discuss the picture')] }))+ const chunks = await drain(ctx.llm.stream({ provider: 'deepseek', model: 'v4', sessionId: 'r1', messages: [userText('Discuss the picture')], tools: [{ name: 'group_relay' }] }))assert.ok(chunks.some(chunk => chunk.type === 'tool-call-delta' && chunk.name === 'group_relay'))assert.equal(bench.requests.length, 1)})@@ -160,7 +160,7 @@ test('the Session hooks pass DS Bot\'s own requests through, and still act on aconst relay = hook(/relayOrPass/)assert.equal(relay(own('r1', [userText('Read this')]), pass), passed)- assert.ok((await drain(relay(round('r1', [userText('Read this')]), pass))).some(chunk => chunk.name === 'group_relay'))+ assert.ok((await drain(relay({ ...round('r1', [userText('Read this')]), tools: [{ name: 'group_relay' }] }, pass))).some(chunk => chunk.name === 'group_relay'))const handoff = [{ role: 'user', source: { kind: 'bot', handoff: true }, content: [{ type: 'text', text: 'Handoff note' }] }]const acknowledge = hook(/acknowledge/)diff --git a/ds-bot/test/switch-keeps-input.test.js b/ds-bot/test/switch-keeps-input.test.jsindex 5d843581..dc941feb 100644--- a/ds-bot/test/switch-keeps-input.test.js+++ b/ds-bot/test/switch-keeps-input.test.js@@ -79,6 +79,7 @@ async function start({ fail = {}, services = {}, home: reuse } = {}) {agents.set(sessionId, {id: sessionId,session: { id: sessionId, header: { cwd: cwds.get(sessionId) ?? team }, requestHeader: () => undefined, deriveMessages: () => [] },+ ctx: { tools: { register: () => () => {} } },calls,status: 'idle',followup(message) { calls.push(['followup', message]) },