Skip to content

Conversation

@indraneel12
Copy link
Contributor

@indraneel12 indraneel12 commented Oct 17, 2025

Resolves #75

Its validation logic is no longer based on case-sensitive file extensions, as the corresponding upstream packages do support case-insensitivity. The new Test Cases validate this use-case, by checking all combinations of File Content and case-insensitive File Extension permutations.

Old Behavior

Supported file extensions are case-sensitive:
Screenshot_20251021_070558

New Behavior

Supported file extensions are not case-sensitive:
Screenshot_20251021_065044

Features

  • correct validation logic
  • comprehensive test cases
  • enhanced documentation

Summary by CodeRabbit

  • New Features

    • Configuration file extension detection is now case-insensitive for .json, .yaml, and .yml.
  • Bug Fixes

    • Explicit errors for unsupported extensions added; invalid content now yields format errors; missing files produce argument errors.
  • Documentation

    • Usage notes added describing expected inputs and possible exceptions when loading configs.
  • Tests

    • Comprehensive tests added covering JSON/YAML parsing, valid/invalid content, supported/unsupported extensions (including case variants), and missing-file scenarios.

No longer case-sensitive, as the corresponding upstream packages do support case-insensitivity.
Added new Test Cases to check all combinations of File Content and case-insensitive File Extension permutations.
Improved the existing documentation by adding:
  - ArgumentError knowledge
  - UnsupportedError knowledge
  - FormatException knowledge
  - explicit mention of case-insensitive file extensions
@coderabbitai
Copy link

coderabbitai bot commented Oct 17, 2025

📝 Walkthrough

Walkthrough

Normalizes configuration file paths to lowercase for case-insensitive extension detection, adds explicit UnsupportedError for unknown extensions, documents caller expectations, and adds comprehensive tests covering JSON/YAML, extension casing, malformed content, unsupported extensions, and missing files.

Changes

Cohort / File(s) Summary
Configuration parser fix
packages/config/lib/src/config/configuration_parser.dart
fromFile lowercases the input path for case-insensitive extension checks, branches to JSON or YAML parsing via fromString with appropriate ConfigEncoding, documents caller expectations (file existence, supported extensions, possible FormatException), and throws UnsupportedError for unrecognized extensions; existing _loadFile behavior (ArgumentError for missing files) is unchanged.
Test suite (new)
packages/config/test/config/config_file_load_test.dart
New tests create temp files across JSON/YAML formats and extension casings (including unsupported), assert successful parsing for valid content, FormatException for malformed content, UnsupportedError for unsupported extensions, and ArgumentError for missing supported-extension files.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ConfigurationParser
  participant FileSystem as _loadFile

  Caller->>ConfigurationParser: fromFile(filePath)
  ConfigurationParser->>FileSystem: _loadFile(filePath)
  FileSystem-->>ConfigurationParser: fileContents or throws ArgumentError

  alt fileContents returned
    ConfigurationParser->>ConfigurationParser: normalize filePath (toLowerCase)
    alt endsWith(".json")
      ConfigurationParser->>ConfigurationParser: parse JSON via fromString (ConfigEncoding.json)
      ConfigurationParser-->>Caller: return parsed Map
    else endsWith(".yaml" or ".yml")
      ConfigurationParser->>ConfigurationParser: parse YAML via fromString (ConfigEncoding.yaml)
      ConfigurationParser-->>Caller: return parsed Map
    else unsupported extension
      ConfigurationParser-->>Caller: throws UnsupportedError
    end
  else missing file
    FileSystem-->>Caller: throws ArgumentError
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix(ConfigurationParser): Validation Logic for Configuration File Extension" accurately describes the primary change in the changeset, which is implementing case-insensitive file extension validation in ConfigurationParser.fromFile. The title is concise, clear, and follows conventional commit format, making it immediately understandable to someone scanning the pull request history. It properly identifies both the component being modified (ConfigurationParser) and the nature of the fix (validation logic for file extensions).
Linked Issues Check ✅ Passed The code changes fully address the requirements from linked issue #75. The configuration_parser.dart modification implements case-insensitive file extension checks by normalizing the path to lowercase and performing comparison against .json, .yaml, and .yml extensions [#75], along with explicit UnsupportedError handling for unsupported extensions [#75]. The new test file comprehensively validates all combinations of file content, case-insensitive extension permutations, and error scenarios including ArgumentError for non-existent files and UnsupportedError for unsupported extensions [#75]. All coding-related requirements from the linked issue have been successfully implemented.
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly within scope and related to the stated objectives in issue #75. The modifications to configuration_parser.dart implement the case-insensitive file extension validation requirement, while the new test file (config_file_load_test.dart) provides comprehensive coverage of the fixed functionality with multiple permutations of formats, extensions, and content validity scenarios. No unrelated or extraneous changes have been introduced outside the scope of fixing the file extension validation logic.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/config/lib/src/config/configuration_parser.dart (1)

