Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
22cae4a
feat(testing): isolate WordPress hooks between tests
Dec 3, 2026
cdef7a7
fix(modules): level the bundled module package.json with module-defau…
Dec 3, 2026
8467e5b
Merge pull request #746 from Pollora/fix/module-stub-wordpress-deps
ogorzalka Dec 3, 2026
502f833
fix(modules): authenticate the GitHub API requests of the downloader
Dec 3, 2026
e127f43
chore: merge develop into fix/module-download-github-token
Dec 3, 2026
87ddc76
chore: merge develop into the testing hooks branch
Dec 3, 2026
714e1a4
fix(modules): chain nothing from a failed authenticated request
Dec 3, 2026
04751a7
Merge pull request #748 from Pollora/fix/module-download-github-token
ogorzalka Dec 3, 2026
182437b
chore: merge develop into the testing hooks branch
Dec 3, 2026
26cca03
fix(blocks): add the current @wordpress packages with pollora:make:block
Dec 3, 2026
ca60de6
fix(version-check): keep the redirects of an authenticated request on…
Dec 3, 2026
2f591ab
Merge branch 'develop' into fix/make-block-wordpress-deps
ogorzalka Dec 3, 2026
8649d16
Merge pull request #750 from Pollora/fix/make-block-wordpress-deps
ogorzalka Dec 3, 2026
6886a7e
ci(e2e): read template tags over git instead of api.github.com
Dec 3, 2026
0b57fb2
chore: merge develop into ci/e2e-template-tag
Dec 3, 2026
a455207
Merge pull request #751 from Pollora/ci/e2e-template-tag
ogorzalka Dec 3, 2026
59c9746
chore: merge develop into the testing hooks branch
Dec 3, 2026
6e62c29
Merge pull request #745 from Pollora/feat/testing-isolate-wp-hooks
ogorzalka Dec 3, 2026
0c20184
fix(testing): register themes and plugins in every application of a t…
Dec 3, 2026
e894a5a
test(testing): give the WP_Hook stub the signature of do_action
Dec 3, 2026
8b1df74
chore(rector): drop the skips of two rules Rector no longer ships
Dec 3, 2026
bfacaf7
chore(rector): keep the empty methods of test doubles
Dec 3, 2026
76d0ad4
test(testing): cover the module registrations within one test each
Dec 3, 2026
581ce35
Merge pull request #752 from Pollora/fix/testing-replay-module-regist…
ogorzalka Dec 3, 2026
aaeff8e
test(version-check): cover the redirect GitHub answers for a renamed …
Dec 4, 2026
4cd1615
chore: merge develop into the update check redirect branch
Dec 4, 2026
c117185
fix(route): do not mark public a page bound to its visitor
Dec 4, 2026
e774db9
fix(version-check): handle the redirects of an authenticated update c…
Dec 4, 2026
59a930b
fix(route): do not mark public a page bound to its visitor
Dec 4, 2026
1438895
docs(changelog): date 13.45.2
Dec 4, 2026
ffacce5
Merge pull request #753 from Pollora/release/13.45.2
ogorzalka Dec 4, 2026
8704b28
test(testing): follow successive applications within one test
Dec 4, 2026
417e090
Merge pull request #755 from Pollora/fix/testing-replay-mutant-order
ogorzalka Dec 4, 2026
54ceacc
ci(harness): give the quality gates up to 90 minutes
Dec 4, 2026
1dbefd4
Merge pull request #756 from Pollora/ci/release-gate-timeout
ogorzalka Dec 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,11 @@ jobs:
- name: Generate application key
run: ddev exec php artisan key:generate --no-interaction

# Through the script, which still gives the site its theme when GitHub's API
# refuses pollora:install the list of tags
- name: Install WordPress
run: |
ddev exec php artisan pollora:install --install \
ddev exec bash packages/framework/tests/e2e/bin/install-wordpress.sh --install \
--title="Pollora" \
--description="Pollora CI" \
--admin-user=admin \
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ jobs:
uses: Pollora/harness/.github/workflows/php-package.yml@v0.1.41
permissions:
contents: read
with:
# The pull request into main scores every file new since the previous release, which can outlast the default of 30
quality-timeout-minutes: 90
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@ All notable changes to the Pollora framework will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/Pollora/framework/compare/v13.45.1...develop)
## [Unreleased](https://github.com/Pollora/framework/compare/v13.45.2...develop)

