fix(cli): improve browser control errors

This commit is contained in:
Peter Steinberger
2025-12-13 17:37:00 +00:00
parent 4228ee326c
commit 9be3394bac
6 changed files with 233 additions and 92 deletions

View File

@@ -0,0 +1,24 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { browserStatus } from "./client.js";
describe("browser client", () => {
afterEach(() => {
vi.unstubAllGlobals();
});
it("wraps connection failures with a gateway hint", async () => {
const refused = Object.assign(new Error("connect ECONNREFUSED 127.0.0.1"), {
code: "ECONNREFUSED",
});
const fetchFailed = Object.assign(new TypeError("fetch failed"), {
cause: refused,
});
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(fetchFailed));
await expect(browserStatus("http://127.0.0.1:18791")).rejects.toThrow(
/Start .*gateway/i,
);
});
});