Repository navigation
(GH-1081) Integrate settings through CLI and lib - #1769
Draft
Mikey Lombardi (He/Him) (michaeltlombardi) wants to merge 2 commits into
Draft
Mikey Lombardi (He/Him) (michaeltlombardi) wants to merge 2 commits into
Mikey Lombardi (He/Him) (michaeltlombardi) wants to merge 2 commits into
Conversation
Mikey Lombardi (He/Him) (michaeltlombardi)
force-pushed
the
gh-1081/main/settings-plumbing
branch
5 times, most recently
from
October 29, 2026 22:01
80a2110 to
70decef
Compare
This change continues the work for using structured settings for DSC. This change: - Defines a globally accessible static for performantly accessing and using the resolved settings. - Replaces ad-hoc settings access with accessing the global static. - Updates the `--ignore-settings-file` argument so users can negate the flag and override the environment variable.
Prior to this change, some of the csp integration tests failed when run in a non-elevated context. This change: - Guards the test behavior on whether the current context is elevated. - Uses `test_case` to treat each test case in the tests as separate tests instead of failing the entire test when one case fails.
Mikey Lombardi (He/Him) (michaeltlombardi)
force-pushed
the
gh-1081/main/settings-plumbing
branch
from
October 30, 2026 17:01
70decef to
1745076
Compare
Mikey Lombardi (He/Him) (michaeltlombardi)
requested a balanced review from Copilot
October 30, 2026 18:36
Copilot started reviewing on behalf of
Mikey Lombardi (He/Him) (michaeltlombardi)
October 30, 2026 18:37
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects can ignore policy settings, bypass executable-path restrictions, and permanently delete user preferences during tests.
9 open issues
Restore the fallback user settings file after tests · New Use the correct plural settings-file environment variable · New Expect one error record at error trace level · New Canonicalize and validate executable paths consistently · New Load external settings in the library initializer · New Propagate false for the settings-file override · New Allow discovery without PATH when environment paths are disabled · New Search configured resource directories for executables · New Preserve UNC paths during Windows canonicalization · New
What changed in this PR
Continues #1081 by connecting structured DSC settings to CLI startup, resource discovery, and command execution, replacing ad-hoc settings access.
Changes:
- Adds shared settings initialization and cached resource paths, with restricted-directory checks before command execution.
- Supports explicit
--ignore-settings-file=falseand resolves tracing through structured settings. - Expands settings integration tests, updates discovery expectations, and parameterizes CSP tests.
| File | Description |
|---|---|
lib/dsc-lib/src/util.rs |
Removes legacy settings loading and updates executable resolution. |
lib/dsc-lib/src/settings/mod.rs |
Exposes the global settings module. |
lib/dsc-lib/src/settings/global.rs |
Adds shared settings storage and accessors. |
lib/dsc-lib/src/settings/fields/tracing.rs |
Adds trace-level type conversions. |
lib/dsc-lib/src/settings/dsc_settings.rs |
Uses public setting names in warnings. |
lib/dsc-lib/src/dscresources/command_resource.rs |
Checks executable directories against resolved restrictions. |
lib/dsc-lib/src/dscerror.rs |
Adds a restricted-executable error. |
lib/dsc-lib/src/discovery/command_discovery.rs |
Uses structured settings and caches discovery paths. |
lib/dsc-lib/locales/en-us.toml |
Updates settings and restriction diagnostics. |
dsc/tests/other/dsc_settings.tests.ps1 |
Expands coverage for settings sources, precedence, and restrictions. |
dsc/tests/other/dsc_settings_policy_security.tests.ps1 |
Updates policy filenames and assertion diagnostics. |
dsc/tests/discovery/dsc_discovery.tests.ps1 |
Adjusts restricted-path and relative-executable tests. |
dsc/tests/discovery/dsc_adapter.tests.ps1 |
Accepts resolved executable paths in trace assertions. |
dsc/src/util.rs |
Configures tracing from resolved settings. |
dsc/src/main.rs |
Initializes settings and propagates selected values to children. |
dsc/src/args.rs |
Supports boolean flag overrides and typed CLI settings conversion. |
Cargo.lock |
Records CSP test dependencies. |
adapters/csp/tests/cli.rs |
Parameterizes tests and gates elevated Windows cases. |
adapters/csp/Cargo.toml |
Adds parameterized-test and elevation-check dependencies. |
Review effort: Balanced
Comment on lines
+302
to
+304
| if (-not [string]::IsNullOrEmpty($env:XDG_CONFIG_HOME)) { | ||
| $script:XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME | ||
| Remove-Item Env:\XDG_CONFIG_HOME |
Comment on lines
+552
to
+554
| if (-not [string]::IsNullOrEmpty($env:DSC_IGNORE_SETTING_FILE)) { | ||
| $script:dscIgnoreSettingFile = $env:DSC_IGNORE_SETTING_FILE | ||
| Remove-Item env:DSC_IGNORE_SETTING_FILE |
| $testContext = New-TestContext -TraceFilePath $TestDrive/tracing.txt | ||
|
|
||
| $traces = Get-Content -Path $TestDrive/tracing.txt | ConvertFrom-Json -Depth 10 | ||
| $traces.Count | Should -BeGreaterOrEqual 3 -Because $testContext |
Comment on lines
+946
to
+948
| let executable_folder = executable.parent().unwrap().to_path_buf(); | ||
|
|
||
| if !directories.value.clone().contains(&executable_folder) { |
| /// | ||
| /// A `MutexGuard` to the global `DscSettings` instance. | ||
| pub fn get_or_init() -> MutexGuard<'static, DscSettings> { | ||
| DSC_SETTINGS_GLOBAL.get_or_init(|| Mutex::new(DscSettings::new())) |
Comment on lines
+90
to
97
| // if ignoring settings files is set from CLI, we create an env var called | ||
| // `DSC_IGNORE_SETTINGS_FILE` set to value 1 for recursive invocations | ||
| if global_settings.ignoring_settings_files() | ||
| && global_settings.resolved().ignore_settings_file.scope == DscSettingsScope::CommandLine { | ||
| unsafe { | ||
| set_var(EnvironmentData::DSC_IGNORE_SETTINGS_FILE_ENV_VAR, "1"); | ||
| } | ||
| } |
Comment on lines
+195
to
+203
| let Some(current_env_path) = env::var_os("PATH") else { | ||
| return Err(DscError::Operation(t!("discovery.commandDiscovery.failedGetEnvPath").to_string())); | ||
| }; | ||
|
|
||
| // if exe home is not already in PATH env var then add it to env var | ||
| // and list of searched paths | ||
| if let Some(exe_home) = get_exe_path()?.parent() { | ||
| let exe_home_pb = &exe_home.to_path_buf(); | ||
| let mut env_paths = env::split_paths(¤t_env_path).collect::<Vec<_>>(); |
Comment on lines
+203
to
+204
| let mut env_paths = env::split_paths(¤t_env_path).collect::<Vec<_>>(); | ||
| if env_paths.contains(exe_home_pb) { |
| if let Some(cwd_path) = cwd { | ||
| if let Ok(mut canonical_path) = canonicalize(cwd_path.join(&executable_path)).map(|p| p.to_string_lossy().to_string()) { | ||
| if cfg!(target_os = "windows") { | ||
| canonical_path = canonical_path.trim_start_matches(r"\\?\").to_string() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


PR Summary
This change continues the work for using structured settings for DSC. This change:
--ignore-settings-fileargument so users can negate the flag and override the environment variable.PR Context
Continues the work from #1081