auth-override.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. import { ProviderID } from "../../src/provider/schema"
  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. await Bun.write(
  15. path.join(pluginDir, "custom-copilot-auth.ts"),
  16. [
  17. "export default async () => ({",
  18. " auth: {",
  19. ' provider: "github-copilot",',
  20. " methods: [",
  21. ' { type: "api", label: "Test Override Auth" },',
  22. " ],",
  23. " loader: async () => ({ access: 'test-token' }),",
  24. " },",
  25. "})",
  26. "",
  27. ].join("\n"),
  28. )
  29. },
  30. })
  31. await using plain = await tmpdir()
  32. const methods = await Instance.provide({
  33. directory: tmp.path,
  34. fn: async () => {
  35. return ProviderAuth.methods()
  36. },
  37. })
  38. const plainMethods = await Instance.provide({
  39. directory: plain.path,
  40. fn: async () => {
  41. return ProviderAuth.methods()
  42. },
  43. })
  44. const copilot = methods[ProviderID.make("github-copilot")]
  45. expect(copilot).toBeDefined()
  46. expect(copilot.length).toBe(1)
  47. expect(copilot[0].label).toBe("Test Override Auth")
  48. expect(plainMethods[ProviderID.make("github-copilot")][0].label).not.toBe("Test Override Auth")
  49. }, 30000) // Increased timeout for plugin installation
  50. })