Skip to content

feat(config): implement schema validation when loading configuration#96

Merged
IT-WIBRC merged 1 commit intodevelopfrom
feat/config-file-validation
Oct 5, 2025
Merged

feat(config): implement schema validation when loading configuration#96
IT-WIBRC merged 1 commit intodevelopfrom
feat/config-file-validation

Conversation

@IT-WIBRC
Copy link
Owner

@IT-WIBRC IT-WIBRC commented Oct 5, 2025

Description

This PR implements schema validation for CLI configuration files (.devkitrc.json and local variants) to ensure data integrity, prevent runtime errors from malformed settings, and provide clear feedback to the user when a configuration is invalid.

This change also refactors the template and settings display utilities to support multiple output modes (tree and table), and fixes a critical bug where templates sharing the same name but belonging to different languages would overwrite each other during processing.


🚀 Key Changes

1. Configuration Validation and Error Handling

  • Schema Enforcement: The CLI now validates both global and local configuration files against the defined schema upon loading.
  • Graceful Failure: If an invalid configuration is detected (e.g., incorrect field types, missing required fields, or invalid enum values like a bad defaultPackageManager), the CLI will:
    • Log a clear validation failure error message.
    • Exit with code 1 during config-dependent commands (like dk config or dk info).
  • New dk info Validation Test: Added an integration test to specifically confirm that dk info correctly reports an error when it encounters a malformed local configuration file.

2. Enhanced Output Display (Tree/Table Modes)

  • The printSettings and printTemplates utilities are updated to accept a mode parameter (tree or table).
  • printSettings: Settings can now be displayed in a clean key-value list (tree, default) or a formal table structure (table).

3. Critical Template Processing Fix

  • Unique Template Key: Fixed a bug in printTemplates where the intermediate map key was based solely on template._name. This caused templates with identical names across different languages (e.g., javascript:basic and typescript:basic) to overwrite each other.
  • Solution: The unique key for the temporary map is now a composite of language and name (${template._language}:${template._name}), ensuring all templates are correctly loaded and available for filtering and display.

✅ Testing

  • Updated integration tests for dk config to include new validation failure cases.
  • Updated integration tests for dk info to check validation failure reporting.
  • Updated unit tests for the printer utility to cover the new tree and table display modes for both templates and settings.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing feature support current supported languages
  • Any dependent changes have been merged and published in downstream modules

@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2025

Coverage Report for ./packages/devkit

Status Category Percentage Covered / Total
🟢 Lines 96.29% (🎯 85%) 3460 / 3593
🟢 Statements 96.29% (🎯 85%) 3460 / 3593
🟢 Functions 96.25% (🎯 90%) 154 / 160
🟢 Branches 92.69% (🎯 85%) 761 / 821
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/devkit/src/commands/index.ts 87.14% 89.47% 100% 87.14% 43-45, 50-55
packages/devkit/src/commands/list.ts 99.13% 91.66% 100% 99.13% 125
packages/devkit/src/core/config/loader.ts 94.87% 87.5% 100% 94.87% 29-30
packages/devkit/src/core/config/validation.ts 78.16% 81.39% 100% 78.16% 53-56, 108-115, 136-137, 153-160, 166-173, 178-185
packages/devkit/src/core/template/filter.ts 100% 97.56% 100% 100%
packages/devkit/src/core/template/printer.ts 94.85% 76.19% 100% 94.85% 20, 47, 50, 107-110, 123, 148
Generated in workflow #282 for commit 99b5b29 by the Vitest Coverage Report Action

@IT-WIBRC IT-WIBRC merged commit 6a4efa2 into develop Oct 5, 2025
2 checks passed
@github-actions github-actions bot deleted the feat/config-file-validation branch October 5, 2025 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant