Skip to content

Add shellspec coverage for pure/read-only subcommands#2

Open
redpeacock78 wants to merge 9 commits into
masterfrom
tests/pure-readonly-specs
Open

Add shellspec coverage for pure/read-only subcommands#2
redpeacock78 wants to merge 9 commits into
masterfrom
tests/pure-readonly-specs

Conversation

@redpeacock78

@redpeacock78 redpeacock78 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • spec/support/helpers.sh を新設し、set_global_version / set_local_version / invoke_in_dir / setup_shim / setup_version_bin_command の 5 関数を抽出。restore spec も新ヘルパに移行。
  • Pure/Read-only カテゴリ 8 サブコマンド (root, shims, commands, where, which, whence, ---help, --h) の spec を新規追加。合計 42 examples (既存 restore 8 と合わせて 50 examples 全green)。
  • spec_helper.shTEX_CMD_LIST_CACHE の初期化 + export を追加 (texenv-whence が set -u 下で参照するため)。

Coverage

Spec Examples
restore (既存) 8
root 5
shims 5
commands 6
which 6
where 7
whence 7
---help 3
--h 3
50

Test Plan

  • ローカルで shellspec50 examples, 0 failures 確認
  • CI (ubuntu-latest / macos-latest) 両方 green確認
  • kcov カバレッジ artifact 確認 (任意)

