Bug
TestMCP_StartWriteable in cmd/mcp_test.go (line 54) sets the FUNC_ENABLE_MCP_WRITE environment variable using os.Setenv but never cleans it up:
_ = os.Setenv("FUNC_ENABLE_MCP_WRITE", "true")
Since Go runs all tests in a package within the same process, this polluted environment variable persists for every subsequent test in the cmd package.
Impact
- Creates a fragile dependency on test execution order
- Running with
go test -shuffle=on could cause flaky failures if a future test checks this variable
- The first assertion in the same test function (testing the default-off behavior, lines 40-51) only passes because it runs before the
Setenv call, not because the env var is actually unset
Fix
Replace os.Setenv with t.Setenv, which automatically restores the original value when the test finishes. This also allows removing the now-unused "os" import.
import (
"context"
- "os"
"testing"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/mock"
. "knative.dev/func/pkg/testing"
)
// Ensure it is set to true on proper truthy value
- _ = os.Setenv("FUNC_ENABLE_MCP_WRITE", "true")
+ t.Setenv("FUNC_ENABLE_MCP_WRITE", "true")
Bug
TestMCP_StartWriteableincmd/mcp_test.go(line 54) sets theFUNC_ENABLE_MCP_WRITEenvironment variable usingos.Setenvbut never cleans it up:Since Go runs all tests in a package within the same process, this polluted environment variable persists for every subsequent test in the
cmdpackage.Impact
go test -shuffle=oncould cause flaky failures if a future test checks this variableSetenvcall, not because the env var is actually unsetFix
Replace
os.Setenvwitht.Setenv, which automatically restores the original value when the test finishes. This also allows removing the now-unused"os"import.import ( "context" - "os" "testing" fn "knative.dev/func/pkg/functions" "knative.dev/func/pkg/mock" . "knative.dev/func/pkg/testing" )