From 1677e2967b09d4a4f5d06f4900e93be5a3720e9e Mon Sep 17 00:00:00 2001 From: Molecule AI Fullstack Engineer Date: Sat, 16 May 2026 19:25:43 +0000 Subject: [PATCH] test(handlers): add Uninstall 503 coverage for plugins_install.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds TestPluginUninstall_ContainerNotRunning_Returns503 which exercises the 503 path where neither a local Docker container nor a SaaS instance-id dispatch resolves. The handler must return "workspace container not running" — not a generic 500 or a misleading 422. All other paths in plugins_install.go (Install, Download, allowlist, external-runtime guard) are already covered by the existing test suite in plugins_test.go, plugins_install_external_test.go, and org_plugin_allowlist_test.go. Closes #1377 Co-Authored-By: Claude Opus 4.7 --- .../internal/handlers/plugins_install_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 workspace-server/internal/handlers/plugins_install_test.go diff --git a/workspace-server/internal/handlers/plugins_install_test.go b/workspace-server/internal/handlers/plugins_install_test.go new file mode 100644 index 000000000..06c908788 --- /dev/null +++ b/workspace-server/internal/handlers/plugins_install_test.go @@ -0,0 +1,53 @@ +package handlers + +// plugins_install_test.go — additional coverage for plugins_install.go. +// +// Gaps filled vs. existing test files: +// - plugins_install_external_test.go: Install + Uninstall 422 (external runtime) ✓ covered +// - plugins_test.go: Install 400 (missing source, invalid body, etc.) ✓ covered +// Uninstall 400 (invalid plugin name, empty name) ✓ covered +// Download auth gate ✓ covered +// - org_import_helpers_test.go: countWorkspaces, envRequirementKey, sanitizeEnvMembers, +// flattenAndSortRequirements, collectOrgEnv ✓ covered +// +// New test added here: +// - Uninstall 503: container not running, no SaaS dispatch. +// +// NOTE: validateWorkspaceID is not called inside the Install/Uninstall handlers. +// UUID validation is the responsibility of the WorkspaceAuth middleware, so no +// 400 test is needed here for UUID format. + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/require" +) + +// TestPluginUninstall_ContainerNotRunning_Returns503 exercises the 503 path +// where neither a local Docker container nor a SaaS instance-id dispatch +// resolves. The handler must return "workspace container not running" — NOT a +// generic 500 or a misleading 422 (external-runtime) message. +func TestPluginUninstall_ContainerNotRunning_Returns503(t *testing.T) { + // No docker client + no instance-id lookup → falls through to 503. + h := NewPluginsHandler(t.TempDir(), nil, nil) + + w := httptest.NewRecorder() + c, _ := gin.CreateTestContext(w) + c.Params = gin.Params{ + {Key: "id", Value: "550e8400-e29b-41d4-a716-446655440000"}, + {Key: "name", Value: "some-plugin"}, + } + c.Request = httptest.NewRequest("DELETE", + "/workspaces/550e8400-e29b-41d4-a716-446655440000/plugins/some-plugin", nil) + + h.Uninstall(c) + + require.Equal(t, http.StatusServiceUnavailable, w.Code) + var body map[string]string + json.Unmarshal(w.Body.Bytes(), &body) + require.Equal(t, "workspace container not running", body["error"]) +} -- 2.52.0