From 75ea8aa0cbe0276c50b942de46007a63bad33303 Mon Sep 17 00:00:00 2001 From: "elvandlie@gmail.com" Date: Sat, 9 May 2026 21:05:31 +0700 Subject: [PATCH] cmd/mcp_test: use t.Setenv to prevent env var leak across tests TestMCP_StartWriteable sets FUNC_ENABLE_MCP_WRITE via os.Setenv but never cleans it up. Since Go runs all tests in a package within the same process, this leaked env var persists for subsequent tests. Replace os.Setenv with t.Setenv, which automatically restores the original value when the test finishes. Remove the now-unused os import. Fixes #3686 Signed-off-by: elvandlie@gmail.com --- cmd/mcp_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/mcp_test.go b/cmd/mcp_test.go index 74ffd41f8e..7ee8ef2608 100644 --- a/cmd/mcp_test.go +++ b/cmd/mcp_test.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "os" "testing" fn "knative.dev/func/pkg/functions" @@ -51,7 +50,7 @@ func TestMCP_StartWriteable(t *testing.T) { } // Ensure it is set to true on proper truthy value - _ = os.Setenv("FUNC_ENABLE_MCP_WRITE", "true") + t.Setenv("FUNC_ENABLE_MCP_WRITE", "true") server = mock.NewMCPServer() server.StartFn = func(_ context.Context, writeEnabled bool) error { if !writeEnabled {