diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c9829c..8312374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Report a failed job when all configured `{repo}` values are blank instead of silently succeeding without running anything. + - Reject Windows Task Scheduler intervals above 1439 minutes during planning instead of producing unsupported minute-mode commands. ## 0.18.0 - 2026-11-15 diff --git a/README.md b/README.md index 6b9da65..462d102 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,9 @@ Legacy fallback also recognizes supported binaries selected by absolute or relative executable path. Discovery records an absolute executable path so saved jobs keep working when the runner starts from another directory. +Jobs using `{repo}` require at least one nonblank repository; blank-only lists +report a failed job instead of silently doing no work. + Scheduler due checks use the exact job and repository identity, so colon-containing names do not share scheduling history. diff --git a/cmd/crawlctl/main_test.go b/cmd/crawlctl/main_test.go index 35a824f..fab583c 100644 --- a/cmd/crawlctl/main_test.go +++ b/cmd/crawlctl/main_test.go @@ -270,3 +270,43 @@ func TestPrintTailHandlesLongLines(t *testing.T) { type ioDiscard struct{} func (ioDiscard) Write(p []byte) (int, error) { return len(p), nil } + +func TestRunJobsRejectsBlankRepositories(t *testing.T) { + for _, tc := range []struct { + name string + repos []string + }{ + {"missing", nil}, + {"empty", []string{""}}, + {"whitespace", []string{" \t\r\n"}}, + {"multiple blanks", []string{"", " ", "\t"}}, + } { + t.Run(tc.name, func(t *testing.T) { + configPath := filepath.Join(t.TempDir(), "crawlctl.toml") + cfg := scheduler.DefaultConfig() + cfg.Jobs["refresh"] = scheduler.Job{Enabled: true, Command: []string{"unused", "{repo}"}, Repos: tc.repos} + paths, err := scheduler.Save(configPath, cfg, false) + if err != nil { + t.Fatal(err) + } + var stdout bytes.Buffer + a := app{stdout: &stdout, stderr: ioDiscard{}, json: true, config: configPath} + err = a.runJobs(t.Context(), nil) + var failure jobFailureError + if !errors.As(err, &failure) || failure.Count != 1 || exitCode(err) != 1 { + t.Fatalf("run error = %v; want one failed job", err) + } + var records []scheduler.RunRecord + if err := json.Unmarshal(stdout.Bytes(), &records); err != nil { + t.Fatal(err) + } + if len(records) != 1 || records[0].Job != "refresh" || records[0].Status != "failed" || !strings.Contains(records[0].Error, "has no repos") { + t.Fatalf("run records = %+v", records) + } + history, err := scheduler.ReadHistory(paths.History) + if err != nil || len(history) != 1 || history[0].ID != records[0].ID { + t.Fatalf("failed job not recorded in history: %+v, %v", history, err) + } + }) + } +} diff --git a/scheduler/run.go b/scheduler/run.go index 928829a..ee7f30d 100644 --- a/scheduler/run.go +++ b/scheduler/run.go @@ -144,9 +144,6 @@ func expandJob(name string, job Job) ([]expandedJob, error) { if !hasRepo { return []expandedJob{{command: append([]string(nil), job.Command...)}}, nil } - if len(job.Repos) == 0 { - return nil, fmt.Errorf("%s uses {repo} but has no repos", name) - } out := make([]expandedJob, 0, len(job.Repos)) for _, repo := range job.Repos { repo = strings.TrimSpace(repo) @@ -159,6 +156,9 @@ func expandJob(name string, job Job) ([]expandedJob, error) { } out = append(out, expandedJob{repo: repo, command: command}) } + if len(out) == 0 { + return nil, fmt.Errorf("%s uses {repo} but has no repos", name) + } return out, nil } diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go index dbdc613..855a8f4 100644 --- a/scheduler/scheduler_test.go +++ b/scheduler/scheduler_test.go @@ -16,7 +16,7 @@ import ( ) func TestExpandRepoJob(t *testing.T) { - job := Job{Command: []string{"gitcrawl", "refresh", "{repo}", "--json"}, Repos: []string{"a/b", "c/d"}} + job := Job{Command: []string{"gitcrawl", "refresh", "{repo}", "--json"}, Repos: []string{"", "a/b", " \t", " c/d "}} expanded, err := expandJob("gitcrawl", job) if err != nil { t.Fatalf("expand: %v", err)