Skip to content

test: add shellcheck disable and spec for rtk-rewrite.sh - #891

Merged
shunkakinoki merged 3 commits into
mainfrom
worktree-bold-fox-4j32
Feb 22, 2026
Merged

test: add shellcheck disable and spec for rtk-rewrite.sh#891
shunkakinoki merged 3 commits into
mainfrom
worktree-bold-fox-4j32

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Feb 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add # shellcheck disable=SC2001 to config/claude/rtk-rewrite.sh — the sed patterns use ^ (start-of-string anchor) which bash parameter expansion cannot replicate
  • Add spec/rtk_rewrite_spec.sh with 26 tests covering guards, skip conditions, git/gh/cargo/file/JS/Python/Go rewrites, env prefix preservation, and output format
  • Register rtk-rewrite.sh in spec/coverage_spec.sh coverage list

Test plan

  • make shell-lint passes (0 warnings)
  • make shell-test passes (523 examples, 0 failures)

🤖 Generated with Claude Code


Summary by cubic

Allow sed-based rewrite patterns in rtk-rewrite.sh and add a comprehensive spec to lock down behavior. Suppresses a false shellcheck warning, expands coverage, keeps CI passing, and formats the new spec.

  • Bug Fixes

    • Disable shellcheck SC2001 in rtk-rewrite.sh.
    • Mock the rtk binary in the spec to avoid guard exits in CI.
    • Format rtk_rewrite_spec.sh for consistency.
  • New Features

    • Add spec/rtk_rewrite_spec.sh with 26 tests for guards, skip conditions, rewrites (git, gh, cargo, file ops, JS/TS, Python, Go), env var preservation, and JSON output.
    • Register rtk-rewrite.sh in spec/coverage_spec.sh.

Written for commit 339ba3e. Summary will update on new commits.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 22, 2026 01:50
@mesa-dot-dev

mesa-dot-dev Bot commented Feb 22, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Feb 22, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds test coverage for a shell script rewriting utility (rtk-rewrite.sh) by introducing a comprehensive BashSpec test suite (spec/rtk_rewrite_spec.sh) with 222 lines of tests, updating the coverage manifest to track the new spec file, and adding a shellcheck linter directive to suppress a specific warning.

Changes

Cohort / File(s) Summary
Linter Configuration
config/claude/rtk-rewrite.sh
Added shellcheck directive to disable SC2001 warning (regex operator use).
Test Coverage Tracking
spec/coverage_spec.sh
Added spec existence check and manifest entry for config/claude/rtk-rewrite.sh and its corresponding test file spec/rtk_rewrite_spec.sh.
Test Suite
spec/rtk_rewrite_spec.sh
Created comprehensive BashSpec test suite covering guard behavior (empty/missing commands), skip conditions (heredocs, existing rtk usage), command rewrites (git, gh, cargo, file ops, JS/TS tooling, curl, pytest, go test), environment variable preservation, JSON output validation, and original field preservation in permissionDecision responses.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through tests so fine,
Rewriting commands, line by line,
With rtk's help, the scripts now shine,
Guard clauses checked, rewrites align,
Coverage grows—what grand design! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main changes: adding a shellcheck disable directive and a comprehensive test spec for rtk-rewrite.sh.
Description check ✅ Passed The pull request description is directly related to the changeset, describing the three main modifications: adding a shellcheck disable directive, creating a comprehensive test spec, and registering the script in coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch worktree-bold-fox-4j32

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@shunkakinoki
shunkakinoki enabled auto-merge (squash) February 22, 2026 01:50
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness and testability of the "rtk-rewrite.sh" script. It addresses a specific "shellcheck" warning by disabling it where necessary due to "sed" pattern usage, and significantly improves test coverage by introducing a dedicated spec file with a wide array of tests for the script's rewriting logic.

Highlights

  • Shellcheck Directive: Added "# shellcheck disable=SC2001" to "config/claude/rtk-rewrite.sh" to address warnings related to "sed" patterns using "^" which cannot be replicated by bash parameter expansion.
  • New Test Suite: Introduced "spec/rtk_rewrite_spec.sh" with 26 comprehensive tests for "rtk-rewrite.sh", covering guards, skip conditions, various command rewrites (git, gh, cargo, file ops, JS/TS, network, python, go), environment variable preservation, and output format.
  • Test Coverage: Registered "rtk-rewrite.sh" in "spec/coverage_spec.sh" to ensure its test coverage is tracked.
