contextCompactionRuntime.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { describe, expect, it } from "vitest";
  2. import type { ZCodeContextCompactionTimelineMeta } from "@zcode/shared";
  3. import {
  4. isRunningContextCompactionTimeline,
  5. shouldContextCompactionTimelineCompleteTask,
  6. } from "../src/lib/contextCompactionRuntime.js";
  7. function createTimeline(
  8. overrides: Partial<ZCodeContextCompactionTimelineMeta>,
  9. ): ZCodeContextCompactionTimelineMeta {
  10. return {
  11. version: 1,
  12. kind: "synthetic",
  13. type: "context_compaction",
  14. operationId: "cmp-test",
  15. status: "completed",
  16. trigger: "manual",
  17. display: "separator",
  18. ...overrides,
  19. };
  20. }
  21. describe("context compaction runtime helpers", () => {
  22. it("keeps auto pre-request terminal compaction inside the running outer turn", () => {
  23. expect(
  24. shouldContextCompactionTimelineCompleteTask(
  25. createTimeline({
  26. trigger: "auto",
  27. phase: "pre_request",
  28. status: "completed",
  29. }),
  30. ),
  31. ).toBe(false);
  32. });
  33. it("completes manual standalone compaction terminal events", () => {
  34. expect(
  35. shouldContextCompactionTimelineCompleteTask(
  36. createTimeline({
  37. trigger: "manual",
  38. phase: "standalone_turn",
  39. status: "completed",
  40. }),
  41. ),
  42. ).toBe(true);
  43. });
  44. it("treats local manual compact failures without phase as standalone", () => {
  45. expect(
  46. shouldContextCompactionTimelineCompleteTask(
  47. createTimeline({
  48. trigger: "manual",
  49. status: "failed",
  50. }),
  51. ),
  52. ).toBe(true);
  53. });
  54. it("identifies running compaction timeline statuses", () => {
  55. expect(isRunningContextCompactionTimeline(createTimeline({ status: "started" }))).toBe(true);
  56. expect(isRunningContextCompactionTimeline(createTimeline({ status: "retrying" }))).toBe(true);
  57. expect(isRunningContextCompactionTimeline(createTimeline({ status: "completed" }))).toBe(false);
  58. });
  59. });