Refuse to run this tree's tests against another tree's source - #121
Open
getnable wants to merge 1 commit into
Open
Refuse to run this tree's tests against another tree's source#121getnable wants to merge 1 commit into
getnable wants to merge 1 commit into
Conversation
finops is installed editable against ONE checkout. A git worktree gets its own
tests/ and its own src/, but `import finops` still resolves to whichever
checkout the install points at. So running pytest from a worktree pairs that
worktree's test FILES with the main checkout's CODE.
Nothing errors. You get a normal-looking run whose result is about neither tree,
and the failures it invents are indistinguishable from real ones.
That is not hypothetical. Today it produced two confident, opposite, wrong
conclusions about the same test inside an hour:
"test_priority_application_order_is_preserved fails on pristine main"
It does not. The tests were main's; the source was a feature branch.
"then fix/tag-attribution must have broken it"
It had not. That branch RENAMED the test to encode a corrected contract,
exactly as its commit message said. Running the old name against the new
code can only fail.
Both were reported before anyone noticed the trees were crossed, and one of them
reached a merged commit message on main.
pytest_configure compares where the tests are with where finops resolved, and
stops the run with one line if they disagree, rather than letting thousands of
meaningless failures scroll past. The message carries the exact PYTHONPATH that
fixes it, because the person hitting this does not yet know what is wrong and a
description of the problem would leave them to work it out.
FINOPS_TESTS_ALLOW_FOREIGN_SOURCE=1 opts out, for deliberately testing an
installed build rather than the working tree.
Verified three ways, in a real worktree: the trap is caught with the right
message, the correct invocation passes, and with the escape hatch set the run
reproduces the original misleading failure, which is the clearest possible
demonstration that the guard is catching something real.
CI is unaffected: the pytest job installs editable in the checkout it tests, so
the two paths already agree. The audit job installs non-editable and does not
run pytest.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
finopsis installed editable against one checkout. A git worktree gets its owntests/and its ownsrc/, butimport finopsstill resolves to whichever checkout the install points at.So running pytest from a worktree pairs that worktree's test files with the main checkout's code. Nothing errors. You get a normal-looking run whose result is about neither tree, and the failures it invents are indistinguishable from real ones.
This already cost something
Today it produced two confident, opposite, wrong conclusions about the same test inside an hour:
Both were reported before anyone noticed the trees were crossed, and one reached a merged commit message on
main(#119).The guard
pytest_configurecompares where the tests are with wherefinopsresolved, and stops with one line if they disagree, rather than letting thousands of meaningless failures scroll past:The message carries the exact fix, because whoever hits this doesn't yet know what's wrong and a description of the problem would leave them to work it out.
FINOPS_TESTS_ALLOW_FOREIGN_SOURCE=1opts out, for deliberately testing an installed build.Verified three ways, in a real worktree
PYTHONPATH)That third row is the point: with the guard disabled you get back exactly the phantom failure that caused the two wrong calls, which is the clearest demonstration that it's catching something real rather than being defensive for its own sake.
CI is unaffected
The pytest job installs editable into the checkout it tests, so the two paths already agree. The audit job installs non-editable and does not run pytest.
🤖 Generated with Claude Code