Skip to content

Comments

Make CLI classes typed#868

Open
kostyanf14 wants to merge 1 commit intoHCK-CI:masterfrom
kostyanf14:typed-cli
Open

Make CLI classes typed#868
kostyanf14 wants to merge 1 commit intoHCK-CI:masterfrom
kostyanf14:typed-cli

Conversation

@kostyanf14
Copy link
Contributor

Rework all attributes to the Sorbet struct property. Unfortunately, sorbet typecheck cannot validate OptionParser option type assignment to the sorbet property type, but it works at runtime.

This is done as part of preparation for the ability to bring up the previous session.

For example, the following code will pass typecheck but will fail at runtime with type cast error:

prop :id, Integer, default: 2
parser.on('--id <id>', String,
                'Set ID for AutoHCK run',
                &method(:id=))

/ruby/3.3.0/gems/sorbet-runtime-0.6.12935/lib/types/configuration.rb:293:in `call_validation_error_handler_default': Parameter 'id': Can't set AutoHCK::CliCommonOptions.id to "s" (instance of String) - need a Integer (TypeError)

Copilot AI review requested due to automatic review settings February 16, 2026 17:59
@gemini-code-assist
Copy link

Summary of Changes

Hello @kostyanf14, 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 introduces Sorbet type checking to the command-line interface (CLI) option classes. By converting CommonOptions, TestOptions, and InstallOptions into T::Structs, the codebase gains improved type safety and better maintainability. This change also serves as foundational work for future features, such as the ability to restore previous sessions, by providing a more robust and predictable structure for CLI arguments.

Highlights

  • Sorbet Type Integration: Implemented Sorbet T::Struct for CommonOptions, TestOptions, and InstallOptions classes, enhancing type safety and clarity.
  • Property-based Options: Replaced attr_accessor with prop definitions in CLI option classes, allowing for explicit type declarations and default values.
  • Refactored CLI Structure: Updated the main CLI class to instantiate and utilize the new T::Struct-based option classes, streamlining option management.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • lib/cli.rb
    • Converted CommonOptions to CliCommonOptions using T::Struct.
    • Converted TestOptions to CliTestOptions using T::Struct.
    • Converted InstallOptions to CliInstallOptions using T::Struct.
    • Added Sorbet type annotations (# typed: true, extend T::Sig, prop) to the new T::Struct classes.
    • Updated the main CLI class to use CliCommonOptions, CliTestOptions, and CliInstallOptions as T::Struct properties.
    • Removed explicit default value assignments from define_options methods, as these are now handled by T::Struct prop definitions.
    • Added sig annotations to methods in the CLI class.
Activity
  • No activity found for this pull request.
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.

Copy link

@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 great step towards making the CLI classes type-safe by refactoring them to use Sorbet's T::Struct. The changes significantly improve code clarity and maintainability. I've found a few issues related to the new implementation. There's a critical issue with command-line argument parsing due to OptionParser instances not being memoized. I've also found a potential bug with the use of JsonHelper and some minor issues regarding the idiomatic use of T::Struct properties. Please see my detailed comments.

Copy link

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 migrates the CLI option containers to Sorbet-typed T::Struct classes to provide runtime type enforcement and better static typing as preparation for restoring previous sessions.

Changes:

  • Replaced CLI option classes based on attr_accessor/manual defaults with T::Struct props (common/test/install).
  • Updated OptionParser wiring to mostly assign directly via generated setters (e.g., &method(:foo=)).
  • Converted AutoHCK::CLI itself to a T::Struct and introduced typed helper methods (parser, sub_parser, parse).

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

@kostyanf14
Copy link
Contributor Author

/gemini review

Copy link

@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 refactors the CLI option handling classes to use Sorbet's T::Struct, which is a great improvement for type safety and code clarity. The changes are well-executed and consistently applied across all option classes. I've found one potential issue regarding the implementation of JsonHelper that will need to be addressed for the session restoration feature to work correctly.

Copy link

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

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


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

Rework all attributes to the Sorbet struct property.
Unfortunately, sorbet typecheck cannot validate OptionParser
option type assignment to the sorbet property type, but it
works at runtime.

This is done as part of preparation for the ability to bring
up the previous session.

For example, the following code will pass typecheck but will
fail at runtime with type cast error:
```
prop :id, Integer, default: 2
parser.on('--id <id>', String,
                'Set ID for AutoHCK run',
                &method(:id=))
```

/ruby/3.3.0/gems/sorbet-runtime-0.6.12935/lib/types/configuration.rb:293:in `call_validation_error_handler_default':
Parameter 'id': Can't set AutoHCK::CliCommonOptions.id to "s" (instance of String) - need a Integer (TypeError)

Signed-off-by: Vitalii Chulak <vitalii@daynix.com>
Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
@kostyanf14
Copy link
Contributor Author

Rspec failed due to new HLK release

Failures:

  1) kit_spec Kit for ./lib/engines/hckinstall/kits/HLK11_25H2.json can be downloaded
     Failure/Error: expect(Digest::SHA256.hexdigest(content)).to eq(kit.sha256) if file_type == 'exe'

       expected: #<Encoding:UTF-8> "b970b8f8dd2af850e951a9dae6278bb16b6e63ad25caa8525be9441567248809"
            got: #<Encoding:US-ASCII> "4b54a67374e32e0239669e4394134cec070d4390a8ef8f2b9a0bd14ae9d1bc6d"

       (compared using ==)
     # ./spec/kit_spec.rb:25:in `block (3 levels) in <top (required)>'

  2) kit_spec Kit for ./lib/engines/hckinstall/kits/HLK2025.json can be downloaded
     Failure/Error: expect(Digest::SHA256.hexdigest(content)).to eq(kit.sha256) if file_type == 'exe'

       expected: #<Encoding:UTF-8> "b970b8f8dd2af850e951a9dae6278bb16b6e63ad25caa8525be9441567248809"
            got: #<Encoding:US-ASCII> "4b54a67374e32e0239669e4394134cec070d4390a8ef8f2b9a0bd14ae9d1bc6d"

       (compared using ==)
     # ./spec/kit_spec.rb:25:in `block (3 levels) in <top (required)>'

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