mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 14:07:20 +08:00
fix: preserve multi-account auth and Snowflake OAuth
Repair the active-only credential import with a v3 data migration that restores every account without duplicating users who already ran v2, while keeping the active account effective. Restore upstream Snowflake Cortex OAuth account/token resolution and combined refresh fetch path.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { expect } from "bun:test"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||
import { ProviderV2 } from "@opencode-ai/core/provider"
|
||||
import { Provider } from "@/provider/provider"
|
||||
import { InstanceLayer } from "@/project/instance-layer"
|
||||
import { Env } from "@/env"
|
||||
import { Plugin } from "@/plugin"
|
||||
import { provideInstanceEffect, tmpdirScoped } from "../fixture/fixture"
|
||||
import { testEffect } from "../lib/effect"
|
||||
|
||||
const it = testEffect(
|
||||
Layer.mergeAll(Provider.defaultLayer, Env.defaultLayer, Plugin.defaultLayer, CrossSpawnSpawner.defaultLayer),
|
||||
)
|
||||
|
||||
it.effect("loads Snowflake Cortex from OAuth credentials", () =>
|
||||
Effect.acquireRelease(
|
||||
Effect.sync(() => {
|
||||
const value = process.env.KILO_AUTH_CONTENT
|
||||
process.env.KILO_AUTH_CONTENT = JSON.stringify({
|
||||
"snowflake-cortex": {
|
||||
type: "oauth",
|
||||
refresh: "refresh-token",
|
||||
access: "access-token",
|
||||
expires: 1,
|
||||
accountId: "test-account",
|
||||
},
|
||||
})
|
||||
return value
|
||||
}),
|
||||
(value) =>
|
||||
Effect.sync(() => {
|
||||
if (value === undefined) delete process.env.KILO_AUTH_CONTENT
|
||||
else process.env.KILO_AUTH_CONTENT = value
|
||||
}),
|
||||
).pipe(
|
||||
Effect.flatMap(() =>
|
||||
Effect.gen(function* () {
|
||||
const directory = yield* tmpdirScoped({
|
||||
config: {
|
||||
provider: {
|
||||
"snowflake-cortex": {
|
||||
name: "Snowflake Cortex",
|
||||
npm: "@ai-sdk/openai-compatible",
|
||||
models: { test: { name: "Test" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
const provider = yield* Provider.use
|
||||
.getProvider(ProviderV2.ID.make("snowflake-cortex"))
|
||||
.pipe(provideInstanceEffect(directory), Effect.provide(InstanceLayer.layer))
|
||||
|
||||
expect(provider.options.baseURL).toBe("https://test-account.snowflakecomputing.com/api/v2/cortex/v1")
|
||||
expect(provider.options.apiKey).toBe("access-token")
|
||||
expect(provider.options.fetch).toBeFunction()
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user