Skip to content

test(hub-server): 最后两个巨型测试文件按生产域归位——agent_team_test.go 3176行/64Test 与 repository_test.go 2221行/55Test 双双删除,119 Test 逐字搬进 19 个域文件(Test名集合/helper集合/=== RUN 418/PASS 284 四路守恒 diff rc=0,文件级 //nolint:gosec 随之消失且 golangci-lint 两包 0 issues) - #2294

Merged
DeliciousBuding merged 2 commits into
masterfrom
test/hub-giant-test-split
Sep 3, 2026

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

一句话

hub-server 最后两个巨型测试文件按生产域归位:internal/service/agentteam/agent_team_test.go(3176 行 / 64 Test)与 internal/repository/repository_test.go(2221 行 / 55 Test)双双删除,119 个 Test 逐字搬进 19 个域测试文件 + 2 个既有域文件,共享夹具各自收进本包 helpers_test.go(27 文件,+5603 / −5398,净 +205 行=拆文件的 package/import/文件头固有成本,非新增断言)。

两个包内的生产代码早已按域切分(agent_team_run.go/agent_team_crud.go/…、device.go/session.go/friendship.go/…),测试侧的这两个 leftovers 是唯一还按"一个文件装整包"的地方。同批已合的 #2288edge-serverhandlers_test.go(3792→184 行)做了同一件事。

拆分结果

agentteam(删 3176 行 / 64 Test)

新文件 Test 数
agent_team_crud_test.go 13
agent_team_member_test.go 4
assignment_lifecycle_test.go 13
route_decision_test.go 9
agent_team_approval_test.go 8
agent_team_compete_test.go 3(+1 私有 mock)
agent_team_review_test.go 1
并入既有 agent_team_run_test.go +12
并入既有 route_helpers_test.go +1
共享夹具/mock 收进 helpers_test.go +19

repository(删 2221 行 / 55 Test)

新文件 Test 数
db_test.go 1 · device_test.go 5 · user_test.go 4 · session_test.go 4 · message_test.go 10 · message_reaction_test.go 4 · message_attachment_test.go 2 · friendship_test.go 7 · notification_test.go 3 · attachment_test.go 1 · session_member_test.go 4 · refresh_token_test.go 2 47
并入既有 agent_test.go +8
夹具 setupSQLite/createTestSession/strPtr 收进新 helpers_test.go

守恒证据(主机独立复跑,不是采信 lane 报告)

守恒项 master 本分支 diff
func Test* 名集合(agentteam) 117(uniq 117) 117(uniq 117) rc=0
func Test* 名集合(repository) 171(uniq 171) 171(uniq 171) rc=0
小写顶层 helper 集合(agentteam / repository) 34 / 46 34 / 46 rc=0 / rc=0
go test -v=== RUN 排序集合(两包合计,含子测试路径) 418 418 rc=0
--- PASS 名集合(两包合计) 284 284 rc=0
--- SKIP 2 2 同名:TestMigration0040AuditEventsPostgresUpProtectsTruncateTestMigration0071PostgresUpCreatesTrgmIndexForMessageSearch(PG-only,master 基线即 SKIP)
--- FAIL 0 0

两包均内存 sqlite + sqlmock,无外部依赖,-count=1 实跑:agentteam ok 1.162s、repository ok 11.125s

//nolint:gosec 处置(本批唯一"减少抑制"的点)

master 的 agent_team_test.go:1 带文件级 //nolint:gosec // 测试 fixture:凭据模式字符串…。该文件被删除后没有把这条抑制凭空补到新文件上,而是实测确认它已无必要:

  • golangci-lint run ./internal/service/agentteam/... ./internal/repository/...(本机 v2.12.2,仓库配置 run.tests: true)→ 0 issues
  • golangci-lint run --default=none --enable=gosec 同两包 → 0 issues
  • python3 scripts/verify/verify-hub-lint-ratchet.py → rc=0(0 findings, all baseline-registeredhub-lint-baseline.json 的 findings 为空 ⇒ 任何新 finding 即红)
  • 凭据字面量集合逐字比对(证明没靠改夹具内容绕过):git grep -hoE "\"[A-Za-z0-9_-]*(secret|token|password|apikey|api_key)[A-Za-z0-9_-]*\"" master vs 分支 → agentteam 13=13、repository 7=7diff rc=0

门禁(本机 huawei-dev 实跑)

命令 结果
go build ./...(hub-server) rc=0
go vet ./...(hub-server) rc=0
go test ./internal/service/agentteam/... ./internal/repository/... -v -count=1 rc=0(418 RUN / 0 FAIL / 2 既有 SKIP)
gofmt -l 两个包目录 空输出,rc=0
python3 scripts/verify/verify-test-sleep-ratchet.py rc=0(47 sleeps across 21 files,count baseline 21 files 未破)
python3 scripts/verify/verify-hub-lint-ratchet.py rc=0
bash /tmp/run-validate.sh <worktree>(61 条 CI validate 命令,含 commit-msg / diff --check / check-secrets) PASS=61 FAIL=0 SKIP(merge-ref)=1(主机复跑 1m08s)

暗卷(主机独立重跑,证明搬家后测试仍然会红)

  1. isTerminalTeamRunStatus 的 terminal 集合从 Completed/Failed/Cancelled 改成只有 Completed--- FAIL: TestIsTerminalTeamRunStatusIncludesCancelledWithoutCancelAPI,失败定位落在搬家后的新位置 route_helpers_test.go:270/272git checkout -- 还原后 ok 1.162s
  2. WrapNotFounderrors.Is(err, gorm.ErrRecordNotFound) 分支从 return mappedErr 改成 return err--- FAIL: TestWrapNotFound,定位新文件 db_test.go:15/16;还原后 ok 11.125s
  3. 两次还原后 git status --short 为空(无残留变异)。

顺带必需的一处锚点更新

internal/repository/user_upsert_predicate_test.go 的 SSOT 锚点表里 {"fixture repository_test.go", "repository_test.go"}{"fixture helpers_test.go", "helpers_test.go"}(1 行)。该测试本身就是"TokenDance sub predicate 必须在每个夹具 DDL 里出现"的守卫,夹具文件改名后锚点必须随迁,否则守卫会指向不存在的文件。

未验证 / 边界(如实)

  • 未跑全仓 go test ./...(4C8G,磁盘 96%);只跑两个被改包 + 主机复跑 61 条 validate。
  • 未跑 CI 的 PG16/Redis7 集成测试(本机不跑 rootful docker);那两条 migration 测试在本机是既有 SKIP,PR 上由 CI 的集成 job 覆盖。
  • stringPtr / strPtr 两个同义 helper 在拆前就并存,本批未合并(合并会改夹具签名,属行为无关但另一批的事),仅原样搬进 helpers_test.go
  • 净 +205 行是 19 个新文件的 package/import/文件头开销,不是新增测试内容;用例数与断言逐条守恒(见上表)。

关联

round-71 消融/归位批第 3 发。同批:#2288(edge-api handlers_test.go 3792→184)、#2289(docs 死实体)、#2291(projects port 死面 −879 行)、#2292reference/ 墓碑机制 −137 行)、#2293gen/schemas 跟踪结论落盘)。

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: c41eb987-f390-490a-8aa9-0734cd9c5926

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DeliciousBuding
DeliciousBuding enabled auto-merge (squash) September 3, 2026 14:57
DeliciousBuding and others added 2 commits September 3, 2026 22:57
… crud/member/assignment_lifecycle/route_decision/approval/compete/review 7 个域测试文件(13+4+13+9+8+3+1),12 个 Test 并入既有 agent_team_run_test.go、1 个并入 route_helpers_test.go,共享夹具与 mock 类型统一收进 helpers_test.go,原巨型文件删除;Test 名集合 117=117、helper 集合 107=107、=== RUN 180=180、0 SKIP(纯搬家零行为变更)

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
…建 db/device/user/session/message/message_reaction/message_attachment/friendship/notification/attachment/session_member/refresh_token 12 个域测试文件(1+5+4+4+10+4+2+7+3+1+4+2),8 个 Test 并入既有 agent_test.go,shared 夹具 setupSQLite/createTestSession/strPtr 收进新 helpers_test.go,原巨型文件删除;SSOT 锚点 repository_test.go→helpers_test.go(夹具 DDL 随迁);Test 名集合 171=171、helper 集合 58=58、=== RUN 238=238、SKIP 2=2(纯搬家零行为变更)

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant