From 4e8ea7d5684dfb0538b1682b3cf64268f1b92299 Mon Sep 17 00:00:00 2001 From: shaw Date: Sat, 18 Jul 2026 21:02:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E6=B1=A0=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E8=A7=84=E5=88=99=E6=B5=8B=E8=AF=95=E9=80=82?= =?UTF-8?q?=E9=85=8D=20#4547=20=E6=A8=A1=E5=9E=8B=E7=BA=A7=E9=9A=94?= =?UTF-8?q?=E7=A6=BB=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #4496 与 #4547 文本无冲突但语义相撞:#4496 的测试断言规则命中后账号级 跨模型封锁,#4547(issue 4527 第4点)将已知模型的临时不可调度改为按 模型隔离(SetModelRateLimit,不再触发账号级 runtime block)。 按 #4547 的语义更新断言:命中模型 gpt-5.4 记模型级封锁、gpt-5.5 不受 影响、不再调用账号级 SetTempUnschedulable;池模式规则仍生效(停止同 账号重试),issue 4470 的诉求不受影响。未知模型的账号级兜底已由 TestOpenAITempUnschedulable_UnknownModelKeepsAccountRuntimeBlock 覆盖。 --- .../openai_account_runtime_block_fastpath_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/internal/service/openai_account_runtime_block_fastpath_test.go b/backend/internal/service/openai_account_runtime_block_fastpath_test.go index 2f20ec276..ae4bfa91d 100644 --- a/backend/internal/service/openai_account_runtime_block_fastpath_test.go +++ b/backend/internal/service/openai_account_runtime_block_fastpath_test.go @@ -84,7 +84,11 @@ func TestOpenAIRuntimeBlocker_IgnoresNonOpenAIFromRateLimitService(t *testing.T) require.False(t, gateway.isOpenAIAccountRuntimeBlocked(account)) } -func TestOpenAIPoolModeTempRule_StopsSameAccountRetryAndBlocksAcrossModels(t *testing.T) { +// 自 #4547(issue 4527 第4点)起,临时不可调度规则命中已知模型时按模型隔离: +// 只封 (账号, 模型) 对,不再账号级一刀切;未知模型仍走账号级兜底 +// (见 TestOpenAITempUnschedulable_UnknownModelKeepsAccountRuntimeBlock)。 +// 池模式规则仍然生效(issue 4470):停止同账号重试并对命中模型设临时封锁。 +func TestOpenAIPoolModeTempRule_StopsSameAccountRetryAndIsolatesBlockToModel(t *testing.T) { repo := &errorPolicyRepoStub{} rateLimitService := NewRateLimitService(repo, nil, &config.Config{}, nil, nil) gateway := &OpenAIGatewayService{ @@ -129,11 +133,13 @@ func TestOpenAIPoolModeTempRule_StopsSameAccountRetryAndBlocksAcrossModels(t *te require.NotNil(t, failoverErr) require.False(t, failoverErr.RetryableOnSameAccount) - require.Equal(t, 1, repo.tempCalls) + require.Zero(t, repo.tempCalls) require.Equal(t, 0, repo.setErrCalls) require.Equal(t, StatusActive, account.Status) - require.True(t, gateway.isOpenAIAccountRequestRuntimeBlocked(account, "gpt-5.4")) - require.True(t, gateway.isOpenAIAccountRequestRuntimeBlocked(account, "gpt-5.5")) + require.Len(t, repo.modelRateLimitCalls, 1) + require.Equal(t, "gpt-5.4", repo.modelRateLimitCalls[0].scope) + require.False(t, gateway.isOpenAIAccountRuntimeBlocked(account)) + require.False(t, gateway.isOpenAIAccountRequestRuntimeBlocked(account, "gpt-5.5")) } func TestOpenAIModelNotFound_DoesNotRuntimeBlockWholeAccount(t *testing.T) {