refactor(ingestion): extract materializer artifact guard - #454
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughThe PR adds shared validation for materializer artifacts. The CLI uses this validator and converts validation failures to ChangesMaterializer validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Pull request overview
Refactors cohort document materializer artifact path validation by moving the shared CLI guard into the ingestion domain module while adding targeted unit coverage for the new domain API and preserving CLI-facing error messages.
Changes:
- Introduces
require_materializer_artifact()incohort_document_materializerfor validating artifact paths (non-symlink traversal, regular file, single-link). - Updates CLI
_require_materializer_artifactto delegate to the domain guard and adapt domain errors toCommandError. - Adds unit tests covering valid artifacts and rejection cases (symlink, missing, directory, hardlink) plus a CLI adapter contract check.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_cohort_document_materializer.py | Adds direct domain tests for artifact validation plus a CLI adapter contract test. |
| legalforecast/ingestion/cohort_document_materializer.py | Adds require_materializer_artifact domain guard for artifact validation. |
| legalforecast/cli.py | Replaces inline artifact validation with a thin wrapper around the new domain guard. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0a37acd to
3479652
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
legalforecast/ingestion/cohort_document_materializer.py:38
require_materializer_artifactonly treatsFileNotFoundErrorfrompath.lstat()as “not a regular file”. OtherOSErrors (e.g.,PermissionError,NotADirectoryError) will now propagate, whereas the previous CLI implementation (Path.is_file()/is_symlink()) would treat these as a failed file check and emit the stable "must be a regular non-symlink file" message. CatchingOSErrorhere would better preserve the stated CLI/domain error contract.
try:
metadata = path.lstat()
except FileNotFoundError:
metadata = None
3479652 to
ea73745
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
legalforecast/ingestion/cohort_document_materializer.py:38
require_materializer_artifactonly treatsFileNotFoundErrorfrompath.lstat()as a validation failure. Other commonOSErrorcases (e.g.,PermissionError,NotADirectoryError, overly-long paths) will currently bubble up as raw OS exceptions, which would break the stated “preserve CLI boundary / unchanged messages” goal because the CLI adapter won’t convert them into aCommandErrorwith the expected text.
try:
metadata = path.lstat()
except FileNotFoundError:
metadata = None
Summary
CommandErroradapter, unchanged messages, and retained exception causesValidation
uv run ruff format --check .uv run ruff check .uv run pyrightuv run pytest -q tests/test_cohort_document_materializer.py(56 passed)uv run pytest -q(6113 passed, 13 skipped)Bead:
LegalForecastBench-cwdv.5Note
Low Risk
Behavior-preserving refactor with expanded tests; validation rules and CLI messages are unchanged.
Overview
Moves cohort materializer artifact path validation (no symlink components, regular file, single hard link) from the CLI into
require_materializer_artifactincohort_document_materializer.The CLI keeps
_require_materializer_artifactas a thin wrapper that mapsCohortDocumentMaterializationErrortoCommandErrorwith the same user-facing messages and exception chaining.Adds direct unit tests for valid files, symlinks, missing paths, directories, hardlinks, and the CLI error contract.
Reviewed by Cursor Bugbot for commit 0a37acd. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests