2026-02-17 02:10:15 +09:00
|
|
|
/// <reference types="bun-types" />
|
|
|
|
|
|
|
|
|
|
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<string, string | undefined> = {
|
|
|
|
|
PATH: "/Users/yeongyu/node_modules/.bin:/usr/bin",
|
|
|
|
|
}
|
|
|
|
|
const resolver = () => "/tmp/bunx-123/node_modules/opencode-ai/bin/opencode"
|
2026-02-18 15:49:44 +09:00
|
|
|
const pathExists = () => true
|
2026-02-17 02:10:15 +09:00
|
|
|
|
|
|
|
|
//#when
|
2026-02-18 15:49:44 +09:00
|
|
|
prependResolvedOpencodeBinToPath(env, resolver, pathExists)
|
2026-02-17 02:10:15 +09:00
|
|
|
|
|
|
|
|
//#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<string, string | undefined> = {
|
|
|
|
|
PATH: "/tmp/bunx-123/node_modules/opencode-ai/bin:/usr/bin",
|
|
|
|
|
}
|
|
|
|
|
const resolver = () => "/tmp/bunx-123/node_modules/opencode-ai/bin/opencode"
|
2026-02-18 15:49:44 +09:00
|
|
|
const pathExists = () => true
|
2026-02-17 02:10:15 +09:00
|
|
|
|
|
|
|
|
//#when
|
2026-02-18 15:49:44 +09:00
|
|
|
prependResolvedOpencodeBinToPath(env, resolver, pathExists)
|
2026-02-17 02:10:15 +09:00
|
|
|
|
|
|
|
|
//#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<string, string | undefined> = {
|
|
|
|
|
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")
|
|
|
|
|
})
|
2026-02-18 15:49:44 +09:00
|
|
|
|
|
|
|
|
it("keeps PATH unchanged when resolved binary path does not exist", () => {
|
|
|
|
|
//#given
|
|
|
|
|
const env: Record<string, string | undefined> = {
|
|
|
|
|
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")
|
|
|
|
|
})
|
2026-02-17 02:10:15 +09:00
|
|
|
})
|