Skip to content

fix(requirements): RootDirectory honours serenity.test.requirements.basedir (#3733)#3734

Open
GianniGiglio wants to merge 1 commit into
serenity-bdd:mainfrom
GianniGiglio:fix_aggregate_requirements_basedir_fallback
Open

fix(requirements): RootDirectory honours serenity.test.requirements.basedir (#3733)#3734
GianniGiglio wants to merge 1 commit into
serenity-bdd:mainfrom
GianniGiglio:fix_aggregate_requirements_basedir_fallback

Conversation

@GianniGiglio

Copy link
Copy Markdown
Contributor

Summary

Adds a fallback in RootDirectory.featuresOrStoriesRootDirectory() so it honours serenity.test.requirements.basedir when serenity.requirements.dir is unset. This makes the existing serenity-gradle-plugin AggregateTask wiring 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>:aggregate will 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-directory narrative.md files.

Before this change, the same setup yielded a flat capabilities.html with no hierarchy and no narratives, while the aggregate log simultaneously reported "Generating test results for 47 tests" and "0 requirements loaded" — because FileSystemRequirementsTagProvider's no-arg constructor fell back to user.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:

./gradlew :<module>:aggregate --rerun-tasks --debug

Before the fix, the aggregate log shows:

0 requirements loaded after 335 ms

After the fix (with SERENITY_TEST_REQUIREMENTS_BASEDIR set by the Gradle plugin, which is already the default wiring):

54 requirements loaded after 210 ms

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.java gains three cases, all passing:

  • featuresOrStoriesRootDirectoryFallsBackToTestRequirementsBasedir — the new fallback fires when only serenity.test.requirements.basedir is set and the path exists.
  • serenityRequirementsDirTakesPrecedenceOverBasedir — guards the existing contract: when both properties are set, serenity.requirements.dir still 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 testTests run: 5, Failures: 0, Errors: 0, Skipped: 0.

Side effects

None expected.

  • When serenity.requirements.dir is set, behaviour is unchanged (the new branch is unreachable).
  • When neither property is set, behaviour is unchanged (the existing classpath/working-directory scan still runs).
  • When only serenity.test.requirements.basedir is 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.basedir is 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.basedir is already documented as the companion of the Gradle plugin's requirementsBaseDir DSL field; this PR makes the runtime behaviour match that documented expectation.

Relevant tickets

Checklist

  • Tests added (WhenFindingTheRootDirectoryForFeatureFiles, 3 new cases)
  • ./mvnw -pl serenity-model test passes locally
  • git diff --check clean
  • Commit message follows the <type>: <message> convention

…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
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.

Aggregate drops the requirement hierarchy in multi-module Gradle builds (FileSystem + TestOutcome providers read the wrong directory)

1 participant