|
1 | 1 | import { describe, expect, test, vi } from "bun:test" |
2 | | -import { BaseSidecarController } from "./types" |
| 2 | +import { BaseSidecarController, createLocalSidecarController, createWslSidecarController } from "./types" |
3 | 3 |
|
4 | 4 | describe("SidecarController Interface", () => { |
5 | 5 | test("manages sidecar lifecycle state transitions", async () => { |
@@ -28,4 +28,44 @@ describe("SidecarController Interface", () => { |
28 | 28 | expect(controller.getUrl()).rejects.toThrow("Failed to start server") |
29 | 29 | expect(controller.status).toBe("failed") |
30 | 30 | }) |
| 31 | + |
| 32 | + test("createLocalSidecarController wraps local server startup and stop", async () => { |
| 33 | + const stopMock = vi.fn().mockResolvedValue(undefined) |
| 34 | + const startMock = vi.fn().mockResolvedValue({ |
| 35 | + url: "http://127.0.0.1:4096", |
| 36 | + listener: { stop: stopMock }, |
| 37 | + }) |
| 38 | + |
| 39 | + const sidecar = createLocalSidecarController("local-main", startMock) |
| 40 | + expect(sidecar.kind).toBe("local") |
| 41 | + expect(sidecar.status).toBe("idle") |
| 42 | + |
| 43 | + const url = await sidecar.getUrl() |
| 44 | + expect(url).toBe("http://127.0.0.1:4096") |
| 45 | + expect(sidecar.status).toBe("ready") |
| 46 | + |
| 47 | + await sidecar.stop() |
| 48 | + expect(stopMock).toHaveBeenCalled() |
| 49 | + expect(sidecar.status).toBe("stopped") |
| 50 | + }) |
| 51 | + |
| 52 | + test("createWslSidecarController wraps WSL server startup and stop", async () => { |
| 53 | + const stopMock = vi.fn() |
| 54 | + const startMock = vi.fn().mockResolvedValue({ |
| 55 | + url: "http://127.0.0.1:8080", |
| 56 | + listener: { stop: stopMock }, |
| 57 | + }) |
| 58 | + |
| 59 | + const sidecar = createWslSidecarController("Ubuntu", startMock) |
| 60 | + expect(sidecar.kind).toBe("wsl") |
| 61 | + expect(sidecar.status).toBe("idle") |
| 62 | + |
| 63 | + const url = await sidecar.getUrl() |
| 64 | + expect(url).toBe("http://127.0.0.1:8080") |
| 65 | + expect(sidecar.status).toBe("ready") |
| 66 | + |
| 67 | + await sidecar.stop() |
| 68 | + expect(stopMock).toHaveBeenCalled() |
| 69 | + expect(sidecar.status).toBe("stopped") |
| 70 | + }) |
31 | 71 | }) |
0 commit comments