Skip to content

refactor(tests): share repeated shell test helpers within four plugins - #17395

Merged
kyle-sexton merged 1 commit into
mainfrom
refactor/same-plugin-test-helpers-prototype-guardrails
Nov 19, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
refactor/same-plugin-test-helpers-prototype-guardrails

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: in-repository duplication pass (control-hub#17), same-plugin test helpers.

Summary

Shell suites in prototype, guardrails, docs-naming and instruction-placement retyped the same test helpers in every file. Each repeated block moves to a helper file inside its own plugin, and the suites source it. Nothing is shared across plugins: docs/contracts/shell-test-helpers/README.md keeps cross-plugin duplication by decision, and an installed plugin can only source its own files. Same shape as #17368 did for architecture.

53 files, +502 / −1417.

Fix

Plugin Helper file Sourced by What moved
prototype lib/test-helpers.sh 3 detect-ecosystems suites pass/fail/assert block; detect_wrapper_contract, the 177-line body the two skill wrapper suites shared, taking the skill and sibling names that were their only differences
prototype lib/browser-test-helpers.sh 5 explore-directions browser suites prerequisite check, scratch dir, playwright session, cleanup trap, ok/bad (browser_setup <prefix> <session> <tools>), bridge start (browser_serve), native/result/code/check
docs-naming lib/test-helpers.sh 8 suites pass/fail/assert_eq/assert_contains/assert_lacks/assert_absent
instruction-placement lib/test-helpers.sh 10 suites pass/fail/assert_eq/assert_contains
instruction-placement lib/migrate-test-helpers.sh 3 migrate suites their own fail() shape, asserts, command_not_found_handle
guardrails lib/git-hooks-test-helpers.sh 5 git-hooks suites + hooks/git-hooks-notice expect <label> <want> <got> (kept apart from hooks/guardrails-test-helpers.sh, whose expect drives guard_invoke)
guardrails hooks/guardrails-test-helpers.sh (existing) pairs of hook suites 65 KB boundary builders and assert_bounded_exit, GitHub MCP payload builders, alias_chain, nul_payload/nul_stderr, replall_json
  • The two wrapper suites add a test-scope line naming the canonical detector and the sibling wrapper, since the paths that named them now sit in the helper.
  • Comments that documented a moved helper are dropped, not moved (the comment lint judges every added comment line); their reasons are in the commit message.
  • bump: none fragments for the four plugins.

Left as they are: guardrails skip() (three suites, each next to a silent-skip-ok marker), run_bounded (differs per suite), the browser suites' run/relocate/page (differ), harness-browser's script_path, and the result footers.

Related

Verification

  • Every touched suite (42) ran before and after on this machine: identical rc/pass/fail/skip on all 42, 0 failures. Passing labels match line for line apart from timings and temp paths. Totals: 4,595 passing checks before, 4,595 after (block-dangerous-git 1094, secret-pattern-detection 315, block-no-verify 470, ...). The five browser suites ran with playwright-cli present (83, 25, 28, 29, 15 passes).
  • shellcheck (repo .shellcheckrc) clean on all 53 changed files. shfmt -d (repo .editorconfig): new files clean; every edited file it flags was already flagged on main.
  • scripts/check-changelog-fragments.sh --check: valid. scripts/affected-tests.sh --base origin/main: every changed file maps, exit 0.
  • Pre-commit (comment lint, content scan) and pre-push (check-affected) hooks passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vcupoo79EqmECYFZ4MTv6C

Suites in prototype, guardrails, docs-naming and instruction-placement
retyped the same helpers per file. Each block moves to a helper file inside
its own plugin and the suites source it; nothing crosses a plugin boundary,
so docs/contracts/shell-test-helpers (cross-plugin duplication) is untouched.

- prototype: lib/test-helpers.sh holds the pass/fail/assert block of the
  three detect-ecosystems suites, and detect_wrapper_contract, the 177-line
  body the two skill wrapper suites shared. The suites differed only in their
  own skill name and the sibling's, now arguments. Each wrapper suite keeps
  its header and declares the canonical detector and the sibling wrapper in
  test-scope, since the paths that named them moved into the helper.
  lib/browser-test-helpers.sh holds the five explore-directions browser
  suites' prerequisite check, scratch dir, playwright session, cleanup trap,
  ok/bad, bridge start, and the native/result/code/check helpers;
  browser_setup takes the scratch prefix, session prefix and tool list that
  were the only differences. playwright-cli keeps its logs and Chromium its
  sockets in the scratch dir: that is why pw runs there.
- docs-naming: lib/test-helpers.sh, the pass/fail/assert_* block of eight
  suites (assert_lacks and assert_absent stay two functions: their messages
  differ).
- instruction-placement: lib/test-helpers.sh for ten suites, and
  lib/migrate-test-helpers.sh for the three migrate suites, whose fail()
  prints a different shape. The migrate file also carries
  command_not_found_handle: an unknown command counts as a failure through a
  file, because bash runs the handler in whatever subshell hit it and a
  subshell's counter increment is lost.
- guardrails: the git-hook suites' expect (label want got) goes to
  lib/git-hooks-test-helpers.sh, apart from hooks/guardrails-test-helpers.sh,
  whose expect drives guard_invoke. guardrails-test-helpers.sh gains the
  builders two hook suites each repeated: the 65 KB boundary payload
  (size_filler, sized_write_json, assert_bounded_exit; jq reads content on
  stdin because a 65 KB --arg passes the Windows argv limit, and a 124 exit
  is named as a hang, not a block), the GitHub MCP payloads (mcp_single_json,
  mcp_push_json, scoped), alias_chain, nul_payload and nul_stderr, and
  replall_json (replace_all is the one Edit shape where repetition is
  expected). mcp_push_json's local array is renamed jq_args so it no longer
  shadows a suite's args for shellcheck.

Left as they are: guardrails skip() (three suites, each beside a
silent-skip-ok marker), run_bounded (differs per suite), the browser suites'
run/relocate/page (differ), harness-browser's script_path (a differently
named native), and the result footers.

