Files
archie/internal/app/controlplane/schedules_test.go
T
sam 0e94196052 refactor(scheduling): delete the legacy file-backed cronstore
The schedules feature no longer runs on it: jobs live in the state store
as the schedules control-plane document, read and written through the
control-plane client (scheduleResourceStore), and the legacy jobs.json
migration into that document has run its course. What remained of
internal/infrastructure/cronstore was 1,600 lines of file store, OS-level
cross-process locking and schema-versioned JSON envelope -- plus the
schedule vocabulary held hostage inside it.

The vocabulary moves to internal/domain/scheduling, which is where
migration-decisions already said a schedules vocabulary belongs: a domain
vocabulary package must not import infrastructure. JobSpec, Target,
Payload, the kind constants, Schedule and Duration move unchanged -- same
wire shape, same JSON tags -- with the two sentinel errors callers
matched outside the package (ErrJobNotFound, ErrScheduleUnsupported) and
ErrInvalidSpec, which the schedule arithmetic itself raises. The store's
own sentinels die with the store.

The legacy migration path (migrateLegacySchedules, readLegacyJobs) goes
with it: its only dependency was cronstore.Open, and its work is done.

crondelivery keeps its consumer-owned contracts; the compile-time
assertions that pinned *cronstore.Store move to the production
implementation, scheduleResourceStore, in internal/app/archied. The
package's fixtures swap the real file store for an in-memory one with
the same Get/MarkRun/Due semantics, so the run-recording acceptance test
still asserts against real schedule arithmetic.

A future storage backend (PocketBase) implements the same vocabulary.
2026-09-23 01:40:22 +10:00

39 lines
1.1 KiB
Go

package controlplane
import (
"encoding/json"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/domain/scheduling"
)
func TestScheduleDefinitionComputesFirstRunAndRejectsDuplicateIDs(t *testing.T) {
t.Parallel()
definition := scheduleDefinition()
jobs := []scheduling.JobSpec{{ID: "daily", Kind: scheduling.KindWorkflow, Schedule: scheduling.Schedule{Kind: scheduling.ScheduleInterval, Interval: scheduling.Duration(time.Hour)}}}
input, err := json.Marshal(jobs)
if err != nil {
t.Fatal(err)
}
got, err := definition.Decode(input)
if err != nil {
t.Fatal(err)
}
var normalized []scheduling.JobSpec
if err := json.Unmarshal(got, &normalized); err != nil {
t.Fatal(err)
}
if len(normalized) != 1 || normalized[0].NextRun.IsZero() || normalized[0].Created.IsZero() || normalized[0].Updated.IsZero() {
t.Fatalf("normalized schedules = %+v", normalized)
}
duplicate, err := json.Marshal(append(jobs, jobs[0]))
if err != nil {
t.Fatal(err)
}
if _, err := definition.Decode(duplicate); err == nil {
t.Fatal("duplicate schedule IDs accepted")
}
}