Commit ef89585
fix(scripts): anchor webconsole_seam_snapshot.py on its own repo, not on sys.path (BACKLOG #1439) (#826)
* fix(scripts): anchor webconsole_seam_snapshot.py on its own repo, not 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>
* docs(backlog): key #1439's census on the missing anchor, not on observed 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>
---------
Co-authored-by: wshallwshall <mefordev@messagefoundry.org>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent bac7d94 commit ef89585
3 files changed
Lines changed: 208 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21483 | 21483 | | |
21484 | 21484 | | |
21485 | 21485 | | |
| 21486 | + | |
| 21487 | + | |
| 21488 | + | |
| 21489 | + | |
| 21490 | + | |
| 21491 | + | |
| 21492 | + | |
| 21493 | + | |
| 21494 | + | |
| 21495 | + | |
| 21496 | + | |
| 21497 | + | |
| 21498 | + | |
| 21499 | + | |
| 21500 | + | |
| 21501 | + | |
| 21502 | + | |
| 21503 | + | |
| 21504 | + | |
| 21505 | + | |
| 21506 | + | |
| 21507 | + | |
| 21508 | + | |
| 21509 | + | |
| 21510 | + | |
| 21511 | + | |
| 21512 | + | |
| 21513 | + | |
| 21514 | + | |
| 21515 | + | |
| 21516 | + | |
| 21517 | + | |
| 21518 | + | |
| 21519 | + | |
| 21520 | + | |
| 21521 | + | |
| 21522 | + | |
| 21523 | + | |
| 21524 | + | |
| 21525 | + | |
| 21526 | + | |
| 21527 | + | |
| 21528 | + | |
| 21529 | + | |
| 21530 | + | |
| 21531 | + | |
| 21532 | + | |
| 21533 | + | |
| 21534 | + | |
| 21535 | + | |
| 21536 | + | |
| 21537 | + | |
| 21538 | + | |
| 21539 | + | |
| 21540 | + | |
| 21541 | + | |
| 21542 | + | |
| 21543 | + | |
| 21544 | + | |
| 21545 | + | |
| 21546 | + | |
| 21547 | + | |
| 21548 | + | |
| 21549 | + | |
| 21550 | + | |
| 21551 | + | |
| 21552 | + | |
| 21553 | + | |
| 21554 | + | |
| 21555 | + | |
| 21556 | + | |
| 21557 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
58 | 88 | | |
59 | 89 | | |
60 | 90 | | |
61 | 91 | | |
62 | 92 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
| 93 | + | |
68 | 94 | | |
69 | 95 | | |
70 | 96 | | |
| |||
0 commit comments