Skip to content

Add structured handling for settings - #1690

Draft
Mikey Lombardi (He/Him) (michaeltlombardi) wants to merge 8 commits into
PowerShell:mainfrom
michaeltlombardi:gh-1081/main/settings-schematization
Draft

Mikey Lombardi (He/Him) (michaeltlombardi) wants to merge 8 commits into
PowerShell:mainfrom
michaeltlombardi:gh-1081/main/settings-schematization

Conversation

@michaeltlombardi

@michaeltlombardi Mikey Lombardi (He/Him) (michaeltlombardi) commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

PR Summary

This PR defines the structure and handling for initializing settings from multiple scopes.

Note

Will update PR throughout development but needed draft up to enable discussion.

PR Context

Prior to this change, DSC accepted settings from multiple sources and
scopes but retrieved those settings adhoc when needed. The settings
were not structured or consistently retrieved and resolved.

This change starts the work for PowerShell#1081 by:

- Adding a new `settings` module to `dsc-lib` to contain the structured
  cascading hierarchy of settings.
- Defining reusable patterns and guidance for maintaining and extending
  the settings that DSC recognizes.
- Providing stubs for writing rust tests where we need to define
  fixtures to replicate reading from files and environment variables.
This change adds the rust integration tests for the `settings` module.
It also introduces helper macros for validating DSC repo schemas and
updates the schema generation tests to cover the newly defined types.
Prior to this change, the implementation for `idiomaticize_string_enum`
incorrectly used the `enumMarkdownDescriptions` keyword instead of the
correct `markdownEnumDescriptions` keyword.

This change fixes the implementation and tests.
Prior to this change, the `schema_i18n` macro only supported
passing a single string literal as the input value. This made
it impossible to correctly construct calls to the macro when
needing to compose the dotpath through a macro or dynamic
lookup.

This change:

- Enables the macro to accept multiple string literals or
  an arbitrary expression.
- Adds documentation to the macro.
- Adds the missing header comments to the source file.
Prior to this change, the i18n tests would find any apparent
usage of the `t!` macro in a file. This unfortunately also
included documentation comments, which raised errors for
undefined translation strings that are not expected to be
defined.

This change strips lines that begin with a comment before
searching for the expected patterns.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Policy trust validation, source precedence, ignore-file loading, and schema-generation defects remain unresolved.

7 open findings
What changed in this PR

Adds a public, structured DSC settings model with scoped sources, resolution types, schemas, localization, and tests.

Changes:

  • Defines policy, preference, environment, CLI, and default settings structures.
  • Adds reusable schema macros, exports, localization, and extensive tests.
  • Corrects VS Code enum-description keyword handling.
