Skip to content

Conversation

@stepan662
Copy link
Contributor

@stepan662 stepan662 commented May 20, 2025

Summary by CodeRabbit

  • Chores
    • Updated dependencies to include "ajv" and upgraded "jsonschema".
  • Bug Fixes
    • Enhanced configuration validation with improved error messages and stricter schema checks.
  • Tests
    • Added end-to-end tests to verify configuration validation and error handling for invalid config fields.
  • Documentation
    • Clarified documentation for configuration file push settings regarding file selection and filtering.

@coderabbitai
Copy link

coderabbitai bot commented May 20, 2025

"""

Walkthrough

The changes update the configuration validation logic by switching from the jsonschema library to ajv for schema validation, including adapting error handling and messages. The package.json is updated to reflect these dependency changes. Additionally, a new end-to-end test suite is added to verify schema validation for configuration files. The documentation comment for the files property in the schema interface was also refined.

Changes

File(s) Change Summary
package.json Added ajv@^8.17.1 dependency; upgraded jsonschema from ^1.4.1 to ^1.5.0.
src/config/tolgeerc.ts Replaced jsonschema with ajv for config validation; updated error handling and messages.
test/e2e/config.test.ts Added end-to-end tests for config schema validation covering invalid field values and unknown fields.
src/schema.d.ts Updated documentation comment for push.files property to clarify usage and remove example.

Sequence Diagram(s)

sequenceDiagram
    participant CLI
    participant ConfigLoader
    participant AjvValidator

    CLI->>ConfigLoader: loadTolgeeRc(configPath)
    ConfigLoader->>AjvValidator: Compile schema (async)
    ConfigLoader->>AjvValidator: Validate config
    AjvValidator-->>ConfigLoader: Validation result (valid/invalid)
    alt Validation fails
        ConfigLoader->>CLI: exitWithError(formatted error message)
    else Validation succeeds
        ConfigLoader-->>CLI: Return parsed config
    end
Loading

Poem

In the warren where configs are checked,
A new validator hops in—quite direct!
Ajv now guards with vigilant eyes,
While tests ensure no bug can disguise.
With dependencies trimmed and errors precise,
This rabbit’s code is robust and nice!
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-28T17_58_10_235Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63aa835 and dfb9959.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json (1 hunks)
  • src/config/tolgeerc.ts (3 hunks)
  • src/schema.d.ts (1 hunks)
  • test/e2e/config.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • package.json
  • src/schema.d.ts
  • test/e2e/config.test.ts
  • src/config/tolgeerc.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: E2E Tests (ubuntu-latest, 20)
  • GitHub Check: E2E Tests (ubuntu-latest, 18)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@stepan662 stepan662 linked an issue May 20, 2025 that may be closed by this pull request
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: 0

🧹 Nitpick comments (1)
src/config/tolgeerc.ts (1)

112-114: Consider simplifying validation check.

The validation and error checking could be slightly simplified.

- validate(config);
- const firstErr = validate.errors?.[0];
- 
- if (firstErr) {
+ if (!validate(config)) {
+   const firstErr = validate.errors?.[0];

This would combine the validation call with the error check, which is a common pattern when using Ajv.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e75c268 and 91eb1eb.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/config/tolgeerc.ts (3 hunks)
  • test/e2e/config.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/e2e/config.test.ts (2)
test/e2e/utils/tmp.ts (1)
  • createTmpFolderWithConfig (27-33)
test/e2e/utils/run.ts (1)
  • run (98-105)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: E2E Tests (ubuntu-latest, 22)
  • GitHub Check: E2E Tests (ubuntu-latest, 20)
  • GitHub Check: E2E Tests (ubuntu-latest, 18)
🔇 Additional comments (10)
package.json (2)

33-33: Dependencies updated appropriately.

Adding the Ajv library as a dependency aligns with the PR objective of switching to ajv for JSON-schema validation.


39-39: Upgraded jsonschema version.

Upgrading the jsonschema dependency to a newer version is a good practice, especially when making validation-related changes.

test/e2e/config.test.ts (5)

4-13: Well-structured test for format validation.

This test correctly verifies that the schema validation fails when an invalid format is provided. The test creates a temporary config file with an invalid value, runs the CLI command, and checks both the exit code and error message.


15-23: Good coverage for projectId validation.

This test ensures that the schema validation correctly handles invalid projectId values. The use of an object instead of a number is a good edge case to test.


25-33: Parser validation test looks good.

This test verifies that the schema validation correctly handles invalid parser values, ensuring that only supported parsers can be specified in the configuration.


35-45: Nested property validation test is valuable.

Testing validation for nested properties like push.forceMode ensures that the schema validation works for all levels of the configuration object.


47-54: Excellent test for future extensibility.

This test is particularly valuable as it verifies that unknown properties don't cause validation failures. This ensures backward compatibility if new properties are added to the schema in future versions.

src/config/tolgeerc.ts (3)

11-11: Import updated to use Ajv.

The import has been correctly updated to use Ajv instead of the previous jsonschema Validator.


34-34: Minor string literal adjustment.

The quote style has been updated from single quotes to a mix of double and single quotes to improve readability of the error message.


109-118: Validation logic switched to Ajv.

The validation logic has been successfully migrated from jsonschema to Ajv. Using allowUnionTypes: true is a good choice to ensure compatibility with schemas that use union types.

The error message formatting is improved, with a clean approach to convert JSON paths (with slashes) to dot notation, which is more readable for users.

@stepan662 stepan662 requested a review from JanCizmar May 20, 2025 12:41
@stepan662 stepan662 force-pushed the stepangranat/fix-tolgee-config-validation branch from 63aa835 to dfb9959 Compare May 28, 2025 17:57
@stepan662 stepan662 merged commit 2eb22c0 into main May 28, 2025
15 checks passed
@stepan662 stepan662 deleted the stepangranat/fix-tolgee-config-validation branch May 28, 2025 18:03
@github-actions
Copy link

🎉 This PR is included in version 2.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

jsonschema package causing error in certain environment

2 participants