Expose --config <PATH> and NETSUKE_CONFIG precedence#285
Expose --config <PATH> and NETSUKE_CONFIG precedence#285
Conversation
…nfig file Introduce a new command-line flag `--config <PATH>` and a new environment variable `NETSUKE_CONFIG` to allow users to explicitly specify a configuration file. This bypasses the automatic config discovery mechanism and loads the specified file directly. The legacy `NETSUKE_CONFIG_PATH` remains supported as a silently deprecated alias, with precedence: - `--config` flag (highest) - `NETSUKE_CONFIG` env variable (new documented alias) - `NETSUKE_CONFIG_PATH` env variable (legacy) - automatic discovery (lowest) The `config` field is added to the `Cli` struct with proper annotations (`#[serde(skip)]` and clap arguments) to exclude it from OrthoConfig serialization and merging pipelines, preventing it from leaking as a config preference. The merge pipeline functions are updated to honor the explicit config path, loading that file directly and skipping discovery when specified. Errors on missing or invalid explicit config files are propagated. Localization keys for the flag help text are added with English and Spanish translations. The user guide and design documentation are updated to describe the new flag and environment variable and the precedence rules. Comprehensive integration and behavioral tests verify correct loading precedence, error handling, and backward compatibility. This completes roadmap item 3.11.3, enhancing config file specification clarity and control for users. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideAdds a detailed ExecPlan document for roadmap item 3.11.3 (exposing a --config flag and NETSUKE_CONFIG env var) and performs minor formatting/line-wrap fixes in the developers guide; no CLI or runtime behavior is changed in this PR. Sequence diagram for explicit config selection in merge pipelinesequenceDiagram
actor User
participant NetsukeCli as Netsuke_CLI_binary
participant CliParser as Cli_parser
participant ConfigMerge as Config_merge
participant ResolvePath as resolve_config_path
participant FileLoader as File_loader
participant Discovery as Config_discovery
User->>NetsukeCli: invoke netsuke [args, env]
NetsukeCli->>CliParser: parse CLI into Cli
CliParser-->>NetsukeCli: Cli { config, directory, ... }
NetsukeCli->>ConfigMerge: merge_with_config(Cli, matches)
ConfigMerge->>ResolvePath: resolve_config_path(Cli)
alt CLI --config provided
ResolvePath-->>ConfigMerge: Some(Path_from_cli)
else NETSUKE_CONFIG set
ResolvePath-->>ConfigMerge: Some(Path_from_NETSUKE_CONFIG)
else NETSUKE_CONFIG_PATH set
ResolvePath-->>ConfigMerge: Some(Path_from_NETSUKE_CONFIG_PATH)
else no explicit path
ResolvePath-->>ConfigMerge: None
end
alt explicit config path resolved
ConfigMerge->>FileLoader: load_config_file_as_chain(path)
alt file exists and parses
FileLoader-->>ConfigMerge: Merge_layers_from_file
ConfigMerge-->>NetsukeCli: Merged_Cli_with_explicit_file
else file missing or invalid
FileLoader-->>ConfigMerge: Error
ConfigMerge-->>NetsukeCli: Error(no_fallback_to_discovery)
end
else no explicit path
ConfigMerge->>Discovery: config_discovery(directory)
Discovery-->>ConfigMerge: Merge_layers_from_discovery
ConfigMerge-->>NetsukeCli: Merged_Cli_from_discovery
end
NetsukeCli-->>User: run command with final merged config
Flow diagram for config path resolution precedenceflowchart TD
Start([Start netsuke invocation])
HasCliConfig{CLI flag
--config set?}
HasEnvConfig{Env NETSUKE_CONFIG
set?}
HasEnvConfigPath{Env NETSUKE_CONFIG_PATH
set?}
UseCliConfig[[Use CLI --config path
as config file]]
UseEnvConfig[[Use NETSUKE_CONFIG path
as config file]]
UseEnvConfigPath[[Use NETSUKE_CONFIG_PATH path
as config file]]
RunDiscovery[[Run two-pass
config discovery]]
LoadConfig[[Load selected config
into merge pipeline]]
ErrorMissing[[Error: explicit config
file missing or invalid]]
Start --> HasCliConfig
HasCliConfig -- Yes --> UseCliConfig
HasCliConfig -- No --> HasEnvConfig
HasEnvConfig -- Yes --> UseEnvConfig
HasEnvConfig -- No --> HasEnvConfigPath
HasEnvConfigPath -- Yes --> UseEnvConfigPath
HasEnvConfigPath -- No --> RunDiscovery
UseCliConfig --> CheckCliFile{File exists
and parses?}
CheckCliFile -- Yes --> LoadConfig
CheckCliFile -- No --> ErrorMissing
UseEnvConfig --> CheckEnvFile{File exists
and parses?}
CheckEnvFile -- Yes --> LoadConfig
CheckEnvFile -- No --> ErrorMissing
UseEnvConfigPath --> CheckEnvPathFile{File exists
and parses?}
CheckEnvPathFile -- Yes --> LoadConfig
CheckEnvPathFile -- No --> ErrorMissing
RunDiscovery --> LoadConfig
LoadConfig --> End([Proceed with merged config])
ErrorMissing --> End
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…config file selection - Introduce a visible `--config <FILE>` CLI flag to specify an explicit config file, bypassing automatic discovery. - Add `NETSUKE_CONFIG` environment variable as the documented override, keeping `NETSUKE_CONFIG_PATH` as a legacy fallback. - Centralize explicit config path resolution in `resolve_config_path()` to unify precedence handling across merging and diagnostic JSON resolution. - Update configuration discovery logic to prioritize explicit selectors (`--config` > `NETSUKE_CONFIG` > `NETSUKE_CONFIG_PATH`) before falling back to automatic discovery. - Extend integration and behavioral tests to cover CLI/environment precedence, missing file errors, and legacy support. - Provide a sample annotated config file and update documentation accordingly. This change improves user ergonomics by exposing explicit config file selection via CLI and environment, clarifies configuration precedence, and unifies implementation logic to prevent inconsistencies. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
|
@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. tests/cli_tests/config_selection.rs Comment on lines +63 to +83 fn config_flag_loads_specified_file() -> Result<()> {
let _env_lock = EnvLock::acquire();
let _cwd_guard = CwdGuard::acquire()?;
let project = tempdir().context("create project directory")?;
let home = tempdir().context("create fake home directory")?;
let _user_scope = sandbox_user_scope(&home)?;
let _config_guard = EnvVarGuard::remove("NETSUKE_CONFIG");
let _legacy_guard = EnvVarGuard::remove("NETSUKE_CONFIG_PATH");
let _theme_guard = EnvVarGuard::remove("NETSUKE_THEME");
let custom = project.path().join("custom.toml");
fs::write(&custom, "theme = \"unicode\"\n").context("write explicit config file")?;
std::env::set_current_dir(project.path()).context("change to project directory")?;
let merged = parse_and_merge(&["netsuke", "--config", "custom.toml"])?;
ensure!(
merged.theme == Some(ThemePreference::Unicode),
"explicit --config file should be loaded"
);
Ok(())
}❌ New issue: Code Duplication |
|
@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Comment on file composer: &mut MergeComposer,
errors: &mut Vec<Arc<ortho_config::OrthoError>>,
directory: Option<&Path>,
cli: &Cli,❌ New issue: Bumpy Road Ahead |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…lication - Added ConfigTestHarness struct to unify repeated env lock, temp dirs, cwd guard, and env var setup in CLI integration tests. - Updated tests in cli_tests/config_selection.rs and related modules to use ConfigTestHarness, improving readability and maintainability. - Fixed test cwd teardown hazards by properly dropping guards after assertions, stabilizing parallel test execution. - Simplified load_layers_from_path calls in config_merge.rs with helper push_layers_result for cleaner error handling. - Documented observations and decisions related to tests and config path handling in docs/execplans/3-11-3-expose-config-path-and-netsuke-config.md. These changes improve test suite stability and code clarity without altering external behavior. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
|
@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Ensure that this is validated against the current version of the codegraph. If further refinement to address this finding would be deleterious, please supply a clear explanatory one to two paragraph markdown message I can paste into the CodeScene web ui's diagnostic suppression function so this diagnostic can be silenced. tests/cli_tests/config_selection.rs Comment on lines +96 to +112 fn config_flag_loads_specified_file() -> Result<()> {
let h = ConfigTestHarness::setup()?;
let _config_guard = EnvVarGuard::remove("NETSUKE_CONFIG");
let _legacy_guard = EnvVarGuard::remove("NETSUKE_CONFIG_PATH");
let _theme_guard = EnvVarGuard::remove("NETSUKE_THEME");
let custom_path = h.write_config("custom.toml", "theme = \"unicode\"\n")?;
let custom_arg = custom_path.to_string_lossy().into_owned();
let merged = parse_and_merge(&["netsuke", "--config", &custom_arg])?;
ensure!(
merged.theme == Some(ThemePreference::Unicode),
"explicit --config file should be loaded"
);
let _project_root = h.project.path();
Ok(())
}❌ New issue: Code Duplication |
Summary
--config <PATH>and a user-facing environment variableNETSUKE_CONFIGto specify a config file directly, while keeping backwards-compatibleNETSUKE_CONFIG_PATHas a silent alias.--config>NETSUKE_CONFIG>NETSUKE_CONFIG_PATH> discovery.Rationale
What changed
config: Option<PathBuf>toCliwith#[serde(skip)]and localized help.--config, thenNETSUKE_CONFIG, thenNETSUKE_CONFIG_PATH, else discovery.NETSUKE_CONFIGoverridesNETSUKE_CONFIG_PATHwhen both are set.--configflag help and English/Spanish messages.src/cli_l10n.rs.--configandNETSUKE_CONFIGinteractions intests/cli_tests/config_selection.rs.tests/features/configuration_discovery.featurewith scenarios for explicit config behavior.docs/sample-netsuke.tomldemonstrating all keys.docs/users-guide.md) to document--config,NETSUKE_CONFIG, and precedence.docs/netsuke-design.md) to reflect the new surface.docs/roadmap.md) to mark 3.11.3 as done.docs/execplans.Precedence and behavior
--configpath is resolved against the process working directory and is a file selector (loads that file directly).--configare resolved against the current working directory.NETSUKE_CONFIG_PATHremains supported as a silent alias and is overridden byNETSUKE_CONFIGwhen both are set.Documentation & localization impact
CLI_FLAG_CONFIG_HELPand wired it to map to the--configflag help.docs/sample-netsuke.tomlprovides an annotated, parsable sample config.docs/users-guide.mdupdated to describe--config,NETSUKE_CONFIG, and the precedence.docs/netsuke-design.mdupdated to reflect the new override surface and precedence rules.docs/roadmap.mdupdated to mark 3.11.3 as complete.Tests & validation
tests/cli_tests/config_selection.rsvalidate:--configloads the specified file and bypasses discoveryNETSUKE_CONFIGloads the specified fileNETSUKE_CONFIG>NETSUKE_CONFIG_PATH--configtakes precedence overNETSUKE_CONFIGwhen both are settests/features/configuration_discovery.featurewith explicit-config scenarios demonstrating the behavior to end users.Validation gates
netsuke --helpincludes a localized--configflag description.Artifacts and notes
src/cli/mod.rs,src/cli/config_merge.rs,src/cli/config_merge_tests.rs,src/cli_l10n.rs,src/localization/keys.rs.locales/en-US/messages.ftl,locales/es-ES/messages.ftl.tests/cli_tests/config_selection.rs,tests/features/configuration_discovery.feature,tests/bdd/steps/configuration_discovery.rs.docs/sample-netsuke.toml,docs/users-guide.md,docs/netsuke-design.md,docs/roadmap.md.docs/execplans/3-11-3-expose-config-path-and-netsuke-config.md.If you have any questions or need adjustments to the wording of the new sections, I can tailor them to your preferred PR messaging style.
📎 Task: https://www.devboxer.com/task/05c12be9-87ad-42d7-8ba0-8e576601053d