Skip to content

feat(dev): add --watch-interval flag to dev validate and dev test#171

Merged
pbrissaud merged 2 commits intomainfrom
feat/watch-interval
Feb 26, 2026
Merged

feat(dev): add --watch-interval flag to dev validate and dev test#171
pbrissaud merged 2 commits intomainfrom
feat/watch-interval

Conversation

@pbrissaud
Copy link
Member

Summary

  • Adds --watch-interval / -i duration flag (default 5s) to dev validate and dev test
  • Replaces hardcoded 5*time.Second in TickerWatchLoop calls with the user-supplied value
  • Fully backward-compatible: existing --watch usage keeps the 5s default

Fixes #165

Test plan

  • ./bin/kubeasy dev validate <slug> --watch behaves identically to before (5s interval)
  • ./bin/kubeasy dev validate <slug> --watch --watch-interval 15s polls every 15s
  • ./bin/kubeasy dev test <slug> --watch -i 30s polls every 30s
  • task test:unit passes
  • task lint reports 0 issues

🤖 Generated with Claude Code

Adds a configurable `--watch-interval` / `-i` duration flag (default: 5s)
to both `dev validate` and `dev test`. This prevents poll overlap when a
validation run takes longer than the hardcoded 5s interval.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Feb 26, 2026

Claude finished @pbrissaud's task in 1m 6s —— View job


PR Review: feat(dev): add --watch-interval flag to dev validate and dev test

  • Gather context
  • Read changed files
  • Review code quality and correctness
  • Post detailed review

Summary

The implementation is clean, minimal, and fully backward-compatible. The flag is wired correctly through DurationVarP with the right default (5s), and the --watch flag descriptions are updated to reference --watch-interval for discoverability.

One Bug: Missing validation for non-positive interval

time.NewTicker panics if the interval is ≤ 0:

panic: non-positive interval for NewTicker

If a user runs dev validate <slug> --watch --watch-interval 0s (or passes a negative value), the CLI will crash. A guard should be added before the TickerWatchLoop call in both files. An inline comment has been left on the specific lines. Fix this →

Minor: --watch-interval without --watch is silently ignored

Passing --watch-interval 30s without --watch has no effect. This is a common and acceptable CLI pattern, but a short ui.Warning when watchInterval is non-default and watch is false could improve UX. Not a blocker.

Everything else looks good

  • DurationVarP correctly handles Go duration strings (10s, 1m30s, etc.)
  • Default 5*time.Second preserves existing behavior
  • -i shorthand is intuitive and doesn't conflict with other flags in these commands
  • Flag help text examples (e.g. 10s, 1m) are helpful
  • Doc strings updated consistently across both files

devValidateCmd.Flags().StringVar(&devValidateDir, "dir", "", "Path to challenge directory (default: auto-detect)")
devValidateCmd.Flags().BoolVarP(&devValidateWatch, "watch", "w", false, "Continuously re-run validations every 5 seconds")
devValidateCmd.Flags().BoolVarP(&devValidateWatch, "watch", "w", false, "Continuously re-run validations at the given interval (see --watch-interval)")
devValidateCmd.Flags().DurationVarP(&devValidateWatchInterval, "watch-interval", "i", 5*time.Second, "Interval between watch re-runs (e.g. 10s, 1m)")
Copy link
Contributor

Choose a reason for hiding this comment

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

The --watch-interval flag has no lower-bound validation. If a user passes --watch-interval 0s or a negative duration, time.NewTicker will panic at runtime:

panic: non-positive interval for NewTicker

Consider adding a validation check before passing the interval to TickerWatchLoop:

if devValidateWatch && devValidateWatchInterval <= 0 {
    return fmt.Errorf("--watch-interval must be a positive duration (e.g. 5s, 1m)")
}

Same applies to dev_test_cmd.go line 100.

time.NewTicker panics on a zero or negative duration. Return a clear
error instead of crashing when --watch-interval <= 0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Contributor

claude bot commented Feb 26, 2026

Claude finished @pbrissaud's task in 45s —— View job


PR Review Update: feat(dev): add --watch-interval flag to dev validate and dev test

  • Gather context
  • Read updated files
  • Verify the non-positive interval fix
  • Post updated review

Previous issue resolved

The bug I flagged in the previous review has been correctly addressed. Both files now include the guard before calling TickerWatchLoop:

cmd/dev_validate.go:61-63

if devValidateWatch && devValidateWatchInterval <= 0 {
    return fmt.Errorf("--watch-interval must be a positive duration (e.g. 5s, 1m)")
}

cmd/dev_test_cmd.go:75-77

if devTestWatch && devTestWatchInterval <= 0 {
    return fmt.Errorf("--watch-interval must be a positive duration (e.g. 5s, 1m)")
}

Both guards correctly:

  • Only trigger when --watch is also active (no false positives for --watch-interval without --watch)
  • Cover both zero and negative durations (time.Duration is an int64 in nanoseconds)
  • Return a user-friendly error message with concrete examples

The PR looks good to merge

All originally flagged issues are resolved. The implementation is clean, minimal, and fully backward-compatible.

@sentry
Copy link

sentry bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pbrissaud pbrissaud merged commit 5b5e346 into main Feb 26, 2026
7 checks passed
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.

feat(dev-mode): add argument to --watch flags to specify the

1 participant