Skip to content

fix(code-metrics): run one measure per collector in setup check before PASS - #5616

Merged
kyle-sexton merged 9 commits into
mainfrom
fix/5552-setup-check-collector-liveness
Sep 30, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
fix/5552-setup-check-collector-liveness

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Refs: #5552

Summary

setup check marked a collector row PASS on the adapter's version probe alone, so a tool that resolved on PATH but could not measure looked healthy.

Fix

Each collector row now runs the probe and then one measure on a bundled fixture. PASS names the version and the measure. FAIL reports a tool that probed but exited non-zero or returned no rows. WARN probe only marks a collector no bundled fixture can exercise. A missing tool stays an INFO row with its install hint. SKILL.md and the README describe the new row. The plugin is bumped to 0.4.1 with a CHANGELOG entry. Whether the Adopters table gets a row is left to the owner, so this PR uses Refs, not Closes.

Verification

  • bash plugins/code-metrics/skills/setup/scripts/setup-check.test.sh: 24 cases, 0 failed
  • scripts/check-changelog-parity.sh --check, --check-order, --check-bump origin/main: pass
  • scripts/validate-plugins.sh: all manifests and the catalog validated

Related

Issue #5552; the 2026-09-29 owner decision on #3847.

🤖 Generated with Claude Code

kyle-sexton and others added 4 commits September 30, 2026 14:05
…e PASS

A collector row passed on probe alone, so a tool that resolved but could
not measure read healthy. The check now runs one ladder measure on a
bundled fixture: PASS when it returns rows, FAIL when the probe passed and
the measure exited non-zero or returned nothing, WARN probe only when no
fixture can exercise the tool.

Refs #5552

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

PR body contract — issue linkage

This PR body conforms to the issue-linkage contract. Nothing to do.

kyle-sexton and others added 2 commits September 30, 2026 14:14
Satisfies shellcheck add-default-case (SC2249) so the lint job passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review September 30, 2026 18:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T18:22:55.770163Z 52e8da9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 33s —— View job


Security review complete

  • Gather context (PR diff, changed files)
  • Understand the request: invoke /review:security-review for this PR
  • Run /review:security-review per its instructions
  • Post findings

