Skip to content

Commit b2141a9

Browse files
author
QTom
committed
fix(ci): 修复 golangci-lint 和 API 合约测试失败
- 修复 errcheck: singleflight 返回值类型断言添加 ok 检查 - 修复 gofmt: 格式化 setting_service.go 和 claude_code_validator_test.go - 修复 TestAPIContracts: 在 GET /admin/settings 期望中添加 min_claude_code_version 字段
1 parent 4280aca commit b2141a9

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

backend/internal/server/api_contract_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ func TestAPIContracts(t *testing.T) {
511511
"home_content": "",
512512
"hide_ccs_import_button": false,
513513
"purchase_subscription_enabled": false,
514-
"purchase_subscription_url": ""
514+
"purchase_subscription_url": "",
515+
"min_claude_code_version": ""
515516
}
516517
}`,
517518
},

backend/internal/service/claude_code_validator_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ func TestExtractVersion(t *testing.T) {
6565
}{
6666
{"claude-cli/2.1.22 (darwin; arm64)", "2.1.22"},
6767
{"claude-cli/1.0.0", "1.0.0"},
68-
{"Claude-CLI/3.10.5 (linux; x86_64)", "3.10.5"}, // 大小写不敏感
69-
{"curl/8.0.0", ""}, // 非 Claude CLI
70-
{"", ""}, // 空字符串
71-
{"claude-cli/", ""}, // 无版本号
72-
{"claude-cli/2.1.22-beta", "2.1.22"}, // 带后缀仍提取主版本号
68+
{"Claude-CLI/3.10.5 (linux; x86_64)", "3.10.5"}, // 大小写不敏感
69+
{"curl/8.0.0", ""}, // 非 Claude CLI
70+
{"", ""}, // 空字符串
71+
{"claude-cli/", ""}, // 无版本号
72+
{"claude-cli/2.1.22-beta", "2.1.22"}, // 带后缀仍提取主版本号
7373
}
7474
for _, tt := range tests {
7575
got := v.ExtractVersion(tt.ua)
@@ -82,14 +82,14 @@ func TestCompareVersions(t *testing.T) {
8282
a, b string
8383
want int
8484
}{
85-
{"2.1.0", "2.1.0", 0}, // 相等
86-
{"2.1.1", "2.1.0", 1}, // patch 更大
87-
{"2.0.0", "2.1.0", -1}, // minor 更小
88-
{"3.0.0", "2.99.99", 1}, // major 更大
89-
{"1.0.0", "2.0.0", -1}, // major 更小
90-
{"0.0.1", "0.0.0", 1}, // patch 差异
91-
{"", "1.0.0", -1}, // 空字符串 vs 正常版本
92-
{"v2.1.0", "2.1.0", 0}, // v 前缀处理
85+
{"2.1.0", "2.1.0", 0}, // 相等
86+
{"2.1.1", "2.1.0", 1}, // patch 更大
87+
{"2.0.0", "2.1.0", -1}, // minor 更小
88+
{"3.0.0", "2.99.99", 1}, // major 更大
89+
{"1.0.0", "2.0.0", -1}, // major 更小
90+
{"0.0.1", "0.0.0", 1}, // patch 差异
91+
{"", "1.0.0", -1}, // 空字符串 vs 正常版本
92+
{"v2.1.0", "2.1.0", 0}, // v 前缀处理
9393
}
9494
for _, tt := range tests {
9595
got := CompareVersions(tt.a, tt.b)

backend/internal/service/setting_service.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ func (s *SettingService) GetMinClaudeCodeVersion(ctx context.Context) string {
891891
}
892892
}
893893
// singleflight: 同一时刻只有一个 goroutine 查询 DB,其余复用结果
894-
result, _, _ := minVersionSF.Do("min_version", func() (interface{}, error) {
894+
result, _, _ := minVersionSF.Do("min_version", func() (any, error) {
895895
// 二次检查,避免排队的 goroutine 重复查询
896896
if cached, ok := minVersionCache.Load().(*cachedMinVersion); ok {
897897
if time.Now().UnixNano() < cached.expiresAt {
@@ -917,7 +917,10 @@ func (s *SettingService) GetMinClaudeCodeVersion(ctx context.Context) string {
917917
})
918918
return value, nil
919919
})
920-
return result.(string)
920+
if s, ok := result.(string); ok {
921+
return s
922+
}
923+
return ""
921924
}
922925

923926
// SetStreamTimeoutSettings 设置流超时处理配置

0 commit comments

Comments
 (0)