import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { test } from "node:test"; test("思考核查:列目录不截断,首次读源码才截断,并保留原始行号", () => { const root = mkdtempSync(join(tmpdir(), "inforsi-route-thinking-")); try { const call = join(root, "calls/r0-entryDraft.researcher-1.entry.none.1"); const sessions = join(call, "sessions"); const code = join(call, "code"); mkdirSync(sessions, { recursive: true }); mkdirSync(code); writeFileSync(join(code, "initial.py"), "print('baseline')\n"); writeFileSync(join(code, "SOURCES.md"), "reference\n"); const messages = [ { type: "session" }, { type: "message", message: { role: "assistant", content: [ { type: "thinking", thinking: "列目录前" }, { type: "toolCall", name: "read_source", arguments: { path: code } }, ] } }, { type: "message", message: { role: "assistant", content: [ { type: "thinking", thinking: "目录之后先想两种解法" }, { type: "toolCall", name: "read_source", arguments: { path: join(code, "SOURCES.md") } }, ] } }, { type: "message", message: { role: "assistant", content: [ { type: "thinking", thinking: "看过来源说明,还未读源码" }, { type: "toolCall", name: "read_source", arguments: { path: join(code, "initial.py") } }, ] } }, { type: "message", message: { role: "assistant", content: [ { type: "thinking", thinking: "读源码后的内容不能算先想" }, ] } }, ]; writeFileSync(join(sessions, "session.jsonl"), messages.map((m) => JSON.stringify(m)).join("\n")); const output = join(root, "thinking.txt"); const result = spawnSync(process.execPath, ["eval/route/thinking.ts", root, output], { encoding: "utf8" }); assert.equal(result.status, 0, result.stderr); const text = readFileSync(output, "utf8"); assert.match(text, /目录之后先想两种解法/); assert.match(text, /看过来源说明,还未读源码/); assert.match(text, /原始 JSONL:4/); assert.match(text, /仅列目录/); assert.match(text, /首次读取基线源码文件/); assert.doesNotMatch(text, /读源码后的内容不能算先想/); } finally { rmSync(root, { recursive: true, force: true }); } });