fix: locate codex plugin from platform binary
This commit is contained in:
@@ -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 { mkdir, mkdtemp, readdir, readFile, readlink, rm, stat, writeFile } from "node:fs/promises"
|
||||||
import { tmpdir } from "node:os"
|
import { tmpdir } from "node:os"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
import { resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex"
|
import { findRepoRootFromImporter, resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex"
|
||||||
|
|
||||||
const EXPECTED_OMO_COMPONENT_BINS = [
|
const EXPECTED_OMO_COMPONENT_BINS = [
|
||||||
{ name: "omo", target: join("components", "ulw-loop", "dist", "cli.js") },
|
{ name: "omo", target: join("components", "ulw-loop", "dist", "cli.js") },
|
||||||
@@ -26,6 +26,22 @@ const STALE_CODEX_COMPONENT_BINS = [
|
|||||||
] as const
|
] as const
|
||||||
|
|
||||||
describe("install-codex", () => {
|
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", () => {
|
test("#given default CODEX_HOME #when resolving installer bin dir without override #then preserves user local bin precedence", () => {
|
||||||
// given
|
// given
|
||||||
const homeDir = join(tmpdir(), "omo-codex-home-default")
|
const homeDir = join(tmpdir(), "omo-codex-home-default")
|
||||||
|
|||||||
@@ -196,15 +196,19 @@ function codexMarketplaceSource(marketplaceRoot: string): CodexMarketplaceSource
|
|||||||
return { sourceType: "local", source: marketplaceRoot }
|
return { sourceType: "local", source: marketplaceRoot }
|
||||||
}
|
}
|
||||||
|
|
||||||
function findRepoRootFromImporter(importerDir: string): string {
|
export function findRepoRootFromImporter(importerDir: string): string {
|
||||||
let current = importerDir
|
let current = importerDir
|
||||||
for (let depth = 0; depth <= 5; depth += 1) {
|
for (let depth = 0; depth <= 5; depth += 1) {
|
||||||
const pluginManifestPath = join(current, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json")
|
const pluginManifestPath = join(current, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json")
|
||||||
if (existsSyncLike(pluginManifestPath)) return current
|
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, "..")
|
current = resolve(current, "..")
|
||||||
}
|
}
|
||||||
throw new Error(
|
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",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user