High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix(e2e-runner): buildSharedStack builds only the plans' services and the runner the suite executes (PIN-380)
Luigi Agosticffd99373f71
diff --git a/tests/tools/runner/internal/e2e/e2e_test.go b/tests/tools/runner/internal/e2e/e2e_test.goindex 94d86763..3484c706 100644--- a/tests/tools/runner/internal/e2e/e2e_test.go+++ b/tests/tools/runner/internal/e2e/e2e_test.go@@ -613,7 +613,7 @@ func TestBringUpSharedStackCloakBuildsSupportImagesOnly(t *testing.T) {},}- if code := r.bringUpSharedStack("compose.yml", []string{"pinchtab", "fixtures"}); code != 0 {+ if code := r.bringUpSharedStack("compose.yml", []string{"pinchtab", "fixtures"}, nil); code != 0 {t.Fatalf("bringUpSharedStack returned %d, stderr: %s", code, stderr.String())}@@ -652,7 +652,7 @@ func TestBringUpSharedStackCloakBuildsStockImageForGhostChrome(t *testing.T) {// even under cloak, so the stock pinchtab image must be built or the// `up --no-build` fails with "No such image: e2e-pinchtab:latest".services := []string{"pinchtab", "pinchtab-ghostchrome", "fixtures"}- if code := r.bringUpSharedStack("compose.yml", services); code != 0 {+ if code := r.bringUpSharedStack("compose.yml", services, nil); code != 0 {t.Fatalf("bringUpSharedStack returned %d, stderr: %s", code, stderr.String())}diff --git a/tests/tools/runner/internal/e2e/runner.go b/tests/tools/runner/internal/e2e/runner.goindex 12f952a0..b43337de 100644--- a/tests/tools/runner/internal/e2e/runner.go+++ b/tests/tools/runner/internal/e2e/runner.go@@ -215,7 +215,8 @@ func smokeLane() lane {func (r *Runner) bringUpAndRunPlans(stack string, plans []suitePlan) (codes map[string]int, restartFailed bool, setupCode int) {services := servicesForPlans(plans, []string{"pinchtab", "fixtures"})- if code := r.bringUpSharedStack(stack, services); code != 0 {+ buildServices := servicesToBuild(plans, []string{"pinchtab", "fixtures"})+ if code := r.bringUpSharedStack(stack, services, buildServices); code != 0 {return nil, false, code}@@ -509,7 +510,9 @@ func (r *Runner) runSingle(def suiteDef) int {return 1}plan := suitePlan{def: def, scenarios: scenarios}- if code := r.bringUpSharedStack(def.Compose, servicesForPlans([]suitePlan{plan}, []string{"pinchtab", "fixtures"})); code != 0 {+ plans := []suitePlan{plan}+ fallback := []string{"pinchtab", "fixtures"}+ if code := r.bringUpSharedStack(def.Compose, servicesForPlans(plans, fallback), servicesToBuild(plans, fallback)); code != 0 {_ = r.composeDown(def.Compose)return code}@@ -559,7 +562,7 @@ func (r *Runner) planSuites(defs []suiteDef) ([]suitePlan, int) {return plans, 0}-func (r *Runner) bringUpSharedStack(composeFile string, services []string) int {+func (r *Runner) bringUpSharedStack(composeFile string, services, buildServices []string) int {// Cloak pinchtab services are supplied by the provider override image.// Build support images such as fixtures and runners, but keep compose from// rebuilding the overridden pinchtab services.@@ -579,7 +582,7 @@ func (r *Runner) bringUpSharedStack(composeFile string, services []string) int {return code}} else {- if code := r.buildSharedStack(composeFile); code != 0 {+ if code := r.buildSharedStack(composeFile, buildServices...); code != 0 {return code}}diff --git a/tests/tools/runner/internal/e2e/runner_test.go b/tests/tools/runner/internal/e2e/runner_test.gonew file mode 100644index 00000000..64e17abc--- /dev/null+++ b/tests/tools/runner/internal/e2e/runner_test.go@@ -0,0 +1,90 @@+package e2e++import (+ "bytes"+ "reflect"+ "slices"+ "strings"+ "testing"+)++func planWithServices(def suiteDef, services ...string) suitePlan {+ return suitePlan{def: def, scenarios: []scenarioMeta{{Key: def.Name, Services: services}}}+}++func TestServicesToBuildAddsOnlyTheRunnersThePlansExecute(t *testing.T) {+ fallback := []string{"pinchtab", "fixtures"}+ for _, tc := range []struct {+ name string+ plans []suitePlan+ want []string+ }{+ {+ name: "api builds its runner-api and no cli runner",+ plans: []suitePlan{planWithServices(apiSuite(), "pinchtab", "fixtures")},+ want: []string{"pinchtab", "fixtures", "runner-api"},+ },+ {+ name: "cli builds runner-cli and never runner-api",+ plans: []suitePlan{planWithServices(cliSuite(), "pinchtab", "fixtures")},+ want: []string{"pinchtab", "fixtures", "runner-cli"},+ },+ {+ name: "extended builds both runners and every pinchtab variant the plans need",+ plans: []suitePlan{+ planWithServices(apiExtendedSuite(), "pinchtab", "pinchtab-secure", "fixtures"),+ planWithServices(cliExtendedSuite(), "pinchtab", "fixtures"),+ },+ want: []string{"pinchtab", "pinchtab-secure", "fixtures", "runner-api", "runner-cli"},+ },+ } {+ t.Run(tc.name, func(t *testing.T) {+ got := servicesToBuild(tc.plans, fallback)+ if !reflect.DeepEqual(got, tc.want) {+ t.Fatalf("servicesToBuild = %v, want %v", got, tc.want)+ }+ up := servicesForPlans(tc.plans, fallback)+ for _, runner := range []string{"runner-api", "runner-cli"} {+ if slices.Contains(up, runner) {+ t.Errorf("up service list must not start the runner %q; it is executed via compose run", runner)+ }+ }+ })+ }+}++func TestDryRunBuildsOnlyTheSuiteRunner(t *testing.T) {+ for _, tc := range []struct {+ name string+ suite string+ wantLine string+ wantNoStr string+ }{+ {name: "api", suite: "api", wantLine: "build pinchtab fixtures runner-api", wantNoStr: "runner-cli"},+ {name: "cli", suite: "cli", wantLine: "build pinchtab fixtures runner-cli", wantNoStr: "runner-api"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ var stdout, stderr bytes.Buffer+ if code := Run([]string{"--suite", tc.suite, "--dry-run"}, &stdout, &stderr); code != 0 {+ t.Fatalf("Run returned %d, stderr: %s", code, stderr.String())+ }+ out := stdout.String()+ buildLine := ""+ for _, line := range strings.Split(out, "\n") {+ if strings.Contains(line, "compose") && strings.Contains(line, " build ") {+ buildLine = line+ break+ }+ }+ if buildLine == "" {+ t.Fatalf("no shared-stack build line in dry run:\n%s", out)+ }+ if !strings.Contains(buildLine, tc.wantLine) {+ t.Errorf("build line = %q, want it to contain %q", buildLine, tc.wantLine)+ }+ if strings.Contains(buildLine, tc.wantNoStr) {+ t.Errorf("build line %q must not name %q for the %s suite", buildLine, tc.wantNoStr, tc.suite)+ }+ })+ }+}diff --git a/tests/tools/runner/internal/e2e/suite.go b/tests/tools/runner/internal/e2e/suite.goindex 1a6da444..f5a71699 100644--- a/tests/tools/runner/internal/e2e/suite.go+++ b/tests/tools/runner/internal/e2e/suite.go@@ -294,6 +294,21 @@ func servicesForPlans(plans []suitePlan, fallback []string) []string {return out}+func servicesToBuild(plans []suitePlan, fallback []string) []string {+ services := append([]string(nil), servicesForPlans(plans, fallback)...)+ seen := map[string]bool{}+ for _, svc := range services {+ seen[svc] = true+ }+ for _, plan := range plans {+ if runner := plan.def.Runner; runner != "" && !seen[runner] {+ seen[runner] = true+ services = append(services, runner)+ }+ }+ return services+}+func (r *Runner) showSuiteSkip(suite string) {_, _ = fmt.Fprintf(r.stdout, "Skipping %s: filter %q has no matching scenarios\n", suite, r.args.Filter)}