runtime-memory-drain.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { afterEach, describe, expect, it, vi } from "vitest";
  2. import { AgentRuntime } from "../src/runtime/agent-runtime.js";
  3. afterEach(() => vi.useRealTimers());
  4. describe("runtime Memory Extraction drain", () => {
  5. it("waits past the normal deadline when an explicit null disables the drain timeout", async () => {
  6. vi.useFakeTimers();
  7. const completion = Promise.withResolvers<void>();
  8. let finished = false;
  9. const draining = AgentRuntime.prototype.drainMemoryExtractions
  10. .call({ memoryExtractionScheduler: { drain: () => completion.promise } } as never, null)
  11. .then(() => {
  12. finished = true;
  13. });
  14. await vi.advanceTimersByTimeAsync(120_000);
  15. expect(finished).toBe(false);
  16. completion.resolve();
  17. await draining;
  18. expect(finished).toBe(true);
  19. expect(vi.getTimerCount()).toBe(0);
  20. });
  21. it("returns immediately when there is no scheduled work", async () => {
  22. await expect(
  23. AgentRuntime.prototype.drainMemoryExtractions.call({} as never, null),
  24. ).resolves.toBeUndefined();
  25. });
  26. it.each([
  27. [{ enabled: true, cliStorageRoot: "/storage", use: true }, true],
  28. [{ enabled: false, cliStorageRoot: "/storage", use: true }, false],
  29. [{ enabled: true, cliStorageRoot: "/storage", use: false }, false],
  30. ] as const)("reports effective Memory enablement for preflight", (memory, expected) => {
  31. expect(
  32. AgentRuntime.prototype.isProjectMemoryEnabled.call({
  33. config: { memory },
  34. workspaceRoot: "/workspace",
  35. } as never),
  36. ).toBe(expected);
  37. });
  38. });