From ada8c127aa239fa95508944ccf1f2c45cc7ccfac Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 18 Feb 2026 16:00:33 +0900 Subject: [PATCH] refactor(cli-run): remove redundant opencode bin path shim --- src/cli/run/opencode-bin-path.test.ts | 69 --------------------------- src/cli/run/opencode-bin-path.ts | 40 ---------------- src/cli/run/server-connection.ts | 3 -- 3 files changed, 112 deletions(-) delete mode 100644 src/cli/run/opencode-bin-path.test.ts delete mode 100644 src/cli/run/opencode-bin-path.ts diff --git a/src/cli/run/opencode-bin-path.test.ts b/src/cli/run/opencode-bin-path.test.ts deleted file mode 100644 index 20e3a24cb..000000000 --- a/src/cli/run/opencode-bin-path.test.ts +++ /dev/null @@ -1,69 +0,0 @@ -/// - -import { describe, expect, it } from "bun:test" -import { prependResolvedOpencodeBinToPath } from "./opencode-bin-path" - -describe("prependResolvedOpencodeBinToPath", () => { - it("prepends resolved opencode-ai bin path to PATH", () => { - //#given - const env: Record = { - PATH: "/Users/yeongyu/node_modules/.bin:/usr/bin", - } - const resolver = () => "/tmp/bunx-123/node_modules/opencode-ai/bin/opencode" - const pathExists = () => true - - //#when - prependResolvedOpencodeBinToPath(env, resolver, pathExists) - - //#then - expect(env.PATH).toBe( - "/tmp/bunx-123/node_modules/opencode-ai/bin:/Users/yeongyu/node_modules/.bin:/usr/bin", - ) - }) - - it("does not duplicate an existing opencode-ai bin path", () => { - //#given - const env: Record = { - PATH: "/tmp/bunx-123/node_modules/opencode-ai/bin:/usr/bin", - } - const resolver = () => "/tmp/bunx-123/node_modules/opencode-ai/bin/opencode" - const pathExists = () => true - - //#when - prependResolvedOpencodeBinToPath(env, resolver, pathExists) - - //#then - expect(env.PATH).toBe("/tmp/bunx-123/node_modules/opencode-ai/bin:/usr/bin") - }) - - it("keeps PATH unchanged when opencode-ai cannot be resolved", () => { - //#given - const env: Record = { - PATH: "/Users/yeongyu/node_modules/.bin:/usr/bin", - } - const resolver = () => { - throw new Error("module not found") - } - - //#when - prependResolvedOpencodeBinToPath(env, resolver) - - //#then - expect(env.PATH).toBe("/Users/yeongyu/node_modules/.bin:/usr/bin") - }) - - it("keeps PATH unchanged when resolved binary path does not exist", () => { - //#given - const env: Record = { - PATH: "/Users/yeongyu/node_modules/.bin:/usr/bin", - } - const resolver = () => "/Users/yeongyu/node_modules/opencode-ai/bin/opencode" - const pathExists = () => false - - //#when - prependResolvedOpencodeBinToPath(env, resolver, pathExists) - - //#then - expect(env.PATH).toBe("/Users/yeongyu/node_modules/.bin:/usr/bin") - }) -}) diff --git a/src/cli/run/opencode-bin-path.ts b/src/cli/run/opencode-bin-path.ts deleted file mode 100644 index bd7c6235e..000000000 --- a/src/cli/run/opencode-bin-path.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { delimiter, dirname } from "node:path" -import { createRequire } from "node:module" -import { existsSync } from "node:fs" - -type EnvLike = Record - -const resolveFromCurrentModule = createRequire(import.meta.url).resolve - -export function prependResolvedOpencodeBinToPath( - env: EnvLike = process.env, - resolve: (id: string) => string = resolveFromCurrentModule, - pathExists: (path: string) => boolean = existsSync, -): void { - let resolvedPath: string - try { - resolvedPath = resolve("opencode-ai/bin/opencode") - } catch { - return - } - - if (!pathExists(resolvedPath)) { - return - } - - const opencodeBinDir = dirname(resolvedPath) - if (!pathExists(opencodeBinDir)) { - return - } - - const currentPath = env.PATH ?? "" - const pathSegments = currentPath ? currentPath.split(delimiter) : [] - - if (pathSegments.includes(opencodeBinDir)) { - return - } - - env.PATH = currentPath - ? `${opencodeBinDir}${delimiter}${currentPath}` - : opencodeBinDir -} diff --git a/src/cli/run/server-connection.ts b/src/cli/run/server-connection.ts index 3472e7a25..949b6de4f 100644 --- a/src/cli/run/server-connection.ts +++ b/src/cli/run/server-connection.ts @@ -3,7 +3,6 @@ import pc from "picocolors" import type { ServerConnection } from "./types" import { getAvailableServerPort, isPortAvailable, DEFAULT_SERVER_PORT } from "../../shared/port-utils" import { withWorkingOpencodePath } from "./opencode-binary-resolver" -import { prependResolvedOpencodeBinToPath } from "./opencode-bin-path" function isPortStartFailure(error: unknown, port: number): boolean { if (!(error instanceof Error)) { @@ -28,8 +27,6 @@ export async function createServerConnection(options: { attach?: string signal: AbortSignal }): Promise { - prependResolvedOpencodeBinToPath() - const { port, attach, signal } = options if (attach !== undefined) {