A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Wait for each test host to stop before removing its home
Fei2411b658624e6afe
diff --git a/ds-bot/test/agents.test.js b/ds-bot/test/agents.test.jsindex 695bab21..8727567e 100644--- a/ds-bot/test/agents.test.js+++ b/ds-bot/test/agents.test.js@@ -67,8 +67,8 @@ function start(team, { config = {} } = {}) {return response.json()}const createdAgents = payload => (ctx.listeners.get('agent/created') ?? []).map(listener => listener(payload))- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, stop, home, created, archived, failArchive, restricted, renamed, createdAgents, ctx }@@ -184,7 +184,7 @@ test('agents survive a state reload', async (t) => {const agent = (await call('add-agent')).value// Restart on the saved file: the agent record is adopted, not lost.const saved = readFileSync(join(home, 'state.json'), 'utf8')- stop()+ await stop()const again = start(JSON.parse(saved))t.after(again.stop)const view = (await again.call('state', {})).valuediff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.jsindex b4b11e1c..c77973cf 100644--- a/ds-bot/test/bot-messages.test.js+++ b/ds-bot/test/bot-messages.test.js@@ -92,8 +92,8 @@ async function start(seed) {method: 'POST', body: JSON.stringify({ endpoint, payload }),}))).json()const exchanges = async () => (await call('exchange', { a: 'a', b: 'b' })).value ?? []- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}// Loading once fills the Session-owner indexes turns.js filters events by.diff --git a/ds-bot/test/connectors.test.js b/ds-bot/test/connectors.test.jsindex 60d5a779..75d82540 100644--- a/ds-bot/test/connectors.test.js+++ b/ds-bot/test/connectors.test.js@@ -80,7 +80,7 @@ test('connecting saves the token, kept out of every Bot shell, and mounts GitHubt.after(() => { globalThis.fetch = realFetch })globalThis.fetch = async () => answer(200, { login: 'octo' })const { ctx, home, mounts } = setup()- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const token = fresh()const before = await call(ctx, 'state', {})@@ -113,7 +113,7 @@ test('a token GitHub refuses is not saved', async (t) => {t.after(() => { globalThis.fetch = realFetch })globalThis.fetch = async () => answer(401, {})const { ctx, home, mounts } = setup()- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const result = await call(ctx, 'connector-connect', { id: 'github', token: fresh() })assert.equal(result.ok, false)assert.match(result.error.message, /did not accept/)@@ -126,7 +126,7 @@ test('a failed MCP connection shows the error without the token, and Try again mt.after(() => { globalThis.fetch = realFetch })globalThis.fetch = async () => answer(200, { login: 'octo' })const { ctx, home, mounts } = setup({ fail: true })- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const token = fresh()const result = await call(ctx, 'connector-connect', { id: 'github', token })const [github] = result.value@@ -142,7 +142,7 @@ test('deleting GITHUB_TOKEN on the Secrets page unmounts GitHub', async (t) => {t.after(() => { globalThis.fetch = realFetch })globalThis.fetch = async () => answer(200, { login: 'octo' })const { ctx, home, mounts } = setup()- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })await call(ctx, 'connector-connect', { id: 'github', token: fresh() })await call(ctx, 'secret-delete', { name: 'GITHUB_TOKEN' })const state = await call(ctx, 'state', {})@@ -155,7 +155,7 @@ test('github: false hides the connector', async (t) => {const ctx = fakeContext()capture(ctx)apply(ctx, { home, github: false })- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })assert.deepEqual((await call(ctx, 'state', {})).value.connectors, [])})@@ -165,7 +165,7 @@ test('a GitHub address without https refuses to send the token', async (t) => {let asked = falseglobalThis.fetch = async () => { asked = true; return answer(200, { login: 'octo' }) }const { ctx, home, mounts } = setup({ github: { url: 'http://mcp.test/', api: 'https://gh.test' } })- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const refused = await call(ctx, 'connector-connect', { id: 'github', token: fresh() })assert.equal(refused.ok, false)assert.match(refused.error.message, /https/)diff --git a/ds-bot/test/group-status.test.js b/ds-bot/test/group-status.test.jsindex c30f33d3..2a8adf9c 100644--- a/ds-bot/test/group-status.test.js+++ b/ds-bot/test/group-status.test.js@@ -71,7 +71,7 @@ async function start() {const tool = (name, args, sessionId, exec = {}) => ctx.registeredTools.get(name).execute(args, { agent: { id: sessionId }, ...exec })const call = async (endpoint, payload) => (await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))).json()const askApproval = (sessionId, extra = {}, next = () => 'from-dsh') => ctx.listeners.get('approval/request')[0]({ agent: { session: { id: sessionId } }, toolName: 'pwsh', reason: 'escalate sandbox', ...extra }, next)- const stop = () => { ctx.dispose(); rmSync(home, { recursive: true, force: true }) }+ const stop = async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) }await tool('list_bots', {}, 'a')return { agentOf, emit, tool, call, askApproval, stop, archived }}diff --git a/ds-bot/test/install.test.js b/ds-bot/test/install.test.jsindex ee0f733a..3f962f74 100644--- a/ds-bot/test/install.test.js+++ b/ds-bot/test/install.test.js@@ -21,8 +21,8 @@ function start(state, { config = {}, services } = {}) {const response = await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))return response.json()}- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { ctx, call, stop }diff --git a/ds-bot/test/legacy-state.test.js b/ds-bot/test/legacy-state.test.jsindex fcf6912e..c543da0a 100644--- a/ds-bot/test/legacy-state.test.js+++ b/ds-bot/test/legacy-state.test.js@@ -38,8 +38,8 @@ function open(saved) {const response = await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))return response.json()}- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, stop, home }diff --git a/ds-bot/test/memory.test.js b/ds-bot/test/memory.test.jsindex 9cb9fb9c..d49c01b6 100644--- a/ds-bot/test/memory.test.js+++ b/ds-bot/test/memory.test.js@@ -164,8 +164,8 @@ function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies =const section = sessionId => ctx.sections.get('bot-memory').text({ agent: { id: sessionId } })const read = (...path) => readFileSync(join(home, 'memory', ...path), 'utf8')const journal = () => read('journal.jsonl').trim().split('\n').map(line => JSON.parse(line))- const stop = ({ keep = false } = {}) => {- ctx.dispose()+ const stop = async ({ keep = false } = {}) => {+ await ctx.dispose()if (!keep) rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { ctx, home, call, tool, section, read, journal, requests, stop }@@ -264,12 +264,12 @@ test('a Session keeps the memory it began with, across restarts, until its snapsawait first.tool('remember', { text: 'Lives in Hangzhou', topic: 'home' }, 'b2')assert.equal(first.section('b2'), opened)// Another dsh run finds the snapshot and keeps the same bytes.- first.stop({ keep: true })+ await first.stop({ keep: true })const second = start({ home: first.home })await second.tool('recall', {}, 'b2')assert.equal(second.section('b2'), opened)// Without its snapshot (renewMemory removes it), the Session freezes the memory anew.- second.ctx.dispose()+ await second.ctx.dispose()const renewed = start({ home: first.home })t.after(() => renewed.stop())rmSync(join(first.home, 'memory', 'snapshots', 'b2.md'))diff --git a/ds-bot/test/questions.test.js b/ds-bot/test/questions.test.jsindex b1f0bc02..82c4ff3f 100644--- a/ds-bot/test/questions.test.js+++ b/ds-bot/test/questions.test.js@@ -54,7 +54,7 @@ async function start() {}))).json()).value.questions// Loading once fills the Session-owner indexes turns.js filters events by.await ctx.registeredTools.get('list_bots').execute({}, { agent: { id: 'chief' } })- return { emit, ask, questions, stop: () => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) } }+ return { emit, ask, questions, stop: async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) } }}const text = value => [{ type: 'text', text: value }]diff --git a/ds-bot/test/roster.test.js b/ds-bot/test/roster.test.jsindex 002de170..b1e8740a 100644--- a/ds-bot/test/roster.test.js+++ b/ds-bot/test/roster.test.js@@ -59,8 +59,8 @@ function start(team, { models = [], reasoning = {}, archiveError } = {}) {const response = await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))return response.json()}- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, stop, home, sent, selected, ctx, archived, warnings }@@ -415,7 +415,7 @@ test('a rolled-back Bot does not come back with a save queued before the rollbact.after(async () => {fsp.rename = renamesyncBuiltinESMExports()- stop()+ await stop()})// The first Bot also saves the team's workspace; later ones save only themselves.await call('create-bot', { name: 'Warm' })diff --git a/ds-bot/test/rounds.test.js b/ds-bot/test/rounds.test.jsindex 79c83297..099204b9 100644--- a/ds-bot/test/rounds.test.js+++ b/ds-bot/test/rounds.test.js@@ -97,8 +97,8 @@ function start() {await emit(sessionId, { type: 'assistant/message', data: { message: { content: [{ type: 'text', text }] } } })await emit(sessionId, { type: 'turn/end', data: { reason: { kind: 'stop' } } })}- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, emit, userMessage, compose, relay, inboxOf, answer, stop, sent, ctx, home }diff --git a/ds-bot/test/schedules.test.js b/ds-bot/test/schedules.test.jsindex ac884b2f..f019f7a1 100644--- a/ds-bot/test/schedules.test.js+++ b/ds-bot/test/schedules.test.js@@ -57,7 +57,7 @@ function setup(services = {}) {test('without the schedule service the page says so and creating is refused', async (t) => {const { ctx, home, call } = setup()- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })assert.deepEqual((await call('schedules', {})).value, { available: false, tasks: [] })const refused = await call('schedule-create', { target: 'm1', title: 'Briefing', prompt: 'Sum up', when: { kind: 'daily', time: '09:00', timeZone: 'Asia/Shanghai' } })assert.equal(refused.ok, false)@@ -67,7 +67,7 @@ test('without the schedule service the page says so and creating is refused', astest('tasks are created on the Bot’s current part, listed by Bot, and deleted', async (t) => {const schedule = scheduleService()const { ctx, home, call } = setup({ schedule })- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const daily = await call('schedule-create', { target: 'w1', title: ' Briefing ', prompt: 'Sum up the day', when: { kind: 'daily', time: '09:00', timeZone: 'Asia/Shanghai' } })assert.equal(daily.ok, true, JSON.stringify(daily))const [created] = [...schedule.tasks.values()]@@ -106,7 +106,7 @@ test('tasks are created on the Bot’s current part, listed by Bot, and deleted'test('a group chat task lives on the group Session and lists under the group', async (t) => {const schedule = scheduleService()const { ctx, home, call } = setup({ schedule })- t.after(() => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })const made = await call('schedule-create', { target: 'g1', title: 'Standup', prompt: 'Where are we?', when: { kind: 'daily', time: '10:00', timeZone: 'UTC' } })assert.equal(made.ok, true, JSON.stringify(made))assert.equal([...schedule.tasks.values()][0].sessionId, 'g1')diff --git a/ds-bot/test/secrets.test.js b/ds-bot/test/secrets.test.jsindex 9ef96365..668c2c56 100644--- a/ds-bot/test/secrets.test.js+++ b/ds-bot/test/secrets.test.js@@ -120,7 +120,7 @@ function start() {return result.value}const env = (agentId, command = '') => contributors.filter(entry => entry.live).at(-1)?.resolve({ agent: { id: agentId, session: { header: { id: agentId } } }, arguments: { command } }) ?? {}- const stop = () => { ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) }+ const stop = async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) }return { ctx, home, call, tool, view, env, listeners, delivered, streamed, contributors, stop }}diff --git a/ds-bot/test/update-bot.test.js b/ds-bot/test/update-bot.test.jsindex b05871cb..1cc74699 100644--- a/ds-bot/test/update-bot.test.js+++ b/ds-bot/test/update-bot.test.js@@ -49,8 +49,8 @@ function start() {apply(ctx, { home })const tool = (name, args, sessionId) => ctx.registeredTools.get(name).execute(args, { agent: { id: sessionId } })const state = () => JSON.parse(readFileSync(join(home, 'state.json'), 'utf8'))- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { ctx, tool, state, stop }diff --git a/ds-bot/test/usage.test.js b/ds-bot/test/usage.test.jsindex 00fb2e68..142d2e28 100644--- a/ds-bot/test/usage.test.js+++ b/ds-bot/test/usage.test.js@@ -107,8 +107,8 @@ function start(home, { listedExtra, logsExtra, subagentsExtra } = {}) {return response.json()}const meter = ctx.listeners.get('llm/stream').at(-1)- const stop = () => {- ctx.dispose()+ const stop = async () => {+ await ctx.dispose()rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, ctx, home, meter, pages, stop, warnings }@@ -161,7 +161,7 @@ test('a call made in a group chat stays group use after the room is gone', asynct.after(() => rmSync(home, { recursive: true, force: true, maxRetries: 5 }))const before = (await first.call('usage', { timeZone: 'Asia/Shanghai' })).valueassert.equal(totals(before)['Chief/group'], 330)- first.ctx.dispose()+ await first.ctx.dispose()const state = JSON.parse(readFileSync(join(home, 'state.json'), 'utf8'))state.rooms = {}@@ -170,7 +170,7 @@ test('a call made in a group chat stays group use after the room is gone', asyncconst second = start(home)const after = (await second.call('usage', { timeZone: 'Asia/Shanghai' })).valueassert.equal(totals(after)['Chief/group'], 330)- second.ctx.dispose()+ await second.ctx.dispose()})test('a plain chat journals its owner before the first scan, so a deleted Bot keeps its name', async (t) => {@@ -183,7 +183,7 @@ test('a plain chat journals its owner before the first scan, so a deleted Bot keassert.equal(first.meter({ sessionId: 'b2', messages: [] }, () => passed), passed)// The ledger opens behind the meter; give it a moment before the shutdown.await new Promise(resolve => setTimeout(resolve, 300))- first.ctx.dispose()+ await first.ctx.dispose()const state = JSON.parse(readFileSync(join(home, 'state.json'), 'utf8'))delete state.bots.b2@@ -197,7 +197,7 @@ test('a plain chat journals its owner before the first scan, so a deleted Bot ke})const view = (await second.call('usage', { timeZone: 'Asia/Shanghai' })).valueassert.equal(totals(view)['Writer/chat'], 55)- second.ctx.dispose()+ await second.ctx.dispose()})test('a subagent Session is read through its parent, even a parent that is gone; one that cannot be read warns once', async (t) => {