Skip to content

fix: implement _get_changed_files for FilePatternCondition#71

Merged
dkargatzis merged 5 commits intowarestack:mainfrom
codesensei-tushar:fix/file-pattern-changed-files
Apr 12, 2026
Merged

fix: implement _get_changed_files for FilePatternCondition#71
dkargatzis merged 5 commits intowarestack:mainfrom
codesensei-tushar:fix/file-pattern-changed-files

Conversation

@codesensei-tushar
Copy link
Copy Markdown
Contributor

@codesensei-tushar codesensei-tushar commented Apr 9, 2026

Summary

  • FilePatternCondition._get_changed_files() was a TODO stub that returned [] for both PR and push events, making the files_match_pattern condition entirely non-functional
  • Now reads from the enriched changed_files list (populated by the PR enricher) for pull request events
  • For push events, aggregates file paths from each commit's added, modified, and removed arrays

Closes #70

Summary by CodeRabbit

  • Bug Fixes

    • Change detection now correctly extracts changed file paths from enriched pull-request and push event payloads, handles mixed entry shapes, filters malformed entries, and de-duplicates results to avoid missed changes.
  • Tests

    • Added unit and integration tests covering all extraction paths and end-to-end pattern-matching behavior across event types.

@trunk-io
Copy link
Copy Markdown

trunk-io bot commented Apr 9, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@watchflow
Copy link
Copy Markdown

watchflow bot commented Apr 9, 2026

🛡️ Watchflow Governance Checks

Status: ❌ 1 Violations Found

🟡 Medium Severity (1)

Ensures PRs that modify source code also include a CHANGELOG or .changeset addition.

Source code was modified without a corresponding CHANGELOG update.
How to fix: Add an entry to CHANGELOG.md or generate a new .changeset file describing your changes.


💡 Reply with @watchflow ack [reason] to override these rules, or @watchflow help for commands.

Thanks for using Watchflow! It's completely free for OSS and private repositories. You can also self-host it easily.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45aab1c1-d183-44c5-b553-495565db5fc4

📥 Commits

Reviewing files that changed from the base of the PR and between 6ffde34 and 92c85c2.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/rules/conditions/filesystem.py
  • tests/unit/rules/conditions/test_filesystem.py
✅ Files skipped from review due to trivial changes (1)
  • tests/unit/rules/conditions/test_filesystem.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • src/rules/conditions/filesystem.py

📝 Walkthrough

Walkthrough

The _get_changed_files() now returns filenames from enriched event payloads: it prefers event["changed_files"] (extracting "filename" from dict entries or passing through strings) and falls back to aggregating added/modified/removed from event["commits"], deduplicating and sorting results. Tests added.

Changes

Cohort / File(s) Summary
Implementation Fix
src/rules/conditions/filesystem.py
Replaced placeholder [] behavior with logic that extracts filenames from PR-style changed_files (handles dicts and plain strings) or from push-style commits (added/modified/removed), using a set for deduplication and returning a sorted list.
Test Coverage
tests/unit/rules/conditions/test_filesystem.py
Added unit tests covering dict and string changed_files, commit-based aggregation for push events, empty-event behavior, robustness against malformed entries, and two async integration-style tests for FilePatternCondition.evaluate() with PR and push contexts.
Changelog
CHANGELOG.md
Added Unreleased entry documenting the fix to _get_changed_files and the corresponding tests; added new dated headings and reordered entries.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 I hopped through payloads, sniffed the trails,
Pulled filenames from commits and PR details.
No more empty lists — the files now show,
Patterns can check where the changes go. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: implementing the previously stubbed _get_changed_files method for FilePatternCondition.
Linked Issues check ✅ Passed The PR implementation fully satisfies issue #70 requirements: extracts filenames from PR changed_files dicts, aggregates files from push event commits (added/modified/removed), deduplicates, and returns empty list as fallback.
Out of Scope Changes check ✅ Passed All changes directly support the stated objectives: implementing _get_changed_files logic, comprehensive test coverage, and updating changelog. No extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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: 1

