feat(rust): relax project root path validation - #154
Open
nizos wants to merge 8 commits into
Open
Conversation
Owner
Author
|
@104hp6u Can I get a review on this? :) |
Introduces resolve_project_root using std::fs::canonicalize to handle absolute, relative, and `..` paths uniformly. Defaults to cwd when no project root is provided. Not yet wired into main — existing validation in main() is unchanged. Note: tests that mutate cwd require --test-threads=1 to avoid races. Per ADR-009. Refs #139. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a base_dir parameter so relative paths resolve against an explicit directory instead of the process-global cwd. This makes the function pure and allows tests to run in parallel without cwd mutation races. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t optional Extracts main() logic into a testable run(args, base_dir) function that uses resolve_project_root for path handling. The --project-root flag is now optional — omitting it defaults to the current working directory. base_dir is injected for testability so tests use isolated temp dirs with no global cwd mutation. Per ADR-009. Refs #139. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Introduces TestContext struct with setup(), with_sub_dir(), test_json_path(), read_test_output(), process_and_read(), and make_args(). Consolidates repeated temp dir creation, path construction, file reading, and JSON parsing. Helpers placed at bottom of the test module, tests at the top. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove unnecessary borrow in detect_runner args, derive Default instead of manual impl for TddGuardOutput, simplify identical if/else branches in reason logic, use .first() instead of .get(0), and remove unused has_test_pass variable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update examples, flag description, and project root documentation to reflect that --project-root is now optional and accepts relative paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reads TDD_GUARD_PROJECT_ROOT as a fallback when no --project-root flag is provided. Errors when neither is configured instead of silently defaulting to cwd, which caused test results to land in the wrong directory when tests ran from a subdirectory. Per ADR-010. Refs #139. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nizos
force-pushed
the
feat/139-rust-relax-project-root
branch
from
April 12, 2026 10:32
21f66ff to
7fc7479
Compare
3 tasks
Owner
Author
|
Can I get a review on this @vnsamy-code @Hiro-Chiba? :) |
Contributor
|
Looks great to me! I was wondering if all the reporter tests should include a test for this behaviour: "TDD_GUARD_PROJECT_ROOT environment variable is read when no --project-root flag is provided. "
|
nizos
pushed a commit
that referenced
this pull request
May 10, 2026
Apply ADR-009 and ADR-010 to the Ruby reporters, mirroring PR #151 (PHPUnit), #153 (Go), and #154 (Rust): - Accept relative paths and paths containing "..", resolved with File.expand_path against the working directory. - Raise ArgumentError when TDD_GUARD_PROJECT_ROOT is not configured instead of silently defaulting to cwd. Per ADR-010, this is an intentional breaking change so misconfiguration surfaces upfront. - Preserve the cwd-within-root sanity check on the resolved path, using File.realpath to canonicalize symlinks (macOS /var -> /private/var) so comparisons are stable. The Minitest reporter's `.handle_load_error` and `.append_unhandled_errors` class methods rescue the configuration ArgumentError so the autorun at_exit hooks do not double-raise when the env var is missing. Closes #173, #174.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Rust reporter no longer requires an absolute path for
--project-root, and the flag itself is now optional. Relative paths and paths containing..are resolved against the current working directory. The reporter now readsTDD_GUARD_PROJECT_ROOTas a fallback and errors when no project root is configured.Details
std::fs::canonicalizehandles absolute, relative, and..paths uniformly, replacing the previousis_absoluteandexistschecks inmain().TDD_GUARD_PROJECT_ROOTenvironment variable is read when no--project-rootflag is provided. When neither is configured, the reporter errors with a descriptive message.main()logic is extracted into a testablerun(args, base_dir)function.base_diris injected so tests use isolated temp dirs without global cwd mutation, allowing parallel execution.TestContextstruct consolidates repeated test setup — temp dir creation, path construction, file reading, and JSON parsing — into a builder with helpers at the bottom of the test file.Notes