Plugin extensibility: format registration mechanism.#122
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughIntroduces ChangesFormat Registry System
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/formats/test_registry.py (1)
100-110: ⚡ Quick winAdd negative tests for malformed
file_patternsvalidation.Given the registry contract is central to plugin extensibility, please add tests for invalid
file_patterns(e.g., bare string and empty tuple) so bad specs fail fast and this behavior stays protected.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/formats/test_registry.py` around lines 100 - 110, Add new test functions to validate that the FormatRegistry properly rejects malformed file_patterns in RegisteredFormat subclasses. Create at least two additional test functions following the same pattern as test_register_validation_missing_format_id: one test where file_patterns is a bare string instead of a tuple, and another where file_patterns is an empty tuple. For each test, instantiate a BadSpec class with the invalid file_patterns value, call reg.register(BadSpec), and assert that it raises a ValueError with an appropriate error message mentioning file_patterns. This ensures the registry validation protects against these common misconfiguration patterns.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/boost_weblate/formats/registry.py`:
- Around line 55-57: The current validation in the file_patterns check only
ensures it's non-empty but doesn't prevent a bare string from being passed,
which causes incorrect behavior since strings are iterable and the
match_filename() method will iterate over individual characters. In the
_validate() method, add explicit validation to ensure file_patterns is a
sequence type (list or tuple) and not a string, raising a ValueError with a
descriptive message if a string is passed. Apply the same validation logic in
the register_entry() method to catch this issue at the entry point where plugins
register their file patterns.
In `@tests/test_settings_override.py`:
- Line 67: The assertion on line 67 uses a hardcoded threshold value of 40 which
creates brittle coupling to a specific Weblate release. Replace this hardcoded
number with a computed expectation derived from the upstream FormatsConf.FORMATS
data that is already being parsed elsewhere in this test file. Calculate the
expected baseline count from the actual formats data and use that computed value
in the assertion instead of the magic number 40.
---
Nitpick comments:
In `@tests/formats/test_registry.py`:
- Around line 100-110: Add new test functions to validate that the
FormatRegistry properly rejects malformed file_patterns in RegisteredFormat
subclasses. Create at least two additional test functions following the same
pattern as test_register_validation_missing_format_id: one test where
file_patterns is a bare string instead of a tuple, and another where
file_patterns is an empty tuple. For each test, instantiate a BadSpec class with
the invalid file_patterns value, call reg.register(BadSpec), and assert that it
raises a ValueError with an appropriate error message mentioning file_patterns.
This ensures the registry validation protects against these common
misconfiguration patterns.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0507ea3b-157a-49d5-a826-1aab5f049796
📒 Files selected for processing (8)
README.mddocs/deployment-runbook.mdsrc/boost_weblate/formats/__init__.pysrc/boost_weblate/formats/quickbook.pysrc/boost_weblate/formats/registry.pysrc/boost_weblate/settings_override.pytests/formats/test_registry.pytests/test_settings_override.py
Close #118.
Summary by CodeRabbit
Release Notes