The tests were passing in the pants repo because rule_runner.py had an explicit dependency on //BUILD_ROOT:files. So, the BUILD_ROOT file was added to the pytest sandbox for every RuleRunner-based test. Removing the rule_runner.py dependency on //BUILD_ROOT:files causes the RuleRunner-based tests to fail in the pants repo as well.
This issue was exposed because the rust-based NativeOptionParser does not provide an API for overriding the BuildRoot, unlike the python layer which uses a singleton BuildRoot object and allows RuleRunner to replace the build_root, bypassing the sentinel file-lookup logic. The NativeOptionParser requires either the PANTS_BUILDROOT_OVERRIDE env var or a sentinel file (one of BUILD_ROOT, BUILDROOT, or pants.toml) in the current working directory (or a parent of the current working directory) to calculate the build_root.
This PR:
Removes dependencies on //BUILD_ROOT:files for some tests that do not actually require it.
Removes the explicit dependency on //BUILD_ROOT:files from testutil/rule_runner.py.
Makes RuleRunner change the current working directory to the temporary build_root directory while bootstrapping options (ie for the codepaths that initialize the rust-based NativeOptionParser).
Makes RuleRunner add the sentinel file in the temporary build_root directory that RuleRunner creates so NativeOptionParser can find it in the current working directory.
Adds a RuleRunner.pushd() api method to allow tests to change the current directory to RuleRunner.build_root.
Adds dependencies on //BUILD_ROOT:files for tests that relied on the transitive dep via testutil/rule_runner.py. These tests either did not use RuleRunner (eg they only used mock_console), or relied on working in the sandbox with the actual pants code under test (meaning the pytest sandbox IS the build_root for that test).
After #20887 (pants 2.22.0.dev2),
RuleRunner
-based tests do not work in external repos: https://pantsbuild.slack.com/archives/C0D7TNJHL/p1719344475216619This test run shows the
ValueError
s that show up inRuleRunner
-based tests: https://github.com/StackStorm/st2/actions/runs/9667956659/job/26670955784The tests were passing in the pants repo because
rule_runner.py
had an explicit dependency on//BUILD_ROOT:files
. So, theBUILD_ROOT
file was added to the pytest sandbox for everyRuleRunner
-based test. Removing therule_runner.py
dependency on//BUILD_ROOT:files
causes theRuleRunner
-based tests to fail in the pants repo as well.This issue was exposed because the rust-based
NativeOptionParser
does not provide an API for overriding theBuildRoot
, unlike the python layer which uses a singletonBuildRoot
object and allows RuleRunner to replace the build_root, bypassing the sentinel file-lookup logic. TheNativeOptionParser
requires either thePANTS_BUILDROOT_OVERRIDE
env var or a sentinel file (one ofBUILD_ROOT
,BUILDROOT
, orpants.toml
) in the current working directory (or a parent of the current working directory) to calculate the build_root.This PR:
//BUILD_ROOT:files
for some tests that do not actually require it.//BUILD_ROOT:files
fromtestutil/rule_runner.py
.RuleRunner
change the current working directory to the temporary build_root directory while bootstrapping options (ie for the codepaths that initialize the rust-basedNativeOptionParser
).RuleRunner
add the sentinel file in the temporary build_root directory thatRuleRunner
creates soNativeOptionParser
can find it in the current working directory.RuleRunner.pushd()
api method to allow tests to change the current directory toRuleRunner.build_root
.//BUILD_ROOT:files
for tests that relied on the transitive dep viatestutil/rule_runner.py
. These tests either did not useRuleRunner
(eg they only usedmock_console
), or relied on working in the sandbox with the actual pants code under test (meaning the pytest sandbox IS the build_root for that test).