Visitar URL original
Fix auto-update bun install cwd by nettee · Pull Request #254 · alvinunreal/oh-my-opencode-slim · GitHub
Skip to content

Fix auto-update bun install cwd - #254

Merged
alvinunreal merged 2 commits into
alvinunreal:masterfrom
nettee:fix/auto-update-cache-dir
Apr 9, 2026
Merged

alvinunreal merged 2 commits into
alvinunreal:masterfrom
nettee:fix/auto-update-cache-dir

Conversation

@nettee

@nettee nettee commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • run auto-update \bun install\\ from the OpenCode cache directory instead of the active project directory
  • add a regression test that locks the auto-update install directory to the cache path
  • avoid creating \bun.lock\\ and \node_modules\\ in pnpm project roots when the plugin checks for updates

Validation

  • bun run build (fails in this repo due existing TypeScript issues unrelated to this change)
  • bun test src/hooks/auto-update-checker/index.test.ts src/hooks/auto-update-checker/checker.test.ts src/hooks/auto-update-checker/cache.test.ts (fails in this repo due existing test/dependency setup issues unrelated to this change)

@greptile-apps

greptile-apps Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes bun install running in the active project directory (ctx.directory) during auto-update, which polluted pnpm project roots with bun.lock and node_modules. The fix redirects the install to CACHE_DIR (the OpenCode cache directory) via a new exported getAutoUpdateInstallDir() helper, and adds a regression test that pins the directory to the cache path using Bun's module mocking.

Confidence Score: 5/5

Safe to merge — the fix is correct and well-targeted; the only finding is a minor unused parameter cleanup.

All remaining findings are P2 (unused ctx parameter in runBunInstallSafe after the refactor). The core bug fix is correct: using CACHE_DIR as the bun install cwd prevents polluting project roots. The regression test is properly structured using Bun module mocking. No P0/P1 issues found.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
src/hooks/auto-update-checker/index.ts Core fix: runBunInstallSafe now uses CACHE_DIR instead of ctx.directory as the cwd for bun install; introduces getAutoUpdateInstallDir as a testable indirection point. The ctx parameter in runBunInstallSafe is now unused.
src/hooks/auto-update-checker/index.test.ts New regression test that mocks constants and verifies getAutoUpdateInstallDir() returns the mocked CACHE_DIR, correctly locking the install directory to the cache path. Bun module mocking is applied before the import, which is the correct pattern.

Sequence Diagram

sequenceDiagram
    participant Hook as createAutoUpdateCheckerHook
    participant BGCheck as runBackgroundUpdateCheck
    participant BunInstall as runBunInstallSafe
    participant CacheDir as CACHE_DIR (~/.cache/opencode)

    Hook->>BGCheck: runBackgroundUpdateCheck(ctx, autoUpdate)
    BGCheck->>BGCheck: invalidatePackage(PACKAGE_NAME)
    BGCheck->>BunInstall: runBunInstallSafe(ctx)
    BunInstall->>BunInstall: installDir = getAutoUpdateInstallDir()
    Note over BunInstall: Previously: cwd = ctx.directory (project root)<br/>Now: cwd = CACHE_DIR
    BunInstall->>CacheDir: Bun.spawn(['bun', 'install'], { cwd: installDir })
    CacheDir-->>BunInstall: exit code
    BunInstall-->>BGCheck: success / failure
    BGCheck-->>Hook: showToast(result)
Loading

Reviews (1): Last reviewed commit: "Fix auto-update bun install cwd" | Re-trigger Greptile

Comment thread src/hooks/auto-update-checker/index.ts Outdated
@alvinunreal
alvinunreal merged commit d2a887f into alvinunreal:master Apr 9, 2026
mhenke pushed a commit to mhenke/oh-my-opencode-slim that referenced this pull request Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants