agent-substrate / agent-substrate/substrate
Centralize the hand-rolled ateapipb.ControlClient test fake
- 主要言語
- Go
- スター
- 1.8k
- フォーク
- 316
- 平均マージ
- 2日 43分
- マージ済み PR(30日)
- 287
説明
### PROBLEM
Five test files hand-roll a fake `ateapipb.ControlClient`, across four packages. #907 adds a sixth,
which is what surfaced this. That PR should land as it stands; consolidating these is follow-up
cleanup, not a prerequisite for it.
Surveyed at [`3f132c6d`](https://github.com/agent-substrate/substrate/commit/3f132c6d25fc50bb3bbd188ef46fa506cb684167) (`main`, 2026-08-17). Links are permalinks pinned to that commit so the line numbers can't drift; the type names are the durable anchor.
| type | package | location | RPCs stubbed |
|---|---|---|---|
| `mockControlClient` | `controllers` | [`actortemplate_controller_test.go:97`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/cmd/atecontroller/internal/controllers/actortemplate_controller_test.go#L97) | `CreateAtespace`, `CreateActor` |
| `healthControlClient` | `router` | [`health_test.go:41`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/cmd/atenet/internal/router/health_test.go#L41) | `ListActors` |
| `mockClient` | `ingress` | [`ingress_test.go:39`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/cmd/atenet/internal/router/ingress/ingress_test.go#L39) | `ResumeActor` |
| `resumerMockClient` | `ingress` | [`resumer_test.go:32`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/cmd/atenet/internal/router/ingress/resumer_test.go#L32) | `ResumeActor` |
| `egressMockClient` | `egress` | [`egress_test.go:197`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/cmd/atenet/internal/router/egress/egress_test.go#L197) | `GetActor` |
The sixth, not yet merged: `fakeControlClient` in `internal/benchmarking/boomer/glutton/fixture_test.go`, package `glutton`, stubbing `CreateAtespace`, `CreateActor`, `ResumeActor`, `SuspendActor`, `DeleteActor`.
The two `ingress` ones live in the same package: the same one-RPC `ResumeActor` fake under two names. Their struct definitions are identical; only the method bodies differ, and `resumerMockClient` nil-guards `resumeFn` where `mockClient` calls it unconditionally.
All six are unexported and live in `_test.go` files, so none is importable. All six use the same idiom: embed `ateapipb.ControlClient` as an anonymous field and override the handful of RPCs the test needs, so calls to any RPC no fake overrides compile and nil-panic at call time.
The union across all six is seven RPCs: `CreateAtespace`, `CreateActor`, `ResumeActor`, `SuspendActor`, `DeleteActor`, `GetActor`, `ListActors`. `ControlClient` declares 28, so one embedding fake needs pluggable func fields for just those seven and inherits the rest.
### PROPOSAL
An exported fake in a non-`_test.go` file under repo-root `internal/`, following the precedent
already set by [`internal/volume/mock.go:52`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/internal/volume/mock.go#L52) (`MockVolumePlugin`, with `NewMockVolumePlugin()` at
[`:55`](https://github.com/agent-substrate/substrate/blob/3f132c6d25fc50bb3bbd188ef46fa506cb684167/internal/volume/mock.go#L55)), which `cmd/ateapi/internal/controlapi/functional_test.go` and `controlapi/volumes_test.go` already call cross-package.
Placement has to be repo-root `internal/`: `cmd//internal/...` is importable only from under
that `cmd/`, and `pkg/proto/ateapipb` is generated. `pkg/` would work mechanically but makes a
test fake part of the public API surface. Put it in a dedicated package rather than an existing production one, so only tests link it and it never reaches a shipped binary.
コントリビューションガイド
評価
この issue はまだ評価されていません。