diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/package.json | 1 | ||||
| -rw-r--r-- | packages/opencode/src/config/config.ts | 2 | ||||
| -rw-r--r-- | packages/opencode/src/plugin/index.ts | 30 | ||||
| -rw-r--r-- | packages/opencode/test/provider/amazon-bedrock.test.ts | 46 | ||||
| -rw-r--r-- | packages/opencode/test/provider/gitlab-duo.test.ts | 36 | ||||
| -rw-r--r-- | packages/opencode/test/provider/provider.test.ts | 23 |
6 files changed, 18 insertions, 120 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json index a0d6892f9..7032245ac 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -72,6 +72,7 @@ "@ai-sdk/xai": "2.0.51", "@clack/prompts": "1.0.0-alpha.1", "@gitlab/gitlab-ai-provider": "3.4.0", + "@gitlab/opencode-gitlab-auth": "1.3.2", "@hono/standard-validator": "0.1.5", "@hono/zod-validator": "catalog:", "@modelcontextprotocol/sdk": "1.25.2", diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index ed1b15500..e1110e092 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -274,7 +274,7 @@ export namespace Config { ...(proxied() ? ["--no-cache"] : []), ], { cwd: dir }, - ).catch(() => {}) + ) } async function isWritable(dir: string) { diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index 4e5776e51..627c6f8cf 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/packages/opencode/src/plugin/index.ts @@ -6,19 +6,15 @@ import { createOpencodeClient } from "@opencode-ai/sdk" import { Server } from "../server/server" import { BunProc } from "../bun" import { Instance } from "../project/instance" -import { Flag } from "../flag/flag" import { CodexAuthPlugin } from "./codex" -import { Session } from "../session" -import { NamedError } from "@opencode-ai/util/error" import { CopilotAuthPlugin } from "./copilot" +import { gitlabAuthPlugin as GitlabAuthPlugin } from "@gitlab/opencode-gitlab-auth" export namespace Plugin { const log = Log.create({ service: "plugin" }) - const BUILTIN = ["[email protected]", "@gitlab/[email protected]"] - // Built-in plugins that are directly imported (not installed from npm) - const INTERNAL_PLUGINS: PluginInstance[] = [CodexAuthPlugin, CopilotAuthPlugin] + const INTERNAL_PLUGINS: PluginInstance[] = [CodexAuthPlugin, CopilotAuthPlugin, GitlabAuthPlugin] const state = Instance.state(async () => { const client = createOpencodeClient({ @@ -45,9 +41,6 @@ export namespace Plugin { const plugins = [...(config.plugin ?? [])] if (plugins.length) await Config.waitForDependencies() - if (!Flag.OPENCODE_DISABLE_DEFAULT_PLUGINS) { - plugins.push(...BUILTIN) - } for (let plugin of plugins) { // ignore old codex plugin since it is supported first party now @@ -57,24 +50,7 @@ export namespace Plugin { const lastAtIndex = plugin.lastIndexOf("@") const pkg = lastAtIndex > 0 ? plugin.substring(0, lastAtIndex) : plugin const version = lastAtIndex > 0 ? plugin.substring(lastAtIndex + 1) : "latest" - const builtin = BUILTIN.some((x) => x.startsWith(pkg + "@")) - plugin = await BunProc.install(pkg, version).catch((err) => { - if (!builtin) throw err - - const message = err instanceof Error ? err.message : String(err) - log.error("failed to install builtin plugin", { - pkg, - version, - error: message, - }) - Bus.publish(Session.Event.Error, { - error: new NamedError.Unknown({ - message: `Failed to install built-in plugin ${pkg}@${version}: ${message}`, - }).toObject(), - }) - - return "" - }) + plugin = await BunProc.install(pkg, version) if (!plugin) continue } const mod = await import(plugin) diff --git a/packages/opencode/test/provider/amazon-bedrock.test.ts b/packages/opencode/test/provider/amazon-bedrock.test.ts index a90c9632d..d1d3cc41c 100644 --- a/packages/opencode/test/provider/amazon-bedrock.test.ts +++ b/packages/opencode/test/provider/amazon-bedrock.test.ts @@ -1,46 +1,12 @@ -import { test, expect, mock, describe } from "bun:test" +import { test, expect, describe } from "bun:test" import path from "path" import { unlink } from "fs/promises" -// === Mocks === -// These mocks are required because Provider.list() triggers: -// 1. BunProc.install("@aws-sdk/credential-providers") - in bedrock custom loader -// 2. Plugin.list() which calls BunProc.install() for default plugins -// Without mocks, these would attempt real package installations that timeout in tests. - -mock.module("../../src/bun/index", () => ({ - BunProc: { - install: async (pkg: string, _version?: string) => { - // Return package name without version for mocking - const lastAtIndex = pkg.lastIndexOf("@") - return lastAtIndex > 0 ? pkg.substring(0, lastAtIndex) : pkg - }, - run: async () => { - throw new Error("BunProc.run should not be called in tests") - }, - which: () => process.execPath, - InstallFailedError: class extends Error {}, - }, -})) - -mock.module("@aws-sdk/credential-providers", () => ({ - fromNodeProviderChain: () => async () => ({ - accessKeyId: "mock-access-key-id", - secretAccessKey: "mock-secret-access-key", - }), -})) - -const mockPlugin = () => ({}) -mock.module("opencode-copilot-auth", () => ({ default: mockPlugin })) -mock.module("opencode-anthropic-auth", () => ({ default: mockPlugin })) -mock.module("@gitlab/opencode-gitlab-auth", () => ({ default: mockPlugin })) - -// Import after mocks are set up -const { tmpdir } = await import("../fixture/fixture") -const { Instance } = await import("../../src/project/instance") -const { Provider } = await import("../../src/provider/provider") -const { Env } = await import("../../src/env") -const { Global } = await import("../../src/global") +import { tmpdir } from "../fixture/fixture" +import { Instance } from "../../src/project/instance" +import { Provider } from "../../src/provider/provider" +import { Env } from "../../src/env" +import { Global } from "../../src/global" test("Bedrock: config region takes precedence over AWS_REGION env var", async () => { await using tmp = await tmpdir({ diff --git a/packages/opencode/test/provider/gitlab-duo.test.ts b/packages/opencode/test/provider/gitlab-duo.test.ts index 4d5aa9c74..c512a4590 100644 --- a/packages/opencode/test/provider/gitlab-duo.test.ts +++ b/packages/opencode/test/provider/gitlab-duo.test.ts @@ -1,35 +1,11 @@ -import { test, expect, mock } from "bun:test" +import { test, expect } from "bun:test" import path from "path" -// === Mocks === -// These mocks prevent real package installations during tests - -mock.module("../../src/bun/index", () => ({ - BunProc: { - install: async (pkg: string, _version?: string) => { - // Return package name without version for mocking - const lastAtIndex = pkg.lastIndexOf("@") - return lastAtIndex > 0 ? pkg.substring(0, lastAtIndex) : pkg - }, - run: async () => { - throw new Error("BunProc.run should not be called in tests") - }, - which: () => process.execPath, - InstallFailedError: class extends Error {}, - }, -})) - -const mockPlugin = () => ({}) -mock.module("opencode-copilot-auth", () => ({ default: mockPlugin })) -mock.module("opencode-anthropic-auth", () => ({ default: mockPlugin })) -mock.module("@gitlab/opencode-gitlab-auth", () => ({ default: mockPlugin })) - -// Import after mocks are set up -const { tmpdir } = await import("../fixture/fixture") -const { Instance } = await import("../../src/project/instance") -const { Provider } = await import("../../src/provider/provider") -const { Env } = await import("../../src/env") -const { Global } = await import("../../src/global") +import { tmpdir } from "../fixture/fixture" +import { Instance } from "../../src/project/instance" +import { Provider } from "../../src/provider/provider" +import { Env } from "../../src/env" +import { Global } from "../../src/global" test("GitLab Duo: loads provider with API key from environment", async () => { await using tmp = await tmpdir({ diff --git a/packages/opencode/test/provider/provider.test.ts b/packages/opencode/test/provider/provider.test.ts index 482587d8a..98cd49c02 100644 --- a/packages/opencode/test/provider/provider.test.ts +++ b/packages/opencode/test/provider/provider.test.ts @@ -1,27 +1,6 @@ -import { test, expect, mock } from "bun:test" +import { test, expect } from "bun:test" import path from "path" -// Mock BunProc and default plugins to prevent actual installations during tests -mock.module("../../src/bun/index", () => ({ - BunProc: { - install: async (pkg: string, _version?: string) => { - // Return package name without version for mocking - const lastAtIndex = pkg.lastIndexOf("@") - return lastAtIndex > 0 ? pkg.substring(0, lastAtIndex) : pkg - }, - run: async () => { - throw new Error("BunProc.run should not be called in tests") - }, - which: () => process.execPath, - InstallFailedError: class extends Error {}, - }, -})) - -const mockPlugin = () => ({}) -mock.module("opencode-copilot-auth", () => ({ default: mockPlugin })) -mock.module("opencode-anthropic-auth", () => ({ default: mockPlugin })) -mock.module("@gitlab/opencode-gitlab-auth", () => ({ default: mockPlugin })) - import { tmpdir } from "../fixture/fixture" import { Instance } from "../../src/project/instance" import { Provider } from "../../src/provider/provider" |
