fix(cr2-backend): 工作台包凭据拒绝与并发幂等、会话/任务终态收口

- CR-02/05/21:confirm 前解包拒绝凭据文件、清理被拒对象;V176 版本唯一键;并发 confirm 幂等
- CR-07/08/09/10:登录世代回读再签、心跳只停续期、终态任务不被失败回调改写、告警先推送再推进基线
- CR-11:品牌 Gating 写操作限平台超管
- CR-18:关键词分页钳制 + V177 四表 DDL
- CR-20:中断恢复标志并上抛
- catch 棘轮按 9 处新增逐条点名更新基线

定向 154 例全绿(0 fail / 0 skip);V174/V175 未回改。
This commit is contained in:
2026-10-26 11:33:25 +08:00
parent 688910f738
commit b5e4c45add
24 changed files with 1206 additions and 41 deletions
@@ -126,6 +126,48 @@ class CostGuardSchedulerTest {
anyString(), contains("平台自费"), anyString(), isNull());
}
@Test
void platformAlertWithoutAnyAdminPersistedDoesNotAdvanceBaselineAndRetries() {
// CR-10:推送返回 0(没有管理员落库)时基线不得推进,否则下一轮 crossed 不再成立、告警永久丢失。
when(usageMapper.sumByUserAndModule(any(LocalDate.class)))
.thenReturn(List.of(row(0L, "proxy", 2_500, 0)));
when(notificationDispatchService.pushToAdmins(
eq(NotificationService.SCENE_COST_GUARD), eq(NotificationService.LEVEL_WARNING),
anyString(), contains("平台自费"), anyString(), isNull()))
.thenReturn(0, 1);
scheduler.runOnce();
assertThat(baselineStore.get(0L)).isNull();
scheduler.runOnce();
assertThat(baselineStore.get(0L).proxy).isEqualTo(2_500L);
scheduler.runOnce();
verify(notificationDispatchService, org.mockito.Mockito.times(2)).pushToAdmins(
eq(NotificationService.SCENE_COST_GUARD), eq(NotificationService.LEVEL_WARNING),
anyString(), contains("平台自费"), anyString(), isNull());
}
@Test
void platformAlertPushExceptionDoesNotAdvanceBaselineAndRetries() {
when(usageMapper.sumByUserAndModule(any(LocalDate.class)))
.thenReturn(List.of(row(0L, "proxy", 2_500, 0)));
when(notificationDispatchService.pushToAdmins(
eq(NotificationService.SCENE_COST_GUARD), eq(NotificationService.LEVEL_WARNING),
anyString(), contains("平台自费"), anyString(), isNull()))
.thenThrow(new IllegalStateException("redis down"))
.thenReturn(1);
scheduler.runOnce();
assertThat(baselineStore.get(0L)).isNull();
scheduler.runOnce();
assertThat(baselineStore.get(0L).proxy).isEqualTo(2_500L);
verify(notificationDispatchService, org.mockito.Mockito.times(2)).pushToAdmins(
eq(NotificationService.SCENE_COST_GUARD), eq(NotificationService.LEVEL_WARNING),
anyString(), contains("平台自费"), anyString(), isNull());
}
@Test
void llmCallsWindowJumpPauses() {
when(usageMapper.sumByUserAndModule(any(LocalDate.class)))