Skip to content

refactor(tests): share repeated shell test preambles - #17368

Merged
kyle-sexton merged 1 commit into
mainfrom
refactor/shared-test-helpers
Nov 19, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
refactor/shared-test-helpers

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: a duplication sweep the owner requested in a session, with no filed issue

Summary

Shell test preambles that were copied file by file now live in shared helpers, in three groups. No assertion, label or message changes.

Fix

Group Suites Shared home
architecture pass/fail/assert_* block, 29 identical lines 17 (lib/*-references, redact-connection, 10 skill suites) new plugins/architecture/lib/test-helpers.sh, sourced from the plugin's own lib/, as the skill suites already source lib/likec4-golden.sh
ci-status step extraction (two awk programs plus the missing-step guard) 11 scripts/ci-*.test.sh new scripts/lib/ci-step.sh (ci_step::read, ci_step::abort)
check-script contract cases (run_case, discover-mode stdout check, unknown-mode exit check) 7, 8 and 10 scripts/check-*.test.sh scripts/lib/test-harness.sh (test_harness::check_case, assert_discover_quiet, assert_unknown_mode)

The 11 architecture headers saying the primitives are "duplicated on purpose, per docs/contracts/shell-test-helpers" are removed. That contract covers sharing across plugins, and these suites all belong to one plugin, so ADR 0019 vendoring does not apply. check-test-tmp-cleanup.test.sh keeps its own run_case because it commits after setup.

Left as is:

  • Cross-plugin test helpers (the 19-file lib/html2md.test.sh / app-control group, the six *-end-of-turn.test.sh, the five allowed-tools-pairing.test.sh, and the code-metrics / attribution / harness-config / code-tidying groups across plugins): docs/contracts/shell-test-helpers/README.md decides that per-plugin assertion primitives stay duplicated ("Duplication of this shape is the accepted default, not an opt-in"). It calls these clone classes "this decision made visible, not debt to fix". Vendoring them would reverse that decision, which belongs to the owner.
  • Eval scaffolds (review fanout-diversity-*, code-review-large-diff-*, knowledge dd-*-verifier-arms, discipline, source-control commit-*, *-format su-*): per https://code.claude.com/docs/en/plugin-evals#add-setup-or-history-with-case-yaml, a scaffold "starts in the empty workspace with a small fixed environment … Nothing else from your shell reaches it, and neither do the case's EVAL_* variables". No documented variable names the case directory, and no scaffold here locates its own directory. A shared fixture would depend on undocumented loader behavior, so each case stays self-contained.
  • Within-plugin groups of the same shape, kept out so this diff stays reviewable: harness-config (22 files), harness-ops (27), prototype (8; explore-directions and pressure-test detect-ecosystems.test.sh share 177 lines), guardrails, work-items seeds, docs-naming, instruction-placement, ai-slop, source-control, evals plugin-eval, corrections, discovery, disk-hygiene, attribution, playbooks, planning, education, the bash-/powershell-/markdown-format git-hooks, session-flow, multi-agent and testing.

Verification

  • Every touched suite ran before and after the change in the worktree. All exit 0 with the same pass count and 0 failures, for example ci-lanes-pr-hold 345, ci-review-lanes 288, ci-hold-cost-decision 210, architecture dependency-graph 297, collect-containers 192, check-read-caller-keys 73 and check-artifact-retention 52.
  • scripts/check-affected.sh: 19 passed, 1 skipped (ruff, no .py files). fixture-git-isolation, test-tmp-cleanup, plugin-imports, cross-plugin-source-drift, silent-skips and pipefail-grep-q pass. shellcheck is clean on all 41 changed shell files.
  • Left out: the full .github suite, which CI runs.

Related

N/A

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vcupoo79EqmECYFZ4MTv6C

Three groups of suites retyped the same block per file:

- architecture: 17 suites carried an identical pass/fail/assert_* block.
  It moves to plugins/architecture/lib/test-helpers.sh, sourced from the
  plugin's own lib, as the skill suites already source lib/likec4-golden.sh.
  One plugin, so no cross-plugin copy (ADR 0019 does not apply). The
  "duplicated on purpose" headers cited docs/contracts/shell-test-helpers,
  which governs sharing across plugins, not within one; they are removed.
- scripts/ci-*.test.sh: 11 suites read a ci-status step and its run body
  with the same two awk programs and missing-step guard. That is
  scripts/lib/ci-step.sh (ci_step::read, ci_step::abort).
- scripts/check-*.test.sh: seven suites had the same run_case, eight the
  same discover-mode stdout check, ten the same unknown-mode check. These
  join scripts/lib/test-harness.sh as test_harness::check_case,
  assert_discover_quiet and assert_unknown_mode, the harness already owning
  the shapes a suite driving a script needs. check-test-tmp-cleanup keeps its
  own run_case: it commits after setup.

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 04:02
@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-19T04:04:14.404350Z fa67443 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.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed fa674438c8178e4c5b1525c7606abe5a8df43d0b: read 42 of 42 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.

What changed: this is a test-only refactor. Seventeen architecture-plugin shell suites now source one new file, plugins/architecture/lib/test-helpers.sh, for their pass, fail and assert_* functions. Ten scripts/check-*.test.sh suites now call new shared helpers in scripts/lib/test-harness.sh (test_harness::check_case, assert_discover_quiet, assert_unknown_mode). Eleven scripts/ci-*.test.sh suites now call the new scripts/lib/ci-step.sh (ci_step::read, ci_step::abort). There is also one changelog fragment with bump: none.

Checks run:

  • No trusted paths. None of the 40 files matches a TRUSTED PATHS glob. No workflow, action, merge-hold script, manifest or token path changes.

  • Hold-step tests still check the same things. Several suites assert the shape of the ci-status hold steps in pr-require-checks.yml (ci-lanes-pr-hold, ci-hold-*, ci-review-lanes, ci-early-queue-holds). I compared the new ci_step::read and ci_step::abort (in chunk 2's scripts/lib/ci-step.sh) with the inline code they replace:

    • The two awk programs are the same.
    • Both versions write the run body to the same file.
    • ci_step::read returns nonzero when that body is empty.
    • The abort still calls fail, then test_harness::report, then exit 1.
    • The step variable each suite matches its if: and env literals against gets the same contents.

    No hold-step assertion was dropped or loosened.

  • check_case behaves the same. It runs eval "$setup" exactly as the per-suite run_case it replaces did. Each suite hard-codes its setup strings, so this adds no new input.

  • Deleted comments are not instructions. The removed lines are header comments in test files ("duplicated on purpose, per docs/contracts/shell-test-helpers"). They are not a CLAUDE.md, rule, skill, agent or hook allowlist, and no control depends on them. The instruction-surface lens does not apply.

Chunk 2 of 2 (2 files)

Security review: chunk 2 of 2 (scripts/lib/ci-step.sh, scripts/lib/test-harness.sh)

I found no security issues in this chunk.

What I checked

  • scripts/lib/ci-step.sh (new file): It adds two test helpers. ci_step::read uses awk to pull a named step's run: | body out of a workflow file into a temp file. ci_step::abort records a failure and exits. Both run only inside the test suites. The step name and paths come from the test files' own literals, not from pull request, issue or comment text, so no untrusted input reaches them. Neither file is on the trusted-path list, and neither gates a merge hold, a token, the kill switch or a trusted-actor check.
  • scripts/lib/test-harness.sh: It adds test_harness::check_case, assert_discover_quiet and assert_unknown_mode. check_case runs eval "$setup" inside the fixture tree. That eval is not new: the full diff removes it from 7 per-suite run_case copies. Each $setup string is a literal in a committed test file, so this is the same code moved into one place, not a new way to inject commands.
  • Instruction-surface lens: These files contain no standing instruction, hook block list or allowlist, so nothing was deleted, narrowed or softened.
  • Plugin manifests: Neither file is a manifest, so I wrote no manifest lines.
  • Spend: The change adds no billing and no extra lane or API usage.

Prior findings: none. This is this lane's first review of the pull request, so the review was not blocking-only.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Chunk 1 of 2 (40 files)

Code review: chunk 1 of 2 (40 files)

No findings in this chunk. This is a refactor that moves repeated shell test setup into shared helpers. I compared each removed block with the helper that replaced it, and they behave the same.

What I checked

  • Architecture plugin suites (17 files plus the new plugins/architecture/lib/test-helpers.sh).
    • The shared pass, fail, assert_contains, assert_not_contains and assert_equals match the removed copies word for word. Only the indentation of the case branches changed. FAILED and CASE_NUM still start at 0.
    • Every suite sets SCRIPT_DIR before it sources the helper.
    • The skill suites reach the helper through $SCRIPT_DIR/../../../lib/. That is the same path the plugin's runtime scripts already use for lib/record-layout.sh and lib/likec4-golden.sh, so it adds no new kind of dependency.
    • Sharing inside one plugin matches docs/contracts/shell-test-helpers/README.md, which only forbids sharing across plugins. plugins/source-control/scripts/test-helpers.sh is an existing example of the same pattern. The bump: none changelog fragment fits a test-only change.
  • scripts/check-*.test.sh (10 files).
    • Each run_case now calls test_harness::check_case mk_tree <script> "$@", which keeps the old local names (tree, label, expected, setup).
    • Each mk_tree writes its result through ${!1} and fixture_tree::build "$1", so the result still lands in the caller's local tree as before.
    • After shift 5, the remaining arguments are the same must-name strings the old shift 3 left.
    • The discover-mode and unknown-mode checks keep their labels, expected exit codes and empty-stdout condition.
    • check-docs-naming and check-conformance-registry change only the unknown-mode check. check-test-tmp-cleanup keeps its own run_case, as the PR description says.
  • scripts/ci-*.test.sh (11 files).
    • ci_step::read runs the same two awk programs. It prints the step text and returns non-zero when the extracted body is empty.
    • ci_step::abort runs in the main shell, not a subshell, so its exit 1 still ends the suite after test_harness::report. fail and test_harness::report are defined first because test-harness.sh is sourced before ci-step.sh.
    • The step text still loses its trailing newline the same way as before, so the later checks against $step see unchanged input.

Review criteria

  • Closing issue: none. The PR says it is a requested duplication cleanup with no filed issue, so I have no acceptance criteria to check.
  • Loosened-check verdict: fail (default; the prompt gave no loosened_check_verdict: or loosened_check_patterns: line); patterns: 0. No test was skipped, no assertion weakened and no check removed; the assertions moved into helpers unchanged.
  • The prompt gave no loosened_check_decision_record: line, so I did not check the citation requirement.
  • No plugin manifest changed, so there are no manifest lines.
  • This is the first review of this PR, not a blocking-only one. There were no prior findings and no settled threads.
  • Verification: the pass counts, the shellcheck result and the check-affected.sh results come from the PR description. I could not run them in this lane.

Verifier dropped 0 of 0 candidates.

Chunk 2 of 2 (2 files)

Code review: chunk 2 of 2 (scripts/lib/ci-step.sh, scripts/lib/test-harness.sh)

No findings in this chunk.

This chunk adds the two shared helper homes that the refactor's callers (in chunk 1) now use. I compared each helper line by line with the inline code it replaces in the full diff:

  • ci_step::read / ci_step::abort (scripts/lib/ci-step.sh): both awk programs are copied unchanged, and the -s body check moved into the function's return status. Callers use step="$(ci_step::read ...)" || ci_step::abort ..., so errexit cannot cut the substitution short. The exit 1 in ci_step::abort runs in the top-level shell, so it still ends the suite and fires the callers' EXIT trap, as the old inline block did. fail and test_harness::report come from test-harness.sh, which every caller sources first.
  • test_harness::check_case: it matches the old run_case body. local tree still sits in the function that calls the fixture builder, so mk_tree tree still sets it through bash dynamic scoping. The two new locals have the _th_ prefix, so they can't shadow any name a <setup> string or a builder reads. The script path $tree/scripts/$_th_script gives the same path as the old literal in each caller.
  • assert_discover_quiet / assert_unknown_mode: these match the removed blocks. stdout and rc are now function locals, not globals. Every caller I checked ends with test_harness::report or, in check-docs-naming.test.sh, a later step, and none of them reads the old globals afterwards.

I did not run the suites. The PR's before/after pass counts and its clean shellcheck run are the author's claims, not something I checked.

Closing issue: none ("No related issue"), so I checked no acceptance criteria. No path-scoped rule under .claude/rules/ matches scripts/lib/*.sh. The PR context contains no embedded directives.

Loosened-check verdict: the wrapper wrote no loosened_check_verdict:, loosened_check_patterns: or loosened_check_decision_record: lines. The default verdict fail therefore applies with no consumer entries, and the citation requirement was not checked. No change in this chunk loosens a check, because each assertion and its exit-code test moved unchanged.

Verifier dropped 0 of 0 candidates.

critical-findings: 0

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