Changelog
  • config/claude/rtk-rewrite.sh
    • Added a "shellcheck disable=SC2001" directive.
  • spec/coverage_spec.sh
    • Included a new test to verify the existence of "spec/rtk_rewrite_spec.sh".
    • Updated the list of covered scripts to include "config/claude/rtk-rewrite.sh".
  • spec/rtk_rewrite_spec.sh
    • Created a new spec file with 26 tests for "rtk-rewrite.sh", validating its functionality across different command types and edge cases.
Activity
  • The author has confirmed that "make shell-lint" passes with 0 warnings.
  • The author has confirmed that "make shell-test" passes with 523 examples and 0 failures.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mesa-dot-dev

mesa-dot-dev Bot commented Feb 22, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Allow sed-based rewrite patterns in rtk-rewrite.sh by disabling a shellcheck warning and add a comprehensive test spec to lock down its behavior, improving coverage and ensuring CI passes.

What changed?

  • config/claude/rtk-rewrite.sh: Added # shellcheck disable=SC2001 to the script.
  • spec/coverage_spec.sh: Updated to include coverage for config/claude/rtk-rewrite.sh by adding a new test case for spec/rtk_rewrite_spec.sh and incorporating config/claude/rtk-rewrite.sh into the list of covered_scripts.
  • spec/rtk_rewrite_spec.sh: New file introducing a comprehensive shellspec test suite for rtk-rewrite.sh, verifying various command rewrites (e.g., git status, gh pr list, cargo test, cat file.txt to rtk read file.txt), ensuring guard conditions are met, commands already using rtk or heredoc commands are skipped, specific commands like git clone are not rewritten, environment variable preservation, and valid JSON output.

Description generated by Mesa. Update settings

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request is a great addition, adding comprehensive tests for the rtk-rewrite.sh script and ensuring it's tracked for test coverage. The new tests in spec/rtk_rewrite_spec.sh cover a wide range of scenarios. My review includes several suggestions to make these new tests even more robust by using exact assertions (eq) instead of partial ones (include), which will help prevent future regressions. Overall, this is a solid contribution to improving the project's test quality.

Comment thread spec/rtk_rewrite_spec.sh
Data '{"tool_input": {"command": "find . -name \"*.ts\""}}'
When run bash -c "bash '$SCRIPT' | jq -r '.hookSpecificOutput.updatedInput.command'"
The status should be success
The output should include 'rtk find'

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.

medium

For a more robust test, it's better to assert the exact output using eq instead of include. This ensures the entire command is rewritten as expected and prevents regressions where arguments might be unintentionally modified.

Suggested change
The output should include 'rtk find'
The output should eq 'rtk find . -name "*.ts"'

Comment thread spec/rtk_rewrite_spec.sh
Data '{"tool_input": {"command": "curl https://example.com"}}'
When run bash -c "bash '$SCRIPT' | jq -r '.hookSpecificOutput.updatedInput.command'"
The status should be success
The output should include 'rtk curl'

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.

medium

For a more robust test, it's better to assert the exact output using eq instead of include. This ensures the entire command is rewritten as expected and prevents regressions.

Suggested change
The output should include 'rtk curl'
The output should eq 'rtk curl https://example.com'

Comment thread spec/rtk_rewrite_spec.sh
Data '{"tool_input": {"command": "pytest tests/"}}'
When run bash -c "bash '$SCRIPT' | jq -r '.hookSpecificOutput.updatedInput.command'"
The status should be success
The output should include 'rtk pytest'

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.

medium

For a more robust test, it's better to assert the exact output using eq instead of include. This ensures the entire command is rewritten as expected and prevents regressions.

Suggested change
The output should include 'rtk pytest'
The output should eq 'rtk pytest tests/'

Comment thread spec/rtk_rewrite_spec.sh
Data '{"tool_input": {"command": "go test ./..."}}'
When run bash -c "bash '$SCRIPT' | jq -r '.hookSpecificOutput.updatedInput.command'"
The status should be success
The output should include 'rtk go test'

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.

medium

For a more robust test, it's better to assert the exact output using eq instead of include. This ensures the entire command is rewritten as expected and prevents regressions.

