forge: commit write_probe two-scan -> Counter DRY collapse (verified)
This commit is contained in:
1 parent
2b85f70ea8
commit
83be3c0f8a
4 files changed
+28
-18
No files matched your search
@@ -127,6 +127,7 @@ import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from collections import Counter
|
||||
|
||||
JSON_FLAG = re.compile(r"add_argument\(\s*[\"']--json[\"']")
|
||||
# A caller-path write flag other than --json. The class is the two name families
|
||||
@@ -665,8 +666,14 @@ def main(argv=None):
|
||||
% (width, r["tool"], r.get("axis", "json"), r["verdict"],
|
||||
"-" if r.get("rc") is None else r["rc"], r["detail"]))
|
||||
print()
|
||||
n_json = len([r for r in rows if r.get("axis") == "json"])
|
||||
n_flag = len([r for r in rows if r.get("axis") == "flag"])
|
||||
# One pass over `rows` replaces two `len([r for r in rows if r.get("axis") ==
|
||||
# X])` scans that differed only by the axis string constant. Counter buckets
|
||||
# each row once by its axis value; a row with no "axis" key yields None, and
|
||||
# axis_counts["json"]/["flag"] read 0 for it -- identical to the two-scans
|
||||
# form, which left a None-axis row in neither column.
|
||||
axis_counts = Counter(r.get("axis") for r in rows)
|
||||
n_json = axis_counts["json"]
|
||||
n_flag = axis_counts["flag"]
|
||||
print("write axis: %d probed, %d ok, %d fault(s) (json %d, flag %d)"
|
||||
% (len(rows), len(rows) - len(bad), len(bad), n_json, n_flag)
|
||||
+ ("" if not bad else " (" + ", ".join(sorted({r["verdict"]
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
# WRITE_PROBE_DRY_REFACTOR_VERIFICATION
|
||||
|
||||
Tool: `tools/write_probe.py` (forge lane: Refactor)
|
||||
Original: `git show HEAD:tools/write_probe.py` (byte-identical at HEAD; the refactor is
|
||||
unstaged in the working tree)
|
||||
Refactored: working tree (`tools/write_probe.py`)
|
||||
Original: `git show HEAD~1:tools/write_probe.py`. The verifier reads HEAD~1 (not HEAD)
|
||||
because the refactor is committed IN this change: at the post-commit tip HEAD carries the
|
||||
refactor, so HEAD~1 is the last clean original. HEAD~1 is byte-identical to the pre-refactor
|
||||
tree at every point before this commit lands, so the same command is a correct original both
|
||||
before and after -- the same guarantee the queue_append_audit verifier relies on.
|
||||
Refactored: working tree / committed tip (`tools/write_probe.py`)
|
||||
|
||||
## The smell
|
||||
|
||||
@@ -49,7 +52,7 @@ write-axis line are unchanged.
|
||||
## Evidence (measured)
|
||||
|
||||
Proof in `wizard-work/forge/verify_write_probe_dry_refactor.py`. It materializes the
|
||||
`HEAD` blob as `write_probe.py` in a temp dir and runs the ORIGINAL and the REFACTORED
|
||||
`HEAD~1` blob as `write_probe.py` in a temp dir and runs the ORIGINAL and the REFACTORED
|
||||
module as subprocesses over the SAME repo (`/root/troupe-standup`) with a writable `--json`
|
||||
target, then compares the three legs:
|
||||
|
||||
@@ -67,7 +70,7 @@ EXIT=0
|
||||
|
||||
### Verdict breakdown
|
||||
|
||||
- **[1] END-TO-END axes+signature drift.** The original (`HEAD`) and refactored (working
|
||||
- **[1] END-TO-END axes+signature drift.** The original (`HEAD~1`) and refactored (working
|
||||
tree) `write_probe.py` both run over `/root/troupe-standup --json <writable> --timeout 60`.
|
||||
The refactor's only output is the `axes` object, and `axes_orig == axes_ref`
|
||||
(`{'json': 21, 'flag': 3}` on both); the non-detail row signature is identical
|
||||
@@ -85,7 +88,7 @@ EXIT=0
|
||||
matching the convention the other forge verifiers use -- the only residual two-scan
|
||||
reference in the worktree is inside a `#` comment):
|
||||
|
||||
| pattern (code lines) | original (HEAD) | refactored (tree) |
|
||||
| pattern (code lines) | original (HEAD~1) | refactored (tree) |
|
||||
|---------------------------------|-----------------|-------------------|
|
||||
| `len([r for r in rows ...` scan | 2 | 0 |
|
||||
| `Counter(r.get("axis") ...` use | 0 | 1 |
|
||||
@@ -97,7 +100,7 @@ EXIT=0
|
||||
|
||||
Behavior-preserving DRY collapse: the two axis-count scans in `write_probe.py` collapsed
|
||||
into a single `Counter` pass. `axes` (`json=21, flag=3`) and the row signature are
|
||||
identical between original (`HEAD`) and refactored on the full repo probe, the tool's own
|
||||
identical between original (`HEAD~1`) and refactored on the full repo probe, the tool's own
|
||||
15-cell `--selftest` stays green, and the smell is gone from code lines while still present
|
||||
in the original.
|
||||
|
||||
|
||||
@@ -83,17 +83,18 @@ def code_lines(text):
|
||||
|
||||
|
||||
def materialize_original():
|
||||
"""Write git HEAD:tools/write_probe.py under its real name in a temp dir;
|
||||
return (dir, path). HEAD is the clean original: the two-scan smell is
|
||||
present, the Counter is absent, and write_probe.py is byte-identical at the
|
||||
tip of the commit lineage (the Counter change is unstaged in the worktree).
|
||||
So HEAD reads a genuine original both before the refactor lands and after it
|
||||
is committed -- the same guarantee the other forge verifiers rely on.
|
||||
"""Write the PRE-refactor source (git HEAD~1) under its real name in a
|
||||
temp dir; return (dir, path). HEAD~1 is the clean original: the two-scan
|
||||
smell is present, the Counter is absent, and write_probe.py is byte-identical
|
||||
at HEAD~1 (the Counter change is unstaged in the worktree, landing on the
|
||||
commit after this one). So HEAD~1 reads a genuine original both before the
|
||||
refactor lands and after it is committed -- the same guarantee the
|
||||
queue_append_audit verifier relies on.
|
||||
"""
|
||||
res = subprocess.run(["git", "-C", REPO, "show", "HEAD:tools/write_probe.py"],
|
||||
res = subprocess.run(["git", "-C", REPO, "show", "HEAD~1:tools/write_probe.py"],
|
||||
capture_output=True, text=True)
|
||||
if not res.stdout:
|
||||
raise Verdict("could not read HEAD:tools/write_probe.py: " + res.stderr.strip())
|
||||
raise Verdict("could not read HEAD~1:tools/write_probe.py: " + res.stderr.strip())
|
||||
d = tempfile.mkdtemp(prefix="wp_orig_")
|
||||
p = os.path.join(d, "write_probe.py")
|
||||
with open(p, "w", encoding="utf-8") as fh:
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
[3] redundancy (code lines) two-scan: orig=2 ref=0 counter-use: orig=0 ref=1 PASS
|
||||
|
||||
VERDICT: ALL GREEN -- write_probe axes+row-signature byte-identical to original, --selftest 15/15, 2 two-scan scans -> 1 Counter pass
|
||||
EXIT=0
|
||||
Reference in new issue
Block a user