fix(pluginhub): allow uninstalling failed container plugins when docker is unavailable

This commit is contained in:
Sycun 2026-11-28 21:09:12 +08:00
parent 5ae0d91ba8
commit 8e0694b594
2 changed files with 22 additions and 1 deletions

View File

@ -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())

View File

@ -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) {