runtime-background-bash-output.test.ts 1.2 KB

12345678910111213141516171819202122232425262728
  1. import { describe, expect, it, vi } from "vitest";
  2. import { readBackgroundBashOutput } from "../src/runtime/methods/background-bash-output.js";
  3. import type { AgentRuntimeInternal } from "../src/runtime/internal.js";
  4. describe("background Bash execution owner routing", () => {
  5. it.each([undefined, "child"])(
  6. "passes the actual owning session to the execution boundary (%s)",
  7. async (sessionId) => {
  8. const read = vi.fn().mockResolvedValue({ kind: "unavailable", workId: "work" });
  9. const runtime = {
  10. sessionId: "root",
  11. executionPort: { readBackgroundBashOutput: read },
  12. } as unknown as AgentRuntimeInternal;
  13. expect(await readBackgroundBashOutput.call(runtime, "work", sessionId)).toEqual({
  14. kind: "unavailable",
  15. workId: "work",
  16. });
  17. expect(read).toHaveBeenCalledExactlyOnceWith("work", sessionId ?? "root");
  18. },
  19. );
  20. it("reports unsupported without creating an execution port", async () => {
  21. const runtime = { sessionId: "root" } as unknown as AgentRuntimeInternal;
  22. expect(await readBackgroundBashOutput.call(runtime, "work")).toEqual({
  23. kind: "unsupported",
  24. workId: "work",
  25. });
  26. });
  27. });