test(client-proxy): expand unit test coverage across packages#2612
Conversation
PR SummaryMedium Risk Overview Reviewed by Cursor Bugbot for commit 69fc15b. Bugbot is set up for automated code reviews on this repo. Configure here. |
❌ 11 Tests Failed:
View the full list of 12 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Code Review
The metrics registration in NewClientProxy incorrectly swaps the telemetry instruments for server and pool connections, leading to inaccurate monitoring data. The implementation also registers observable metric callbacks that are never unregistered, causing a resource leak and incorrect aggregated metrics when NewClientProxy is invoked multiple times.
There was a problem hiding this comment.
Test-only coverage expansion in client-proxy; the inline nit about a couple of tautological assertions is worth fixing but doesn't block.
Extended reasoning...
Overview
This PR is purely additive test code in packages/client-proxy: a new cfg/model_test.go (env defaults/overrides/invalid-int), info_test.go (ServiceInfo state transitions + concurrent access), paused_sandbox_resumer_grpc_test.go (constructor branches + bufconn-backed Resume/Init/Close), and additions to proxy_test.go (NewClientProxy construction, error-path handler responses, and an errorCatalog fake). No production code changes.
Security risks
None. Test files only, no auth/crypto/permission logic touched. The new gRPC test code uses bufconn and insecure credentials in-process which is appropriate and standard for unit tests.
Level of scrutiny
Low. Coverage-only additions to non-production files; worst case is a flaky or weak test, not runtime risk. Existing tests in the same files follow the same patterns the new ones use.
Other factors
The bug-hunting system flagged a nit about misleading test names (...DuplicateMetricsRegistrationReturnsErrors asserting NoError, comment about 'separate service names' that uses one hard-coded name) and tautological assertions (GreaterOrEqual(CurrentPoolSize(), 0), NotEqual(StatusOK) duplicating an existing stronger assertion). These are real but cosmetic — they don't compromise the correctness of the test suite or the production code. Worth tightening but not worth blocking on, especially given the substantial coverage uplift (internal/cfg 0→100%, internal 0→100%, internal/proxy 40.8→87.7%).
| rr := httptest.NewRecorder() | ||
| p.Handler.ServeHTTP(rr, req) | ||
|
|
||
| require.NotEqual(t, http.StatusOK, rr.Code) | ||
| } | ||
|
|
||
| func TestNewClientProxy_DuplicateMetricsRegistrationReturnsErrors(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| c := catalog.NewMemorySandboxesCatalog() | ||
| ff := newFF(t, true) | ||
|
|
||
| // noop meter provider should not error; this is a sanity test that NewClientProxy | ||
| // works repeatedly for separate service names without leaking metric registrations. |
There was a problem hiding this comment.
🟡 Two newly-added tests in proxy_test.go have misleading names/comments and assertions that don't validate what they claim. TestNewClientProxy_DuplicateMetricsRegistrationReturnsErrors (line 480) asserts require.NoError despite its name claiming 'ReturnsErrors', its comment claims 'separate service names' but the loop hard-codes "service", and noopmetric.NewMeterProvider() cannot surface duplicate-registration errors anyway. TestNewClientProxy_PoolAccessors (line 509) asserts GreaterOrEqual(p.CurrentPoolSize(), 0) which is a tautology on a non-negative count, and its trailing HTTP block duplicates TestNewClientProxy_SandboxNotFoundReturns502 with a strictly weaker NotEqual(StatusOK) assertion. Either rename/rewrite these tests to validate what they claim (e.g. TestNewClientProxy_RepeatedConstruction, exact Equal(0, ...) and Equal(StatusBadGateway, ...) assertions) or drop the redundant pieces.
Extended reasoning...
What's wrong
Two of the new tests in packages/client-proxy/internal/proxy/proxy_test.go have names, comments, and assertions that disagree with what the test bodies actually do. In a PR whose explicit purpose is coverage expansion, this is worth flagging because future readers will reasonably trust that a test named ...DuplicateMetricsRegistrationReturnsErrors is exercising the duplicate-registration error path — and it isn't.
Bug 1: TestNewClientProxy_DuplicateMetricsRegistrationReturnsErrors (lines 474–487)
Three independent contradictions, all in the same ~13-line test:
- Name vs. assertion — function name says
...ReturnsErrors, but the body's only assertion isrequire.NoError(t, err). - Comment vs. body — the comment says 'works repeatedly for separate service names', but every iteration of the
for range 3loop callsNewClientProxy(..., "service", ...)with the same hard-coded name. - No-op provider can't surface what the name promises —
noopmetric.NewMeterProvider()returns a no-op SDK whoseMeter/instrument constructors never report duplicate-registration errors. So even ifNewClientProxyhad a real metric-collision bug on repeated construction, this test could not detect it.
Bug 2: TestNewClientProxy_PoolAccessors (lines 503–518)
Two pieces:
require.GreaterOrEqual(t, p.CurrentPoolSize(), 0)is a tautology.CurrentPoolSize()(packages/shared/pkg/proxy/proxy.go:89) returnsp.pool.Size(), which forwards top.pool.Count()inpool/pool.go:112— a pool count is non-negative by construction. The assertion can never fail in a stable implementation; it asserts no behavioral invariant. On a freshly-constructed proxy, the meaningful claim isEqual(0, p.CurrentPoolSize()).- The trailing HTTP block sends a request and asserts only
require.NotEqual(t, http.StatusOK, rr.Code).TestNewClientProxy_SandboxNotFoundReturns502(lines 391–406) already drives the same request through the same handler with the strictly strongerrequire.Equal(t, http.StatusBadGateway, rr.Code). The block adds no incremental coverage and tolerates handler regressions (e.g. a handler that started returning 500 instead of 502 would still pass). - The leading comment 'Validate the Construction test exercises pool size accessor too' is also grammatically muddled.
Step-by-step proof
For bug 1, consider a hypothetical regression where someone reworks NewClientProxy so it registers a metric twice with the same name. Walk through:
- The test calls
NewClientProxy(noopmetric.NewMeterProvider(), "service", ...)three times. - Each call asks the no-op meter for an instrument;
go.opentelemetry.io/otel/metric/noopalways returns a working no-op instrument and never returns an error from registration. erris therefore alwaysnil, regardless of whether the same name is being registered repeatedly.- The assertion
require.NoError(t, err)passes; the regression goes undetected.
For bug 2, walk through the assertion:
p.CurrentPoolSize()returnsint. The only way it returns a negative number would be a counting bug elsewhere; nothing the test sets up could provoke it.- On a freshly-constructed proxy with no work done, the true invariant is
== 0. The test instead asserts>= 0, which anyintvalue other than negative numbers satisfies — including obviously-broken values like12345.
Addressing the refutation
The refuting verifier correctly notes the submitter acknowledged 'a test-quality issue rather than a bug' and that the test does exercise the constructor and handler paths. That's fair — and is why this is filed as nit, not blocking. But the contradictions in bug 1 (name says one thing, asserts the opposite; comment says one thing, body does another; provider chosen cannot detect what name promises) are not stylistic — they are factual mismatches between what the test claims and what it does. A reader auditing coverage by test name will conclude duplicate-registration is covered when it is not.
Suggested fix
- Rename
TestNewClientProxy_DuplicateMetricsRegistrationReturnsErrorstoTestNewClientProxy_RepeatedConstructionDoesNotError(or wire a real SDK meter provider that surfaces conflicts), fix the comment to say 'same service name', or pass distinct names on each iteration. - In
TestNewClientProxy_PoolAccessors: changeGreaterOrEqual(..., 0)toEqual(0, ...), drop the redundant HTTP block (or strengthen toEqual(StatusBadGateway, ...)), and rewrite the leading comment.
Lifts overall coverage in `packages/client-proxy` significantly by
adding tests for previously untested code paths:
- `internal/cfg`: 0% -> 100%. New `model_test.go` covers `Parse`
defaults, env-var overrides for every field, and an invalid-integer
error case.
- `internal`: 0% -> 100%. New `info_test.go` covers `ServiceInfo`
zero-value, transitions across `Healthy`/`Draining`/`Unhealthy`,
idempotent same-state writes, and a race-safe concurrent get/set
exercise.
- `internal/proxy`: 40.8% -> 87.7%.
- `paused_sandbox_resumer_grpc_test.go` exercises
`NewGRPCPausedSandboxResumer` constructor branches (empty address,
OAuth misconfiguration, insecure and TLS credential paths) and
drives `Resume`/`Init`/`Close` against an in-process `bufconn`
gRPC server, asserting metadata propagation
(`MetadataSandboxRequestPort`, `MetadataTrafficAccessToken`,
`MetadataEnvdAccessToken`), empty-token omission, server-side
error surfacing, and auth-failure short-circuit.
- `proxy_test.go` adds `NewClientProxy` tests covering construction
with a no-op meter provider, idle-timeout wiring, repeated
registration, and end-to-end handler responses for the not-found,
permission-denied, resource-exhausted, still-transitioning, and
invalid-host code paths.
- `proxy_test.go` also adds an `errorCatalog` fake plus
`TestCatalogResolution_CatalogReturnsGenericError` to cover the
previously untested wrapped-error branch in `catalogResolution`
that returns errors other than `ErrSandboxNotFound`.
All new tests pass under `-race`, `go vet ./...` is clean, and
`go build ./...` succeeds.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 69fc15b. Configure here.
| for range 3 { | ||
| _, err := NewClientProxy(noopmetric.NewMeterProvider(), "service", 0, c, nil, ff) | ||
| require.NoError(t, err) | ||
| } |
There was a problem hiding this comment.
Test name contradicts assertions and tests nothing meaningful
Low Severity
TestNewClientProxy_DuplicateMetricsRegistrationReturnsErrors says "ReturnsErrors" but asserts require.NoError. More importantly, it creates a fresh noopmetric.NewMeterProvider() on every iteration, so it never actually tests duplicate registration on a shared provider. The test does not exercise the scenario its name describes.
Reviewed by Cursor Bugbot for commit 69fc15b. Configure here.


Lifts overall coverage in
packages/client-proxysignificantly by adding tests for previously untested code paths:internal/cfg: 0% -> 100%. Newmodel_test.gocoversParsedefaults, env-var overrides for every field, and an invalid-integer error case.internal: 0% -> 100%. Newinfo_test.gocoversServiceInfozero-value, transitions acrossHealthy/Draining/Unhealthy, idempotent same-state writes, and a race-safe concurrent get/set exercise.internal/proxy: 40.8% -> 87.7%.paused_sandbox_resumer_grpc_test.goexercisesNewGRPCPausedSandboxResumerconstructor branches (empty address, OAuth misconfiguration, insecure and TLS credential paths) and drivesResume/Init/Closeagainst an in-processbufconngRPC server, asserting metadata propagation (MetadataSandboxRequestPort,MetadataTrafficAccessToken,MetadataEnvdAccessToken), empty-token omission, server-side error surfacing, and auth-failure short-circuit.proxy_test.goaddsNewClientProxytests covering construction with a no-op meter provider, idle-timeout wiring, repeated registration, and end-to-end handler responses for the not-found, permission-denied, resource-exhausted, still-transitioning, and invalid-host code paths.proxy_test.goalso adds anerrorCatalogfake plusTestCatalogResolution_CatalogReturnsGenericErrorto cover the previously untested wrapped-error branch incatalogResolutionthat returns errors other thanErrSandboxNotFound.All new tests pass under
-race,go vet ./...is clean, andgo build ./...succeeds.