Skip to content

Comments

Refactor CLI tunnel service and authorized fetch options#575

Merged
dahlia merged 4 commits intofedify-dev:mainfrom
dahlia:main
Feb 20, 2026
Merged

Refactor CLI tunnel service and authorized fetch options#575
dahlia merged 4 commits intofedify-dev:mainfrom
dahlia:main

Conversation

@dahlia
Copy link
Member

@dahlia dahlia commented Feb 19, 2026

This PR refactors two related CLI option parsers in the @fedify/cli package and upgrades Optique to 0.10.6.

createTunnelServiceOption() factory function

The former tunnelServiceOption constant is replaced by a createTunnelServiceOption() factory function. Previously, the lookup command and the tunnel command each defined their own tunnel service option independently, leading to duplicated logic. The factory accepts an optional list of option names (defaulting to ["--tunnel-service"]), so the tunnel command can reuse the same definition under its -s/--service aliases without copy-pasting.

The default value is also changed from the hard-coded "localhost.run" to undefined. The tunneling implementation already handles the undefined case by randomly selecting a service, so the old default was masking that behavior rather than expressing intent.

The description of the --tunnel-service option no longer redundantly lists all available service names inline; the metavar SERVICE and the config file documentation are sufficient.

authorizedFetchOption with withDefault

authorizedFetchOption is now wrapped with Optique's withDefault() instead of relying on each field's bindConfig default parameter. As a result, --first-knock and --tunnel-service are rejected when provided without the -a/--authorized-fetch flag, giving clearer validation errors on misuse.

The test suite for authorizedFetchOption is expanded to cover:

  • Parsing without -a via setActiveConfig directly
  • Config-driven authorized fetch enablement
  • Reading firstKnock from config
  • Rejection of --first-knock without -a
  • Rejection of --tunnel-service without -a

Optique 0.10.6

Updates @optique/core and @optique/run to 0.10.6 across deno.json, pnpm-workspace.yaml, and the lock files.

dahlia and others added 4 commits February 20, 2026 07:32
Since showChoices: true is set in the runner configuration, the
choice() value parser automatically appends the list of valid
tunnel service options to the help text.  Manually listing them
via valueSet() in the description was redundant.
The `tunnelServiceOption` constant in `options.ts` has been replaced
with a `createTunnelServiceOption()` factory function that accepts
an optional list of option names.  This allows the tunnel command to
reuse the shared option configuration while adding its own short
aliases (`-s`, `--service`) without duplicating the option logic.

The hardcoded default value of `"localhost.run"` has also been removed
from the config binding, delegating the fallback behavior to the
tunneling implementation, which can randomly select a service when
none is specified.
Wrap the `authorizedFetchOption` object parser with Optique's
`withDefault()` instead of supplying fallback values through
`bindConfig`'s `default` parameter.  As a result, `--first-knock`
and `--tunnel-service` are now rejected when provided without
the `-a`/`--authorized-fetch` flag, giving clearer validation
errors on misuse.

The test suite is expanded to cover additional scenarios:

- Parsing without `-a` using `setActiveConfig` directly (without
  the async config-loading path)
- Config-driven authorized fetch enablement
- Reading `firstKnock` value from config
- Rejection of `--first-knock` without `-a`
- Rejection of `--tunnel-service` without `-a`

Co-Authored-By: Codex <codex@openai.com>
@issues-auto-labeler issues-auto-labeler bot added component/build Build system and packaging component/cli CLI tools related component/federation Federation object related labels Feb 19, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dahlia, 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 refactors key command-line interface (CLI) option parsers within the @fedify/cli package to improve code reusability, clarify default behaviors, and enhance input validation. These changes make the CLI more robust and user-friendly by centralizing option definitions and providing more precise error feedback. Additionally, it includes an update to the underlying Optique library, ensuring the project benefits from the latest improvements in its CLI parsing framework.

