v4-background-bash-output.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { describe, expect, it, vi } from "vitest";
  2. import { ConversationV4Gateway, type V4GatewayHost } from "../src/zcode-protocol-v4/v4-gateway.js";
  3. describe("background Bash readonly gateway", () => {
  4. it("queries an existing host without hydrating, subscribing or running commands", async () => {
  5. const readBackgroundBashOutput = vi
  6. .fn()
  7. .mockResolvedValue({ kind: "unavailable", workId: "work" });
  8. const executeCommand = vi.fn();
  9. const emitWireFrame = vi.fn();
  10. const gateway = new ConversationV4Gateway({
  11. readBackgroundBashOutput,
  12. executeCommand,
  13. emitWireFrame,
  14. } as unknown as V4GatewayHost);
  15. try {
  16. expect(await gateway.backgroundBashOutput({ sessionId: "session", workId: "work" })).toEqual({
  17. kind: "unavailable",
  18. workId: "work",
  19. });
  20. expect(readBackgroundBashOutput).toHaveBeenCalledExactlyOnceWith("session", "work");
  21. expect(executeCommand).not.toHaveBeenCalled();
  22. expect(emitWireFrame).not.toHaveBeenCalled();
  23. await expect(
  24. gateway.backgroundBashOutput({ sessionId: "session", workId: "work", path: "/secret" }),
  25. ).rejects.toThrow();
  26. expect(readBackgroundBashOutput).toHaveBeenCalledTimes(1);
  27. } finally {
  28. gateway.dispose();
  29. }
  30. });
  31. });