From a76e3ce47aa4802b02178567573e50e032ee7923 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 15 Oct 2026 15:25:21 +0200 Subject: [PATCH] test(reconcile): assert the dependent of the selection is recreated too The narrowed-selection test only checked the selected service itself, so a plan silently dropping its dependent would have passed. Also match the disabled service by its resource prefix rather than a substring, and drop the drifted image setup that force recreate made irrelevant. Signed-off-by: Nicolas De Loof --- pkg/compose/reconcile_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/compose/reconcile_test.go b/pkg/compose/reconcile_test.go index 609139ff6..5e2e00f40 100644 --- a/pkg/compose/reconcile_test.go +++ b/pkg/compose/reconcile_test.go @@ -2202,21 +2202,19 @@ func TestReconcile_SelectionLeavesOtherServicesUntouched(t *testing.T) { assert.DeepEqual(t, project.ServiceNames(), []string{"web", "worker"}) assert.DeepEqual(t, project.DisabledServiceNames(), []string{"api"}) - // api's live container was created from a configuration that has since - // drifted: it would be recreated if it were part of the plan - driftedAPI := apiSvc - driftedAPI.Image = "stale" observed := &ObservedState{ ProjectName: "myproject", Containers: map[string][]ObservedContainer{ "web": {runningContainer(t, web, "c1aabbccddee")}, "worker": {runningContainer(t, worker, "c2aabbccddee")}, - "api": {runningContainer(t, driftedAPI, "c3aabbccddee")}, + "api": {runningContainer(t, apiSvc, "c3aabbccddee")}, }, Networks: map[string][]ObservedNetwork{}, Volumes: map[string][]ObservedVolume{}, } + // force recreate rebuilds every service of the plan: api would be + // recreated too if the narrowing ever stopped keeping it out opts := defaultReconcileOptions() opts.Recreate = api.RecreateForce opts.RemoveOrphans = true @@ -2225,11 +2223,12 @@ func TestReconcile_SelectionLeavesOtherServicesUntouched(t *testing.T) { recreated := map[string]bool{} for _, node := range plan.Nodes { - assert.Assert(t, !strings.Contains(node.Operation.ResourceID, "api") && !strings.HasPrefix(node.Operation.ResourceID, "orphan:"), + assert.Assert(t, !strings.HasPrefix(node.Operation.ResourceID, "service:api:") && !strings.HasPrefix(node.Operation.ResourceID, "orphan:"), "a service outside the selection must not be touched:\n%s", plan.String()) recreated[node.Operation.ResourceID] = true } assert.Assert(t, recreated["service:web:1"], "the selected service must be recreated:\n%s", plan.String()) + assert.Assert(t, recreated["service:worker:1"], "a dependent of the selected service must be recreated too:\n%s", plan.String()) } func runningContainer(t *testing.T, svc types.ServiceConfig, id string) ObservedContainer {