refactor: Extract schedule_def tests to submodule#142
Conversation
Move 442 lines of tests from schedule_def.rs to schedule_def/tests.rs, following the same pattern as engine/, protocol/, types/, and output/. Before: 778 LoC (57% tests) After: 334 LoC production code + 442 LoC tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThe single-file schedule definition implementation was replaced by a new module ( Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/pu-core/src/schedule_def/mod.rs`:
- Around line 199-200: next_none_occurrence currently treats after == base as a
valid next occurrence, which violates the exclusive-after semantics used by
recurring branches; update the comparison in next_none_occurrence(base:
DateTime<Utc>, after: DateTime<Utc>) so it returns Some(base) only when after <
base and returns None when after >= base, ensuring a one-shot schedule is not
considered runnable again when after == base.
- Around line 122-136: find_schedule_def currently skips name validation and
allows path traversal; call the existing validate_name(name) at the start of
find_schedule_def and return None (reject) if validation fails so names like
"../other" are not used to build dir.join(format!("{name}.yaml")). Keep the rest
of the lookup logic (find_in_dir, paths::schedules_dir,
paths::global_schedules_dir) unchanged — just early-return on invalid names.
In `@crates/pu-core/src/schedule_def/tests.rs`:
- Around line 182-199: The tests only write schedule defs into
paths::schedules_dir(root) so they never exercise global schedules; update the
failing tests (e.g.,
given_local_and_global_schedule_defs_should_list_local_first and the test around
lines 273-284) to use two separate TempDir roots—one for the project root and
one to act as HOME—call isolate_home() with the HOME temp dir, create and write
a global fixture into paths::global_schedules_dir(home_root) (using
save_schedule_def) and create local fixtures in
paths::schedules_dir(project_root), and for the duplicate-name case write the
same schedule name into both global and local so that
list_schedule_defs()/find_schedule_def() must prefer the local copy and set
scope to "local".
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6da6ce74-7cc7-478b-8ba5-b56c4953c11f
📒 Files selected for processing (3)
crates/pu-core/src/schedule_def.rscrates/pu-core/src/schedule_def/mod.rscrates/pu-core/src/schedule_def/tests.rs
💤 Files with no reviewable changes (1)
- crates/pu-core/src/schedule_def.rs
- Add name validation to find_schedule_def() to prevent path traversal - Fix next_none_occurrence() to use exclusive-after semantics (< vs <=) - Update tests to properly exercise global schedule directories - Add test for next_none_occurrence when after == base Addresses all 3 actionable comments from CodeRabbit review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
crates/pu-core/src/schedule_def/mod.rs (1)
39-41: Consider reusing the existingdefault_agenthelper.There's already a
default_agent()function incrate::serde_defaults(line 8-10 per the context snippet) that returns the same"claude".to_string(). Using it would reduce duplication:-fn default_agent() -> String { - "claude".to_string() -}Then update line 34:
#[serde(default = "crate::serde_defaults::default_agent")]🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/pu-core/src/schedule_def/mod.rs` around lines 39 - 41, Replace the local fn default_agent() in this module with reuse of the existing crate::serde_defaults::default_agent to avoid duplication: update the serde attribute that currently references the local helper to #[serde(default = "crate::serde_defaults::default_agent")] and remove the duplicate fn default_agent() from this file so the module uses the centralized helper instead.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/churn`:
- Around line 33-43: The options --days, --top, and --min-loc currently call
shift 2 without checking that a value exists or is valid; update the argument
parsing loop to validate $2 before consuming it: for each of DAYS, TOP, and
MIN_LOC (the cases handling "--days", "--top", "--min-loc") check that "$2" is
non-empty and does not begin with "-" (and optionally that it matches a numeric
pattern) and if invalid call usage or print a clear error and exit; only then
assign the variable and perform shift 2. Ensure flags like --no-tests, --json
and -h/--help continue to use single shifts unchanged.
- Around line 92-94: The current lookup uses grep -F "$file" against scc_file
which does substring matching and can produce false positives; replace that line
so it performs an exact match on the first TSV column instead. Modify the
scc_line assignment (the code that sets scc_line from scc_file) to use an
awk-based check that splits fields on tab and returns the first matching record
where the first column equals the value of $file (and exits after the first
match), so [[ -z "$scc_line" ]] logic remains valid; update any related variable
names if needed to preserve behavior.
---
Nitpick comments:
In `@crates/pu-core/src/schedule_def/mod.rs`:
- Around line 39-41: Replace the local fn default_agent() in this module with
reuse of the existing crate::serde_defaults::default_agent to avoid duplication:
update the serde attribute that currently references the local helper to
#[serde(default = "crate::serde_defaults::default_agent")] and remove the
duplicate fn default_agent() from this file so the module uses the centralized
helper instead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 81eabf47-713a-4ad3-ac55-98cbb9baa431
📒 Files selected for processing (3)
crates/pu-core/src/schedule_def/mod.rscrates/pu-core/src/schedule_def/tests.rsscripts/churn
The scripts/churn file was unrelated to this PR's purpose (schedule_def refactoring). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
schedule_def.rstoschedule_def/tests.rsengine/,protocol/,types/, andoutput/Changes
find_schedule_def()to prevent path traversalnext_none_occurrence()Before/After
Test plan
cargo test -p pu-core schedule_def- 38 tests passcargo clippy -p pu-core- no warnings🤖 Generated with Claude Code