## [v13.45.2](https://github.com/Pollora/framework/compare/v13.45.1...v13.45.2) - 2026-12-04

### Added

- **`Pollora\Testing\IsolatesWordPressHooks`: the hooks of one test no longer reach the next one** ([#741](https://github.com/Pollora/framework/issues/741)). A test process loads WordPress once and creates one application per test, so the callbacks of a flushed application stayed in `$wp_filter` and failed, or ran twice, when a later test fired them. Add the trait to the base test case of the project (`use IsolatesWordPressHooks;`); nothing changes without it. After each test, `$wp_filter`, `$wp_actions` and `$wp_filters` go back to what loading WordPress left: what the application or the test hooked is removed, what the core, plugins, must-use plugins and `functions.php` hooked is kept, as are the static methods hooked while the application booted and what `pollora/roles` and `pollora/schedule` hook once per process. It restores hooks only: other statics and WordPress globals still outlive a test. A callback hooked by a file first included during a test is removed with the rest and does not come back. Requires `APP_ENV=testing` for the load to be recorded; without it, each test only gets back the hooks it started with.

### Changed

- **The module template bundled with the framework is level with `pollora/module-default` v1.0.0**: its `package.json` asks for the current `@wordpress/*` packages (`block-editor` ^20, `blocks` ^17.1, `components` ^44, `element` ^10.1, `i18n` ^7.1), so that `npm install` in a module written from this copy, when the download fails, prints no peer or deprecation warning. Existing modules are not changed.
- **`pollora:make:block` adds the same `@wordpress/*` versions** to a theme, plugin or module that does not declare these packages. Versions already declared are left as they are.

### Fixed

- **In a test process, every application has the theme and plugins that register with Pollora, not only the first** ([#749](https://github.com/Pollora/framework/issues/749)). WordPress includes `functions.php` and plugin files once per process, so from the second test on `pollora_register()` was never called again: no theme views, configuration or providers, and no plugin ones. The calls made while WordPress loads are now remembered and repeated for each later application, and what they hook into `plugins_loaded`, `setup_theme`, `after_setup_theme`, `widgets_init`, `init` and `wp_loaded` runs again, without counting those actions twice; the callbacks of the earlier application they replace are unhooked, with or without `IsolatesWordPressHooks`. Only under unit tests (`APP_ENV=testing`): nothing is repeated elsewhere. Only `pollora_register()` is repeated: other code of `functions.php`, of a plugin file or of `app/inc` still runs once per process, as does a direct call to a registrar.
- **The files of a module's `app/inc` are included once per process.** A module registered a second time, as when a child theme and its parent both call `pollora_register(ModuleType::Theme)`, included them again, which is fatal when one declares a function.
- **`pollora:make:theme`, `pollora:make:plugin` and `pollora:make:module` can authenticate their requests to the GitHub API** ([#747](https://github.com/Pollora/framework/issues/747)). Since 13.45.1 nothing is downloaded when the list of tags cannot be read, and the anonymous limit of 60 requests an hour for each IP address is easily reached from a shared address such as a CI runner. Set `MODULES_GITHUB_TOKEN` (`modules.versions.github_token`, so far only used by the update checks of private modules) and those requests are authenticated. The token goes to `https://api.github.com` only: not to the archive or checksum downloads of github.com, and not along a redirect that leaves the API. It therefore does not make the archive of a private repository downloadable. `GITHUB_TOKEN` is not read: map it to `MODULES_GITHUB_TOKEN` where that is wanted. A refusal for a `403` or `429` now says how to configure the token. **If you already set `MODULES_GITHUB_TOKEN`**, these commands now send it too: a token that is expired or revoked makes them fail with a `401` where the anonymous request would have worked. Without a token nothing changes.

### Security

- **WordPress pages bound to one visitor are no longer sent as publicly cacheable. This changes what a shared cache may store.** The framework answered `Cache-Control: public` to every visitor not logged in to WordPress, so a shared cache could store such a page and serve it, its cookies or session included, to someone else. Where it would have answered `public`, it now answers `private, no-cache, must-revalidate` (`no-store` is kept) when `wordpress.sessions` is enabled and the page is served by a `Route::wp()` route that has the session of the `web` group, as one declared in `routes/web.php` does (**enabled is the framework default when the project's `config/wordpress.php` lacks the key**); when a cookie is set or queued, `setcookie()` and `session_start()` included; when the request otherwise has a Laravel session; or when a `Cache-Control` already sent forbids shared storage. **If your front end needs no session, set `'sessions' => false` in `config/wordpress.php`**: the session no longer keeps those pages out of shared caches (`csrf_token()`, `old()` and flash data then have nothing to read from). A plugin that sets a cookie for every visitor now keeps the pages it does so on out of shared caches. Cache directives your application sets on its response are left as they are. If a shared cache stands in front of the site, purge it after upgrading.
- **Redirects of the module update check are handled by the framework when the request carries a token.** They are followed only within the same scheme, host and port, up to five, which covers a renamed repository; any other redirect counts as no answer. Requests without credentials are unchanged.

## [v13.45.1](https://github.com/Pollora/framework/compare/v13.45.0...v13.45.1) - 2026-12-03

Expand Down
4 changes: 3 additions & 1 deletion config/modules-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
'capability' => 'activate_plugins',
],

// Update checks of the modules installed by Composer from a private GitHub repository
// Token of the requests to api.github.com: update checks of the modules installed by Composer
// from a private GitHub repository, and the tag lists read by pollora:make:theme, make:plugin
// and make:module, which GitHub otherwise limits to 60 an hour for each IP address
'versions' => [
'github_token' => env('MODULES_GITHUB_TOKEN'),
],
Expand Down
1 change: 1 addition & 0 deletions config/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
* Set to false to leave the session, error-sharing and CSRF middleware off
* Route::wp() routes; Laravel-native routes are not affected.
* csrf_token(), old() and flash data then have nothing to read from.
* While a route has a session, shared caches are told not to store its pages.
*/
'sessions' => true,

Expand Down
12 changes: 5 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ScalarParamTypeByMethodCallTypeRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use RectorLaravel\Rector\ArrayDimFetch\ServerVariableToRequestFacadeRector;
use RectorLaravel\Rector\FuncCall\UnlinkFuncCallToFileFacadeDeleteRector;
use RectorLaravel\Rector\MethodCall\ContainerBindConcreteWithClosureOnlyRector;
Expand All @@ -17,11 +16,10 @@
__DIR__.'/tests',
])
->withSkip([
AddOverrideAttributeToOverriddenMethodsRector::class,
// getAttribute($key) and setAttribute($key) override Eloquent's untyped
// signatures: typing $key would be a fatal incompatible declaration.
ScalarParamTypeByMethodCallTypeRector::class => [
__DIR__.'/src/Models/Concerns/HasTypedMeta.php',
// An empty method of a test double is there to be called or reflected:
// Rector 2.9.2 removes them.
RemoveEmptyClassMethodRector::class => [
__DIR__.'/tests',
],
// rector-laravel 2.7 turns every unlink() into File::delete(). The
// cleanup of temp files, caches and test fixtures runs where the
Expand Down
10 changes: 5 additions & 5 deletions src/Block/UI/Console/MakeBlockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class MakeBlockCommand extends Command
private const array NPM_DEPENDENCIES = [
'@roots/vite-plugin' => '^2.0.0',
'glob' => '^11.0.0',
'@wordpress/blocks' => '^14.0.0',
'@wordpress/block-editor' => '^14.0.0',
'@wordpress/components' => '^29.0.0',
'@wordpress/element' => '^6.0.0',
'@wordpress/i18n' => '^5.0.0',
'@wordpress/blocks' => '^17.1.0',
'@wordpress/block-editor' => '^20.0.0',
'@wordpress/components' => '^44.0.0',
'@wordpress/element' => '^10.1.0',
'@wordpress/i18n' => '^7.1.0',
];

/**
Expand Down
25 changes: 25 additions & 0 deletions src/Modules/Domain/Exceptions/ModuleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ public static function tagListUnavailable(string $repository, string $reason): s
return new self(sprintf('Unable to read the list of tags of %s (%s), so the version to install is unknown. Nothing was downloaded: the default branch has no checksum and is not installed instead. Retry later, or ask for an explicit version (--repo-version), whose checksum is checked as usual.', $repository, $reason));
}

/**
* The list of tags was answered with another status than 200 and 404.
*
* @param string $repository The GitHub repository whose tags could not be listed
* @param int $status HTTP status of the answer
* @param bool $authenticated Whether a token was sent
*/
public static function tagListRefused(string $repository, int $status, bool $authenticated): self
{
$message = self::tagListUnavailable($repository, 'HTTP '.$status)->getMessage();

if ($authenticated && in_array($status, [401, 403, 429], true)) {
$message .= ' The request was sent with the token of MODULES_GITHUB_TOKEN (modules.versions.github_token): check that it is still valid, has not reached its rate limit and may read this repository.';
} elseif (! $authenticated && in_array($status, [403, 429], true)) {
$message .= ' GitHub allows 60 anonymous requests an hour for each IP address: to authenticate them, set MODULES_GITHUB_TOKEN in the environment (modules.versions.github_token) to a GitHub token, and run php artisan config:clear if the configuration is cached.';
}

return new self($message);
}

public static function gitHubTokenMalformed(): self
{
return new self('The GitHub token of MODULES_GITHUB_TOKEN (modules.versions.github_token) holds a space, a line break or a character outside ASCII, which no token has. Nothing was sent: fix or remove the value.');
}

public static function checksumMismatch(string $url, string $expected, string $actual): self
{
return new self(sprintf('Checksum mismatch for %s: the release publishes SHA-256 %s, the downloaded archive has %s. Nothing was extracted. Do not install it unless the module author explains the difference.', $url, $expected, $actual));
Expand Down
11 changes: 9 additions & 2 deletions src/Modules/Infrastructure/Services/ModuleAssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Pollora\Asset\Application\Services\AssetManager;
use Pollora\Foundation\Support\IncludesFiles;
use Psr\Log\LoggerInterface;
use Symfony\Component\Finder\Finder;

/**
* Generic module asset manager.
Expand Down Expand Up @@ -144,8 +145,14 @@ public function loadModuleIncludes(string $modulePath): void
{
$includeDirectory = $modulePath.'/app/inc';

if (is_dir($includeDirectory)) {
$this->includes($includeDirectory);
if (! is_dir($includeDirectory)) {
return;
}

// Once per process: a module registered again (a later application of a test process, a parent and a child
// theme) must not declare its functions twice
foreach (Finder::create()->files()->name('*.php')->in($includeDirectory)->sortByName() as $file) {
@include_once $file->getRealPath();
}
}

Expand Down
89 changes: 84 additions & 5 deletions src/Modules/Infrastructure/Services/ModuleDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Pollora\Modules\Infrastructure\Services;

use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use InvalidArgumentException;
Expand All @@ -26,6 +29,8 @@
* - Verifies the archive of a tag against the SHA-256 published with its release
* (asset `module.sha256`, see {@see ReleaseChecksum}), and warns when there is none
* - Refuses to pick a version when the list of tags cannot be read
* - Authenticates its requests to api.github.com, and those only, with the token of
* `modules.versions.github_token` when one is configured
* - Generic implementation for both themes and plugins
*
* Example usage:
Expand All @@ -36,6 +41,16 @@
*/
class ModuleDownloader
{
/**
* Root of the GitHub API, the only address the token is sent to.
*/
private const string API_ROOT = 'https://api.github.com/';

/**
* Redirects of the API followed with the token: a renamed repository answers one.
*/
private const int MAX_API_REDIRECTS = 5;

/**
* GitHub repository full name (e.g. 'owner/repo').
*/
Expand Down Expand Up @@ -199,7 +214,7 @@ public function downloadForModule(ModuleInterface $module, string $destination):
*/
public function getAvailableVersions(): array
{
$response = Http::get(sprintf('https://api.github.com/repos/%s/tags', $this->repository));
$response = $this->requestApi(sprintf('repos/%s/tags', $this->repository), $this->gitHubToken());

if (! $response->successful()) {
return [];
Expand All @@ -215,7 +230,7 @@ public function getAvailableVersions(): array
*/
public function getRepositoryInfo(): array
{
$response = Http::get('https://api.github.com/repos/'.$this->repository);
$response = $this->requestApi('repos/'.$this->repository, $this->gitHubToken());

if (! $response->successful()) {
throw ModuleException::repositoryUnreachable($this->repository);
Expand Down Expand Up @@ -290,10 +305,13 @@ protected function getLatestTag(): ?string
*/
private function listTagNames(): array
{
// Read outside the try: a token that cannot be used is not a failed request
$token = $this->gitHubToken();

try {
// 100 rather than the default 30: a repository with more tags than that
// could have its highest version on the second page, unreachable here.
$response = Http::get(sprintf('https://api.github.com/repos/%s/tags?per_page=100', $this->repository));
$response = $this->requestApi(sprintf('repos/%s/tags?per_page=100', $this->repository), $token);
} catch (Throwable) {
throw ModuleException::tagListUnavailable($this->repository, 'the request failed');
}
Expand All @@ -303,7 +321,7 @@ private function listTagNames(): array
}

if ($response->status() !== 200) {
throw ModuleException::tagListUnavailable($this->repository, 'HTTP '.$response->status());
throw ModuleException::tagListRefused($this->repository, $response->status(), $token !== null);
}

// Objects are kept as objects: `{}` must not pass for the empty list
Expand All @@ -321,6 +339,67 @@ private function listTagNames(): array
);
}

/**
* The token that authenticates the requests to the API, from `modules.versions.github_token`.
*
* @return string|null Null when none is configured: the requests are then anonymous
*
* @throws ModuleException When the value holds characters no token has. The HTTP
* client would quote it in its own error message.
*/
private function gitHubToken(): ?string
{
$configured = Config::get('modules.versions.github_token');
$token = is_string($configured) ? trim($configured) : '';

if ($token === '') {
return null;
}

if (preg_match('/^[\x21-\x7E]+$/D', $token) !== 1) {
throw ModuleException::gitHubTokenMalformed();
}

return $token;
}

/**
* GET on the GitHub API.
*
* With a token, redirects are followed here rather than by the HTTP client, and
* only to the API itself: any other one is returned as the answer, so the token
* never leaves api.github.com whatever the client does with its headers.
*
* @param string $path Path below the root of the API
*
* @throws ConnectionException When GitHub cannot be reached
*/
private function requestApi(string $path, #[\SensitiveParameter] ?string $token): Response
{
$url = self::API_ROOT.$path;

if ($token === null) {
return Http::get($url);
}

$redirects = 0;

do {
try {
$response = Http::withToken($token)->withoutRedirecting()->get($url);
} catch (Throwable) {
// Whatever failed, not chained: the original may hold the request, and with it the token
throw new ConnectionException(sprintf('Unable to reach %s.', $url));
}

$url = $response->header('Location');
} while (in_array($response->status(), [301, 302, 303, 307, 308], true)
&& str_starts_with($url, self::API_ROOT)
&& $redirects++ < self::MAX_API_REDIRECTS);

return $response;
}

/**
* Pick the highest version among tag names.
*
Expand Down Expand Up @@ -386,7 +465,7 @@ private function normaliseVersion(string $name): string
*/
protected function getDefaultBranch(): string
{
$response = Http::get('https://api.github.com/repos/'.$this->repository);
$response = $this->requestApi('repos/'.$this->repository, $this->gitHubToken());

if (! $response->successful()) {
return 'main';
Expand Down
10 changes: 5 additions & 5 deletions src/Modules/stubs/module-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"@pollora/vite-config": "^1.0.0",
"@roots/vite-plugin": "^2.0.0",
"@tailwindcss/vite": "^4.2.3",
"@wordpress/block-editor": "^14.0.0",
"@wordpress/blocks": "^14.0.0",
"@wordpress/components": "^29.0.0",
"@wordpress/element": "^6.0.0",
"@wordpress/i18n": "^5.0.0",
"@wordpress/block-editor": "^20.0.0",
"@wordpress/blocks": "^17.1.0",
"@wordpress/components": "^44.0.0",
"@wordpress/element": "^10.1.0",
"@wordpress/i18n": "^7.1.0",
"laravel-vite-plugin": "^3.0.1",
"tailwindcss": "^4.2.3",
"vite": "^8.0.9"
Expand Down
Loading
Loading