Suggested change
The output should include 'rtk go test'
The output should eq 'rtk go test ./...'

Comment thread spec/rtk_rewrite_spec.sh
Data '{"tool_input": {"command": "FOO=bar git status"}}'
When run bash -c "bash '$SCRIPT' | jq -r '.hookSpecificOutput.updatedInput.command'"
The status should be success
The output should include 'FOO=bar rtk git status'

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.

medium

For a more robust test, it's better to assert the exact output using eq instead of include. This ensures the environment variable prefix is preserved correctly and no other part of the command is unintentionally modified.

Suggested change
The output should include 'FOO=bar rtk git status'
The output should eq 'FOO=bar rtk git status'

Comment thread spec/rtk_rewrite_spec.sh Outdated
Data '{"tool_input": {"command": "git status"}}'
When run bash -c "bash '$SCRIPT' | jq -e '.hookSpecificOutput.permissionDecision'"
The status should be success
The output should include 'allow'

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.

medium

The output of this jq command is deterministic. Using eq for an exact match is more precise and robust than include.

Suggested change
The output should include 'allow'
The output should eq 'allow'

Comment thread spec/rtk_rewrite_spec.sh
Data '{"tool_input": {"command": "git status", "timeout": 5000}}'
When run bash -c "bash '$SCRIPT' | jq -e '.hookSpecificOutput.updatedInput.timeout'"
The status should be success
The output should include '5000'

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.

medium

The output here will be exactly '5000'. Using eq provides a stricter and more reliable test than include.

Suggested change
The output should include '5000'
The output should eq '5000'

Copilot AI 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.

Pull request overview

Adds ShellSpec coverage for the Claude Code rtk-rewrite.sh pre-tool hook and registers it in the repo’s shell-script test coverage list, while silencing a ShellCheck warning related to sed usage.

Changes:

  • Added spec/rtk_rewrite_spec.sh with coverage for guard/skip behavior and a variety of command rewrite cases.
  • Registered config/claude/rtk-rewrite.sh in spec/coverage_spec.sh so it’s enforced by the “all scripts covered” test.
  • Added # shellcheck disable=SC2001 to config/claude/rtk-rewrite.sh.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
spec/rtk_rewrite_spec.sh New ShellSpec suite validating rewrite/skip behavior and JSON output contract.
spec/coverage_spec.sh Ensures the new script has a spec and is included in the “covered scripts” list.
config/claude/rtk-rewrite.sh Adds a targeted ShellCheck suppression for sed-based rewrites.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/rtk_rewrite_spec.sh
@@ -0,0 +1,206 @@
#!/usr/bin/env bash
# shellcheck disable=SC2329

Copilot AI Feb 22, 2026

Copy link

Choose a reason for hiding this comment

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

These specs rely on config/claude/rtk-rewrite.sh passing its dependency guard (command -v rtk), but the spec doesn’t set up a stub rtk binary in PATH. In environments where rtk isn’t installed (e.g., fresh CI runners), the script will exit 0 with empty output and the jq assertions will fail. Consider adding a setup()/cleanup() with mock_bin_setup rtk / mock_bin_cleanup (as used in other specs) so the rewrite tests are hermetic and don’t depend on system-installed rtk.

Suggested change
setup() {
mock_bin_setup rtk
}
cleanup() {
mock_bin_cleanup
}

Copilot uses AI. Check for mistakes.
CI doesn't have rtk installed, so the guard exits silently.
Use helper functions with MOCK_BIN in PATH to ensure tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
spec/rtk_rewrite_spec.sh (2)

141-141: Prefer eq over include where the full rewritten command is deterministic.

should include is appropriate for partial matches, but for find, curl, pytest, go test, and the env-prefix test the full expected string is known. should eq would catch accidental double-prefixing or trailing garbage, whereas include would silently accept rtk rtk find . or FOO=bar rtk FOO=bar rtk git status.

♻️ Suggested assertion strengthening
 # find (line 141)
-The output should include 'rtk find'
+The output should eq 'rtk find . -name "*.ts"'

 # curl (line 173)
-The output should include 'rtk curl'
+The output should eq 'rtk curl https://example.com'

 # pytest (line 182)
