Repository navigation
tests/test_naming_policy.py: give the unread-link-warning test its own tmp_path so a sibling openXdox checkout cannot flip it, and split a composite assertion so a failure names which half broke (#114) - #120
Conversation
…n tmp_path so a sibling openXdox checkout cannot flip it, and split a composite assertion so a failure names which half broke (#114) Lane: openreposhape-2 (openRepoShape-2) Claim: #114 (comment) Closes #114. ## What was wrong `test_cli_reports_an_unread_link_as_a_warning_and_still_classifies` called `run_script(VALIDATOR, ...)` with no `cwd=`, so the validator subprocess inherited whatever directory pytest itself happened to be invoked from. `scripts/validate-repository-naming.py` reads that inherited directory at `here = Path.cwd()` (line 333) and hands it to every `Target` as `root`; `link_pins_from_trees` passes `root` straight into `resolve_link_source` (`scripts/repo_shape.py:1449`), whose rule 3 -- "a checkout sitting BESIDE this project" -- does `Path(root).resolve().parent / product`: it looks for a directory named `openXdox` beside wherever pytest's cwd was. On this workstation (and on anyone's, wherever both happen to be cloned side by side), `~/projects/openXdox` and `~/projects/openDox` are real checkouts, so running the suite from any checkout or worktree under `~/projects` satisfied rule 3, the link resolved against that real tree, and the `declared-unverified` warning the test asserts on never printed: ``` $ cd ~/projects/openRepoShape--naming-test-isolation && python3 -m pytest \ tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies -q F AssertionError: assert 'WARNING codexDox: declared-unverified' in '' 1 failed in 0.50s ``` The identical test, against the identical file, passed when pytest's own cwd had no `openXdox` sibling (e.g. run from `/tmp`) -- which is exactly why CI never saw it and it only bites a workstation shaped a certain way. `scripts/repo_shape.py`'s rule 3 is deliberate, digest-pinned behaviour and is not touched here: the defect is entirely that the test left its one machine-dependent input, the process's cwd, unset. I checked every other CLI invocation in the file that supplies a `--referent-chain` (the only ones that reach `resolve_link_source` at all): `test_cli_classifies_a_chain_given_on_the_command_line` and `test_cli_reports_a_broken_link_as_a_finding_naming_it` both pass an explicit `--link-source <product>=<path>`, which is rule 1 and is checked before rule 3 is ever reached, so neither depends on cwd. `test_cli_reads_the_chain_out_of_a_project_manifest` and `test_cli_finds_a_recorded_chain_that_does_not_hold` go through `--project <manifest>`, where `root` is derived from the manifest's own path (`path.resolve().parent`, always inside `tmp_path`) rather than from `Path.cwd()`. This test was the only one falling through to the cwd-derived `root` with nothing isolating it. ## What landed The test now takes the `tmp_path` fixture, creates a fresh `codexDox` directory under it, and runs the validator with `cwd=` set there -- mirroring the isolation the neighbouring Python-level tests in this same section already use (`_tree(tmp_path / "openXdox", ...)` a few lines above). `resolve_link_source`'s sibling lookup then resolves against `tmp_path` itself, which is fresh and unique per test run on every machine, so the outcome no longer depends on what anybody happens to have checked out beside the repository. `python:S9073` (composite assertion, `test_cli_refuses_a_near_miss_workspace_name`): `assert "brett--wip" in result.stderr and "brett-wip-2" in result.stderr` is now two separate assertions, so a failure names which of the two strings was missing instead of only "the `and` was false". `python:S3415` (assertion argument order), reviewed and NOT taken: I read every equality assertion in this file (126 lines matching `assert ... ==`, via `grep -nE '^\s*assert\s+[A-Za-z_][^=]*==' tests/test_naming_policy.py | wc -l` -> 126) plus the file's one other use of a variable literally named `expected` (line 1102). All of them, without exception, place the computed/actual expression on the left of `==` and the expected literal (or the `expected` variable) on the right -- there is no second, reversed convention anywhere in the file to unify toward. Forcing the alternative order would touch on the order of 126 lines file-wide, not "a handful", so per the brief's own guidance for this item I left it as is rather than manufacture an inconsistency to fix. ## The proof Single test, from this worktree under `~/projects` -- where it fails on unmodified `main` (verified above) -- after this commit: ``` $ python3 -m pytest tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies -q 1 passed in 0.49s ``` `python3 -m pytest tests/test_naming_policy.py -q`: **158 passed** (no regressions in the rest of the file). Full suite, foreground, from this worktree under `~/projects` (the exact location that reproduces the flake on unmodified `main`): `python3 -m pytest tests -q -p no:cacheprovider`: **985 passed, 1 skipped, 0 failed in 437.88s (0:07:17)** -- zero failures, including the one that is otherwise pre-existing from this location. No `--help` text moved (`scripts/render-cli-reference.py` was not run because no CLI surface was touched; `tests/test_cli_reference.py` is included in the full-suite run above and passed with it). Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.
You can request another review in 2 days and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.
|
@codex review |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR makes the unread-link warning test deterministic by isolating the validator subprocess cwd under tmp_path, preventing accidental sibling checkouts from changing link resolution, and improves failure diagnostics by splitting a compound assertion. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
🔵 Needs a closer look
Sanitize relevant pin-source environment variables so the warning test cannot be bypassed.
Pull request overview
This PR stabilizes naming-policy tests against workstation layout and improves assertion diagnostics.
Changes:
- Isolates the unread-link test in a temporary working directory.
- Splits the composite workspace-name assertion.
File summaries
| File | Summary |
|---|---|
tests/test_naming_policy.py |
Adds cwd isolation and clearer assertions; inherited pin-source environment variables still need sanitization. |
Review details
Suppressed comments (1)
tests/test_naming_policy.py:714
- Setting
cwdremoves the sibling-checkout source, butrun_scriptstill inherits the parent environment (tests/conftest.py:100).resolve_link_sourcechecksSHAPE_PIN_SOURCE_OPENXDOXbefore the cwd-based lookup, so a valid variable in a developer or CI environment can still verify the link and make this offline-warning assertion fail. Clear the relevant pin-source variables (or otherwise pass a sanitized environment) for this test as well.
cwd=workdir)
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ted-from-sibling-checkouts
…ses SHAPE_PIN_SOURCE_OPENXDOX, so a developer or CI environment that exports it cannot verify the link either (#114) PR #120 gave test_cli_reports_an_unread_link_as_a_warning_and_still_ classifies its own tmp_path cwd so a sibling ~/projects/openXdox checkout could no longer satisfy resolve_link_source's rule 3 (the sibling-checkout lookup) and silently turn the expected offline warning into a verified chain. Copilot's review of that PR (id 5183204764) named the other rule in the same function that reads the disk instead of an argument: rule 2, `SHAPE_PIN_SOURCE_<PRODUCT>` in the environment, checked BEFORE rule 3. run_script (tests/conftest.py) starts every subprocess from a COPY of the calling process's own environment, so a developer shell or CI box that exports SHAPE_PIN_SOURCE_OPENXDOX — pointed at a tree that really does declare openDox, the same shape ~/projects/openXdox has on this workstation — verifies the link the same way a sibling checkout would, and `assert "WARNING codexDox: declared-unverified" in result.stderr` fails. Reproduced against 0007cef: with that variable exported to the real ~/projects/openXdox, the test failed with `AssertionError: assert 'WARNING codexDox: declared-unverified' in ''`. The test now passes its own `env=` override to run_script, pinning SHAPE_PIN_SOURCE_OPENXDOX to a path known to carry no manifest, so the outcome cannot depend on what the calling environment exports. Proven against the same real checkout: the test now passes whether or not SHAPE_PIN_SOURCE_OPENXDOX is exported ambiently. No other test in the file shares the exposure: the two other CLI tests that resolve a link source (test_cli_classifies_a_chain_given_on_the_ command_line, test_cli_reports_a_broken_link_as_a_finding_naming_it) both pass an explicit --link-source for the same product, which wins over the environment in resolve_link_source's own order regardless of what is ambiently set, and the in-process test_an_unreadable_link_is_declared_unverified_and_still_classifies calls NamingPolicy.classify directly with an explicit link_pins dict, never reaching resolve_link_source or os.environ at all. A general rule in run_script itself — blank every SHAPE_PIN_SOURCE_* variable unless the caller names it — would close this class of exposure for every current and future test at once, but tests/ conftest.py is owned by PR #112 this round, so that belongs in a follow-up rather than here. Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Lane: openreposhape-2 (openRepoShape-2) Answering Copilot's suppressed finding (review id 5183204764, 2026-09-11T20:35:46Z, at The variable, and the lookup order it sits in
def pin_source_env_name(product: str) -> str:
return PIN_SOURCE_ENV_PREFIX + re.sub(r"[^A-Z0-9_]", "_", product.upper())with
def resolve_link_source(product: str, root: Path | None = None,
keyed_sources: dict | None = None,
default_source=None) -> tuple[Path | None, str | None]:
"""Where `product`'s own manifest can be read, if anywhere at all.
1. `--link-source <product>=<path>` (case-insensitive on the name)
2. `SHAPE_PIN_SOURCE_<PRODUCT>` in the environment
3. a checkout sitting BESIDE this project (`../openXdox`)
4. a bare `--link-source <path>` with no `product=` prefix
"""
candidates: list[tuple[Path, str]] = []
keyed = (keyed_sources or {}).get(product.casefold())
if keyed is not None:
candidates.append((Path(keyed), f"--link-source {product}=..."))
env_name = pin_source_env_name(product)
env_value = os.environ.get(env_name)
if env_value:
candidates.append((Path(env_value), f"${env_name}"))
if root is not None:
sibling = Path(root).resolve().parent / product
candidates.append((sibling, f"sibling checkout ({sibling})"))
...
for path, how in candidates:
if link_manifest_path(path) is not None:
return path, how
return None, NoneRule 2 (the environment) is checked before rule 3 (the sibling checkout PR #120 already isolated by giving the test its own Before / after proofAt After ...and unset, exactly as CI runs it: Full suite on Scope: only the one testGrepped the file for every other place that could share the exposure. No other test does:
One process note: a merge, not a rebaseMain moved twice under this PR today (to Follow-up named, not done hereA general rule in 🤖 Generated with Claude Code |
…ted-from-sibling-checkouts
|
Lane: openreposhape-2 (openRepoShape-2) Update: main moved again while the above was in review — PR #112 landed as (985→1132 passed is PR #112's own added tests, not this PR's doing.) This sharpens the conftest.py follow-up named above: PR #112's if "LANES_LANE" not in asked:
env["LANES_LANE"] = ""— for exactly the reason given here: an ambient value would make a test's outcome depend on whatever environment happens to run it. Generalizing that same Head is 🤖 Generated with Claude Code |
|
…_* variable unless the caller names it, so no test can be swayed by what the environment happens to export (#126) (#128) Closes #126. ## What was wrong `run_script` (`tests/conftest.py`) blanked one inherited environment variable, `LANES_LANE` (PR #112), but not the other family that changes tool output the same way: `SHAPE_PIN_SOURCE_<PRODUCT>` (`scripts/repo_shape.py`'s `PIN_SOURCE_ENV_PREFIX`), read by `resolve_link_source`'s rule 2 BEFORE rule 3, the cwd-derived sibling checkout. PR #120 hit this directly — Copilot found that `test_cli_reports_an_unread_link_as_a_warning_and_still_classifies` would verify a link it should report as declared-unverified whenever `SHAPE_PIN_SOURCE_OPENXDOX` happened to be exported at a real `openDox`-declaring checkout (exactly what `~/projects/openXdox` is on this workstation) — and fixed it locally, one test at a time, with both of its own review-thread comments naming the general fix as a follow-up left for after PR #112 landed and gave `run_script` the `LANES_LANE` mechanism to generalise. #126 is that follow-up. ## What landed `run_script` gets a second blanking rule beside `LANES_LANE`: every inherited environment variable whose name starts with `PIN_SOURCE_ENV_PREFIX` (imported from `scripts/repo_shape.py`, not re-spelled) is blanked to `""` unless THIS call's own `env=` names that exact variable — `""` because `resolve_link_source`'s `if env_value:` already reads an empty string as absent, the same convention `lane_trailer` already uses for an empty `LANES_LANE`. PR #120's own local `env=` override is now redundant and removed; its docstring points at two new proof tests. No digest-pinned file (see the repo-wide list in `AGENTS.md`) is touched by this PR. ## How it was proven Both new tests in `tests/test_naming_policy.py` are mutation-tested, not just written to pass once: - `test_run_script_blanks_an_inherited_pin_source_unless_named` — monkeypatches the ambient `SHAPE_PIN_SOURCE_OPENXDOX` to a tree that WOULD verify the link and asserts the warning still prints. Disabling the blanking loop turns it red (`assert 'WARNING codexDox: declared-unverified' in ''` — the link verifies instead); restored, it's green. - `test_run_script_still_passes_a_pin_source_the_caller_names` — a caller that DOES name the variable must still reach the child. Drafting it first with its verifying tree at the sibling path (`tmp_path / "openXdox"`) hid a real gap: a mutant that blanks EVERY `SHAPE_PIN_SOURCE_*` unconditionally (ignoring the caller's own `env=`) still left it green, because rule 3 found the same tree by accident. Moved to `elsewhere` (mirroring `test_a_link_source_names_the_tree_ explicitly`'s placement for the same reason, one rule earlier), the same mutant now turns it red too. Grepped `tests/` for every other caller that already names a `SHAPE_PIN_SOURCE_*` variable in its own `env=`: only `tests/test_neutral_pin_validator.py::test_a_neutral_pin_recomputes_from_ the_env_var`. Confirmed it still passes unchanged, and that the same unconditional-blanking mutant above turns it red too — it already carried its own regression coverage. Full suite, three foreground chunks from this worktree (`tests/test_naming_policy.py tests/test_update_shape.py tests/test_shape_doctor.py`; the next eleven files alphabetically; the last eleven): **1134 passed, 1 skipped**, no other red — PR #120's merged baseline (1132 passed, 1 skipped) plus this PR's two new tests. No known flake encountered. ## Summary by Sourcery Make test environment isolation cover all pin-source overrides so naming and validation tests depend only on their declared inputs. Bug Fixes: - Prevent inherited SHAPE_PIN_SOURCE_* environment variables from altering test subprocess results unless explicitly supplied by the test. - Keep explicitly requested pin-source overrides available to child processes while handling case-insensitive environment names safely. Enhancements: - Clear ambient pin-source variables for direct in-process naming-policy tests to keep link resolution hermetic. Tests: - Add regression and mutation-focused coverage for inherited and caller-supplied pin-source variables, including Windows-style case folding. (Squashed by the landing session from the pull request body; the branch carried five authored commits — the rule, Copilot's case-folding round, the direct-call tests, the shared clearer, and the shared predicate — plus one git-generated merge commit from catching up with main under a ruleset that refuses force-push.) Lane: openreposhape-2 (openRepoShape-2) Co-Authored-By: Claude Fable 5.1 <[email protected]>



Lane: openreposhape-2 (openRepoShape-2)
Claim: #114 (comment)
Closes #114.
What was wrong
test_cli_reports_an_unread_link_as_a_warning_and_still_classifiescalledrun_script(VALIDATOR, ...)with nocwd=, so the validator subprocessinherited whatever directory pytest itself happened to be invoked from.
scripts/validate-repository-naming.pyreads that inherited directory athere = Path.cwd()(line 333) and hands it to everyTargetasroot;link_pins_from_treespassesrootstraight intoresolve_link_source(
scripts/repo_shape.py:1449), whose rule 3 — "a checkout sitting BESIDEthis project" — does
Path(root).resolve().parent / product: it looks fora directory named
openXdoxbeside wherever pytest's cwd was.On this workstation (and on anyone's, wherever both happen to be cloned
side by side),
~/projects/openXdoxand~/projects/openDoxare realcheckouts:
So running the suite from any checkout or worktree under
~/projectssatisfied rule 3, the link resolved against that real tree, and the
declared-unverifiedwarning the test asserts on never printed:The identical test, against the identical file, passed when pytest's own
cwd had no
openXdoxsibling (e.g. run from/tmp) — which is exactly whyCI never saw this: no GitHub runner has that sibling checkout, only a
workstation shaped a certain way does.
scripts/repo_shape.py's rule 3 isdeliberate, digest-pinned behaviour and is not touched by this PR: the
defect is entirely that the test left its one machine-dependent input —
the validator subprocess's cwd — unset.
I checked every other CLI invocation in the file that supplies a
--referent-chain(the only ones that can reachresolve_link_sourceatall):
test_cli_classifies_a_chain_given_on_the_command_lineandtest_cli_reports_a_broken_link_as_a_finding_naming_itboth already passan explicit
--link-source <product>=<path>, which is rule 1 and ischecked before rule 3 is ever reached, so neither depends on cwd.
test_cli_reads_the_chain_out_of_a_project_manifestandtest_cli_finds_a_recorded_chain_that_does_not_holdgo through--project <manifest>, whererootis derived from the manifest's own path(
path.resolve().parent, always insidetmp_path) rather than fromPath.cwd(). This test was the only one in the file falling through tothe cwd-derived
rootwith nothing isolating it.What landed
No digest-pinned file is touched by this PR — only
tests/test_naming_policy.py,which carries no pin.
The test now takes the
tmp_pathfixture, creates a freshcodexDoxdirectory under it, and runs the validator with
cwd=set there —mirroring the isolation the neighbouring Python-level tests in this same
section of the file already use (
_tree(tmp_path / "openXdox", ...), afew lines above this test).
resolve_link_source's sibling lookup thenresolves against
tmp_pathitself, which is fresh and unique per test runon every machine, so the outcome no longer depends on what anybody
happens to have checked out beside the repository.
python:S9073(composite assertion,test_cli_refuses_a_near_miss_workspace_name):assert "brett--wip" in result.stderr and "brett-wip-2" in result.stderris now two separateassertions, so a failure names which of the two strings was missing
instead of only reporting that the
andwas false.python:S3415(assertion argument order), reviewed and not taken: Iread every equality assertion in this file — 126 lines matching
assert ... ==(grep -nE '^\s*assert\s+[A-Za-z_][^=]*==' tests/test_naming_policy.py | wc -l→ 126) — plus the file's one other use of a variable literally namedexpected(line 1102). All of them, without exception, place thecomputed/actual expression on the left of
==and the expected literal(or the
expectedvariable) on the right; there is no second, reversedconvention anywhere in the file to unify toward. Forcing the opposite
order across the file would touch on the order of 126 lines, not "a
handful of asserts", so per the brief's own guidance for this item I left
it as is rather than manufacture an inconsistency to fix. Named here with
the count, as asked.
How it was proven
Single test, from this worktree under
~/projects— where it fails todayon unmodified
mainatcd57c4b— before and after this change:python3 -m pytest tests/test_naming_policy.py -q(whole file): 158passed — no regressions from either change.
Full suite, foreground, from this worktree under
~/projects— the exactlocation that reproduces the flake on unmodified
main—python3 -m pytest tests -q -p no:cacheprovider: 985 passed, 1 skipped,0 failed in 437.88s (0:07:17). Zero failures, including the one the
fan-out brief calls out as pre-existing and location-dependent from any
worktree under
~/projects: this PR is that flake's fix, so it no longerreproduces from here either.
No
--helptext changed (only a test file is touched), soscripts/render-cli-reference.pywas not run;tests/test_cli_reference.pyis part of the full-suite run above and passed with it.
🤖 Generated with Claude Code
Summary by Sourcery
Make naming-policy tests deterministic and improve failure diagnostics.
Bug Fixes:
Enhancements:
Tests: