From 9fc12afdaa79d194d7f697c7b80483756cae69ac Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 1 Jun 2026 18:01:19 +0300 Subject: [PATCH] test(codersdk/toolsdk): use portable echo in WorkspaceSSHExec test (#25840) PowerShell's echo aliases to Write-Output, which rejects -e as an ambiguous parameter and exits 1. Use plain echo with spaces instead. Remove the Windows t.Skip and TestMain exception. TestMain untested-tools check now only fails on full-suite runs. Filtered runs (e.g. -run TestTools) warn instead. Closes CODAGT-518 --- codersdk/toolsdk/toolsdk_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/codersdk/toolsdk/toolsdk_test.go b/codersdk/toolsdk/toolsdk_test.go index 41bb6fe28a..bd4949baaa 100644 --- a/codersdk/toolsdk/toolsdk_test.go +++ b/codersdk/toolsdk/toolsdk_test.go @@ -4,12 +4,12 @@ import ( "context" "database/sql" "encoding/json" + "flag" "fmt" "net/http" "net/http/httptest" "os" "path/filepath" - "runtime" "sort" "sync" "testing" @@ -1048,9 +1048,6 @@ func TestTools(t *testing.T) { }) t.Run("WorkspaceSSHExec", func(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("WorkspaceSSHExec is not supported on Windows") - } // Setup workspace exactly like main SSH tests client, workspace, agentToken := setupWorkspaceForAgent(t, nil) @@ -1076,7 +1073,7 @@ func TestTools(t *testing.T) { // Test output trimming result, err = testTool(t, toolsdk.WorkspaceBash, tb, toolsdk.WorkspaceBashArgs{ Workspace: workspace.Name, - Command: "echo -e '\\n test with whitespace \\n'", + Command: "echo ' test with whitespace '", }) require.NoError(t, err) require.Equal(t, 0, result.ExitCode) @@ -2576,29 +2573,31 @@ func TestMain(m *testing.M) { var untested []string for _, tool := range toolsdk.All { if tested, ok := testedTools.Load(tool.Name); !ok || !tested.(bool) { - // Test is skipped on Windows - if runtime.GOOS == "windows" && tool.Name == "coder_workspace_bash" { - continue - } untested = append(untested, tool.Name) } } if len(untested) > 0 && code == 0 { - code = 1 - println("The following tools were not tested:") + _, _ = fmt.Fprintln(os.Stderr, "The following tools were not tested:") for _, tool := range untested { - println(" - " + tool) + _, _ = fmt.Fprintf(os.Stderr, " - %s\n", tool) + } + _, _ = fmt.Fprintln(os.Stderr, "Please ensure that all tools are tested using testTool().") + _, _ = fmt.Fprintln(os.Stderr, "If you just added a new tool, please add a test for it.") + // Only fail when the full suite ran. When -run filters to a + // subset (e.g. CI flake checks use -run ^TestTools), tools + // covered by other top-level functions appear untested. + if f := flag.Lookup("test.run"); f == nil || f.Value.String() == "" { + code = 1 + } else { + _, _ = fmt.Fprintln(os.Stderr, "NOTE: if you just ran an individual test, this is expected.") } - println("Please ensure that all tools are tested using testTool().") - println("If you just added a new tool, please add a test for it.") - println("NOTE: if you just ran an individual test, this is expected.") } // Check for goroutine leaks. Below is adapted from goleak.VerifyTestMain: if code == 0 { if err := goleak.Find(testutil.GoleakOptions...); err != nil { - println("goleak: Errors on successful test run: ", err.Error()) + _, _ = fmt.Fprintln(os.Stderr, "goleak: Errors on successful test run:", err.Error()) code = 1 } }