-
Notifications
You must be signed in to change notification settings - Fork 665
Add shared_state configuration option with CLI override support #4514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add shared_state boolean to JSON schema, types, and constants - Implement CLI override logic using Click ParameterSource detection - Update execution flow to support config-driven shared state - Add comprehensive test coverage for all CLI/config combinations - Maintain full backward compatibility
- Resolve linter error about missing arguments to main() function - Use Click's proper invocation mechanism instead of direct call
There was a problem hiding this 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 adds shared_state configuration option support to Molecule, allowing teams to enable shared state infrastructure by default in molecule.yml while maintaining CLI override capabilities. This enables consistent shared state behavior for CI/CD environments while preserving existing CLI workflows.
Key changes:
- Added
shared_stateboolean field to configuration schema, types, and default values - Implemented CLI override logic using Click's parameter source detection to apply explicit CLI flags over config file values
- Updated execution flow to use shared state when either CLI flags are set OR any scenario has
shared_state: truein configuration
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/molecule/data/molecule.json | Added shared_state boolean field to JSON schema with default false |
| src/molecule/types.py | Added shared_state to TypedDict definitions for configuration types |
| src/molecule/constants.py | Added shared_state: False to DEFAULT_CONFIG |
| src/molecule/config.py | Added CLI override logic and shared_state property as single source of truth |
| src/molecule/scenarios.py | Added shared_state property to check if any scenario requires shared infrastructure |
| src/molecule/command/base.py | Updated execution functions to accept and use shared_state parameter consistently |
| tests/unit/test_migration_logic.py | Updated expected configurations to include new shared_state default |
| tests/unit/command/test_reset.py | Updated test fixtures to support new function signatures and shared_state property |
| tests/unit/command/test_base.py | Added comprehensive test covering all CLI/config override combinations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Add
shared_stateconfiguration option with CLI override supportUser Benefit: Teams can now set
shared_state: trueinmolecule.ymlto enable shared state by default for multi-scenario testing, while retaining the ability to override via--shared-state/--no-shared-stateCLI flags.This is neccessary to keep the use of
shared-statein the molecule configuration for CI and other users of the content.Implementation Flow:
shared_stateboolean to JSON schema,DEFAULT_CONFIG, and TypedDict definitionsshared_stateviaCOMMON_OPTIONS, building identicalcommand_argsstructures_apply_cli_overrides()method inConfig.__init__()uses Click'sget_parameter_source()to detect explicit CLI usage vs defaults, applying CLI values only when explicitly providedscenarios.shared_stateproperty determines if any selected scenario requires shared infrastructureexecute_subcommand_default()runs global create/destroy when CLI flag is set OR any scenario config hasshared_state: trueexecute_scenario()receives global shared state context to skip individual create/destroy actionsConfig.configdictionary during instantiation, makingConfig.shared_stateproperty the authoritative sourceCLI Scope: The
--shared-state/--no-shared-stateflags apply to all scenarios in the current execution, overriding individual scenario configurations. This ensures consistent shared state behavior across multi-scenario runs.Technical Details:
click.core.ParameterSource.COMMANDLINEto distinguish explicit CLI usage from defaultsshared_statethrough common option inheritanceMigration: Fully backward compatible. Existing workflows continue to work unchanged.
Per-file Changes
Core Configuration
src/molecule/data/molecule.json: Addedshared_stateboolean field to JSON schemasrc/molecule/types.py: Addedshared_statetoDefaultConfigDataandConfigDataTypedDict definitionssrc/molecule/constants.py: Addedshared_state: FalsetoDEFAULT_CONFIGConfiguration Processing
src/molecule/config.py:_apply_cli_overrides()method with Click parameter source detectionshared_stateproperty as single source of truthstateproperty to useself.shared_stateExecution Logic
src/molecule/command/base.py:execute_subcommand_default()to accept keyword-onlyshared_stateparameter_run_scenarios()to usescenarios.shared_statepropertyexecute_scenario()to receiveshared_statecontext parametersrc/molecule/scenarios.py: Addedshared_stateproperty to check if any selected scenario requires shared infrastructuresrc/molecule/command/test.py: Removed temporary CLI override trackingTest Coverage
tests/unit/command/test_base.py: Added comprehensive parameterized test covering all 9 CLI/config combinationstests/unit/command/test_reset.py: Updated mocks to support newshared_stateproperty and function signaturestests/unit/test_migration_logic.py: Updated expected configurations to includeshared_statedefault