dynamic-workflow-run-progress.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. // dwf run 进度的**出回合追加**(out-of-turn append):run 事件到达时父会话可能正在跑一个
  2. // 回合,也可能完全空闲,两种都必须落地。见 docs/dynamic-workflow/presentation.md「The run state the pane draws」。
  3. //
  4. // 为什么需要 runtime 上的一个公共方法:BackgroundTask* 走的是 core 内部
  5. // (tool executor 的 deps.emitEvent → runtime.appendEvent),而 dwf 的事件源在 bootstrap 的
  6. // run service 里,那一层拿不到 AgentRuntimeInternal。既有的同形先例是 recordTargetChanged
  7. // (bootstrap 的 session-facade 就那样出回合追加 TargetChanged)。
  8. import { describe, expect, it, vi } from "vitest";
  9. import {
  10. SessionEventType,
  11. createSessionId,
  12. createToolCallId,
  13. type SessionEvent,
  14. } from "@zcode/contracts";
  15. import { AgentRuntime } from "../src/index.js";
  16. import { createTestSessionEventStore } from "./test-event-store.js";
  17. function makeRuntime(name: string): { runtime: AgentRuntime; events: SessionEvent[] } {
  18. const runtime = new AgentRuntime(
  19. createSessionId(name),
  20. { agentName: "dwf-progress-test", workingDirectory: "/tmp/zcode-dwf-progress" },
  21. { eventStore: createTestSessionEventStore(), modelAdapter: {} as never },
  22. );
  23. const events: SessionEvent[] = [];
  24. runtime.subscribeEvents({ onSessionEvent: (event) => events.push(event) });
  25. return { runtime, events };
  26. }
  27. const progress = {
  28. runId: "dwfrun-1",
  29. sequence: 3,
  30. eventType: "node-dispatched",
  31. payload: { instance: { siteId: "ask#1", ordinal: 1 } },
  32. };
  33. describe("recordDynamicWorkflowRunProgress", () => {
  34. it("会话空闲时也能追加(run 事件不等回合)", async () => {
  35. const { runtime, events } = makeRuntime("dwf-progress-idle");
  36. expect(runtime.getActiveTurnInfo()).toBeUndefined();
  37. await runtime.recordDynamicWorkflowRunProgress(progress);
  38. const appended = events.filter(
  39. (event) => event.type === SessionEventType.DynamicWorkflowRunProgress,
  40. );
  41. expect(appended).toHaveLength(1);
  42. expect(appended[0]?.payload).toEqual(progress);
  43. // 空闲期追加的事件不冒领任何回合:turnId 必须为空,否则冷恢复会把它塞进上一轮的尾巴。
  44. expect(appended[0]?.turnId).toBeUndefined();
  45. });
  46. it("事件经 event store 补号后才发布(live 与 replay 共用同一套顺序事实)", async () => {
  47. const { runtime, events } = makeRuntime("dwf-progress-seq");
  48. await runtime.recordDynamicWorkflowRunProgress(progress);
  49. await runtime.recordDynamicWorkflowRunProgress({ ...progress, sequence: 4 });
  50. const appended = events.filter(
  51. (event) => event.type === SessionEventType.DynamicWorkflowRunProgress,
  52. );
  53. expect(appended.map((event) => event.sequenceNumber)).toEqual([1, 2]);
  54. // 载荷里的 sequence 是 **journal** sequence,与会话事件的 sequenceNumber 是两把不同的尺。
  55. expect(appended.map((event) => (event.payload as typeof progress).sequence)).toEqual([3, 4]);
  56. });
  57. it("toolCallId 透传(工具卡 → 详情页的关联键)", async () => {
  58. const { runtime, events } = makeRuntime("dwf-progress-toolcall");
  59. const toolCallId = createToolCallId("create-workflow-call");
  60. await runtime.recordDynamicWorkflowRunProgress({ ...progress, toolCallId });
  61. const appended = events.find(
  62. (event) => event.type === SessionEventType.DynamicWorkflowRunProgress,
  63. );
  64. expect((appended?.payload as { toolCallId?: string }).toolCallId).toBe(toolCallId);
  65. });
  66. });
  67. // ————————————————————————————————————————————————
  68. // run 中的升级通知(apps/zcode-cli/packages/dynamic-workflow/docs/execution-engine.md「How progress and completion reach the app and the main agent」)。
  69. //
  70. // 这是主代理**唯一**会主动收到的「有人在等你」的信号:actor 停驻在自己那次 escalate 调用上,
  71. // 没有超时会替它兜底。所以三件事被钉死:恰好一条通知、载有 qid 与逐字的下一步、
  72. // escalation-resolved 不再发第二条(作答方就是主代理自己,回执已经是那次工具调用的结果)。
  73. // ————————————————————————————————————————————————
  74. interface CapturedEscalationMeta {
  75. kind: "escalation";
  76. qid: string;
  77. actor: string;
  78. question: string;
  79. context?: string;
  80. askedAt?: number;
  81. }
  82. interface CapturedNotification {
  83. text: string;
  84. taskId?: string;
  85. originMeta?: {
  86. backgroundSource?: string;
  87. title?: string;
  88. workId?: string;
  89. workflowNotification?: CapturedEscalationMeta;
  90. };
  91. }
  92. /** 通知在 runtime 上产出(enqueueBackgroundTaskNotification 是原型方法),实例桩即可截获。 */
  93. function captureNotifications(runtime: AgentRuntime): CapturedNotification[] {
  94. const captured: CapturedNotification[] = [];
  95. (runtime as unknown as { enqueueBackgroundTaskNotification: (n: CapturedNotification) => void })
  96. .enqueueBackgroundTaskNotification = (notification) => {
  97. captured.push(notification);
  98. };
  99. return captured;
  100. }
  101. const raised = {
  102. runId: "dwfrun-esc",
  103. sequence: 7,
  104. eventType: "escalation-raised",
  105. payload: {
  106. qid: "dwfq-esc12345-1",
  107. actor: { siteId: "actor#1", ordinal: 2 },
  108. actorName: "implementer",
  109. question: "评分上限是 95,通过线是 96,这个门不可能过。",
  110. context: "已经试了 6 轮,最高 95。",
  111. },
  112. };
  113. describe("escalation-raised → run 中通知", () => {
  114. it("恰好一条通知,载 qid、问题、上下文与逐字的下一步", async () => {
  115. const { runtime } = makeRuntime("dwf-progress-escalation");
  116. const captured = captureNotifications(runtime);
  117. await runtime.recordDynamicWorkflowRunProgress(raised);
  118. expect(captured).toHaveLength(1);
  119. const text = captured[0]?.text ?? "";
  120. expect(text).toContain("dwfq-esc12345-1");
  121. expect(text).toContain("评分上限是 95,通过线是 96,这个门不可能过。");
  122. expect(text).toContain("已经试了 6 轮,最高 95。");
  123. // 逐字的下一步:模型读完这条通知就该知道要调哪个工具、传什么。
  124. expect(text).toContain('ResolveWorkflowQuestion with question_id="dwfq-esc12345-1"');
  125. // run 没有停:缺了这句,模型会以为整条工作流在等它,从而放下手上一切事。
  126. expect(text).toContain("The run is still running");
  127. // 通知丢弃后的查询兜底(GetWorkflowRun 的 pendingQuestions)。
  128. expect(text).toContain("GetWorkflowRun");
  129. // 合成 user 消息不得被误读成用户发言。
  130. expect(text).toContain("[SYSTEM NOTIFICATION - NOT USER INPUT]");
  131. });
  132. it("actorName 在场时用人名;匿名 actor 落到结构化 ref site@ordinal", async () => {
  133. const { runtime } = makeRuntime("dwf-progress-escalation-actor");
  134. const captured = captureNotifications(runtime);
  135. await runtime.recordDynamicWorkflowRunProgress(raised);
  136. await runtime.recordDynamicWorkflowRunProgress({
  137. ...raised,
  138. sequence: 8,
  139. payload: { ...raised.payload, actorName: undefined, qid: "dwfq-esc12345-2" },
  140. });
  141. expect(captured[0]?.text).toContain("implementer");
  142. // 引擎刻意不合成兜底标签(匿名 actor 缺席 actorName),渲染兜底在读侧。
  143. expect(captured[1]?.text).toContain("actor#1@2");
  144. });
  145. it("展示名走 registry 的 description,缺席时回落到 runId", async () => {
  146. const { runtime } = makeRuntime("dwf-progress-escalation-label");
  147. const captured = captureNotifications(runtime);
  148. // registry 里没有这个 run(还没登记 / 已退场)→ 展示名回落到 runId,绝不留空。
  149. await runtime.recordDynamicWorkflowRunProgress(raised);
  150. expect(captured[0]?.text).toContain("dwfrun-esc");
  151. expect(captured[0]?.originMeta).toEqual({
  152. backgroundSource: "workflow",
  153. title: "dwfrun-esc",
  154. // workId ≡ runId:与该 run 的终态通知同一个展示锚点。
  155. workId: "dwfrun-esc",
  156. // manifest 载荷(escalation 判别分支)随 originMeta 走全管线。
  157. workflowNotification: {
  158. kind: "escalation",
  159. qid: "dwfq-esc12345-1",
  160. actor: "implementer",
  161. question: "评分上限是 95,通过线是 96,这个门不可能过。",
  162. context: "已经试了 6 轮,最高 95。",
  163. },
  164. });
  165. expect(captured[0]?.taskId).toBe("dwfrun-esc");
  166. });
  167. it("manifest 载荷:qid/actor/question/context/askedAt 同源,缺 askedAt 即字段缺席", async () => {
  168. const { runtime } = makeRuntime("dwf-progress-escalation-manifest");
  169. const captured = captureNotifications(runtime);
  170. // askedAt 在场:作为数字直读进载荷(stringField 读不出数字)。
  171. await runtime.recordDynamicWorkflowRunProgress({
  172. ...raised,
  173. payload: { ...raised.payload, askedAt: 1_725_000_000_000 },
  174. });
  175. // askedAt 缺席:整字段缺席,不置 0。
  176. await runtime.recordDynamicWorkflowRunProgress({
  177. ...raised,
  178. sequence: 8,
  179. payload: { ...raised.payload, qid: "dwfq-esc12345-9" },
  180. });
  181. expect(captured[0]?.originMeta?.workflowNotification).toEqual({
  182. kind: "escalation",
  183. qid: "dwfq-esc12345-1",
  184. actor: "implementer",
  185. question: "评分上限是 95,通过线是 96,这个门不可能过。",
  186. context: "已经试了 6 轮,最高 95。",
  187. askedAt: 1_725_000_000_000,
  188. });
  189. expect(captured[1]?.originMeta?.workflowNotification?.askedAt).toBeUndefined();
  190. expect(captured[1]?.originMeta?.workflowNotification?.qid).toBe("dwfq-esc12345-9");
  191. });
  192. it("匿名 actor 的载荷 actor 落到结构化 ref site@ordinal(与通知文本同一条兜底链)", async () => {
  193. const { runtime } = makeRuntime("dwf-progress-escalation-manifest-anon");
  194. const captured = captureNotifications(runtime);
  195. await runtime.recordDynamicWorkflowRunProgress({
  196. ...raised,
  197. payload: { ...raised.payload, actorName: undefined },
  198. });
  199. expect(captured[0]?.originMeta?.workflowNotification?.actor).toBe("actor#1@2");
  200. });
  201. it("超界 question/context 在发射侧就地截断到 ≤4000(shared schema 同界)", async () => {
  202. const { runtime } = makeRuntime("dwf-progress-escalation-manifest-cap");
  203. const captured = captureNotifications(runtime);
  204. const longQuestion = "问".repeat(5_000);
  205. const longContext = "境".repeat(5_000);
  206. await runtime.recordDynamicWorkflowRunProgress({
  207. ...raised,
  208. payload: { ...raised.payload, question: longQuestion, context: longContext },
  209. });
  210. const meta = captured[0]?.originMeta?.workflowNotification;
  211. expect(meta?.question.length).toBe(4_000);
  212. expect(meta?.context?.length).toBe(4_000);
  213. });
  214. it("escalation-resolved 不产生通知(主代理就是作答方,回执已在工具结果里)", async () => {
  215. const { runtime, events } = makeRuntime("dwf-progress-escalation-resolved");
  216. const captured = captureNotifications(runtime);
  217. await runtime.recordDynamicWorkflowRunProgress({
  218. runId: "dwfrun-esc",
  219. sequence: 9,
  220. eventType: "escalation-resolved",
  221. payload: { qid: "dwfq-esc12345-1", answer: "按 95 通过。" },
  222. });
  223. expect(captured).toHaveLength(0);
  224. // 事件本身照常落库(GUI 的事件日志要渲染它)——不发通知与不记事件是两件事。
  225. expect(
  226. events.filter((event) => event.type === SessionEventType.DynamicWorkflowRunProgress),
  227. ).toHaveLength(1);
  228. });
  229. it("其他 run 事件不产生通知", async () => {
  230. const { runtime } = makeRuntime("dwf-progress-escalation-other");
  231. const captured = captureNotifications(runtime);
  232. await runtime.recordDynamicWorkflowRunProgress(progress);
  233. expect(captured).toHaveLength(0);
  234. });
  235. it("载荷缺 qid 或 question 时跳过通知,但事件照常落库", async () => {
  236. const { runtime, events } = makeRuntime("dwf-progress-escalation-malformed");
  237. const captured = captureNotifications(runtime);
  238. const logged = vi.fn();
  239. (runtime as unknown as { logger?: unknown }).logger = {
  240. debug: vi.fn(),
  241. info: vi.fn(),
  242. error: vi.fn(),
  243. warn: logged,
  244. };
  245. await runtime.recordDynamicWorkflowRunProgress({
  246. ...raised,
  247. payload: { actor: { siteId: "actor#1", ordinal: 1 } },
  248. });
  249. // 进度面是观察面:载荷形状不对只跳过通知并留痕,绝不打挂一个正在跑的 run。
  250. expect(captured).toHaveLength(0);
  251. expect(logged).toHaveBeenCalledTimes(1);
  252. expect(
  253. events.filter((event) => event.type === SessionEventType.DynamicWorkflowRunProgress),
  254. ).toHaveLength(1);
  255. });
  256. });
  257. // ————————————————————————————————————————————————
  258. // run 级停滞(apps/zcode-cli/packages/dynamic-workflow/docs/execution-engine.md「Terminal states」):`run-stalled` → 一条 run 中通知。
  259. // ————————————————————————————————————————————————
  260. const stalled = {
  261. runId: "dwfrun-stall",
  262. sequence: 11,
  263. eventType: "run-stalled",
  264. payload: { sinceMs: 1_200_000, reason: "rate_limited", cap: 2 },
  265. };
  266. describe("run-stalled → run 中通知", () => {
  267. it("恰好一条通知:run 仍在跑、不需要模型做什么、不要取消或重建", async () => {
  268. const { runtime } = makeRuntime("dwf-progress-stall");
  269. const captured = captureNotifications(runtime);
  270. await runtime.recordDynamicWorkflowRunProgress(stalled);
  271. expect(captured).toHaveLength(1);
  272. const text = captured[0]?.text ?? "";
  273. expect(text).toContain("[SYSTEM NOTIFICATION - NOT USER INPUT]");
  274. expect(text).toContain("<workflow-stall>");
  275. expect(text).toContain("<since-ms>1200000</since-ms>");
  276. expect(text).toContain("<dominant-reason>rate_limited</dominant-reason>");
  277. expect(text).toContain("<cap>2</cap>");
  278. expect(text).toContain("has not completed a model request in 20 minutes");
  279. expect(text).toContain("rate_limited");
  280. expect(text).toContain("It is still running and needs nothing from you.");
  281. expect(text).toContain("Do not cancel or rebuild it on your own.");
  282. expect(captured[0]?.taskId).toBe("dwfrun-stall");
  283. expect(captured[0]?.originMeta).toEqual({
  284. backgroundSource: "workflow",
  285. title: "dwfrun-stall",
  286. workId: "dwfrun-stall",
  287. workflowNotification: { kind: "stall", sinceMs: 1_200_000, reason: "rate_limited", cap: 2 },
  288. });
  289. });
  290. it("reason / cap 缺席即字段缺席;sinceMs 形状不对则整条跳过", async () => {
  291. const { runtime } = makeRuntime("dwf-progress-stall-shape");
  292. const captured = captureNotifications(runtime);
  293. await runtime.recordDynamicWorkflowRunProgress({
  294. ...stalled,
  295. payload: { sinceMs: 1_500_000 },
  296. });
  297. expect(captured).toHaveLength(1);
  298. expect(captured[0]?.originMeta?.workflowNotification).toEqual({
  299. kind: "stall",
  300. sinceMs: 1_500_000,
  301. });
  302. expect(captured[0]?.text).toContain("the provider keeps failing requests");
  303. expect(captured[0]?.text).not.toContain("<cap>");
  304. await runtime.recordDynamicWorkflowRunProgress({
  305. ...stalled,
  306. sequence: 12,
  307. payload: { sinceMs: "soon" },
  308. });
  309. expect(captured).toHaveLength(1);
  310. });
  311. });
  312. // ————————————————————————————————————————————————
  313. // 留白(docs/dynamic-workflow/transcript-and-notifications.md 的 `hole` 载荷与「What the model reads」):
  314. // `hole-reached` → 恰好一条 run 中通知,载荷从快照的 `holes[]` 补齐类型 / 行号 / 前后阶段,草稿路径
  315. // 来自快照的 `scriptPath`;`hole-filled` 不发通知(补全方就是主代理自己,回执已在工具结果里)。
  316. // ————————————————————————————————————————————————
  317. interface CapturedHoleMeta {
  318. kind: "hole";
  319. siteId: string;
  320. ordinal: number;
  321. name: string;
  322. type: string;
  323. prompt?: string;
  324. draftPath?: string;
  325. line?: number;
  326. before?: string;
  327. after?: string;
  328. reachedAt?: number;
  329. }
  330. const reached = {
  331. runId: "dwfrun-hole",
  332. sequence: 21,
  333. eventType: "hole-reached",
  334. payload: {
  335. instance: { siteId: "hole#1", ordinal: 1 },
  336. name: "决定分组",
  337. prompt: "把 7 个候选按风险分成两组。",
  338. phaseName: "收集",
  339. },
  340. };
  341. function attachHoleSnapshot(
  342. runtime: AgentRuntime,
  343. holes: unknown[] | undefined,
  344. scriptPath?: string,
  345. ): string[] {
  346. const calls: string[] = [];
  347. (runtime as unknown as { dynamicWorkflowRunPort: unknown }).dynamicWorkflowRunPort = {
  348. async getTask(runId: string) {
  349. calls.push(runId);
  350. return {
  351. runId,
  352. taskId: runId,
  353. status: "running",
  354. startedAt: new Date(0),
  355. ...(scriptPath === undefined ? {} : { scriptPath }),
  356. ...(holes === undefined ? {} : { holes }),
  357. };
  358. },
  359. };
  360. return calls;
  361. }
  362. describe("hole-reached → run 中通知", () => {
  363. const waiting = {
  364. siteId: "hole#1",
  365. ordinal: 1,
  366. name: "决定分组",
  367. type: "Verdict",
  368. state: "waiting",
  369. since: 1_725_000_000_000,
  370. line: 12,
  371. before: "收集",
  372. after: "汇总",
  373. };
  374. it("恰好一条通知,载荷从快照补齐,文本带逐字的下一步", async () => {
  375. const { runtime } = makeRuntime("dwf-progress-hole");
  376. const captured = captureNotifications(runtime);
  377. const calls = attachHoleSnapshot(
  378. runtime,
  379. [waiting],
  380. "/repo/.zcode/workflow-drafts/triage.dwf.ts",
  381. );
  382. await runtime.recordDynamicWorkflowRunProgress(reached);
  383. expect(calls).toEqual(["dwfrun-hole"]);
  384. expect(captured).toHaveLength(1);
  385. const meta = captured[0]?.originMeta?.workflowNotification as unknown as CapturedHoleMeta;
  386. expect(meta).toEqual({
  387. kind: "hole",
  388. siteId: "hole#1",
  389. ordinal: 1,
  390. name: "决定分组",
  391. type: "Verdict",
  392. prompt: "把 7 个候选按风险分成两组。",
  393. draftPath: "/repo/.zcode/workflow-drafts/triage.dwf.ts",
  394. line: 12,
  395. before: "收集",
  396. after: "汇总",
  397. reachedAt: 1_725_000_000_000,
  398. });
  399. expect(captured[0]?.taskId).toBe("dwfrun-hole");
  400. expect(captured[0]?.originMeta?.workId).toBe("dwfrun-hole");
  401. const text = captured[0]?.text ?? "";
  402. expect(text).toContain("[SYSTEM NOTIFICATION - NOT USER INPUT]");
  403. expect(text).toContain("<workflow-hole>");
  404. expect(text).toContain("<run-id>dwfrun-hole</run-id>");
  405. expect(text).toContain("<hole-id>hole#1</hole-id>");
  406. expect(text).toContain("<name>决定分组</name>");
  407. expect(text).toContain("<type>Verdict</type>");
  408. expect(text).toContain("<prompt>把 7 个候选按风险分成两组。</prompt>");
  409. expect(text).toContain("<draft>/repo/.zcode/workflow-drafts/triage.dwf.ts</draft>");
  410. expect(text).toContain("<line>12</line>");
  411. expect(text).toContain("<before>收集</before>");
  412. expect(text).toContain("<after>汇总</after>");
  413. // 逐字的下一步:读草稿、写函数体、带 hole_id 调 FillWorkflowHole。
  414. expect(text).toContain('FillWorkflowHole with run_id="dwfrun-hole" and hole_id="hole#1"');
  415. expect(text).toContain("Only this branch of the script is parked");
  416. expect(text).toContain("nothing times out");
  417. expect(text).toContain("compiled where the hole stands");
  418. expect(text).toContain("must return a value of type `Verdict`");
  419. expect(text).toContain("GetWorkflowRun");
  420. });
  421. it("快照缺席时仍发通知,只带载荷自己说得出的字段;prompt 超界截到 4000 并以 … 收尾", async () => {
  422. const { runtime } = makeRuntime("dwf-progress-hole-noport");
  423. const captured = captureNotifications(runtime);
  424. await runtime.recordDynamicWorkflowRunProgress({
  425. ...reached,
  426. payload: { ...reached.payload, prompt: "问".repeat(5_000) },
  427. });
  428. expect(captured).toHaveLength(1);
  429. const meta = captured[0]?.originMeta?.workflowNotification as unknown as CapturedHoleMeta;
  430. expect(meta.type).toBe("unknown");
  431. expect("draftPath" in meta).toBe(false);
  432. expect("line" in meta).toBe(false);
  433. expect(meta.prompt?.length).toBe(4_000);
  434. expect(meta.prompt?.endsWith("…")).toBe(true);
  435. expect(captured[0]?.text).not.toContain("<draft>");
  436. });
  437. it("hole-filled 不产生通知;载荷缺 name 时跳过并留痕,事件照常落库", async () => {
  438. const { runtime, events } = makeRuntime("dwf-progress-hole-filled");
  439. const captured = captureNotifications(runtime);
  440. const logged = vi.fn();
  441. (runtime as unknown as { logger?: unknown }).logger = {
  442. debug: vi.fn(),
  443. info: vi.fn(),
  444. error: vi.fn(),
  445. warn: logged,
  446. };
  447. await runtime.recordDynamicWorkflowRunProgress({
  448. runId: "dwfrun-hole",
  449. sequence: 22,
  450. eventType: "hole-filled",
  451. payload: { siteId: "hole#1", filledAt: 5, phaseNames: ["收集", "决定分组", "汇总"] },
  452. });
  453. await runtime.recordDynamicWorkflowRunProgress({
  454. ...reached,
  455. sequence: 23,
  456. payload: { instance: { siteId: "hole#1", ordinal: 2 } },
  457. });
  458. expect(captured).toHaveLength(0);
  459. expect(logged).toHaveBeenCalledTimes(1);
  460. expect(
  461. events.filter((event) => event.type === SessionEventType.DynamicWorkflowRunProgress),
  462. ).toHaveLength(2);
  463. });
  464. });
  465. // 递归留白:嵌套站点 id(`hole#1/hole#1`)在载荷与文本里逐字出现,模型才能原样抄回 FillWorkflowHole。
  466. describe("hole-reached → 嵌套 id 逐字透传", () => {
  467. it("载荷 siteId 与 <hole-id> / hole_id 都是嵌套 id 原文", async () => {
  468. const { runtime } = makeRuntime("dwf-progress-hole-nested");
  469. const captured = captureNotifications(runtime);
  470. attachHoleSnapshot(runtime, [
  471. {
  472. siteId: "hole#1/hole#1",
  473. ordinal: 1,
  474. name: "内层裁决",
  475. type: "Inner",
  476. state: "waiting",
  477. since: 7,
  478. },
  479. ]);
  480. await runtime.recordDynamicWorkflowRunProgress({
  481. ...reached,
  482. payload: { instance: { siteId: "hole#1/hole#1", ordinal: 1 }, name: "内层裁决" },
  483. });
  484. expect(captured).toHaveLength(1);
  485. const meta = captured[0]?.originMeta?.workflowNotification as unknown as CapturedHoleMeta;
  486. expect(meta).toMatchObject({
  487. kind: "hole",
  488. siteId: "hole#1/hole#1",
  489. type: "Inner",
  490. reachedAt: 7,
  491. });
  492. const text = captured[0]?.text ?? "";
  493. expect(text).toContain("<hole-id>hole#1/hole#1</hole-id>");
  494. expect(text).toContain('hole_id="hole#1/hole#1"');
  495. });
  496. });