Skip to content

Test the download streaming that ends a request - #176

Merged
PDowney merged 2 commits into
mainfrom
download-coverage
Dec 2, 2026
Merged

PDowney merged 2 commits into
mainfrom
download-coverage

Conversation

@PDowney

@PDowney PDowney commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • esse_output_file_content() no longer calls exit; esse_serve_file_download() calls it after streaming. The steps before streaming (open and recheck the file, clear the output buffers, start the rate limit, record the download, send the headers) move into the new esse_start_file_download(). A download does the same things in the same order.
  • New tests: a whole download request runs in its own PHP process (tests/download-request.php), because it closes every output buffer, PHPUnit's too, and exits: only the file reaches the output, no buffer is left, and a report written at shutdown shows the rate limit started and the download was recorded. In the suite itself: streaming an opened handle sends the exact bytes and closes it; a stream that stops early is logged as an error; a file that changed is refused before the rate limit starts.
  • MINIMUM_LINE_COVERAGE goes from 58 to 61.

No changelog entry: the plugin's behavior does not change. The .pot file's line references are all before the changed lines.

Coverage

Before After
Unit suite (Windows) 62.98% (1,640 of 2,604) 63.32% (1,650 of 2,606)
includes/download.php 98 of 133 108 of 135

The steps that run in the separate process (esse_start_file_download(), buffer clearing, and the exit) are tested there but not counted as covered, because coverage is collected only in PHPUnit's process. The race checks between validation and opening stay uncovered.

Checks run locally

composer test (322 tests, also three random orders, and on PHPUnit 13.4.8 as the highest-deps jobs use), composer phpcs, Codacy's phpcs.xml, phpmd, psalm, psalm:taint, phpstan, rector, php -l on 8.4 and 8.5, yamllint, actionlint, zizmor --offline, check-jsonschema, and gitleaks on the staged changes.

🤖 Generated with Claude Code

esse_output_file_content() no longer ends the request: esse_serve_file_download()
calls exit after it. The steps before streaming move into
esse_start_file_download(). A download does the same things in the same order,
and the unit suite can now run each step.

New tests cover a started download (buffers cleared, rate limit started,
download recorded), the streamed bytes, a stream that stops early, and a
download refused before the rate limit starts. Unit coverage rises from
62.98% to 63.81%; the workflow's floor goes from 58 to 61.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for contributing to EngineScript Site Exporter!

Before we review:

  • Have you tested your changes with WordPress 7.0+?
  • Are your changes compatible with PHP 8.3+?
  • Have you followed WordPress coding standards?
  • Did you update the CHANGELOG.md if needed?

Security Reminder
This plugin creates site export archives, so please ensure:

  • All user input is properly sanitized
  • All output is properly escaped
  • No security vulnerabilities are introduced

We'll review your PR soon.

@codacy-production

codacy-production Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 0 duplication

Metric Results
Complexity 4
Duplication 0

View in Codacy

🟢 Coverage 33.33% diff coverage · +0.33% coverage variation

Metric Results
Coverage variation ✅ +0.33% coverage variation (-1.00%)
Diff coverage ✅ 33.33% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (fe5bf23) 2611 1663 63.69%
Head commit (952d517) 2613 (+2) 1673 (+10) 64.03% (+0.33%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#176) 3 1 33.33%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

PHPUnit 13 marks a test risky when the code under test closes PHPUnit's own
output buffer, which esse_serve_file_download() must do before it streams a
file. The whole download now runs in a separate PHP process
(tests/download-request.php): the test checks that only the file reaches the
output, that no buffer is left, and, from a report written at shutdown after
the exit, that the rate limit started and the download was recorded.
Streaming an opened handle stays an in-process test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PDowney
PDowney merged commit a61df3d into main Dec 2, 2026
29 checks passed
@github-actions
github-actions Bot deleted the download-coverage branch December 2, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant