Skip to content

refactor(testkit): 消融两层纯转发 shim——删掉 edge/hub internal/testkit 里只把 WaitFor/Eventually 原样转给 pkg/testkit 的 2×25 行复制层,11 个测试文件 import 直指 pkg/testkit(净 −44 行、−1 包) - #2283

Merged
DeliciousBuding merged 1 commit into
masterfrom
refactor/testkit-shim
Sep 3, 2026

Conversation

@DeliciousBuding

Copy link
Copy Markdown
Collaborator

做了什么

消融两层纯转发 shim(round-70 过度抽象轴):

删除 事实依据
edge-server/internal/testkit/eventually.go(25 行,整包消失) 包内只有 WaitFor/Eventually 两个函数,函数体各一行原样转给 pkg/testkit;0 自有行为、0 测试
hub-server/internal/testkit/eventually.go(25 行) 同上;该包剩下的 resp.go 是 Hub 专有的 APIResponse 夹具(真实共享代码,保留)

11 个测试文件只把 import 路径从 <server>/internal/testkit 换成 pkg/testkit调用点一字未改(两边包名都叫 testkit)。

判定标准(本 PR 用的剃刀):1 个真实现 + 1 个 mock 是合理可测性,不算过度抽象;0 行为、0 测试、只把调用原样搬到另一个包的间接层才是。 这两层属于后者——它们存在的唯一理由写在注释里("callers keep their existing testkit.* imports"),即为兼容旧 import 路径而保留的复制层,pkg/testkit#1550)落地后就已经是死重量。

顺带修的两处手抄分岔(round-69 教训:删了实现却留下指向它的注释):

  • hub-server/internal/testkit/resp.go:包 doc 原本写在被删的 eventually.go 里,删完包变成无 doc,已补回并写明该包现在只装 Hub 专有夹具。
  • pkg/testkit/eventually.go:注释声称 "was duplicated verbatim in hub/edge internal/testkit",现副本已不存在,改为陈述现状。

−44 行、−1 个包(15 files changed, 19 insertions(+), 63 deletions(-))。

证据(本机 huawei-dev 实跑)

$ cd edge-server && go build ./... ; echo $?   → 0
$ cd edge-server && go vet ./...   ; echo $?   → 0
$ cd hub-server  && go build ./... ; echo $?   → 0
$ cd hub-server  && go vet ./...   ; echo $?   → 0   # 含 tests/{integration,oidc,scenarios,teamrun},即 APIResponse 的 4 个消费方仍可编译

$ go test ./internal/events/... ./internal/hub/... ./internal/lifecycle/...
ok  edge-server/internal/events     3.590s
ok  edge-server/internal/hub        26.113s
ok  edge-server/internal/lifecycle  17.110s

$ go test ./internal/service/agent/... ./internal/service/contact/... ./internal/service/session/... ./internal/ws/... ./internal/testkit/...
ok  hub-server/internal/service/agent     8.471s
ok  hub-server/internal/service/contact   0.153s
ok  hub-server/internal/service/session   0.383s
ok  hub-server/internal/ws                12.397s
?   hub-server/internal/testkit           [no test files]

覆盖到全部 11 个改过 import 的文件所属包(edge 6 个文件分布在 events/hub/lifecycle/tests;hub 5 个分布在 service/agent、service/contact、service/session、ws)。edge-server/tests/hub_e2e_test.go 与 hub tests/**go vet ./... 保证编译通过(它们需要真实 Hub/PG,属 L1/L2,不在本 PR 的 L0 门禁内跑)。

残留引用核查:git grep "edge-server/internal/testkit" = 0 命中(只剩 pkg/testkit 注释里已订正的历史说明)。

Negative constraints(本 PR 没做也不该做)

  • 没动 pkg/testkit/oidcfixture(169 行,5 个真实消费方,是共享夹具不是间接层)。
  • 没拆 hub-server/internal/{handler,repository} 域子包、没拆 edge-server/internal/lifecycle(19k 行是 god type 不是 god package,拆类型属设计项目)。
  • 没合并 dispatch/dispatchsvc(单向依赖 + 双 doc.go 明写勿合)。
  • 41 个单文件 Go 包绝大多数是按域切的正常结构,未做无差别合并。

…tFor/Eventually 原样转给 pkg/testkit(2×25 行 0 自有行为 0 测试),删掉后 11 个测试文件的 import 直指 pkg/testkit、调用点一字未改;hub internal/testkit 只剩 Hub 专有的 APIResponse 夹具并补回被 shim 带走的包 doc,pkg/testkit 里指向已删副本的过期注释同步订正(净 −44 行、−1 包)

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
@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: 702d3a0c-4cff-4009-aa85-e95b760bfbb5

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.

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