Skip to content

fix(efficacy): the layering probe reads what import tariff loads - #127

Merged
braboj merged 6 commits into
mainfrom
fix/layering-closure
Nov 4, 2026
Merged

braboj merged 6 commits into
mainfrom
fix/layering-closure

Conversation

@braboj

@braboj braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The layering probe could never report a violation: a module that imports Flask or sqlite3 was classed web or persistence by that fact, and the probe then asked whether a domain module imports either. It now reads the contract the spec states, import tariff works without Flask and without touching the database.

before:  role by imports -> only "domain" modules checked -> never any
after:   import closure of tariff/__init__ (relative and tariff.* imports)
         -> every module in it that imports flask, werkzeug, jinja2,
            sqlite3 or sqlalchemy is a violation
         -> no package entry: the reading is missing, not zero
Where Change
probes.py, structure script layering_violations over the import closure; import_closure listed beside it
probes.py, self-test store.py reached through an absolute import is a violation; web.py, never imported, is outside; a root without __init__ reads missing. 17 checks
report.py the row reads "Modules import tariff loads that reach Flask or the database"
docs/coverage.md, ch. 8.6.3 the three labels; the probe's question restated

For the owner before merging. This row sits in the Design radar axis and read 0 for every arm of round 5c. Under ADR-021 a fixed instrument means every reading round is re-scored. The structure probe needs no model call, so a re-score of 5c's 75 trials is CPU time only, but it is a decision: merge now and re-score 5c and 5d's reused trials, or hold this until round 5d is scored and reported and let round 6 be the first to read it.

Closes #125

🤖 Generated with Claude Code

https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY

braboj and others added 2 commits November 4, 2026 13:37
The probe classed each module by what it imports, then looked for domain
modules importing Flask or a database driver, which by that definition
there never are. It now walks the import closure of the package's
__init__, relative and absolute imports alike, and reports every module in
it that imports Flask, Werkzeug, Jinja or a database driver. Without a
package entry the reading is missing, not zero.

Closes #125

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY
…gh every initializer

An import inside a function body, the factory's lazy import of the web
module that the specification allows, is not what import tariff loads, so
the closure and the names it counts skip function bodies. A dotted import
runs every package initializer on its way, so each one joins the closure.
Files are named by their path under the package, which tells two
initializers apart.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY
@braboj

braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codex review, round 1 (gpt-6-astra, high): two findings, both real, both fixed.

# Severity Finding Outcome
1 P2 A from . import web inside the factory's body was followed, so the lazy factory the spec allows read as a Flask violation Fixed: the closure and the names it counts skip function bodies. Test: the planted create_app imports web lazily; web.py stays outside the closure
2 P2 from .data.store import x added data/store.py but not data/__init__.py, which Python runs first Fixed: every initializer on a dotted import's way joins the closure. Test: data/__init__.py imports sqlite3 and is the one violation

Also: closure entries are now paths under the package (tariff/data/__init__.py), so two initializers are told apart. Probes self-test 18/18, trace clean. Round 2 follows.

…riff loads

Only a type checker reads such a branch, so the closure skips its body and
takes its else branch. The planted store names Flask and the web module
under the guard; neither reads as loaded.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY
@braboj

braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codex review, round 2 (gpt-6-astra, high): one finding, real, fixed.

# Severity Finding Outcome
1 P2 An import under if TYPE_CHECKING: was followed, so a module annotating with Flask types read as a violation, and a guarded from tariff import web joined the closure Fixed: the closure skips the guarded body and takes its else branch. Test: the planted data/store.py names Flask and web under the guard; neither reads as loaded

Probes self-test 19/19, trace clean. Round 3 follows.

…module

An import under if __name__ == "__main__" runs only for a script, so the
closure skips it as it skips a type-checking guard. Where a package and a
module share a name, the package is what Python imports, so the resolver
takes it first.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY
@braboj

braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codex review, round 3 (gpt-6-astra, high): three findings. Two fixed, one by design.

# Severity Finding Outcome
1 P2 An import under if __name__ == "__main__": was counted as loaded Fixed: a main guard is skipped like a type-checking guard. Test: the planted __init__ names Werkzeug under one; no violation
2 P2 from typing import TYPE_CHECKING as TC then if TC: is not recognised By design: the guard is read by name, TYPE_CHECKING or typing.TYPE_CHECKING, the two spellings a build writes. Tracking aliases is machinery for a case no trial has shown; if one does, its violation names the module and the reader sees the alias
3 P2 rules.py beside rules/__init__.py: the resolver took the module, Python takes the package Fixed: the package is tried first. Test: a planted data.py importing Jinja beside the data package; the module stays outside the closure

Probes self-test 21/21, trace clean. Round 4 follows.

An inverted guard, if __name__ != "__main__", runs on import, so its
imports count. The planted store carries one over sqlite3.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY
@braboj

braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codex review, round 4 (gpt-6-astra, high): one finding, real, fixed.

# Severity Finding Outcome
1 P2 if __name__ != "__main__": was read as a main guard because both names appeared in the comparison, though its body runs on import Fixed: only a single equality with "__main__" is a main guard. Test: the planted store imports sqlite3 under the inverted guard, and that import is a violation

Probes self-test 22/22, trace clean. Round 5 follows.

…river

from .sqlite3 import x imports tariff.sqlite3, so the layering count reads
only absolute imports; the relative ones the closure already follows.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DpT5xPGzmuB6WLaUppMRKY
@braboj

braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codex review, round 5 (gpt-6-astra, high): three findings. One fixed, two by design.

# Severity Finding Outcome
1 P2 The else: of a main guard, and if not TYPE_CHECKING:, are read as running on import By design: the guards are read in the forms a build writes, if TYPE_CHECKING: and if __name__ == "__main__":, and an else on either, or a negated guard, is not one of them. Evaluating guards symbolically is machinery for a case no trial has shown
2 P2 from .sqlite3 import x counted the external sqlite3, though Python imports tariff.sqlite3 Fixed: the layering count reads absolute imports only; relative ones the closure already follows. Test: the planted store imports a local data/sqlalchemy.py; it joins the closure and is no violation
3 P2 from tariff import web where __init__ already binds web does not load web.py, but the probe follows it By design: a name bound before a same-named submodule is imported is not a shape a trial has shown; the probe follows the submodule where one exists

Probes self-test 23/23, trace clean. Round 6 follows.

@braboj

braboj commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Codex review, round 6 (gpt-6-astra, high): two findings, both by design, nothing new.

# Severity Finding Outcome
1 P2 The else: of an inverted main guard, or of if not TYPE_CHECKING:, is read as running on import By design, as answered in round 5: the guards are read in the two forms a build writes
2 P2 from .adapters import * with __all__ = ["store"] loads adapters/store.py, which the closure does not follow By design: a wildcard import of a subpackage whose __all__ names submodules is not a shape a trial has shown. The star is resolved as a name and finds nothing, so the subpackage's own initializer is still read

The loop ends here: six rounds, six real findings fixed with a test each, five answered by design. Ready for the owner's review.

@braboj
braboj merged commit 5580e2c into main Nov 4, 2026
2 checks passed
@braboj
braboj deleted the fix/layering-closure branch November 4, 2026 12:26
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.

The layering probe can never report a violation

1 participant