Skip to content

fix(test): restore the CLI output globals after every test that sets them - #1233

Merged
Dumbris merged 1 commit into
mainfrom
fix/cli-output-globals-test-isolation
Sep 9, 2026
Merged

fix(test): restore the CLI output globals after every test that sets them#1233
Dumbris merged 1 commit into
mainfrom
fix/cli-output-globals-test-isolation

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 9, 2026

Copy link
Copy Markdown
Member

What the shuffle lane found

The advisory Unit Tests (shuffle) lane from #1230 went red on its first unrelated PR (#1232, docs only). That is the lane working as intended.

globalOutputFormat and globalJSONOutput are package-level flag targets in cmd/mcpproxy. Fifteen tests assigned them and never restored, so whichever ran last left its choice installed for the rest of the test binary. In file order that is invisible. Under -shuffle=on it is not: TestVersionCommandTableOutput and TestOutputActivityError_TableFormat both render through clioutput.ResolveFormat and assert the default table output, so an inherited "json" fails them.

Reproduce on origin/main:

go test -count=1 -shuffle=1788937037978355714 ./cmd/mcpproxy/
--- FAIL: TestVersionCommandTableOutput (0.00s)
    version_cmd_test.go:28: table output should start with "MCPProxy v0.1.0 (personal) linux/amd64", got: "{\n  \"version\": ...
--- FAIL: TestOutputActivityError_TableFormat (0.00s)

Same class as #1222 (registry fixtures leaking the SSRF allow-policy) and the BlockedValues leak fixed in #1230, different global.

The fix

Adds setOutputGlobals(t, format, jsonOut) in a new cmd/mcpproxy/output_globals_test.go: it saves the pair and restores it from t.Cleanup, so a failing or panicking test still restores. All fifteen bare assignment sites route through it (3 in tools_cmd_test.go, 12 in upstream_cmd_test.go). The sites that already saved and restored by hand are left alone. No production code changes; no test's intended format changes.

TestSetOutputGlobalsRestores pins the restore half, so removing the t.Cleanup fails a test rather than only showing up as a shuffled-order surprise later.

Verification

Check Result
Seed 1788937037978355714 on origin/main fails both tests
Same seed on this branch ok
go test -count=1 -race -shuffle=on ./cmd/mcpproxy/ × 5 5 × ok
golangci-lint v2, .github/.golangci.yml, ./cmd/mcpproxy/... 0 issues

Follow-up, not touched here

cmd/mcpproxy/activity_cmd_test.go is already unformatted on origin/main (gofmt -l flags it before and after this change). Left alone to keep this diff to the one problem.

…them

The shuffle lane added in #1230 went red on its first unrelated PR, which is
what it is for.

globalOutputFormat and globalJSONOutput are package-level flag targets in
cmd/mcpproxy. Fifteen tests assigned them and never restored, so whichever
ran last left its choice installed for the rest of the binary. In file order
that is invisible. Under -shuffle=on it is not: TestVersionCommandTableOutput
and TestOutputActivityError_TableFormat both render through
clioutput.ResolveFormat and assert the default table output, so an inherited
"json" fails them. Seed 1788937037978355714 reproduces both on origin/main.

Adds setOutputGlobals(t, format, jsonOut), which saves the pair and restores
it from t.Cleanup, and routes all fifteen sites through it. The sites that
already saved and restored by hand are left alone. No production code
changes, and no test's intended format changes.

Verified: the CI seed fails on main and passes here; five fresh
-race -shuffle=on runs of the package are green; golangci-lint v2 with the
CI config reports 0 issues.

Note for a follow-up, not touched here: cmd/mcpproxy/activity_cmd_test.go is
already unformatted on origin/main.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 20fa67c
Status: ✅  Deploy successful!
Preview URL: https://db9c2eab.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-cli-output-globals-test.mcpproxy-docs.pages.dev

View logs

@Dumbris
Dumbris enabled auto-merge (squash) September 9, 2026 07:09
@Dumbris
Dumbris merged commit 774d5be into main Sep 9, 2026
37 of 38 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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