32-39: Documentation could be clearer about file existence validation.

The documentation states "It is expected that the caller ensures [filePath] exists" but the code still validates file existence in _loadFile (lines 58-60). While this defensive programming is good practice, the documentation could be more precise, e.g., "Validates that [filePath] exists and throws [ArgumentError] if not found."

review_comment_end -->

packages/config/test/config/config_file_load_test.dart (1)

87-88: Consider removing debug print statements.

Print statements in test setup add noise to test output. Consider removing them or making them conditional on a debug flag.

-  print('Unique JSON extensions for testing: $jsonExtensionSamplesCount');
-  print('Unique YAML extensions for testing: $yamlExtensionSamplesCount');

review_comment_end -->

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a811a6f and ad33d06.

📒 Files selected for processing (2)
  • packages/config/lib/src/config/configuration_parser.dart (1 hunks)
  • packages/config/test/config/config_file_load_test.dart (1 hunks)
🔇 Additional comments (6)
packages/config/lib/src/config/configuration_parser.dart (2)

41-47: LGTM! Case-insensitive extension check implemented correctly.

The fix properly addresses issue #75 by normalizing the path to lowercase before extension checking. This ensures that extensions like .JSON, .Json, .yaml, .YAML, etc., are all correctly recognized while maintaining backward compatibility.

review_comment_end -->


53-53: Good addition of explicit error handling.

Adding the explicit UnsupportedError for unrecognized extensions improves error clarity and ensures all code paths are properly handled.

review_comment_end -->

packages/config/test/config/config_file_load_test.dart (4)

115-144: Excellent implementation of case-insensitive string generation.

The recursive approach correctly generates all case variations while properly handling non-alphabetic characters. The logic is clean and well-structured.

review_comment_end -->


62-89: Good use of mathematical verification for test data integrity.

The verification logic ensures uniqueness and correctness of generated extensions using the formula 2^n for n-character strings. This catches configuration errors early.

review_comment_end -->


155-200: Comprehensive test coverage for all scenarios.

The test cases thoroughly cover all combinations of content validity, extension correctness, and file formats. Well-organized with descriptive test names.

review_comment_end -->

Also applies to: 202-247


249-276: Good coverage of non-existent file scenarios.

Tests properly verify that missing files with supported extensions throw ArgumentError while missing files with unsupported extensions throw UnsupportedError, ensuring correct error precedence.

review_comment_end -->

@indraneel12 indraneel12 marked this pull request as draft October 17, 2025 15:10
@indraneel12 indraneel12 marked this pull request as ready for review October 17, 2025 15:27
Copy link
Collaborator

@christerswahn christerswahn left a comment

Choose a reason for hiding this comment

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

Great bugfix! Just some restructuring of the tests is needed.

@indraneel12 indraneel12 marked this pull request as draft October 21, 2025 00:47
- improved a variable name
- made a branch structure slightly more readable
Hardcoded the small output of generator-function.
- better description and coverage
- readability improvements
@indraneel12
Copy link
Contributor Author

@christerswahn sir, your review has significantly improved its readability and coverage. Thank you for introducing the GWT technique to my knowledge repertoire.

@indraneel12 indraneel12 marked this pull request as ready for review October 21, 2025 01:29
Copy link
Collaborator

@christerswahn christerswahn left a comment

Choose a reason for hiding this comment

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

Good job! LGTM!

@christerswahn christerswahn changed the title fix(ConfigurationParser): Validation Logic for Configuration File Extension fix(config): Validation Logic for Configuration File Extension Oct 21, 2025
@christerswahn christerswahn merged commit d6b9670 into serverpod:main Oct 21, 2025
13 checks passed
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.

[config] Bug: Validation Logic for Configuration File Extension

2 participants