Skip to content

refactor(code-metrics): simplify the collectors and harness code - #15042

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14424-42781306246-1
Nov 10, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14424-42781306246-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14424

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Simplified four of the seven listed collector files without changing behavior. radon.py now reads each source file once rather than once per function, and shares one row builder and one JSON-shape check between the cc and hal translators. scc.py uses NAME in place of repeated "scc" literals, mypy-report.py moves the twice-written cwd base expression into one _cwd_base() helper, and type-coverage.py counts per-file occurrences with collections.Counter. shellmetrics.py, sonarjs.py and harness/stub_harness.py came out of the four-check review with nothing to fix inside the file: their only duplication is the probe and collect boilerplate shared with other adapters, and moving or deduping code across files is out of scope.

Not verified

  • The collector unit suites (test_radon.py, test_scc.py, test_mypy_report.py, test_type_coverage.py) were not run directly: this lane runs no interpreter. check-affected's summary does not name which suites it ran, so they are left to the PR's CI.
  • tidy pass 5 (ai-slop:audit fix) did not run its detector: the lane lets Bash run only the named wrappers, and detect.sh is not one. The two mandated fragment lines were read against the rubric instead, with no tells found.
  • Build and lint of the touched Python files (ruff, mypy) were not run here: no interpreter or linter is allowed in this lane. Left to the PR's CI.
  • ci-status green is an acceptance criterion the PR's CI decides.

Fix

  • plugins/code-metrics/scripts/collectors/radon.py: _non_blank now counts a list of lines read once per file by the new _read_lines (it used to reopen the file for every function); the new _document gives the cc and hal JSON-object check with the same error text; the new _row builds the row dict in…
  • plugins/code-metrics/scripts/collectors/scc.py: NAME replaces the hard-coded "scc" in probe, collect and their stderr messages (same text).
  • plugins/code-metrics/scripts/collectors/mypy-report.py: the new _cwd_base() helper replaces the duplicated os.path.normcase(os.path.abspath(os.getcwd())) in split_collisions and match_modules.
  • plugins/code-metrics/scripts/collectors/type-coverage.py: a collections.Counter replaces the hand-rolled per-file occurrence count in translate.
  • .changes/code-metrics/work-resolve-issue-issue-14424-42781306246-1-2818d18d.md: new patch fragment, made with new-changelog-fragment code-metrics patch, with a body of '### Changed' and 'Internal simplification, no behavior change.'

Verification

The runner ran each check from the base copy against 8ef69a5:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • check-changelog-fragments: all 5 fragments under .changes/ valid (run before and after tidy and the review fix)
  • check-changed-skills: no changed skills, nothing to gate
  • check-affected: 13 passed, 6 skipped over 5 changed files (run before and after tidy and the review fix)
  • fresh-context review subagent, comparing the diff against git-read show HEAD for each file: no behavior difference reachable from the CLI; stdout key order, stderr text, exit codes and raised exception types were all preserved, and no test references a removed or changed name. It flagged one…
  • tidy-diff over the change's 26 hunk rows: pass 1 found nothing further to simplify; pass 2 kept the one new docstring (_cwd_base), which states the contract module_name expects, so nothing was deleted; pass 3 found no generated-code residue; pass 4 (write-for-humans) left the fragment unchanged…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42781306246

Left out: the items under Not verified.

Related

#14424

Merge-Risk: max=LOW demote=false head=8ef69a56ea8b429490d79c6c9a46efb628c004a8 rubric=8.3.3 rater=claude-opus-5-5 checker=claude-opus-5-5

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 8ef69a56ea8b429490d79c6c9a46efb628c004a8: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15042, refactor(code-metrics): simplify the collectors and harness code

I found no security issues in this change.

I read every hunk of all 5 changed files. None of them matches a trusted-path glob, and the PR touches no trust control, merge hold, workflow, action, token request, plugin manifest or instruction surface.

What each change does:

  • radon.py: reads each source file once with _read_lines, instead of once per function, and pulls the JSON check and row building into _document and _row. The file path still comes from the caller's wanted list through wanted_norm, so radon's output still can't choose which file gets opened. The slice lines[start - 1 : end] is the same as the slice the old _non_blank used. A failed read still counts as zero lines, as before.
  • scc.py: uses the constant NAME = "scc" in place of repeated "scc" literals in shutil.which and the stderr messages. The executable it looks up and the message text don't change.
  • mypy-report.py: moves os.path.normcase(os.path.abspath(os.getcwd())) into a _cwd_base() helper. The value it returns is unchanged.
  • type-coverage.py: counts per-file occurrences with collections.Counter instead of a hand-written dict. Looking up a missing key returns 0, as .get(key, 0) did.
  • .changes/...md: a new changelog fragment with no executable content.

None of these changes adds an input, a subprocess argument, a path source or a way for data to leave the machine. The PR context holds no text that tries to steer this review.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 8ef69a56ea8b429490d79c6c9a46efb628c004a8: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Code review: no findings

I read every hunk of all 5 changed files. I found nothing that should block or be flagged.

Behavior checked file by file (by reading the code; I ran nothing):

  • radon.py
    • translate_cc still reads nothing from disk for cyclomatic. It now reads each file once instead of once per function.
    • An unreadable file still gives 0. _read_lines returns [], so _non_blank of the whole file and of each slice both come out as 0, the same as the old early return 0.
    • The slice lines[start - 1 : end] is unchanged.
    • _document keeps both error messages word for word (radon cc -j did not print an object and radon hal -j did not print an object).
    • _row keeps the old key order (file, function, start_line, end_line, lane, values, collector, labels). The Halstead values key order is also unchanged.
  • scc.py: NAME == "scc", so every message and which lookup is the same string as before.
  • mypy-report.py: _cwd_base() returns exactly the expression it replaces, in both callers.
  • type-coverage.py:
    • Counter gives the same answers for key not in listed and for listed[key] on a missing key (0).
    • Looking up a missing key on a Counter does not insert it, so the later in checks are unaffected.
    • listed is used nowhere else.

Closing issue #14424 acceptance criteria:

  • Behavior unchanged: met, as above. The existing collector suites (test_radon.py and the others) cover these translators. The author says they did not run them and left them to CI; I did not run them either.
  • Only the listed files plus changelog fragments are edited: met.
  • Within 400 lines and 15 hand-edited files: met, at about 100 changed lines across 4 files.
  • ci-status green: left to CI.
  • Changelog fragment: met. bump: patch with body ### Changed / "Internal simplification, no behavior change."

Other checks:

  • Path-scoped rules: only .claude/rules/ruff-pin.md matches (**/*.py), and nothing in this diff touches what it governs.
  • Paved paths: no paved-path row turned up under docs/standards/, so there is nothing to report.
  • Plugin manifests: none changed.
  • Embedded instructions: none found in the PR context.
  • Earlier reviews: none on an earlier head, so this was a full review, not blocking-only.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 8ef69a56ea8b429490d79c6c9a46efb628c004a8, the head its arming checks judged.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 8ef69a5

The verifier passed this head. The capture artifact holds the capture summary, which says whether the capture ran, and any screenshot or video that passed the mask check; this comment uploads no file.

Capture artifact: pr-capture-15042-8ef69a56ea8b429490d79c6c9a46efb628c004a8, expires on 2026-12-10.

One comment per pull request, updated in place for each new head.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 5a1af4b Nov 10, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14424-42781306246-1 branch November 10, 2026 12:54
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 6, survived 1, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 86%; mutation score 86%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/code-metrics/scripts/collectors/mypy-report.py 0 1 0 0 0 0
plugins/code-metrics/scripts/collectors/radon.py 4 0 0 0 0 0
plugins/code-metrics/scripts/collectors/scc.py 1 0 0 0 0 0
plugins/code-metrics/scripts/collectors/type-coverage.py 1 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/code-metrics/scripts/collectors/mypy-report.py:209 other productive input-gap

The run's summary has the full report.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit 5a1af4bbf14432436a87f9d802c91a5e721cfb29; later checks count it verified from this comment.

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.

Simplify the collectors and harness code-metrics plugin code

0 participants