A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Retry removing a test's data folder while a save is still writing to it
Fei2411e9fe2f618738
diff --git a/ds-bot/test/agents.test.js b/ds-bot/test/agents.test.jsindex c1623609..695bab21 100644--- a/ds-bot/test/agents.test.js+++ b/ds-bot/test/agents.test.js@@ -69,7 +69,7 @@ function start(team, { config = {} } = {}) {const createdAgents = payload => (ctx.listeners.get('agent/created') ?? []).map(listener => listener(payload))const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, stop, home, created, archived, failArchive, restricted, renamed, createdAgents, ctx }}diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.jsindex 259bd02d..ddbc46af 100644--- a/ds-bot/test/bot-messages.test.js+++ b/ds-bot/test/bot-messages.test.js@@ -94,7 +94,7 @@ async function start(seed) {const exchanges = async () => (await call('exchange', { a: 'a', b: 'b' })).value ?? []const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ rmSync(home, { recursive: true, force: true, maxRetries: 5 })}// Loading once fills the Session-owner indexes turns.js filters events by.await tool('list_bots', {}, 'a')diff --git a/ds-bot/test/connectors.test.js b/ds-bot/test/connectors.test.jsindex 66dfab39..60d5a779 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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/diagnostics.test.js b/ds-bot/test/diagnostics.test.jsindex bc6d8a47..ebfe10d3 100644--- a/ds-bot/test/diagnostics.test.js+++ b/ds-bot/test/diagnostics.test.js@@ -49,7 +49,7 @@ function host(home, extra = {}) {test('warnings are kept, cleaned, written to the log, and read back after a restart', async (t) => {const home = mkdtempSync(join(tmpdir(), 'ds-bot-diag-'))- t.after(() => rmSync(home, { recursive: true, force: true }))+ t.after(() => rmSync(home, { recursive: true, force: true, maxRetries: 5 }))const error = Object.assign(new Error(`cannot open ${homedir()}/x with sk-abcdefghij`), { code: 'EACCES' })const quiet = t.mock.method(console, 'error', () => {})const rt = host(home)@@ -86,7 +86,7 @@ test('warnings are kept, cleaned, written to the log, and read back after a resttest('warnings send only cleaned text to the logger and stderr', (t) => {const home = mkdtempSync(join(tmpdir(), 'ds-bot-diag-'))- t.after(() => rmSync(home, { recursive: true, force: true }))+ t.after(() => rmSync(home, { recursive: true, force: true, maxRetries: 5 }))const values = ['synthetic-api-key-123456', 'synthetic-bearer-token-12345', 'synthetic-query-token-12345']const error = new Error(`api_key=${values[0]} Bearer ${values[1]} https://example.invalid/?token=${values[2]}`)error.stack = `${error.name}: ${error.message}\n at fake (https://example.invalid/?token=${values[2]}:1:1)`@@ -110,7 +110,7 @@ test('warnings send only cleaned text to the logger and stderr', (t) => {test('diagnostics append fallback redacts an error message', async (t) => {const home = mkdtempSync(join(tmpdir(), 'ds-bot-diag-'))- t.after(() => rmSync(home, { recursive: true, force: true }))+ t.after(() => rmSync(home, { recursive: true, force: true, maxRetries: 5 }))const value = 'synthetic-api-key-append-123456'const stderr = []const quiet = t.mock.method(console, 'error', (...args) => stderr.push(args.join(' ')))diff --git a/ds-bot/test/home-lock.test.js b/ds-bot/test/home-lock.test.jsindex fac8c922..bd8a98bf 100644--- a/ds-bot/test/home-lock.test.js+++ b/ds-bot/test/home-lock.test.js@@ -11,7 +11,7 @@ import { fakeContext } from './fake-ctx.js'const tempHome = (t) => {const home = mkdtempSync(join(tmpdir(), 'ds-bot-lock-'))- t.after(() => rmSync(home, { recursive: true, force: true }))+ t.after(() => rmSync(home, { recursive: true, force: true, maxRetries: 5 }))return home}diff --git a/ds-bot/test/install.test.js b/ds-bot/test/install.test.jsindex f01c8550..bbe1db58 100644--- a/ds-bot/test/install.test.js+++ b/ds-bot/test/install.test.js@@ -23,7 +23,7 @@ function start(state, { config = {}, services } = {}) {}const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ 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 7306625d..fcf6912e 100644--- a/ds-bot/test/legacy-state.test.js+++ b/ds-bot/test/legacy-state.test.js@@ -40,7 +40,7 @@ function open(saved) {}const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ 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 6efbbc06..77c87386 100644--- a/ds-bot/test/memory.test.js+++ b/ds-bot/test/memory.test.js@@ -166,7 +166,7 @@ function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies =const journal = () => read('journal.jsonl').trim().split('\n').map(line => JSON.parse(line))const stop = ({ keep = false } = {}) => {ctx.dispose()- if (!keep) rmSync(home, { recursive: true, force: true })+ if (!keep) rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { ctx, home, call, tool, section, read, journal, requests, stop }}diff --git a/ds-bot/test/mock-llm.test.js b/ds-bot/test/mock-llm.test.jsindex 063fb5f7..fc516f75 100644--- a/ds-bot/test/mock-llm.test.js+++ b/ds-bot/test/mock-llm.test.js@@ -42,7 +42,7 @@ test('长任务 writes text on every step when the step size is left out', asyncconst mock = spawn(process.execPath, [MOCK], {env: { ...process.env, MOCK_PORT: '0', MOCK_LOG: join(home, 'mock.jsonl'), MOCK_DELAY_MS: '5', MOCK_JITTER_MS: '0' },})- t.after(() => { mock.kill(); rmSync(home, { recursive: true, force: true }) })+ t.after(() => { mock.kill(); rmSync(home, { recursive: true, force: true, maxRetries: 5 }) })// MOCK_PORT=0 lets the kernel pick a free port; the mock prints the real one.const url = await new Promise((resolve, reject) => {mock.stdout.on('data', chunk => {diff --git a/ds-bot/test/questions.test.js b/ds-bot/test/questions.test.jsindex 9e5961cc..b1f0bc02 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 }) } }+ return { emit, ask, questions, stop: () => { 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 dbe175a4..1cd79cbe 100644--- a/ds-bot/test/roster.test.js+++ b/ds-bot/test/roster.test.js@@ -61,7 +61,7 @@ function start(team, { models = [], reasoning = {}, archiveError } = {}) {}const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, stop, home, sent, selected, ctx, archived, warnings }}diff --git a/ds-bot/test/rounds.test.js b/ds-bot/test/rounds.test.jsindex b46eccf8..79c83297 100644--- a/ds-bot/test/rounds.test.js+++ b/ds-bot/test/rounds.test.js@@ -99,7 +99,7 @@ function start() {}const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ 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 487af700..ac884b2f 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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 }) })+ t.after(() => { 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 e7a55c35..9ef96365 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 }) }+ const stop = () => { 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/store.test.js b/ds-bot/test/store.test.jsindex c6281312..03cd46f6 100644--- a/ds-bot/test/store.test.js+++ b/ds-bot/test/store.test.js@@ -56,7 +56,7 @@ function runtime(t, saved) {}t.after(async () => {await dispose()- fs.rmSync(home, { recursive: true, force: true })+ fs.rmSync(home, { recursive: true, force: true, maxRetries: 5 })})return { rt, home, statePath, warnings, dispose }}diff --git a/ds-bot/test/update-bot.test.js b/ds-bot/test/update-bot.test.jsindex bc67de8e..b05871cb 100644--- a/ds-bot/test/update-bot.test.js+++ b/ds-bot/test/update-bot.test.js@@ -51,7 +51,7 @@ function start() {const state = () => JSON.parse(readFileSync(join(home, 'state.json'), 'utf8'))const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { ctx, tool, state, stop }}diff --git a/ds-bot/test/update.test.js b/ds-bot/test/update.test.jsindex 6304b5bc..b88ec95c 100644--- a/ds-bot/test/update.test.js+++ b/ds-bot/test/update.test.js@@ -172,7 +172,7 @@ test('without a source from the plugin manager, the profile\'s own dependency enassert.equal(view.available, true)writeFileSync(join(dir, 'package.json'), JSON.stringify({ dependencies: { [PKG.name]: 'link:/work/ds-bot' } }))assert.equal((await rt.updateCheck({ fresh: true })).source, 'path')- rmSync(dir, { recursive: true, force: true })+ rmSync(dir, { recursive: true, force: true, maxRetries: 5 })})test('a check that finds nothing clears the version a check before it found', async () => {@@ -197,7 +197,7 @@ test('a check that finds nothing clears the version a check before it found', asconst gone = await rt.updateCheck({ fresh: true })assert.equal(gone.available, false)assert.equal(gone.latest, null)- rmSync(dir, { recursive: true, force: true })+ rmSync(dir, { recursive: true, force: true, maxRetries: 5 })})test('a failed install reports why and can be tried again', async () => {diff --git a/ds-bot/test/usage.test.js b/ds-bot/test/usage.test.jsindex bd8388b8..00fb2e68 100644--- a/ds-bot/test/usage.test.js+++ b/ds-bot/test/usage.test.js@@ -109,7 +109,7 @@ function start(home, { listedExtra, logsExtra, subagentsExtra } = {}) {const meter = ctx.listeners.get('llm/stream').at(-1)const stop = () => {ctx.dispose()- rmSync(home, { recursive: true, force: true })+ rmSync(home, { recursive: true, force: true, maxRetries: 5 })}return { call, ctx, home, meter, pages, stop, warnings }}@@ -158,7 +158,7 @@ test('the usage view counts every Session under its owner, by hour in the askedtest('a call made in a group chat stays group use after the room is gone', async (t) => {const first = start()const { home } = first- t.after(() => rmSync(home, { recursive: true, force: true }))+ t.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()@@ -176,7 +176,7 @@ test('a call made in a group chat stays group use after the room is gone', asynctest('a plain chat journals its owner before the first scan, so a deleted Bot keeps its name', async (t) => {const first = start()const { home } = first- t.after(() => rmSync(home, { recursive: true, force: true }))+ t.after(() => rmSync(home, { recursive: true, force: true, maxRetries: 5 }))// Writer talks once, Usage is never opened: the meter lets the request// through, but the Session's owner lands in the ledger on its own.const passed = (async function* () { yield { type: 'text', text: 'hi' } })()