mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-18 09:54:35 +08:00
refactor: standardize code comments
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// ============================================================
|
||||
// 测试 QwenClient 创建和配置
|
||||
// Test QwenClient Creation and Configuration
|
||||
// ============================================================
|
||||
|
||||
func TestNewQwenClient_Default(t *testing.T) {
|
||||
@@ -16,13 +16,13 @@ func TestNewQwenClient_Default(t *testing.T) {
|
||||
t.Fatal("client should not be nil")
|
||||
}
|
||||
|
||||
// 类型断言检查
|
||||
// Type assertion check
|
||||
qwenClient, ok := client.(*QwenClient)
|
||||
if !ok {
|
||||
t.Fatal("client should be *QwenClient")
|
||||
}
|
||||
|
||||
// 验证默认值
|
||||
// Verify default values
|
||||
if qwenClient.Provider != ProviderQwen {
|
||||
t.Errorf("Provider should be '%s', got '%s'", ProviderQwen, qwenClient.Provider)
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func TestNewQwenClientWithOptions(t *testing.T) {
|
||||
|
||||
qwenClient := client.(*QwenClient)
|
||||
|
||||
// 验证自定义选项被应用
|
||||
// Verify custom options are applied
|
||||
if qwenClient.logger != mockLogger {
|
||||
t.Error("logger should be set from option")
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func TestNewQwenClientWithOptions(t *testing.T) {
|
||||
t.Error("MaxTokens should be 4000")
|
||||
}
|
||||
|
||||
// 验证 Qwen 默认值仍然保留
|
||||
// Verify Qwen default values are retained
|
||||
if qwenClient.Provider != ProviderQwen {
|
||||
t.Errorf("Provider should still be '%s'", ProviderQwen)
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func TestNewQwenClientWithOptions(t *testing.T) {
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 测试 SetAPIKey
|
||||
// Test SetAPIKey
|
||||
// ============================================================
|
||||
|
||||
func TestQwenClient_SetAPIKey(t *testing.T) {
|
||||
@@ -97,20 +97,20 @@ func TestQwenClient_SetAPIKey(t *testing.T) {
|
||||
|
||||
qwenClient := client.(*QwenClient)
|
||||
|
||||
// 测试设置 API Key(默认 URL 和 Model)
|
||||
// Test setting API Key (default URL and Model)
|
||||
qwenClient.SetAPIKey("sk-test-key-12345678", "", "")
|
||||
|
||||
if qwenClient.APIKey != "sk-test-key-12345678" {
|
||||
t.Errorf("APIKey should be 'sk-test-key-12345678', got '%s'", qwenClient.APIKey)
|
||||
}
|
||||
|
||||
// 验证日志记录
|
||||
// Verify logging
|
||||
logs := mockLogger.GetLogsByLevel("INFO")
|
||||
if len(logs) == 0 {
|
||||
t.Error("should have logged API key setting")
|
||||
}
|
||||
|
||||
// 验证 BaseURL 和 Model 保持默认
|
||||
// Verify BaseURL and Model remain default
|
||||
if qwenClient.BaseURL != DefaultQwenBaseURL {
|
||||
t.Error("BaseURL should remain default")
|
||||
}
|
||||
@@ -135,11 +135,11 @@ func TestQwenClient_SetAPIKey_WithCustomURL(t *testing.T) {
|
||||
t.Errorf("BaseURL should be '%s', got '%s'", customURL, qwenClient.BaseURL)
|
||||
}
|
||||
|
||||
// 验证日志记录
|
||||
// Verify logging
|
||||
logs := mockLogger.GetLogsByLevel("INFO")
|
||||
hasCustomURLLog := false
|
||||
for _, log := range logs {
|
||||
if log.Format == "🔧 [MCP] Qwen 使用自定义 BaseURL: %s" {
|
||||
if log.Format == "🔧 [MCP] Qwen using custom BaseURL: %s" {
|
||||
hasCustomURLLog = true
|
||||
break
|
||||
}
|
||||
@@ -165,11 +165,11 @@ func TestQwenClient_SetAPIKey_WithCustomModel(t *testing.T) {
|
||||
t.Errorf("Model should be '%s', got '%s'", customModel, qwenClient.Model)
|
||||
}
|
||||
|
||||
// 验证日志记录
|
||||
// Verify logging
|
||||
logs := mockLogger.GetLogsByLevel("INFO")
|
||||
hasCustomModelLog := false
|
||||
for _, log := range logs {
|
||||
if log.Format == "🔧 [MCP] Qwen 使用自定义 Model: %s" {
|
||||
if log.Format == "🔧 [MCP] Qwen using custom Model: %s" {
|
||||
hasCustomModelLog = true
|
||||
break
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func TestQwenClient_SetAPIKey_WithCustomModel(t *testing.T) {
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 测试集成功能
|
||||
// Test Integration Features
|
||||
// ============================================================
|
||||
|
||||
func TestQwenClient_CallWithMessages_Success(t *testing.T) {
|
||||
@@ -205,7 +205,7 @@ func TestQwenClient_CallWithMessages_Success(t *testing.T) {
|
||||
t.Errorf("expected 'Qwen AI response', got '%s'", result)
|
||||
}
|
||||
|
||||
// 验证请求
|
||||
// Verify request
|
||||
requests := mockHTTP.GetRequests()
|
||||
if len(requests) != 1 {
|
||||
t.Fatalf("expected 1 request, got %d", len(requests))
|
||||
@@ -213,19 +213,19 @@ func TestQwenClient_CallWithMessages_Success(t *testing.T) {
|
||||
|
||||
req := requests[0]
|
||||
|
||||
// 验证 URL
|
||||
// Verify URL
|
||||
expectedURL := DefaultQwenBaseURL + "/chat/completions"
|
||||
if req.URL.String() != expectedURL {
|
||||
t.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL.String())
|
||||
}
|
||||
|
||||
// 验证 Authorization header
|
||||
// Verify Authorization header
|
||||
authHeader := req.Header.Get("Authorization")
|
||||
if authHeader != "Bearer sk-test-key" {
|
||||
t.Errorf("expected 'Bearer sk-test-key', got '%s'", authHeader)
|
||||
}
|
||||
|
||||
// 验证 Content-Type
|
||||
// Verify Content-Type
|
||||
if req.Header.Get("Content-Type") != "application/json" {
|
||||
t.Error("Content-Type should be application/json")
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func TestQwenClient_Timeout(t *testing.T) {
|
||||
t.Errorf("expected timeout 30s, got %v", qwenClient.httpClient.Timeout)
|
||||
}
|
||||
|
||||
// 测试 SetTimeout
|
||||
// Test SetTimeout
|
||||
client.SetTimeout(60 * time.Second)
|
||||
|
||||
if qwenClient.httpClient.Timeout != 60*time.Second {
|
||||
@@ -251,19 +251,19 @@ func TestQwenClient_Timeout(t *testing.T) {
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 测试 hooks 机制
|
||||
// Test hooks Mechanism
|
||||
// ============================================================
|
||||
|
||||
func TestQwenClient_HooksIntegration(t *testing.T) {
|
||||
client := NewQwenClientWithOptions()
|
||||
qwenClient := client.(*QwenClient)
|
||||
|
||||
// 验证 hooks 指向 qwenClient 自己(实现多态)
|
||||
// Verify hooks point to qwenClient itself (implements polymorphism)
|
||||
if qwenClient.hooks != qwenClient {
|
||||
t.Error("hooks should point to qwenClient for polymorphism")
|
||||
}
|
||||
|
||||
// 验证 buildUrl 使用 Qwen 配置
|
||||
// Verify buildUrl uses Qwen configuration
|
||||
url := qwenClient.buildUrl()
|
||||
expectedURL := DefaultQwenBaseURL + "/chat/completions"
|
||||
if url != expectedURL {
|
||||
|
||||
Reference in New Issue
Block a user