|
| 1 | +import { describe, expect, test } from "bun:test" |
| 2 | +import path from "path" |
| 3 | +import fs from "fs/promises" |
| 4 | +import { tmpdir } from "../fixture/fixture" |
| 5 | +import { Instance } from "../../src/project/instance" |
| 6 | +import { ProviderAuth } from "../../src/provider/auth" |
| 7 | + |
| 8 | +describe("plugin.auth-override", () => { |
| 9 | + test("user plugin overrides built-in github-copilot auth", async () => { |
| 10 | + await using tmp = await tmpdir({ |
| 11 | + init: async (dir) => { |
| 12 | + const pluginDir = path.join(dir, ".opencode", "plugin") |
| 13 | + await fs.mkdir(pluginDir, { recursive: true }) |
| 14 | + |
| 15 | + await Bun.write( |
| 16 | + path.join(pluginDir, "custom-copilot-auth.ts"), |
| 17 | + [ |
| 18 | + "export default async () => ({", |
| 19 | + " auth: {", |
| 20 | + ' provider: "github-copilot",', |
| 21 | + " methods: [", |
| 22 | + ' { type: "api", label: "Test Override Auth" },', |
| 23 | + " ],", |
| 24 | + " loader: async () => ({ access: 'test-token' }),", |
| 25 | + " },", |
| 26 | + "})", |
| 27 | + "", |
| 28 | + ].join("\n"), |
| 29 | + ) |
| 30 | + }, |
| 31 | + }) |
| 32 | + |
| 33 | + await Instance.provide({ |
| 34 | + directory: tmp.path, |
| 35 | + fn: async () => { |
| 36 | + const methods = await ProviderAuth.methods() |
| 37 | + const copilot = methods["github-copilot"] |
| 38 | + expect(copilot).toBeDefined() |
| 39 | + expect(copilot.length).toBe(1) |
| 40 | + expect(copilot[0].label).toBe("Test Override Auth") |
| 41 | + }, |
| 42 | + }) |
| 43 | + }, 30000) // Increased timeout for plugin installation |
| 44 | +}) |
0 commit comments