From 8e0694b5942013861caea6ea84b879299f154f10 Mon Sep 17 00:00:00 2001 From: Sycun <165354365+Sycun@users.noreply.github.com> Date: Sat, 28 Nov 2026 21:09:12 +0800 Subject: [PATCH] fix(pluginhub): allow uninstalling failed container plugins when docker is unavailable --- internal/pluginhub/runner/docker.go | 7 ++++++- internal/pluginhub/runner/docker_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/pluginhub/runner/docker.go b/internal/pluginhub/runner/docker.go index 15175109..4303df1e 100644 --- a/internal/pluginhub/runner/docker.go +++ b/internal/pluginhub/runner/docker.go @@ -660,6 +660,11 @@ func (d *Docker) Stop(ctx context.Context, spec Spec) error { if err != nil { return err } + if _, statErr := os.Stat(spec.VersionDir()); errors.Is(statErr, os.ErrNotExist) { + // Prepare() only creates VersionDir() after verifying Docker and pulling images. + // When it is absent, no container or managed Docker network was ever created. + return nil + } for _, s := range stopOrder(distribution.Services) { item, err := d.find(ctx, serviceName(spec, s.Name), spec) if err != nil { @@ -764,7 +769,7 @@ func (d *Docker) ensureNetwork(ctx context.Context, spec Spec, network managedNe } func (d *Docker) Remove(ctx context.Context, spec Spec) error { - if err := d.Stop(ctx, spec); err != nil { + if err := d.Stop(ctx, spec); err != nil && !errors.Is(err, exec.ErrNotFound) { return err } return os.RemoveAll(spec.VersionDir()) diff --git a/internal/pluginhub/runner/docker_test.go b/internal/pluginhub/runner/docker_test.go index 009b75a9..926f0ec7 100644 --- a/internal/pluginhub/runner/docker_test.go +++ b/internal/pluginhub/runner/docker_test.go @@ -215,6 +215,22 @@ func TestPluginDockerMissingCLIReportsGuidance(t *testing.T) { if probe := d.Probe(context.Background(), "strict"); probe.Available || probe.Guidance == "" { t.Fatalf("probe %+v", probe) } + spec := Spec{ + InstallID: uuid.NewString(), + VersionID: uuid.NewString(), + Root: t.TempDir(), + Declaration: &manifest.Declaration{ + Distribution: []manifest.Distribution{{ + Type: "container", + Mode: "docker", + Services: []manifest.Service{{Name: "web", Role: "web", ContainerPort: 80}}, + }}, + }, + Plan: &manifest.InstallPlan{Artifact: manifest.Artifact{Driver: "container"}}, + } + if err := d.Remove(context.Background(), spec); err != nil { + t.Fatalf("expected uninstall of never-prepared container plugin to succeed without docker: %v", err) + } } func TestPluginRuntimeLogRedactsBearerJSONAndDSN(t *testing.T) {