Files
9router/tests/unit/headroom-detect.test.js
Carmelo Campos 50ed79fe9e fix(headroom): support Docker sidecar proxy
Treat configured Headroom proxy as running when its /health endpoint
responds, even if local headroom CLI is not installed. Dashboard
Start/Stop stays limited to local loopback proxies while external
Docker sidecars can be enabled via HEADROOM_URL.

Closes #1948

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-21 17:45:27 +07:00

37 lines
1.2 KiB
JavaScript

import { describe, it, expect, vi, afterEach } from "vitest";
const mocks = vi.hoisted(() => ({
execSync: vi.fn(() => { throw new Error("not found"); }),
}));
vi.mock("child_process", () => ({
execSync: mocks.execSync,
}));
import { getHeadroomStatus, isLoopbackHeadroomUrl } from "../../src/lib/headroom/detect.js";
afterEach(() => {
vi.clearAllMocks();
});
describe("headroom detect", () => {
it("treats a reachable external proxy as running without local CLI", async () => {
global.fetch = vi.fn(async () => new Response("ok", { status: 200 }));
const status = await getHeadroomStatus("http://headroom:8787");
expect(status.installed).toBe(false);
expect(status.running).toBe(true);
expect(status.localUrl).toBe(false);
expect(status.canStart).toBe(false);
expect(global.fetch).toHaveBeenCalledWith("http://headroom:8787/health", expect.any(Object));
});
it("recognizes loopback URLs for managed local mode", () => {
expect(isLoopbackHeadroomUrl("http://localhost:8787")).toBe(true);
expect(isLoopbackHeadroomUrl("http://127.0.0.1:8787")).toBe(true);
expect(isLoopbackHeadroomUrl("http://headroom:8787")).toBe(false);
expect(isLoopbackHeadroomUrl("not-a-url")).toBe(false);
});
});