fix: pass wrapper package root to codex installer
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 { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { findRepoRootFromImporter, resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex"
|
||||
import { findRepoRoot, findRepoRootFromImporter, resolveCodexInstallerBinDir, runCodexInstaller } from "./install-codex"
|
||||
|
||||
const EXPECTED_OMO_COMPONENT_BINS = [
|
||||
{ name: "omo", target: join("components", "ulw-loop", "dist", "cli.js") },
|
||||
@@ -42,6 +42,23 @@ describe("install-codex", () => {
|
||||
expect(repoRoot).toBe(wrapperRoot)
|
||||
})
|
||||
|
||||
test("#given wrapper root env #when resolving vendored repo root #then prefers wrapper package root", async () => {
|
||||
// given
|
||||
const platformPackageRoot = await mkdtemp(join(tmpdir(), "omo-codex-platform-package-"))
|
||||
const wrapperRoot = await mkdtemp(join(tmpdir(), "omo-codex-wrapper-package-"))
|
||||
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 = findRepoRoot({
|
||||
importerDir: join(platformPackageRoot, "bin"),
|
||||
env: { OMO_WRAPPER_PACKAGE_ROOT: wrapperRoot },
|
||||
})
|
||||
|
||||
// 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")
|
||||
|
||||
@@ -14,7 +14,7 @@ import type { CodexInstallOptions, CodexInstallResult, CodexMarketplaceSource, I
|
||||
const SISYPHUS_LEGACY_CACHE_MARKETPLACES = ["lazycodex", "code-yeongyu-codex-plugins"] as const
|
||||
|
||||
export async function runCodexInstaller(options: CodexInstallOptions = {}): Promise<CodexInstallResult> {
|
||||
const repoRoot = resolve(options.repoRoot ?? findRepoRootFromImporter(import.meta.dir))
|
||||
const repoRoot = resolve(options.repoRoot ?? findRepoRoot({ importerDir: import.meta.dir, env: process.env }))
|
||||
const codexHome = resolve(options.codexHome ?? process.env.CODEX_HOME ?? join(homedir(), ".codex"))
|
||||
const binDir = resolveCodexInstallerBinDir({ binDir: options.binDir, codexHome, env: process.env })
|
||||
const runCommand = options.runCommand ?? defaultRunCommand
|
||||
@@ -199,11 +199,9 @@ function codexMarketplaceSource(marketplaceRoot: string): CodexMarketplaceSource
|
||||
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
|
||||
if (isRepoRootWithCodexPlugin(current)) 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
|
||||
if (isRepoRootWithCodexPlugin(wrapperPackageRoot)) return wrapperPackageRoot
|
||||
}
|
||||
current = resolve(current, "..")
|
||||
}
|
||||
@@ -212,6 +210,22 @@ export function findRepoRootFromImporter(importerDir: string): string {
|
||||
)
|
||||
}
|
||||
|
||||
export function findRepoRoot(input: {
|
||||
readonly importerDir: string
|
||||
readonly env?: { readonly [key: string]: string | undefined }
|
||||
}): string {
|
||||
const wrapperPackageRoot = input.env?.OMO_WRAPPER_PACKAGE_ROOT
|
||||
if (wrapperPackageRoot !== undefined && wrapperPackageRoot.trim().length > 0) {
|
||||
const resolvedWrapperPackageRoot = resolve(wrapperPackageRoot)
|
||||
if (isRepoRootWithCodexPlugin(resolvedWrapperPackageRoot)) return resolvedWrapperPackageRoot
|
||||
}
|
||||
return findRepoRootFromImporter(input.importerDir)
|
||||
}
|
||||
|
||||
function isRepoRootWithCodexPlugin(repoRoot: string): boolean {
|
||||
return existsSyncLike(join(repoRoot, "packages", "omo-codex", "plugin", ".codex-plugin", "plugin.json"))
|
||||
}
|
||||
|
||||
function existsSyncLike(path: string): boolean {
|
||||
return existsSync(path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user