|
| 1 | +import { describe, expect, test, vi } from "bun:test" |
| 2 | +import { BaseSidecarController } from "./types" |
| 3 | + |
| 4 | +describe("SidecarController Interface", () => { |
| 5 | + test("manages sidecar lifecycle state transitions", async () => { |
| 6 | + const fetchUrl = vi.fn().mockResolvedValue("http://127.0.0.1:4096") |
| 7 | + const stopFn = vi.fn().mockResolvedValue(undefined) |
| 8 | + |
| 9 | + const controller = new BaseSidecarController("local-1", "local", fetchUrl, stopFn) |
| 10 | + |
| 11 | + expect(controller.status).toBe("idle") |
| 12 | + |
| 13 | + const url = await controller.getUrl() |
| 14 | + expect(url).toBe("http://127.0.0.1:4096") |
| 15 | + expect(controller.status).toBe("ready") |
| 16 | + |
| 17 | + await controller.stop() |
| 18 | + expect(stopFn).toHaveBeenCalled() |
| 19 | + expect(controller.status).toBe("stopped") |
| 20 | + }) |
| 21 | + |
| 22 | + test("handles startup failures gracefully", async () => { |
| 23 | + const fetchUrl = vi.fn().mockRejectedValue(new Error("Failed to start server")) |
| 24 | + const stopFn = vi.fn().mockResolvedValue(undefined) |
| 25 | + |
| 26 | + const controller = new BaseSidecarController("wsl-ubuntu", "wsl", fetchUrl, stopFn) |
| 27 | + |
| 28 | + expect(controller.getUrl()).rejects.toThrow("Failed to start server") |
| 29 | + expect(controller.status).toBe("failed") |
| 30 | + }) |
| 31 | +}) |
0 commit comments