Reject minute units in stop-after relative time deltas#2611
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Agentic Changeset Generator triggered by this pull request. |
There was a problem hiding this comment.
Pull Request Overview
This PR restricts the stop-after field to reject minute units in relative time deltas, enforcing hours as the minimum granularity. The change introduces a new parsing function specifically for stop-after while preserving backward compatibility for log filtering functionality.
Key Changes:
- Added
parseTimeDeltaForStopAfter()function that rejects minute units via internalparseTimeDeltaWithMinutes(allowMinutes bool)helper - Updated
resolveStopTime()to use the new stricter parser - Added comprehensive test coverage for the minute rejection behavior
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/time_delta.go | Introduced parseTimeDeltaForStopAfter() and refactored parsing logic to support conditional minute validation |
| pkg/workflow/stop_after.go | Switched from parseTimeDelta() to parseTimeDeltaForStopAfter() for stop-after validation |
| pkg/workflow/time_delta_test.go | Added TestParseTimeDeltaForStopAfter() with minute rejection tests and updated existing test to expect errors |
| pkg/workflow/stop_after_test.go | Added TestResolveStopTimeRejectsMinutes() to verify end-to-end minute rejection |
| pkg/workflow/time_delta_integration_test.go | Updated integration tests to use valid time units and added minute rejection error cases |
| pkg/workflow/compiler_test.go | Changed example from +30m to +3h |
| pkg/cli/templates/instructions.md | Updated documentation to clarify minimum unit constraint and remove minute examples |
| docs/src/content/docs/reference/triggers.md | Updated documentation examples from +90m to valid formats |
| .github/instructions/github-agentic-workflows.instructions.md | Updated documentation to remove minute unit examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| result.Minutes != tt.expected.Minutes || result.Weeks != tt.expected.Weeks || | ||
| result.Months != tt.expected.Months { | ||
| t.Errorf("parseTimeDeltaForStopAfter(%q) = {Months: %d, Weeks: %d, Days: %d, Hours: %d, Minutes: %d}, want {Months: %d, Weeks: %d, Days: %d, Hours: %d, Minutes: %d}", | ||
| tt.input, result.Months, result.Weeks, result.Days, result.Hours, result.Minutes, | ||
| tt.expected.Months, tt.expected.Weeks, tt.expected.Days, tt.expected.Hours, tt.expected.Minutes) | ||
| } |
There was a problem hiding this comment.
The Minutes field check is unnecessary since parseTimeDeltaForStopAfter never allows minutes to be set. Consider removing the Minutes comparison from this assertion or explicitly verify it's always zero in valid cases.
| result.Minutes != tt.expected.Minutes || result.Weeks != tt.expected.Weeks || | |
| result.Months != tt.expected.Months { | |
| t.Errorf("parseTimeDeltaForStopAfter(%q) = {Months: %d, Weeks: %d, Days: %d, Hours: %d, Minutes: %d}, want {Months: %d, Weeks: %d, Days: %d, Hours: %d, Minutes: %d}", | |
| tt.input, result.Months, result.Weeks, result.Days, result.Hours, result.Minutes, | |
| tt.expected.Months, tt.expected.Weeks, tt.expected.Days, tt.expected.Hours, tt.expected.Minutes) | |
| } | |
| result.Weeks != tt.expected.Weeks || result.Months != tt.expected.Months { | |
| t.Errorf("parseTimeDeltaForStopAfter(%q) = {Months: %d, Weeks: %d, Days: %d, Hours: %d}, want {Months: %d, Weeks: %d, Days: %d, Hours: %d}", | |
| tt.input, result.Months, result.Weeks, result.Days, result.Hours, | |
| tt.expected.Months, tt.expected.Weeks, tt.expected.Days, tt.expected.Hours) | |
| } | |
| if result.Minutes != 0 { | |
| t.Errorf("parseTimeDeltaForStopAfter(%q) Minutes = %d, want 0", tt.input, result.Minutes) | |
| } |
| delta.Hours = value | ||
| case "m": | ||
| if !allowMinutes { | ||
| return nil, fmt.Errorf("minute unit 'm' is not allowed for stop-after. Minimum unit is hours 'h'. Use +%dh instead of +%dm", (value+59)/60, value) |
There was a problem hiding this comment.
[nitpick] The calculation (value+59)/60 for rounding up minutes to hours could be replaced with a more explicit ceiling division for clarity. Consider using a helper function or a comment explaining the rounding behavior.
The
stop-afterfield now rejects minute (m) units in relative time deltas. Minimum granularity is hours (h).Changes
pkg/workflow/time_delta.go: AddedparseTimeDeltaForStopAfter()that rejects minutes via new internalparseTimeDeltaWithMinutes(allowMinutes bool)function. OriginalparseTimeDelta()unchanged for log filtering compatibility.pkg/workflow/stop_after.go: Switched fromparseTimeDelta()toparseTimeDeltaForStopAfter()Tests: New
TestParseTimeDeltaForStopAfter()andTestResolveStopTimeRejectsMinutes(). Updated existing test cases using minutes in stop-after.Documentation: Updated examples from
+90mto+1d12h. Clarified minimum unit constraint.Error Message
Examples
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.