core-agent-ide/codex-cli/tests
Benny Yen d61da89ed3
feat: notify when a newer version is available (#333)
**Summary**  
This change introduces a new startup check that notifies users if a
newer `@openai/codex` version is available. To avoid spamming, it writes
a small state file recording the last check time and will only re‑check
once every 24 hours.

**What’s Changed**  
- **New file** `src/utils/check-updates.ts`  
  - Runs `npm outdated --global @openai/codex`  
  - Reads/writes `codex-state.json` under `CONFIG_DIR`  
  - Limits checks to once per day (`UPDATE_CHECK_FREQUENCY = 24h`)  
- Uses `boxen` for a styled alert and `which` to locate the npm binary
- **Hooked into** `src/cli.tsx` entrypoint:
  ```ts
  import { checkForUpdates } from "./utils/check-updates";
  // …
  // after loading config
  await checkForUpdates().catch();
  ```
- **Dependencies**  
  - Added `boxen@^8.0.1`, `which@^5.0.0`, `@types/which@^3.0.4`  
- **Tests**  
  - Vitest suite under `tests/check-updates.test.ts`  
  - Snapshot in `__snapshots__/check-updates.test.ts.snap`  

**Motivation**  
Addresses issue #244. Users running a stale global install will now see
a friendly reminder—at most once per day—to upgrade and enjoy the latest
features.

**Test Plan**  
- `getNPMCommandPath()` resolves npm correctly  
- `checkOutdated()` parses `npm outdated` JSON  
- State file prevents repeat alerts within 24h  
- Boxen snapshot matches expected output  
- No console output when state indicates a recent check  

**Related Issue**  
try resolves #244


**Preview**
Prompt a pnpm‑style alert when outdated  

![outdated‑alert](https://github.com/user-attachments/assets/294dad45-d858-45d1-bf34-55e672ab883a)

Let me know if you’d tweak any of the messaging, throttle frequency,
placement in the startup flow, or anything else.

---------

Co-authored-by: Thibault Sottiaux <tibo@openai.com>
2025-04-18 17:00:45 -07:00
..
__fixtures__ Initial commit 2025-04-16 12:56:08 -04:00
__snapshots__ feat: notify when a newer version is available (#333) 2025-04-18 17:00:45 -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 revert: suggest mode file read behavior openai/codex#197 (#285) 2025-04-17 17:32:53 -07:00
cancel-exec.test.ts Initial commit 2025-04-16 12:56:08 -04:00
check-updates.test.ts feat: notify when a newer version is available (#333) 2025-04-18 17:00:45 -07:00
config.test.tsx feat: add notifications for MacOS using Applescript (#160) 2025-04-17 16:19:26 -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
format-command.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -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
parse-apply-patch.test.ts Back out @lib indirection in tsconfig.json (#111) 2025-04-16 14:16:53 -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.test improve reliability and error handling (#280) 2025-04-17 23:00:28 -07:00
terminal-chat-input-compact.test.tsx feat: add /compact (#289) 2025-04-17 22:48:30 -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