fix(instance): run bootstrap from instance store (#25475)
This commit is contained in:
@@ -1,11 +1,40 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import path from "path"
|
||||
import fs from "fs/promises"
|
||||
import { Effect } from "effect"
|
||||
import { tmpdir } from "../fixture/fixture"
|
||||
import { Instance } from "../../src/project/instance"
|
||||
import { pathToFileURL } from "url"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { provideTestInstance, tmpdir } from "../fixture/fixture"
|
||||
import { ProviderAuth } from "@/provider/auth"
|
||||
import { ProviderID } from "../../src/provider/schema"
|
||||
import { Plugin } from "@/plugin"
|
||||
import { Auth } from "@/auth"
|
||||
import { Bus } from "@/bus"
|
||||
import { TestConfig } from "../fixture/config"
|
||||
|
||||
function layer(directory: string, plugins: string[]) {
|
||||
return ProviderAuth.layer.pipe(
|
||||
Layer.provide(Auth.defaultLayer),
|
||||
Layer.provide(
|
||||
Plugin.layer.pipe(
|
||||
Layer.provide(Bus.layer),
|
||||
Layer.provide(
|
||||
TestConfig.layer({
|
||||
get: () =>
|
||||
Effect.succeed({
|
||||
plugin: plugins,
|
||||
plugin_origins: plugins.map((plugin) => ({
|
||||
spec: plugin,
|
||||
source: path.join(directory, "opencode.json"),
|
||||
scope: "local" as const,
|
||||
})),
|
||||
}),
|
||||
directories: () => Effect.succeed([directory]),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
describe("plugin.auth-override", () => {
|
||||
test("user plugin overrides built-in github-copilot auth", async () => {
|
||||
@@ -37,30 +66,32 @@ describe("plugin.auth-override", () => {
|
||||
|
||||
await using plain = await tmpdir()
|
||||
|
||||
const methods = await Instance.provide({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
return Effect.runPromise(
|
||||
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(ProviderAuth.defaultLayer)),
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
const plainMethods = await Instance.provide({
|
||||
directory: plain.path,
|
||||
fn: async () => {
|
||||
return Effect.runPromise(
|
||||
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(ProviderAuth.defaultLayer)),
|
||||
)
|
||||
},
|
||||
})
|
||||
const plugin = pathToFileURL(path.join(tmp.path, ".opencode", "plugin", "custom-copilot-auth.ts")).href
|
||||
const [methods, plainMethods] = await Promise.all([
|
||||
provideTestInstance({
|
||||
directory: tmp.path,
|
||||
fn: async () => {
|
||||
return Effect.runPromise(
|
||||
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(layer(tmp.path, [plugin]))),
|
||||
)
|
||||
},
|
||||
}),
|
||||
provideTestInstance({
|
||||
directory: plain.path,
|
||||
fn: async () => {
|
||||
return Effect.runPromise(
|
||||
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(layer(plain.path, []))),
|
||||
)
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
const copilot = methods[ProviderID.make("github-copilot")]
|
||||
expect(copilot).toBeDefined()
|
||||
expect(copilot.length).toBe(1)
|
||||
expect(copilot[0].label).toBe("Test Override Auth")
|
||||
expect(plainMethods[ProviderID.make("github-copilot")][0].label).not.toBe("Test Override Auth")
|
||||
}, 30000) // Increased timeout for plugin installation
|
||||
}, 30000)
|
||||
})
|
||||
|
||||
const file = path.join(import.meta.dir, "../../src/plugin/index.ts")
|
||||
|
||||
Reference in New Issue
Block a user