fix(requirements): RootDirectory honours serenity.test.requirements.basedir (#3733)#3734
Open
GianniGiglio wants to merge 1 commit into
Open
Conversation
…asedir
The Serenity Gradle plugin's AggregateTask wires its `requirementsBaseDir`
DSL field into the `serenity.test.requirements.basedir` system property,
but does not mirror it into `serenity.requirements.dir`. These are two
distinct properties in serenity-core's requirements machinery:
- `serenity.requirements.dir` is consumed by
RootDirectory.featuresOrStoriesRootDirectory() and
getResourceDirectories(), which FileSystemRequirementsTagProvider and
TestOutcomeRequirementsTagProvider ultimately rely on when locating
the feature tree and the outcomes directory.
- `serenity.test.requirements.basedir` is consumed only by
getRootDirectoryPaths() path 1.
For a Gradle multi-module build, the working directory during
`:module:aggregate` is the root project, not the sub-module that owns
the feature files. Without `serenity.requirements.dir` set,
featuresOrStoriesRootDirectory() falls through to a classpath /
working-directory scan that misfires, and the providers ultimately
return an empty requirements tree. BaseRequirementsService
.getRequirementTypes() then returns an empty list, and the
RequirementsReports pipeline silently drops all per-type HTML pages
(requirement_type_theme.html / _capability.html / _feature.html) along
with the theme_*.html / capability_*.html hierarchy and any narratives
from per-directory narrative.md files. The aggregator logs
"Generating test results for N tests" (reporter.outputDirectory is
correct) while simultaneously logging "0 requirements loaded"
(provider roots are wrong), a misleading split-brain state with no
stack trace.
Add a fallback in RootDirectory.featuresOrStoriesRootDirectory(): when
`serenity.requirements.dir` is unset but `serenity.test.requirements
.basedir` points at an existing directory, honour that path. Existing
behaviour (SERENITY_REQUIREMENTS_DIR takes precedence; non-existent
basedir paths are ignored so callers retain the classpath-scan
fallback) is preserved and verified by new tests.
Fixes the scenario where a multi-module Gradle project configures
`serenity { requirementsBaseDir = … }` in the sub-module's
build.gradle.kts and the aggregate report lands on a flat
capabilities.html with no hierarchical navigation.
Refs serenity-bdd#3733
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a fallback in
RootDirectory.featuresOrStoriesRootDirectory()so it honoursserenity.test.requirements.basedirwhenserenity.requirements.diris unset. This makes the existingserenity-gradle-pluginAggregateTaskwiring work for multi-module Gradle builds without asking callers to configure the same path under two property names.Fixes #3733.
Intended effect
For a multi-module Gradle project that puts its feature tree in a sub-module (e.g.
<module>/src/main/resources/features/) and configures:serenity { requirementsBaseDir = file("src/main/resources/features").absolutePath outputDirectory = "build/site/report" }…running
./gradlew :<module>:aggregatewill now load the full requirements tree and emit the usual hierarchical HTML pages (requirement_type_theme.html,requirement_type_capability.html,requirement_type_feature.html,theme_*.html,capability_*.html) plus any narratives from per-directorynarrative.mdfiles.Before this change, the same setup yielded a flat
capabilities.htmlwith no hierarchy and no narratives, while the aggregate log simultaneously reported "Generating test results for 47 tests" and "0 requirements loaded" — becauseFileSystemRequirementsTagProvider's no-arg constructor fell back touser.dir + "/src/test/resources/features"(the root project during:module:aggregate, not the sub-module). Full analysis in #3733.How this was manually tested
On the affected downstream project:
Before the fix, the aggregate log shows:
After the fix (with
SERENITY_TEST_REQUIREMENTS_BASEDIRset by the Gradle plugin, which is already the default wiring):and the report output directory gains ~20 additional HTML files corresponding to the three requirement types and every theme/capability under the feature tree, plus rendered narratives from
narrative.md.Equivalent confirmation by setting
-Dserenity.requirements.dir=<abs path>on the aggregate task on the unpatched build — same outcome — isolates the path resolution as the sole cause.Tests
serenity-model/src/test/java/net/thucydides/model/requirements/WhenFindingTheRootDirectoryForFeatureFiles.javagains three cases, all passing:featuresOrStoriesRootDirectoryFallsBackToTestRequirementsBasedir— the new fallback fires when onlyserenity.test.requirements.basediris set and the path exists.serenityRequirementsDirTakesPrecedenceOverBasedir— guards the existing contract: when both properties are set,serenity.requirements.dirstill wins.basedirFallbackIgnoresNonExistentPaths— stale basedir values do not leak a non-existent path to callers; the classpath/working-directory scan fallback is retained.Local run:
./mvnw -pl serenity-model -Dtest='WhenFindingTheRootDirectoryForFeatureFiles' -Dsurefire.failIfNoSpecifiedTests=false test→Tests run: 5, Failures: 0, Errors: 0, Skipped: 0.Side effects
None expected.
serenity.requirements.diris set, behaviour is unchanged (the new branch is unreachable).serenity.test.requirements.basediris set and points at a directory that does not exist, the fallback is skipped and behaviour again matches the pre-patch code path.The only observable change is the case the bug report targets: only
serenity.test.requirements.basediris set and points at a real directory. Previously that configuration quietly resolved to the wrong path; now it resolves correctly.Documentation changes
No changes required.
serenity.test.requirements.basediris already documented as the companion of the Gradle plugin'srequirementsBaseDirDSL field; this PR makes the runtime behaviour match that documented expectation.Relevant tickets
Checklist
WhenFindingTheRootDirectoryForFeatureFiles, 3 new cases)./mvnw -pl serenity-model testpasses locallygit diff --checkclean<type>: <message>convention