package minimax import ( "net/http" "testing" "time" ) // MiniMax 有双模式 (ModeAnthropic vs ModeNative|OpenAI), 两个底层 client 独立应用超时, // 所以本组测试显式覆盖两条路径, 不 share 代码 - 否则 ModeAnthropic 分支回归风险不可见. func TestNew_DefaultTimeout_NativeMode(t *testing.T) { p := New(Config{APIKey: "test-key", Mode: ModeNative}) assertResponseHeaderTimeout(t, p.wireClient.HTTPClient(), defaultTimeout, "wireClient/Native default") } func TestNew_DefaultTimeout_AnthropicMode(t *testing.T) { p := New(Config{APIKey: "test-key", Mode: ModeAnthropic}) assertResponseHeaderTimeout(t, p.anthroClient.HTTPClient(), defaultTimeout, "anthroClient/Anthropic default") } func TestNew_ConfigTimeout_NativeMode(t *testing.T) { want := 42 * time.Second p := New(Config{APIKey: "test-key", Mode: ModeNative, Timeout: want}) assertResponseHeaderTimeout(t, p.wireClient.HTTPClient(), want, "wireClient/Native explicit") } func TestNew_ConfigTimeout_AnthropicMode(t *testing.T) { want := 42 * time.Second p := New(Config{APIKey: "test-key", Mode: ModeAnthropic, Timeout: want}) assertResponseHeaderTimeout(t, p.anthroClient.HTTPClient(), want, "anthroClient/Anthropic explicit") } func TestNew_HTTPClientOverridesTimeout_NativeMode(t *testing.T) { consumerTimeout := 7 * time.Second consumerClient := &http.Client{ Transport: &http.Transport{ResponseHeaderTimeout: consumerTimeout}, } p := New(Config{ APIKey: "test-key", Mode: ModeNative, HTTPClient: consumerClient, Timeout: 999 * time.Second, // must be ignored }) if p.wireClient.HTTPClient() != consumerClient { t.Errorf("wireClient not using consumer's HTTPClient") } assertResponseHeaderTimeout(t, p.wireClient.HTTPClient(), consumerTimeout, "wireClient/Native HTTPClient override") } func TestNew_HTTPClientOverridesTimeout_AnthropicMode(t *testing.T) { consumerTimeout := 7 * time.Second consumerClient := &http.Client{ Transport: &http.Transport{ResponseHeaderTimeout: consumerTimeout}, } p := New(Config{ APIKey: "test-key", Mode: ModeAnthropic, HTTPClient: consumerClient, Timeout: 999 * time.Second, // must be ignored }) if p.anthroClient.HTTPClient() != consumerClient { t.Errorf("anthroClient not using consumer's HTTPClient") } assertResponseHeaderTimeout(t, p.anthroClient.HTTPClient(), consumerTimeout, "anthroClient/Anthropic HTTPClient override") } func assertResponseHeaderTimeout(t *testing.T, hc *http.Client, want time.Duration, label string) { t.Helper() if hc == nil { t.Fatalf("%s: nil http.Client", label) } transport, ok := hc.Transport.(*http.Transport) if !ok { t.Fatalf("%s: Transport is %T, want *http.Transport", label, hc.Transport) } if transport.ResponseHeaderTimeout != want { t.Errorf("%s: ResponseHeaderTimeout = %v, want %v", label, transport.ResponseHeaderTimeout, want) } }