package ai import ( "bytes" "testing" ) func TestTaskFieldsWinOverSameDifferentAndNullParamValues(t *testing.T) { for _, name := range []string{"same", "different", "null"} { t.Run(name, func(t *testing.T) { task, providers := currentFixture(t, "full_ai") canonical, err := Bind(task, providers) if err != nil { t.Fatal(err) } task = changeCurrentAgent(t, task, func(agent map[string]any) { asrModel, llmModel, voice := any("ignored-model"), any("ignored-model"), any("ignored-voice") if name == "same" { asrModel, llmModel, voice = canonical.ASR.Model, canonical.LLM.Model, canonical.TTS.Voice } else if name == "null" { asrModel, llmModel, voice = nil, nil, nil } agent["asr"].(map[string]any)["params"] = map[string]any{"model_name": asrModel, "reqid": "ignored-id", "sequence": 99, "opaque": false} agent["llm"].(map[string]any)["params"] = map[string]any{"model": llmModel, "messages": "ignored-messages", "opaque": false} agent["tts"].(map[string]any)["params"] = map[string]any{"voice": voice, "opaque": false} }) original := append([]byte(nil), task.Raw...) bound, err := Bind(task, providers) if err != nil { t.Fatalf("duplicate opaque params must not reject the task: %v", err) } if bound.ASR.Model != canonical.ASR.Model || bound.LLM.Model != canonical.LLM.Model || bound.TTS.Voice != canonical.TTS.Voice { t.Fatal("params changed canonical task fields") } if string(bound.ASR.Params["opaque"]) != "false" || string(bound.LLM.Params["opaque"]) != "false" || string(bound.TTS.Params["opaque"]) != "false" { t.Fatal("nonconflicting opaque params were changed") } if !bytes.Equal(original, task.Raw) { t.Fatal("binding changed the approved task snapshot") } }) } }