Skip to content

feat: --scopes オプションのヘルプに有効なスコープ一覧を追加#73

Merged
miya0001 merged 3 commits into
mainfrom
scopes-help
Mar 17, 2026
Merged

feat: --scopes オプションのヘルプに有効なスコープ一覧を追加#73
miya0001 merged 3 commits into
mainfrom
scopes-help

Conversation

@miya0001

@miya0001 miya0001 commented Mar 17, 2026

Copy link
Copy Markdown
Member

Summary

  • help.tsaddNotes() 機能を追加(addExamples と同パターン)し、コマンドヘルプに NOTES セクションを表示可能に
  • --scopes を持つ4コマンド (me oauth-clients create, me api-keys create, admin api-keys create, admin api-keys update) に全16リソーススコープの一覧と包含関係 (write:X implies read:X, admin:X implies both) を表示
  • README の Valid Scopes セクションを全スコープに更新、特殊スコープ (permanent, jwt) の説明を追加
  • admin api-keys create の例で誤ったスコープ形式 (entities:read) を read:entities に修正

Test plan

  • npm run lint — pass
  • npm run typecheck — pass
  • npm test — 624 tests pass
  • geonic help me oauth-clients create で NOTES セクションにスコープ一覧が表示されることを確認
  • geonic help me api-keys create で同様に確認
  • geonic help admin api-keys create で同様に確認
  • geonic help admin api-keys update で同様に確認
  • CI passes

Summary by CodeRabbit

リリースノート

  • 新機能

    • コマンドヘルプに有効なスコープを列挙する新しい NOTES セクションを追加しました。
  • ドキュメンテーション

    • README の有効なスコープを18個に拡充し、スコープの意味(read/write/admin や特別スコープ)とランタイム制約の注記を追加しました。
  • バグ修正

    • APIキー作成例のスコープ表記を修正しました。
    • E2E テスト設定を v2 形式に統一し、認証周りのフレークを改善しました。

help.ts に addNotes() 機能を追加し、--scopes を持つコマンド
(me oauth-clients create, me api-keys create, admin api-keys create/update)
の NOTES セクションに全16リソーススコープと包含関係を表示。
@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

コマンドヘルプにNOTESセクションを追加する機能を導入し、SCOPES_HELP_NOTES定数を追加して複数コマンドのヘルプに注記を付与し、関連ドキュメントとテストモックを更新しました。

Changes

Cohort / File(s) Summary
Documentation Updates
CHANGELOG.md, README.md
Unreleasedセクションを追加し、スコープ一覧と説明を拡張。admin APIキースコープの表記修正(例: entities:readread:entities)とスコープ制約の注記を追加。
Help feature core
src/commands/help.ts, src/helpers.ts
addNotes(cmd, notes)を実装してコマンドにNOTESを紐付ける機能を追加。SCOPES_HELP_NOTESをエクスポートしてスコープ説明を格納。
Command integrations
src/commands/admin/api-keys.ts, src/commands/me-api-keys.ts, src/commands/me-oauth-clients.ts
各コマンドでaddNotesSCOPES_HELP_NOTESをインポートしてcreate/update等のサブコマンドに注記を追加。APIキー例のスコープ表記を更新。
Tests & mocks
tests/... (多数) — see list below
テストモック全般にSCOPES_HELP_NOTES: []addNotes: vi.fn()を追加し、新エクスポートをテスト環境でサポート。
E2E config migration updates
tests/e2e/step_definitions/auth.steps.ts, tests/e2e/step_definitions/token.steps.ts, tests/e2e/support/world.ts
テストの設定書き換えをv2マルチプロファイル形式に合わせる変更。既存フィールドのマージを置換し、トークン更新ロジックをプロファイル内に移動。

