workflow-driver.live.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /**
  2. * Live 层集成测试(phase 1.5 步骤 7,**默认不跑**):真实 driver + 真实 AgentRuntime + 真实 model adapter。
  3. * 用 `describe.skipIf` 按环境变量 `ZCODE_WORKFLOW_LIVE_TEST` 门控——缺省整块跳过,`pnpm test` 保持确定性。
  4. *
  5. * 如何运行:
  6. * ZCODE_WORKFLOW_LIVE_TEST=1 pnpm --filter @zcode/bootstrap exec vitest run tests/workflow-driver.live.test.ts
  7. * 凭据与模型直接取自本机 v2 配置(~/.zcode/v2/config.json + setting.json)里活跃的 provider——见
  8. * resolveV2ModelConfig。无需额外 env(可选 ZCODE_WORKFLOW_LIVE_MODEL 覆盖模型 id)。若本机无 v2
  9. * 配置或活跃 provider 无内联 apiKey,则整块跳过。
  10. *
  11. * 覆盖真模型才能验证的东西(phase 1 用 fake driver 无法证):真实 submit 的 schema 一致性、
  12. * repair 在预算 3 内的修复效力、nudge 行为、以及 resume over a live-model journal with zero dispatches。
  13. * 第二个 describe 块把覆盖面扩到工作流形态:顺序流水线、并行 fan-out+join、数据依赖分支、
  14. * 同 actor 上下文延续、反馈驱动循环、world-read 喂 ask。
  15. */
  16. import { appendFileSync, existsSync, readFileSync } from "node:fs";
  17. import { homedir } from "node:os";
  18. import { join } from "node:path";
  19. import { describe, expect, it } from "vitest";
  20. import { createTestAgentRuntime } from "./helpers/test-agent-runtime.js";
  21. import { createInMemorySessionEventStore } from "@zcode/adapters/storage";
  22. import { parseModelRef, type RuntimeModelConfig } from "@zcode/contracts";
  23. import { AgentRuntime } from "@zcode/core";
  24. import { InMemoryJournalStore, inputHash } from "@zcode/dynamic-workflow";
  25. import { createModelAdapter } from "../src/index.js";
  26. import { workflowActorToolPolicy } from "../src/app/workflow-actor-tools.js";
  27. import { fakeFileSystemPort, runDriverScript, type PlannedResponse } from "./workflow-driver.helpers.js";
  28. import type { ActorRuntimeFactory } from "../src/app/workflow-driver.js";
  29. /**
  30. * 直接读取本机 v2 配置(~/.zcode/v2/config.json + setting.json)解析出活跃 provider 的凭据与模型,
  31. * 构造 RuntimeModelConfig 注入 createModelAdapter —— 镜像生产里桌面经协议下发 bootstrapModelConfig
  32. * 的做法。CLI 的 createConfig 只读已废弃的 v1 ~/.zcode/cli/config.json,不认 v2 provider map(v2 的
  33. * 原生解析在桌面 @zcode/services,按协议边界不被 CLI 依赖),所以这里让 live 测试自解析 v2 并注入
  34. * modelConfig,而不是依赖那条会落到 v1 空配置的 fallback。测试专用,只读不写,绝不落盘或打印密钥。
  35. * 可用 ZCODE_WORKFLOW_LIVE_MODEL 覆盖模型 id。
  36. */
  37. interface ResolvedLiveModel {
  38. modelConfig: RuntimeModelConfig;
  39. modelRef: string;
  40. }
  41. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  42. function resolveV2ModelConfig(): ResolvedLiveModel | undefined {
  43. const configPath = join(homedir(), ".zcode", "v2", "config.json");
  44. if (!existsSync(configPath)) return undefined;
  45. let providers: Record<string, any>;
  46. try {
  47. providers = JSON.parse(readFileSync(configPath, "utf8")).provider ?? {};
  48. } catch {
  49. return undefined;
  50. }
  51. const providerId = pickActiveProviderId(providers);
  52. if (providerId === undefined) return undefined;
  53. const p = providers[providerId];
  54. const apiKey: string | undefined = p?.options?.apiKey;
  55. if (!apiKey) return undefined; // 无内联 key(如 oauth-only family):跳过,本 live 测试只覆盖 apiKey provider。
  56. const modelId: string | undefined = process.env.ZCODE_WORKFLOW_LIVE_MODEL ?? Object.keys(p.models ?? {})[0];
  57. if (!modelId) return undefined;
  58. return {
  59. modelConfig: { main: { kind: p.kind, provider: providerId, model: modelId, apiKey, baseURL: p?.options?.baseURL } },
  60. modelRef: `${providerId}/${modelId}`,
  61. };
  62. }
  63. /** 活跃 provider:优先 setting.json 的 family 选择,否则取 enabled 且带 apiKey 的第一个。 */
  64. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  65. function pickActiveProviderId(providers: Record<string, any>): string | undefined {
  66. const settingPath = join(homedir(), ".zcode", "v2", "setting.json");
  67. if (existsSync(settingPath)) {
  68. try {
  69. const s = JSON.parse(readFileSync(settingPath, "utf8"));
  70. const key: unknown = s.modelProviderFamilySelectedKeys?.[s.providerFamilyDomain];
  71. // key 形如 "preset:builtin:bigmodel" / "coding-plan:builtin:zai-coding-plan":取首个冒号后的 provider id。
  72. if (typeof key === "string") {
  73. const id = key.slice(key.indexOf(":") + 1);
  74. if (providers[id]?.options?.apiKey) return id;
  75. }
  76. } catch {
  77. /* 落到下面的 enabled+key 兜底 */
  78. }
  79. }
  80. for (const [id, p] of Object.entries(providers)) {
  81. if (p?.enabled !== false && typeof p?.options?.apiKey === "string" && p.options.apiKey.length > 0) return id;
  82. }
  83. return undefined;
  84. }
  85. const RESOLVED = process.env.ZCODE_WORKFLOW_LIVE_TEST ? resolveV2ModelConfig() : undefined;
  86. const LIVE = Boolean(RESOLVED);
  87. /**
  88. * ZCODE_WORKFLOW_LIVE_TRANSCRIPT=<path>:把每次模型请求/应答以 JSONL 追加到该文件,供人工/agent
  89. * 复核真实会话是否合理(schema 尾注、submit 载荷、feedback 线程化、同 actor 上下文延续)。
  90. * 请求体不含凭据(key 在 adapter 闭包里);仅调试用,缺省关闭、零开销。
  91. */
  92. function withTranscript<T>(adapter: T): T {
  93. const path = process.env.ZCODE_WORKFLOW_LIVE_TRANSCRIPT;
  94. if (!path) return adapter;
  95. let seq = 0;
  96. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  97. const base = adapter as any;
  98. const write = (entry: Record<string, unknown>) =>
  99. appendFileSync(path, `${JSON.stringify({ seq: ++seq, at: new Date().toISOString(), ...entry })}\n`);
  100. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  101. const slim = (req: any) => ({
  102. model: req?.model,
  103. toolNames: req?.tools?.map((t: { name: string }) => t.name),
  104. toolChoice: req?.toolChoice,
  105. messages: req?.messages,
  106. });
  107. const wrapped = Object.create(base);
  108. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  109. wrapped.generateText = async (req: any) => {
  110. const res = await base.generateText(req);
  111. write({
  112. kind: "generateText",
  113. request: slim(req),
  114. response: { finishReason: res?.finishReason, text: res?.text, toolCalls: res?.toolCalls, usage: res?.usage },
  115. });
  116. return res;
  117. };
  118. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  119. wrapped.streamText = (req: any) => {
  120. const inner = base.streamText(req);
  121. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  122. const events: any[] = [];
  123. async function* logged() {
  124. try {
  125. for await (const e of inner) {
  126. events.push(e);
  127. yield e;
  128. }
  129. } finally {
  130. write({ kind: "streamText", request: slim(req), events });
  131. }
  132. }
  133. return logged();
  134. };
  135. return wrapped as T;
  136. }
  137. /** 真实 model adapter 支撑的 runtime 工厂(每 actor 一个持久 child runtime);注入 v2 modelConfig。 */
  138. function liveRuntimeFactory(resolved: ResolvedLiveModel): ActorRuntimeFactory {
  139. const modelAdapter = withTranscript(
  140. createModelAdapter({
  141. env: process.env,
  142. appVersion: "wf-live-test",
  143. modelConfig: resolved.modelConfig,
  144. }),
  145. );
  146. const modelRef = parseModelRef(resolved.modelRef);
  147. const fileSystemPort = fakeFileSystemPort({});
  148. return ({ sessionId, persona, submitPort }) =>
  149. createTestAgentRuntime(
  150. sessionId,
  151. {
  152. systemPrompt: persona.system ?? "You are a workflow actor. Follow the instructions precisely.",
  153. mode: "yolo",
  154. taskType: "workflow_child",
  155. subagents: { enabled: false },
  156. modelRef,
  157. // actor 的工具面:全集减去会悬挂/越权的交互工具。
  158. ...workflowActorToolPolicy(),
  159. },
  160. {
  161. eventStore: createInMemorySessionEventStore(),
  162. modelAdapter,
  163. workflowSubmitPort: submitPort,
  164. fileSystemPort,
  165. },
  166. );
  167. }
  168. const noScripts: Record<string, PlannedResponse[]> = {};
  169. describe.skipIf(!LIVE)("workflow driver — LIVE (env-gated)", () => {
  170. it(
  171. "a real model submits a schema-conforming result and the run completes",
  172. async () => {
  173. const script = [
  174. "interface Summary { title: string; bullet_points: string[]; }",
  175. 'const worker = agent("worker", "You summarize short texts into a title and bullet points.");',
  176. 'const s = await worker.ask<Summary>("Summarize: The cat sat on the mat, then chased a mouse.");',
  177. "return s;",
  178. ].join("\n");
  179. const { settlement, journal } = await runDriverScript(script, {
  180. actorScripts: noScripts,
  181. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  182. timeoutMs: 120_000,
  183. });
  184. expect(settlement.status).toBe("completed");
  185. const node = journal.getNode("run", "ask#1", 1);
  186. expect(node?.status).toBe("completed");
  187. const result = node?.result as { title?: unknown; bullet_points?: unknown } | undefined;
  188. expect(typeof result?.title).toBe("string");
  189. expect(Array.isArray(result?.bullet_points)).toBe(true);
  190. },
  191. 130_000,
  192. );
  193. it(
  194. "resumes over a live-model journal with zero dispatches",
  195. async () => {
  196. const script = [
  197. "interface Answer { value: number; }",
  198. 'const a = await agent("mathy", "You do arithmetic.").ask<Answer>("What is 21 + 21? Return the number.");',
  199. "return a;",
  200. ].join("\n");
  201. const journal = new InMemoryJournalStore();
  202. const first = await runDriverScript(script, {
  203. journal,
  204. actorScripts: noScripts,
  205. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  206. timeoutMs: 120_000,
  207. });
  208. expect(first.settlement.status).toBe("completed");
  209. // Resume:复用 journal,工厂设为「被调用即抛错」以硬断言零派发。
  210. let dispatched = false;
  211. const throwingFactory: ActorRuntimeFactory = (input) => {
  212. dispatched = true;
  213. return liveRuntimeFactory(RESOLVED!)(input);
  214. };
  215. const resumed = await runDriverScript(script, {
  216. journal,
  217. actorScripts: noScripts,
  218. runtimeFactory: throwingFactory,
  219. timeoutMs: 30_000,
  220. });
  221. expect(resumed.settlement).toEqual(first.settlement);
  222. expect(dispatched).toBe(false);
  223. },
  224. 140_000,
  225. );
  226. });
  227. /**
  228. * 模式覆盖(live):真实模型跑「工作流形态」而非单点 ask——顺序流水线、并行 fan-out+join、
  229. * 数据依赖分支、同 actor 多 ask 的上下文延续、反馈驱动的循环、world-read 喂给真实 ask。
  230. * 断言优先押引擎性质(journal 结构、actorSeq、分支唯一性、结果自洽),少押模型答案;
  231. * 需要押模型时只押小学算术、明显情感这类几乎不会错的行为。
  232. */
  233. describe.skipIf(!LIVE)("workflow driver — LIVE workflow patterns (env-gated)", () => {
  234. it(
  235. "seq: threads one ask's typed output into the next actor's prompt",
  236. async () => {
  237. const script = [
  238. "interface Extracted { numbers: number[]; }",
  239. "interface Parity { even: boolean; }",
  240. 'const extractor = agent("extractor", "You extract integers from text.");',
  241. 'const e = await extractor.ask<Extracted>("Extract all the integers: there are 3 cats, 5 dogs and 14 birds.");',
  242. "const sum = e.numbers.reduce((a, b) => a + b, 0);",
  243. 'const checker = agent("checker", { system: "You answer arithmetic questions." });',
  244. "const p = await checker.ask<Parity>(`Is the number ${sum} even?`);",
  245. "return { sum, even: p.even };",
  246. ].join("\n");
  247. const { settlement, journal } = await runDriverScript(script, {
  248. actorScripts: noScripts,
  249. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  250. timeoutMs: 150_000,
  251. });
  252. expect(settlement.status).toBe("completed");
  253. if (settlement.status !== "completed") return;
  254. // 自洽:sum 由 ask#1 的 journal 产物重算,parity 是它的确定函数。
  255. const extracted = journal.getNode("run", "ask#1", 1)?.result as { numbers: number[] };
  256. expect(Array.isArray(extracted.numbers)).toBe(true);
  257. const sum = extracted.numbers.reduce((a, b) => a + b, 0);
  258. const artifact = settlement.artifact as { sum: number; even: boolean };
  259. expect(artifact.sum).toBe(sum);
  260. expect(artifact.even).toBe(sum % 2 === 0);
  261. // 线程化证明:ask#2 的 inputHash 等于「嵌入了 ask#1 产物」的 prompt 的哈希。
  262. expect(journal.getNode("run", "ask#2", 1)?.inputHash).toBe(inputHash(`Is the number ${sum} even?`));
  263. },
  264. 170_000,
  265. );
  266. it(
  267. "parallel: fans out over Promise.all onto fresh actors, then reduces via an aggregator ask",
  268. async () => {
  269. const script = [
  270. "interface Value { value: number; }",
  271. "interface Total { total: number; }",
  272. 'const problems = ["2 + 3", "10 + 4", "7 + 6"];',
  273. "const values = await Promise.all(",
  274. ' problems.map((p) => agent("solver").ask<Value>(`Compute ${p} and return the value.`)),',
  275. ");",
  276. "const nums = values.map((v) => v.value);",
  277. 'const agg = await agent("aggregator", { system: "You add numbers." })',
  278. " .ask<Total>(`Add these numbers: ${nums.join(\", \")}. Return the total.`);",
  279. "return { nums, total: agg.total };",
  280. ].join("\n");
  281. const { settlement, journal, events } = await runDriverScript(script, {
  282. actorScripts: noScripts,
  283. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  284. timeoutMs: 180_000,
  285. });
  286. expect(settlement.status).toBe("completed");
  287. if (settlement.status !== "completed") return;
  288. // fan-out:ask#1 三个实例(各自新 actor)+ aggregator,共 4 个 ask 节点、4 个 actor。
  289. const askNodes = journal
  290. .listNodes("run", { kinds: "all", withResult: true })
  291. .filter((n) => n.kind === "ask");
  292. expect(askNodes).toHaveLength(4);
  293. expect(askNodes.every((n) => n.status === "completed")).toBe(true);
  294. expect(events.filter((e) => e.type === "actor-created")).toHaveLength(4);
  295. const artifact = settlement.artifact as { nums: number[]; total: number };
  296. expect(artifact.nums).toEqual([5, 14, 13]);
  297. expect(artifact.total).toBe(32);
  298. // 自洽(与绝对值互为冗余):total 等于三个 fan-out journal 产物之和。
  299. const fanned = askNodes
  300. .filter((n) => n.siteId === "ask#1")
  301. .map((n) => (n.result as { value: number }).value);
  302. expect(fanned).toHaveLength(3);
  303. expect(fanned.reduce((a, b) => a + b, 0)).toBe(artifact.total);
  304. },
  305. 200_000,
  306. );
  307. it(
  308. "control: branches on a typed enum verdict; only the taken branch's ask is journaled",
  309. async () => {
  310. const script = [
  311. 'interface Verdict { sentiment: "positive" | "negative"; }',
  312. 'const judge = agent("judge", { system: "You classify sentiment." });',
  313. 'const v = await judge.ask<Verdict>("Classify the sentiment: I absolutely love this product, it works perfectly.");',
  314. 'if (v.sentiment === "positive") {',
  315. ' const cheer = await agent("fan").ask("Reply with one short cheerful sentence.");',
  316. " return { sentiment: v.sentiment, reply: cheer };",
  317. "}",
  318. 'const sigh = await agent("consoler").ask("Reply with one short consoling sentence.");',
  319. "return { sentiment: v.sentiment, reply: sigh };",
  320. ].join("\n");
  321. const { settlement, journal } = await runDriverScript(script, {
  322. actorScripts: noScripts,
  323. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  324. timeoutMs: 150_000,
  325. });
  326. expect(settlement.status).toBe("completed");
  327. if (settlement.status !== "completed") return;
  328. // enum schema 一致性:真实提交落在字面量并集内。
  329. const verdictNode = journal.getNode("run", "ask#1", 1);
  330. const verdict = (verdictNode?.result as { sentiment: string } | undefined)?.sentiment;
  331. expect(["positive", "negative"]).toContain(verdict);
  332. // 分支唯一性:恰好执行了 verdict 对应的那一支(不押 verdict 本身)。
  333. expect(journal.getNode("run", "ask#2", 1) !== undefined).toBe(verdict === "positive");
  334. expect(journal.getNode("run", "ask#3", 1) !== undefined).toBe(verdict === "negative");
  335. // 分支 ask 是 untyped:从真实 turn 的 final text 结算出非空字符串。
  336. const artifact = settlement.artifact as { sentiment: string; reply: string };
  337. expect(artifact.sentiment).toBe(verdict);
  338. expect(typeof artifact.reply).toBe("string");
  339. expect(artifact.reply.length).toBeGreaterThan(0);
  340. },
  341. 170_000,
  342. );
  343. it(
  344. "actor context: a second ask on the same actor recalls facts from the first (FIFO, one runtime)",
  345. async () => {
  346. // 码字只出现在 ask#1 的 prompt;ask#2 能答出它的唯一途径是持久 child runtime 的会话历史。
  347. const script = [
  348. "interface Ack { ok: boolean; }",
  349. "interface Recall { codeword: string; }",
  350. 'const keeper = agent("keeper", "You remember facts from this conversation and answer recall questions.");',
  351. 'await keeper.ask<Ack>("Remember the codeword PLUM-42. Reply with ok=true.");',
  352. 'const r = await keeper.ask<Recall>("What codeword were you asked to remember earlier in this conversation? Return exactly that codeword.");',
  353. "return r;",
  354. ].join("\n");
  355. const { settlement, journal, events } = await runDriverScript(script, {
  356. actorScripts: noScripts,
  357. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  358. timeoutMs: 150_000,
  359. });
  360. expect(settlement.status).toBe("completed");
  361. if (settlement.status !== "completed") return;
  362. expect((settlement.artifact as { codeword: string }).codeword).toContain("PLUM-42");
  363. // 同一 actor 站点上的串行两问:单 actor、actorSeq 0 → 1。
  364. expect(events.filter((e) => e.type === "actor-created")).toHaveLength(1);
  365. const first = journal.getNode("run", "ask#1", 1);
  366. const second = journal.getNode("run", "ask#2", 1);
  367. expect(first?.actorSiteId).toBe("actor#1");
  368. expect(second?.actorSiteId).toBe("actor#1");
  369. expect(first?.actorSeq).toBe(0);
  370. expect(second?.actorSeq).toBe(1);
  371. },
  372. 170_000,
  373. );
  374. it(
  375. "loop: a feedback-driven loop converges — each round threads script feedback into the next ask",
  376. async () => {
  377. // 秘密数写死在脚本里(7);反馈(too low/too high)由脚本代码生成并嵌入下一轮 prompt。
  378. // 有反馈的猜数对任何可用模型 ≤6 轮必收敛(二分 4 轮),收敛性可押。
  379. const script = [
  380. "interface Guess { value: number; }",
  381. 'const guesser = agent("guesser", { system: "You guess integers, using the feedback on your earlier guesses." });',
  382. 'let feedback = "none yet";',
  383. "let found = -1;",
  384. "let rounds = 0;",
  385. "for (let i = 0; i < 6 && found === -1; i++) {",
  386. " rounds = i + 1;",
  387. " const g = await guesser.ask<Guess>(`Guess the secret integer between 1 and 10. Feedback on your previous guess: ${feedback}.`);",
  388. " if (g.value === 7) { found = g.value; }",
  389. " else { feedback = g.value < 7 ? `${g.value} is too low` : `${g.value} is too high`; }",
  390. "}",
  391. "return { found, rounds };",
  392. ].join("\n");
  393. const { settlement, journal, events } = await runDriverScript(script, {
  394. actorScripts: noScripts,
  395. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  396. timeoutMs: 300_000,
  397. });
  398. expect(settlement.status).toBe("completed");
  399. if (settlement.status !== "completed") return;
  400. const artifact = settlement.artifact as { found: number; rounds: number };
  401. expect(artifact.found).toBe(7);
  402. expect(artifact.rounds).toBeGreaterThanOrEqual(1);
  403. expect(artifact.rounds).toBeLessThanOrEqual(6);
  404. // 同一 ask 站点的第 N 轮 = 实例 N,全部 completed,串行落在同一 actor 上(actorSeq 递增)。
  405. const askNodes = journal
  406. .listNodes("run", { kinds: "all", withResult: true })
  407. .filter((n) => n.kind === "ask");
  408. expect(askNodes).toHaveLength(artifact.rounds);
  409. expect(askNodes.every((n) => n.status === "completed" && n.actorSiteId === "actor#1")).toBe(
  410. true,
  411. );
  412. expect(events.filter((e) => e.type === "actor-created")).toHaveLength(1);
  413. expect(journal.getNode("run", "ask#1", artifact.rounds)?.actorSeq).toBe(artifact.rounds - 1);
  414. }, 320_000);
  415. it(
  416. "world reads: file content read by the harness is consumed by a live typed ask",
  417. async () => {
  418. const script = [
  419. "interface Config { port: number; }",
  420. 'const text = await files.read("config/server.txt");',
  421. 'const parser = agent("parser", { system: "You extract fields from configuration text." });',
  422. "const c = await parser.ask<Config>(`In the following config, what is the port?\\n${text}`);",
  423. "return c;",
  424. ].join("\n");
  425. const content = "host = example.com\nport = 4823\ntimeout = 30\n";
  426. const { settlement, journal } = await runDriverScript(script, {
  427. actorScripts: noScripts,
  428. runtimeFactory: liveRuntimeFactory(RESOLVED!),
  429. files: { read: content },
  430. timeoutMs: 130_000,
  431. });
  432. expect(settlement.status).toBe("completed");
  433. if (settlement.status !== "completed") return;
  434. // world-read 照常落 journal;真实模型从被嵌入 prompt 的文件内容里抽出字段。
  435. expect(journal.getNode("run", "world-read#1", 1)?.result).toBe(content);
  436. expect((settlement.artifact as { port: number }).port).toBe(4823);
  437. },
  438. 150_000,
  439. );
  440. });