fix(xtask): binary path resolution and mutex poison recovery (#6)#15
Conversation
|
Warning Rate limit exceeded
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 25 minutes and 26 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the xtask utility to improve the resolution of the diffguard binary and enhances environment variable synchronization in tests. Key changes include a more robust cargo_bin_path logic and the introduction of a lock_env helper to handle poisoned mutexes. Review feedback highlights a potential race condition due to duplicate environment locks across modules, suggests handling build failures when locating the binary to avoid stale paths, and recommends refactoring duplicated path resolution logic for better maintainability.
| fn lock_env() -> std::sync::MutexGuard<'static, ()> { | ||
| ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()) | ||
| } |
There was a problem hiding this comment.
While this helper correctly handles mutex poisoning, note that a separate ENV_LOCK static is also defined in conform_real.rs (line 1466). Since environment variables are global to the process, having multiple independent locks for the same resource across different modules in the same crate allows tests to run concurrently while modifying the environment, which can lead to race conditions or crashes. Consider consolidating ENV_LOCK into a single shared static accessible by both modules to ensure proper synchronization.
| } | ||
|
|
||
| // Fall back to workspace-relative target/debug path | ||
| let _ = ensure_diffguard_built(); |
There was a problem hiding this comment.
The result of ensure_diffguard_built() is ignored here. If the build fails, the function will return a path that might point to a stale binary or a non-existent file, leading to confusing error messages in tests. Since this is a test utility, it's better to panic with a clear message if the prerequisite build fails, ensuring that tests run against the intended version of the code.
| let _ = ensure_diffguard_built(); | |
| ensure_diffguard_built().expect("failed to build diffguard binary"); |
| if let Ok(bin) = std::env::var("CARGO_BIN_EXE_diffguard") { | ||
| let output = Command::new(bin) | ||
| .args(args) | ||
| .current_dir(dir) | ||
| .output() | ||
| .context("run diffguard")?; | ||
| return Ok(output); | ||
| if bin.contains("diffguard") && !bin.contains("xtask") { | ||
| let output = Command::new(bin) | ||
| .args(args) | ||
| .current_dir(dir) | ||
| .output() | ||
| .context("run diffguard")?; | ||
| return Ok(output); | ||
| } | ||
| } |
There was a problem hiding this comment.
This logic for resolving the binary path from the environment variable is duplicated from cargo_bin_path(). To improve maintainability and ensure consistent behavior (especially regarding the xtask path validation), run_diffguard should ideally leverage cargo_bin_path() instead of re-implementing the check. Note that the manual path construction logic following this block is also duplicated in cargo_bin_path().
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab92fa09b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .output() | ||
| .context("run diffguard")?; | ||
| return Ok(output); | ||
| if bin.contains("diffguard") && !bin.contains("xtask") { |
There was a problem hiding this comment.
Match binary by filename instead of path substring
The !bin.contains("xtask") filter rejects valid CARGO_BIN_EXE_diffguard paths whenever any parent directory name includes xtask (for example a custom CARGO_TARGET_DIR like /tmp/xtask-target/.../diffguard). In that case run_diffguard() falls back to workspace_root()/target/debug/diffguard, which does not honor CARGO_TARGET_DIR, so the spawned binary can be missing even though Cargo provided a correct executable path. This makes conformance runs fail in otherwise valid environments.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| // Fall back to workspace-relative target/debug path | ||
| let _ = ensure_diffguard_built(); |
There was a problem hiding this comment.
Propagate build errors before returning a binary path
Ignoring ensure_diffguard_built() failures means cargo_bin_path() can still return target/debug/diffguard after a failed build, allowing callers to execute a stale binary from an earlier compile instead of failing immediately. In conform_real checks that invoke Command::new(cargo_bin_path()), this can hide current compile breakages and produce misleading pass/fail results.
Useful? React with 👍 / 👎.
Fix #6: xtask conformance tests fail due to wrong binary path. - cargo_bin_path(): check env var actually points to diffguard (not xtask), fall back to workspace target/debug, auto-build if missing - run_diffguard(): same check for env var before using it - Add lock_env() helper to recover from poisoned mutex in test ENV_LOCK, preventing cascade failures between xtask tests - xtask tests now run reliably from cargo test -p xtask All 11 xtask tests pass. Format clean, clippy clean.
ab92fa0 to
4a575ed
Compare
* chore: add flow/plan docs for PR #5 merge prep Archives the full reasoning trail for landing v0.2 enhancements: - Issue triage (#6-#13) - Fix PRs (#14, #15, #16) - Merge process, friction log, stats Index in .hermes/index.md for discoverability. * chore: consolidate agent context into .hermes/agent-context.md AGENTS.md, CLAUDE.md, GEMINI.md were 90% identical with minor wording differences. Canonicalized into single .hermes/agent-context.md with thin pointer files at root for agent discovery. Added .hermes/index.md entry for agent-context.md.
* chore: add flow/plan docs for PR #5 merge prep Archives the full reasoning trail for landing v0.2 enhancements: - Issue triage (#6-#13) - Fix PRs (#14, #15, #16) - Merge process, friction log, stats Index in .hermes/index.md for discoverability. * chore: consolidate agent context into .hermes/agent-context.md AGENTS.md, CLAUDE.md, GEMINI.md were 90% identical with minor wording differences. Canonicalized into single .hermes/agent-context.md with thin pointer files at root for agent discovery. Added .hermes/index.md entry for agent-context.md. * chore: add publish script and release notes for v0.2.0 * chore: clean up Cargo.toml package metadata for crates.io - Remove redundant exclude blocks (include is an allowlist, exclude is ignored) - Remove CLAUDE.md from include lists (thin pointers, not needed in packages) - Fix include/exclude conflict warning * chore: fix crate includes for crates.io, add publish workflow Remove ../../ paths from include fields (crates.io only packages crate-local files). Add GitHub Actions publish workflow triggered on v* tag push with verify → publish → release stages. * chore: remove include fields, let cargo use git-tracked defaults
Fix #6: xtask binary path resolution
Problem
cargo test -p xtaskfails becauseCARGO_BIN_EXE_diffguardpoints to the xtask test binary, not the actual diffguard binary when running tests from the xtask package.Changes
conform_real.rs:cargo_bin_path(): validate env var actually contains "diffguard" and not "xtask" before using it; fall back to workspacetarget/debug/diffguardpath; auto-build if missingrun_diffguard(): same validation of env var before using itmain.rs:lock_env()helper that recovers from poisoned mutex (unwrap_or_else(|e| e.into_inner())) instead of panicking, preventing cascade failures between tests that useENV_LOCKVerification