mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-18 00:23:25 +00:00
fix(core): tolerate unavailable wellknown config
This commit is contained in:
parent
6895728add
commit
c22942c1f3
2 changed files with 15 additions and 4 deletions
|
|
@ -151,7 +151,13 @@ export const layer = (options?: Options) =>
|
|||
)
|
||||
if (!credential || credential.value.type !== "key") return []
|
||||
const variables = { [auth.env]: credential.value.key }
|
||||
const configs = yield* wellknown.resolve(entry, variables).pipe(Effect.orDie)
|
||||
const configs = yield* wellknown.resolve(entry, variables).pipe(
|
||||
Effect.catch(() =>
|
||||
Effect.logWarning("failed to load wellknown config", { source: entry.origin }).pipe(
|
||||
Effect.as([] as const),
|
||||
),
|
||||
),
|
||||
)
|
||||
return yield* Effect.forEach(configs, (config) =>
|
||||
ConfigVariable.substitute({
|
||||
type: "virtual",
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ describe("Config", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.live("loads authenticated wellknown config before user configuration", () =>
|
||||
it.live("tolerates unavailable authenticated wellknown config and reloads it later", () =>
|
||||
Effect.acquireUseRelease(
|
||||
Effect.promise(() => tmpdir()),
|
||||
(tmp) =>
|
||||
|
|
@ -322,6 +322,7 @@ describe("Config", () => {
|
|||
})
|
||||
|
||||
const integrationID = Integration.ID.make("https://example.com")
|
||||
let available = false
|
||||
let key = "secret"
|
||||
const credentialNode = makeGlobalNode({
|
||||
service: Credential.Service,
|
||||
|
|
@ -361,7 +362,10 @@ describe("Config", () => {
|
|||
refresh: () => Effect.succeed(false),
|
||||
add: () => Effect.die("unused Wellknown.add"),
|
||||
remove: () => Effect.die("unused Wellknown.remove"),
|
||||
resolve: (_entry, variables) => Effect.succeed([{ shell: variables.TOKEN }]),
|
||||
resolve: (_entry, variables) =>
|
||||
available
|
||||
? Effect.succeed([{ shell: variables.TOKEN }])
|
||||
: Effect.fail(new Error("expired credential")),
|
||||
}),
|
||||
),
|
||||
deps: [],
|
||||
|
|
@ -374,11 +378,12 @@ describe("Config", () => {
|
|||
expect(Config.latest(initial, "shell")).toBe("project")
|
||||
expect(
|
||||
initial.flatMap((entry) => (entry.type === "document" && entry.info.shell ? [entry.info.shell] : [])),
|
||||
).toEqual(["secret", "global", "project"])
|
||||
).toEqual(["global", "project"])
|
||||
const updated = yield* bus
|
||||
.subscribe(Event.Updated)
|
||||
.pipe(Stream.take(1), Stream.runCollect, Effect.forkScoped)
|
||||
yield* Effect.yieldNow
|
||||
available = true
|
||||
key = "next"
|
||||
yield* bus.publish(Integration.Event.ConnectionUpdated, { integrationID })
|
||||
expect(yield* Fiber.join(updated)).toHaveLength(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue