| 1 | package schedule |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | // A pinned release (paused work, B1): Run now's leave on the one |
| 9 | // connection the person was told it would use. Fable's scenario: Review |
| 10 | // is held (Engineering ran on Claude), Codex is at its limit, Claude is |
| 11 | // 85% used, and TensorX has budget. Unpinned leave takes TensorX (another |
| 12 | // family, metered) and bills; pinned to Claude it runs on Claude, and |
| 13 | // pinned to a connection that cannot take it, it holds: never another. |
| 14 | func TestDecidePinned(t *testing.T) { |
| 15 | eng := &Engineer{ID: "claude-1", Family: "claude", Account: "claude-1"} |
| 16 | codex := sub("codex-1", "codex", 1.0) |
| 17 | codex.State, codex.LimitedUntil = StateLimited, *at(9 * time.Hour) |
| 18 | review := Step{Role: RoleReview, Engineer: eng, Release: "r"} |
| 19 | conns := []Conn{sub("claude-1", "claude", 0.85), codex, meter("tensorx-1", 0, 0)} |
| 20 | if d := Decide(in(review, conns...)); d.Connection != "tensorx-1" || d.Reason != ReasonMeteredRelease { |
| 21 | t.Fatalf("unpinned leave: %+v", d) |
| 22 | } |
| 23 | if d := DecidePinned(in(review, conns...), "claude-1"); !d.Run || d.Connection != "claude-1" { |
| 24 | t.Fatalf("pinned to Claude: %+v", d) |
| 25 | } |
| 26 | // Pinned to a connection that has no room even with leave (stale |
| 27 | // reading: it filled since): held, not moved to TensorX. |
| 28 | full := sub("claude-1", "claude", 1.0) |
| 29 | full.State, full.LimitedUntil = StateLimited, *at(2 * time.Hour) |
| 30 | if d := DecidePinned(in(review, full, codex, meter("tensorx-1", 0, 0)), "claude-1"); d.Run { |
| 31 | t.Fatalf("pinned to a full connection ran: %+v", d) |
| 32 | } |
| 33 | // A kept metered session is not kept when the pin names another. |
| 34 | fix := Step{Role: RoleEngineering, Kept: "tensorx-1", KeptModel: glm53.ID, Release: "r"} |
| 35 | if d := DecidePinned(in(fix, sub("claude-1", "claude", 0.85), meter("tensorx-1", 0, 0)), "claude-1"); d.Connection != "claude-1" { |
| 36 | t.Fatalf("pinned past a kept metered session: %+v", d) |
| 37 | } |
| 38 | // Pinned to a metered connection: it runs there with its model, the |
| 39 | // bars applying. |
| 40 | 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 { |
| 41 | t.Fatalf("pinned metered: %+v", d) |
| 42 | } |
| 43 | if d := DecidePinned(in(fix, meter("tensorx-1", 2_000_000, 0)), "tensorx-1"); d.Run || d.Reason != ReasonBudget { |
| 44 | t.Fatalf("pinned metered at its budget: %+v", d) |
| 45 | } |
| 46 | // An avoided pin is not taken (failover keeps its bar). |
| 47 | avoided := Step{Role: RoleEngineering, Release: "r", Avoid: []string{"claude-1"}} |
| 48 | if d := DecidePinned(in(avoided, sub("claude-1", "claude", 0.1), meter("tensorx-1", 0, 0)), "claude-1"); d.Run { |
| 49 | t.Fatalf("pinned to an avoided connection ran: %+v", d) |
| 50 | } |
| 51 | } |
| 52 | |