🧹 Nitpick comments (1)
tests/unit/rules/conditions/test_filesystem.py (1)

99-166: Add one malformed-payload regression for _get_changed_files

Nice coverage on happy paths and dedup. Please add one error-path test with mixed invalid entries (e.g., missing filename, None, non-list commit keys) and assert it returns only valid string paths without exceptions.

As per coding guidelines: "Write unit tests for deterministic rule evaluation (pass/warn/block), model validation, and error paths" and "Write regression tests for every bug fix; keep CI coverage thresholds green".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/rules/conditions/test_filesystem.py` around lines 99 - 166, Add a
regression test that supplies a mixed malformed payload to
FilePatternCondition._get_changed_files (e.g., changed_files containing a dict
missing "filename", a None, a non-string value, and commits with non-list values
or non-string entries) and assert the method returns only the valid string file
paths and does not raise an exception; implement this as a new test function
(e.g., test_get_changed_files_with_malformed_payload) mirroring existing tests'
style and using condition._get_changed_files to validate the filtered output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/rules/conditions/filesystem.py`:
- Around line 120-135: The _get_changed_files parsing trusts payload shapes;
update the logic that reads event.get("changed_files") and event.get("commits")
to validate types: only accept changed_files when it's a list and each entry is
either a non-empty str or a dict with a non-empty str "filename"; for commits,
skip non-dict commit entries, ensure added/modified/removed are lists, and only
add items that are non-empty str paths to the seen set before returning
sorted(seen); reference the variables/functionality around changed_files,
commits, the keys ("added","modified","removed"), and the seen set when applying
the guards.

---

Nitpick comments:
In `@tests/unit/rules/conditions/test_filesystem.py`:
- Around line 99-166: Add a regression test that supplies a mixed malformed
payload to FilePatternCondition._get_changed_files (e.g., changed_files
containing a dict missing "filename", a None, a non-string value, and commits
with non-list values or non-string entries) and assert the method returns only
the valid string file paths and does not raise an exception; implement this as a
new test function (e.g., test_get_changed_files_with_malformed_payload)
mirroring existing tests' style and using condition._get_changed_files to
validate the filtered output.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 192a864b-5e0c-4a8c-a536-c17cff74ed2e

📥 Commits

Reviewing files that changed from the base of the PR and between bdac59c and be60ed0.

📒 Files selected for processing (2)
  • src/rules/conditions/filesystem.py
  • tests/unit/rules/conditions/test_filesystem.py
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (.cursor/rules/guidelines.mdc)

**/*.py: Use modern typing only: dict[str, Any], list[str], str | None (no Dict, List, Optional)
GitHub/HTTP/DB calls must be async def; avoid blocking calls (time.sleep, sync HTTP) in async paths
All agent outputs and external payloads must use validated BaseModel from Pydantic
Use dataclasses for internal immutable state where appropriate
Use structured logging at boundaries with fields: operation, subject_ids, decision, latency_ms
Implement Agent pattern: single-responsibility agents with typed inputs/outputs
Use Decorator pattern for retries, metrics, caching as cross-cutting concerns
Agent outputs must include: decision, confidence (0..1), short reasoning, recommendations, strategy_used
Implement confidence policy: reject or route to human-in-the-loop when confidence < 0.5
Use minimal, step-driven prompts; provide Chain-of-Thought only for complexity > 0.7 or ambiguity > 0.6
Strip secrets/PII from agent prompts; scope tools; keep raw reasoning out of logs (store summaries only)
Cache idempotent lookups; lazy-import heavy dependencies; bound fan-out with asyncio.Semaphore
Avoid redundant LLM calls; memoize per event when safe
Use domain errors (e.g., AgentError) with error_type, message, context, timestamp, retry_count
Use exponential backoff for transient failures; circuit-break noisy integrations when needed
Fail closed for risky decisions; provide actionable remediation in error paths
Validate all external inputs; verify webhook signatures
Implement prompt-injection hardening; sanitize repository content passed to LLMs
Performance targets: Static validation ~<100ms typical, hybrid decisions sub-second when cache warm, budget LLM paths thoughtfully
Reject old typing syntax (Dict, List, Optional) in code review
Reject blocking calls in async code; reject bare except: clauses; reject swallowed errors
Reject LLM calls for trivial/deterministic checks
Reject unvalidated agent outputs and missing confidenc...

Files:

  • src/rules/conditions/filesystem.py
  • tests/unit/rules/conditions/test_filesystem.py
tests/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/guidelines.mdc)

tests/**/*.py: Write unit tests for deterministic rule evaluation (pass/warn/block), model validation, and error paths
Write integration tests for webhook parsing, idempotency, multi-agent coordination, and state persistence
Use pytest.mark.asyncio for async tests; avoid live network calls; freeze time and seed randomness
Write regression tests for every bug fix; keep CI coverage thresholds green

