Skip to content

fix(localnet): keep tests from booting the real shared observability stack - #362

Merged
zheli merged 2 commits into
mainfrom
fix/hermetic-shared-observability-tests
Nov 5, 2026
Merged

zheli merged 2 commits into
mainfrom
fix/hermetic-shared-observability-tests

Conversation

@srikanth-bitdynamics

Copy link
Copy Markdown
Collaborator

Why

TestRunUp_InheritsOptInProfilesOnReup re-ups an instance whose stored profiles include observability, so RunUp probes the shared stack through sharedStackReachable → EnsureSharedStack. The test stubbed the instance compose runner (NewRunner) but not the package var newSharedRunner. Every go test ./internal/localnet/... therefore ran a real docker compose up and left canton-devkit-observability-prometheus and -grafana running, with their compose working_dir in the test's deleted t.TempDir().

The shared project name is fixed (canton-devkit-observability), so this goes beyond leaked containers. An unstubbed test can also:

  • read a developer's real shared stack (DiscoverPort), or
  • tear it down. Stop is -p-only (docker compose -p canton-devkit-observability down --volumes).

What

  • Guard: under go test (testing.Testing()), the default newSharedRunner now returns a runner that refuses Up/Stop/DiscoverPort, unless CANTON_DEVKIT_TEST_ALLOW_SHARED_STACK=1 is set (for a future integration test). Callers treat the refusal like a host without Docker. Those paths are already best-effort.
  • TestRunUp_InheritsOptInProfilesOnReup: stubs newSharedRunner via a new stubSharedRunner(t, …) helper (restored with t.Cleanup). The stub reports the shared stack as unreachable, so RunUp takes the per-instance overlay path, which NewRunner already stubs. TestTeardownSharedStackIfIdle_RefcountGate now uses the same helper.
  • cli/localnet TestObservabilityStatus_TextOff: stubs sharedGrafanaURL. It was running docker compose port grafana 3000 against the shared project.
  • Regression test: TestNewSharedRunner_RefusesDockerUnderGoTest. It checks the runner's type before calling any method, so a regressed guard fails the test without running a real teardown.

Audit

I temporarily instrumented the default runner to log a stack trace on every call and ran go test ./.... Only two tests reached it: the two fixed above. No internal/ui/handlers test reaches RegisterInstanceAndEnsureStack / EnsureSharedStack. SetObservability drives the per-instance project, not the shared one, and its tests never take the docker enable path.

Test plan

  • go test ./internal/localnet/... ./internal/ui/...: passes except TestSpliceMemoryFloors_NeverBelowDockerGate. That test already fails on main (splice.RecommendedMemoryFor("0.9.0") = 0) and is unrelated to this change.
  • make test: same single pre-existing failure.
  • make lint (golangci-lint v2.12.2): 0 issues.
  • docker ps -a --filter name=canton-devkit-observability shows no containers after the runs (Docker 29.2.1 reachable).

srikanth-bitdynamics and others added 2 commits October 22, 2026 15:44
…stack

TestRunUp_InheritsOptInProfilesOnReup re-ups an instance whose stored
profiles include observability, so RunUp probes the shared stack via
EnsureSharedStack. The test stubbed the instance compose runner but not
newSharedRunner, so every `go test ./internal/localnet/...` ran a real
`docker compose up` and left canton-devkit-observability-prometheus and
-grafana running from the test's TempDir.

Because the shared project name is fixed, any unstubbed test can also
discover (DiscoverPort) or tear down (Stop is `-p`-only) a developer's
real shared stack. So beyond stubbing the two tests that reached it:

- newSharedRunner now returns a refusing runner when testing.Testing()
  is true, unless CANTON_DEVKIT_TEST_ALLOW_SHARED_STACK=1. Callers treat
  the refusal like a host without Docker (best-effort paths already
  handle that).
- Add a stubSharedRunner helper and use it in the re-up test (shared
  stack reported unreachable, so RunUp takes the stubbed per-instance
  overlay path) and in the refcount test.
- Stub sharedGrafanaURL in the CLI TestObservabilityStatus_TextOff,
  which was running `docker compose port` against the shared project.
Pick up curated Splice 0.9.0 memory floors (#363) so
TestSpliceMemoryFloors_NeverBelowDockerGate passes in CI.
@zheli
zheli merged commit 072adb8 into main Nov 5, 2026
26 checks passed
@zheli
zheli deleted the fix/hermetic-shared-observability-tests branch November 5, 2026 20:39
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.

2 participants