Skip to content

[#657] [#659] Fixed accessibility report directory and report URL display.#660

Merged
AlexSkrypnyk merged 2 commits into
mainfrom
feature/657-a11y-report-paths
Jun 19, 2026
Merged

[#657] [#659] Fixed accessibility report directory and report URL display.#660
AlexSkrypnyk merged 2 commits into
mainfrom
feature/657-a11y-report-paths

Conversation

@AlexSkrypnyk

@AlexSkrypnyk AlexSkrypnyk commented Jun 19, 2026

Copy link
Copy Markdown
Member

Closes #657
Closes #659

Summary

AccessibilityTrait built its report directory from a live getcwd() call, but the Drupal Extension @api bootstrap calls chdir() to the docroot before the first scenario runs, silently moving reports into web/.logs/... instead of the project-root .logs/ tree. A new #[BeforeSuite] hook captures the launch directory into a static $accessibilityBaseDir once before any scenario can alter it, anchoring the default report path to that stable base. Per-scenario reports and console/gate messages also printed the full internal URL including host and port (e.g. http://nginx:8080/contact), which is noise and non-portable across environments. A new accessibilityFormatUrl() method strips the configured Mink base_url prefix so display paths show as /contact; the base URL itself maps to /, query strings are preserved, and genuinely cross-origin URLs remain absolute.

Changes

src/AccessibilityTrait.php

  • Added $accessibilityBaseDir static property to hold the captured launch directory.
  • Added #[BeforeSuite] hook accessibilityCaptureBaseDir() that sets $accessibilityBaseDir from getcwd() once before any scenario runs.
  • Updated accessibilityGetReportDir() to anchor the default .logs/test_results/accessibility path to $accessibilityBaseDir, falling back to the live getcwd() when the hook has not run.
  • Added accessibilityFormatUrl(string $url): string that strips the base_url prefix for display, mapping the base root to / and preserving query strings; cross-origin URLs are left absolute.
  • Applied accessibilityFormatUrl() at all five rendering sites: auto-mode gate violation lines, auto-mode gate incomplete lines, console output line, explicit gate message header, HTML <h2> heading, and JUnit testsuite name + URL: detail line.

tests/behat/bootstrap/FeatureContext.php

  • Added accessibilityGetReportDir() override that derives the base from the Mink files_path parameter, keeping accessibility reports in the same .logs tree as coverage and screenshots when Behat is launched from build/ with a project-root behat.yml.

tests/behat/features/accessibility.feature

  • Strengthened @trait scenario assertions to verify that the stripped page path (/sites/default/files/accessibility_violations.html) appears in gate output rather than just checking the gate prefix.

tests/phpunit/src/AccessibilityTraitTest.php (new)

  • Data-provider unit tests for accessibilityFormatUrl() covering path stripping, root mapping, query-string preservation, cross-origin safety, similar-prefix safety, and empty base URL passthrough.
  • Unit tests for accessibilityGetReportDir() verifying it anchors to the captured base dir and falls back to the live cwd when unset.
  • Unit tests for accessibilityCaptureBaseDir() verifying it sets the property when unset and does not overwrite an existing value.

Before / After

Report directory (with @api bootstrap)

Before:  web/.logs/test_results/accessibility/scenario-name.html
After:   .logs/test_results/accessibility/scenario-name.html

Gate / console output URL display

Before:  [accessibility] http://nginx:8080/contact: 3 violations ...
After:   [accessibility] /contact: 3 violations ...

Before:  Accessibility gate failed on http://nginx:8080/contact (rules: ...)
After:   Accessibility gate failed on /contact (rules: ...)

Summary

This PR fixes two issues in AccessibilityTrait output stability and portability:

  1. Report directory placement after Drupal @api bootstrap

    • The Drupal Extension’s drupal API driver calls chdir() to the docroot during bootstrap, shifting getcwd() away from the project root.
    • Accessibility reports were therefore written under web/.logs/test_results/accessibility/ instead of the expected project-root .logs/test_results/accessibility/.
    • The fix adds a suite-level #[BeforeSuite] hook accessibilityCaptureBaseDir() that captures the initial working directory into a static $accessibilityBaseDir before scenarios can change it. accessibilityGetReportDir() now builds paths from this captured base (falling back to live getcwd() for backward compatibility). If base capture encounters a transient failure, the captured base is left unset so the fallback can still retry rather than persisting stale state.
  2. Environment-specific absolute URLs in reports and console output

    • Per-scenario reports and gate failure messages previously displayed full internal container URLs like http://nginx:8080/contact, polluting output and breaking portability.
    • A new accessibilityFormatUrl() normalizes displayed URLs by stripping the Mink base_url prefix (mapping the base itself to /, preserving query strings, and keeping genuinely cross-origin absolute URLs unchanged).
    • Rendering points updated include gate failure messages, STDOUT/console accessibility summaries, HTML headings, and JUnit XML details.

Changes

  • src/AccessibilityTrait.php

    • Added $accessibilityBaseDir and #[BeforeSuite] accessibilityCaptureBaseDir() capture logic.
    • Updated accessibilityGetReportDir() to anchor to $accessibilityBaseDir (with fallback to getcwd()).
    • Added accessibilityFormatUrl() and updated five output/rendering sites to use it.
  • tests/behat/bootstrap/FeatureContext.php

    • Overrode accessibilityGetReportDir() to derive the base directory from the Mink files_path, keeping accessibility reports in the same .logs tree as other Behat artifacts.
  • tests/behat/features/accessibility.feature

    • Updated expectations to match formatted URL output (e.g., asserting /sites/default/files/accessibility_violations.html and including it in auto/explicit gate failure lines).
  • tests/phpunit/src/AccessibilityTraitTest.php

    • Added unit tests covering:
      • URL formatting across base-root vs nested paths, trailing slash normalization, query string preservation, cross-origin absolute URL handling, and empty base URL behavior.
      • Report directory resolution using the captured base and fallback behavior when unset.
      • Capture semantics (sets when unset, does not overwrite existing captured base).

Step definition / CONTRIBUTING.md compliance

  • No step definitions were added or modified; Behat changes are limited to feature expectations and a context method override, so no CONTRIBUTING.md step-format violations are introduced.

…play.

Captured the working directory at @BeforeSuite so the default report directory stays anchored to the run base path instead of the docroot that the 'drupal' driver chdir()s into during '@api' bootstrap. The test FeatureContext derives the base from the Mink 'files_path'.

Added 'accessibilityFormatUrl()' to strip the configured Mink 'base_url' prefix from URLs shown in HTML and JUnit reports, gate messages, and console output, while keeping genuinely cross-origin URLs absolute.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: aa04ff66-1240-4f60-9207-08e28763f6ae

📥 Commits

Reviewing files that changed from the base of the PR and between dc5f8d5 and b53b840.

📒 Files selected for processing (2)
  • src/AccessibilityTrait.php
  • tests/phpunit/src/AccessibilityTraitTest.php

Walkthrough

AccessibilityTrait gains a #[BeforeSuite] hook that captures the process working directory once into $accessibilityBaseDir, anchoring accessibilityGetReportDir() against later chdir() calls. A new accessibilityFormatUrl() helper strips the Mink base_url prefix so all report output (STDOUT, gate messages, HTML, JUnit) shows page paths instead of internal host/port URLs. PHPUnit tests and updated Behat feature expectations are added.

Changes

AccessibilityTrait stability and URL formatting

Layer / File(s) Summary
Base dir capture and report dir anchoring
src/AccessibilityTrait.php
Adds $accessibilityBaseDir static property, a #[BeforeSuite] accessibilityCaptureBaseDir() hook that stores getcwd() once before any test bootstrap can chdir(), and updates accessibilityGetReportDir() to use that captured value with a live getcwd() fallback.
URL formatter and all output sites
src/AccessibilityTrait.php
Adds accessibilityFormatUrl() which strips the Mink base_url prefix (mapping the base to / and leaving cross-origin URLs unchanged), then routes STDOUT summary, auto gate failure header, per-finding message, HTML section heading, and JUnit suite name through it.
FeatureContext override and Behat feature tests
tests/behat/bootstrap/FeatureContext.php, tests/behat/features/accessibility.feature
Overrides accessibilityGetReportDir() in FeatureContext to anchor to files_path-derived path under /.logs/test_results/accessibility; updates feature scenarios to expect formatted URLs in gate failure and auto-mode violation output.
PHPUnit test coverage
tests/phpunit/src/AccessibilityTraitTest.php
Adds AccessibilityTraitTest with data-provider-driven URL formatting assertions, report-dir anchoring vs. chdir() fallback tests, and base-dir capture once/no-overwrite tests; adds AccessibilityTraitTestImplementation stub exposing trait internals.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A rabbit once lost all their logs in web/,
For chdir() had wandered where docroot had led.
Now BeforeSuite snaps a photo of cwd,
And /nginx:8080 fades—just /contact instead.
The reports run stable, the paths short and bright,
This bunny hops onward—the output is right! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing accessibility report directory placement and URL formatting in reports, directly addressing both issue #657 and #659.
Linked Issues check ✅ Passed The PR implements all requirements from both linked issues: captures base directory at suite bootstrap to fix #657's getcwd() issue, and introduces URL formatting to strip base_url for portable paths, addressing #659's full-URL-in-reports problem.
Out of Scope Changes check ✅ Passed All changes align with the stated objectives: AccessibilityTrait modifications for base-dir capture and URL formatting, corresponding test overrides in FeatureContext, Behat feature test updates, and new PHPUnit unit tests for the new functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/657-a11y-report-paths

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/AccessibilityTrait.php`:
- Around line 119-121: When `getcwd()` returns FALSE in the AccessibilityTrait
class initialization block, the code currently sets
`self::$accessibilityBaseDir` to an empty string, which prevents the fallback
logic at line 319-321 from retrying `getcwd()` later since that fallback checks
for NULL. To preserve the fallback semantics, keep `self::$accessibilityBaseDir`
as NULL when `getcwd()` fails instead of assigning an empty string, allowing the
fallback mechanism to properly retry `getcwd()` and resolve reports to the
correct run-local path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7e9c77a9-70df-4e51-b3a5-29d13488077a

📥 Commits

Reviewing files that changed from the base of the PR and between 72a09a3 and dc5f8d5.

📒 Files selected for processing (4)
  • src/AccessibilityTrait.php
  • tests/behat/bootstrap/FeatureContext.php
  • tests/behat/features/accessibility.feature
  • tests/phpunit/src/AccessibilityTraitTest.php

Comment thread src/AccessibilityTrait.php Outdated
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.60%. Comparing base (72a09a3) to head (b53b840).

Files with missing lines Patch % Lines
src/AccessibilityTrait.php 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #660      +/-   ##
==========================================
+ Coverage   96.59%   96.60%   +0.01%     
==========================================
  Files          46       46              
  Lines        3523     3537      +14     
==========================================
+ Hits         3403     3417      +14     
  Misses        120      120              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AlexSkrypnyk AlexSkrypnyk added the Needs review Pull request needs a review from assigned developers label Jun 19, 2026
@AlexSkrypnyk AlexSkrypnyk merged commit 1ab0cbc into main Jun 19, 2026
14 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/657-a11y-report-paths branch June 19, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs review Pull request needs a review from assigned developers

Projects

None yet

1 participant