Files:

  • tests/unit/rules/conditions/test_filesystem.py
🧠 Learnings (2)
📚 Learning: 2026-03-27T12:52:44.067Z
Learnt from: oleksii-quinta
Repo: warestack/watchflow PR: 67
File: src/webhooks/handlers/issue_comment.py:153-159
Timestamp: 2026-03-27T12:52:44.067Z
Learning: When enqueuing processor tasks using `task_queue`, follow the documented pre-built-task pattern: (1) build the task with `pre_built_task = task_queue.build_task(event_type, payload, processor.process, delivery_id=...)`; (2) call `task_queue.enqueue(processor.process, event_type, payload, pre_built_task, delivery_id=...)` by passing the pre-built task as a single positional `*args` element; (3) ensure the worker ultimately calls `await processor.process(pre_built_task)` (i.e., the processor `process(self, task: Task)` receives the `Task` instance). This matches the expectation that `enqueue` stores the pre-built task in the wrapper Task’s `args` as described by `build_task`’s docstring (“pass as single arg to enqueue”).

Applied to files:

  • src/rules/conditions/filesystem.py
📚 Learning: 2026-01-31T19:35:22.504Z
Learnt from: CR
Repo: warestack/watchflow PR: 0
File: .cursor/rules/guidelines.mdc:0-0
Timestamp: 2026-01-31T19:35:22.504Z
Learning: Applies to tests/**/*.py : Write unit tests for deterministic rule evaluation (pass/warn/block), model validation, and error paths

Applied to files:

  • tests/unit/rules/conditions/test_filesystem.py

Comment thread src/rules/conditions/filesystem.py
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project status has failed because the head coverage (73.0%) is below the target coverage (80.0%). You can increase the head coverage or adjust the target coverage.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@           Coverage Diff           @@
##            main     #71     +/-   ##
=======================================
+ Coverage   72.8%   73.0%   +0.1%     
=======================================
  Files        181     181             
  Lines      13398   13456     +58     
=======================================
+ Hits        9762    9828     +66     
+ Misses      3636    3628      -8     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ab4368...92c85c2. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@dkargatzis dkargatzis left a comment

Choose a reason for hiding this comment

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

The implementation is robust with proper type guards and covers both happy and error paths. Tests are also thorough.

@watchflow
Copy link
Copy Markdown

watchflow bot commented Apr 12, 2026

🛡️ Watchflow Governance Checks

Status: ❌ 1 Violations Found

🟠 High Severity (1)

When a PR modifies paths that have owners defined in CODEOWNERS, the corresponding code owners must be added as reviewers

Code owners for modified paths must be added as reviewers: dkargatzis
How to fix: Add the listed code owners as requested reviewers on the PR.


💡 Reply with @watchflow ack [reason] to override these rules, or @watchflow help for commands.

Thanks for using Watchflow! It's completely free for OSS and private repositories. You can also self-host it easily.

@dkargatzis dkargatzis merged commit 5658ed3 into warestack:main Apr 12, 2026
3 of 4 checks passed
@codesensei-tushar codesensei-tushar deleted the fix/file-pattern-changed-files branch April 14, 2026 05:15
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.

fix: FilePatternCondition never checks files — _get_changed_files() always returns empty list

3 participants