Skip to content

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

Merged
brettheap merged 4 commits into
mainfrom
fix/naming-test-isolated-from-sibling-checkouts
Sep 11, 2026

Conversation

@brettheap

@brettheap brettheap commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

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:

$ ls -d ~/projects/openXdox ~/projects/openDox
/home/brett/projects/openDox
/home/brett/projects/openXdox

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 this: no GitHub runner has that sibling checkout, only a
workstation shaped a certain way does. scripts/repo_shape.py's rule 3 is
deliberate, 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 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 already 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 in the file falling through to
the cwd-derived root with 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_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 of the file already use (_tree(tmp_path / "openXdox", ...), a
few lines above this test). 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 reporting that 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 ... == (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 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 today
on unmodified main at cd57c4b — before and after this change:

# before (unmodified main, this worktree, under ~/projects)
$ 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

# after (this branch, same worktree, same location)
$ 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 (whole file): 158
passed
— no regressions from either change.

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 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 longer
reproduces from here either.

No --help text changed (only a test file is touched), so
scripts/render-cli-reference.py was not run; tests/test_cli_reference.py
is 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:

  • Isolate the unread-link warning test from the invoking working directory and environment so sibling checkouts or exported pin sources cannot alter its result.

Enhancements:

  • Split a composite naming assertion into separate checks so failures identify the missing workspace name.

Tests:

  • Update naming-policy tests to use temporary working-directory and link-source isolation while preserving the existing validation behavior.

…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]>
Copilot AI lite review requested due to automatic review settings September 11, 2026 20:33

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The 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

Change Details Files
Isolate the unread-link CLI test from the invoking process's working directory.
  • Add the tmp_path fixture and create a dedicated work directory.
  • Run the validator with the isolated directory as cwd so sibling checkout discovery cannot alter the result.
  • Retain assertions for successful classification and the expected unread-link warning.
tests/test_naming_policy.py
Split a compound diagnostic assertion into independent checks.
  • Assert each near-miss workspace name separately so failures identify the missing output.
tests/test_naming_policy.py

Assessment against linked issues

Issue Objective Addressed Explanation
#114 Make test_cli_reports_an_unread_link_as_a_warning_and_still_classifies deterministic by isolating the validator subprocess from any sibling openXdox or openDox checkout on the pytest process's working-directory path. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 cwd removes the sibling-checkout source, but run_script still inherits the parent environment (tests/conftest.py:100). resolve_link_source checks SHAPE_PIN_SOURCE_OPENXDOX before 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.

brettheap and others added 2 commits September 11, 2026 17:17
…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]>
Copilot AI review requested due to automatic review settings September 11, 2026 21:24
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openreposhape-2 (openRepoShape-2)

Answering Copilot's suppressed finding (review id 5183204764, 2026-09-11T20:35:46Z, at tests/test_naming_policy.py:714, no thread): it is real, and c30d9f4 fixes it.

The variable, and the lookup order it sits in

scripts/repo_shape.py:

def pin_source_env_name(product: str) -> str:
    return PIN_SOURCE_ENV_PREFIX + re.sub(r"[^A-Z0-9_]", "_", product.upper())

with PIN_SOURCE_ENV_PREFIX = "SHAPE_PIN_SOURCE_", so product="openXdox" names SHAPE_PIN_SOURCE_OPENXDOX — exactly what Copilot named.

resolve_link_source's docstring and body give the full order (scripts/repo_shape.py):

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, None

