Skip to content

CLI: Add Source to ArgMap for sourcing the origin of argument data - #41636

Draft
David Bennett (dkbennett) wants to merge 2 commits into
masterfrom
user/dkbennett/argumentsource
Draft

David Bennett (dkbennett) wants to merge 2 commits into
masterfrom
user/dkbennett/argumentsource

Conversation

@dkbennett

Copy link
Copy Markdown
Member

Summary of the Pull Request

Adds Source data to arguments so their origin can be tracked for diagnostic and user error attribution. The immediate use case is any argument set by environment variable can be known to be set by environment variable so we could give the user more information than just "invalid arg" if that argument fails validation or during execution, since it would be hidden inside an environment var the user may not realize is being used.

This is future-looking plumbing for supporing something like #41468

  • Add a Source bitmask to ArgMap with None, Default, Environment, Settings, CommandLine, and Input values.
  • Require every ArgMap::Add() call to identify its source explicitly.
  • Track one aggregate source mask per ArgType; repeated values accumulate contributing sources, while single-value replacement clears the previous source.
  • Report resolved GetValue() defaults as Source::Default.
  • Mark parser values as CommandLine, environment bindings as Environment, and prompted or stdin values as Input.
  • Add GetSource() for diagnostics and future user-facing error attribution.
  • Add coverage for aggregation, replacement, defaults, removal, invalid source masks, failed-write rollback, environment precedence, and parser sources.

The idea here is that if an arg value is being set by settings or environment variables not obvious to the user that we can tailor a more appropriate and effective error message instead of just a somewhat bewildering "session not found" when they didn't provide a session in the command line. This may have other value for future diagnostics and logging to better replicate a failure case by ensuring arguments are sourced the same way as the failure repro which could be part of the bug.

This is not an urgent PR.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [xcan I ] Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Build and added / changed tests pass.

Copilot AI lite review requested due to automatic review settings September 17, 2026 20:02

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

Address the critical header self-containment issue and add the missing parser source-reset regression test.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds provenance tracking to WSLC CLI arguments for improved diagnostics and source attribution.

Changes:

  • Adds source masks and aggregation to ArgMap.
  • Tags command-line, environment, default, and input values.
  • Expands unit-test coverage for provenance and precedence.
File summaries
File Summary
test/windows/wslc/WSLCCLIParserUnitTests.cpp Tests parser source attribution.
test/windows/wslc/WSLCCLIExecutionUnitTests.cpp Updates source-aware argument tests.
test/windows/wslc/WSLCCLIEnvironmentOptionsUnitTests.cpp Tests environment provenance and precedence.
test/windows/wslc/WSLCCLIArgumentUnitTests.cpp Tests source aggregation, defaults, and rollback.
src/windows/wslc/core/EnvironmentOptions.cpp Tags environment-derived values.
src/windows/wslc/commands/RegistryCommand.cpp Tags prompted and stdin values.
src/windows/wslc/arguments/ArgumentParser.cpp Tags parsed values as command-line sourced.
src/windows/wslc/arguments/ArgMap.h Stores and exposes argument provenance.
Review details

Suppressed comments (1)

src/windows/wslc/arguments/ArgumentParser.cpp:123

  • The last-wins source reset is not covered: parser tests only repeat command-line flags, so they cannot detect a stale Source::Environment bit. Please add a regression case that starts with an environment-backed single-value argument, parses the same option from the command line, and asserts GetSource() is only Source::CommandLine after ClearArgument/Add.
    m_executionArgs.Add(type, value, Source::CommandLine);
  • Files reviewed: 8/8 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


namespace wsl::windows::wslc::argument {

enum class Source : uint32_t

This branch has not been deployed

No deployments
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