Repository navigation
test: widen the tier guard to catch a SAMPLE_ROOT join via a module-level tuple - #2427
Conversation
|
Coverage: 91.73% (unit tier, Python 3.15,
Per-file detail: the |
|
Review: NEEDS CHANGES at
Also flagged, non-blocking: two inaccuracies in the docstring ("the one unit-tier module that touches SAMPLE_ROOT" — |
…evel tuple The AST audit in tests/_tiers.py only recognised a generated-capture read as a literal argument to tests._support.sample_path(...). It missed the indirection PR #2421's first revision hit: a module-level CAPTURES tuple read in a for loop whose body joined SAMPLE_ROOT / name directly, bypassing sample_path(). The guard's own static pass never flagged it, which is the defect this fixes -- CI's unit-tests leg did fail on that revision, on every affected Python interpreter, because the capture genuinely was not on disk; it only passed locally where make_samples.py had already been run. - tests/_tiers.py: add sample_root_join_calls(), which follows a SAMPLE_ROOT join back to a module-level name bound to a single string, or to a for loop's target over a module-level (or inline) tuple/list of strings. audit_module() now merges these findings with the existing sample_path_calls() ones, in source order. Deliberately narrow, per the module docstring's existing rationale for rejecting a blanket ".pcap literal" rule: no new false positive across the real suite (verified). - tests/test_tier_guard.py: new AuditTests cases pin the loop and direct-join shapes being flagged, and that a committed capture, a try/except-handled read, and a for loop over sorted(CAPTURES) (a module-level tuple wrapped in a call, rather than read bare) stay unflagged. Verified: reverting the tests/_tiers.py change makes the three new "is flagged" tests fail (0 findings where 1-2 are expected, plus an AttributeError for the new function); restoring it makes them pass. Full tests/test_tier_guard.py + test_tier_guard_xdist.py + test_capture_tracking.py suite green (156 passed, 3 skipped), and a whole-suite audit_module() sweep over every unit-tier module on disk still reports zero findings. mypy and pylint report no new findings against either file. Closes #2426
37c7573 to
cb573a1
Compare
|
Review: GOOD TO GO at Both requested fixes confirmed:
|
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fixfeatperfrefactortestdocscireleasechoreDescription
Closes #2426.
tests/_tiers.py'saudit_moduleonly saw a generated-captureread as a literal argument to
sample_path(...). It missed the indirectiontests/foundation/reassembly/test_datagram_deferred_pickle_2417_unit.pyused on PR #2421's first revision: a module-level
CAPTUREStuple read in aforloop whose body joinedSAMPLE_ROOT / namedirectly, never callingsample_path()at all. CI's unit-tests leg genuinely failed on thatrevision, on every affected Python interpreter, because the capture was not
on disk; it passed only locally, where
make_samples.pyhad already beenrun. What this guard's own static pass missed was the violation itself, not
a CI run.
sample_root_join_calls()follows aSAMPLE_ROOTjoin back to either amodule-level name bound to a single string, or a
forloop's target over amodule-level (or inline) tuple/list of strings;
audit_module()merges itsfindings with the existing
sample_path_calls()ones, in source order. Itstays deliberately narrow — the module docstring already documents why a
blanket ".pcap literal" rule was rejected, and this shape doesn't revisit
that: a whole-suite sweep after the change still reports zero findings.
New
AuditTestscases intests/test_tier_guard.pypin both the loop anddirect-join shapes being flagged, and that a committed capture, a
try/except-handled read, and a
forloop oversorted(CAPTURES)(amodule-level tuple wrapped in a call, rather than read bare) stay unflagged.
Verified fail-without-fix by reverting the
tests/_tiers.pychange: thethree "is flagged" tests then fail (0 findings instead of 1-2, plus an
AttributeErrorfor the new function).