File Description
xtask/​src/​schemas/​export.rs Exports settings schemas.
lib/​dsc-lib/​tests/​integration/​settings/​sources/​preference_file.rs Tests preference schemas and serde.
lib/​dsc-lib/​tests/​integration/​settings/​sources/​policy_file.rs Tests policy schemas and serde.
lib/​dsc-lib/​tests/​integration/​settings/​sources/​environment.rs Tests environment settings.
lib/​dsc-lib/​tests/​integration/​settings/​sources/​command_line.rs Tests CLI settings schemas.
lib/​dsc-lib/​tests/​integration/​settings/​sources/​code_defaults.rs Tests default settings schema.
lib/​dsc-lib/​tests/​integration/​settings/​resolved/​settings.rs Tests resolved settings output.
lib/​dsc-lib/​tests/​integration/​settings/​mod.rs Registers settings tests.
lib/​dsc-lib/​tests/​integration/​settings/​fields/​resource_path.rs Tests resource-path fields.
lib/​dsc-lib/​tests/​integration/​settings/​fields/​ignore_settings_file.rs Tests ignore-file field.
lib/​dsc-lib/​tests/​integration/​settings/​fields/​forbid_ignore_settings_file.rs Tests policy prohibition field.
lib/​dsc-lib/​tests/​integration/​schemas/​schema_for.rs Covers settings schema generation.
lib/​dsc-lib/​tests/​integration/​schemas/​mod.rs Adds schema assertions.
lib/​dsc-lib/​tests/​integration/​main.rs Registers macros and settings tests.
lib/​dsc-lib/​tests/​integration/​macros/​test_schema_validation.rs Adds schema-validation macro.
lib/​dsc-lib/​tests/​integration/​macros/​test_schema_docs.rs Adds schema-documentation macro.
lib/​dsc-lib/​tests/​integration/​macros/​test_meta_schema.rs Adds meta-schema macro.
lib/​dsc-lib/​src/​types/​fully_qualified_type_name.rs Updates API documentation.
lib/​dsc-lib/​src/​tests/​stubs/​mod.rs Registers test stubs.
lib/​dsc-lib/​src/​tests/​stubs/​fs.rs Stubs file reads.
lib/​dsc-lib/​src/​tests/​stubs/​env.rs Stubs environment variables.
lib/​dsc-lib/​src/​tests/​settings/​sources/​preference_file.rs Tests preference loading.
lib/​dsc-lib/​src/​tests/​settings/​sources/​policy_file.rs Tests policy loading.
lib/​dsc-lib/​src/​tests/​settings/​mod.rs Organizes settings unit tests.
lib/​dsc-lib/​src/​tests/​mod.rs Registers unit-test infrastructure.
lib/​dsc-lib/​src/​settings/​sources/​preference_file.rs Defines preference-file data.
lib/​dsc-lib/​src/​settings/​sources/​policy_file.rs Defines policy-file data.
lib/​dsc-lib/​src/​settings/​sources/​mod.rs Organizes settings sources.
lib/​dsc-lib/​src/​settings/​sources/​command_line.rs Defines CLI settings data.
lib/​dsc-lib/​src/​settings/​sources/​code_defaults.rs Defines code defaults.
lib/​dsc-lib/​src/​settings/​resolved/​settings.rs Defines effective settings.
lib/​dsc-lib/​src/​settings/​resolved/​mod.rs Exports resolved types.
lib/​dsc-lib/​src/​settings/​resolved/​field.rs Tracks values and source scopes.
lib/​dsc-lib/​src/​settings/​fields/​tracing.rs Defines tracing settings.
lib/​dsc-lib/​src/​settings/​fields/​resource_path.rs Defines resource-path settings.
lib/​dsc-lib/​src/​settings/​fields/​mod.rs Organizes setting fields.
lib/​dsc-lib/​src/​settings/​fields/​macros/​utility.rs Adds macro utilities.
lib/​dsc-lib/​src/​settings/​fields/​macros/​tests.rs Tests generated field types.
lib/​dsc-lib/​src/​settings/​fields/​macros/​mod.rs Exports field macros.
lib/​dsc-lib/​src/​settings/​fields/​macros/​define_boolean_field.rs Generates boolean fields.
lib/​dsc-lib/​src/​settings/​fields/​ignore_settings_file.rs Defines ignore-file setting.
lib/​dsc-lib/​src/​settings/​fields/​forbid_ignore_settings_file.rs Defines policy prohibition.
lib/​dsc-lib/​src/​settings/​constants_and_statics.rs Defines settings paths.
lib/​dsc-lib/​src/​lib.rs Exposes the settings API.
lib/​dsc-lib/​locales/​schemas.settings.test.yaml Adds macro-test translations.
lib/​dsc-lib/​locales/​en-us.toml Adds settings messages.
lib/​dsc-lib/​Cargo.toml Adds serialized-test support.
lib/​dsc-lib-jsonschema/​tests/​integration/​transforms/​idiomaticize_string_enum.rs Updates enum keyword tests.
lib/​dsc-lib-jsonschema/​tests/​integration_locales/​schemas.yaml Expands schema fixtures.
lib/​dsc-lib-jsonschema/​src/​transforms/​idiomaticize_string_enum.rs Corrects markdown enum output.
lib/​dsc-lib-jsonschema/​src/​schema_utility_extensions.rs Improves invalid-ID diagnostics.
lib/​dsc-lib-jsonschema/​src/​dsc_repo/​macros.rs Documents schema localization macro.
lib/​dsc-lib-jsonschema/​src/​dsc_repo/​dsc_repo_schema.rs Refines trait documentation.
dsc/​tests/​dsc_i18n.tests.ps1 Excludes Rust comments from key discovery.
Cargo.toml Adds shared serial_test.
Cargo.lock Locks the new dependency.
.vscode/​dsc-lib.settings.code-snippets Adds settings error snippets.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/dsc-lib/src/lib.rs
pub mod parser;
pub mod progress;
pub mod schemas;
pub mod settings;
Comment on lines +60 to +62
pub static USER_SETTINGS_FILE_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
if let Some(xdg_config_home) = std::env::var_os("XDG_CONFIG_HOME") {
return Path::new(&xdg_config_home)
Comment on lines 260 to 263
if enum_markdown_descriptions.iter().any(|e| !e.is_empty()) {
schema.insert(
"enumMarkdownDescriptions".to_string(),
"markdownEnumDescriptions".to_string(),
serde_json::to_value(enum_markdown_descriptions).unwrap()
Comment thread lib/dsc-lib/src/lib.rs
pub mod parser;
pub mod progress;
pub mod schemas;
pub mod settings;
Comment thread lib/dsc-lib/src/lib.rs
pub mod parser;
pub mod progress;
pub mod schemas;
pub mod settings;
Comment thread lib/dsc-lib/src/lib.rs
pub mod parser;
pub mod progress;
pub mod schemas;
pub mod settings;
title = crate::schemas::dsc_repo::schema_i18n!("title"),
description = crate::schemas::dsc_repo::schema_i18n!("description"),
extend(
"$schema" = Self::default_export_schema_id_uri(),
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.

2 participants