workflowAvatarAllocation.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { describe, expect, it } from "vitest";
  2. import { buildWorkflowTimeline } from "@/components/workflow-timeline/timeline-model.js";
  3. import type { WorkflowCausalityGraphData } from "@/components/workflow-graph/types.js";
  4. describe("workflow avatar allocation", () => {
  5. it("同名代理不碰撞,同一代理跨阶段复用编号", () => {
  6. const lanes = Array.from({ length: 10 }, (_, i) => ({
  7. id: `actor#${i}`,
  8. name: "same name",
  9. line: i + 1,
  10. column: 1,
  11. }));
  12. const phases = ["a", "b"].map((id) => ({ id, name: id, line: 1 }));
  13. const steps = phases.flatMap((phase) =>
  14. lanes.map((lane) => ({
  15. id: `${phase.id}-${lane.id}`,
  16. kind: "ask" as const,
  17. label: "ask",
  18. line: 1,
  19. column: 1,
  20. lane: lane.id,
  21. phase: phase.id,
  22. })),
  23. );
  24. const graph: WorkflowCausalityGraphData = {
  25. lanes,
  26. phases,
  27. steps,
  28. participants: steps.map((step) => ({
  29. id: step.id,
  30. phase: step.phase,
  31. lane: step.lane,
  32. steps: [step.id],
  33. })),
  34. handoffs: [],
  35. phaseEdges: [{ from: "a", to: "b" }],
  36. exits: ["b"],
  37. };
  38. const stations = buildWorkflowTimeline(graph, undefined).stations;
  39. expect(stations[0]!.pills.map((p) => p.avatarIndex)).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
  40. expect(stations[1]!.pills.map((p) => p.avatarIndex)).toEqual(
  41. stations[0]!.pills.map((p) => p.avatarIndex),
  42. );
  43. });
  44. });