auth-override.test.ts 1.4 KB

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