feat(user-secret): 密钥设置支持 LLM 渠道与代理供应商切换
- 用户密钥新增 channel 列(V180):LLM 行存渠道 longtaitou/t8star,代理行存供应商 qingguo/jikip;存量与新建默认均回填 t8star/jikip(默认仍走贞贞与极客,手动可切) - 外观专利/货源查询按任务归属用户的密钥渠道路由 LLM 主机(渠道经 SecretUsageContext 下到工作线程,不逐层改签名);切到龙抬头时模型映射 gemini-3.1-flash-lite 并补 enable_thinking + thinking_budget=medium(对齐贞贞现网口径),检测链路刻意不思考 - 代理检测按供应商解析:青果 code 为字符串、隧道端点支持 域名:端口、 NO_AVAILABLE_CHANNEL 归为可重试;青果只验提取成功(账密只在客户端本地) - 密钥设置页:每个模块加渠道分段选择、代理卡加供应商选择与青果 Authkey/Authpwd (只存本机,不上报),切换渠道未重填密钥时拦住保存;换号继承带渠道与供应商 - 后管密钥管理三列显示渠道/供应商标签
This commit is contained in:
+1
@@ -179,6 +179,7 @@ class AppearancePatentCandidateCollectionFaultToleranceTest {
|
||||
},
|
||||
task -> "prompt",
|
||||
task -> "sk-test",
|
||||
task -> null,
|
||||
(taskId, scopeHash, chunkIndex, rows) -> List.of(),
|
||||
(preferred, fallback) -> preferred == null || preferred.isBlank() ? fallback : preferred,
|
||||
// 本夹具只驱动「候选收集」,永远不会进欠费终态分支;真进来了就说明测试形状变了
|
||||
|
||||
+60
@@ -251,4 +251,64 @@ class UserApiSecretCheckServiceTest {
|
||||
"{\"data\":{\"list\":[{\"ip\":\"1.2.3.4\",\"port\":8080}]},\"code\":0}")).isFalse();
|
||||
assertThat(service.isInsufficientBalance("")).isFalse();
|
||||
}
|
||||
|
||||
// ---------- 青果(overseas.proxy.qg.net):code 是字符串、地址在 data[].server ----------
|
||||
|
||||
@Test
|
||||
void extractQingguoProxyUrlUsesServerFieldNotProxyIp() {
|
||||
// 青果文档明确:server 才是代理地址,proxy_ip 只是真实出口 IP(没端口,拿来连必失败)
|
||||
String body = "{\"code\":\"SUCCESS\",\"data\":[{\"proxy_ip\":\"123.54.55.24\","
|
||||
+ "\"server\":\"123.54.55.24:59419\",\"area\":\"河南省商丘市\",\"isp\":\"电信\","
|
||||
+ "\"deadline\":\"2023-02-25 15:38:36\"}],\"request_id\":\"83158ebe\"}";
|
||||
|
||||
assertThat(service.extractProxyUrlFromBody(body)).isEqualTo("http://123.54.55.24:59419");
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractQingguoProxyUrlNullWhenNoServerAndNoPort() {
|
||||
assertThat(service.extractProxyUrlFromBody(
|
||||
"{\"code\":\"SUCCESS\",\"data\":[{\"proxy_ip\":\"123.54.55.24\"}]}")).isNull();
|
||||
assertThat(service.extractProxyUrlFromBody(
|
||||
"{\"code\":\"SUCCESS\",\"data\":[]}")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void qingguoBalanceShortageIsInsufficientBalance() {
|
||||
UserApiSecretCheckService.CheckOutcome outcome = service.classifyProviderRejection(
|
||||
com.nanri.aiimage.modules.usersecret.support.ProxyProvider.QINGGUO,
|
||||
"{\"code\":\"BALANCE_INSUFFICIENT\",\"message\":\"余额不足\",\"request_id\":\"x\"}", 88);
|
||||
|
||||
assertThat(outcome).isNotNull();
|
||||
assertThat(outcome.status()).isEqualTo(UserApiSecretCheckService.STATUS_FAILED);
|
||||
assertThat(outcome.code()).isEqualTo(UserApiSecretCheckService.CODE_INSUFFICIENT_BALANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void qingguoAuthDenyIsForbiddenWithChineseMessage() {
|
||||
UserApiSecretCheckService.CheckOutcome outcome = service.classifyProviderRejection(
|
||||
com.nanri.aiimage.modules.usersecret.support.ProxyProvider.QINGGUO,
|
||||
"{\"code\":\"API_AUTH_DENY\",\"message\":\"Api授权不通过,请检查Api鉴权配置\",\"request_id\":\"x\"}", 90);
|
||||
|
||||
assertThat(outcome).isNotNull();
|
||||
assertThat(outcome.status()).isEqualTo(UserApiSecretCheckService.STATUS_FAILED);
|
||||
assertThat(outcome.code()).isEqualTo(UserApiSecretCheckService.CODE_FORBIDDEN);
|
||||
assertThat(outcome.message()).contains("青果").contains("API_AUTH_DENY");
|
||||
}
|
||||
|
||||
@Test
|
||||
void qingguoSuccessIsNotRejection() {
|
||||
assertThat(service.classifyProviderRejection(
|
||||
com.nanri.aiimage.modules.usersecret.support.ProxyProvider.QINGGUO,
|
||||
"{\"code\":\"SUCCESS\",\"data\":[]}", 60)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void jikipBalanceShortageStillClassified() {
|
||||
UserApiSecretCheckService.CheckOutcome outcome = service.classifyProviderRejection(
|
||||
com.nanri.aiimage.modules.usersecret.support.ProxyProvider.JIKIP,
|
||||
"{\"code\":-1,\"data\":null,\"message\":\"余额不足\"}", 70);
|
||||
|
||||
assertThat(outcome).isNotNull();
|
||||
assertThat(outcome.code()).isEqualTo(UserApiSecretCheckService.CODE_INSUFFICIENT_BALANCE);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-24
@@ -11,6 +11,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import com.nanri.aiimage.common.security.ShopCredentialCryptoService;
|
||||
import com.nanri.aiimage.config.UserSecretProperties;
|
||||
import com.nanri.aiimage.config.AppearancePatentProperties;
|
||||
import com.nanri.aiimage.config.SimilarAsinProperties;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.ReadScope;
|
||||
import com.nanri.aiimage.modules.notification.service.NotificationDispatchService;
|
||||
@@ -99,6 +101,7 @@ class UserApiSecretServiceTest {
|
||||
return new UserApiSecretService(
|
||||
mapper, crypto, checkService, adminUserMapper, adminAuthSupport,
|
||||
adminGroupMapper, userDataScopeSupport, notificationDispatchService, userSecretProperties,
|
||||
mock(AppearancePatentProperties.class), mock(SimilarAsinProperties.class),
|
||||
stringRedisTemplate, objectMapper);
|
||||
}
|
||||
|
||||
@@ -144,7 +147,7 @@ class UserApiSecretServiceTest {
|
||||
UserApiSecretService service = newService();
|
||||
UserApiSecretEntity existing = existingRow("enc:old-key");
|
||||
when(mapper.selectOne(any())).thenReturn(existing);
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "正常", 1678));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "正常", 1678));
|
||||
|
||||
service.check(7L, "similar-asin", "sk-input");
|
||||
// 输入值检测只暂存,不落库
|
||||
@@ -167,7 +170,7 @@ class UserApiSecretServiceTest {
|
||||
UserApiSecretService service = newService();
|
||||
UserApiSecretEntity existing = existingRow("enc:old-key");
|
||||
when(mapper.selectOne(any())).thenReturn(existing);
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "正常", 900));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "正常", 900));
|
||||
|
||||
service.check(7L, "similar-asin", "sk-input");
|
||||
service.save(7L, "similar-asin", "sk-changed");
|
||||
@@ -184,7 +187,7 @@ class UserApiSecretServiceTest {
|
||||
UserApiSecretService service = newService();
|
||||
UserApiSecretEntity existing = existingRow("enc:old-key");
|
||||
when(mapper.selectOne(any())).thenReturn(existing);
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("failed", "invalid_key", "密钥无效", 300));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("failed", "invalid_key", "密钥无效", 300));
|
||||
|
||||
service.check(7L, "similar-asin", "sk-bad");
|
||||
service.save(7L, "similar-asin", "sk-bad");
|
||||
@@ -199,7 +202,7 @@ class UserApiSecretServiceTest {
|
||||
UserApiSecretService service = newService();
|
||||
UserApiSecretEntity existing = existingRow("enc:old-key");
|
||||
when(mapper.selectOne(any())).thenReturn(existing);
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "正常", 500));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "正常", 500));
|
||||
when(valueOps.get(anyString())).thenThrow(new IllegalStateException("redis down"));
|
||||
|
||||
assertThat(service.check(7L, "similar-asin", "sk-input").getCheckStatus()).isEqualTo("passed");
|
||||
@@ -214,12 +217,12 @@ class UserApiSecretServiceTest {
|
||||
@Test
|
||||
void repeatedCheckWithinFreshWindowReusesResult() {
|
||||
UserApiSecretService service = newService();
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "代理可用", 120));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "代理可用", 120));
|
||||
|
||||
var first = service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=abc");
|
||||
var second = service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=abc");
|
||||
|
||||
verify(checkService, times(1)).probe(any(), anyString());
|
||||
verify(checkService, times(1)).probe(any(), anyString(), any());
|
||||
assertThat(second.getCheckStatus()).isEqualTo("passed");
|
||||
assertThat(second.getCheckStatus()).isEqualTo(first.getCheckStatus());
|
||||
}
|
||||
@@ -228,25 +231,25 @@ class UserApiSecretServiceTest {
|
||||
@Test
|
||||
void repeatedCheckProbesAgainWhenValueChanged() {
|
||||
UserApiSecretService service = newService();
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "正常", 100));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "正常", 100));
|
||||
|
||||
service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=aaa");
|
||||
service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=bbb");
|
||||
|
||||
verify(checkService, times(2)).probe(any(), anyString());
|
||||
verify(checkService, times(2)).probe(any(), anyString(), any());
|
||||
}
|
||||
|
||||
/** 失败结果不进新鲜期缓存:余额不足充值后应能立即重检。 */
|
||||
@Test
|
||||
void failedCheckIsNotReusedWithinFreshWindow() {
|
||||
UserApiSecretService service = newService();
|
||||
when(checkService.probe(any(), anyString()))
|
||||
when(checkService.probe(any(), anyString(), any()))
|
||||
.thenReturn(outcome("failed", "insufficient_balance", "代理服务商余额不足,请充值后重试", 80));
|
||||
|
||||
service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=abc");
|
||||
service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=abc");
|
||||
|
||||
verify(checkService, times(2)).probe(any(), anyString());
|
||||
verify(checkService, times(2)).probe(any(), anyString(), any());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,12 +259,12 @@ class UserApiSecretServiceTest {
|
||||
@Test
|
||||
void freshCheckIsSharedAcrossAccountsUsingTheSameSecret() {
|
||||
UserApiSecretService service = newService();
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "代理可用", 120));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "代理可用", 120));
|
||||
|
||||
var first = service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=abc");
|
||||
var second = service.check(8L, "proxy", "https://api.jikip.com/ip-get?num=1&key=abc");
|
||||
|
||||
verify(checkService, times(1)).probe(any(), anyString());
|
||||
verify(checkService, times(1)).probe(any(), anyString(), any());
|
||||
assertThat(second.getCheckStatus()).isEqualTo("passed");
|
||||
assertThat(second.getCheckStatus()).isEqualTo(first.getCheckStatus());
|
||||
}
|
||||
@@ -270,24 +273,24 @@ class UserApiSecretServiceTest {
|
||||
@Test
|
||||
void freshCheckDoesNotLeakAcrossDifferentSecretValues() {
|
||||
UserApiSecretService service = newService();
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "正常", 100));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "正常", 100));
|
||||
|
||||
service.check(7L, "proxy", "https://api.jikip.com/ip-get?num=1&key=aaa");
|
||||
service.check(8L, "proxy", "https://api.jikip.com/ip-get?num=1&key=bbb");
|
||||
|
||||
verify(checkService, times(2)).probe(any(), anyString());
|
||||
verify(checkService, times(2)).probe(any(), anyString(), any());
|
||||
}
|
||||
|
||||
/** 同一串值在不同模块下结论可能不同(货源/外观各自独立的检测端点),新鲜期按模块隔离。 */
|
||||
@Test
|
||||
void freshCheckIsScopedPerModule() {
|
||||
UserApiSecretService service = newService();
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "连通正常", 100));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "连通正常", 100));
|
||||
|
||||
service.check(7L, "similar-asin", "sk-shared");
|
||||
service.check(8L, "appearance-patent", "sk-shared");
|
||||
|
||||
verify(checkService, times(2)).probe(any(), anyString());
|
||||
verify(checkService, times(2)).probe(any(), anyString(), any());
|
||||
}
|
||||
|
||||
private UserApiSecretEntity existingRow(String cipher) {
|
||||
@@ -980,7 +983,7 @@ class UserApiSecretServiceTest {
|
||||
11L, storedRow(11L, "proxy", sharedCipher),
|
||||
12L, storedRow(12L, "proxy", sharedCipher),
|
||||
13L, storedRow(13L, "proxy", sharedCipher)));
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "代理可用", 120));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "代理可用", 120));
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
inspectionRow(1L, 11L, "proxy", sharedCipher),
|
||||
inspectionRow(2L, 12L, "proxy", sharedCipher),
|
||||
@@ -988,7 +991,7 @@ class UserApiSecretServiceTest {
|
||||
|
||||
var summary = service.checkAllForScheduler(500, 20);
|
||||
|
||||
verify(checkService, times(1)).probe(any(), anyString());
|
||||
verify(checkService, times(1)).probe(any(), anyString(), any());
|
||||
assertThat(summary.checked()).isEqualTo(3);
|
||||
assertThat(summary.probed()).isEqualTo(1);
|
||||
assertThat(inspectionWrites.keySet()).containsExactlyInAnyOrder(11L, 12L, 13L);
|
||||
@@ -1003,7 +1006,7 @@ class UserApiSecretServiceTest {
|
||||
stubInspectionStore(Map.of(
|
||||
11L, storedRow(11L, "proxy", sharedCipher),
|
||||
12L, storedRow(12L, "proxy", sharedCipher)));
|
||||
when(checkService.probe(any(), anyString())).thenReturn(
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(
|
||||
outcome("failed", "insufficient_balance", "代理服务商余额不足,请充值后重试", 80));
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
inspectionRow(1L, 11L, "proxy", sharedCipher),
|
||||
@@ -1011,7 +1014,7 @@ class UserApiSecretServiceTest {
|
||||
|
||||
var summary = service.checkAllForScheduler(500, 20);
|
||||
|
||||
verify(checkService, times(1)).probe(any(), anyString());
|
||||
verify(checkService, times(1)).probe(any(), anyString(), any());
|
||||
assertThat(summary.probed()).isEqualTo(1);
|
||||
assertThat(summary.failed()).isEqualTo(2);
|
||||
assertThat(inspectionWrites.values()).containsOnly("failed");
|
||||
@@ -1025,14 +1028,14 @@ class UserApiSecretServiceTest {
|
||||
stubInspectionStore(Map.of(
|
||||
11L, storedRow(11L, "similar-asin", sharedCipher),
|
||||
12L, storedRow(12L, "appearance-patent", sharedCipher)));
|
||||
when(checkService.probe(any(), anyString())).thenReturn(outcome("passed", "ok", "连通正常", 100));
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(outcome("passed", "ok", "连通正常", 100));
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
inspectionRow(1L, 11L, "similar-asin", sharedCipher),
|
||||
inspectionRow(2L, 12L, "appearance-patent", sharedCipher)), List.of());
|
||||
|
||||
var summary = service.checkAllForScheduler(500, 20);
|
||||
|
||||
verify(checkService, times(2)).probe(any(), anyString());
|
||||
verify(checkService, times(2)).probe(any(), anyString(), any());
|
||||
assertThat(summary.checked()).isEqualTo(2);
|
||||
assertThat(summary.probed()).isEqualTo(2);
|
||||
}
|
||||
@@ -1049,7 +1052,7 @@ class UserApiSecretServiceTest {
|
||||
11L, storedRow(11L, "proxy", sharedCipher),
|
||||
12L, storedRow(12L, "proxy", sharedCipher),
|
||||
13L, storedRow(13L, "proxy", sharedCipher)));
|
||||
when(checkService.probe(any(), anyString())).thenReturn(
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(
|
||||
outcome("failed", "insufficient_balance", "代理服务商余额不足,请充值后重试", 80));
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
inspectionRow(1L, 11L, "proxy", sharedCipher),
|
||||
@@ -1081,7 +1084,7 @@ class UserApiSecretServiceTest {
|
||||
UserApiSecretService service = newService();
|
||||
String cipher = "enc:sk-solo";
|
||||
stubInspectionStore(Map.of(11L, storedRow(11L, "similar-asin", cipher)));
|
||||
when(checkService.probe(any(), anyString())).thenReturn(
|
||||
when(checkService.probe(any(), anyString(), any())).thenReturn(
|
||||
outcome("failed", "invalid_key", "密钥无效或已被拒绝", 90));
|
||||
when(mapper.selectList(any())).thenReturn(List.of(
|
||||
inspectionRow(1L, 11L, "similar-asin", cipher)), List.of());
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.nanri.aiimage.modules.usersecret.support;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.config.AppearancePatentProperties;
|
||||
import com.nanri.aiimage.config.SimilarAsinProperties;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* 密钥「货源」维度:LLM 渠道(龙抬头/贞贞)与代理供应商(青果/极客)的归一化、默认值、主机与模型映射。
|
||||
*
|
||||
* <p>口径来源(2026-10-29 用户拍板):新建默认龙抬头 + 青果;存量由迁移 V180 回填贞贞/极客;
|
||||
* 龙抬头的模型 id 统一用 {@code gemini-3.1-flash-lite}。</p>
|
||||
*/
|
||||
class LlmChannelProxyProviderTest {
|
||||
|
||||
@Test
|
||||
void llmChannelDefaultsToT8star() {
|
||||
// 2026-10-30 用户拍板:默认仍是贞贞,龙抬头只做手动切换
|
||||
assertThat(LlmChannel.of(null)).isEqualTo(LlmChannel.T8STAR);
|
||||
assertThat(LlmChannel.of(" ")).isEqualTo(LlmChannel.T8STAR);
|
||||
assertThat(LlmChannel.of("unknown-channel")).isEqualTo(LlmChannel.T8STAR);
|
||||
assertThat(LlmChannel.of(" LONGTAITOU ")).isEqualTo(LlmChannel.LONGTAITOU);
|
||||
}
|
||||
|
||||
@Test
|
||||
void llmChannelParseRejectsUnknownWithoutFallback() {
|
||||
assertThat(LlmChannel.parse("t8star")).isEqualTo(LlmChannel.T8STAR);
|
||||
assertThat(LlmChannel.parse("nope")).isNull();
|
||||
assertThat(LlmChannel.parse("")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void longtaitouUsesItsOwnModelId() {
|
||||
// 贞贞的模型名在龙抬头那边不存在,切渠道必须换 id,否则 model_not_found
|
||||
assertThat(LlmChannel.LONGTAITOU.modelFor("gemini-3.1-flash-lite-preview-thinking-medium"))
|
||||
.isEqualTo("gemini-3.1-flash-lite");
|
||||
// 贞贞保持配置里的模型名原样
|
||||
assertThat(LlmChannel.T8STAR.modelFor("gemini-3.1-flash-lite-preview-thinking-medium"))
|
||||
.isEqualTo("gemini-3.1-flash-lite-preview-thinking-medium");
|
||||
}
|
||||
|
||||
@Test
|
||||
void modelMappingFollowsRequestHost() {
|
||||
assertThat(LlmChannel.modelForHost("https://longtaitou.token6688.com", "any-model"))
|
||||
.isEqualTo("gemini-3.1-flash-lite");
|
||||
assertThat(LlmChannel.modelForHost("https://ai.t8star.org", "any-model")).isEqualTo("any-model");
|
||||
assertThat(LlmChannel.modelForHost(null, "any-model")).isEqualTo("any-model");
|
||||
assertThat(LlmChannel.modelForHost("https://unknown.example.com", "any-model")).isEqualTo("any-model");
|
||||
}
|
||||
|
||||
@Test
|
||||
void proxyProviderDefaultsToQingguoAndDetectsByUrl() {
|
||||
assertThat(ProxyProvider.of(null)).isEqualTo(ProxyProvider.JIKIP);
|
||||
assertThat(ProxyProvider.of("jikip")).isEqualTo(ProxyProvider.JIKIP);
|
||||
assertThat(ProxyProvider.detectFromUrl(
|
||||
"https://overseas.proxy.qg.net/get?key=abc&num=1&format=json")).isEqualTo(ProxyProvider.QINGGUO);
|
||||
assertThat(ProxyProvider.detectFromUrl("https://api.jikip.com/ip-get?num=1&minute=3&key=abc"))
|
||||
.isEqualTo(ProxyProvider.JIKIP);
|
||||
assertThat(ProxyProvider.detectFromUrl("https://example.com/get")).isNull();
|
||||
assertThat(ProxyProvider.detectFromUrl(null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void longtaitouNeedsExplicitThinkingParamsLikeT8star() {
|
||||
// 贞贞把 thinking 写在模型名里(…-thinking-medium),请求体不用额外字段
|
||||
Map<String, Object> t8 = new LinkedHashMap<>();
|
||||
LlmChannel.applyThinkingForHost("https://ai.t8star.org", t8);
|
||||
assertThat(t8).isEmpty();
|
||||
|
||||
// 龙抬头的同名模型默认不思考,业务链路要显式补上,才等于现网口径
|
||||
Map<String, Object> ltt = new LinkedHashMap<>();
|
||||
LlmChannel.applyThinkingForHost("https://longtaitou.token6688.com", ltt);
|
||||
assertThat(ltt).containsEntry("enable_thinking", true);
|
||||
assertThat(ltt).containsEntry("thinking_budget", "medium");
|
||||
|
||||
// 未知主机不动请求体(自建中转/本地假上游不要被塞参数)
|
||||
Map<String, Object> unknown = new LinkedHashMap<>();
|
||||
LlmChannel.applyThinkingForHost("http://127.0.0.1:8080", unknown);
|
||||
assertThat(unknown).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void moduleDefaultsAndValidation() {
|
||||
assertThat(UserSecretModule.APPEARANCE_PATENT.defaultChannel()).isEqualTo("t8star");
|
||||
assertThat(UserSecretModule.SIMILAR_ASIN.defaultChannel()).isEqualTo("t8star");
|
||||
assertThat(UserSecretModule.PROXY.defaultChannel()).isEqualTo("jikip");
|
||||
|
||||
assertThat(UserSecretModule.APPEARANCE_PATENT.requireChannel(null)).isEqualTo("t8star");
|
||||
assertThat(UserSecretModule.APPEARANCE_PATENT.requireChannel("T8STAR")).isEqualTo("t8star");
|
||||
assertThat(UserSecretModule.PROXY.requireChannel("jikip")).isEqualTo("jikip");
|
||||
assertThatThrownBy(() -> UserSecretModule.APPEARANCE_PATENT.requireChannel("qingguo"))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("未知的 LLM 渠道");
|
||||
assertThatThrownBy(() -> UserSecretModule.PROXY.requireChannel("longtaitou"))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("未知的代理供应商");
|
||||
}
|
||||
|
||||
@Test
|
||||
void proxyChannelFallsBackToUrlDetectionForLegacyRows() {
|
||||
// 老数据只有链接、没有供应商列:按域名识别,别把极客链接当青果解析
|
||||
assertThat(UserSecretModule.PROXY.channelOrDefault(null, "https://api.jikip.com/ip-get?key=x"))
|
||||
.isEqualTo("jikip");
|
||||
assertThat(UserSecretModule.PROXY.channelOrDefault(null, "https://overseas.proxy.qg.net/get?key=x"))
|
||||
.isEqualTo("qingguo");
|
||||
assertThat(UserSecretModule.PROXY.channelOrDefault(null, "https://example.com/get"))
|
||||
.isEqualTo("jikip");
|
||||
}
|
||||
|
||||
@Test
|
||||
void llmHostResolvesByChannelAndFallsBackToModuleConfig() {
|
||||
AppearancePatentProperties appearance = new AppearancePatentProperties();
|
||||
SimilarAsinProperties similar = new SimilarAsinProperties();
|
||||
|
||||
assertThat(UserSecretModule.APPEARANCE_PATENT.resolveLlmHost(appearance, similar, "longtaitou"))
|
||||
.isEqualTo("https://longtaitou.token6688.com");
|
||||
assertThat(UserSecretModule.APPEARANCE_PATENT.resolveLlmHost(appearance, similar, "t8star"))
|
||||
.isEqualTo("https://ai.t8star.org");
|
||||
// 迁移前遗留行没有 channel:沿用模块全局配置,行为不变
|
||||
assertThat(UserSecretModule.APPEARANCE_PATENT.resolveLlmHost(appearance, similar, null))
|
||||
.isEqualTo(appearance.getLlmHost());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user