(テストファイル群の例: tests/setup-command-mocks.ts, tests/admin-api-keys.test.ts, tests/admin-oauth-clients.test.ts, tests/admin-policies.test.ts, tests/admin-tenants.test.ts, tests/admin-users.test.ts, tests/auth.test.ts, tests/commands-config.test.ts, tests/commands-profile.test.ts, tests/entities.test.ts, tests/health.test.ts, tests/me-api-keys.test.ts, tests/me-oauth-clients.test.ts, tests/snapshots.test.ts, tests/temporal.test.ts, tests/types.test.ts)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 ノートを抱えて跳ねるぼく、
ヘルプにひらりとひかる光。
スコープの道しるべを残して、
コマンドたちにやさしい導き。
みんなで渡れば安心だよ。

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRのタイトルは、主な変更点である「--scopesオプションのヘルプに有効なスコープ一覧を追加」を明確かつ簡潔に説明しており、実際の変更内容(help.tsへのaddNotes機能追加、複数コマンドへのNOTESセクション追加、READMEの更新など)と完全に一致しています。

✏️ 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
  • Commit unit tests in branch scopes-help
📝 Coding Plan
  • Generate coding plan for human review comments

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

@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)
src/helpers.ts (1)

10-19: スコープ定義を構造化すると将来の更新差分を減らせます(任意)。

現状でも動作は正しいですが、文字列を直接列挙する形だと更新時に漏れや整形差分が入りやすいです。RESOURCE_SCOPES のような配列を元に NOTES 文面を組み立てる形にすると保守しやすくなります。

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

In `@src/helpers.ts` around lines 10 - 19, Replace the hard-coded multi-line
string array SCOPES_HELP_NOTES with a derived construction from a structured
RESOURCE_SCOPES array: define RESOURCE_SCOPES (e.g., list of resources like
entities, subscriptions, registrations, rules, custom-data-models, users,
tenants, policies, oauth-clients, api-keys, metrics) with allowed verbs (read,
write, admin) or mapped scope variants, then programmatically generate
SCOPES_HELP_NOTES by iterating RESOURCE_SCOPES to produce the formatted lines
(including grouping admin and write implications and the header/footer lines).
Update any usages of SCOPES_HELP_NOTES to reference the generated constant so
future scope additions only require editing RESOURCE_SCOPES.
tests/me-oauth-clients.test.ts (1)

27-30: NOTES 配線の回帰防止として addNotes 呼び出し検証を1件追加するのがおすすめです。

モック追加はできているので、コマンド登録時に addNotes が実際に呼ばれることまで確認できると、この機能の退行をより早く検知できます。

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

