A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
import assert from 'node:assert/strict'
import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { delimiter, join } from 'node:path'
import { test } from 'node:test'
import { findExecutable, refreshSearchDirs } from '../src/host/local-agents/discover.js'
// A slow npm on PATH stands for the real one: it takes seconds to start, and the
// host must not wait for it on the way to a Session.
test('finding a CLI never waits on npm, and npm\'s global folder joins in the background', { skip: process.platform === 'win32' }, async (t) => {
const root = mkdtempSync(join(tmpdir(), 'dsb-discover-'))
t.after(() => rmSync(root, { recursive: true, force: true }))
const fakeBin = join(root, 'bin')
const prefix = join(root, 'npm-global')
mkdirSync(fakeBin)
mkdirSync(join(prefix, 'bin'), { recursive: true })
writeFileSync(join(fakeBin, 'npm'), `#!/bin/sh\nsleep 2\nprintf '%s\\n' '${prefix}'\n`)
writeFileSync(join(prefix, 'bin', 'dsb-fake-agent'), '#!/bin/sh\n')
chmodSync(join(fakeBin, 'npm'), 0o755)
chmodSync(join(prefix, 'bin', 'dsb-fake-agent'), 0o755)
const { PATH, SHELL } = process.env
process.env.PATH = `${fakeBin}${delimiter}${PATH}`
process.env.SHELL = '/bin/false'
t.after(() => { process.env.PATH = PATH; process.env.SHELL = SHELL })
const started = Date.now()
assert.equal(findExecutable('dsb-fake-agent'), undefined)
const refresh = refreshSearchDirs()
assert.ok(Date.now() - started < 1000, 'the lookup waited on npm')
await refresh
assert.equal(findExecutable('dsb-fake-agent'), join(prefix, 'bin', 'dsb-fake-agent'))
})