Rule 2 (the environment) is checked before rule 3 (the sibling checkout PR #120 already isolated by giving the test its own tmp_path cwd). tests/conftest.py's run_script starts every subprocess from {**os.environ, **(env or {})} — a COPY of the calling process's own environment — so a developer shell or CI box that happens to export SHAPE_PIN_SOURCE_OPENXDOX, pointed at a tree that declares openDox, satisfies rule 2 before rule 3 is ever reached, and the link verifies instead of staying unread. This machine's own ~/projects/openXdox is exactly such a tree (its project.yaml carries neutral_product_pins: [openDox]), which is how the finding was reproduced below rather than merely reasoned about.

Before / after proof

At 0007cef (this PR's tip before today's fix), with the ambient variable pointed at a real, verifying checkout:

$ SHAPE_PIN_SOURCE_OPENXDOX=/home/brett/projects/openXdox python3 -m pytest tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies -q
F
...
>       assert "WARNING codexDox: declared-unverified" in result.stderr
E       AssertionError: assert 'WARNING codexDox: declared-unverified' in ''
1 failed in 0.26s

After c30d9f4 (this test now passes its own env= override to run_script, pinning SHAPE_PIN_SOURCE_OPENXDOX to a path known to carry no manifest), the SAME command against the SAME real checkout:

$ SHAPE_PIN_SOURCE_OPENXDOX=/home/brett/projects/openXdox python3 -m pytest tests/test_naming_policy.py::test_cli_reports_an_unread_link_as_a_warning_and_still_classifies -q
.
1 passed in 1.47s

...and unset, exactly as CI runs it:

$ 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.42s

Full suite on c30d9f4: 985 passed, 1 skipped in 415.93s (0:06:55) — no other red.

Scope: only the one test

Grepped the file for every other place that could share the exposure. No other test does:

  • 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> for the SAME product they classify — rule 1 wins over rule 2 in resolve_link_source's own order regardless of what the environment holds, so neither is exposed.
  • test_an_unreadable_link_is_declared_unverified_and_still_classifies calls NamingPolicy.classify(...) directly with an explicit link_pins dict (or none) — it never calls run_script, resolve_link_source, or reads os.environ at all.
  • test_cli_reads_the_chain_out_of_a_project_manifest / test_cli_finds_a_recorded_chain_that_does_not_hold also resolve a link through rule 3 with no --link-source, but they assert the OPPOSITE direction (a real sibling tree that should verify, or should break) rather than an offline warning, so they are not the same exposure Copilot flagged; I left them as they are rather than widen this PR's diff.

One process note: a merge, not a rebase

Main moved twice under this PR today (to 9923fea then e9fa826, PR #121). I rebased first as asked, but git push --force-with-lease was rejected outright by this repo's non_fast_forward ruleset ("Cannot force-push to this branch") — that rule applies to this topic branch too, not only main. I reset back to the pushed tip and merged origin/main instead (506c499), which reconciles the same way without rewriting anything already on the remote. c30d9f4 (this fix) sits on top of that merge. Worth knowing for future rounds on this repo: a rebase that has already been pushed cannot be force-pushed back — merge instead.

Follow-up named, not done here

A general rule in run_script itself — blank every SHAPE_PIN_SOURCE_* variable unless the caller names it in env= — would close this whole class of exposure for every current and future test at once. Not done in this PR: tests/conftest.py is owned by PR #112 this round. Filing that follow-up is for after #112 lands.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes are focused test improvements with no unresolved blocking issues.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 11, 2026 21:43
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openreposhape-2 (openRepoShape-2)

Update: main moved again while the above was in review — PR #112 landed as 3d3c155. Merged (059a6cf), not rebased, for the same non_fast_forward-ruleset reason as before. It touches tests/conftest.py but not tests/test_naming_policy.py; this PR's fix is unaffected and re-verified on the merged tree:

$ SHAPE_PIN_SOURCE_OPENXDOX=/home/brett/projects/openXdox 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.59s
$ python3 -m pytest tests -q
1132 passed, 1 skipped in 451.15s (0:07:31)

(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 run_script now blanks LANES_LANE unless the caller names it —

    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 run_script mechanism to blank every SHAPE_PIN_SOURCE_* variable unless the caller names it in env= would fold this test's local workaround into the one place that already carries the identical pattern for LANES_LANE, and remove the need for any future test to know to defend itself. Naming it, not doing it here: tests/conftest.py was PR #112's this round, and is likely someone else's next.

Head is 059a6cf.

🤖 Generated with Claude Code

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues remain.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@brettheap
brettheap merged commit 8f72237 into main Sep 11, 2026
6 checks passed
@brettheap
brettheap deleted the fix/naming-test-isolated-from-sibling-checkouts branch September 11, 2026 22:07
brettheap added a commit that referenced this pull request Sep 12, 2026
…_* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/test_naming_policy.py: the unread-link warning test depends on whether a sibling openXdox checkout exists beside the worktree

2 participants