Scope reviewed: all 6 changed files, with focus on the security-relevant surface —
setup-check.sh
(the new check_collector/fixture_files logic that copies bundled fixtures into a mktemp -d
scratch dir and actually invokes each collector adapter's collect subcommand, not just probe)
and the corresponding test additions in
setup-check.test.sh.
The manifest/README/CHANGELOG/SKILL.md changes are documentation and version-bump only.

No security issues found.

Notes from the review (none rise to a reportable finding):

  • The fixture files copied into the scratch directory (FIXTURES="$SCRIPTS/fixtures/sources",
    fixture_files()) are a static, bundled, repo-controlled list — not derived from PR input,
    repo contents under test, or any external/attacker-controlled data — so there's no injection
    path through the cp/mkdir -p "$work/$(dirname "$f")" calls.
  • check_collector now actually executes each resolved collector's collect subcommand (previously
    only probe/version was invoked), but the collector binaries were already being executed for the
    version probe and are tools the operator has deliberately installed and trusted on PATH; this
    doesn't cross a new trust boundary.
  • $name (the collector identifier used in the PROJECT_BOUND substring match and the ladder
    awk filter) comes from enumerating $SCRIPTS/collectors/*.py, a bundled/static file set, not
    external input.
  • Cleanup uses trap 'rm -rf ... "$LIVE"' EXIT on a mktemp -d directory — standard, no race or
    predictable-path issue.
  • No eval, no unquoted expansions of dynamic content, no shell-out with attacker-influenced
    strings.
  • No instruction-surface deletions: SKILL.md only adds detail to the collector-row description;
    no guardrail, permission, or standing instruction is removed or softened.

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 4m 59s —— View job


Claude finished the /review:code-review lane

Summary

Reviewed the diff (gh pr diff 5616, all 6 changed files) against this lane's criteria: correctness and maintainability in plugins/code-metrics/skills/setup/scripts/setup-check.sh and its test, and doc/manifest consistency in SKILL.md, README.md, CHANGELOG.md, plugin.json.

The core change adds check_collector() / fixture_files() to setup-check.sh (lines 142–212), which runs one measure per collector on a bundled fixture before a row can PASS. I traced this carefully:

  • Exit-code 4 convention: the WARN "probe only" branch on rc -eq 4 (setup-check.sh:203) isn't invented here — mypy-report.py's collect() already documents and returns exit 4 for "resolved but cannot run on these files," so the new code correctly matches an existing adapter contract rather than guessing at one.
  • NDJSON row counting (grep -c '^{') is safe: every adapter emits json.dumps(row) with no indent=, so one line per object.
  • Ladder traversal in check_collector (picks the first lane/measure for a tool that has a bundled fixture, falling back to the first ladder row for the "no fixture" message) matches the new test's expectation that line-counter is measured against cm-sample.ts via the typescript file_lines line-counter row.
  • PROJECT_BOUND (eslint-complexity, sonarjs, type-coverage) correctly short-circuits to WARN before attempting collect, matching the stated rationale (needs the project's own node_modules/config, which a fixture copy can't supply).
  • I also checked whether cpd/dupl can ever be exercised: collector-ladder.tsv (unchanged by this PR) never pairs either with the bash lane, and fixture_files()'s duplication case only has content for bash. So those two collectors will always land on the WARN "no bundled fixture" path rather than ever reaching PASS/FAIL. That's consistent with the documented WARN semantics ("no fixture for its lane") and isn't new behavior this PR could regress, so I'm not raising it as a finding — flagging it here only as a fact for the author to weigh, since it's not obvious from the diff alone.
  • Docs (SKILL.md, README.md) accurately describe the new PASS/FAIL/WARN wording, and CHANGELOG.md/plugin.json bump together (0.4.0 → 0.4.1) consistently.

No inline findings — I didn't find a case a careful senior reviewer would block on.

Verification note: I was not able to execute setup-check.test.sh myself (the sandbox in this session denies approval for running shell scripts/git fetch), so the PR body's "24 cases, 0 failed" and the changelog-parity/validate-plugins.sh results are author-claimed and unverified by me — my review is based on static reading of the script, the adapter contract (adapter_paths.py), and cross-referencing mypy-report.py's exit-4 usage, not a test run.
· branch fix/5552-setup-check-collector-liveness

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52e8da909e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 18s —— View job


Security review complete

  • Gather context (PR diff, changed files, prior reviews)
  • Invoke /review:security-review for this PR
  • Post findings

Scope reviewed: all 6 changed files (git diff origin/main...HEAD), against HEAD ac6cf21. The security-relevant surface is
setup-check.sh
(check_collector/fixture_files, which copies bundled fixtures into a mktemp -d scratch dir and invokes each collector adapter's collect subcommand) and the matching additions in
setup-check.test.sh.
plugin.json, CHANGELOG.md, README.md, and SKILL.md are version-bump/doc-only.

No security issues found.

This head (ac6cf21) carries one substantive change since the last security review (52e8da9): the fix for Codex's P1 finding, which now prepends the invoking project's node_modules/.bin to PATH before running a measure from the temp fixture directory —
setup-check.sh:200:
(cd "$work" && PATH="$proj/node_modules/.bin:$PATH" "${PY[@]}" "$adapter" collect "$lane" "$measure" "${fx[@]}" ...). I checked this doesn't open a new trust boundary:

  • proj="$PWD" is captured before the cd, inside a subshell — the PATH mutation doesn't leak into the parent shell.
  • node_modules/.bin is part of the repo the operator is already auditing and already deliberately trusts (this is the standard place npm/yarn scripts resolve local tooling from); this isn't attacker-controlled input reaching a new execution path, just restoring resolution for a devDependency-installed tool once the subshell cds away from the project root.
  • $proj is quoted; no injection via word-splitting or globbing.

Everything from the earlier review of 52e8da9 still holds on this diff: fixtures under fixtures/sources are a static, bundled, pre-existing file set (not part of this PR, not derived from PR/repo-under-test input); $name/$adapter/$lane/$measure come from enumerating bundled files (collectors/*.py, collector-ladder.tsv), not external input; cleanup uses trap ... EXIT on mktemp -d/mktemp, no race or predictable-path issue; no eval, no unquoted expansion of dynamic content, no shell-out with attacker-influenced strings; row() only printfs values, never executes them. No instruction-surface files (CLAUDE.md/AGENTS.md/rules/skill or agent bodies) are touched in this diff, so the instruction-exception-register check doesn't apply here.

Codex's remaining P2 comment (CPD/bash fixture pairing) is a correctness question, not a security one, and is outside this lane's scope — the author's rebuttal (cpd is never paired with bash in collector-ladder.tsv) checks out against the current file.
· branch fix/5552-setup-check-collector-liveness

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 4m 2s —— View job


Claude finished the /review:code-review lane

Summary

This head (ac6cf21) includes the fix for Codex's earlier P1 finding (f32094c: prepend node_modules/.bin to PATH before running a collector's measure on the fixture, so a project-local tool like jscpd still resolves after the subshell cds into the scratch dir). I re-reviewed the full diff against origin/main (all 6 files) given the new commits since the prior pass on 52e8da9.

1 finding, posted inline on setup-check.sh:192-199:

The P1 fix's proj="$PWD" captures the script's own invocation directory, not the already-resolved $REPO_ROOT every other repo-relative operation in this file uses. When setup-check.sh runs from a subdirectory of the repo, or with --repo-root <dir> while $PWD is elsewhere (a case the script explicitly supports), the node_modules/.bin PATH prepend targets the wrong directory, and a project-local tool silently fails to resolve inside the fixture subshell — reopening the same false-negative (FAIL where it should PASS) the P1 fix closed, just for a cwd/REPO_ROOT mismatch instead of the fixture-dir cd. Test 5b doesn't catch it because it also cds into $repo first, making $PWD == $REPO_ROOT there by coincidence. Suggested fix: proj="$REPO_ROOT".

I also traced through both points Codex's review raised on this head:

  • P1 (preserve project-local jscpd across the cd): fixed in f32094c, confirmed by test 5b — modulo the $PWD-vs-$REPO_ROOT gap above.
  • P2 (CPD given a bash duplication fixture it can't use): not reproducible, and the author's rebuttal in review comments is correct — collector-ladder.tsv never pairs cpd with the bash lane (typescript/python/go/dotnet only), so check_collector's ladder scan for cpd never matches the bash-only duplication fixture and lands on WARN probe only: no bundled fixture, not FAIL. I verified this by reading the ladder file directly.

Docs (SKILL.md, README.md) accurately describe the new PASS/FAIL/WARN wording, and CHANGELOG.md/plugin.json bump together (0.4.2 → 0.4.3) consistently. (Note: the PR description says "bumped to 0.4.1", which doesn't match the actual 0.4.3 in the diff — likely just stale description text, not a code issue, so not raised as a finding.)

Verification note: this sandbox denies approval for running shell scripts, git fetch, and even python3 -c in this session, so I could not execute setup-check.test.sh myself. The PR body's "24 cases, 0 failed" and the changelog-parity/validate-plugins.sh results remain author-claimed and unverified by me; my review is based on static reading of setup-check.sh, setup-check.test.sh, collector-ladder.tsv, jscpd.py, and the bundled duplication fixture.
· branch fix/5552-setup-check-collector-liveness

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 6s —— View job


Claude finished the /review:code-review lane

Summary

This trigger fired on a synchronize event, but the new commit (c37dd93, "chore: merge origin/main into fix/5552-setup-check-collector-liveness") only merges origin/main into this branch. I diffed the PR's own files between the previously-reviewed head (ac6cf21) and the current head (c37dd93):

git diff ac6cf21 c37dd93 -- plugins/code-metrics/skills/setup/scripts/setup-check.sh \
  plugins/code-metrics/skills/setup/scripts/setup-check.test.sh \
  plugins/code-metrics/skills/setup/SKILL.md

— no output. setup-check.sh, setup-check.test.sh, and SKILL.md are byte-identical to what this lane already reviewed at ac6cf21 (comment above, 2026-09-30T18:50:45Z), which found one issue (proj="$PWD" vs $REPO_ROOT at setup-check.sh:192) that the author already rebutted in a review comment with a technically sound explanation (the probe that gates entry to check_collector also resolves relative to $PWD, so $PWD and $REPO_ROOT need to agree for the row to be reachable at all — swapping to $REPO_ROOT would desync the probe and the measure rather than fix anything).

The only actual change in this merge commit is version/changelog bookkeeping: plugin.json and CHANGELOG.md moved 0.4.3 → 0.4.4 because origin/main had independently landed an unrelated 0.4.3 (the persist-report.sh project-keying fix), and this branch's own 0.4.3 had to bump to 0.4.4 to keep versions non-colliding. Version bump and changelog entry are consistent with check-changelog-parity.sh's bump rule — nothing to flag.

Per this lane's skip gate ("this head already has a successful review from this lane that still applies"), I'm not re-running a full pass or re-posting the earlier finding — it stands as already addressed (rebutted) on the unchanged code.

No new findings.
· branch fix/5552-setup-check-collector-liveness

@claude

claude Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 46s —— View job


Security review complete

  • Gather context (PR diff, changed files, prior reviews)
  • Invoke /review:security-review for this PR at head c37dd93
  • Post findings

Scope reviewed: diff between the last-reviewed head (ac6cf21, cleared in two prior security
passes on this PR) and current head
c37dd93.

No security issues found.

c37dd93 is a merge of origin/main into this branch (pulling in unrelated commits, notably
ee58afe). I diffed ac6cf21..c37dd93 to see what actually changed:

  • The security-relevant surface —
    setup-check.sh
    (check_collector/fixture_files) and
    setup-check.test.sh —
    is byte-identical to ac6cf21, which already received two clean security passes (on 52e8da9
    and ac6cf21) covering the fixture-copy logic, the collect subcommand invocation, and the
    node_modules/.bin PATH prepend fix for Codex's P1. Nothing new to re-review there.
  • The only changes the merge brought into this PR's own files are non-security: plugin.json
    version bump (0.4.3 → 0.4.4) and CHANGELOG.md/README.md reflow, caused by an unrelated
    persist-report.sh fix landing on main for the same plugin. No code, no logic, no new
    execution or trust-boundary surface.
  • The 40+ other files the merge pulled in from main (claude-ops, discovery, disk-hygiene,
    prototype, visualization, docs) are pre-existing main content unrelated to this PR's diff
    and outside its scope per the skip-gate review-once rule.

This remains consistent with both prior passes: fixtures are a static, bundled, repo-controlled
file set; collector names/adapters/lanes/measures come from enumerating bundled files, not
external input; cleanup uses trap ... EXIT on mktemp -d; no eval, no unquoted expansion of
dynamic content, no shell-out with attacker-influenced strings. No instruction-surface files
(CLAUDE.md/AGENTS.md/rules/skill or agent bodies) are touched by this diff.
· branch fix/5552-setup-check-collector-liveness

@kyle-sexton
kyle-sexton merged commit aa6a958 into main Sep 30, 2026
3 checks passed
@kyle-sexton
kyle-sexton deleted the fix/5552-setup-check-collector-liveness branch September 30, 2026 19:38
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.

1 participant