fix: locate codex plugin from platform binary

This commit is contained in:
YeonGyu-Kim
2026-05-31 00:01:34 +09:00
parent 25d75be6db
commit 64db15a6ac
2 changed files with 23 additions and 3 deletions
+17 -1
View File
@@ -5,7 +5,7 @@ import { describe, expect, test } from "bun:test"
import { mkdir, mkdtemp, readdir, readFile, readlink, rm, stat, writeFile } from "node:fs/promises"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex"
import { findRepoRootFromImporter, resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex"
const EXPECTED_OMO_COMPONENT_BINS = [
{ name: "omo", target: join("components", "ulw-loop", "dist", "cli.js") },
@@ -26,6 +26,22 @@ const STALE_CODEX_COMPONENT_BINS = [
] as const
describe("install-codex", () => {
test("#given npm platform binary package #when resolving vendored repo root #then finds sibling wrapper package", async () => {
// given
const nodeModules = await mkdtemp(join(tmpdir(), "omo-codex-node-modules-"))
const importerDir = join(nodeModules, "oh-my-openagent-darwin-arm64", "bin")
const wrapperRoot = join(nodeModules, "oh-my-openagent")
await mkdir(join(importerDir), { recursive: true })
await mkdir(join(wrapperRoot, "packages", "omo-codex", "plugin", ".codex-plugin"), { recursive: true })
await writeFile(join(wrapperRoot, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json"), "{}")
// when
const repoRoot = findRepoRootFromImporter(importerDir)
// then
expect(repoRoot).toBe(wrapperRoot)
})
test("#given default CODEX_HOME #when resolving installer bin dir without override #then preserves user local bin precedence", () => {
// given
const homeDir = join(tmpdir(), "omo-codex-home-default")
+6 -2
View File
@@ -196,15 +196,19 @@ function codexMarketplaceSource(marketplaceRoot: string): CodexMarketplaceSource
return { sourceType: "local", source: marketplaceRoot }
}
function findRepoRootFromImporter(importerDir: string): string {
export function findRepoRootFromImporter(importerDir: string): string {
let current = importerDir
for (let depth = 0; depth <= 5; depth += 1) {
const pluginManifestPath = join(current, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json")
if (existsSyncLike(pluginManifestPath)) return current
for (const wrapperPackageRoot of [join(current, "node_modules", "oh-my-openagent"), join(current, "oh-my-openagent")]) {
const wrapperPluginManifestPath = join(wrapperPackageRoot, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json")
if (existsSyncLike(wrapperPluginManifestPath)) return wrapperPackageRoot
}
current = resolve(current, "..")
}
throw new Error(
"Unable to locate vendored Codex plugin: expected packages/omo-codex/plugin/.codex-plugin/plugin.json within 5 parent levels",
"Unable to locate vendored Codex plugin: expected packages/omo-codex/plugin/.codex-plugin/plugin.json in this package or sibling oh-my-openagent package within 5 parent levels",
)
}