Skip to content

refactor(scripts): load active token patterns through one token-scan helper - #15494

Merged
melodic-automation-lanes[bot] merged 3 commits into
mainfrom
work-resolve-issue/issue-15433-43137995556-1
Nov 12, 2026
Merged

melodic-automation-lanes[bot] merged 3 commits into
mainfrom
work-resolve-issue/issue-15433-43137995556-1

Conversation

@melodic-automation-lanes

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

Copy link
Copy Markdown
Contributor

Closes #15433

Summary

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

check-shell-portability.sh and check-skill-portability.sh each had a copy of the block that loads a token list's active patterns. That block is now one function, token_scan::load_active <token-file> <active-var> <operand-var>, in scripts/lib/token-scan.sh, and each script calls it once with || exit 2. The function is a plain call that sets the caller's TOKENS_ACTIVE and TOKENS through namerefs and sets the EXIT trap itself. The trap string is still rm -f "$TOKENS_ACTIVE", set at the same point (after mktemp succeeds, before the patterns are written), so error messages, exit codes, findings and temp-file cleanup are unchanged. The token-file check (token_scan::require_token_file) moved into the helper too, because it was part of the repeated block. Each caller declares TOKENS_ACTIVE and TOKENS at top level before the call, so the nameref assignments always land in globals that the EXIT trap and the awk calls read.

Not verified

  • Did not run scripts/check-shell-portability.test.sh or the skill-portability test suite here: this lane cannot run test runners or bash directly. They are left to the PR's CI, which runs them
  • Tidy skipped: the change is entirely under scripts/, which is on the lane's shared-path list for tidy
  • ci-status green is a PR CI check, left to the PR's CI
  • cant-fail-scan not run: it scans test files, and this change edits none

Fix

  • scripts/lib/token-scan.sh: added token_scan::load_active, which runs the token-file check, read_list::into in leading mode, the empty-set guard, mktemp, the EXIT trap, the pattern write and the awk operand; updated the header to say the file also owns the token-list load and that callers must…
  • scripts/check-shell-portability.sh: replaced the inline load block (require check, read_list::into, empty guard, mktemp, trap, operand) with a top-level declaration and one token_scan::load_active call; shortened the comment above it
  • scripts/check-skill-portability.sh: same replacement and comment change as check-shell-portability.sh

Verification

The runner ran each check from the base copy against 098584e:

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

