Skip to content

refactor(code-metrics): simplify the collector adapters - #15179

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14423

Summary

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

Simplified six of the ten listed code-metrics collector files without changing what they do: files_from walks its arguments with an iterator instead of an index, the version fallbacks use or chains (a found version is never empty, since the pattern captures at least two digits and a dot), dupl reuses the shared UNKNOWN_VERSION constant and drops a needless list copy, jscpd strips the ignore value once, cpd writes its file list with writelines, and eslint-complexity's NO_CONFIGURATION regex now sits with the module's other constants. gocognit.py, gocyclo.py, line-counter.py and lizard.py were reviewed and left unchanged: the only cleanup they offer is the duplicate probe loop that gocyclo and gocognit share, and deduping across files is out of scope for this chunk. A review found one bug that predates this change: in cpd.py a file name that is not valid UTF-8 raises an uncaught UnicodeEncodeError while the file list is written (jscpd filters such names out with split_invalid_names). Fixing it would change behavior, so it was left alone.

Not verified

  • Python test suites (test_adapter_paths.py, test_cpd.py, test_dupl.py, test_eslint_complexity.py, test_jscpd.py, test_multimetric.py) were not executed: this lane runs no interpreter. Left to the PR's CI.
  • ci-status green is a PR CI check, left to the PR's CI.
  • tidy pass 5 (ai-slop fix): the lane allows no detect.sh run, so the detector did not run; the rubric read of the one-line fragment found no tells. Passes 1-4 ran with no edits.
  • Pre-existing, unchanged: cpd.py crashes with an uncaught UnicodeEncodeError on a file name that is not valid UTF-8 (plugins/code-metrics/scripts/collectors/cpd.py:148-149). Not fixed, since this issue requires no behavior change.
  • The working tree also holds untracked root files this run did not create (.bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile, .zshrc), most likely sandbox mount artifacts; they are not part of this change.

Fix

  • plugins/code-metrics/scripts/collectors/adapter_paths.py: files_from iterates its arguments with next() instead of an index; version_or_unknown returns version_in(text) or UNKNOWN_VERSION
  • plugins/code-metrics/scripts/collectors/cpd.py: the CPD file list is written with one writelines call
  • plugins/code-metrics/scripts/collectors/dupl.py: probe prints the shared UNKNOWN_VERSION constant; _row computes the line span in one expression; close() passes the instance list without copying it
  • plugins/code-metrics/scripts/collectors/eslint-complexity.py: the NO_CONFIGURATION regex and its comment moved up beside the other module constants
  • plugins/code-metrics/scripts/collectors/jscpd.py: _command strips CODE_METRICS_DUP_IGNORE once
  • plugins/code-metrics/scripts/collectors/multimetric.py: probe prints one or chain of version_in, installed_version and the fallback text
  • .changes/code-metrics/work-resolve-issue-issue-14423-42885991157-1-a7d530b6.md: new patch fragment, ### Changed with "Internal simplification, no behavior change."

Verification

The runner ran each check from the base copy against 37f402a:

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

The run reports:

  • check-changelog-fragments: all 4 fragments under .changes/ valid (run before and after tidy)
  • check-changed-skills: no changed skills, nothing to gate (run before and after tidy)
  • check-affected: 13 passed, 6 skipped over 7 changed files (run before and after tidy)
  • fresh-context review subagent, given the old code and the new files: found no input where the new code behaves differently, and found that the strings the six matching test files assert (for example unknown-version in test_dupl.py and the multimetric fallback text) are unchanged
  • tidy-diff over the 13 changed hunks: no edits; the one comment in the listed lines (eslint-complexity.py:62-63) kept as load-bearing
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/42885991157

Left out: the items under Not verified.

Related

#14423

Merge-Risk: max=MEDIUM demote=false head=37f402a99c24efe623d64d2da89974c8b6517fb9 rubric=8.3.5 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 37f402a99c24efe623d64d2da89974c8b6517fb9: read 7 of 7 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15179, no security issues found.

I read every hunk of all 7 changed files. None of them match a trusted path, and none touches a trust control, a plugin manifest, a workflow or a standing instruction. The change refactors the code-metrics collector adapters and adds one changelog fragment:

  • adapter_paths.py: files_from now steps through its arguments with an iterator instead of an index. The --paths-from file is still opened with the same open(...) call and the same error handling as before. Behaviour is unchanged: a --paths-from with no file after it still exits with code 2.
  • cpd.py: the file list is now written with one writelines call. The subprocess argument vector is unchanged and still built as a list, with no shell.
  • jscpd.py: CODE_METRICS_DUP_IGNORE is stripped once. It is still passed as one list argument to the subprocess, so no injection surface is added.
  • dupl.py, multimetric.py, eslint-complexity.py: a shared constant is reused, version fallbacks use or chains, and a regex constant moved. None of these affects security.

The PR context file has no embedded instructions aimed at this lane.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 37f402a99c24efe623d64d2da89974c8b6517fb9: read 7 of 7 changed file(s); 1 finding(s), 0 as inline comments.

Code review: refactor(code-metrics): simplify the collector adapters

I read every hunk of all 7 changed files. I also read the unchanged code that the changed lines call: version_in and the VERSION pattern in adapter_paths.py, translate in dupl.py, and collect in cpd.py. I found no blocking issues. I did not run any tests.

Each rewrite against the old code (I read these; none executed):

  • adapter_paths.files_from: the iterator version matches the index loop. A trailing --paths-from still exits 2, because the argument list holds only strings, so next(..., None) returns None only when the list runs out. The token after --paths-from is still always taken as the listing. Tests at test_adapter_paths.py:29-55 cover plain arguments, a listing, a missing listing argument and a missing listing file.
  • version_or_unknown and the or chain in multimetric.probe: this is safe because VERSION (\d+\.\d+(?:\.\d+)?) can never match an empty string, so version_in returns either None or a non-empty string.
  • dupl._row(instances, …) without the copy: safe. translate rebinds instances = [] after each close() and never changes a list in place, so a list already stored in a row's "instances" is never altered later.
  • dupl printing UNKNOWN_VERSION: the constant is "unknown-version", so the printed text is unchanged.
  • eslint-complexity: NO_CONFIGURATION moved up beside the other module constants. It is still defined before anything uses it, and re was already imported.
  • jscpd and cpd: the changes are equivalent (the ignore value is stripped once; the file list is written with one writelines call).

Closing issue #14423, acceptance criteria:

  • Behavior unchanged: met, by my reading above. The existing collector tests would catch a regression.
  • Diff edits only the listed files plus a changelog fragment: met.
  • Within 400 lines and 15 files: met (7 files, about 60 lines).
  • Fragment with body ### Changed and "Internal simplification, no behavior change.": met. bump: patch fits a refactor with no behavior change.
  • ci-status green: left to CI; the author says it is not verified.

The author's Verification items (fragment and skill checks, check-affected, the subagent review) are author-claimed and unverified by me.

No plugin manifest changed, so there are no manifest lines. There is no paved-path or embedded-instruction content to report.

Advisory finding (does not block):

  • Pre-existing (advisory):
    with open(listing, "w", encoding="utf-8") as handle:
    handle.writelines(f"{path}\n" for path in files)
    • What happens: the CPD file list is opened with encoding="utf-8" and no errors= handler.
    • When: a path that arrives through files_from (read with surrogateescape) or through POSIX argv, and is not valid UTF-8, carries lone surrogates.
    • Result: handle.writelines(...) on line 149 raises an uncaught UnicodeEncodeError. Nothing catches it, so the collector crashes instead of returning an exit code.
    • Origin: the changed line 149 calls this path, and the defect already existed on the base branch's handle.write(path + "\n") loop; this PR did not introduce it.
    • Next step: the PR body already lists it. It should go to a follow-up, since fixing it (for example, filtering names the way jscpd's split_invalid_names does) would change behavior, which Simplify the collectors code-metrics plugin code #14423 rules out.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 37f402a

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-15179-37f402a99c24efe623d64d2da89974c8b6517fb9, 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 bc02a6c Nov 10, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14423-42885991157-1 branch November 10, 2026 22:06
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit bc02a6caee5856bddb8b2103cea2ca06dbddf2f0; 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 code-metrics plugin code

0 participants