package schedule import ( "context" "encoding/json" "testing" "github.com/carlosframework/platform/internal/release" ) // The wire shape is additive: an object written before this field existed // must still parse, and read back as false. func TestStatusWithoutHoldsAwakeStillParses(t *testing.T) { raw := []byte(`{"schema":1,"host":"h","box":"b","reported_at":"2026-08-30T21:40:05Z","timers":[{"name":"sweep","kind":"schedule","spec":"every 5m","path":"/jobs/sweep","next_at":1788126300}]}`) var st Status if err := json.Unmarshal(raw, &st); err != nil { t.Fatalf("unmarshal a pre-holds_awake status: %v", err) } if len(st.Timers) != 1 || st.Timers[0].HoldsAwake { t.Errorf("HoldsAwake = %v, want false for an object written before the field existed", st.Timers[0].HoldsAwake) } } func TestWriteAndListStatus(t *testing.T) { ctx := context.Background() st := release.NewDirStore(t.TempDir()) b := Status{Host: "b.bab.oncarlos.com", Box: "box1", ReportedAt: "2026-08-23T22:00:00Z", Timers: []TimerStatus{{Name: "sync", Kind: KindSchedule, Spec: "every 6h0m0s", Path: "/jobs/sync", NextAt: 100}}} a := Status{Host: "a.bab.oncarlos.com", Box: "box1", ReportedAt: "2026-08-23T22:00:00Z", Unsupported: "unit-backed instance"} for _, s := range []Status{b, a, b} { // the rewrite must not conflict if err := WriteStatus(ctx, st, "bab", "app", s); err != nil { t.Fatal(err) } } got, err := ListStatus(ctx, st, "bab", "app") if err != nil { t.Fatal(err) } if len(got) != 2 || got[0].Host != a.Host || got[1].Timers[0].Name != "sync" || got[0].Schema != 1 { t.Fatalf("list = %+v", got) } if got[0].Timers == nil { t.Fatal("timers must marshal as [] not null — the CLI ranges over it") } } func TestListStatusEmptyPrefix(t *testing.T) { got, err := ListStatus(context.Background(), release.NewDirStore(t.TempDir()), "bab", "app") if err != nil || len(got) != 0 { t.Fatalf("%v %v", got, err) } }