fix(auth): add graceful fallback for server auth injection
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
0dd42e2901
commit
e073412da1
@ -1,3 +1,6 @@
|
|||||||
|
/// <reference types="bun-types" />
|
||||||
|
|
||||||
|
import { describe, test, expect, beforeEach, afterEach } from "bun:test"
|
||||||
import { getServerBasicAuthHeader, injectServerAuthIntoClient } from "./opencode-server-auth"
|
import { getServerBasicAuthHeader, injectServerAuthIntoClient } from "./opencode-server-auth"
|
||||||
|
|
||||||
describe("opencode-server-auth", () => {
|
describe("opencode-server-auth", () => {
|
||||||
@ -68,22 +71,18 @@ describe("opencode-server-auth", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("#given server password #when client has no _client #then throws error", () => {
|
test("#given server password #when client has no _client #then does not throw", () => {
|
||||||
process.env.OPENCODE_SERVER_PASSWORD = "secret"
|
process.env.OPENCODE_SERVER_PASSWORD = "secret"
|
||||||
const client = {}
|
const client = {}
|
||||||
|
|
||||||
expect(() => injectServerAuthIntoClient(client)).toThrow(
|
expect(() => injectServerAuthIntoClient(client)).not.toThrow()
|
||||||
"[opencode-server-auth] OPENCODE_SERVER_PASSWORD is set but SDK client structure is incompatible"
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("#given server password #when client._client has no setConfig #then throws error", () => {
|
test("#given server password #when client._client has no setConfig #then does not throw", () => {
|
||||||
process.env.OPENCODE_SERVER_PASSWORD = "secret"
|
process.env.OPENCODE_SERVER_PASSWORD = "secret"
|
||||||
const client = { _client: {} }
|
const client = { _client: {} }
|
||||||
|
|
||||||
expect(() => injectServerAuthIntoClient(client)).toThrow(
|
expect(() => injectServerAuthIntoClient(client)).not.toThrow()
|
||||||
"[opencode-server-auth] OPENCODE_SERVER_PASSWORD is set but SDK client._client.setConfig is not a function"
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("#given no server password #when client is invalid #then does not throw", () => {
|
test("#given no server password #when client is invalid #then does not throw", () => {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export function injectServerAuthIntoClient(client: unknown): void {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runtime type guard for SDK client structure
|
try {
|
||||||
if (
|
if (
|
||||||
typeof client !== "object" ||
|
typeof client !== "object" ||
|
||||||
client === null ||
|
client === null ||
|
||||||
@ -62,4 +62,8 @@ export function injectServerAuthIntoClient(client: unknown): void {
|
|||||||
Authorization: auth,
|
Authorization: auth,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : String(error)
|
||||||
|
console.warn(`[opencode-server-auth] Failed to inject server auth: ${message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user