Skip to content

fix(test-emu): fail-fast and corruption-aware avr8js npm cache#105

Merged
zackees merged 1 commit intomainfrom
fix/avr8js-cache-hardening-86
Apr 18, 2026
Merged

fix(test-emu): fail-fast and corruption-aware avr8js npm cache#105
zackees merged 1 commit intomainfrom
fix/avr8js-cache-hardening-86

Conversation

@zackees
Copy link
Copy Markdown
Member

@zackees zackees commented Apr 18, 2026

Closes #86.

fbuild test-emu --emulator avr8js failed with Node ERR_MODULE_NOT_FOUND when ~/.fbuild/cache/avr8js-node/node_modules/avr8js/ was missing or corrupt. Root cause: ensure_avr8js_npm's exists() check accepted a directory that lacked package.json.

Changes

  • Integrity marker: require node_modules/avr8js/package.json as the proof of a non-corrupt install. If the dir exists but the marker doesn't, wipe and reinstall.
  • Error messages: when npm is not on PATH or install exits non-zero, capture both stdout and stderr and name the cache dir.
  • New env var FBUILD_REFRESH_EMU_CACHE=1 forces reinstall regardless of marker state (accepts 1|true|TRUE|yes|YES).
  • Fail-fast logging before spawning node when the cache state is still bad.

Node-spawn audit

Two spawn sites: find_node() (probes node --version, no avr8js needed) and run_avr8js_headless(). Both callers (deploy_avr8js, Avr8jsRunner::run) already called ensure_avr8js_npm() first — no bypass. The real gap was the integrity check.

Test plan

  • uv run cargo test -p fbuild-daemon --lib — 107 passing
  • uv run cargo clippy --workspace --all-targets -- -D warnings
  • uv run cargo fmt --all

Deferred

  • CLI flag --refresh-emu-cache plumbed through TestEmuRequest (env var works but needs daemon restart)
  • find_node() still returns a bare node/node.exe PathBuf rather than an absolute resolved path — minor race window between probe and spawn if PATH changes

🤖 Generated with Claude Code

…#86)

- ensure_avr8js_npm now verifies node_modules/avr8js/package.json exists,
  not just the dir; wipes a corrupt partial install before reinstalling.
- Error when npm is unresolvable names 'npm', the cache dir, and the new
  FBUILD_REFRESH_EMU_CACHE recovery hint.
- Capture both npm stdout and stderr on non-zero exit (previously only
  stderr was surfaced).
- Fail-fast in run_avr8js_headless: re-verify the cache is intact right
  before spawning Node, with a clear "avr8js cache not populated at <path>;
  aborting" log instead of a cryptic ERR_MODULE_NOT_FOUND from Node.
- Add FBUILD_REFRESH_EMU_CACHE=1 env to force a clean reinstall. Env-var
  only for now; daemon must be restarted for it to take effect. CLI flag
  not wired (would require daemon-client plumbing; env is sufficient).
- Tests: PATH-minus-npm produces the specific error; corrupt cache
  triggers a wipe before reinstall; predicate unit tests for cache
  integrity and prep outcomes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@zackees has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 57 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 22 minutes and 57 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bedcb10b-61d3-48c4-bc2d-42d5b0ebdb5c

📥 Commits

Reviewing files that changed from the base of the PR and between d37995b and a7efbb6.

📒 Files selected for processing (1)
  • crates/fbuild-daemon/src/handlers/emulator.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/avr8js-cache-hardening-86

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees zackees merged commit 16cea64 into main Apr 18, 2026
74 of 77 checks passed
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.

test-emu --emulator avr8js: auto npm install fails silently with ERR_MODULE_NOT_FOUND

1 participant