Fail the paid eval fast when the route contract is not attached #229
@@ -160,6 +160,52 @@ func TestEvalRouteContractAttachedOnlyWhenProductionRuleAdmits(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func evalRouteContractModels(t *testing.T, contract any) map[string]any {
|
||||||
|
t.Helper()
|
||||||
|
route := map[string]any{"model": evalRouteContractModel, "baseUrl": evalRouteContractBase, "apiKey": "fixture-key"}
|
||||||
|
if contract != nil {
|
||||||
|
route["routeContractEOF"] = contract
|
||||||
|
}
|
||||||
|
models, ok := evalModelSettings(route)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("route file rejected")
|
||||||
|
}
|
||||||
|
return models
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalRouteContractFailFastWhenConfiguredButNotAttached(t *testing.T) {
|
||||||
|
digest := agentllm.RouteContractIdentity(evalRouteContractModel, evalRouteContractBase)
|
||||||
|
matching := map[string]any{"model": evalRouteContractModel, "baseUrl": evalRouteContractBase, "identitySha256": digest}
|
||||||
|
client, _ := evalRouteContractClient(t, matching)
|
||||||
|
if !evalRouteContractAttached(evalRouteContractModels(t, matching), client) {
|
||||||
|
t.Fatal("matching route contract must be reported attached")
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, contract := range map[string]map[string]any{
|
||||||
|
"digest mismatch": {"model": evalRouteContractModel, "baseUrl": evalRouteContractBase, "identitySha256": strings.Repeat("0", 64)},
|
||||||
|
"other model": {"model": "other-model", "baseUrl": evalRouteContractBase, "identitySha256": agentllm.RouteContractIdentity("other-model", evalRouteContractBase)},
|
||||||
|
"other base": {"model": evalRouteContractModel, "baseUrl": "https://other.example.com/v1", "identitySha256": agentllm.RouteContractIdentity(evalRouteContractModel, "https://other.example.com/v1")},
|
||||||
|
"missing digest": {"model": evalRouteContractModel, "baseUrl": evalRouteContractBase},
|
||||||
|
"empty object": {},
|
||||||
|
} {
|
||||||
|
client, _ := evalRouteContractClient(t, contract)
|
||||||
|
if evalRouteContractAttached(evalRouteContractModels(t, contract), client) {
|
||||||
|
t.Fatalf("%s: configured but unattached route contract must fail fast", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client, _ = evalRouteContractClient(t, nil)
|
||||||
|
if !evalRouteContractAttached(evalRouteContractModels(t, nil), client) {
|
||||||
|
t.Fatal("route without routeContractEOF must keep running without a contract")
|
||||||
|
}
|
||||||
|
if !evalRouteContractAttached(map[string]any{"chat": map[string]any{}}, nil) {
|
||||||
|
t.Fatal("absent routeContractEOF must not depend on the client")
|
||||||
|
}
|
||||||
|
if evalRouteContractAttached(map[string]any{"routeContractEOF": map[string]any{}}, nil) {
|
||||||
|
t.Fatal("configured routeContractEOF without a client must fail fast")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEvalRouteContractRejectsMalformedRouteFileContract(t *testing.T) {
|
func TestEvalRouteContractRejectsMalformedRouteFileContract(t *testing.T) {
|
||||||
for _, contract := range []any{"text", map[string]any{"model": 1, "baseUrl": evalRouteContractBase, "identitySha256": "x"}} {
|
for _, contract := range []any{"text", map[string]any{"model": 1, "baseUrl": evalRouteContractBase, "identitySha256": "x"}} {
|
||||||
route := map[string]any{"model": evalRouteContractModel, "baseUrl": evalRouteContractBase, "routeContractEOF": contract}
|
route := map[string]any{"model": evalRouteContractModel, "baseUrl": evalRouteContractBase, "routeContractEOF": contract}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ func TestServeWorkCheckpointEval(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer st.Close()
|
defer st.Close()
|
||||||
config := evalFixtureSettings()
|
config := evalFixtureSettings()
|
||||||
var modelRoute map[string]any
|
var modelRoute, modelSettings map[string]any
|
||||||
if mode == "model" {
|
if mode == "model" {
|
||||||
raw, e := os.ReadFile(os.Getenv("WORK_CHECKPOINT_ROUTE_FILE"))
|
raw, e := os.ReadFile(os.Getenv("WORK_CHECKPOINT_ROUTE_FILE"))
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@@ -212,6 +212,7 @@ func TestServeWorkCheckpointEval(t *testing.T) {
|
|||||||
route["fallbacks"] = ""
|
route["fallbacks"] = ""
|
||||||
config["models"] = models
|
config["models"] = models
|
||||||
modelRoute = route
|
modelRoute = route
|
||||||
|
modelSettings = models
|
||||||
}
|
}
|
||||||
// The isolated fixture owns its startup configuration; managed model/mock
|
// The isolated fixture owns its startup configuration; managed model/mock
|
||||||
// settings use the same trusted system layer as production bootstrap.
|
// settings use the same trusted system layer as production bootstrap.
|
||||||
@@ -245,7 +246,11 @@ func TestServeWorkCheckpointEval(t *testing.T) {
|
|||||||
front := &runtime.LLMRunner{Prompts: promptSvc}
|
front := &runtime.LLMRunner{Prompts: promptSvc}
|
||||||
sub := &runtime.SubLLMRunner{Prompts: promptSvc}
|
sub := &runtime.SubLLMRunner{Prompts: promptSvc}
|
||||||
if mode == "model" {
|
if mode == "model" {
|
||||||
stream := evalProviderStreamWithSettings(modelRoute, settingSvc.Effective(store.OwnerDefault, ""), dir)
|
client := evalProviderClient(modelRoute, settingSvc.Effective(store.OwnerDefault, ""))
|
||||||
|
if !evalRouteContractAttached(modelSettings, client) {
|
||||||
|
t.Fatal("route contract configured but not attached")
|
||||||
|
}
|
||||||
|
stream := evalProviderStreamWithProvider(client.Stream, dir)
|
||||||
if guardedA01 {
|
if guardedA01 {
|
||||||
stream = limitExtraA01Runs(st, stream)
|
stream = limitExtraA01Runs(st, stream)
|
||||||
}
|
}
|
||||||
@@ -467,6 +472,15 @@ func evalProviderClient(route map[string]any, eff core.EffectiveSettings) *agent
|
|||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// evalRouteContractAttached reports false when the route file configured a
|
||||||
|
// routeContractEOF object that production's rule did not attach to the client.
|
||||||
|
func evalRouteContractAttached(models map[string]any, client *agentllm.Client) bool {
|
||||||
|
if _, configured := models["routeContractEOF"]; !configured {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return client != nil && client.RouteContract != nil
|
||||||
|
}
|
||||||
|
|
||||||
func evalProviderStream(route map[string]any, dir string) agentllm.StreamFunc {
|
func evalProviderStream(route map[string]any, dir string) agentllm.StreamFunc {
|
||||||
return evalProviderStreamWithSettings(route, core.EffectiveSettings{}, dir)
|
return evalProviderStreamWithSettings(route, core.EffectiveSettings{}, dir)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user