In `@tests/me-oauth-clients.test.ts` around lines 27 - 30, The test currently
mocks addNotes (and addExamples) but doesn't assert it was invoked; after the
code path that registers the command(s) in this test, add an assertion that the
mocked addNotes was called (e.g., expect(addNotes).toHaveBeenCalledTimes(1) or
toHaveBeenCalled()), referencing the existing vi.mock stub for addNotes so the
assertion verifies the command registration triggers addNotes; place this
assertion immediately after the command-registration invocation in the
me-oauth-clients test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/helpers.ts`:
- Around line 10-19: Replace the hard-coded multi-line string array
SCOPES_HELP_NOTES with a derived construction from a structured RESOURCE_SCOPES
array: define RESOURCE_SCOPES (e.g., list of resources like entities,
subscriptions, registrations, rules, custom-data-models, users, tenants,
policies, oauth-clients, api-keys, metrics) with allowed verbs (read, write,
admin) or mapped scope variants, then programmatically generate
SCOPES_HELP_NOTES by iterating RESOURCE_SCOPES to produce the formatted lines
(including grouping admin and write implications and the header/footer lines).
Update any usages of SCOPES_HELP_NOTES to reference the generated constant so
future scope additions only require editing RESOURCE_SCOPES.

In `@tests/me-oauth-clients.test.ts`:
- Around line 27-30: The test currently mocks addNotes (and addExamples) but
doesn't assert it was invoked; after the code path that registers the command(s)
in this test, add an assertion that the mocked addNotes was called (e.g.,
expect(addNotes).toHaveBeenCalledTimes(1) or toHaveBeenCalled()), referencing
the existing vi.mock stub for addNotes so the assertion verifies the command
registration triggers addNotes; place this assertion immediately after the
command-registration invocation in the me-oauth-clients test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 81e4946b-8a85-4606-8c4e-dbe8555195ff

📥 Commits

Reviewing files that changed from the base of the PR and between f148d69 and 10a4e7c.

📒 Files selected for processing (23)
  • CHANGELOG.md
  • README.md
  • src/commands/admin/api-keys.ts
  • src/commands/help.ts
  • src/commands/me-api-keys.ts
  • src/commands/me-oauth-clients.ts
  • src/helpers.ts
  • tests/admin-api-keys.test.ts
  • tests/admin-oauth-clients.test.ts
  • tests/admin-policies.test.ts
  • tests/admin-tenants.test.ts
  • tests/admin-users.test.ts
  • tests/auth.test.ts
  • tests/commands-config.test.ts
  • tests/commands-profile.test.ts
  • tests/entities.test.ts
  • tests/health.test.ts
  • tests/me-api-keys.test.ts
  • tests/me-oauth-clients.test.ts
  • tests/setup-command-mocks.ts
  • tests/snapshots.test.ts
  • tests/temporal.test.ts
  • tests/types.test.ts

writeConfig() に v1→v2 自動ラップを追加し、CLI プロセスでの
auto-migration(ファイル再書き込み)を不要にした。
これにより別プロセス間のファイル I/O タイミング問題を解消。

@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 (1)
tests/e2e/step_definitions/token.steps.ts (1)

8-12: profiles[active] が存在しない場合の潜在的な問題

profiles[active] がundefinedの場合、.token = "invalidated" でランタイムエラーが発生する可能性があります。writeConfig が常に default プロファイルを作成するため、performLogin 後であれば問題ありませんが、防御的にチェックを追加することを検討してください。

🛡️ 防御的なコードの提案
 const full = this.readFullConfig();
 const profiles = full.profiles as Record<string, Record<string, unknown>>;
 const active = (full.currentProfile as string) ?? "default";
+if (!profiles[active]) {
+  throw new Error(`Profile "${active}" not found in config`);
+}
 profiles[active].token = "invalidated";
 this.writeConfig(full);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/step_definitions/token.steps.ts` around lines 8 - 12,
profiles[active] を直接参照して token を上書きすると、profiles[active] が undefined
の場合にクラッシュするので、readFullConfig() で取得した full.profiles と active を使う箇所(変数 names:
full, profiles, active)で profiles[active] が存在しない場合は防御的に新しいプロファイルオブジェクトを作成してから
token を設定し、最後に writeConfig(full) を呼ぶように修正してください(存在チェックと代替作成ロジックを追加)。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/e2e/step_definitions/token.steps.ts`:
- Around line 8-12: profiles[active] を直接参照して token を上書きすると、profiles[active] が
undefined の場合にクラッシュするので、readFullConfig() で取得した full.profiles と active を使う箇所(変数
names: full, profiles, active)で profiles[active]
が存在しない場合は防御的に新しいプロファイルオブジェクトを作成してから token を設定し、最後に writeConfig(full)
を呼ぶように修正してください(存在チェックと代替作成ロジックを追加)。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19260a42-0669-49ef-8db5-0cf5dd582e72

📥 Commits

Reviewing files that changed from the base of the PR and between 10a4e7c and 05e3027.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • tests/e2e/step_definitions/auth.steps.ts
  • tests/e2e/step_definitions/token.steps.ts
  • tests/e2e/support/world.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@miya0001
miya0001 merged commit 649cffe into main Mar 17, 2026
7 checks passed
@miya0001
miya0001 deleted the scopes-help branch March 17, 2026 14: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.

1 participant