The run reports:

  • check-affected (no arguments): first run failed shellcheck SC2154 (TOKENS referenced but not assigned) and then SC2034 (TOKENS_ACTIVE unused). Fixed both by declaring the variables at top level and adding a scoped SC2034 disable on TOKENS_ACTIVE. Final run: 10 passed, 6 skipped over 3 changed files
  • check-changelog-fragments (no arguments): all 15 changelog fragments under .changes/ are valid; no plugin changed, so no fragment is owed
  • check-changed-skills (no arguments): no changed skills under plugins/*/skills/, nothing to gate
  • fresh-context review subagent over the change and its callers: no correctness bugs. It confirmed the trap expands to the same command, the nameref chain into read-list.sh's rl locals has no name collision, and nothing else reads token_patterns or sets an EXIT trap. Its comment nits (header…
  • grep across the repo: token_patterns and TOKENS_ACTIVE are used nowhere outside the two scripts; no test asserts on the removed lines
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43137995556

Left out: the items under Not verified.

Related

#15433

Merge-Risk: max=MEDIUM demote=false head=6794ea7bb9d4ed227f0d6414df1c593d6c853465 rubric=8.4.11 rater=claude-opus-5-5 checker=claude-opus-5-5

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

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

Security review: PR #15494 at 6794ea7b

No security issues found.

Scope. I read every hunk of all 5 changed files in .claude-lane/pr.diff:

  • scripts/lib/token-scan.sh adds token_scan::load_active. In order, it:

    1. runs the existing require_token_file check;
    2. loads the list with read_list::into in leading mode;
    3. fails when the list has no active patterns;
    4. creates the temp file with mktemp;
    5. sets the EXIT trap;
    6. writes the patterns and builds the awk operand.

    The trap string is trap "rm -f \"\$$2\"" EXIT. $2 is a fixed variable name that each caller passes as a literal (TOKENS_ACTIVE). It is never outside input, so nothing can be injected into the trap. The value is read only at exit, which gives the same rm -f "$TOKENS_ACTIVE" as before.

  • scripts/check-shell-portability.sh and scripts/check-skill-portability.sh replace the copied load block with one token_scan::load_active ... || exit 2 call. Both keep failing closed with exit 2: on a missing file, an unreadable file, no active patterns, or a failed mktemp. That guard keeps the gate from passing a scan that checks nothing.

  • scripts/check-shell-portability.test.sh and scripts/check-skill-portability.test.sh each add one test. It checks that a clean scan exits 0 and leaves the scan's own TMPDIR empty. It uses only fixed fixture text and temp directories it makes for itself.

Trust boundary. None of the 5 files matches a trusted path. Nothing here changes a trust control, a merge hold, a workflow, a token request, the kill switch or a plugin manifest, and no standing instruction is removed. The scanners read only repository files and the token list that the local env vars point to. Neither is attacker input that reaches a credentialed context through this change.

Settled threads. There are two settled threads on scripts/lib/token-scan.sh: the mode bit and the trap-cleanup test. Both are marked lines changed since resolution: no, and the head matches their resolutions, so neither is raised again.

Prior findings. This lane already reviewed an earlier head (blocking only: yes), so this review reports only blocking findings, and it found none. The earlier summary reported 0 findings, so nothing carries forward.

PR context. It holds no text aimed at the review lane.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 2 inline finding(s) on 098584e8159167021284893c7eeb1885d6a0ac77; the summary is in this lane's pull request comment.

claude-lane: claude-review

Comment thread scripts/lib/token-scan.sh Resolved
Comment thread scripts/lib/token-scan.sh Resolved
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

Code review: PR #15494 at 6794ea7b

I found nothing blocking. This lane has already reviewed earlier heads, so this pass looked for blocking findings only.

I read every hunk of all 5 changed files in the full diff: scripts/lib/token-scan.sh, both gate scripts and both test suites. Since the last head this lane reviewed (2db6e72b), the only new commit merges main into the branch. The pull request's own change matches what was reviewed then, and I checked the head copy of scripts/lib/token-scan.sh against the diff.

What I checked

  • token_scan::load_active (scripts/lib/token-scan.sh:73-88) does the same steps in the same order as the inline block it replaces in both gates:
    • checks that the token file exists;
    • runs read_list::into in leading mode;
    • stops with the same error message when no patterns are active;
    • calls mktemp, then sets the EXIT trap;
    • writes the patterns, then builds the awk operand.
  • The EXIT trap. It expands to rm -f "$TOKENS_ACTIVE", read at exit. Neither gate sets another EXIT trap that would replace it.
  • The callers. Both gates create TOKENS_ACTIVE and TOKENS at top level before the call, so the nameref assignments land in globals. Neither gate refers to token_patterns any more.
  • The new tests (check-shell-portability.test.sh:1510-1521, check-skill-portability.test.sh:178-188). Each runs its gate under a fresh TMPDIR and checks for exit 0 and an empty directory, so a broken trap cleanup would fail them.

Issue #15433 acceptance criteria

  • The repeated block now exists once, in token-scan.sh, and both gates call it: met.
  • Behavior unchanged, including the EXIT trap's cleanup: met as far as reading the code shows. The new tests cover the cleanup.
  • The diff edits only the listed files plus the tests for them: met.
  • The pull request stays under the size limit: met.
  • ci-status green: I can't judge this here; it is left to CI.

Not verified by me. I had no shell and ran nothing. The owner says the suites pass and that both new tests fail when the trap is deliberately broken. That claim is the author's and unverified.

Earlier threads. Both earlier threads (the file-mode change and the missing trap-cleanup test) were settled by the owner, and their lines have not changed since, so I did not raise them again. No plugin manifests changed. I found no embedded instructions in the PR context, settled-threads or prior-findings files.

@melodic-automation-lanes

melodic-automation-lanes Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 2db6e72bcee50a05bf206bcc01a36a6def7a44fc. No person needs to act: a lane clears this reason, and the next scheduled run judges it again.

pr-merge's gate holds it on its risk score (unreadable: the head is
  6794ea7bb9d4ed227f0d6414df1c593d6c853465, not 2db6e72bcee50a05bf206bcc01a36a6def7a44fc)

kyle-sexton and others added 2 commits November 12, 2026 09:07
…ile mode

Run each token-list gate once under a fresh TMPDIR on a clean file and
assert it exits 0 and leaves the directory empty, so a broken EXIT trap in
token_scan::load_active fails both suites. token-scan.sh is sourced, never
executed, so it goes back to mode 100644.

Refs: #15433

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q3tnh28AzDYZ8AUjhH
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

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

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

Verification evidence for 6794ea7

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-15494-6794ea7bb9d4ed227f0d6414df1c593d6c853465, expires on 2026-12-12.

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 12, 2026
Merged via the queue into main with commit 30b2c39 Nov 12, 2026
62 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-15433-43137995556-1 branch November 12, 2026 15:58
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 6, survived 1, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 86%; mutation score 86%.

File Killed Survived Timeout No coverage Invalid Not run
scripts/check-shell-portability.sh 1 0 0 0 0 0
scripts/check-skill-portability.sh 1 0 0 0 0 0
scripts/lib/token-scan.sh 4 1 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
scripts/lib/token-scan.sh:77 SBR 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 30b2c39a9ddaae1daded684af7c10ecd8d9a4992; 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.

Load the active token patterns through one token-scan helper

1 participant