Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions .github/scripts/plan_local_java_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ def class_fqn(path: str) -> str | None:

def class_header(text: str, name: str) -> str | None:
"""The annotations and declaration of class `name` in a Java source, without comments."""
text = COMMENT.sub(" ", text)
declaration = re.search(rf"\bclass\s+{re.escape(name)}\b", text)
if not declaration:
return None
start = 0
for statement in IMPORT_OR_PACKAGE.finditer(text, 0, declaration.start()):
start = statement.end()
return COMMENT.sub(" ", text[start : declaration.end()])
return text[start : declaration.end()]


def is_pattern(test: str) -> bool:
Expand Down Expand Up @@ -585,26 +586,38 @@ def conditional(self) -> dict[str, str]:
if prop not in self.pom
}

def _integration_test_classes(self) -> dict[str, str]:
prefix = self.it_root + "/"
return {
path[len(prefix) :]: simple_name(path)
def _declared_test_classes(
self, prefix: str, pattern: re.Pattern[str]
) -> dict[str, str]:
candidates = [
path
for path in self.files
if path.startswith(prefix)
and path.endswith(".java")
and IT_CLASS.match(simple_name(path))
and pattern.match(simple_name(path))
]
return {
path: simple_name(path)
for path, text in self._read_all(candidates).items()
if class_header(text, simple_name(path)) is not None
}

def _integration_test_classes(self) -> dict[str, str]:
prefix = self.it_root + "/"
return {
path[len(prefix) :]: name
for path, name in self._declared_test_classes(prefix, IT_CLASS).items()
}

def _unit_test_classes(self) -> dict[str, dict[str, str]]:
modules: dict[str, dict[str, str]] = {}
for module in self.maven["unitTestModules"]:
prefix = f"{module}/src/test/java/"
modules[module] = {
simple_name(path): path
for path in self.files
if path.startswith(prefix)
and path.endswith(".java")
and UNIT_TEST_CLASS.match(simple_name(path))
name: path
for path, name in self._declared_test_classes(
prefix, UNIT_TEST_CLASS
).items()
}
return modules

Expand Down
74 changes: 74 additions & 0 deletions .github/scripts/test_plan_local_java_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,80 @@ def test_classes_no_lane_runs_are_read_from_the_code_and_the_pom() -> None:
assert by_name["TableResourceIT"] not in REPO.never_run


@pytest.mark.parametrize("ref", [None, "HEAD"])
def test_discovery_skips_placeholders_and_keeps_inherited_test_classes(
tmp_path: Path, ref: str | None
) -> None:
def git(*args: str) -> None:
subprocess.run(
[
"git",
"-c",
"core.hooksPath=/dev/null",
"-c",
"commit.gpgsign=false",
"-c",
"user.name=t",
"-c",
"user.email=t@t",
*args,
],
cwd=tmp_path,
check=True,
capture_output=True,
)

sources = {
"Empty": "",
"PackageOnly": "package example;\n",
"TodoOnly": "package example;\n// TODO: Implement {name} extending BaseTest.\n",
"LineComment": "package example;\n// class {name} extends BaseTest {{}}\n",
"BlockComment": "package example;\n/* class {name} extends BaseTest {{}} */\n",
"Inherited": "package example;\nclass {name} extends BaseTest {{}}\n",
}
for prefix, suffix in (
("it/src/test/java/example", "IT"),
("service/src/test/java/example", "Test"),
):
directory = tmp_path / prefix
directory.mkdir(parents=True)
for stem, source in sources.items():
name = stem + suffix
(directory / f"{name}.java").write_text(
source.format(name=name), encoding="utf-8"
)
(tmp_path / "it/pom.xml").write_text("<project/>", encoding="utf-8")
git("init", "-q")
git("add", ".")
git("commit", "-qm", "test sources")

repo = PLANNER.Repo(
tmp_path,
{
"maven": {
"integrationTestModule": "it",
"integrationTestSourceRoot": "it/src/test/java",
"unitTestModules": ["service"],
"lanes": {},
}
},
ref=ref,
)

assert repo.it_classes == {"example/InheritedIT.java": "InheritedIT"}
assert repo.unit_test_classes == {
"service": {"InheritedTest": "service/src/test/java/example/InheritedTest.java"}
}


def test_ai_context_plan_selects_the_mcp_and_llm_service_its() -> None:
_, plan = plan_for(f"{SERVICE}/aicontext/AIContextMarkdown.java")

selected = its(plan)
assert "McpServerResourceIT" in selected
assert "LLMServiceResourceIT" in selected


def test_an_abstract_unit_test_runs_through_the_classes_that_extend_it() -> None:
# Surefire runs SessionStoreContractTest's tests only inside RedisSessionStoreTest and writes
# no report under its name, so selecting it by name failed a step whose tests all passed.
Expand Down
Loading