Bug fix: bazel-bin/library/tests/dtest -f NNNN did not work when invoked from the repo root - #280
Bug fix: bazel-bin/library/tests/dtest -f NNNN did not work when invoked from the repo root#280tameware wants to merge 12 commits into
Conversation
Running from outside the repo (or via bazel-bin) no longer depends on the old ../hands/ layout; look up listN.txt under ./hands first, then relative to bazel-bin/library/tests without following the bazel-bin symlink. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Not ready to approve
The new path helpers export unnecessary global symbols and the normalization/absolute-path logic has portability pitfalls (notably POSIX \\ handling and mixed separators on Windows).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR updates dtest’s -f/--file handling so numeric inputs (e.g. -f 100) can be resolved reliably from either the current working directory’s hands/ tree or a hands/ directory relative to the dtest binary location, and adds unit tests covering the resolution behavior.
Changes:
- Added
resolve_dtest_input_file()and updatedread_args()to use it for-f/--fileresolution (cwd-first, then binary-relative fallback). - Updated
dtestusage text to document the new lookup behavior. - Expanded
args_testto cover literal-path preference, cwd preference, binary-relative fallback, and relativeargv0cases.
File summaries
| File | Description |
|---|---|
library/tests/args.hpp |
Declares resolve_dtest_input_file() and documents the new lookup order. |
library/tests/args.cpp |
Implements path resolution helpers and switches -f parsing to use the resolver; updates help text. |
library/tests/args_test.cpp |
Adds GoogleTest coverage for the new resolver behaviors and edge cases. |
Review details
Suppressed comments (2)
library/tests/args.cpp:212
normalize_logical_path()is only used within args.cpp. Mark itstatic(or put it in an unnamed namespace) to avoid leaking internal helper symbols into the global link namespace.
string normalize_logical_path(const string& path)
library/tests/args.cpp:289
absolute_path_logical()is an implementation detail used only byresolve_dtest_input_file(). Marking itstatickeeps the symbol local to this translation unit.
string absolute_path_logical(const string& path)
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
bazel run sets CWD to the runfiles tree, so ./hands is missing; consult BUILD_WORKING_DIRECTORY then BUILD_WORKSPACE_DIRECTORY before the binary-relative fallback. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep is_absolute_path, normalize_logical_path, and absolute_path_logical TU-local so they are not exported as global symbols. Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid mixed \\ and / on Windows in normalize_logical_path output. Co-authored-by: Cursor <cursoragent@cursor.com>
A leading backslash is a normal filename character on POSIX, so do not classify it as an absolute path when normalizing argv0. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Not ready to approve
The new tests modify Bazel environment variables without restoring prior values, and one updated error message is inconsistent with the actual resolution behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (3)
library/tests/args_test.cpp:216
- This test mutates
BUILD_WORKING_DIRECTORY/BUILD_WORKSPACE_DIRECTORYbut does not restore any pre-existing values afterwards (it only clears one variable). Preserve and restore the prior environment to avoid cross-test interference when these variables are set externally.
#ifdef _WIN32
_putenv_s("BUILD_WORKING_DIRECTORY", "");
_putenv_s("BUILD_WORKSPACE_DIRECTORY", root_.c_str());
#else
ASSERT_EQ(unsetenv("BUILD_WORKING_DIRECTORY"), 0);
library/tests/args.cpp:436
- The error message after failing to resolve
-fomits theBUILD_WORKING_DIRECTORY/BUILD_WORKSPACE_DIRECTORYfallbacks thatresolve_dtest_input_file()actually tries, which can mislead users running underbazel run. Update the message to match the resolution order described in usage/docs.
cout << "Also tried hands/list" << optarg <<
".txt under the current directory and relative to the "
"dtest binary\n";
library/tests/args_test.cpp:203
- This test mutates
BUILD_WORKING_DIRECTORY/BUILD_WORKSPACE_DIRECTORYbut only clears them at the end, which can break other tests if the variables were already set in the environment. Save the previous values and restore them after the assertion.
This issue also appears on line 212 of the same file.
#ifdef _WIN32
_putenv_s("BUILD_WORKING_DIRECTORY", root_.c_str());
_putenv_s("BUILD_WORKSPACE_DIRECTORY", "");
#else
ASSERT_EQ(setenv("BUILD_WORKING_DIRECTORY", root_.c_str(), 1), 0);
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Prevent cross-test interference by saving/restoring BUILD_* directories, and mention those fallbacks in the missing-input message. Co-authored-by: Cursor <cursoragent@cursor.com>
…ndows. TempDir and the resolver mix / and \\; normalize absolute candidates and treat them as equal in tests. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Not ready to approve
The new Windows absolute-path detection can misclassify UNC and drive-relative paths, which can break argv0-relative fallback resolution on Windows.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (2)
library/tests/args.cpp:212
- On Windows,
is_absolute_path()treats anyC:prefix as absolute and does not recognize UNC paths (\\server\share\...///server/share/...). This can causeabsolute_path_logical()/resolve_dtest_input_file()to compute the wrong base directory whenargv0is a UNC path or a drive-relative path likeC:bin\\dtest(which is not actually absolute on Windows). Consider tightening the drive-letter check to require a root separator and adding UNC handling.
#ifdef _WIN32
return path.size() >= 2 && std::isalpha(static_cast<unsigned char>(path[0])) &&
path[1] == ':';
#else
return path[0] == '/';
library/tests/args_test.cpp:61
make_dir()ignores errors from_mkdir/mkdir. If directory creation fails for reasons other than already-existing paths (permissions, invalid/mixed separators on Windows, etc.), the tests will continue and later fail in less obvious ways. Consider makingmake_dir()report failure (e.g., return bool/int andASSERT_*at each call site) or explicitly handle EEXIST vs other errors.
void make_dir(const std::string& path)
{
#ifdef _WIN32
_mkdir(path.c_str());
#else
mkdir(path.c_str(), 0755);
#endif
}
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Require a root separator (and recognize UNC) so drive-relative argv0 is not treated as rooted, and assert directory creation in the path-resolution tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Run from the fake binary directory without hands/ and clear Bazel env vars so X:dtest exercises drive-relative resolution. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Not ready to approve
Windows root-relative paths like \repo\... are currently misclassified as non-absolute in the new absolute-path logic, which can break the binary-relative fallback for some valid invocation styles.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (2)
library/tests/args.cpp:250
- On Windows, paths rooted at the current drive like
\repo\bazel-bin\...(leading single backslash, not UNC) are considered absolute by Win32 path semantics, butis_absolute_path()currently treats them as relative. This can causeabsolute_path_logical(argv0)to prepend the current working directory and break the binary-relative fallback when dtest is invoked with a root-relative argv0.
if (is_unc_path(path))
return true;
// Drive-rooted absolute: "C:\..." or "C:/...". "C:foo" is drive-relative.
return path.size() >= 3 &&
std::isalpha(static_cast<unsigned char>(path[0])) &&
library/tests/args.hpp:48
- The
is_dtest_absolute_path()doc comment describes Windows absolute paths as onlyC:\.../C:/...or UNC. Ifis_absolute_path()is updated to also treat rooted current-drive paths like\path\to\fileas absolute, the header comment should reflect that so the contract is accurate for callers and tests.
/// True for a rooted absolute path: POSIX `/...`, Windows `C:\...` / `C:/...`,
/// or UNC `\\server\share\...` / `//server/share/...`. Drive-relative forms
/// like `C:bin\dtest` are not absolute.
bool is_dtest_absolute_path(const std::string& path);
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Leading \ or / (non-UNC) must not be joined to cwd; expand with the cwd drive letter and document the contract in tests. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Not ready to approve
The new make_dir() test helper returns success on EEXIST even if the path is a file, which can mask fixture setup errors and should be corrected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
library/tests/args_test.cpp:67
make_dir()treatserrno == EEXISTas success even ifpathexists as a regular file, which contradicts the comment and can mask fixture setup errors. Verify the existing path is actually a directory before returning true.
return errno == EEXIST;
}
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Avoid treating a regular file at the path as a successful mkdir in the args path-resolution tests. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Not ready to approve
args_test.cpp uses S_ISDIR in new code, which is not reliably available on Windows/MSVC and can cause build failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
library/tests/args_test.cpp:63
path_is_directory()usesS_ISDIR, which is not guaranteed to be available on Windows/MSVC (it’s a POSIX macro). This can break Windows builds ofargs_test. UseS_IFMT/S_IFDIRunder_WIN32(both provided by<sys/stat.h>), and keepS_ISDIRfor POSIX.
bool path_is_directory(const std::string& path)
{
struct stat st;
if (stat(path.c_str(), &st) != 0)
return false;
return S_ISDIR(st.st_mode);
}
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟢 Ready to approve
The updated resolution logic matches the stated requirements and is covered by targeted unit tests for the key invocation scenarios.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Summary
-f NNNNfindhands/listNNNN.txtunder the current directory firsthands/directory relative tobazel-bin/library/tests/dtest, without walking through thebazel-binsymlink into the execrootargv0inargs_testTest plan
bazel test //library/tests:args_testbazel build //library/tests:dtest && ./bazel-bin/library/tests/dtest -f 1 -s solve -n 1(cd /tmp && \"$REPO/bazel-bin/library/tests/dtest\" -f 1 -s solve -n 1)succeedsbazel run //library/tests:dtest -- -f 100Made with Cursor