fix(provider): sanitize OpenCode endpoint messages

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-06-20 20:22:16 -07:00
1 parent d267246cac
commit 65ff046bdf
2 files changed
+20 -2

No files matched your search

@@ -210,7 +210,7 @@ it.layer(testLayer)("checkOpenCodeProviderStatus with configured server URL", (i
runtimeMock.state.inventoryError = new Error("401 Unauthorized");
const snapshot = yield* checkOpenCodeProviderStatus(
makeOpenCodeSettings({
serverUrl: "http://127.0.0.1:9999",
serverUrl: "http://url-user:[email protected]:9999/private?token=secret#fragment",
serverPassword: "secret-password",
}),
process.cwd(),
@@ -244,6 +244,10 @@ it.layer(testLayer)("checkOpenCodeProviderStatus with configured server URL", (i
snapshot.message,
"Couldn't reach the configured OpenCode server at http://127.0.0.1:9999. Check that the server is running and the URL is correct.",
);
NodeAssert.doesNotMatch(
snapshot.message ?? "",
/url-user|url-password|private|token|secret|fragment/,
);
}),
);
});
@@ -59,6 +59,16 @@ function normalizedErrorMessage(cause: unknown): string | undefined {
return normalizeProbeMessage(cause.message);
}
function openCodeServerDisplayTarget(input: string): string | undefined {
try {
const url = new URL(input);
const port = url.port === "" ? "" : `:${url.port}`;
return `${url.protocol}//${url.hostname}${port}`;
} catch {
return undefined;
}
}
function formatOpenCodeProbeError(input: {
readonly cause: unknown;
readonly isExternalServer: boolean;
@@ -89,9 +99,13 @@ function formatOpenCodeProbeError(input: {
lower.includes("timeout") ||
lower.includes("socket hang up")
) {
const serverTarget = openCodeServerDisplayTarget(input.serverUrl);
return {
installed: true,
message: `Couldn't reach the configured OpenCode server at ${input.serverUrl}. Check that the server is running and the URL is correct.`,
message:
serverTarget === undefined
? "Couldn't reach the configured OpenCode server. Check that the server is running and the URL is correct."
: `Couldn't reach the configured OpenCode server at ${serverTarget}. Check that the server is running and the URL is correct.`,
};
}