Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Pick a kernel-assigned port in the mock-llm regression test

lulu feizhu1f1530f1bdec
diff --git a/ds-bot/dev/mock-llm.mjs b/ds-bot/dev/mock-llm.mjs
index 8cb930a9..862d4b24 100644
--- a/ds-bot/dev/mock-llm.mjs
+++ b/ds-bot/dev/mock-llm.mjs
@@ -586,4 +586,4 @@ const server = createServer((req, res) => {
})
})
-server.listen(PORT, '127.0.0.1', () => console.log(`ds-bot mock on http://127.0.0.1:${PORT}/v1`))
+server.listen(PORT, '127.0.0.1', () => console.log(`ds-bot mock on http://127.0.0.1:${server.address().port}/v1`))
diff --git a/ds-bot/test/mock-llm.test.js b/ds-bot/test/mock-llm.test.js
index ce139039..8637b3a8 100644
--- a/ds-bot/test/mock-llm.test.js
+++ b/ds-bot/test/mock-llm.test.js
@@ -6,12 +6,10 @@ import { join } from 'node:path'
import { test } from 'node:test'
import { fileURLToPath } from 'node:url'
-const PORT = 8917
-const url = `http://127.0.0.1:${PORT}/v1/messages`
const MOCK = fileURLToPath(new URL('../dev/mock-llm.mjs', import.meta.url))
// One Anthropic-shaped request, its SSE reply folded into { text, tools }.
-async function call(messages) {
+async function call(url, messages) {
const res = await fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/json' },
@@ -42,29 +40,33 @@ function fold(messages, out) {
test('长任务 writes text on every step when the step size is left out', async (t) => {
const home = mkdtempSync(join(tmpdir(), 'dsb-mock-'))
const mock = spawn(process.execPath, [MOCK], {
- env: { ...process.env, MOCK_PORT: String(PORT), MOCK_LOG: join(home, 'mock.jsonl'), MOCK_DELAY_MS: '5', MOCK_JITTER_MS: '0' },
+ 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 }) })
- await new Promise((resolve, reject) => {
- mock.stdout.on('data', chunk => { if (String(chunk).includes('/v1')) resolve() })
+ // 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 => {
+ const found = /127\.0\.0\.1:(\d+)\/v1/.exec(String(chunk))
+ if (found !== null) resolve(`http://127.0.0.1:${found[1]}/v1/messages`)
+ })
mock.once('exit', code => reject(new Error(`mock-llm exited ${code}`)))
})
const messages = [{ role: 'user', content: '长任务 3' }]
- let out = await call(messages)
+ let out = await call(url, messages)
assert.equal(out.text.length, 4000) // 步骤0
fold(messages, out)
- out = await call(messages)
+ out = await call(url, messages)
assert.equal(out.text.length, 4000) // a tool result continues the task
fold(messages, out)
// A spliced Bot message mid-task hits the other parse of the same command.
messages.push({ role: 'user', content: '[Message from HelperBot] 进度如何?' })
- out = await call(messages)
+ out = await call(url, messages)
assert.equal(out.text.length, 4000)
fold(messages, out)
- out = await call(messages)
+ out = await call(url, messages)
assert.match(out.text, /长任务做完了,一共 3 步。/)
})