test: keep the project-root test inside its fixture when TMPDIR is under $HOME - #148
Merged
acidkill merged 1 commit intoAug 3, 2026
Conversation
…der $HOME
`test_relocated_global_config_dir_is_not_a_project_root` in
tests/unit/test_surface_path_and_decay.py fails on any machine whose TMPDIR
sits under the home directory:
assert detect_project_root() is None
E AssertionError: assert PosixPath('<$HOME>') is None
`detect_project_root` walks up from `Path.cwd()` and stops only when it
reaches `Path.home()` (surface/resolver.py:195-205). The test patches cwd to
`tmp_path/srv/data` and home to `tmp_path/home` -- a sibling of the walk, not
an ancestor of it -- so the walk never meets the patched home. It leaves
tmp_path, keeps climbing into the real home directory, finds a marker there
and returns it.
The marker it finds is usually `.surrealmemory`, which `detect_project_root`
checks first and which this tool creates in the home directory itself;
`package.json` is another one. Deleting either does not help, because the walk
then matches the other.
Anchoring the patched home at `tmp_path` keeps the walk inside the fixture.
The assertion is untouched and still says the same thing: the directory that
holds SURREAL_MEMORY_DIR must not be promoted to a project root.
Verified in both directions, because a test that cannot fail proves nothing:
TMPDIR under home, before -> 1 failed, 22 passed
TMPDIR under home, after -> 23 passed
TMPDIR=/tmp, after -> 23 passed
full suite, both TMPDIRs -> 6719 passed, 119 skipped, 1 xfailed
with the global-dir guard in surface/resolver.py deliberately removed, the
fixed test fails again under both TMPDIRs -- so it still catches the
regression it was written for.
No production code changes: walking up to the home directory is documented and
intended behaviour.
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.
Second of the three small things from our 3.0.3 migration. Test-only, and it cost us a
puzzled half-hour before we spotted what was going on — which is usually a sign it is worth
fixing for whoever hits it next.
Summary
TMPDIRsits under the home directory, because thecode under test walks out of the fixture and into the real filesystem.
Why
detect_project_root()walks up fromPath.cwd()and stops only when it reachesPath.home()(
src/surreal_memory/surface/resolver.py:195-205):test_relocated_global_config_dir_is_not_a_project_rootpatches cwd totmp_path/srv/dataandhome to
tmp_path/home. That home is a sibling of the walk, not an ancestor of it, so the walknever meets it. It climbs out of
tmp_path, into the real home directory, finds a marker thereand returns it:
The marker it finds is usually
.surrealmemory— checked first in the marker list, and createdin the home directory by this tool itself — or
package.json. Removing one does not help,because the walk then matches the other.
pytestputstmp_pathunderTMPDIR, so whether the test passes depends entirely on whetherthe developer's
TMPDIRhappens to be outside their home directory. The sibling test at line 48is unaffected because its cwd is the patched home, so it breaks out on the first iteration.
Changes
tests/unit/test_surface_path_and_decay.py— anchor the patchedhomeattmp_pathso thewalk terminates inside the fixture, with a comment stating why. The assertion, the global-dir
patching and what the test proves are all unchanged.
Type of Change
Test plan
pytest tests/ -m "not stress" -n autopasses locally — and now under both worlds:ruff check src/ tests/clean on 0.16.1. On 0.15.20 the tree still reports thepre-existing
S310inmcp/version_check_handler.py, which this branch does not touch.mypy src/ --ignore-missing-importsclean —Success: no issues found in 351 source files.Verified in both directions, because a test that cannot fail proves nothing. With the
global-config-dir guard in
surface/resolver.pydeliberately removed —Manual check: applies cleanly onto a pristine
v3.0.3tree.Checklist
demonstrated by the guard-removal run above.
matching
#137and#140. Say the word and I will add one.Related Issues
None.
Verified by
@RobertSigmundsson