package schedule import ( "testing" "time" ) // A pinned release (paused work, B1): Run now's leave on the one // connection the person was told it would use. Fable's scenario: Review // is held (Engineering ran on Claude), Codex is at its limit, Claude is // 85% used, and TensorX has budget. Unpinned leave takes TensorX (another // family, metered) and bills; pinned to Claude it runs on Claude, and // pinned to a connection that cannot take it, it holds: never another. func TestDecidePinned(t *testing.T) { eng := &Engineer{ID: "claude-1", Family: "claude", Account: "claude-1"} codex := sub("codex-1", "codex", 1.0) codex.State, codex.LimitedUntil = StateLimited, *at(9 * time.Hour) review := Step{Role: RoleReview, Engineer: eng, Release: "r"} conns := []Conn{sub("claude-1", "claude", 0.85), codex, meter("tensorx-1", 0, 0)} if d := Decide(in(review, conns...)); d.Connection != "tensorx-1" || d.Reason != ReasonMeteredRelease { t.Fatalf("unpinned leave: %+v", d) } if d := DecidePinned(in(review, conns...), "claude-1"); !d.Run || d.Connection != "claude-1" { t.Fatalf("pinned to Claude: %+v", d) } // Pinned to a connection that has no room even with leave (stale // reading: it filled since): held, not moved to TensorX. full := sub("claude-1", "claude", 1.0) full.State, full.LimitedUntil = StateLimited, *at(2 * time.Hour) if d := DecidePinned(in(review, full, codex, meter("tensorx-1", 0, 0)), "claude-1"); d.Run { t.Fatalf("pinned to a full connection ran: %+v", d) } // A kept metered session is not kept when the pin names another. fix := Step{Role: RoleEngineering, Kept: "tensorx-1", KeptModel: glm53.ID, Release: "r"} if d := DecidePinned(in(fix, sub("claude-1", "claude", 0.85), meter("tensorx-1", 0, 0)), "claude-1"); d.Connection != "claude-1" { t.Fatalf("pinned past a kept metered session: %+v", d) } // Pinned to a metered connection: it runs there with its model, the // bars applying. if d := DecidePinned(in(fix, sub("claude-1", "claude", 1.0), meter("tensorx-1", 0, 0)), "tensorx-1"); d.Connection != "tensorx-1" || d.Model != glm53.ID { t.Fatalf("pinned metered: %+v", d) } if d := DecidePinned(in(fix, meter("tensorx-1", 2_000_000, 0)), "tensorx-1"); d.Run || d.Reason != ReasonBudget { t.Fatalf("pinned metered at its budget: %+v", d) } // An avoided pin is not taken (failover keeps its bar). avoided := Step{Role: RoleEngineering, Release: "r", Avoid: []string{"claude-1"}} if d := DecidePinned(in(avoided, sub("claude-1", "claude", 0.1), meter("tensorx-1", 0, 0)), "claude-1"); d.Run { t.Fatalf("pinned to an avoided connection ran: %+v", d) } }