Comments that documented a moved helper are dropped rather than moved: the
comment lint judges every added comment line. Assertions, labels and
messages are unchanged; every touched suite passes with the same count
before and after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vcupoo79EqmECYFZ4MTv6C
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 19, 2026 06:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T06:42:40.132927Z 9f34982 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.

@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: 9f349829b3

ℹ️ 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".

@github-actions

Copy link
Copy Markdown
Contributor

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

Chunk 1 of 2 (40 files)

Security review: chunk 1 of 2 (40 files)

No security issues found in this chunk.

Every change here is a test-only refactor. Shell test helpers that each suite used to define for itself now live in one helper file per plugin, and the suites source that file:

  • docs-naming: pass/fail/assert_* move to plugins/docs-naming/lib/test-helpers.sh, sourced by 8 suites.
  • instruction-placement: the same kind of helpers move to lib/test-helpers.sh (10 suites). The migrate helpers, including command_not_found_handle and its UNKNOWN_COMMANDS temp file, move to lib/migrate-test-helpers.sh (3 suites). The EXIT traps that remove UNKNOWN_COMMANDS stay in each suite.
  • guardrails: expect moves to lib/git-hooks-test-helpers.sh (5 git-hooks suites and git-hooks-notice.test.sh). The payload builders (replall_json, nul_payload, nul_stderr, size_filler, sized_write_json, mcp_single_json, mcp_push_json, scoped, alias_chain) and assert_bounded_exit move into the existing hooks/guardrails-test-helpers.sh. I compared the moved bodies with the deleted ones and found no change in behaviour. The only edit is that a local array in mcp_push_json was renamed from args to jq_args.
  • Changelog fragment: .changes/docs-naming/...4d598a9c.md is a bump: none note, and the three identical fragments under .changes/ are copies at equivalent changelog paths. Their location does not change what they do.

What I checked:

  • Hooks and plugin manifests: no changed file is a hook, a guard script, a workflow, a manifest, or anything else under the trusted-path list. The guard hooks themselves are unchanged: only the code that tests them moved, so no guard's block list or allowlist was narrowed.
  • Paths sourced: every new source line uses a fixed path inside the plugin ($SCRIPT_DIR/.., $PLUGIN/lib, $ROOT/lib). None takes outside input, so nothing can be injected through them.
  • Instructions and manifests: no standing instruction (CLAUDE.md, a skill or agent body, a rules file) and no plugin.json or marketplace.json is touched, so no manifest lines apply.
  • Prior and settled threads: this lane has no prior findings on this pull request. The single settled thread (migrate-test-helpers.sh lines 36-39, settled by an owner reply stating a decision, lines unchanged) is about where a comment's reason is recorded, not a security point, and I am not raising it again.

Chunk 2 of 2 (10 files)

Security review: chunk 2 of 2 (prototype plugin test helpers)

No security issues found in this chunk.

What was reviewed

I read all 10 files in chunk 2:

  • 2 new helper files: plugins/prototype/lib/browser-test-helpers.sh and plugins/prototype/lib/test-helpers.sh.
  • 8 test suites that now source those helpers: 3 detect-ecosystems suites and 5 explore-directions browser suites.

