Files
troupe-standup/wizard-work/forge/SMELL_SCAN_REFACTOR_VERIFICATION.md

3.7 KiB

Smell-scan refactor verification

Work

Refactored /root/troupe-standup/wizard-work/forge/_smell_scan.py into _smell_scan_refactored.py, with the verifier verify_smell_scan_refactor.py. The refactor target is a code-smell scanner, so the fixes below are the smells a detector should flag on its own author:

  • Removed dead variable arg_names (list comprehension computed, never read).
  • Collapsed the redundant or "end >= n:" in line clause: "end >= n" is a substring of every line matching "end >= n:", so the second operand of the or never adds a match -> removing it changes no results.
  • Removed dead variable reconstruct_src ("\n".join(lines[240:280]), computed and never consumed).
  • Replaced the magic range 241 <= i <= 280 and the sliced lines[240:280] with a named constant RECONSTRUCT_RANGE = (241, 280).
  • Extracted pure, testable helpers find_unused_arguments, scan_pattern, scan_in_range; module no longer executes file I/O at import time.
  • Guarded entry with if __name__ == "__main__": main().

Harness fix (in this pass)

The verifier's two smell-absence checks scanned the whole file including the docstring, and the refactored module's docstring legitimately names the patterns it removes (reconstruct_src, 241 <= i <= 280, lines[240:280]). That produced false positives (checks 6 and 8 failed on documentation, not code). Fixed verify_smell_scan_refactor.py to blank the module docstring and comment-only lines before scanning (_code_only), so smell-absence checks inspect code only -- the correct behavior for a smell detector's own verifier.

Evidence (measured, not claimed)

Byte-identical stdout+stderr (original vs refactored):

$ python3 _smell_scan.py        > _orig_smoke.txt 2>&1; echo "orig rc=$?"
orig rc=0
$ python3 _smell_scan_refactored.py > _ref_smoke.txt 2>&1; echo "ref rc=$?"
ref rc=0
$ diff -u _orig_smoke.txt _ref_smoke.txt && echo "DIFF_EXIT=$? (0=identical)"
DIFF_EXIT=0 (0=identical)
$ cksum _orig_smoke.txt _ref_smoke.txt
1832815637 330 _orig_smoke.txt
1832815637 330 _ref_smoke.txt

Verifier run:

$ python3 verify_smell_scan_refactor.py; echo "=== VERIFIER EXIT=$? ==="
OK: py_compile passes
OK: identical output (exit 0): 'UNUSED ARG: func=reconstruct arg=overlap_tokens line=241\n\n--- Checking _hard_split_long for redundant break ---\n\n--- Checking reconstruct body for overlap_tokens usage ---\nLine 241: def reconstruct(chunks: list[str], overlap_tokens: int = 32) -> str:\nLine 276: # No sentinel (e.g. overlap_tokens=0, or the first chunk): the chunk'
OK: no 'global' statements
OK: dead 'arg_names' variable removed
OK: dead 'reconstruct_src' variable removed
OK: redundant 'or end >= n:' clause removed
OK: magic range replaced by named constant
OK: __main__ guard present

=== Verification: 8/8 checks passed ===
=== VERIFIER EXIT=0 ===

Metrics (smell counts, before -> after)

smell original refactored
dead variables (arg_names, reconstruct_src) 2 0
redundant or clause in pattern scan present removed
magic line-range literal (241<=i<=280, lines[240:280]) 2 0 (named constant)
global statements 0 0
import-time side effects yes (file I/O + AST walk at top level) none (guarded main)
byte-identical output (cksum) -- 1832815637 330 == 1832815637 330

Verdict

Behavior-preserving and measurable: py_compile clean, byte-identical output (330 bytes, identical cksum), all 8 verifier checks pass (exit 0). The scanner's own dead-code/redundant/magic-literal smells are eliminated, and it is now side-effect-free at import time.