refactor(install): prefer native plugin install across targets (#609)
Some checks failed
CI / pr-title (push) Has been cancelled
CI / test (push) Has been cancelled
Release PR / release-pr (push) Has been cancelled
Release PR / publish-cli (push) Has been cancelled

Co-authored-by: John Cavanaugh <cavanaug@users.noreply.github.com>
This commit is contained in:
Trevin Chow
2026-04-20 18:47:07 -07:00
committed by GitHub
parent 9497a00d90
commit c2d60b47be
104 changed files with 7073 additions and 7068 deletions

View File

@@ -1,7 +1,7 @@
import { describe, expect, test } from "bun:test"
import { afterEach, describe, expect, test } from "bun:test"
import os from "os"
import path from "path"
import { resolveTargetOutputRoot } from "../src/utils/resolve-output"
import { resolveOpenCodeWriteScope, resolveTargetOutputRoot } from "../src/utils/resolve-output"
const baseOptions = {
outputRoot: "/tmp/output",
@@ -21,111 +21,54 @@ describe("resolveTargetOutputRoot", () => {
expect(result).toBe(baseOptions.piHome)
})
test("droid returns ~/.factory", () => {
const result = resolveTargetOutputRoot({ ...baseOptions, targetName: "droid" })
expect(result).toBe(path.join(os.homedir(), ".factory"))
})
test("cursor with no explicit output uses cwd", () => {
const result = resolveTargetOutputRoot({ ...baseOptions, targetName: "cursor" })
expect(result).toBe(path.join(process.cwd(), ".cursor"))
})
test("cursor with explicit output uses outputRoot", () => {
test("opencode with explicit output returns outputRoot as-is", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "cursor",
hasExplicitOutput: true,
})
expect(result).toBe(path.join("/tmp/output", ".cursor"))
})
test("windsurf default scope (global) resolves to ~/.codeium/windsurf/", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "windsurf",
scope: "global",
})
expect(result).toBe(path.join(os.homedir(), ".codeium", "windsurf"))
})
test("windsurf workspace scope resolves to cwd/.windsurf/", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "windsurf",
scope: "workspace",
})
expect(result).toBe(path.join(process.cwd(), ".windsurf"))
})
test("windsurf with explicit output overrides global scope", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "windsurf",
hasExplicitOutput: true,
scope: "global",
targetName: "opencode",
})
expect(result).toBe("/tmp/output")
})
test("windsurf with explicit output overrides workspace scope", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "windsurf",
hasExplicitOutput: true,
scope: "workspace",
})
expect(result).toBe("/tmp/output")
})
describe("opencode without explicit output", () => {
const originalEnv = process.env.OPENCODE_CONFIG_DIR
test("windsurf with no scope and no explicit output uses cwd/.windsurf/", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "windsurf",
afterEach(() => {
if (originalEnv === undefined) {
delete process.env.OPENCODE_CONFIG_DIR
} else {
process.env.OPENCODE_CONFIG_DIR = originalEnv
}
})
expect(result).toBe(path.join(process.cwd(), ".windsurf"))
})
test("opencode returns outputRoot as-is", () => {
const result = resolveTargetOutputRoot({ ...baseOptions, targetName: "opencode" })
expect(result).toBe("/tmp/output")
})
test("openclaw uses openclawHome + pluginName", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "openclaw",
openclawHome: "/custom/openclaw/extensions",
pluginName: "my-plugin",
test("falls back to ~/.config/opencode when OPENCODE_CONFIG_DIR is unset", () => {
delete process.env.OPENCODE_CONFIG_DIR
const result = resolveTargetOutputRoot({ ...baseOptions, targetName: "opencode" })
expect(result).toBe(path.join(os.homedir(), ".config", "opencode"))
})
expect(result).toBe("/custom/openclaw/extensions/my-plugin")
})
test("openclaw falls back to default home when not provided", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "openclaw",
pluginName: "my-plugin",
test("respects OPENCODE_CONFIG_DIR when set", () => {
process.env.OPENCODE_CONFIG_DIR = "/custom/opencode"
const result = resolveTargetOutputRoot({ ...baseOptions, targetName: "opencode" })
expect(result).toBe("/custom/opencode")
})
expect(result).toBe(path.join(os.homedir(), ".openclaw", "extensions", "my-plugin"))
})
test("qwen uses qwenHome + pluginName", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "qwen",
qwenHome: "/custom/qwen/extensions",
pluginName: "my-plugin",
})
expect(result).toBe("/custom/qwen/extensions/my-plugin")
})
test("qwen falls back to default home when not provided", () => {
const result = resolveTargetOutputRoot({
...baseOptions,
targetName: "qwen",
pluginName: "my-plugin",
})
expect(result).toBe(path.join(os.homedir(), ".qwen", "extensions", "my-plugin"))
})
})
describe("resolveOpenCodeWriteScope", () => {
test("returns 'global' when no explicit output and no requested scope", () => {
expect(resolveOpenCodeWriteScope(false, undefined)).toBe("global")
})
test("returns undefined when explicit output is given and no requested scope", () => {
expect(resolveOpenCodeWriteScope(true, undefined)).toBeUndefined()
})
test("honors explicit requested scope even without explicit output", () => {
expect(resolveOpenCodeWriteScope(false, "workspace")).toBe("workspace")
})
test("honors explicit requested scope when explicit output is given", () => {
expect(resolveOpenCodeWriteScope(true, "global")).toBe("global")
})
})