Highlights

  • CLI Option Refactoring: The tunnelServiceOption has been refactored into a createTunnelServiceOption() factory function, eliminating duplicated logic and allowing for custom option names. The default value for the tunnel service is now undefined, aligning with the random service selection behavior.
  • Enhanced Validation for Authorized Fetch: The authorizedFetchOption now utilizes Optique's withDefault() to enforce clearer validation. This change ensures that --first-knock and --tunnel-service are explicitly rejected if the -a/--authorized-fetch flag is not provided.
  • Expanded Test Coverage: The test suite for authorizedFetchOption has been significantly expanded to cover new validation rules, config-driven behaviors, and the updated default values.
  • Dependency Upgrade: The @optique/core and @optique/run dependencies have been upgraded to version 0.10.6 across the project's configuration and lock files.
Changelog
  • deno.json
    • Updated @optique/config, @optique/core, and @optique/run dependencies to ^0.10.6.
  • deno.lock
    • Updated @hono/hono to 4.12.0.
    • Updated @optique/config, @optique/core, and @optique/run to 0.10.6.
    • Updated integrity hashes for various dependencies.
  • packages/cli/src/lookup.test.ts
    • Added new tests to verify authorizedFetchOption behavior without the -a flag, with config-driven enablement, and for reading firstKnock from config.
    • Added tests to ensure --first-knock and --tunnel-service are rejected when used without -a.
    • Modified existing tests to reflect the tunnelService default value change from "localhost.run" to undefined.
  • packages/cli/src/lookup.ts
    • Imported withDefault from @optique/core.
    • Replaced the direct use of tunnelServiceOption with createTunnelServiceOption().
    • Wrapped authorizedFetchOption with withDefault to manage default values and enforce validation logic.
    • Adjusted bindConfig keys for authorizedFetch and firstKnock to align with the new withDefault structure.
  • packages/cli/src/options.ts
    • Imported OptionName and removed valueSet from @optique/core.
    • Replaced the tunnelServiceOption constant with a new createTunnelServiceOption factory function.
    • The createTunnelServiceOption now accepts custom option names and sets the default tunnel service to undefined.
    • Updated createTunnelOption to use the new createTunnelServiceOption factory.
  • packages/cli/src/tunnel.ts
    • Removed unused imports option, optional, valueSet, and choice.
    • Replaced the direct definition of the service option with a call to createTunnelServiceOption to reuse the new factory function, passing "-s" and "--service" as aliases.
  • pnpm-lock.yaml
    • Updated @optique/config, @optique/core, and @optique/run dependencies to 0.10.6.
    • Updated various eslint-import-resolver-typescript and eslint-plugin-import entries to reflect dependency changes and integrity hashes.
  • pnpm-workspace.yaml
    • Updated @optique/config, @optique/core, and @optique/run dependencies to ^0.10.6.
Activity
  • No human activity has been recorded on this pull request yet.
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.

@dahlia dahlia added this to the Fedify 2.0 milestone Feb 19, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 solid refactoring of CLI options, improving code reuse with the createTunnelServiceOption factory and enhancing validation for authorizedFetchOption using withDefault. The expanded test suite is a valuable addition. I have two suggestions: one to simplify a configuration key for better clarity, and another to correct what appears to be a mistaken assertion in a new test.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 96.49123% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/cli/src/options.ts 88.88% 2 Missing ⚠️
Files with missing lines Coverage Δ
packages/cli/src/lookup.ts 43.87% <100.00%> (+1.21%) ⬆️
packages/cli/src/tunnel.ts 91.89% <100.00%> (-1.22%) ⬇️
packages/cli/src/options.ts 77.22% <88.88%> (-0.56%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@sij411 sij411 left a comment

Choose a reason for hiding this comment

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

Looks cleaner than before

@dahlia dahlia merged commit c8838c6 into fedify-dev:main Feb 20, 2026
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/build Build system and packaging component/cli CLI tools related component/federation Federation object related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants