perf(core): ignore credential events for unrelated integrations (#60782)

This commit is contained in:
Aiden Cline
2026-10-30 22:45:11 -05:00
committed by GitHub
Unverified
parent 074da8f807
commit 2d800e4742
3 changed files with 30 additions and 4 deletions
@@ -7,8 +7,8 @@ import type { Provider } from "../../provider.js"
/**
* Tracks provider settings a plugin derives from the active connection's stored credential, such as login form
* answers kept as credential metadata. The model resolver does not pass credential metadata to packages, so a
* plugin that needs it applies these settings in its provider transform. A credential update or switch reloads
* providers when the derived settings change.
* plugin that needs it applies these settings in its provider transform. Switching this integration's active
* credential reloads providers when the derived settings change.
*/
export const credentialSettings = Effect.fn("ProviderPlugin.credentialSettings")(function* (
ctx: Context,
@@ -25,7 +25,8 @@ export const credentialSettings = Effect.fn("ProviderPlugin.credentialSettings")
return stored ? select(stored.value) : {}
})
const current = { settings: yield* load() }
yield* bus.subscribe([Credential.Event.Updated, Credential.Event.Switched]).pipe(
yield* bus.subscribe(Credential.Event.Switched).pipe(
Stream.filter((event) => event.data.integrationID === integrationID),
Stream.runForEach(() =>
Effect.gen(function* () {
const next = yield* load()
+1 -1
View File
@@ -526,7 +526,7 @@ const layer = Layer.effect(
},
)
})
yield* bus.subscribe([Integration.Event.Updated, Credential.Event.Updated, Credential.Event.Switched]).pipe(
yield* bus.subscribe([Integration.Event.Updated, Credential.Event.Switched]).pipe(
Stream.runForEach(() => notify),
Effect.forkScoped({ startImmediately: true }),
)
@@ -6,6 +6,7 @@ import { PluginHost } from "@opencode/core/plugin/host"
import { CloudflareWorkersAIPlugin } from "@opencode/core/plugin/provider/cloudflare-workers-ai"
import { Provider } from "@opencode/core/provider"
import { Integration } from "@opencode/core/integration"
import { drain } from "../lib/clock"
import { testEffect } from "../lib/effect"
import { PluginTestLayer } from "./fixture"
@@ -121,6 +122,30 @@ describe("CloudflareWorkersAIPlugin", () => {
),
)
it.effect("follows the account ID when another form login becomes active", () =>
withEnv({ CLOUDFLARE_ACCOUNT_ID: undefined }, () =>
Effect.gen(function* () {
const catalog = yield* seed((provider) => {
provider.package = "@opencode/ai/providers/cloudflare-workers-ai"
})
const credentials = yield* Credential.Service
const first = yield* credentials.create({
integrationID: Integration.ID.make("cloudflare-workers-ai"),
value: Credential.Key.make({ type: "key", key: "secret", metadata: { accountId: "first-acct" } }),
})
yield* credentials.create({
integrationID: Integration.ID.make("cloudflare-workers-ai"),
value: Credential.Key.make({ type: "key", key: "secret", metadata: { accountId: "second-acct" } }),
})
yield* addPlugin()
expect(required(yield* catalog.get(providerID)).settings).toEqual({ accountId: "second-acct" })
yield* credentials.activate(first.id)
yield* drain
expect(required(yield* catalog.get(providerID)).settings).toEqual({ accountId: "first-acct" })
}),
),
)
it.effect("preserves a configured endpoint URL instead of deriving one from account ID", () =>
withEnv({ CLOUDFLARE_ACCOUNT_ID: "acct" }, () =>
Effect.gen(function* () {