Skip to content

refactor(code-metrics): simplify dispatch, python-resolve and replica-collapse scripts - #15030

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

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

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #14425

Summary

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

Behavior-preserving simplification of five of the eight listed code-metrics scripts. dispatch.sh folds the JOBS default into one parameter expansion, collapses the three sentinel ladder tools (none, n/a, deferred) into one status/fallback case with a single run_row call, and maps threshold names through a case. python-resolve.sh lower-cases with ${resolved,,} instead of forking printf|tr (bash 4 is already guaranteed by the function's own check) and returns the probe status directly. replica-collapse.py extracts the first-match registry lookup into registry_match() and drops the redundant order list, since dicts keep insertion order. replica-collapse.sh folds its two cleanup-and-return-2 branches into one. detect-lanes.sh loses only a redundant lane="". Its set +e around cm_resolve_python and its brace-group usage exits stay, because detect-lanes.sh runs under set -e and the repository's shellcheck config (SC2310) rejects the shorter forms; a first attempt at them failed check-affected and was reverted. entry-common.sh, persist-report.sh and pathglob.py were reviewed and left unchanged: no simplification there made them clearer without moving code or touching the --help banner line ranges cm_usage_banner prints.

Not verified

  • The code-metrics test suites (dispatch.test.sh, detect-lanes.test.sh, python-resolve.test.sh, persist-report.test.sh and the audit-* suites) were not run directly in this lane, which can run only the named wrappers; left to the PR's CI
  • Review finding accepted: cm_collapse_replicas previously returned the final rm -f status on success, so a temp file mktemp created but rm could not delete would have returned 1; it now returns 0 on success. Every failure path still returns 2 and removes the temp file.
  • tidy pass 5 (ai-slop): detect.sh is not a wrapper this lane may run, so the deterministic detector did not run; the fragment's single mandated line was read against the rubric by hand and has no tells
  • ci-status green on the PR: left to the PR's CI

Fix

  • plugins/code-metrics/scripts/dispatch.sh: JOBS default as one ${CODE_METRICS_JOBS:-$(...)} expansion; none/n/a/deferred ladder sentinels share one status/fallback case and one run_row call; halstead/function_lines threshold-name mapping as a case
  • plugins/code-metrics/scripts/python-resolve.sh: ${resolved,,} replaces the printf|tr lower-casing subprocess; probe results returned through && rather than if/return blocks; unused lower local dropped
  • plugins/code-metrics/scripts/replica-collapse.py: registry_match() helper replaces the nested loop-and-break lookup; the redundant order list is replaced by iterating groups.items(); setdefault replaces the manual first-seen bookkeeping
  • plugins/code-metrics/scripts/replica-collapse.sh: cm_collapse_replicas runs both Python steps in one && chain with a single rm and return
  • plugins/code-metrics/scripts/detect-lanes.sh: drop the redundant lane="" (both branches assign it)
  • .changes/code-metrics/work-resolve-issue-issue-14425-42781317997-1-3b202d99.md: patch fragment, ### Changed, "Internal simplification, no behavior change."

Verification

The runner ran each check from the base copy against e3f9c11:

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

The run reports:

Left out: the items under Not verified.

Related

#14425

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

Security review: PR #15030 (head e3f9c11)

No security issues found.

I read every hunk of all 6 changed files. None of them matches a trusted-path glob. No plugin manifest, workflow, trust control, merge hold or instruction surface is touched.

  • plugins/code-metrics/scripts/dispatch.sh:
    • The JOBS default is now a single parameter expansion. The existing ^[0-9]+$ check still validates it.
    • The none/n/a/deferred sentinels now share one status/fallback case. status is reset on every loop iteration, so a value can't carry over from the previous tool, and every argument stays quoted.
    • The threshold-name mapping is now a case.
    • Nothing new reaches a command line, and no user input reaches a new shell string.
  • plugins/code-metrics/scripts/python-resolve.sh: ${resolved,,} replaces the printf | tr call. The WindowsApps-stub skip and the probe order are unchanged, so interpreter resolution still runs command -v over python3/python, then py -3, as before.
  • plugins/code-metrics/scripts/replica-collapse.py: the registry lookup is moved into a helper with the same first-match logic, and setdefault keeps insertion order. Only data handling moved; nothing new touches the filesystem or a command.
  • plugins/code-metrics/scripts/replica-collapse.sh: the two Python steps now run in one && chain. The temp file is still removed on every path, failures still return 2, and success now returns 0. The file mode changes from 644 to 755; it is a sourced helper, so that has no security effect.
  • plugins/code-metrics/scripts/detect-lanes.sh: drops a redundant lane="", since both branches assign it.
  • .changes/...md: changelog fragment only.

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

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #15030 (code-metrics script simplification)

I read every hunk of all 6 changed files. No findings. None of the changed files is on a trusted path.

Behavior check, one change at a time. I traced each one by reading the code. I could not run anything in this lane.

  • detect-lanes.sh: dropping lane="" is safe. Both branches of the if at L157-172 assign lane before it is read at L173.
  • dispatch.sh JOBS: ${CODE_METRICS_JOBS:-$(…)} treats an unset value and an empty one the same way the old -z test did, and the regex guard after it is unchanged.
  • dispatch.sh sentinel tools: status is reset on every pass of the loop. fallback is set on every path that sets status. run_row gets the same arguments for none, n/a and deferred as before. Neither variable is used anywhere else in the script.
  • dispatch.sh threshold-name mapping: the case produces the same names as the two && lines it replaces.
  • python-resolve.sh:
    • ${resolved,,} is safe here because the function already requires bash 4 (L42).
    • _cm_probe only ever returns 0 or 1, and command -v fails with 1, so the function still returns 0, 1 or 2 as before.
    • Under set -e, the [[ … ]] && continue and _cm_probe … && return 0 lines are exempt from errexit. Every caller is either in a || context or wrapped in set +e (detect-lanes.sh L115-118).
  • replica-collapse.py:
    • groups.items() keeps insertion order, which matches the removed order list.
    • setdefault keeps the first index seen, as the old code did.
    • members.sort changes list values while iterating the dict, but not the dict's size, so that is safe.
    • registry_match returns the first match, the same tuple the nested loop with break produced.
  • replica-collapse.sh:
    • A && B || rc=2 gives 2 whenever either Python step fails, and the temp file is still removed on every path.
    • The success path now returns 0 instead of rm's status, as the PR body says.
    • The mode change from 100644 to 100755 comes from the lane's own patch step, which marks every changed .sh file executable (scripts/check-affected.sh L240-246). The file is a sourced library, so the executable bit changes nothing at runtime.

Closing issue #14425, acceptance criteria:

  • Behavior unchanged: met, by the trace above. The existing code-metrics suites (dispatch.test.sh, python-resolve.test.sh, detect-lanes.test.sh) cover these paths. The PR says it did not run them and leaves that to CI. I did not run them either.
  • Only listed files and changelog fragments edited: met. Five listed scripts plus one fragment.
  • Within 400 lines and 15 files: met.
  • ci-status green: I can't check this from here. The PR leaves it to CI.
  • Fragment: met. bump: patch, ### Changed, and "Internal simplification, no behavior change."

The PR body's verification results are the author's claims; I did not confirm them. There is no embedded instruction text in the PR context, and there are no prior findings: this is the first review.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for e3f9c11

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-15030-e3f9c11444d903e9dc3dfdd6f8f9c210403f4a69, 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 56c71af Nov 10, 2026
65 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14425-42781317997-1 branch November 10, 2026 08:57
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 4, survived 3, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 57%; mutation score 57%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/code-metrics/scripts/dispatch.sh 2 0 0 0 0 0
plugins/code-metrics/scripts/python-resolve.sh 1 1 0 0 0 0
plugins/code-metrics/scripts/replica-collapse.py 1 1 0 0 0 0
plugins/code-metrics/scripts/replica-collapse.sh 0 1 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/code-metrics/scripts/python-resolve.sh:56 other productive input-gap
plugins/code-metrics/scripts/replica-collapse.py:134 other productive input-gap
plugins/code-metrics/scripts/replica-collapse.sh:64 SBR productive input-gap

The run's summary has the full report.

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 scripts code-metrics plugin code (1 of 2)

0 participants