What the change does

It is a refactor of test scaffolding only. Two kinds of code move into the new helper files:

  • Repeated test code. The pass/fail/assert functions, the scratch-dir and playwright session setup, the cleanup trap, the notes-bridge start, and the native/result/code/check functions.
  • The shared detector wrapper test. The wrapper-contract body that the two skill wrapper suites both carried is now detect_wrapper_contract.

Checks

  • Behaviour is unchanged. The moved code matches the removed code except for three things:
    • the scratch-dir prefix and session prefix are now passed in as arguments;
    • ${bridge:?} makes the cleanup and serve steps stop with an error when bridge is unset;
    • the cleanup case match uses the BROWSER_TMP_PREFIX value set right after mktemp.
  • Cleanup is still safe. rm -rf still runs only on a path matching */<prefix>.*, the same guard as before.
  • check() still passes $2 to python3 -c as code. This is not new: the removed copies did the same, and every caller passes a fixed literal from its own suite.
  • Nothing reaches shipped code or CI. No hook, skill body, manifest, workflow or trust-control file is in this chunk. No userConfig or .claude-plugin manifest is touched. No instruction surface is deleted or weakened: the removed comments are rationale for test code.
  • The new test-scope lines only map files to tests for the affected-tests tooling.
  • Identical files. The copied changelog fragments under .changes/<plugin>/ are bump: none data at ordinary fragment paths, so their location does not change what they do.

Context

  • Prior findings: none. This is the first review of this PR (blocking only: no).
  • No settled threads apply.
  • No embedded instructions were found in the PR context.
  • Spend: none beyond the normal test runs.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Chunk 1 of 2 (40 files)

Code review: chunk 1 of 2 (docs-naming, guardrails, instruction-placement)

No findings. I read every hunk of the 40 files in this chunk. The changelog fragment copies listed in identical.txt were counted through their first path. Each copy is a bump: none fragment under its own plugin's .changes/ directory, and the path only picks which plugin it belongs to, so a copy's path changes nothing about what it does.

What I checked, using the files at head:

  • Source paths resolve to the new helpers. Each suite defines the variable it sources from before the source line:

    • all 8 docs-naming suites define SCRIPT_DIR at lines 10–24, so ../lib or ../../../lib reaches plugins/docs-naming/lib;
    • the 5 guardrails git-hooks suites define PLUGIN="$(cd "$HERE/.." && pwd)", and git-hooks-notice.test.sh defines ROOT the same way, so each reaches plugins/guardrails/lib/git-hooks-test-helpers.sh;
    • in instruction-placement, the relative depth is right from context/, evals/, scripts/, scripts/lib/ and skills/migrate/scripts/.

    Each # shellcheck source= directive matches its runtime path.

  • Moved guardrails hook helpers are still reachable. hardcoded-path-check, secret-pattern-detection, skill-reference-verify, stale-path-verify, block-dangerous-git, block-no-verify and block-noncanonical-commit all source hooks/guardrails-test-helpers.sh before the call sites. The functions those helpers call are defined in that same file: ok, bad and guard_invoke, the last of which sets GUARD_ERR and GUARD_RC. $FIXTURE is read at call time, and each suite sets it before the boundary cases (hardcoded-path-check.test.sh:55, secret-pattern-detection.test.sh:78). No other file in the plugins defines a helper with one of the moved names, apart from an eval fixture copy under plugins/testing/.../u34/, which is never sourced.

  • The moved helpers behave the same.

    • docs-naming keeps assert_lacks ("does not contain") and assert_absent ("does NOT contain") as two functions with their original messages.
    • The migrate suites' two-line fail shape is unchanged.
    • UNKNOWN_COMMANDS and command_not_found_handle still come before each suite's trap … rm -f "${UNKNOWN_COMMANDS:-}".
    • The skip and assert_lacks/assert_not_contains functions kept in some suites still work with the shared counters (CASE_NUM, FAILED, SKIPPED).
    • In mcp_push_json, renaming the local args to jq_args changes nothing outside the function.
  • No check was loosened. No assertion, expected value, threshold or suppression changed meaning, and no case was dropped. The only added shellcheck disable lines (SC2154 for FIXTURE, SC2016 and SC2329) were moved along with the code they cover.

  • Path-scoped rules. .claude/rules/mod-authoring.md, cost-claims.md, skill-bodies-state-current-rules.md and eval-case-transcripts.md match some paths in this chunk. These are test-only helper moves, and none of those rules' criteria apply to them.

  • Settled threads. The settled thread on plugins/instruction-placement/lib/migrate-test-helpers.sh lines 36–39 is about the dropped command_not_found_handle comment. The owner rejected that finding and its lines are unchanged since, so I did not raise it again.

  • Closing issue. The PR closes no issue ("No related issue"), so I had no acceptance criteria to check against.

  • Not verified by me. The author's report that the 42 suites give the same results before and after (4,595 passing checks each time) and that shellcheck is clean comes from the PR description. I could not run any shell in this lane.

