Skip to content

Commit f41bf9b

Browse files
committed
fix(opencode): distinguish HTTP auth errors from endpoint ports
1 parent 93e6517 commit f41bf9b

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

‎packages/provider-opencode/src/server/status.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,44 @@ it.layer(layerTest)("checkOpenCodeProviderStatus", (it) => {
776776
});
777777

778778
it.layer(layerTest)("checkOpenCodeProviderStatus with configured server URL", (it) => {
779+
it.effect.each([
780+
"401 Unauthorized",
781+
"403 Forbidden",
782+
"status=401 body={}",
783+
"status=403 body={}",
784+
"HTTP 401",
785+
"HTTP/1.1 403",
786+
])("keeps explicit authentication rejection actionable: %s", (detail) =>
787+
Effect.gen(function* () {
788+
runtimeMock.state.connectionError = new Error(detail);
789+
const snapshot = yield* checkProvider(
790+
makeOpenCodeSettings({ serverUrl: "http://127.0.0.1:9999" }),
791+
);
792+
793+
NodeAssert.equal(snapshot.status, "error");
794+
NodeAssert.equal(snapshot.auth.status, "unauthenticated");
795+
NodeAssert.equal(
796+
snapshot.message,
797+
"OpenCode server rejected authentication. Check the server URL and password.",
798+
);
799+
}),
800+
);
801+
802+
it.effect.each([401, 403, 4010, 4030])("keeps connection failures on port %s retryable", (port) =>
803+
Effect.gen(function* () {
804+
const serverUrl = `http://127.0.0.1:${port}`;
805+
runtimeMock.state.connectionError = new Error(`connect ECONNREFUSED 127.0.0.1:${port}`);
806+
const snapshot = yield* checkProvider(makeOpenCodeSettings({ serverUrl }));
807+
808+
NodeAssert.equal(snapshot.status, "error");
809+
NodeAssert.equal(snapshot.auth.status, "unknown");
810+
NodeAssert.equal(
811+
snapshot.message,
812+
`Couldn't reach the configured OpenCode server at ${serverUrl}. Check that the server is running and the URL is correct.`,
813+
);
814+
}),
815+
);
816+
779817
it.effect("routes a configured OpenCode 2 server to the 2.x check, never via 1.x", () =>
780818
Effect.gen(function* () {
781819
const settings = makeOpenCodeSettings({

‎packages/provider-opencode/src/server/status.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ function formatOpenCodeProbeError(input: {
7575
const lower = detail?.toLowerCase() ?? "";
7676

7777
if (input.isExternalServer) {
78+
// Bare auth-code digits can be part of the endpoint's port or path.
7879
if (
79-
lower.includes("401") ||
80-
lower.includes("403") ||
81-
lower.includes("unauthorized") ||
82-
lower.includes("forbidden")
80+
/(?:^|\s)(?:status[=:]\s*|http(?:\/\d(?:\.\d)?)?\s+)(?:401|403)\b/.test(lower) ||
81+
/\b(?:unauthorized|forbidden)\b/.test(lower)
8382
) {
8483
return {
8584
installed: true,

0 commit comments

Comments
 (0)