Skip to content

fix: fix check of auth options required#1346

Merged
nameless-mc merged 7 commits intomainfrom
fix/auth-options-required-check
Feb 20, 2026
Merged

fix: fix check of auth options required#1346
nameless-mc merged 7 commits intomainfrom
fix/auth-options-required-check

Conversation

@nameless-mc
Copy link
Contributor

Why

Previously, all commands shared the same commonOptions which included all auth options (username, password, api-token, etc.) regardless of whether the command supported them. Commands had to .hide() unsupported options and perform runtime validation in handlers, which was error-prone and provided unclear feedback to users.

What

  • Replace commonOptions with a new connectionOptions.ts module that separates auth strategies:
    • withPasswordAuth: For commands requiring username/password auth (plugin upload, customize apply/export)
    • withApiTokenAuth: For commands requiring API token auth (record delete)
    • withEitherAuth: For commands accepting either username/password or API token (record import/export)
    • guestSpaceOptions: Separated guest space options, applied only to commands that need them
  • Update each command builder to use the appropriate auth function
  • Move validation to yargs check() for declarative validation, removing runtime checks from handlers
  • Add middleware to prioritize password auth when both auth types are provided
  • Add unit tests (connectionOptions.test.ts) and command integration tests (commands.test.ts)

How to test

  • Run pnpm test to verify unit tests pass
  • Verify appropriate error messages are shown when auth options are missing:
    • record import --base-url ... --app 1 --file-path ... → Either username or API token is required
    • record delete --base-url ... --app 1 --yes → API token is required
    • plugin upload --base-url ... --input ... → Username and password are required

Checklist

  • Read CONTRIBUTING.md
  • Updated documentation if it is required.
  • Added/updated tests if it is required. (or tested manually)
  • Passed pnpm lint and pnpm test on the root directory.

@nameless-mc nameless-mc self-assigned this Feb 13, 2026
@nameless-mc nameless-mc requested a review from a team as a code owner February 13, 2026 07:32
@nameless-mc nameless-mc requested review from chihiro-adachi, Copilot and tasshi-me and removed request for a team February 13, 2026 07:32
Copy link
Contributor

Copilot AI left a comment

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 refactors CLI authentication handling to make it more declarative and type-safe. Previously, all commands shared a single commonOptions object and manually hid unsupported auth options, leading to inconsistent validation and unclear error messages. The new approach uses dedicated auth helper functions that explicitly define which auth strategies each command supports.

Changes:

  • Introduced connectionOptions.ts with three auth helper functions (withPasswordAuth, withApiTokenAuth, withEitherAuth) that encapsulate auth validation logic
  • Updated all CLI commands to use the appropriate auth helper function instead of manually hiding options
  • Moved auth validation from runtime handlers to declarative yargs check() functions
  • Added comprehensive unit and integration tests

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
src/cli/connectionOptions.ts New module defining connection options and auth helper functions with validation
src/cli/commonOptions.ts Removed in favor of the new modular approach
src/cli/record/import.ts Now uses withEitherAuth and guestSpaceOptions
src/cli/record/export.ts Now uses withEitherAuth and guestSpaceOptions
src/cli/record/delete.ts Now uses withApiTokenAuth, removed runtime validation
src/cli/plugin/upload.ts Now uses withPasswordAuth, removed guestSpaceId parameter
src/cli/customize/apply.ts Now uses withPasswordAuth and guestSpaceOptions
src/cli/customize/export.ts Now uses withPasswordAuth and guestSpaceOptions
src/cli/tests/connectionOptions.test.ts New unit tests for auth helper functions
src/cli/tests/commands.test.ts New integration tests verifying auth validation in commands
src/tests/api.test.ts Removed redundant test for auth prioritization (now handled at CLI layer)

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

* Either (username AND password) or API token is required.
* When both are provided, password auth takes priority (api-token is cleared).
*/
export const withEitherAuth = (args: yargs.Argv) => {
Copy link
Member

Choose a reason for hiding this comment

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

好みもあるけど、ビルダーパターンでも良さそうに思いました。
サポートする認証方法が増えたときとか(例: OAuth追加)、プロキシなどのネットワーク系のオプションを個別に有効無効にしたくなった場合の改修コストが抑えやすそうです。

function buildConnectionOptions(
  {
   auth: ("password"|"apiToken")[], // 複数指定された場合はいずれか必須になる
   guestSpace?: boolean // (デフォルトfalse)
  }
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

あー確かにその方が良さそうですね
ちょっとそういう方針で調整してみます

Copy link
Contributor Author

Choose a reason for hiding this comment

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

7c80061 で対応してみました

@nameless-mc nameless-mc merged commit c78a44b into main Feb 20, 2026
42 checks passed
@nameless-mc nameless-mc deleted the fix/auth-options-required-check branch February 20, 2026 08:54
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.

4 participants