Out of scope

  • texenv-help spec → 別カテゴリ PR
  • 残り 7 カテゴリ (version queries, version selection, env/init, dispatch core, maintenance, repo/freeze, hooks, install/uninstall) → 順次別 PR
  • libexec/* 本体への変更なし

Follow-up tickets

  • commands spec の負アサーション (should not include '-help') を行単位マッチへ tighten
  • whence spec の --help 例追加 (現状 -h のみ)
  • errors when texenv-help is missing パターンの helper 共通化検討

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • テスト
    • 複数のコマンドコンポーネント(texenv-helptexenv-commandstexenv-roottexenv-shimstexenv-whencetexenv-wheretexenv-which)に対する仕様テストスイートを追加しました。
    • テスト実行時の環境設定とヘルパ関数を拡張し、テストの可維持性と信頼性を向上させました。

redpeacock78 and others added 9 commits June 5, 2026 19:37
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Complex PR? Review this PR in Change Stack to move by importance, not file order.

Review Change Stack

📝 Walkthrough

Walkthrough

本 PR は、texenv の複数のサブコマンドに対する shellspec ベースのテストスイートと、テスト実行を支援する共通ヘルパー関数群を新規追加します。テスト環境を一元管理する spec/support/helpers.sh と、それを組み込む spec/spec_helper.sh の更新により、テストコードの一貫性と保守性を向上させています。

Changes

テスト仕様追加

Layer / File(s) Summary
テストヘルパー関数と環境設定
spec/support/helpers.sh, spec/spec_helper.sh
バージョン・シム・コマンド生成、ディレクトリ内実行、テスト用環境変数(TEX_CMD_LIST_CACHE)の定義・export を行う新規ヘルパ関数群を導入。
ヘルプコマンドとエイリアスの仕様テスト
spec/libexec/texenv---help_spec.sh, spec/libexec/texenv--h_spec.sh
texenv---help(フルヘルプ)と texenv--h(短縮形)の終了コード、usage バナー出力、stderr 空、および texenv-help 欠落時のエラー(終了コード 1、help component(s) missing)を検証。
情報取得・列挙コマンドの仕様テスト
spec/libexec/texenv-commands_spec.sh, spec/libexec/texenv-root_spec.sh, spec/libexec/texenv-shims_spec.sh
texenv-commands(サブコマンド一覧・アルファベット順・エイリアス除外)、texenv-rootTEXENV_ROOT パス出力・未設定時エラー)、texenv-shims(シムリスト出力・未生成時エラー)の期待動作を検証。各コマンドで -h/--help フラグ処理と texenv-help 欠落時エラーを確認。
コマンド検索・解決の仕様テスト
spec/libexec/texenv-which_spec.sh, spec/libexec/texenv-where_spec.sh, spec/libexec/texenv-whence_spec.sh
texenv-which(シムパス出力)、texenv-where(バージョン bin 内パス出力)、texenv-whence(複数バージョン横断検索と ${TEX_CMD_LIST_CACHE} キャッシュ利用)の成功・失敗パスと引数検証を実施。
既存テストスイートのリファクタリング
spec/libexec/texenv-restore_spec.sh
invoke() を従来の ( cd "${TEXENV_DIR}" && ... ) サブシェルパターンから新規 invoke_in_dir ヘルパへ置き換え、ディレクトリ管理を統一。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • redpeacock78/texenv#1: 本 PR の shellspec テストスイート追加と spec/libexec/texenv-restore_spec.shinvoke_in_dir リファクタリングパターンは、当該 PR の shellspec 移行と密接に関連。

Poem

🐰 テストの庭に新しい花、
ヘルパー関数で枝を結び、
コマンドごとに仕様を重ね、
検証の道を明るく照らす。
テスト基盤、堅く育ちぬ!🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR タイトルは、追加されたテストカバレッジの対象となる pure/read-only サブコマンド群の仕様テスト追加を明確に説明しており、実装内容と正確に一致しています。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tests/pure-readonly-specs

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.

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

Pull request overview

This PR improves the ShellSpec test suite by extracting common spec helpers into a shared module and adding new specs to cover the “pure/read-only” subcommands (plus their help/alias entrypoints), without changing any libexec/* production scripts.

Changes:

  • Added spec/support/helpers.sh and moved commonly used setup/invocation helpers there (also used by the existing restore spec).
  • Added new ShellSpec coverage for 8 pure/read-only subcommands: root, shims, commands, where, which, whence, ---help, --h.
  • Initialized and exported TEX_CMD_LIST_CACHE in spec_helper.sh to support texenv-whence under set -u.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
spec/support/helpers.sh New shared helper functions for version file setup, per-dir invocation, and shim/version command setup.
spec/spec_helper.sh Sources new helpers; initializes/exports TEX_CMD_LIST_CACHE in the test environment.
spec/libexec/texenv-restore_spec.sh Switches to shared invoke_in_dir (and shared set_global_version).
spec/libexec/texenv-root_spec.sh Adds specs for texenv-root output, help flags, and error paths.
spec/libexec/texenv-shims_spec.sh Adds specs for shim listing behavior, help flags, and error paths.
spec/libexec/texenv-commands_spec.sh Adds specs for subcommand enumeration and exclusion rules, plus help/missing-component paths.
spec/libexec/texenv-where_spec.sh Adds specs for resolving command paths in the selected version and related error/help cases.
spec/libexec/texenv-which_spec.sh Adds specs for shim resolution and related error/help cases.
spec/libexec/texenv-whence_spec.sh Adds specs for cross-version search behavior including cache-file usage and error/help cases.
spec/libexec/texenv---help_spec.sh Adds specs for the ---help alias behavior and missing-help error.
spec/libexec/texenv--h_spec.sh Adds specs for the --h alias behavior and missing-help error.

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

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
spec/libexec/texenv-whence_spec.sh (1)

56-67: ⚡ Quick win

--help フラグのテストケースが不足しています。

他のすべての spec ファイルは -h--help の両方をテストしていますが、このファイルには -h のテスト(56-60 行目)のみが含まれています。一貫性を保つため、--help フラグのテストケースも追加することを推奨します。

PR の目的にも follow-up として記載されているため、今後の対応で問題ありません。

📋 推奨される追加テストケース
   It 'execs texenv-help whence when -h is given'
     When call invoke -h
     The status should equal 0
     The output should include 'Usage: texenv whence'
   End
 
+  It 'execs texenv-help whence when --help is given'
+    When call invoke --help
+    The status should equal 0
+    The output should include 'Usage: texenv whence'
+  End
+
   It 'errors when texenv-help is missing'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spec/libexec/texenv-whence_spec.sh` around lines 56 - 67, Add a parallel test
to the existing "-h" case to assert "--help" behavior: duplicate the "It 'execs
texenv-help whence when -h is given'" block but call invoke with "--help"
instead of "-h", assert status is 0 and output includes 'Usage: texenv whence';
keep the existing "errors when texenv-help is missing" test untouched. This
ensures the spec in spec/libexec/texenv-whence_spec.sh covers both -h and --help
flags consistently.
spec/libexec/texenv-where_spec.sh (1)

56-61: ⚡ Quick win

texenv-help 欠落時のテストケースが不足しています。

他のすべての spec ファイル(commands, root, shims, which, whence)には「texenv-help が欠落している場合のエラー」テストが含まれていますが、このファイルには texenv-libs 欠落のテストのみが存在します。texenv-where-h/--help フラグをサポートしているため(44-54 行目)、texenv-help への依存も検証すべきです。

一貫性を保つため、以下のテストケースの追加を推奨します:

📋 推奨される追加テストケース
   It 'errors when texenv-libs is missing'
     rm -f "${TEXENV_SPEC_BIN}/texenv-libs"
     When call invoke
     The status should equal 1
     The stderr should include 'required component(s) missing'
   End
+
+  It 'errors when texenv-help is missing'
+    rm -f "${TEXENV_SPEC_BIN}/texenv-help"
+    When call invoke
+    The status should equal 1
+    The stderr should include 'required component(s) missing'
+  End
 End
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spec/libexec/texenv-where_spec.sh` around lines 56 - 61, Add a parallel test
to spec/libexec/texenv-where_spec.sh that checks failure when texenv-help is
missing: remove "${TEXENV_SPEC_BIN}/texenv-help" before calling the existing
test helper (the same helper invoked by "When call invoke"), then assert the
exit status is 1 and stderr contains 'required component(s) missing'—mirror the
existing "errors when texenv-libs is missing" test to ensure texenv-where's
dependency on texenv-help is verified.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@spec/libexec/texenv-where_spec.sh`:
- Line 8: The spec is missing a test for the "texenv-help missing" case and also
relies on texenv_make_version (which is defined in spec/spec_helper.sh), so add
a new test in spec/libexec/texenv-where_spec.sh mirroring the existing
"texenv-libs missing" test: set up the environment so the texenv-help component
is absent (e.g., remove/rename from PATH or mock its absence), call the same
test helper(s) that invoke texenv-where, assert the exit status and that the
output contains the "help component(s) missing" message, and ensure you
reference texenv_make_version (from spec/spec_helper.sh) as used by the other
specs for version setup so the new test is consistent with the rest.

---

Nitpick comments:
In `@spec/libexec/texenv-whence_spec.sh`:
- Around line 56-67: Add a parallel test to the existing "-h" case to assert
"--help" behavior: duplicate the "It 'execs texenv-help whence when -h is
given'" block but call invoke with "--help" instead of "-h", assert status is 0
and output includes 'Usage: texenv whence'; keep the existing "errors when
texenv-help is missing" test untouched. This ensures the spec in
spec/libexec/texenv-whence_spec.sh covers both -h and --help flags consistently.

In `@spec/libexec/texenv-where_spec.sh`:
- Around line 56-61: Add a parallel test to spec/libexec/texenv-where_spec.sh
that checks failure when texenv-help is missing: remove
"${TEXENV_SPEC_BIN}/texenv-help" before calling the existing test helper (the
same helper invoked by "When call invoke"), then assert the exit status is 1 and
stderr contains 'required component(s) missing'—mirror the existing "errors when
texenv-libs is missing" test to ensure texenv-where's dependency on texenv-help
is verified.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c3f23e8-61a7-4f8d-9629-2578b13c070a

📥 Commits

Reviewing files that changed from the base of the PR and between 1514e01 and 5570202.

📒 Files selected for processing (11)
  • spec/libexec/texenv---help_spec.sh
  • spec/libexec/texenv--h_spec.sh
  • spec/libexec/texenv-commands_spec.sh
  • spec/libexec/texenv-restore_spec.sh
  • spec/libexec/texenv-root_spec.sh
  • spec/libexec/texenv-shims_spec.sh
  • spec/libexec/texenv-whence_spec.sh
  • spec/libexec/texenv-where_spec.sh
  • spec/libexec/texenv-which_spec.sh
  • spec/spec_helper.sh
  • spec/support/helpers.sh

where_before() {
texenv_setup
texenv_install_libexec texenv-where texenv-libs texenv-help
texenv_make_version 2025.01

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# texenv_make_version の定義を検索
rg -n 'texenv_make_version' --type=sh

Repository: redpeacock78/texenv

Length of output: 386


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) 関連 spec を確認
echo "=== spec/spec_helper.sh (texenv_make_version 周辺) ==="
sed -n '60,110p' spec/spec_helper.sh

echo
echo "=== spec/libexec/texenv-where_spec.sh ==="
nl -ba spec/libexec/texenv-where_spec.sh | sed -n '1,120p'

echo
echo "=== spec/libexec/texenv-restore_spec.sh ==="
nl -ba spec/libexec/texenv-restore_spec.sh | sed -n '1,160p'

# 2) texenv-help 未存在テストが他ファイルにあるか探索
echo
echo "=== テスト文字列探索(texenv-help missing) ==="
rg -n "texenv-help.*missing|help.*missing|--help.*missing" spec/libexec --type=sh || true
rg -n "texenv_make_version" spec --type=sh

Repository: redpeacock78/texenv

Length of output: 1014


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== spec/libexec/texenv-where_spec.sh (先頭〜120行) ==="
sed -n '1,120p' spec/libexec/texenv-where_spec.sh | awk '{printf "%4d:%s\n", NR, $0}'

echo
echo "=== spec/libexec/texenv-restore_spec.sh (先頭〜180行) ==="
sed -n '1,180p' spec/libexec/texenv-restore_spec.sh | awk '{printf "%4d:%s\n", NR, $0}'

echo
echo "=== テスト文字列探索(texenv-help missing 系) ==="
rg -n "texenv-help.*missing|help.*missing|--help.*missing" spec/libexec --type=sh || true

echo
echo "=== texenv_make_version の参照箇所(spec 配下) ==="
rg -n "texenv_make_version" spec --type=sh

Repository: redpeacock78/texenv

Length of output: 7808


🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n "texenv-help" spec/libexec/texenv-where_spec.sh --type=sh

Repository: redpeacock78/texenv

Length of output: 235


texenv_make_version の定義場所と、texenv-help 欠落テスト不足の指摘
texenv_make_versionspec/spec_helper.sh に定義されています(helpers.sh ではありません)。
ただし spec/libexec/texenv-where_spec.sh には texenv-libs 欠落時のテストはある一方で、他の spec と同様の「texenv-help 欠落時(help component(s) missing)」のテストがありません。追加して整合性を取ってください。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spec/libexec/texenv-where_spec.sh` at line 8, The spec is missing a test for
the "texenv-help missing" case and also relies on texenv_make_version (which is
defined in spec/spec_helper.sh), so add a new test in
spec/libexec/texenv-where_spec.sh mirroring the existing "texenv-libs missing"
test: set up the environment so the texenv-help component is absent (e.g.,
remove/rename from PATH or mock its absence), call the same test helper(s) that
invoke texenv-where, assert the exit status and that the output contains the
"help component(s) missing" message, and ensure you reference
texenv_make_version (from spec/spec_helper.sh) as used by the other specs for
version setup so the new test is consistent with the rest.

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