Skip to content

Conversation

@jbrinkman
Copy link
Owner

Description

Fixes #38: Configuration values for OutputFormat and OutputPath are now properly used when included in configuration files.

Problem

The original issue was that configuration values from JSON files were being ignored due to incorrect precedence logic. Command line default values were unconditionally overriding configuration file values, even when users didn't explicitly provide command line arguments.

Solution

Core Changes

  1. Fixed Configuration Precedence Logic (CompareCommand.cs):

    • Changed OutputFormat property from non-nullable with default value to nullable
    • Updated override logic to only apply when user explicitly provides command line values
    • Now distinguishes between explicit user input vs. automatic defaults
  2. Fixed JSON Enum Serialization (ComparisonConfiguration.cs):

    • Added JsonStringEnumConverter to SaveToJsonFile method
    • Ensures consistent enum handling between serialization and deserialization

Test Coverage

  1. Added Comprehensive Unit Tests (JsonEnumSerializationTests.cs):

    • 9 passing tests verifying JSON enum parsing with various case formats
    • Tests for both "Html" and "html" format variations
    • Validates LoadFromJsonFile method functionality
  2. Added Integration Tests (CliWorkflowTests.cs):

    • CliWorkflow_ConfigurationJsonEnumParsing_ShouldParseOutputFormatCorrectly: Verifies config values are used when no CLI override
    • CliWorkflow_CommandLineOverridesConfig_ShouldUseExplicitCommandLineFormat: Verifies CLI values override config when explicitly provided

Behavior

✅ Before Fix

  • Configuration file values were ignored
  • Command line defaults always overrode config values
  • JSON enum parsing worked but precedence was broken

✅ After Fix

  • Config File Values Used: When no command line output format is specified, values from configuration file are respected
  • Command Line Override Works: When user explicitly provides --output argument, it correctly overrides config file values
  • JSON Enum Parsing: Both "Html" and "html" formats in JSON config files work correctly
  • Round-trip Serialization: Save and load configuration maintains enum values properly

Testing

  • All 425 tests passing with no regressions
  • Tested both precedence scenarios (config used vs CLI override)
  • Verified JSON enum parsing with multiple case variations
  • Integration tests confirm end-to-end functionality

Files Changed

  • src/DotNetApiDiff/Commands/CompareCommand.cs - Fixed precedence logic
  • src/DotNetApiDiff/Models/Configuration/ComparisonConfiguration.cs - Fixed JSON serialization
  • tests/DotNetApiDiff.Tests/Integration/CliWorkflowTests.cs - Added integration tests
  • tests/DotNetApiDiff.Tests/Unit/JsonEnumSerializationTests.cs - Added unit tests
  • tests/DotNetApiDiff.Tests/TestData/config-output-format-and-path.json - Test data

Fixes #38: Configuration values for OutputFormat and OutputPath are now
properly used when included in configuration files.

Changes:
- Modified CompareCommand.cs to fix configuration precedence logic
- Changed OutputFormat property to nullable to detect explicit user input
- Fixed JSON enum serialization in ComparisonConfiguration.cs
- Added comprehensive unit tests for JSON enum parsing
- Added integration tests for configuration precedence scenarios

The fix ensures:
- Config file values are used when no CLI override is provided
- Explicit CLI arguments properly override config values
- JSON enum parsing works with both 'Html' and 'html' formats
- Round-trip serialization maintains enum values correctly

All 425 tests passing with no regressions.
@jbrinkman jbrinkman requested a review from Copilot July 31, 2025 13:00
Copy link
Contributor

Copilot AI left a 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 fixes a configuration precedence issue where command line default values were incorrectly overriding configuration file values for OutputFormat and OutputPath parameters, even when users didn't explicitly provide command line arguments.

  • Changed OutputFormat property to nullable to distinguish between explicit user input and automatic defaults
  • Fixed JSON enum serialization to ensure consistent handling between save and load operations
  • Added comprehensive test coverage for configuration precedence scenarios

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/DotNetApiDiff/Commands/CompareCommand.cs Fixed configuration precedence logic by making OutputFormat nullable and only overriding config values when explicitly provided
src/DotNetApiDiff/Models/Configuration/ComparisonConfiguration.cs Added JsonStringEnumConverter to SaveToJsonFile method for consistent enum serialization
tests/DotNetApiDiff.Tests/Unit/JsonEnumSerializationTests.cs Added comprehensive unit tests for JSON enum parsing with case variations
tests/DotNetApiDiff.Tests/Integration/CliWorkflowTests.cs Added integration tests to verify configuration precedence and CLI override behavior
tests/DotNetApiDiff.Tests/TestData/config-output-format-and-path.json Test configuration file with output format and path settings

Fixes Windows CI failure where file paths with backslashes in JSON strings
were not properly escaped, causing JSON parsing errors.

Changes:
- Escape backslashes in outputPath interpolation for integration tests
- Use .Replace('\', '\\') to convert single backslashes to double backslashes
- Fixes both CliWorkflow tests that create JSON config files with paths

This resolves the System.Text.Json.JsonException on Windows CI builds
while maintaining compatibility with Unix-style paths on macOS/Linux.
- Fixed CliWorkflow_WithConfigFileOutputSettings_ShouldUseConfigurationValues test
- Added proper JSON escaping when replacing paths in config file content
- Use .Replace('\', '\\') to escape backslashes for Windows paths
- Resolves JSON parsing error: 'U' is an invalid escapable character

This complements the previous Windows CI fix and ensures all integration
tests work correctly on Windows by properly escaping file paths when
they are inserted into JSON configuration files.
@jbrinkman jbrinkman merged commit 5bf69c8 into main Jul 31, 2025
7 checks passed
@jbrinkman jbrinkman deleted the fix/configuration-precedence-issue-38 branch July 31, 2025 13:29
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.

Configuration values for OutputFormat and OutputPath are not being used when included in the configuration file

2 participants