Loosened-check verdict: fail (default; the prompt had no loosened_check_verdict: or loosened_check_patterns: line); patterns: 0. The prompt also had no loosened_check_decision_record: line, so I did not check the citation requirement.

No plugin manifest changes in this chunk.

Verifier dropped 0 of 0 candidates.

Chunk 2 of 2 (10 files)

Code review, chunk 2 of 2 (the 10 plugins/prototype files): no findings.

This chunk moves the repeated shell test helpers into two files that live inside the plugin. Behaviour stays the same.

  • plugins/prototype/lib/test-helpers.sh
    • The pass/fail/assert_* block, body and run_from match the removed copies, apart from case indentation.
    • detect_wrapper_contract carries every assertion from the two removed wrapper suites, in the same order and with the same labels. The skill and sibling names are now parameters.
    • The fixtures became local multi/empty, and basename still produces the same labels.
    • # shellcheck disable=SC2016 sits before the first command, so it still covers the whole file and the single-quoted ${…} strings that moved with the body.
    • The root scripts/detect-ecosystems.test.sh sources only the assert block and keeps its own TEST_TMPDIR and trap.
  • plugins/prototype/lib/browser-test-helpers.sh
    • browser_setup keeps the original order: prerequisite SKIP, then mktemp, then trap finish EXIT. So a SKIP still exits before any cleanup is set up, as before.
    • tmp, d, session and port stay global, which the suites rely on ($tmp, $session, $port, $d).
    • The cleanup guard now matches */"$BROWSER_TMP_PREFIX".*, which each suite sets through its prefix argument. ${bridge:?} holds because every suite sets bridge before it sources the file.
    • Under the suites' set -euo pipefail, ok/bad/check/code behave as before.
    • Suites that keep their own run/script_path still work.
  • Dropped # prereq-ok: test-only markers. The new helper is not a *.test.* file, so scripts/check-declared-prerequisites.mjs scans it. The playwright-cli, python3, node and curl calls it now holds are all declared in plugins/prototype/prerequisites.json, so dropping the markers opens no gap.
  • Extra # test-scope: lines. The two wrapper suites now carry a second line. scripts/affected-tests.sh (scope_declarations) reads every test-scope line in the leading comment block, so these are picked up.

Loosened checks. No assertion, expected value or check was removed or relaxed. Every moved assertion is carried over as it was.
Loosened-check verdict: fail (default: the prompt carried no loosened_check_verdict: / loosened_check_patterns: lines); patterns: 0. The prompt had no loosened_check_decision_record: line, so the citation requirement was not checked.

Closing issue. The PR closes none ("No related issue"), so there are no acceptance criteria to check. No plugin manifest changed in this chunk.

Settled thread. The one settled thread is on plugins/instruction-placement/lib/migrate-test-helpers.sh, which is in chunk 1, not this one.

Author's verification. The PR's claims (42 suites with identical results before and after, shellcheck clean) are the author's and unverified here: this lane has no shell to run them.

Verifier dropped 0 of 0 candidates.

critical-findings: 0

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 6d12ca5 Nov 19, 2026
170 of 185 checks passed
@kyle-sexton
kyle-sexton deleted the refactor/same-plugin-test-helpers-prototype-guardrails branch November 19, 2026 08:56
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

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

File Killed Survived Timeout No coverage Invalid Not run
plugins/docs-naming/lib/test-helpers.sh 0 1 0 0 0 0
plugins/guardrails/hooks/guardrails-test-helpers.sh 0 0 0 0 0 1
plugins/guardrails/lib/git-hooks-test-helpers.sh 0 0 0 0 0 1
plugins/instruction-placement/lib/migrate-test-helpers.sh 0 1 0 0 0 0
plugins/instruction-placement/lib/test-helpers.sh 1 0 0 0 0 0
plugins/prototype/lib/browser-test-helpers.sh 1 0 0 0 0 0
plugins/prototype/lib/test-helpers.sh 1 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
plugins/docs-naming/lib/test-helpers.sh:13 SBR unclassified none
plugins/instruction-placement/lib/migrate-test-helpers.sh:39 SBR unclassified none

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

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant