extension enable check

This commit is contained in:
robert dennis
2026-10-12 05:18:55 -04:00
parent 48628b5288
commit e8fbafc9e1
2 changed files with 20 additions and 3 deletions
@@ -60,9 +60,13 @@ final class ExtensionCompatibility
/** @param Collection<string, ExtensionManifest> $enabled */
public function assertCompatible(ExtensionManifest $manifest, Collection $enabled): void
{
$errors = $this->resolve((clone $enabled)->put($manifest->id, $manifest))['errors'];
// A claim both sides make is reported from the side of the extension being checked.
$reason = $errors[$manifest->id] ?? reset($errors);
$before = $this->resolve($enabled)['errors'];
$after = $this->resolve((clone $enabled)->put($manifest->id, $manifest))['errors'];
// An extension that was already failing does not hold this one back: only a failure
// of its own, or one it causes in another extension, does. A claim both sides make
// is reported from the side of the extension being checked.
$caused = array_diff_key($after, $before);
$reason = $after[$manifest->id] ?? reset($caused);
throw_if($reason !== false, InvalidExtensionException::class, $reason);
$this->assertDistinctAutoloader($manifest, $enabled);
}
@@ -65,6 +65,19 @@ test('rejects upgrades and disabling that would break an enabled dependent', fun
$compatibility->assertCanDisable('child', $enabled);
});
test('an extension that is already failing does not stop another from being enabled', function (): void {
$enabled = collect([
'future' => manifest('future', ['panel' => '^3.0']),
'orphan' => manifest('orphan', ['extensions' => ['gone' => '*']]),
]);
$compatibility = resolve(ExtensionCompatibility::class);
$compatibility->assertCompatible(manifest('healthy'), $enabled);
expect(fn () => $compatibility->assertCompatible(manifest('dependent', ['extensions' => ['future' => '*']]), $enabled))
->toThrow(InvalidExtensionException::class, 'Extension "dependent" requires unavailable extension "future".');
});
/** @param list<string> $components */
function presentation(string $id, array $components): ExtensionManifest
{