Repository navigation
fix(maven): find tests under a relative <testSourceDirectory> - #317
Conversation
A module whose only customization is a plain relative <testSourceDirectory> inside the module now has its tests discovered there instead of falling back to the full suite. A custom <sourceDirectory>, or a test root that is interpolated, absolute, outside the module or declared more than once, still requires full validation. Fixes DiffCI#163 Signed-off-by: sarankumar1325 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2355b0f502
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java") || | ||
| tags(xml, "testSourceDirectory").some(root => root !== "src/test/java"), | ||
| customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java"), | ||
| testRoot: resolveTestRoot(dir, tags(xml, "testSourceDirectory")), |
There was a problem hiding this comment.
Fail closed for profile-scoped test roots
When a POM declares <testSourceDirectory> only inside a profile that is inactive for the Maven invocation, tags() still supplies that value here and resolveTestRoot treats it as the active root. The actual src/test/java tests are then omitted without a blocker; if another reactor module has discovered tests, the empty-universe fallback will not force full validation, so a dependency change can omit this module's Maven tests. Reject profile-scoped declarations unless the active profiles are resolved.
Useful? React with 👍 / 👎.
|
|
||
| for (const pom of poms) { | ||
| if (pom.customSourceRoots) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`); | ||
| if (pom.customSourceRoots || pom.testRoot === undefined) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`); |
There was a problem hiding this comment.
Preserve fallback for inherited test roots
When a local parent POM sets a custom <testSourceDirectory> that child modules inherit without repeating, this root is accepted and no longer triggers a blocker, while each child is assigned the default src/test/java root. Tests under the inherited root are therefore not discovered; in a reactor with other recognized tests, narrowing can omit the child module's Maven tests. Propagate inherited roots or keep full validation for children whose effective root is unresolved.
Useful? React with 👍 / 👎.
|
Thanks, the path guards and the tests are thorough. Codex's two P1s reproduce, and both are regressions from
Please add a fixture for each, with a library change that must either select the application's test or fall back. Happy to merge once those two fail closed. |
A <testSourceDirectory> inside a profile applies only when the profile is active, and a module without its own declaration inherits the nearest local parent's. Neither is visible to this static adapter, so treat both as unresolved and keep full validation instead of assuming src/test/java. Signed-off-by: sarankumar1325 <[email protected]>
Fixes #163
Changed behavior
<testSourceDirectory>now has its tests discovered under that directory, and it no longer gets thecustom source roots require full validationblocker. The Surefire/Failsafe basename rules are unchanged.src/test/kotlinstill counts. Once the Java test root moves, test-named files left undersrc/test/javaare no longer treated as tests, because Maven wouldn't compile them.<sourceDirectory>still falls back, as before.<testSourceDirectory>is only used when it is a single plain relative path that stays inside the module after normalization. It still falls back (same message, never a guess) when it:${…}(for example${project.basedir}/tests),..),docs/using-diffci.mddescribes the narrower trigger.Validation
tests/repo/maven-test-source-directory.test.tsis new. It uses synthetic reactor fixtures:tests,./tests/andsrc/it/../../testsresolve. A library change selects the test under the custom root and does not fall back.src/test/java/...Test.javais ignored once the root moves.<sourceDirectory>plus a resolvable test root still falls back.testSourceDirectorycase intests/repo/language-adapters.test.tsnow uses${project.basedir}/tests, so it still covers the fallback path.resolveTestRoot, the source-inclusion rule, the test-root check inisTest, or the blocker condition makes at least one test fail.npm test: 1300 pass, 0 fail.npm run typecheck,npm run buildandnpm run audit:boundarypass; the new test file is added torelease-files.json.