Skip to content

refactor(hub): service public_stats 归组子包(#1761 首个增量) - #1768

Open
DeliciousBuding wants to merge 2 commits into
masterfrom
simp/hub-service-grouping
Open

refactor(hub): service public_stats 归组子包(#1761 首个增量)#1768
DeliciousBuding wants to merge 2 commits into
masterfrom
simp/hub-service-grouping

Conversation

@DeliciousBuding

@DeliciousBuding DeliciousBuding commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

变更内容(#1761 首个安全增量)

hub-server/internal/service/public_stats.go 提取为子包 internal/service/publicstats/,沿用既有子包模式(agentevent/deliveryoutbox/dispatchsvc/:doc.go + 原文件仅改 package 子句)。类型名与方法签名保持不变(PublicStatsService.GetStats),纯目录归组,无行为变更

同步更新的外部消费者仅 3 处:

  • internal/app/wiring.go(构造调用 + import)
  • internal/handler/public.go(字段与构造参数类型限定符)
  • internal/handler/public_test.go(构造调用 + import)

耦合分析(为何选 public_stats)

对 11 个候选文件统计与扁平 service 包的双向依赖(引用兄弟符号数 / 被兄弟引用数):

候选 引用兄弟 被兄弟引用 结论
public_stats.go 0 0 ✅ 本次提取
image_meta.go 0 0 零耦合,但仅是单个 helper 函数,非服务域
user_settings.go 0 0 零耦合,下一批候选
skill.go / mcp_server.go 0 0 零耦合,下一批候选
notification.go 0 0 零耦合,但被 app/events.go 深度消费
device.go 0 0 本地接口桥接 execution_target,建议与之同批
document.go 0 0 零耦合,体量较大(272 行)
audit.go 0 0 零耦合,但带生命周期/metrics/3 个测试文件
execution_target.go 0(但 import dispatch 子包 + egress) 0(dispatch/ 仅注释提及;device.go 以接口消费) 需与 dispatch 子包、device 协调顺序
relay.go 0 2(agent.go、dispatch_adapters.go) 与 agent/dispatch 耦合

public_stats 是零耦合候选中最完整的"服务域"(struct + 构造器 + 方法,经 app 组装被 handler 消费),且无生命周期钩子、无接口注入、router 层零引用 —— 首增量风险最小。

验证(全部通过)

cd hub-server && go build ./... && go vet ./... && go test ./internal/service/... -short
  • go build ./...
  • go vet ./...
  • go test ./internal/service/... -short ✅(14 个包全绿)
  • 额外:go test ./internal/handler/ -run TestPublicStats

剩余域(后续增量建议)

  • 下一批最易:user_settings、skill、mcp_server(同样零耦合,纯 handler/wiring 消费者)
  • 中等:image_meta(归入 attachment 域需先理清 attachment.go vs attachment/ 现状)、notification(app/events.go 消费点较多)、document、audit(带 Shutdown 生命周期)、device + execution_target(registrar 接口桥接,建议同批)
  • 受阻/最后:relay(被 agent.go、dispatch_adapters.go 引用)、agent 域全家桶(与 relay/dispatch/seqalloc 重耦合,按 [P2] hub-server:internal/service 平铺文件按域归组子包 #1761 计划最后处理)

将 internal/service/public_stats.go 提取为 internal/service/publicstats/ 子包,
沿用 agentevent/、deliveryoutbox/ 等既有子包模式(doc.go + 原文件改 package 子句)。

选择 public_stats 的原因:耦合分析显示它与扁平 service 包的双向依赖均为 0 ——
不引用任何兄弟文件符号,也未被任何兄弟文件引用;外部消费者仅 3 处
(app/wiring.go、handler/public.go、handler/public_test.go),无生命周期钩子、
无接口注入、router 层零引用,是最安全的首个增量。

类型与方法签名保持不变(PublicStatsService.GetStats),纯归组无行为变更。
验证:go build ./... && go vet ./... && go test ./internal/service/... -short 全绿。

Co-authored-by: Cursor <cursor@vectorcontrol.tech>
@DeliciousBuding DeliciousBuding added go Pull requests that update go code P2 Medium priority lane-A Lane A cleanup-baseline AgentHub cleanup baseline program labels Aug 18, 2026
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@DeliciousBuding, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e901d16-440f-4534-81bc-9f77478cba22

📥 Commits

Reviewing files that changed from the base of the PR and between 5f57cac and 79f240f.

📒 Files selected for processing (1)
  • hub-server/tests/integration/setup_test.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7aa8f620-197b-4536-80dd-5732405446f5

📥 Commits

Reviewing files that changed from the base of the PR and between de446df and 5f57cac.

📒 Files selected for processing (5)
  • hub-server/internal/app/wiring.go
  • hub-server/internal/handler/public.go
  • hub-server/internal/handler/public_test.go
  • hub-server/internal/service/publicstats/doc.go
  • hub-server/internal/service/publicstats/public_stats.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The public statistics service now resides in the publicstats package. Application wiring, PublicHandler, and the handler test use the new package path and constructor.

Changes

Public statistics package migration

Layer / File(s) Summary
Define the publicstats package
hub-server/internal/service/publicstats/*
The service implementation now declares the publicstats package. Package documentation was added.
Update service integration
hub-server/internal/app/wiring.go, hub-server/internal/handler/public.go, hub-server/internal/handler/public_test.go
Application wiring, PublicHandler, and its test now import and construct PublicStatsService from internal/service/publicstats.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5f57c

This change only reorganizes the public statistics service and updates its consumers without changing behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了将 public_stats 服务归组到子包的主要重构变更。
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch simp/hub-service-grouping

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.

public_stats 归组为 service/publicstats 子包后,tests/integration/setup_test.go
仍引用旧的 service.NewPublicStatsService,导致 Backend integration 编译失败。
更新为 publicstats.NewPublicStatsService 并按字母序补 import。

验证:go test -c -tags integration 编译通过;go build/vet ./... 全绿;
go test ./internal/service/... -short 全绿。

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

cleanup-baseline AgentHub cleanup baseline program go Pull requests that update go code lane-A Lane A P2 Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant