Skip to content

refactor(harness-ops): simplify the second half of install_state.py - #15681

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-14510-43300879038-1
Nov 12, 2026
Merged

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

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #14510

Summary

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

Simplified the functions that start in lines 1034-2066 of install_state.py (range 2 of 2 of the 2066-line file at the start of this part) without changing behavior. The changes: summarize_numeric's nested five-way conditional for self_pids_walk_note is now a _WALK_NOTES lookup with the same fallback, and its tallies use Counter. largest_subtrees finds each directory's largest child in one pass instead of rescanning every key for every key (O(n) instead of O(n^2)). node_modules_bucket keeps one tally dict per bucket in place of six variables. unreferenced_versions sums sizes with Counter. home_root_state sets note on its record instead of copying it. recent_writers keeps the newest mtime with max(). engine_version reuses _LIB_DIR instead of recomputing the path. write_csv builds its header and rows from FileRow's fields through csv_safe, which leaves ints, bools and ISO mtimes unchanged. No public name, flag, JSON key or key order, CSV content, exit code or printed text changed.

Not verified

  • Python test suites (test_install_state.py, install_state.test.sh) not run: this lane has no interpreter; left to the PR's CI
  • ci-status green on the PR: a PR CI check, left to the PR's CI
  • Build and lint of the Python file not run locally (no interpreter or linter in this lane); left to the PR's CI
  • Tidy passes 4 (docs-hygiene) and 5 (ai-slop fix) skipped: the only markdown lines are the changelog fragment text the issue mandates word for word, so no edit was allowed. Tidy passes 1-3 ran. Pass 1 condensed the largest_subtrees filter, but that dropped the 'has children' guard for passthrough…
  • Untracked dotfiles at the checkout root (.bashrc, .gitconfig, .idea, .mcp.json, .vscode and similar) come from the runner environment, not this change; they were not counted, touched or removed

Fix

  • plugins/harness-ops/skills/audit-install-state/scripts/install_state.py: simplified recent_writers, summarize_numeric (plus a new private WALK_NOTES constant next to the WALK* constants), home_root_state, largest_subtrees, node_modules_bucket, unreferenced_versions, engine_version and write_csv;…
  • .changes/harness-ops/work-resolve-issue-issue-14510-43300879038-1-f4563544.md: patch fragment from new-changelog-fragment, body '### Changed' and 'Internal simplification, no behavior change.'

Verification

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

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

