Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(test-selection): keep --prioritize order in Go runner args (#3341)

nosmile9935ff9b9e612a
diff --git a/packages/core/src/repowise/core/analysis/test_selection.py b/packages/core/src/repowise/core/analysis/test_selection.py
index e7e6210e7..2d6bd85c0 100644
--- a/packages/core/src/repowise/core/analysis/test_selection.py
+++ b/packages/core/src/repowise/core/analysis/test_selection.py
@@ -1309,8 +1309,11 @@ def _pytest_args(selection: Selection) -> list[str]:
def _go_args(selection: Selection) -> list[str]:
go_tests = [f for f in selection.test_files if f.endswith("_test.go")]
- dirs = {str(PurePosixPath(f).parent) for f in go_tests} | set(selection.packages)
- return sorted("." if d == "." else f"./{d}" for d in dirs)
+ dirs = list(dict.fromkeys(str(PurePosixPath(f).parent) for f in go_tests))
+ for package in selection.packages:
+ if package not in dirs:
+ dirs.append(package)
+ return ["." if d == "." else f"./{d}" for d in dirs]
def _jest_args(selection: Selection) -> list[str]:
diff --git a/tests/unit/analysis/test_test_selection.py b/tests/unit/analysis/test_test_selection.py
index a6b389853..5d21b65a6 100644
--- a/tests/unit/analysis/test_test_selection.py
+++ b/tests/unit/analysis/test_test_selection.py
@@ -654,6 +654,24 @@ def test_go_gets_each_package_directory_once() -> None:
assert runner_args(sel, "go") == [".", "./pkg/x"]
+def test_go_keeps_ranked_order_of_package_directories() -> None:
+ # --prioritize rewrites test_files in likeliest-to-fail order; the Go
+ # runner must keep that order instead of printing packages alphabetically.
+ sel = _subset(files=("zeta/z_test.go", "alpha/a_test.go", "mid/m_test.go"))
+ assert runner_args(sel, "go") == ["./zeta", "./alpha", "./mid"]
+
+
+def test_go_appends_changed_packages_not_covered_by_test_files() -> None:
+ sel = Selection(
+ run_all=False,
+ reasons=(),
+ tests=("zeta/z_test.go",),
+ test_files=("zeta/z_test.go",),
+ packages=("pkg/q", "zeta"),
+ )
+ assert runner_args(sel, "go") == ["./zeta", "./pkg/q"]
+
+
def test_go_runs_the_package_of_every_changed_go_file_with_tests() -> None:
"""Same-package tests import nothing, so the graph alone can miss them."""
tiers = _tiers(