Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Save discovered executables as absolute paths so relative app selections work from another runner directory.

- Preserve each job's latest text status when history keys collide or runs finish in the same second.

- Keep scheduler due checks scoped to the exact job and repository when colon-containing names share a legacy history key.

- Keep scheduler status scoped to the exact job name when another job or repository history key shares its prefix.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ schedule source-specific commands such as Photos' `import_apple`.
Discovery reports malformed metadata and missing manifest IDs in the app's
`error` field. Supported legacy binaries retain their fallback manifests.
Legacy fallback also recognizes supported binaries selected by absolute or
relative executable path.
relative executable path. Discovery records an absolute executable path so saved
jobs keep working when the runner starts from another directory.

Scheduler due checks use the exact job and repository identity, so colon-containing
names do not share scheduling history.
Expand Down
11 changes: 4 additions & 7 deletions cmd/crawlctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (a *app) runStatus(args []string) error {
if job.Enabled {
state = "never"
}
if record, ok := latestRecordForJob(last, name); ok {
if record, ok := latestRecordForJob(history, name); ok {
state = record.Status
detail = " " + record.FinishedAt
}
Expand All @@ -303,17 +303,14 @@ func (a *app) runStatus(args []string) error {
return nil
}

func latestRecordForJob(last map[string]scheduler.RunRecord, name string) (scheduler.RunRecord, bool) {
if record, ok := last[name]; ok && record.Job == name {
return record, true
}
func latestRecordForJob(history []scheduler.RunRecord, name string) (scheduler.RunRecord, bool) {
var latest scheduler.RunRecord
found := false
for _, record := range last {
for _, record := range history {
if record.Job != name {
continue
}
if !found || record.FinishedAt > latest.FinishedAt {
if !found || record.FinishedAt >= latest.FinishedAt {
latest = record
found = true
}
Expand Down
62 changes: 59 additions & 3 deletions cmd/crawlctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -38,9 +39,9 @@ func TestResolveVersion(t *testing.T) {
}

func TestLatestRecordForJobAggregatesRepoRuns(t *testing.T) {
records := map[string]scheduler.RunRecord{
"gitcrawl:openclaw/old": {Job: "gitcrawl", Repo: "openclaw/old", Status: "success", FinishedAt: "2026-05-22T10:00:00Z"},
"gitcrawl:openclaw/new": {Job: "gitcrawl", Repo: "openclaw/new", Status: "failed", FinishedAt: "2026-05-22T11:00:00Z"},
records := []scheduler.RunRecord{
{Job: "gitcrawl", Repo: "openclaw/old", Status: "success", FinishedAt: "2026-05-22T10:00:00Z"},
{Job: "gitcrawl", Repo: "openclaw/new", Status: "failed", FinishedAt: "2026-05-22T11:00:00Z"},
}
record, ok := latestRecordForJob(records, "gitcrawl")
if !ok {
Expand All @@ -51,6 +52,17 @@ func TestLatestRecordForJobAggregatesRepoRuns(t *testing.T) {
}
}

func TestLatestRecordForJobUsesLastEntryAtSameTime(t *testing.T) {
history := []scheduler.RunRecord{
{Job: "sync", Status: "failed", FinishedAt: "2026-05-22T10:00:00Z"},
{Job: "sync", Status: "success", FinishedAt: "2026-05-22T10:00:00Z"},
}
record, ok := latestRecordForJob(history, "sync")
if !ok || record.Status != "success" {
t.Fatalf("latest record = %+v, found = %v; want the later successful run", record, ok)
}
}

func TestStatusDoesNotUseAnotherJobsHistory(t *testing.T) {
for _, tc := range []struct {
name, job, recordedJob, repo string
Expand Down Expand Up @@ -91,6 +103,50 @@ func TestStatusDoesNotUseAnotherJobsHistory(t *testing.T) {
}
}

func TestStatusKeepsJobsWithCollidingHistoryKeys(t *testing.T) {
for _, reversed := range []bool{false, true} {
t.Run(fmt.Sprint(reversed), func(t *testing.T) {
configPath := filepath.Join(t.TempDir(), "crawlctl.toml")
cfg := scheduler.DefaultConfig()
for _, name := range []string{"sync", "sync:owner/repo"} {
cfg.Jobs[name] = scheduler.Job{Enabled: true, Command: []string{"unused"}}
}
paths, err := scheduler.Save(configPath, cfg, false)
if err != nil {
t.Fatal(err)
}
records := []scheduler.RunRecord{
{Job: "sync:owner/repo", Status: "failed", FinishedAt: "2026-05-22T10:00:00Z"},
{Job: "sync", Repo: "owner/repo", Status: "success", FinishedAt: "2026-05-22T11:00:00Z"},
}
if reversed {
records[0], records[1] = records[1], records[0]
}
var history bytes.Buffer
for _, record := range records {
if err := json.NewEncoder(&history).Encode(record); err != nil {
t.Fatal(err)
}
}
if err := os.MkdirAll(filepath.Dir(paths.History), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(paths.History, history.Bytes(), 0o600); err != nil {
t.Fatal(err)
}
var stdout bytes.Buffer
a := app{stdout: &stdout, stderr: ioDiscard{}, config: configPath}
if err := a.runStatus(nil); err != nil {
t.Fatal(err)
}
want := "sync: success 2026-05-22T11:00:00Z\nsync:owner/repo: failed 2026-05-22T10:00:00Z\n"
if stdout.String() != want {
t.Fatalf("status = %q, want %q", stdout.String(), want)
}
})
}
}

func TestRunJSONDoesNotIncludeProgress(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("uses POSIX echo")
Expand Down
5 changes: 5 additions & 0 deletions scheduler/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func discoverOne(ctx context.Context, binary string) App {
app.Error = err.Error()
return app
}
path, err = filepath.Abs(path)
if err != nil {
app.Error = err.Error()
return app
}
app.Found = true
app.Path = path
cmd := exec.CommandContext(ctx, path, "metadata", "--json")
Expand Down
35 changes: 35 additions & 0 deletions scheduler/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,38 @@ func TestDiscoverLegacyBinaryPaths(t *testing.T) {
}
}
}

func TestDiscoveredRelativeExecutableRunsFromAnotherDirectory(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("synthetic POSIX executable fixture")
}
binDir := t.TempDir()
executable := filepath.Join(binDir, "wacrawl")
if err := os.WriteFile(executable, []byte("#!/bin/sh\nif [ \"$1\" = metadata ]; then exit 2; fi\nprintf 'synthetic crawler ran\\n'\n"), 0o700); err != nil {
t.Fatal(err)
}
t.Chdir(binDir)
app := Discover(context.Background(), []string{"./wacrawl"})[0]
job, ok := DefaultJobForApp(app, nil)
if !app.Found || !app.Legacy || !ok {
t.Fatalf("relative discovery = %+v, job = %+v", app, job)
}
cfg := DefaultConfig()
cfg.Jobs = map[string]Job{"wacrawl": job}
paths, err := Save(filepath.Join(t.TempDir(), "crawlctl.toml"), cfg, false)
if err != nil {
t.Fatal(err)
}
t.Chdir(t.TempDir())
loaded, _, err := Load(paths.ConfigPath)
if err != nil {
t.Fatal(err)
}
records, err := Run(context.Background(), RunOptions{Config: loaded, Paths: paths, Names: []string{"wacrawl"}})
if err != nil || len(records) != 1 || records[0].Status != "success" {
t.Fatalf("relative selection from another directory: records = %+v, error = %v", records, err)
}
if app.Path != executable || loaded.Jobs["wacrawl"].Command[0] != executable {
t.Fatalf("selected executable not retained absolutely: app = %+v, command = %v", app, loaded.Jobs["wacrawl"].Command)
}
}
Loading