30 lines
1.7 KiB
Go
30 lines
1.7 KiB
Go
package runtime
|
|
|
|
import "testing"
|
|
|
|
func TestMaterialFinalReserveDecision(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
state materialBudgetState
|
|
wantFinal, wantStop bool
|
|
}{
|
|
{"first request", materialBudgetState{Limit: 30000}, false, false},
|
|
{"two saved checkpoints", materialBudgetState{Limit: 30000, Used: 16000, LastPrompt: 5000, OutputCap: 4000, SavedCheckpoints: 2, Responses: 2, UsageKnown: true}, true, false},
|
|
{"one checkpoint and limited remainder", materialBudgetState{Limit: 30000, Used: 15000, LastPrompt: 5000, OutputCap: 4000, SavedCheckpoints: 1, Responses: 1, UsageKnown: true}, true, false},
|
|
{"enough for another checkpoint", materialBudgetState{Limit: 30000, Used: 6000, LastPrompt: 3000, OutputCap: 4000, SavedCheckpoints: 1, Responses: 1, UsageKnown: true}, false, false},
|
|
{"final prompt cannot fit", materialBudgetState{Limit: 30000, Used: 27000, LastPrompt: 8000, OutputCap: 4000, SavedCheckpoints: 1, Responses: 2, UsageKnown: true}, false, true},
|
|
// Old A01's three material responses totalled 35,632 tokens; the third
|
|
// consumed 14,231. This offline check would stop before that third call.
|
|
{"old A01 before third request", materialBudgetState{Limit: 30000, Used: 35632 - 14231, LastPrompt: 10134, OutputCap: 4000, SavedCheckpoints: 1, Responses: 2, UsageKnown: true}, false, true},
|
|
{"provider usage missing", materialBudgetState{Limit: 30000, Responses: 1}, false, true},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
final, stop := materialFinalDecision(tc.state)
|
|
if final != tc.wantFinal || stop != tc.wantStop {
|
|
t.Fatalf("final=%v stop=%v; want final=%v stop=%v", final, stop, tc.wantFinal, tc.wantStop)
|
|
}
|
|
})
|
|
}
|
|
}
|