Skip to content

fix(xtask): binary path resolution and mutex poison recovery (#6)#15

Merged
EffortlessSteven merged 1 commit into
mainfrom
fix/xtask-binary-path
Apr 5, 2026
Merged

fix(xtask): binary path resolution and mutex poison recovery (#6)#15
EffortlessSteven merged 1 commit into
mainfrom
fix/xtask-binary-path

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Fix #6: xtask binary path resolution

Problem

cargo test -p xtask fails because CARGO_BIN_EXE_diffguard points 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 workspace target/debug/diffguard path; auto-build if missing
  • run_diffguard(): same validation of env var before using it

main.rs:

  • Add lock_env() helper that recovers from poisoned mutex (unwrap_or_else(|e| e.into_inner())) instead of panicking, preventing cascade failures between tests that use ENV_LOCK

Verification

  • xtask tests: 11 passed, 0 failed
  • CI simulation passes

@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 26 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 25 minutes and 26 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ca24aed1-1a50-4df4-a141-ac55f2cafde7

📥 Commits

Reviewing files that changed from the base of the PR and between e91df15 and 4a575ed.

📒 Files selected for processing (2)
  • xtask/src/conform_real.rs
  • xtask/src/main.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/xtask-binary-path

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread xtask/src/main.rs
Comment on lines +126 to +128
fn lock_env() -> std::sync::MutexGuard<'static, ()> {
ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner())
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Comment thread xtask/src/conform_real.rs
}

// Fall back to workspace-relative target/debug path
let _ = ensure_diffguard_built();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
let _ = ensure_diffguard_built();
ensure_diffguard_built().expect("failed to build diffguard binary");

Comment thread xtask/src/conform_real.rs
Comment on lines 1323 to 1332
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);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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().

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread xtask/src/conform_real.rs
.output()
.context("run diffguard")?;
return Ok(output);
if bin.contains("diffguard") && !bin.contains("xtask") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread xtask/src/conform_real.rs
}

// Fall back to workspace-relative target/debug path
let _ = ensure_diffguard_built();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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.
@EffortlessSteven EffortlessSteven merged commit c68890d into main Apr 5, 2026
9 of 10 checks passed
@EffortlessSteven EffortlessSteven deleted the fix/xtask-binary-path branch April 5, 2026 22:36
EffortlessSteven added a commit that referenced this pull request Apr 5, 2026
Bring in PRs #14 (config DAG support + field-wise defaults merge) and
#15 (xtask binary path resolution + mutex poison recovery) from main.

Conflict resolution: take HEAD (feat branch) changes for server.rs
which has the git diff timeout fix from PR #16 that is not yet on main.
EffortlessSteven added a commit that referenced this pull request Apr 6, 2026
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.
EffortlessSteven added a commit that referenced this pull request Apr 6, 2026
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.
EffortlessSteven added a commit that referenced this pull request Apr 6, 2026
* 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.
EffortlessSteven added a commit that referenced this pull request Apr 6, 2026
* 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
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.

fix: xtask conformance tests fail — binary path resolution broken

1 participant