fix(update): surface actionable message for unsupported proxy schemes
omp update re-threw Bun's raw fetch() UnsupportedProxyProtocol error, telling CLI users to pass verbose:true to fetch() — an instruction unavailable through the CLI. The update fetch catches now detect this failure and report which proxy env var uses an unsupported scheme plus the http/https requirement. Fixes #8784
This commit is contained in:
@@ -89,3 +89,35 @@ describe("getLatestRelease rename pointers", () => {
|
||||
expect(release.packages).toEqual({ pkg: "@oh-my-pi/pi-coding-agent", natives: "@oh-my-pi/pi-natives" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("getLatestRelease proxy errors", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("translates Bun's UnsupportedProxyProtocol fetch failure into an actionable CLI message", async () => {
|
||||
const fetchStub = Object.assign(
|
||||
async () => {
|
||||
throw new Error(
|
||||
'UnsupportedProxyProtocol fetching "https://registry.npmjs.org/@oh-my-pi/pi-coding-agent/latest". ' +
|
||||
"For more information, pass `verbose: true` in the second argument to fetch()",
|
||||
);
|
||||
},
|
||||
{ preconnect: globalThis.fetch.preconnect },
|
||||
);
|
||||
vi.spyOn(globalThis, "fetch").mockImplementation(fetchStub);
|
||||
|
||||
const err = await getLatestRelease({ timeoutMs: 5000 }).then(
|
||||
() => null,
|
||||
(e: unknown) => e as Error,
|
||||
);
|
||||
|
||||
expect(err).toBeInstanceOf(Error);
|
||||
// The raw fetch() instruction the CLI user cannot act on must not leak through.
|
||||
expect(err?.message).not.toContain("verbose: true");
|
||||
expect(err?.message).not.toContain("fetch()");
|
||||
// Instead the user gets actionable guidance about supported proxy schemes.
|
||||
expect(err?.message).toMatch(/SOCKS/i);
|
||||
expect(err?.message).toMatch(/https?:\/\//i);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user