Skip to content

Disambiguate test source path resolution#201

Merged
mkutz merged 4 commits intomainfrom
200-inventory-should-reference-approved-files-from-src
Feb 23, 2026
Merged

Disambiguate test source path resolution#201
mkutz merged 4 commits intomainfrom
200-inventory-should-reference-approved-files-from-src

Conversation

@mkutz
Copy link
Owner

@mkutz mkutz commented Feb 23, 2026

Summary

  • Exclude bin and out directories from test source file search (fixes IntelliJ copying sources into bin)
  • Prefer paths containing src when multiple matches are found, resolving ambiguity from output directories not explicitly excluded
  • Throw a descriptive error when the source file location is still ambiguous after filtering

Closes #200

Test plan

  • Existing tests for build and target exclusion still pass
  • New test for bin directory exclusion
  • New test for src path preference when multiple matches exist
  • New test for ambiguous paths (multiple src matches) throwing error
  • New test for missing source file throwing error

Exclude bin and out directories from file search and prefer
paths containing "src" when multiple matches are found.
Throw an error when the source file location is still ambiguous.

Closes #200
Copilot AI review requested due to automatic review settings February 23, 2026 14:50
@mkutz mkutz linked an issue Feb 23, 2026 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #200 where test source files were sometimes incorrectly referenced from build output directories (like bin) instead of actual source directories. The solution adds exclusions for bin and out directories, implements a disambiguation strategy that prefers paths containing src, and provides clear error messages when the source file cannot be found or is ambiguous.

Changes:

  • Extended the directory exclusion regex pattern to exclude bin and out directories in addition to build and target
  • Replaced the "first match wins" strategy with a comprehensive disambiguation approach that collects all matches and prefers paths containing src when multiple matches exist
  • Added descriptive error handling for missing and ambiguous source file scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
modules/core/src/main/java/org/approvej/approve/StackTraceTestFinderUtil.java Updated path filtering regex to exclude bin and out directories; replaced simple first-match logic with disambiguation strategy that prefers src paths
modules/core/src/test/java/org/approvej/approve/StackTraceTestFinderUtilTest.java Added comprehensive tests for bin directory exclusion, missing source files, src path preference, and ambiguous path scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Use path separator in negative lookahead to avoid excluding
directories that merely start with excluded names. Include
src match count in ambiguity error message. Add out directory
to parameterized test.
Copilot AI review requested due to automatic review settings February 23, 2026 15:03
@sonarqubecloud
Copy link

@mkutz mkutz merged commit 82bd8cf into main Feb 23, 2026
7 checks passed
@mkutz mkutz deleted the 200-inventory-should-reference-approved-files-from-src branch February 23, 2026 15:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +90 to +91
"Found multiple test source files (%d contain 'src'): %s"
.formatted(srcMatches.size(), matches));
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

The error message indicates how many paths contain 'src' but then shows all matches. This could be confusing if srcMatches.size() differs from matches.size(). Consider either showing only srcMatches in the error message, or clarifying that all matches are being shown. For example: "Found multiple test source files (%d total, %d contain 'src'): %s".formatted(matches.size(), srcMatches.size(), matches)

Suggested change
"Found multiple test source files (%d contain 'src'): %s"
.formatted(srcMatches.size(), matches));
"Found multiple test source files (%d total, %d contain 'src'): %s"
.formatted(matches.size(), srcMatches.size(), matches));

Copilot uses AI. Check for mistakes.
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.

Inventory should reference approved files from src

2 participants