Skip to content

fix(test): locate CLI binary by target-dir depth, not fixed deps/ pop - #508

Merged
newhoggy merged 1 commit into
mainfrom
issue-507-ci-nightly-cargo-build-dir-v2-breaks-cli-bin
Jul 31, 2026
Merged

fix(test): locate CLI binary by target-dir depth, not fixed deps/ pop#508
newhoggy merged 1 commit into
mainfrom
issue-507-ci-nightly-cargo-build-dir-v2-breaks-cli-bin

Conversation

@newhoggy

Copy link
Copy Markdown
Contributor

Description

This PR fixes test suite failures on nightly Cargo builds caused by Cargo's new build-dir-layout-v2 directory structure. Nightly Cargo (from ~2026-07 onwards) changed the default build directory layout, nesting test binaries under target/<profile>/build/<pkg>/<hash>/out/ instead of the flat target/<profile>/deps/ structure. The CLI binary locator helper in four test suites was hardcoded to pop the deps/ directory component, resulting in incorrect paths and test failures.

The fix introduces a layout-agnostic path resolution strategy that locates the target directory component and derives <target>/<profile>/ from there, working correctly with both the legacy flat layout and the new nested build-dir-layout-v2.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Test coverage improvement
  • CI/CD changes

Related Issue

Fixes #507 - CI nightly Cargo build-dir-layout-v2 breaks CLI binary tests

Changes Made

Test Binary Path Resolution:

  • Replaced hardcoded deps/ path popping logic with a new target_profile_dir_from_test_exe() helper function in all four test suites
  • The new helper searches for the target path component and derives <target>/<profile>/ by collecting path components up to and including the profile directory
  • This approach works with both Cargo's classic flat layout (target/<profile>/deps/) and the new build-dir-layout-v2 nested layout (target/<profile>/build/<pkg>/<hash>/out/)

Files Modified:

  • tests/dsv_cli_tests.rs - Added target_profile_dir_from_test_exe() helper, refactored succinctly_bin() to use it
  • tests/json_validate_tests.rs - Added target_profile_dir_from_test_exe() helper, refactored succinctly_bin() to use it
  • tests/text_cli_tests.rs - Added target_profile_dir_from_test_exe() helper, refactored succinctly_bin() to use it
  • tests/yaml_validate_tests.rs - Added target_profile_dir_from_test_exe() helper, refactored succinctly_bin() to use it

Testing

Automated Testing:

  • All existing tests pass
  • Tests verified to work with Cargo's classic flat layout
  • Tests verified to work with Cargo's new build-dir-layout-v2 nested layout
  • Changes are backward compatible with stable Rust toolchains

Manual Testing:

  • Tested on x86_64
  • Test suites verified on nightly toolchain with build-dir-layout-v2

Test Commands

cargo test
cargo +nightly test
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check

Performance Impact

  • No performance impact - only affects test execution, not production code

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • Changes address the root cause of the nightly CI failures
  • New and existing tests pass locally
  • My changes generate no new warnings

Additional Notes

Root Cause Analysis:
Cargo's new build-dir-layout-v2 (rust-lang/cargo#17258) changes directory nesting but preserves the property that the profile directory immediately follows the target component in all paths. The original code assumed a fixed depth (always popping two levels to reach the profile directory), which broke under the new layout. By searching for the target component dynamically, we make the code resilient to both current and future Cargo layout changes.

Why This Solution:
This approach is layout-agnostic and doesn't rely on assumptions about directory depth. It will continue working if Cargo changes the layout again, as long as the target/<profile>/ ancestor relationship is maintained.

CI Impact:
This fix enables the full test suite to pass on nightly CI runs without requiring layout-specific workarounds or conditional compilation.

…s/ pop

Nightly Cargo defaulted to build-dir-layout-v2 (rust-lang/cargo#17258),
nesting test binaries under target/<profile>/build/<pkg>/<hash>/out/
instead of the flat target/<profile>/deps/. The succinctly_bin() helper
in dsv_cli_tests.rs, text_cli_tests.rs, json_validate_tests.rs, and
yaml_validate_tests.rs assumed the old layout and computed a bogus path,
failing all 4 suites on the nightly CI leg. Derive target/<profile>/ by
finding the `target` path component instead, which holds under both
layouts.
@github-actions

Copy link
Copy Markdown

Coverage

Total: 81.52% 🟢 0.01 pp vs main

Comparing 34532eb..bb41b9c (merge-base → PR head)

No per-file coverage changes vs main.

Patch coverage

No new executable lines added by this diff.

📦 Full per-file coverage summary · run summary

@github-actions

Copy link
Copy Markdown

Coverage

Total: 81.61% ⚪ 0 pp vs main

Comparing 34532eb..bb41b9c (merge-base → PR head)

No per-file coverage changes vs main.

Patch coverage

No new executable lines added by this diff.

📦 Full per-file coverage summary · run summary

@newhoggy
newhoggy marked this pull request as ready for review July 31, 2026 03:52
@newhoggy
newhoggy merged commit fffa123 into main Jul 31, 2026
23 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.

ci: nightly Cargo's build-dir-layout-v2 breaks CLI-binary-locating test helpers

1 participant