Skip to content

feat: support :integer option type in CLI spec - #13

Merged
toshi0806 merged 4 commits into
mainfrom
issue-12-integer-option-type
Jul 22, 2026
Merged

feat: support :integer option type in CLI spec#13
toshi0806 merged 4 commits into
mainfrom
issue-12-integer-option-type

Conversation

@toshi0806

Copy link
Copy Markdown
Member

概要

option_def の型を :boolean | :string | :integer に拡張する(K2 追補。ecosystem-manager の --max-concurrency 採用時に dialyzer の型不一致で発覚)。

Resolves #12 / 親 epic: smkwlab/latex-ecosystem#146

変更内容

  • option_def.type / strict_switches の型に :integer を追加
  • help 描画: VALUE プレースホルダの条件を「:string のみ」→「:boolean 以外」へ(rm/tm は boolean/string のみのため出力不変。registry-manager のバイト一致 fixture テスト無変更で green)

確認済み

  • mix test --cover 9 doctests + 71 tests, 0 failures ✔(integer オプションの導出・描画・検証テスト追加)
  • mix format --check-formatted / mix credo 0 issues / mix dialyzer 0 errors ✔

merge 後に tag v0.1.2 を発行し、E1(em#9)から参照します。

Widen option_def's type union and render a VALUE placeholder for any
non-boolean option. Needed by ecosystem-manager's --max-concurrency;
registry-manager's byte-identical help fixtures are unchanged.

Resolves #12

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

全体的にシンプルで意図が明確な変更です。型定義・仕様・ヘルプ描画・テストが一貫して更新されており、品質は高いと判断します。1点だけ指摘します。


assert {:jobs, :integer} in Spec.strict_switches(spec)
assert Spec.render_command_help(spec, "run") =~ "--jobs VALUE"
assert Spec.validate_opts(spec, "run", jobs: 4) == :ok

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ [MEDIUM] validate_opts/3 に対して jobs: 4(整数値)のみ検証していますが、:integer 型のオプションに文字列や浮動小数点数が渡された場合(例: jobs: "four"jobs: 3.14)のバリデーション失敗ケースがテストされていません。OptionParser:integer を正しく拒否するかどうかは実装依存であり、将来の変更で誤った値が通過するリスクがあります。正常系に加えて異常系のテストケースも追加することを推奨します。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

修正済み(2b08f44)。整数でない値の拒否は OptionParser(strict)の責務で、Parser がパース段階のエラーに変換します。Parser.parse(spec, ["run", "--jobs", "four"]){:error, ...} になる negative テストを追加しました。

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

全体的にシンプルで意図が明確な変更です。型定義・ロジック・テストの三点が整合しており、品質は良好です。1点だけ軽微な懸念を挙げます。

Comment thread test/tool_kit/cli/spec_test.exs Outdated

# 整数でない値の拒否は OptionParser(strict)の責務で、
# Parser がパース段階のエラーに変換する
assert {:error, message} = ToolKit.CLI.Parser.parse(spec, ["run", "--jobs", "four"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️ [LOW] テストで ToolKit.CLI.Parser.parse/2 を直接呼び出していますが、このモジュールへの aliasimport がテストファイル冒頭に存在しない場合、コンパイルエラーになります。現在 mix test が通っているとのことなので問題はないと思われますが、他のテストケースとの一貫性のため、モジュール参照を Spec と同様に短縮形で統一するか、明示的に alias ToolKit.CLI.Parser を追加することを検討してください。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

対応済み(6adf83e)。alias ToolKit.CLI.Parser を追加して短縮形に統一しました(CI の credo strict がこの点を検出して failure になっていたため、同 commit で解消済みです)。

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

全体的に変更は明確で、型の拡張・ヘルプ描画の修正・テストの追加がバランスよく行われています。以下に気になる点を挙げます。

Comment thread lib/tool_kit/cli/spec.ex
type: :boolean | :string,
type: :boolean | :string | :integer,
alias: atom() | nil,
values: [String.t()] | nil,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️ [LOW] :integer 型のオプションに対して values フィールドが nil 以外(例: ["1", "2", "4"] のような候補リスト)を持つケースを将来的に許容するかどうかが不明確です。現在の render_values/1:string 向けに設計されている場合、:integervalues が非 nil のときの描画が意図通りになるか確認が必要です。型定義上 values: [String.t()] | nil のままであり、:integer との組み合わせの意味論が曖昧です。将来の拡張を見越してコメントや型定義で制約を明示することを検討してください。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

据え置きます。values は enum 検証(パース済み値が文字列リストに含まれるか)のためのフィールドで、意味論上 :string 専用です。:integer オプションで values を設定すると validate_opts が必ず不一致になるため事実上使えず、使う予定もありません(現行の利用者 rm/tm/em に該当なし)。必要になった時点で型定義の制約強化を検討します。


# 整数でない値の拒否は OptionParser(strict)の責務で、
# Parser がパース段階のエラーに変換する
assert {:error, message} = Parser.parse(spec, ["run", "--jobs", "four"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ️ [LOW] Spec.validate_opts(spec, "run", jobs: 4):ok を確認していますが、jobs: -1jobs: 0 など境界値・負値のケースが検証されていません。また、Parser.parse/2"four" を渡した際のエラーメッセージが "--jobs" を含むことのみを確認していますが、エラーの種類(型不一致)を示すメッセージ内容についてもアサーションを追加すると、将来のリグレッション検出に役立ちます。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

据え置きます。負値・0 などの値域検証は spec エンジンの責務ではなくツール側のビジネスロジックの責務です(OptionParser は任意の整数を受理し、例えば max_concurrency の下限はツールが判断する)。エラーメッセージ文言のアサーション追加は、文言変更のたびに壊れる brittle なテストになるため、エラーであること + 対象オプション名の包含の検証に留めています。

@toshi0806

Copy link
Copy Markdown
Member Author

AI レビュー指摘への対応まとめ

全 4 スレッド対応済み(修正 2・据え置き 2)。CI は 6adf83e で全 green。

  • :integer 不正値の negative テスト(MEDIUM)2b08f44 で追加(拒否は OptionParser strict の責務、Parser がエラー変換)
  • Parser の alias(LOW)6adf83e で追加(credo strict の failure 原因でもあった)
  • :integer × values の意味論(LOW) → values は :string 専用の enum 検証。integer で使う予定なし
  • 境界値・文言アサーション(LOW) → 値域はツール側責務、文言検証は brittle のため対象名包含に留める

補足: 2b08f44 push 時に Actions が発火しない事象があり、空 commit(5629776)で再トリガしています。

@toshi0806
toshi0806 merged commit dfdc43b into main Jul 22, 2026
5 checks passed
@toshi0806
toshi0806 deleted the issue-12-integer-option-type branch July 22, 2026 23:59
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.

Support :integer option type in CLI spec

1 participant