info-schema.test.ts 947 B

1234567891011121314151617181920212223242526272829303132
  1. import { describe, expect, test } from "bun:test"
  2. import { Schema } from "effect"
  3. import { Pty } from "@opencode-ai/core/pty"
  4. const sample = (pid: number) => ({
  5. id: "pty_01J5Y5H0AH4Q4NXJ6P4C3P5V2K",
  6. title: "demo",
  7. command: "cmd.exe",
  8. args: [],
  9. cwd: "C:\\",
  10. status: "running",
  11. pid,
  12. })
  13. describe("Pty.Info", () => {
  14. test("accepts pid 0 (Windows ConPTY assigns the pid asynchronously)", () => {
  15. expect(Schema.decodeUnknownSync(Pty.Info)(sample(0)).pid).toBe(0)
  16. })
  17. test("accepts a positive pid", () => {
  18. expect(Schema.decodeUnknownSync(Pty.Info)(sample(48012)).pid).toBe(48012)
  19. })
  20. test("rejects a negative pid", () => {
  21. expect(() => Schema.decodeUnknownSync(Pty.Info)(sample(-1))).toThrow()
  22. })
  23. test("accepts an exit code for retained exited sessions", () => {
  24. const info = Schema.decodeUnknownSync(Pty.Info)({ ...sample(48012), status: "exited", exitCode: 4 })
  25. expect(info.exitCode).toBe(4)
  26. })
  27. })