picoclaw/internal/fantasy/providertests/azure_test.go
ZanzyTHEbar 906d11612d test: modernize test suite with t.Context() and t.Parallel()
Apply two idiomatic Go test improvements across all 113 test files in the
codebase:

1. Replace context.Background() with t.Context() in test functions.
   t.Context() (added in Go 1.21) returns a context that is automatically
   cancelled when the test finishes, preventing goroutine leaks and making
   test teardown deterministic without manual cancel calls.

2. Add t.Parallel() to independent test functions.
   Parallel tests run concurrently within a package, significantly reducing
   total test suite wall-clock time and surfacing data races that sequential
   execution would hide.

Also fix TestStateStore_AddTransition: add "UpdatedAt" to the
cmpopts.IgnoreFields list — the DB now populates UpdatedAt on insert,
causing the zero-value comparison to fail.

Packages affected (113 files):
- eval/go_evals
- internal/fantasy (agent, json, jsonrepair, providers/*, providertests/*, schema, tool_runtime_*)
- pkg/agent (integration, kv_delegate, loop, offloading_runtime, state_store, tool_result_search)
- pkg/auth (oauth, pkce, store)
- pkg/cache, pkg/channels, pkg/config, pkg/cron
- pkg/fantasy (adapter, convert)
- pkg/heartbeat, pkg/ids
- pkg/itr (commands, dag/*, fb_codec, wasm/*)
- pkg/logger
- pkg/memory (dag/*, delegate/*, integration, kernel_contract, migrate_sessions, observation, store/*)
- pkg/migrate
- pkg/rlm (engine, fanout, rope, strategy)
- pkg/runtime
- pkg/security (jsonextract, redact, securebus/*, urlguard, vault, zkp)
- pkg/session, pkg/skills, pkg/state, pkg/sync
- pkg/tools (agentic_map, call, dag, edit, filesystem, focus, llm_map, map_*, message, obligation, registry_progressive, result, retrieval, search, shell, skills, spawn, subagent_*, toolloop, web)
- pkg/worker
2026-02-21 21:08:54 +00:00

78 lines
2.4 KiB
Go

package providertests
import (
"cmp"
"net/http"
"os"
"testing"
"charm.land/fantasy"
"charm.land/fantasy/providers/azure"
"charm.land/fantasy/providers/openai"
"charm.land/x/vcr"
"github.com/stretchr/testify/require"
)
const defaultBaseURL = "https://fantasy-playground-resource.openai.azure.com"
func TestAzureCommon(t *testing.T) {
t.Parallel()
testCommon(t, []builderPair{
{"azure-o4-mini", builderAzureO4Mini, nil, nil},
{"azure-gpt-5-mini", builderAzureGpt5Mini, nil, nil},
{"azure-grok-3-mini", builderAzureGrok3Mini, nil, nil},
})
}
func TestAzureThinking(t *testing.T) {
t.Parallel()
opts := fantasy.ProviderOptions{
openai.Name: &openai.ProviderOptions{
ReasoningEffort: openai.ReasoningEffortOption(openai.ReasoningEffortHigh),
},
}
testThinking(t, []builderPair{
{"azure-gpt-5-mini", builderAzureGpt5Mini, opts, nil},
{"azure-grok-3-mini", builderAzureGrok3Mini, opts, nil},
}, testAzureThinking)
}
func testAzureThinking(t *testing.T, result *fantasy.AgentResult) {
require.Greater(t, result.Response.Usage.ReasoningTokens, int64(0), "expected reasoning tokens, got none")
}
func builderAzureO4Mini(t *testing.T, r *vcr.Recorder) (fantasy.LanguageModel, error) {
provider, err := azure.New(
azure.WithBaseURL(cmp.Or(os.Getenv("FANTASY_AZURE_BASE_URL"), defaultBaseURL)),
azure.WithAPIKey(cmp.Or(os.Getenv("FANTASY_AZURE_API_KEY"), "(missing)")),
azure.WithHTTPClient(&http.Client{Transport: r}),
)
if err != nil {
return nil, err
}
return provider.LanguageModel(t.Context(), "o4-mini")
}
func builderAzureGpt5Mini(t *testing.T, r *vcr.Recorder) (fantasy.LanguageModel, error) {
provider, err := azure.New(
azure.WithBaseURL(cmp.Or(os.Getenv("FANTASY_AZURE_BASE_URL"), defaultBaseURL)),
azure.WithAPIKey(cmp.Or(os.Getenv("FANTASY_AZURE_API_KEY"), "(missing)")),
azure.WithHTTPClient(&http.Client{Transport: r}),
)
if err != nil {
return nil, err
}
return provider.LanguageModel(t.Context(), "gpt-5-mini")
}
func builderAzureGrok3Mini(t *testing.T, r *vcr.Recorder) (fantasy.LanguageModel, error) {
provider, err := azure.New(
azure.WithBaseURL(cmp.Or(os.Getenv("FANTASY_AZURE_BASE_URL"), defaultBaseURL)),
azure.WithAPIKey(cmp.Or(os.Getenv("FANTASY_AZURE_API_KEY"), "(missing)")),
azure.WithHTTPClient(&http.Client{Transport: r}),
)
if err != nil {
return nil, err
}
return provider.LanguageModel(t.Context(), "grok-3-mini")
}