The run reports:

  • check-changelog-fragments: all 15 fragments valid (run after the edits, after tidy, and after the review fixes)
  • check-changed-skills: audit-install-state PASS, 0 errors, 1 warning that was already there (SKILL.md body length, file not touched)
  • check-affected: 13 passed, 6 skipped (skipped ones are tools not installed or that run code from the checked tree), 0 failed
  • fresh-context review subagent compared each hunk against HEAD for edge cases (zero-byte files, unknown walk values, dict key order, Counter vs dict serialization, csv cell values) and found no behavior difference; it raised two coupling concerns, both fixed (CSV header now derived from the same…
  • git-read diff --numstat HEAD: one source file changed plus one new fragment, well under the 400-line / 15-file limit
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43300879038

Left out: the items under Not verified.

Related

#14510

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

Copy link
Copy Markdown
Contributor

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

Security review: PR #15681 (head cd8a329)

No security issues found.

Scope: I read the whole change in both listed files: .changes/harness-ops/work-resolve-issue-issue-14510-43300879038-1-f4563544.md and plugins/harness-ops/skills/audit-install-state/scripts/install_state.py. Neither matches a trusted-path glob. The PR changes no trust control, merge hold, workflow, manifest or instruction surface.

What I checked:

  • CSV formula-injection guard (write_csv). Before this change, the rows called csv_safe on each string field one by one. Now every value in dataclasses.astuple(row) goes through it. csv_safe returns non-strings unchanged, so the int bytes and bool deny_listed cells come out as before. mtime (an ISO string) now also passes through the guard, which adds protection and removes none. The header comes from the FileRow fields in their declared order, with mtime renamed to mtime_utc. That is the same columns as the old hard-coded list. FileRow has no field holding file contents or secrets, so building rows from the dataclass adds nothing to the artifact.
  • engine_version. _LIB_DIR is Path(__file__).resolve().parents[3] / "lib", so _LIB_DIR.parent is the same manifest directory the old code computed. It reads the same file, and nothing new controls the path.
  • home_root_state. It now sets note on the record instead of copying the record. Values are still never read, and the note text is the same.
  • summarize_numeric, largest_subtrees, node_modules_bucket, unreferenced_versions and recent_writers. These tallying refactors have no trust-boundary, injection or secret-handling surface.
  • Changelog fragment. Plain text only.

Embedded text: none found in the PR context.

The protected-class list in the instruction-exception register was not consulted: the diff deletes or softens no standing instruction.

Spend: none. The change only affects a local audit script.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: no findings

I read the whole diff: both changed files, every hunk. This PR refactors the second half of install_state.py and adds a changelog fragment. Neither file matches a trusted-path glob, and no plugin manifest changed. This is the first review of this PR (0 earlier heads reviewed), so I reviewed everything, not only blocking issues.

Each hunk against the base, read from the head file:

  • recent_writers: max(seen.get(head, row.mtime), row.mtime) keeps the newest mtime per head and the same insertion order. The mtimes are ISO strings from iso(), so comparing them as strings is fine.
  • summarize_numeric:
    • Counter is already imported (L43).
    • Both tallies are written through dict(sorted(...)), so the JSON is unchanged.
    • _WALK_NOTES.get(walk, _WALK_NOTES[WALK_PARENT_ONLY]) gives the same text and the same fallback as the old nested conditional.
  • home_root_state: record is a fresh dict on each loop pass and has no note key before this line, so setting it in place gives the same key order as the old copy.
  • largest_subtrees: key.rpartition("/")[0] == parent marks a direct child exactly as the old startswith(prefix) with no further / did, since every key has at least min_depth ≥ 2 segments. Sizes are never negative, so the 0 default in max does not change the guard. The size and children and ... guard is still there as bucket[0] and key in largest_child and ....
  • node_modules_bucket: measured() gives bytes, files, directories, evidence in the old order, with note after them in the nested object.
  • unreferenced_versions: summing with Counter gives the same totals.
  • engine_version: _LIB_DIR is Path(__file__).resolve().parents[3] / "lib" (L48), so its .parent is the old path. Dropping IndexError is safe because the module-level computation would already have raised it at import.
  • write_csv:
    • The FileRow fields (L592-601) match the old nine-column header in order, with mtime renamed to mtime_utc.
    • csv_safe (L1838) passes non-strings through untouched, and ISO mtimes start with a digit.
    • len(rows) equals the old count of rows written.

Closing issue #14510:

  • The fragment has bump: patch and the required body text.
  • Only the listed file and the fragment are edited.
  • The diff is well under the size limits.
  • Every changed function, and the new _WALK_NOTES constant, sits in range 2 of 2 of the file.
  • Unchanged behavior is covered by the existing test_install_state.py tests that call write_csv and check engine_version.
  • I could not run anything (no interpreter in this lane), so the tests and ci-status green are unverified by me. The PR's own verification claims come from its author and are also unverified.

There is no embedded instruction text in the PR context.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for cd8a329

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-15681-cd8a329c75f3d676d2ca771dd1e8a418620dfae7, expires on 2026-12-12.

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Merge-Risk: max=MEDIUM demote=false head=cd8a329c75f3d676d2ca771dd1e8a418620dfae7 rubric=8.4.13 rater=claude-opus-5-5 checker=claude-opus-5-5

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit a870cb1 Nov 12, 2026
50 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-14510-43300879038-1 branch November 12, 2026 21:28
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 2, survived 5, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 29%; mutation score 29%.

File Killed Survived Timeout No coverage Invalid Not run
plugins/harness-ops/skills/audit-install-state/scripts/install_state.py 2 5 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/harness-ops/skills/audit-install-state/scripts/install_state.py:1113 other productive no-assertion
plugins/harness-ops/skills/audit-install-state/scripts/install_state.py:1315 other productive input-gap
plugins/harness-ops/skills/audit-install-state/scripts/install_state.py:1362 SBR productive no-assertion
plugins/harness-ops/skills/audit-install-state/scripts/install_state.py:1528 ROR productive no-assertion
plugins/harness-ops/skills/audit-install-state/scripts/install_state.py:1871 ROR productive no-assertion

The run's summary has the full report.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The post-merge check verified merge commit a870cb1aab28b47506244e5a4fad717fafcae693; 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 install_state.py harness-ops plugin code (part 2 of 2)

0 participants