From 5553b5048ea40a33154cb2fee550a50073b59330 Mon Sep 17 00:00:00 2001 From: kevinwang5658 <20214115+kevinwang5658@users.noreply.github.com> Date: Sun, 19 Jul 2026 03:02:43 +0000 Subject: [PATCH] fix: auto-fix test failures from Test all (MacOS) --- src/resources/codex/codex.ts | 51 +++++++++++++++--------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/resources/codex/codex.ts b/src/resources/codex/codex.ts index 43fc3097..50b08274 100644 --- a/src/resources/codex/codex.ts +++ b/src/resources/codex/codex.ts @@ -2,10 +2,11 @@ import { CreatePlan, DestroyPlan, ExampleConfig, + PackageManager, Resource, ResourceSettings, - SpawnError, SpawnStatus, + Utils, getPty, z, } from '@codifycli/plugin-core'; @@ -151,40 +152,25 @@ export class CodexResource extends Resource { } async refresh(): Promise | null> { - const codexBin = path.join(os.homedir(), '.local', 'bin', 'codex'); - try { - await fs.access(codexBin); - } catch { - return null; - } - - return {}; + const $ = getPty(); + const { status } = await $.spawnSafe('which codex'); + return status === SpawnStatus.SUCCESS ? {} : null; } async create(_plan: CreatePlan): Promise { - const $ = getPty(); - - const installCmd = 'bash -c "curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_NON_INTERACTIVE=1 sh"'; - - // The official installer resolves "latest" via GitHub's unauthenticated release API, - // which is IP rate-limited and intermittently returns 403 on shared CI runners. - // Retry with backoff rather than failing outright on what is usually a transient block. - const maxAttempts = 4; - let result; - for (let attempt = 1; attempt <= maxAttempts; attempt++) { - result = await $.spawnSafe(installCmd, { interactive: true }); - if (result.status === SpawnStatus.SUCCESS) { - break; - } - - if (attempt < maxAttempts) { - await new Promise((resolve) => setTimeout(resolve, attempt * 15_000)); - } + if (Utils.isMacOS()) { + // The Homebrew cask downloads a pinned release asset directly, avoiding the + // unauthenticated GitHub release API that the official curl installer relies on + // to resolve "latest" (that API is IP rate-limited and returns 403 on shared CI runners). + await Utils.installViaPkgMgr('codex', { [PackageManager.BREW]: { cask: true } }, PackageManager.BREW); + return; } - if (result!.status !== SpawnStatus.SUCCESS) { - throw new SpawnError(installCmd, result!.exitCode, result!.data); - } + const $ = getPty(); + await $.spawn( + 'bash -c "curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_NON_INTERACTIVE=1 sh"', + { interactive: true }, + ); // Ensure PATH is updated so subsequent lifecycle methods can call `codex` const localBin = path.join(os.homedir(), '.local', 'bin'); @@ -192,6 +178,11 @@ export class CodexResource extends Resource { } async destroy(_plan: DestroyPlan): Promise { + if (Utils.isMacOS()) { + await Utils.uninstallViaPkgMgr('codex', { [PackageManager.BREW]: { cask: true } }, PackageManager.BREW); + return; + } + // Native uninstall: remove the binary and standalone release artifacts await fs.rm(path.join(os.homedir(), '.local', 'bin', 'codex'), { force: true }); await fs.rm(path.join(os.homedir(), '.codex', 'packages', 'standalone'), { recursive: true, force: true });