core-agent-ide/codex-cli/tests
Benny Yen 3e71c87708
refactor(updates): fetch version from registry instead of npm CLI to support multiple managers (#446)
## Background  
Addressing feedback from
https://github.com/openai/codex/pull/333#discussion_r2050893224, this PR
adds support for Bun alongside npm, pnpm while keeping the code simple.

## Summary  
The update‑check flow is refactored to use a direct registry lookup
(`fast-npm-meta` + `semver`) instead of shelling out to `npm outdated`,
and adds a lightweight installer‑detection mechanism that:

1. Checks if the invoked script lives under a known global‑bin directory
(npm, pnpm, or bun)
2. If not, falls back to local detection via `getUserAgent()` (the
`package‑manager‑detector` library)

## What’s Changed  
- **Registry‑based version check**  
- Replace `execFile("npm", ["outdated"])` with `getLatestVersion()` and
`semver.gt()`
- **Multi‑manager support**  
- New `renderUpdateCommand` handles update commands for `npm`, `pnpm`,
and `bun`.
  - Detect global installer first via `detectInstallerByPath()`  
  - Fallback to local detection via `getUserAgent()`  
- **Module cleanup**  
- Extract `detectInstallerByPath` into
`utils/package-manager-detector.ts`
- Remove legacy `checkOutdated`, `getNPMCommandPath`, and child‑process
JSON parsing
- **Flow improvements in `checkForUpdates`**  
  1. Short‑circuit by `UPDATE_CHECK_FREQUENCY`  
  3. Fetch & compare versions  
  4. Persist new timestamp immediately  
  5. Render & display styled box only when an update exists  
- **Maintain simplicity**
- All multi‑manager logic lives in one small helper and a concise lookup
rather than a complex adapter hierarchy
- Core `checkForUpdates` remains a single, easy‑to‑follow async function
- **Dependencies added**  
- `fast-npm-meta`, `semver`, `package-manager-detector`, `@types/semver`

## Considerations
If we decide to drop the interactive update‑message (`npm install -g
@openai/codex`) rendering altogether, we could remove most of the
installer‑detection code and dependencies, which would simplify the
codebase further but result in a less friendly UX.

## Preview

* npm

![refactor-update-check-flow-npm](https://github.com/user-attachments/assets/57320114-3fb6-4985-8780-3388a1d1ec85)

* bun

![refactor-update-check-flow-bun](https://github.com/user-attachments/assets/d93bf0ae-a687-412a-ab92-581b4f967307)

## Simple Flow Chart

```mermaid
flowchart TD
  A(Start) --> B[Read state]
  B --> C{Recent check?}
  C -- Yes --> Z[End]
  C -- No --> D[Fetch latest version]
  D --> E[Save check time]
  E --> F{Version data OK?}
  F -- No --> Z
  F -- Yes --> G{Update available?}
  G -- No --> Z
  G -- Yes --> H{Global install?}
  H -- Yes --> I[Select global manager]
  H -- No --> K{Local install?}
  K -- No --> Z
  K -- Yes --> L[Select local manager]
  I & L --> M[Render update message]
  M --> N[Format with boxen]
  N --> O[Print update]
  O --> Z
```
2025-04-21 00:00:20 -07:00
..
__fixtures__ Initial commit 2025-04-16 12:56:08 -04:00
__snapshots__ refactor(updates): fetch version from registry instead of npm CLI to support multiple managers (#446) 2025-04-21 00:00:20 -07:00
agent-cancel-early.test.ts feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -07:00
agent-cancel-prev-response.test.ts feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -07:00
agent-cancel-race.test.ts feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -07:00
agent-cancel.test.ts feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -07:00
agent-function-call-id.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-generic-network-error.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-interrupt-continue.test.ts feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -07:00
agent-invalid-request-error.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-max-tokens-error.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-network-errors.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-project-doc.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-rate-limit-error.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-server-retry.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
agent-terminate.test.ts feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -07:00
agent-thinking-time.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
api-key.test.ts Initial commit 2025-04-16 12:56:08 -04:00
apply-patch.test.ts Initial commit 2025-04-16 12:56:08 -04:00
approvals.test.ts feat: add user-defined safe commands configuration and approval logic #380 (#386) 2025-04-18 22:35:32 -07:00
cancel-exec.test.ts Initial commit 2025-04-16 12:56:08 -04:00
check-updates.test.ts refactor(updates): fetch version from registry instead of npm CLI to support multiple managers (#446) 2025-04-21 00:00:20 -07:00
config.test.tsx feat: read approvalMode from config file (#298) 2025-04-19 07:25:25 -07:00
dummy.test.ts Initial commit 2025-04-16 12:56:08 -04:00
external-editor.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
file-system-suggestions.test.ts feat: tab completions for file paths (#279) 2025-04-20 22:34:27 -07:00
fixed-requires-shell.test.ts fix: command pipe execution by improving shell detection (#437) 2025-04-20 21:11:19 -07:00
format-command.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
history-overlay.test.tsx refactor(history-overlay): split into modular functions & add tests (fixes #402) (#403) 2025-04-20 22:27:06 -07:00
input-utils.test.ts re-enable Prettier check for codex-cli in CI (#417) 2025-04-19 11:22:45 -07:00
invalid-command-handling.test.ts add support for -w,--writable-root to add more writable roots for sandbox (#263) 2025-04-17 15:39:26 -07:00
markdown.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
model-utils-network-error.test.ts Initial commit 2025-04-16 12:56:08 -04:00
multiline-ctrl-enter-submit.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
multiline-dynamic-width.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
multiline-enter-submit-cr.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
multiline-external-editor-shortcut.test.tsx Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
multiline-history-behavior.test.tsx Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
multiline-input-test.ts Initial commit 2025-04-16 12:56:08 -04:00
multiline-newline.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
multiline-shift-enter-crlf.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
multiline-shift-enter-mod1.test.tsx Fix handling of Shift+Enter in e.g. Ghostty (#338) 2025-04-18 09:19:06 -07:00
multiline-shift-enter.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
package-manager-detector.test.ts refactor(updates): fetch version from registry instead of npm CLI to support multiple managers (#446) 2025-04-21 00:00:20 -07:00
parse-apply-patch.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
pipe-command.test.ts fix: command pipe execution by improving shell detection (#437) 2025-04-20 21:11:19 -07:00
project-doc.test.ts Initial commit 2025-04-16 12:56:08 -04:00
raw-exec-process-group.test.ts fix(raw-exec-process-group): improve test reliability (#434) 2025-04-20 12:21:02 -07:00
requires-shell.test.ts fix: command pipe execution by improving shell detection (#437) 2025-04-20 21:11:19 -07:00
responses-chat-completions.test.ts feat: support multiple providers via Responses-Completion transformation (#247) 2025-04-20 20:59:34 -07:00
slash-commands.test.ts feat: /diff command to view git diff (#426) 2025-04-19 16:23:27 -07:00
terminal-chat-completions.test.tsx feat: tab completions for file paths (#279) 2025-04-20 22:34:27 -07:00
terminal-chat-input-compact.test.tsx feat: /diff command to view git diff (#426) 2025-04-19 16:23:27 -07:00
terminal-chat-input-multiline.test.tsx feat: allow multi-line input (#438) 2025-04-20 08:51:38 -07:00
terminal-chat-response-item.test.tsx Initial commit 2025-04-16 12:56:08 -04:00
text-buffer-copy-paste.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
text-buffer-crlf.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
text-buffer-gaps.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
text-buffer-word.test.ts fix(text-buffer): correct word deletion logic for trailing spaces (Ctrl+Backspace) (#131) 2025-04-16 16:25:08 -07:00
text-buffer.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -07:00
typeahead-scroll.test.tsx (fix) do not transitively rely on deprecated lodash deps (#175) 2025-04-16 20:52:35 -07:00
ui-test-helpers.tsx Initial commit 2025-04-16 12:56:08 -04:00