-The output should include 'rtk pytest'
+The output should eq 'rtk pytest tests/'

 # go test (line 191)
-The output should include 'rtk go test'
+The output should eq 'rtk go test ./...'

 # env prefix (line 200)
-The output should include 'FOO=bar rtk git status'
+The output should eq 'FOO=bar rtk git status'

Also applies to: 173-174, 182-183, 191-192, 200-200

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/rtk_rewrite_spec.sh` at line 141, Tests using "should include" for
fully-deterministic rewritten commands (the "rtk find", "rtk curl", "rtk
pytest", "rtk go test" and the env-prefix case) should be tightened to "should
eq": locate the assertions in the spec that expect the rewritten command output
(the tests referencing "rtk find", "rtk curl", "rtk pytest", "rtk go test" and
the env-prefix test) and replace the include-based matchers with exact equality
matchers so the expected full string is compared exactly (this prevents
double-prefixing or trailing garbage being accepted).

89-100: Consider adding tests for head rewrites — the most complex transformation in the script has no coverage.

The head branch performs argument reordering (head -N filertk read file --max-lines N and head --lines=N filertk read file --max-lines N), which is structurally different from all other rewrites (which are pure prefix substitutions). Both sed extraction chains are untested, including the LINES/FILE capture and their interaction with multi-word filenames.

💡 Suggested test cases to add inside the existing spec
+Describe 'head rewrites'
+  It 'rewrites head -N file to rtk read with --max-lines'
+    Data '{"tool_input": {"command": "head -20 README.md"}}'
+    When run run_hook_jq
+    The status should be success
+    The output should eq 'rtk read README.md --max-lines 20'
+  End
+
+  It 'rewrites head --lines=N file to rtk read with --max-lines'
+    Data '{"tool_input": {"command": "head --lines=10 src/main.ts"}}'
+    When run run_hook_jq
+    The status should be success
+    The output should eq 'rtk read src/main.ts --max-lines 10'
+  End
+
+  It 'does not rewrite head without -N flag'
+    Data '{"tool_input": {"command": "head file.txt"}}'
+    When run run_hook
+    The status should be success
+    The output should eq ''
+  End
+End
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spec/rtk_rewrite_spec.sh` around lines 89 - 100, Add tests covering the
"head" rewrite transformation in spec/rtk_rewrite_spec.sh: create a new Describe
block (e.g., Describe 'head rewrites') that uses Data with inputs for both forms
"head -5 file.txt" and "head --lines=5 file.txt" and for at least one case a
multi-word filename (e.g., "my file.txt"); run run_hook and assert status is
success and The output should eq the expected rewritten command "rtk read
file.txt --max-lines 5" (and for the multi-word file ensure quoting/spacing is
preserved in the expected output); include cases that verify the sed capture
behavior for LINES and FILE so both the "-N" and "--lines=N" parsing branches
are exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@spec/rtk_rewrite_spec.sh`:
- Line 141: Tests using "should include" for fully-deterministic rewritten
commands (the "rtk find", "rtk curl", "rtk pytest", "rtk go test" and the
env-prefix case) should be tightened to "should eq": locate the assertions in
the spec that expect the rewritten command output (the tests referencing "rtk
find", "rtk curl", "rtk pytest", "rtk go test" and the env-prefix test) and
replace the include-based matchers with exact equality matchers so the expected
full string is compared exactly (this prevents double-prefixing or trailing
garbage being accepted).
- Around line 89-100: Add tests covering the "head" rewrite transformation in
spec/rtk_rewrite_spec.sh: create a new Describe block (e.g., Describe 'head
rewrites') that uses Data with inputs for both forms "head -5 file.txt" and
"head --lines=5 file.txt" and for at least one case a multi-word filename (e.g.,
"my file.txt"); run run_hook and assert status is success and The output should
eq the expected rewritten command "rtk read file.txt --max-lines 5" (and for the
multi-word file ensure quoting/spacing is preserved in the expected output);
include cases that verify the sed capture behavior for LINES and FILE so both
the "-N" and "--lines=N" parsing branches are exercised.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shunkakinoki
shunkakinoki merged commit 36f6a3b into main Feb 22, 2026
31 checks passed
@shunkakinoki
shunkakinoki deleted the worktree-bold-fox-4j32 branch February 22, 2026 06:22
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.

2 participants