Skip to content

Commit ef4d1dd

Browse files
Skip unused kernel cache diagnostics in plain WordPress projects
1 parent 44db4dd commit ef4d1dd

4 files changed

Lines changed: 45 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Align read-only Doctor and explicit cache maintenance with Kernel 1.1.4's selected private fallback, configured cache/build roots and discovery metadata.
66
- Fail diagnostics for unsafe explicit cache directories; report implicit fallback selection without creating directories or executing cache metadata.
7+
- Mark unused cache/build diagnostics and permissions as not-applicable when the optional Kernel is absent, including WordPress core installed in the project root.
78
- Support explicitly configured external cache/build roots with mode 0700 and matching ownership; reject symlinks, parent traversal and unsafe permissions before any deletion.
89
- Require Kernel 1.1.4 or newer when the optional kernel is installed, and pin shared QA workflows to the released 1.2.2 source.
910

‎docs/releases/1.2.2.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Runtime's Doctor and `kernel-cache` now select the same generation as Kernel
44
1.1.4, including its durable private per-user fallback. When the optional Kernel
55
is installed, Composer requires 1.1.4 or newer. Plain WordPress installations
66
remain supported without Kernel.
7+
Doctor marks unused kernel cache/build directories and their permissions as
8+
not-applicable when Kernel is absent, including plain WordPress installed directly
9+
in the project root. Unused cache overrides do not cause diagnostic failures.
710

811
An unsafe explicit `APP_CACHE_DIR` fails instead of producing a passing diagnostic
912
or silently selecting another directory. Implicit fallback selection appears as

‎src/Console/Doctor.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@ public function inspect(bool $production = false, bool $databaseHealth = false,
104104
}
105105
$packages = new PackageFinder($this->context);
106106
$hasKernel = $packages->findByName('sympress/kernel') !== null;
107-
if (!$hasKernel) {
108-
$record('kernel.cache', 'not-applicable', 'sympress/kernel is not installed.');
109-
}
110107
$kernelDirectories = [];
111108
foreach (['cache', 'build'] as $id) {
109+
if (!$hasKernel) {
110+
$record('kernel.' . $id, 'not-applicable', 'sympress/kernel is not installed.');
111+
$record('permissions.kernel-' . $id, 'not-applicable', 'sympress/kernel is not installed; its directories are unused.');
112+
continue;
113+
}
112114
try {
113115
$path = $id === 'cache' ? $kernel->cache() : $kernel->build();
114116
$kernel->assertSafe($path, $id);
115117
$kernelDirectories['kernel-' . $id] = $path;
116-
if ($hasKernel) {
117-
$record('kernel.' . $id, is_dir($path) && is_readable($path) ? 'pass' : 'unknown', is_dir($path) ? 'Selected kernel directory is readable.' : 'Selected kernel directory has not been created; run cache warmup as the PHP-FPM user.');
118-
}
118+
$record('kernel.' . $id, is_dir($path) && is_readable($path) ? 'pass' : 'unknown', is_dir($path) ? 'Selected kernel directory is readable.' : 'Selected kernel directory has not been created; run cache warmup as the PHP-FPM user.');
119119
} catch (Throwable) {
120120
$record('kernel.' . $id, 'fail', 'Unsafe kernel directory. Configure APP_CACHE_DIR/APP_BUILD_DIR outside the webroot without symlinks or group/world write access. External roots require mode 0700. Create and warm them as the PHP-FPM user.');
121121
$record('permissions.kernel-' . $id, 'fail', 'Unsafe kernel directory cannot be used for cache operations.');

‎tests/Integration/DoctorTest.php‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SymPress\Runtime\Tests\Integration;
66

7+
use PHPUnit\Framework\Attributes\DataProvider;
78
use PHPUnit\Framework\Attributes\Group;
89
use SymPress\Runtime\Tests\Support\TemporaryProject;
910
use Symfony\Component\Process\Process;
@@ -85,4 +86,38 @@ public function testInvalidRuntimeOptionsStillProduceStructuredRedactedDiagnosti
8586
$report = json_decode($failed->getOutput(), true, flags: JSON_THROW_ON_ERROR);
8687
self::assertSame('fail', array_column($report['checks'], 'status', 'id')['configuration']);
8788
}
89+
90+
/** @return iterable<string, array{bool, bool}> */
91+
public static function kernelFreeLayouts(): iterable
92+
{
93+
yield 'ordinary layout' => [false, false];
94+
yield 'core in root' => [true, false];
95+
yield 'unused unsafe cache' => [false, true];
96+
yield 'core in root with unused unsafe cache' => [true, true];
97+
}
98+
99+
#[DataProvider('kernelFreeLayouts')]
100+
#[Group('PAR-SYM-001')]
101+
public function testKernelFreeWordPressDoesNotInspectUnusedKernelDirectories(bool $coreInRoot, bool $unsafeCache): void
102+
{
103+
$this->fixture();
104+
if ($coreInRoot) {
105+
$this->write('composer.json', '{"extra":{"wordpress-install-dir":".","sympress-runtime":{}}}');
106+
$this->write('wp-load.php', '<?php // WordPress core in the project root');
107+
}
108+
if ($unsafeCache) {
109+
$this->write('unused-cache/production/kernel/meta.php', 'unused');
110+
chmod($this->root . '/unused-cache/production/kernel', 0770);
111+
$this->write('.env', (string) file_get_contents($this->root . '/.env') . "APP_CACHE_DIR=unused-cache\n");
112+
}
113+
$process = $this->diagnose();
114+
self::assertSame(0, $process->getExitCode(), $process->getOutput() . $process->getErrorOutput());
115+
$report = json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR);
116+
$checks = array_column($report['checks'], 'status', 'id');
117+
foreach (['kernel.cache', 'kernel.build', 'permissions.kernel-cache', 'permissions.kernel-build'] as $id) {
118+
self::assertSame('not-applicable', $checks[$id]);
119+
}
120+
self::assertFileDoesNotExist($this->root . '/.env.cached.php');
121+
self::assertDirectoryDoesNotExist($this->root . '/var');
122+
}
88123
}

0 commit comments

Comments
 (0)