From 8aef24f3a654d24bea8eb8ddf8aca22a377a4e72 Mon Sep 17 00:00:00 2001 From: shaw Date: Fri, 12 Jun 2026 11:12:32 +0800 Subject: [PATCH] =?UTF-8?q?test(plugin):=20=E4=BF=AE=E5=A4=8D=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=B3=A8=E5=86=8C=E8=A1=A8=E5=A7=94=E6=89=98=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=AF=B9=20-count>1=20=E7=9A=84=E4=B8=8D=E5=B9=82?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 终审第二路审计发现:该测试向进程级全局默认注册表注册探针且无法清理, go test -count=2 同进程重跑撞重复注册 panic。改为已注册即复用探针, 使 -count>1 抖动扫描(审计常用手段)可覆盖本包。count=3 与 -race -count=2 验证通过。 --- backend/internal/plugin/registry_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/internal/plugin/registry_test.go b/backend/internal/plugin/registry_test.go index 7f2c20b96a..4593cb5647 100644 --- a/backend/internal/plugin/registry_test.go +++ b/backend/internal/plugin/registry_test.go @@ -134,9 +134,13 @@ func TestRegistryIsolation(t *testing.T) { } func TestPackageLevelFunctionsDelegateToDefaultRegistry(t *testing.T) { - // 使用唯一 ID,避免与同进程其他测试冲突(包级默认注册表是进程级状态)。 + // 使用唯一 ID,避免与同进程其他测试冲突(包级默认注册表是进程级状态, + // 无法清理)。注册仅做一次:`go test -count>1` 同进程重跑时探针已存在, + // 直接复用——否则会撞重复注册 panic(终审第二路审计发现的测试幂等性问题)。 const id = ModuleID("test_default_registry.probe") - RegisterModule(newStubModule(id)) + if _, registered := GetModule(id); !registered { + RegisterModule(newStubModule(id)) + } info, ok := GetModule(id) require.True(t, ok)