dynamic-workflow-run-sequence-capture.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // 序号捕获层(引擎拿到的 journal)必须把读面选项原样转发(docs/execution-engine.md「Reading the
  2. // journal」):TS 允许实现的形参比签名少,写成固定选项照样编译通过,引擎的窄读就会悄悄退化回
  3. // 整表读——这条测试钉住每一条读的选项都到达了真 store。
  4. import { describe, expect, it } from "vitest";
  5. import { InMemoryJournalStore } from "@zcode/dynamic-workflow";
  6. import { createJournalSequenceCapture } from "../src/app/dynamic-workflow-run-sequence-capture.js";
  7. function seeded(): InMemoryJournalStore {
  8. const store = new InMemoryJournalStore();
  9. store.createRun({ runId: "r", caps: { maxConcurrency: 4 }, spentTokens: 0, status: "running" });
  10. store.putActor({
  11. runId: "r",
  12. siteId: "actor#1",
  13. ordinal: 1,
  14. name: "a",
  15. persona: { system: "s" },
  16. });
  17. store.putActor({
  18. runId: "r",
  19. siteId: "actor#2",
  20. ordinal: 1,
  21. name: "b",
  22. persona: { system: "s" },
  23. });
  24. for (let ordinal = 1; ordinal <= 3; ordinal += 1) {
  25. store.putNode({
  26. runId: "r",
  27. siteId: "report#1",
  28. ordinal,
  29. kind: "report",
  30. inputHash: `h${ordinal}`,
  31. status: "completed",
  32. result: ordinal,
  33. });
  34. store.appendEvent("r", {
  35. type: "report",
  36. instance: { siteId: "report#1", ordinal },
  37. item: ordinal,
  38. });
  39. }
  40. store.putNode({
  41. runId: "r",
  42. siteId: "ask#1",
  43. ordinal: 1,
  44. kind: "ask",
  45. inputHash: "a",
  46. status: "completed",
  47. result: "x",
  48. });
  49. return store;
  50. }
  51. describe("createJournalSequenceCapture forwards read options", () => {
  52. it("passes kinds / withResult / limit / countNodes / types / reportItems / actor filters through", () => {
  53. const { journal } = createJournalSequenceCapture(seeded());
  54. const reports = journal.listNodes("r", { kinds: ["report"], withResult: false, limit: 2 });
  55. expect(reports.map((row) => row.ordinal)).toEqual([1, 2]);
  56. expect(reports.every((row) => !("result" in row))).toBe(true);
  57. expect(journal.countNodes("r", "report")).toBe(3);
  58. expect(journal.getNode("r", "ask#1", 1, { withResult: false })).not.toHaveProperty("result");
  59. const events = journal.listEvents("r", { types: ["report"], reportItems: { limit: 1 } });
  60. expect(events.map((stored) => "item" in stored.event)).toEqual([true, false, false]);
  61. const actors = journal.listActors("r", { name: "b", withPersona: false });
  62. expect(actors.map((actor) => actor.siteId)).toEqual(["actor#2"]);
  63. expect(actors[0]).not.toHaveProperty("persona");
  64. });
  65. });