Skip to content

fix(maven): find tests under a relative <testSourceDirectory> - #317

Merged
adityankale190895 merged 2 commits into
DiffCI:mainfrom
sarankumar1325:maven-test-source-dir
Nov 18, 2026
Merged

adityankale190895 merged 2 commits into
DiffCI:mainfrom
sarankumar1325:maven-test-source-dir

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Fixes #163

Changed behavior

  • A module whose only customization is <testSourceDirectory> now has its tests discovered under that directory, and it no longer gets the custom source roots require full validation blocker. The Surefire/Failsafe basename rules are unchanged. src/test/kotlin still counts. Once the Java test root moves, test-named files left under src/test/java are no longer treated as tests, because Maven wouldn't compile them.
  • Java/Kotlin files under the resolved test root are counted as module sources, so changes there map to the module.
  • A custom <sourceDirectory> still falls back, as before.
  • A <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:
    • contains ${…} (for example ${project.basedir}/tests),
    • is absolute or starts with a Windows drive,
    • contains a backslash,
    • resolves to the module root or outside it (..),
    • is declared more than once with different values (for example a profile that overrides it).
  • The Maven fallback table in docs/using-diffci.md describes the narrower trigger.

Validation

  • tests/repo/maven-test-source-directory.test.ts is new. It uses synthetic reactor fixtures:
    • tests, ./tests/ and src/it/../../tests resolve. A library change selects the test under the custom root and does not fall back.
    • A stale src/test/java/...Test.java is ignored once the root moves.
    • <sourceDirectory> plus a resolvable test root still falls back.
    • A property, an absolute path, a Windows drive, a backslash, a path outside the module, the module root itself, and two different declarations each fall back.
  • The testSourceDirectory case in tests/repo/language-adapters.test.ts now uses ${project.basedir}/tests, so it still covers the fallback path.
  • Mutation-checked: removing each guard in resolveTestRoot, the source-inclusion rule, the test-root check in isTest, or the blocker condition makes at least one test fail.
  • npm test: 1300 pass, 0 fail. npm run typecheck, npm run build and npm run audit:boundary pass; the new test file is added to release-files.json.

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T07:05:24.878127Z 2355b0f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/repo/adapters/maven.ts Outdated
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")),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@adityankale190895

Copy link
Copy Markdown
Member

Thanks, the path guards and the tests are thorough. Codex's two P1s reproduce, and both are regressions from main, where they fell back:

  1. Profile-only declaration. tags() also reads <testSourceDirectory> inside <profiles>, so a declaration in a profile that isn't active becomes the module's root, and src/test/java tests are dropped with no blocker. Please fall back whenever a <testSourceDirectory> appears inside <profiles>, until active profiles are resolved.
  2. Inherited root. A local parent that sets <testSourceDirectory> no longer blocks, but its children keep the default src/test/java, so tests under the inherited root aren't discovered. Either pass the parent's resolved root down to children that don't declare one (Maven resolves it against each child's basedir), or keep the blocker when the declaring POM is a parent of another local POM.

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]>
@adityankale190895
adityankale190895 merged commit bf5d2f5 into DiffCI:main Nov 18, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maven: follow a custom <testSourceDirectory>

2 participants