Skip to content

Users/jstatia/fix plugin switch mappings#159

Merged
elantiguamsft merged 6 commits intomainfrom
users/jstatia/fix_plugin_switch_mappings
Jan 28, 2026
Merged

Users/jstatia/fix plugin switch mappings#159
elantiguamsft merged 6 commits intomainfrom
users/jstatia/fix_plugin_switch_mappings

Conversation

@JeromySt
Copy link
Member

This pull request introduces improved handling for boolean command-line flags in the plugin command infrastructure. It adds explicit support for boolean options that can be specified without a value (e.g., --flag instead of --flag true), both in the core abstractions and in plugin implementations. The changes also include comprehensive tests and adjustments to the command-line argument processing logic to ensure correct behavior for boolean flags.

Key changes:

Core Abstractions and Infrastructure

  • Added a new BooleanOptions property to the IPluginCommand interface and its implementations, allowing each command to specify which options are treated as boolean flags (i.e., can be specified without a value and default to true). (CoseSignTool.Abstractions/IPluginCommand.cs, CoseSignTool.Abstractions/PluginCommandBase.cs) [1] [2]
  • Implemented the GetBooleanFlag method in PluginCommandBase to correctly interpret boolean flags from configuration, treating the presence of a flag (with any value except "false") as true. (CoseSignTool.Abstractions/PluginCommandBase.cs)
  • Updated the command-line argument processing in CoseSignTool.cs to automatically insert "true" for recognized boolean flags that are specified without a value, ensuring compatibility with the configuration system. (CoseSignTool/CoseSignTool.cs) [1] [2]

Plugin Command Implementations

  • Defined and exposed the appropriate boolean options for signing and verification commands in the indirect signature plugin, ensuring that flags like --enable-scitt, --scitt, --allow-untrusted, and --allow-outdated are correctly recognized as boolean. (CoseSignTool.IndirectSignature.Plugin/IndirectSignatureCommandBase.cs, CoseSignTool.IndirectSignature.Plugin/IndirectSignCommand.cs, CoseSignTool.IndirectSignature.Plugin/IndirectVerifyCommand.cs) [1] [2] [3]
  • Updated the logic in IndirectVerifyCommand to use the new GetBooleanFlag method for boolean options, improving correctness and consistency. (CoseSignTool.IndirectSignature.Plugin/IndirectVerifyCommand.cs)

Testing and Test Infrastructure

  • Added comprehensive unit tests for the new boolean flag handling, including default behaviors and various flag value scenarios. (CoseSignTool.Abstractions.Tests/PluginInterfaceTests.cs)
  • Added tests to verify that the correct boolean options are exposed by plugin commands. (CoseSignTool.IndirectSignature.Plugin.Tests/IndirectSignCommandTests.cs, CoseSignTool.IndirectSignature.Plugin.Tests/IndirectVerifyCommandTests.cs) [1] [2]
  • Improved test infrastructure to handle plugin loading and filter out expected warnings in test outputs. (CoseSignTool.Tests/CoseSignTool.Tests.csproj, CoseSignTool.Tests/MainTests.cs) (F733901cL28R28, [1] [2] [3]

…ConfigurationProvider

The Options dictionary in plugins uses 'option-name' -> 'description' format,
but CommandLineConfigurationProvider expects switch mappings in '--option-name' -> 'configKey' format.

This was causing 'The switch mappings contain an invalid switch' errors when running
any plugin command (like indirect-sign).
…ecution

Added comprehensive integration tests that:
- Validate all plugin option keys can be converted to valid switch mappings
- Test that plugin commands execute without crashing on help requests
- Test plugin discovery and loading
- Test indirect-sign and indirect-verify command execution
- Specifically validate the switch mapping conversion that fixed the original bug

Also updated:
- CoseSignTool.Tests.csproj: Added project reference to CoseSignTool.Abstractions and plugin copy target
- MainTests.cs: Filter out expected plugin conflict warnings from stderr assertion
Override GetAdditionalOptionalArguments() to display the payload-location
option in the command's help/usage output.
Boolean flags like --allow-untrusted were not working when specified without
an explicit value (e.g., '--allow-untrusted' vs '--allow-untrusted true').

This was because Microsoft.Extensions.Configuration.CommandLine requires a
value for each switch. When a boolean flag was at the end of the command line
without a value, the configuration key didn't exist.

Changes:
- IPluginCommand.cs: Added BooleanOptions property to interface for plugins
  to declare which options are boolean flags
- PluginCommandBase.cs: Added default empty BooleanOptions, and GetBooleanFlag()
  helper for proper boolean parsing
- CoseSignTool.cs: Added PreprocessBooleanFlags() to insert 'true' for known
  boolean flags. Uses universal flags (--verbose, etc.) plus plugin-provided
  BooleanOptions to maintain proper plugin architecture separation
- IndirectSignatureCommandBase.cs: Added ValidationBooleanOptions and
  SigningBooleanOptions arrays
- IndirectSignCommand.cs: Override BooleanOptions with SigningBooleanOptions
- IndirectVerifyCommand.cs: Override BooleanOptions with ValidationBooleanOptions,
  use GetBooleanFlag() for allow-untrusted/allow-outdated
@JeromySt JeromySt force-pushed the users/jstatia/fix_plugin_switch_mappings branch from a4e9f6b to e4a3aba Compare January 28, 2026 05:48
@JeromySt JeromySt force-pushed the users/jstatia/fix_plugin_switch_mappings branch from e4a3aba to b806d7f Compare January 28, 2026 06:12
@JeromySt JeromySt force-pushed the users/jstatia/fix_plugin_switch_mappings branch from b806d7f to ebdbc2a Compare January 28, 2026 06:12
@JeromySt JeromySt closed this Jan 28, 2026
@JeromySt JeromySt reopened this Jan 28, 2026
@elantiguamsft elantiguamsft merged commit ce6ada4 into main Jan 28, 2026
12 checks passed
@elantiguamsft elantiguamsft deleted the users/jstatia/fix_plugin_switch_mappings branch January 28, 2026 17:47
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.

5 participants