fix(scripts): anchor webconsole_seam_snapshot.py on its own repo, not on sys.path (BACKLOG #1439) - #826
Merged
Merged
Conversation
… on sys.path (BACKLOG #1439) The generator derived the seam digest from whichever `messagefoundry` sys.path happened to offer, while reading _CONSOLE_DIR and _ENGINE_DIR out of the repository it lives in. Run from a git worktree with no .venv of its own -- the normal state for these sessions -- those are two different trees. Python puts the SCRIPT's directory on sys.path[0], never the caller's cwd, so `scripts/` led the path and the import fell through to site-packages: the primary checkout's, via its path-based editable install (_editable_impl_messagefoundry.pth holds the primary root). The failure was silent and it pointed the wrong way. Measured 2026-09-03 in a worktree with no .venv of its own: `--write` printed the primary tree's digest 93ba1f10b9dccfc8, rewrote both files with that unchanged value, and reported success naming both, while tests/test_webconsole_seam_snapshot.py kept failing against 266cbfd342b22819 -- a digest the script had never computed. The only loud word was "rewrote", so the repair on offer was to a gate that was right. This is the SDS-3.8 shape: an instrument answering an adjacent question. The fix is the sys.path insert three sibling scripts already carry, above the `from messagefoundry...` imports, citing the rule scripts/coord/alloc.ps1 states for `git` (#1060): anchor on the script, not on the caller. Two tests, because the obvious one is not enough: test_the_script_run_by_path_computes_the_same_digest runs the generator as a subprocess, by path, from a cwd that is not the repo root and with PYTHONPATH scrubbed. Both scrubs are load-bearing: under pytest the root is already on sys.path, so every in-process check in that file is blind to this defect by construction. test_the_script_prefers_its_own_repo_over_an_earlier_path_entry supplies a second engine tree itself -- a decoy messagefoundry package on PYTHONPATH, which for a by-path invocation sits ahead of site-packages and behind an explicit sys.path.insert(0, repo_root). It reds if and only if the anchor is gone, on any machine. The first test cannot carry that weight: one tree on a hosted runner means an unanchored script is right by luck, and measured here it stayed green with the anchor deleted, because this box's two trees currently carry the same seam. Census of scripts/ for the same class: six .py files import an in-repo top-level package. Three already anchor on __file__ (bench/stage_residency.py, security/dast_auth_sweep.py, tray/make_icons.py). Two are libraries with no __main__ reached only as scripts.security.X, so they inherit a corrected path and are not exposed (security/dast_target.py, security/route_gates.py). This was the only one. Verification: 8 passed in tests/test_webconsole_seam_snapshot.py. Mutation check run rather than argued -- anchor deleted, the decoy test reds naming the decoy import; anchor restored, 8 passed. ruff check and ruff format --check clean on both files; the 4 mypy findings in the test file are pre-existing (identical at HEAD) and tests/ is outside CI's mypy scope. The seam constant and the golden are deliberately untouched: the contract did not move. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ved resolution Three peer sessions raised the same methodological point independently: a script can resolve to the correct tree today for a reason that has nothing to do with the script, so a census keyed on "which tree did it resolve to" clears every script whose cwd currently rescues it. Verified here, one interpreter, one command, three working directories. From a worktree root `python -c "import messagefoundry"` resolves to the WORKTREE, because cwd is sys.path[0] and precedes the editable install. From the primary root or a neutral cwd the same command resolves to the primary. A by-path script resolves to the primary from everywhere. That is this defect's mirror image: a by-path script reads the primary because nothing anchors it, a bare interpreter reads the worktree because cwd happens to win, and both are the same missing anchor. Only one of them looks wrong. The fleet's recipe for a .venv-less worktree depends entirely on that rescue. The census table was already keyed on the anchor rather than on resolution, but the item did not say so, and a future reader re-running it could reasonably key it the other way. It says so now. Also re-derived the table by AST on the predicate "imports an in-repo package AND is runnable by path AND puts nothing on sys.path". It agreed with the reading exactly. Positive control, since a pattern that finds nothing anywhere is indistinguishable from a clean tree: 53 .py files under scripts/, 28 deriving a path from __file__, 6 importing an in-repo package. Control on the instrument itself: against the parent commit the census flags webconsole_seam_snapshot.py as EXPOSED and nothing else; against the fix it reports none. Two further corrections to the record: The two library modules are structurally safe, not accidentally safe. The scripts.security.X import form cannot resolve unless the repo root is already importable, so the root supplying the module necessarily supplies its messagefoundry. One tree by construction, not by cwd. Added what the census could NOT see: its scope is scripts/**/*.py only, its runnability test is a __main__ guard which would misjudge a module invoked by path without one, and it says nothing about the wider class the peers named. No code change. The fix, both tests and the seam value are untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
Author
|
LANDER: applying SO READ THIS LABEL AS A BYPASS TOKEN, NOT A REVIEW. It records that the gate was cleared by instruction. It does not assert that anyone read this diff, and no later reader should infer one from it. What I can say: this PR appeared in a read-only pre-verification sweep of all 59 non-draft open PRs (per-PR defect read, plus pairwise -- Lander |
Both sides append a new section at the same point in docs/BACKLOG.md, under different item numbers. Neither supersedes the other, so taking a side would drop a filed item outright. Both blocks are kept, in the ascending item order the file already uses. Verified with parse_items from scripts/docs/backlog_status_check.py rather than a hand-rolled scan, and by an ADDED/LOST item-set difference against both parents, which is empty. A count alone would not catch two blocks folding into one.
Both sides append a new section at the same point in docs/BACKLOG.md, under different item numbers. Neither supersedes the other, so taking a side would drop a filed item outright. Both blocks are kept, in the ascending item order the file already uses. Verified with parse_items from scripts/docs/backlog_status_check.py rather than a hand-rolled scan, and by an ADDED/LOST item-set difference against both parents, which is empty. A count alone would not catch two blocks folding into one.
Both sides append a new section at the same point in docs/BACKLOG.md, under different item numbers. Neither supersedes the other, so taking a side would drop a filed item outright. Both blocks are kept, in the ascending item order the file already uses. Verified with parse_items from scripts/docs/backlog_status_check.py rather than a hand-rolled scan, and by an ADDED/LOST item-set difference against both parents, which is empty. A count alone would not catch two blocks folding into one.
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.
Closes BACKLOG #1439.
scripts/webconsole_seam_snapshot.pyderived the seam digest from whichevermessagefoundrysys.pathhappened to offer, while reading_CONSOLE_DIRand_ENGINE_DIRout of the repository it lives in. Run from a git worktree with no.venvof its own -- the normal state for these sessions -- those are two different trees.Python puts the SCRIPT's directory on
sys.path[0], never the caller's cwd. Soscripts/led the path, no entry offeredmessagefoundry, and the import fell through to site-packages: the primary checkout's, via its path-based editable install (_editable_impl_messagefoundry.pthholds the primary root). That is also why an ordinarysys.path.insert(0, ...)is enough to beat it.The success output is the part that misled
Measured 2026-09-03 in a worktree with no
.venv:--writeprinted the primary tree's digest93ba1f10b9dccfc8, rewrotemessagefoundry/api/_ui_seam.pyand the golden with that unchanged value, and reported success naming both files -- whiletests/test_webconsole_seam_snapshot.pykept failing against266cbfd342b22819, a digest the script had never computed.The only loud word in the room was
rewrote, so the repair on offer to a reader is that the gate is broken. The gate was right the whole time. This is the SDS-3.8 shape: an instrument answering a question adjacent to the one asked.The measurement, as a controlled comparison
Four scripts run by path from one cwd, under one interpreter, with
sys.path[0]set to each target's own directory. The only variable is whether the script anchors itself:The first instrument tried was the wrong one, and the item records it so it is not tried again. A
runpy.run_pathprobe from the repo root reported all four resolving correctly -- it could not have done otherwise, becauserunpyleft cwd onsys.pathand so never reproduced a by-path invocation. Checking that the instrument answers the asked question is the same discipline this PR is about, and it caught a false clean one step in.The census bounds it at exactly one script
Every
.pyunderscripts/importing an in-repo top-level package (messagefoundry,messagefoundry_webconsole,harness,tee,ide), including indented and deferred imports:__file__bench/stage_residency.pyparents[2]security/dast_auth_sweep.pyparents[2]security/dast_target.py__main__security/route_gates.py__main__, says sotray/make_icons.pyparents[2]webconsole_seam_snapshot.pyThe two unanchored security modules are reached only as
scripts.security.X, which already requires the root onsys.path;dast_auth_sweep.pyinserts it before importing them and pytest supplies it, so they inherit a corrected path.scripts/security/crypto_inventory_check.pynames those packages only in AST-matching string constants, not imports.So three siblings already carried this fix and one was missed -- which is the strongest thing the census says. A per-script anchor has no list for an unanchored script to be absent from, so the omission was invisible by construction.
Two tests, because the obvious one is not enough
test_the_script_run_by_path_computes_the_same_digestruns the generator as a subprocess, by path, from a cwd that is not the repo root and withPYTHONPATHscrubbed. Both scrubs are load-bearing: under pytest the root is already onsys.path, so every in-process check in that file is blind to this defect by construction, and a subprocess inheriting either rescue would pass for a reason unrelated to the script.That test cannot fail on a hosted runner -- one engine tree means an unanchored script is right by luck -- and measured here it did not fail without the fix either, because this box's two trees currently carry the same seam. A test whose environment cannot produce the failure is not evidence the failure is absent.
So
test_the_script_prefers_its_own_repo_over_an_earlier_path_entrysupplies the second tree itself: a decoymessagefoundrypackage onPYTHONPATH, which for a by-path invocation sits ahead of site-packages and behind an explicitsys.path.insert(0, repo_root). It reds if and only if the anchor is gone, on any machine, with no worktree and no second checkout needed.Checks
pytest tests/test_webconsole_seam_snapshot.pypytestseam + ledger files (6 files)ruff check,ruff format --checkmypyHEAD);tests/andscripts/are outside CI'smypy messagefoundry messagefoundry_webconsolescopescripts/docs/backlog_status_check.pyNot run: the full
pytestsuite, and any hosted-runner-only leg. Please read the CI legs after they report.messagefoundry/api/_ui_seam.pyandtests/golden/webconsole_seam.snapshotare deliberately untouched -- the contract did not move, only the instrument that measures it.Severity
No engine effect, no PHI axis, and no deployment axis (CLAUDE.md section 0):
scripts/ships in no wheel and this tool touches no product surface. The cost is bounded to a developer's session -- wasted debugging, and a gate a reader would "fix" in the wrong direction. Nothing was mis-shipped, because CI runs on a hosted runner with exactly one engine tree, where the defect cannot express itself.Adjacent, and deliberately not fixed here
docs/WEBCONSOLE-PACKAGE.md's seam-refresh procedure is stale in three steps left behind by #1220: it says to bumpENGINE_UI_SEAMby hand (1to2) when the value is a derived digest, it says to update curated lists in this script that #1220 retired, and its step 5 prescribespython scripts/webconsole_seam_snapshot.py > tests/golden/...-- the shell redirect this script's own docstring forbids, because PowerShell's>writes UTF-16LE with a BOM into a file the test reads as UTF-8. That is doc drift with its own cause and wants its own item; folding a documentation rewrite into asys.pathfix would make both harder to review.🤖 Generated with Claude Code