fix(release): AP 部分缺口出表、平台自费计次与工作台预签名 TTL
- AP 抓取缺行不再一律判死,按覆盖率判定;≥95% 出表成功并保留缺口提示 - 无归属代理提取记 0 号平台自费桶,后台可见并推管理员日告警 - 工作台安装包预签名从 180s 提到可配置 3600s,避免慢网上传在途过期
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
package com.nanri.aiimage.modules.appearancepatent.service.support;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class AppearancePatentPartialGapStatusTest {
|
||||
|
||||
private static final String PARTIAL_GAP =
|
||||
"有 3 行抓取失败(未取得商品页数据):B0833QW1CB;B0CZ41T8ZQ;B08R1WH7SS";
|
||||
|
||||
@Test
|
||||
void crawlGapIsPartialNotFatal() {
|
||||
assertTrue(AppearancePatentResultJobSupport.isPartialDataGapError(PARTIAL_GAP));
|
||||
assertTrue(AppearancePatentResultJobSupport.isPartialDataGapError(
|
||||
"有 1 行未完成检测、有 2 行未采集到数据(结果文件中这些行已单独标注)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void assemblyFailureIsStillFatal() {
|
||||
assertFalse(AppearancePatentResultJobSupport.isPartialDataGapError(
|
||||
"已收到 12 个结果分片,但结果文件生成多次失败,任务已自动结束"));
|
||||
assertFalse(AppearancePatentResultJobSupport.isPartialDataGapError(
|
||||
"Generate appearance patent result failed"));
|
||||
assertFalse(AppearancePatentResultJobSupport.isPartialDataGapError(null));
|
||||
assertFalse(AppearancePatentResultJobSupport.isPartialDataGapError(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void coverageAtOrAboveFloorSurvivesCrawlGap() {
|
||||
assertFalse(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, PARTIAL_GAP, 1_000, 0.997, 0.95));
|
||||
assertFalse(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, PARTIAL_GAP, 1_000, 0.95, 0.95));
|
||||
}
|
||||
|
||||
@Test
|
||||
void coverageBelowFloorStillFails() {
|
||||
assertTrue(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, PARTIAL_GAP, 1_000, 0.90, 0.95));
|
||||
assertTrue(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, null, 1_000, 0.50, 0.95));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fatalErrorOrTerminalTaskNeverRevives() {
|
||||
assertTrue(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
true, PARTIAL_GAP, 1_000, 1.0, 0.95));
|
||||
assertTrue(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, "结果文件生成多次失败,任务已自动结束", 1_000, 1.0, 0.95));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyRowAccountKeepsLegacyOutcome() {
|
||||
assertFalse(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, null, 0, 0.0, 0.95));
|
||||
assertTrue(AppearancePatentResultJobSupport.shouldFailAfterAssembly(
|
||||
false, PARTIAL_GAP, 0, 0.0, 0.95));
|
||||
}
|
||||
}
|
||||
+30
@@ -96,6 +96,36 @@ class CostGuardSchedulerTest {
|
||||
anyString(), contains("继续任务"), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void platformProxyDailyOverLimitNotifiesAdminsWithoutPausingAnyone() {
|
||||
// 无归属购买记在 0 号桶:金额真实,但没有可暂停的账号,只能推管理员告警。
|
||||
when(usageMapper.sumByUserAndModule(any(LocalDate.class)))
|
||||
.thenReturn(List.of(row(0L, "proxy", 2_500, 0)));
|
||||
|
||||
scheduler.runOnce();
|
||||
|
||||
verify(guardService, never()).isPaused(anyLong());
|
||||
verify(guardService, never()).pause(anyLong(), anyString());
|
||||
verify(notificationDispatchService).pushToAdmins(
|
||||
eq(NotificationService.SCENE_COST_GUARD), eq(NotificationService.LEVEL_WARNING),
|
||||
anyString(), contains("平台自费"), anyString(), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void platformNewDayBaselineDoesNotSwallowAlert() {
|
||||
// 昨天基线已高于告警线;今天累计变小是跨天,今天首次越线仍必须告警。
|
||||
baselineStore.put(0L, new CostGuardBaselineStore.Baseline(
|
||||
5_000, 0, 0, System.currentTimeMillis() - 120_000L));
|
||||
when(usageMapper.sumByUserAndModule(any(LocalDate.class)))
|
||||
.thenReturn(List.of(row(0L, "proxy", 2_100, 0)));
|
||||
|
||||
scheduler.runOnce();
|
||||
|
||||
verify(notificationDispatchService).pushToAdmins(
|
||||
eq(NotificationService.SCENE_COST_GUARD), eq(NotificationService.LEVEL_WARNING),
|
||||
anyString(), contains("平台自费"), anyString(), isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void llmCallsWindowJumpPauses() {
|
||||
when(usageMapper.sumByUserAndModule(any(LocalDate.class)))
|
||||
|
||||
+34
@@ -111,6 +111,40 @@ class UserSecretUsageServiceTest {
|
||||
verify(usageMapper).increment(eq(7L), eq("proxy"), eq(LocalDate.now()), eq(10_000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordReportedAllowsPlatformBucketOnlyForProxy() {
|
||||
UserSecretUsageService service = newService();
|
||||
when(usageMapper.increment(any(), any(), any(), any(Integer.class))).thenReturn(1);
|
||||
|
||||
assertThat(service.recordReported(0L, "proxy", 3)).isTrue();
|
||||
assertThat(service.recordReported(0L, "appearance-patent", 3)).isFalse();
|
||||
assertThat(service.recordReported(-1L, "proxy", 3)).isFalse();
|
||||
|
||||
verify(usageMapper).increment(eq(0L), eq("proxy"), eq(LocalDate.now()), eq(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminPageLabelsPlatformBucket() {
|
||||
UserSecretUsageService service = newService();
|
||||
when(adminAuthSupport.currentRole(any())).thenReturn("super_admin");
|
||||
when(usageMapper.selectList(any())).thenReturn(List.of(
|
||||
usageRow(0L, "proxy", 50),
|
||||
usageRow(1L, "proxy", 2)));
|
||||
AdminUserEntity user1 = new AdminUserEntity();
|
||||
user1.setId(1L);
|
||||
user1.setUsername("张三");
|
||||
when(adminUserMapper.selectBatchIds(any())).thenReturn(List.of(user1));
|
||||
when(adminGroupMapper.selectGroupNamesByUserIds(any())).thenReturn(List.of());
|
||||
|
||||
var page = service.adminPage(new AdminUserEntity(), new AdminUserSecretUsageQuery(), ReadScope.unfiltered());
|
||||
|
||||
var platformRow = page.getItems().stream()
|
||||
.filter(item -> item.getUserId() == 0L).findFirst().orElseThrow();
|
||||
assertThat(platformRow.getUsername()).isEqualTo("平台自费");
|
||||
assertThat(platformRow.getProxyCount()).isEqualTo(50);
|
||||
assertThat(platformRow.getGroups()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminPageAggregatesByUserAndSortsByTotal() {
|
||||
UserSecretUsageService service = newService();
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ class WorkbenchClientPackageServiceTest {
|
||||
|
||||
@Test
|
||||
void presignUsesIndependentPrefixAndReturnsUploadUrl() {
|
||||
when(ossStorageService.presignWorkbenchClientUpload(anyString(), eq(180)))
|
||||
when(ossStorageService.presignWorkbenchClientUpload(anyString(), eq(3600)))
|
||||
.thenReturn("https://oss.aishufu.top/client/workbench-client/versions/put");
|
||||
when(ossStorageService.getWorkbenchClientDownloadUrl(anyString()))
|
||||
.thenReturn("https://download.aishufu.top/client/workbench-client/versions/1.2.3.zip");
|
||||
@@ -82,7 +82,7 @@ class WorkbenchClientPackageServiceTest {
|
||||
@Test
|
||||
void presignKeysAreUniqueForTheSameVersion() {
|
||||
// 同毫秒/同版本两次预签名必须不同:只靠时间戳会在 A/B 实例或并发上传时覆盖对象
|
||||
when(ossStorageService.presignWorkbenchClientUpload(anyString(), eq(180))).thenReturn("put");
|
||||
when(ossStorageService.presignWorkbenchClientUpload(anyString(), eq(3600))).thenReturn("put");
|
||||
when(ossStorageService.getWorkbenchClientDownloadUrl(anyString())).thenReturn("download");
|
||||
|
||||
String first = (String) service().presignPackage("pkg.zip", "1.2.3").get("object_key");
|
||||
|
||||
Reference in New Issue
Block a user