backgroundBashOutput.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. backgroundBashOutputResultSchema,
  4. v4BackgroundBashOutputParamsSchema,
  5. } from "../src/zcode-protocol-v4/index.js";
  6. describe("background Bash output query", () => {
  7. it("rejects arbitrary paths and caller-selected read budgets", () => {
  8. const input = { sessionId: "session", workId: "work" };
  9. expect(v4BackgroundBashOutputParamsSchema.parse(input)).toEqual(input);
  10. for (const extra of [{ path: "/secret" }, { limit: 100_000 }, { offset: 0 }]) {
  11. expect(v4BackgroundBashOutputParamsSchema.safeParse({ ...input, ...extra }).success).toBe(
  12. false,
  13. );
  14. }
  15. });
  16. it("separates empty successful output from missing or unreadable output", () => {
  17. const output = {
  18. kind: "output",
  19. workId: "work",
  20. status: "running",
  21. output: "",
  22. truncated: false,
  23. outputPath: "/output",
  24. };
  25. expect(backgroundBashOutputResultSchema.parse(output)).toEqual(output);
  26. for (const extra of [
  27. { command: "build" },
  28. { startedAt: 1 },
  29. { completedAt: 2 },
  30. { exitCode: 0 },
  31. { totalBytes: 0 },
  32. ]) {
  33. expect(backgroundBashOutputResultSchema.safeParse({ ...output, ...extra }).success).toBe(
  34. false,
  35. );
  36. }
  37. expect(
  38. backgroundBashOutputResultSchema.safeParse({ ...output, output: "x".repeat(8193) }).success,
  39. ).toBe(false);
  40. for (const kind of ["unavailable", "unsupported", "read_failed"]) {
  41. expect(backgroundBashOutputResultSchema.parse({ kind, workId: "work" }).kind).toBe(kind);
  42. }
  43. });
  44. });