test: migrate auth override plugin test (#27140)
This commit is contained in:
@@ -1,15 +1,19 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs/promises"
|
|
||||||
import { pathToFileURL } from "url"
|
import { pathToFileURL } from "url"
|
||||||
import { Effect, Layer } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
import { provideTestInstance, tmpdir } from "../fixture/fixture"
|
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
||||||
|
import { provideInstance, TestInstance, tmpdirScoped } from "../fixture/fixture"
|
||||||
import { ProviderAuth } from "@/provider/auth"
|
import { ProviderAuth } from "@/provider/auth"
|
||||||
import { ProviderID } from "../../src/provider/schema"
|
import { ProviderID } from "../../src/provider/schema"
|
||||||
import { Plugin } from "@/plugin"
|
import { Plugin } from "@/plugin"
|
||||||
import { Auth } from "@/auth"
|
import { Auth } from "@/auth"
|
||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import { TestConfig } from "../fixture/config"
|
import { TestConfig } from "../fixture/config"
|
||||||
|
import { testEffect } from "../lib/effect"
|
||||||
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||||
|
|
||||||
|
const it = testEffect(Layer.mergeAll(CrossSpawnSpawner.defaultLayer, AppFileSystem.defaultLayer))
|
||||||
|
|
||||||
function layer(directory: string, plugins: string[]) {
|
function layer(directory: string, plugins: string[]) {
|
||||||
return ProviderAuth.layer.pipe(
|
return ProviderAuth.layer.pipe(
|
||||||
@@ -37,13 +41,15 @@ function layer(directory: string, plugins: string[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("plugin.auth-override", () => {
|
describe("plugin.auth-override", () => {
|
||||||
test("user plugin overrides built-in github-copilot auth", async () => {
|
it.instance(
|
||||||
await using tmp = await tmpdir({
|
"user plugin overrides built-in github-copilot auth",
|
||||||
init: async (dir) => {
|
() =>
|
||||||
const pluginDir = path.join(dir, ".opencode", "plugin")
|
Effect.gen(function* () {
|
||||||
await fs.mkdir(pluginDir, { recursive: true })
|
const tmp = yield* TestInstance
|
||||||
|
const fs = yield* AppFileSystem.Service
|
||||||
|
const pluginDir = path.join(tmp.directory, ".opencode", "plugin")
|
||||||
|
|
||||||
await Bun.write(
|
yield* fs.writeWithDirs(
|
||||||
path.join(pluginDir, "custom-copilot-auth.ts"),
|
path.join(pluginDir, "custom-copilot-auth.ts"),
|
||||||
[
|
[
|
||||||
"export default {",
|
"export default {",
|
||||||
@@ -61,37 +67,26 @@ describe("plugin.auth-override", () => {
|
|||||||
"",
|
"",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
)
|
)
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await using plain = await tmpdir()
|
const plain = yield* tmpdirScoped({ git: true })
|
||||||
|
const plugin = pathToFileURL(path.join(pluginDir, "custom-copilot-auth.ts")).href
|
||||||
|
const methods = yield* ProviderAuth.Service.use((svc) => svc.methods()).pipe(
|
||||||
|
Effect.provide(layer(tmp.directory, [plugin])),
|
||||||
|
)
|
||||||
|
const plainMethods = yield* ProviderAuth.Service.use((svc) => svc.methods()).pipe(
|
||||||
|
Effect.provide(layer(plain, [])),
|
||||||
|
provideInstance(plain),
|
||||||
|
)
|
||||||
|
|
||||||
const plugin = pathToFileURL(path.join(tmp.path, ".opencode", "plugin", "custom-copilot-auth.ts")).href
|
const copilot = methods[ProviderID.make("github-copilot")]
|
||||||
const [methods, plainMethods] = await Promise.all([
|
expect(copilot).toBeDefined()
|
||||||
provideTestInstance({
|
expect(copilot.length).toBe(1)
|
||||||
directory: tmp.path,
|
expect(copilot[0].label).toBe("Test Override Auth")
|
||||||
fn: async () => {
|
expect(plainMethods[ProviderID.make("github-copilot")][0].label).not.toBe("Test Override Auth")
|
||||||
return Effect.runPromise(
|
|
||||||
ProviderAuth.Service.use((svc) => svc.methods()).pipe(Effect.provide(layer(tmp.path, [plugin]))),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
provideTestInstance({
|
{ git: true },
|
||||||
directory: plain.path,
|
30000,
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const file = path.join(import.meta.dir, "../../src/plugin/index.ts")
|
const file = path.join(import.meta.dir, "../../src/plugin/index.ts")
|
||||||
|
|||||||
Reference in New Issue
Block a user