Something went wrong. Try again.
A Kubernetes operator that runs Claude Code sessions on long-horizon work
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394package operator_test
import ( "testing" "testing/synctest" "time"
"tangled.org/guid.foo/simmer/api/v1alpha1" "tangled.org/guid.foo/simmer/cluster" "tangled.org/guid.foo/simmer/dataplane" "tangled.org/guid.foo/simmer/internal/world")
// rang reports whether the bell holds a wake, and takes it.func (r *running) rang() bool { select { case <-r.bell.Rung(): return true default: return false }}
func (r *running) cadenceSessions() int { count := 0 for _, s := range world.List[v1alpha1.Session](r.w, cluster.Sessions) { if s.Spec.Origin == nil { count++ } } return count}
// A due Duty waits while an event waits for a Session. The Mandates'// pass runs before the Sessions' pass, so the pass that acknowledges// the events wakes the next pass at once, and that pass starts the// Duty.func TestADutyStartsOnceTheEventsItWaitedOnAreDone(t *testing.T) { synctest.Test(t, func(t *testing.T) { tune := world.Every(ops(), "tune", "24h") lastRun := time.Now().Add(-24*time.Hour + time.Minute).UTC().Truncate(time.Second) tune.Status.LastRunAt = &lastRun r := startWith(t, roomy(), ops(), triage(), tune) r.pass(t) r.pass(t) s := r.only(t) ref := dataplane.SessionRef{Namespace: "telemetry", Name: s.Metadata.Name} _, _ = r.store.Take(ref, 1) time.Sleep(2 * time.Minute) r.pass(t) held := r.cadenceSessions() r.succeed(t, s.Metadata.Name+"-1") r.rang()
r.pass(t) woke := r.rang() r.pass(t)
if held != 0 || !woke || r.cadenceSessions() != 1 { t.Errorf("%d cadence Sessions while the event waited, woke = %v, %d after; want none, a wake, and one", held, woke, r.cadenceSessions()) } })}
// A Mandate whose Duties are all cadences has no Session to wait on// the brake, so its due Duty, held by an Allowance with no reading,// must ask for the probe itself.func TestWorkHeldByAnAccountWithNoReadingProbesIt(t *testing.T) { tune := world.Mandate("telemetry", "tune", "upkeep") cases := []struct { name string mandate *v1alpha1.Mandate duty *v1alpha1.Duty }{ {"a Session that waits on the brake", ops(), triage()}, {"a due Duty on a cadence", tune, world.Every(tune, "tune", "24h")}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { synctest.Test(t, func(t *testing.T) { r := startWith(t, world.Account("personal"), c.mandate, c.duty)
r.pass(t) r.pass(t) r.pass(t)
if _, probed := world.Get[cluster.Job](r.w, cluster.ProbeJobs, world.Namespace, "simmer-probe-personal"); !probed { t.Error("no probe Job reads the Account, want one") } }) }) }}