directory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'ptero-extension-runtime-'.uniqid(); File::ensureDirectoryExists($this->directory); config(['extensions.enabled' => true]); $this->available = []; $this->failures = []; $this->app->bind(DeletesServers::class, CoreDeleter::class); // The layout reads the built Vite manifest; use the committed fixture instead. $this->app->bind(AssetHashService::class, fn (): AssetHashService => new AssetHashService($this->app->make(FilesystemManager::class), base_path('tests/Fixtures'))); CoreDeleter::$deleted = []; }); afterEach(function (): void { File::deleteDirectory($this->directory); }); test('a wrapped action runs extension code around the core action and honours fluent options', function (): void { extensions('dns'); provider('dns')->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner)); $action = $this->app->make(DeletesServers::class); expect($action)->toBeInstanceOf(RecordingDeleter::class); expect($action->withForce())->toBe($action); $action->delete(new Server); expect(CoreDeleter::$deleted)->toBe(['before', 'forced', 'after']); expect($this->failures)->toBe([]); }); test('extensions wrap in load order and each resolution is decorated afresh', function (): void { extensions('first', 'second'); provider('first')->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner, 'first')); provider('second')->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner, 'second')); $this->app->make(DeletesServers::class)->delete(new Server); $this->app->make(DeletesServers::class)->delete(new Server); expect(CoreDeleter::$deleted)->toBe([ 'second:before', 'first:before', 'deleted', 'first:after', 'second:after', 'second:before', 'first:before', 'deleted', 'first:after', 'second:after', ]); }); test('a wrapper is inert while its extension is not available', function (): void { extensions(); provider('dns')->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner)); expect($this->app->make(DeletesServers::class))->toBeInstanceOf(CoreDeleter::class); extensions('dns'); expect($this->app->make(DeletesServers::class))->toBeInstanceOf(RecordingDeleter::class); }); test('a wrapper staged by a provider that never commits or fails to commit is inert', function (): void { extensions('dns'); $discarded = provider('dns'); $discarded->beginRegistration(); $discarded->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner)); $discarded->discardRegistration(); expect($this->app->make(DeletesServers::class))->toBeInstanceOf(CoreDeleter::class); $failed = provider('dns'); $failed->beginRegistration(); $failed->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner)); $failed->consoleCommands([ProbeCommand::class]); $failed->schedule(function (Schedule $schedule): void { $schedule->call(fn (): null => null); }); $failed->headTags([['tag' => 'meta', 'name' => 'theme-color', 'content' => '#000000']]); $failed->permissions('Broken.', []); expect(fn () => $failed->commitRegistration())->toThrow(InvalidArgumentException::class); expect($this->app->make(DeletesServers::class))->toBeInstanceOf(CoreDeleter::class); expect($this->app->make(ExtensionConsoleRegistry::class)->snapshot())->toBe(['commands' => [], 'schedules' => []]); expect($this->app->make(ExtensionHeadTags::class)->toHtml())->toBe(''); }); test('a broken decorator is recorded and the core action stays resolvable', function (Closure $decorator, string $message): void { extensions('dns'); provider('dns')->wrap(DeletesServers::class, $decorator); expect($this->app->make(DeletesServers::class))->toBeInstanceOf(CoreDeleter::class); expect($this->failures)->toBe([['dns', $message, 'action']]); })->with([ 'throws' => [fn (): never => throw new RuntimeException('decorator failed'), 'decorator failed'], 'returns another type' => [fn (): Server => new Server, 'The decorator for '.DeletesServers::class.' must return an implementation of that contract.'], ]); test('exceptions of a wrapper and of the core action reach the caller unchanged', function (): void { extensions('dns'); provider('dns')->wrap(DeletesServers::class, fn (DeletesServers $inner): DeletesServers => new RecordingDeleter($inner, failure: new RuntimeException('dns cleanup failed'))); expect(fn () => $this->app->make(DeletesServers::class)->delete(new Server))->toThrow(RuntimeException::class, 'dns cleanup failed'); CoreDeleter::$failure = $core = new RuntimeException('wings is unreachable'); try { $this->app->make(DeletesServers::class)->delete(new Server); $this->fail('The core exception must propagate.'); } catch (Throwable $throwable) { expect($throwable)->toBe($core); } finally { CoreDeleter::$failure = null; } }); test('only bound panel contracts can be wrapped', function (string $contract): void { extensions('dns'); expect(fn () => provider('dns')->wrap($contract, fn ($inner) => $inner))->toThrow(InvalidArgumentException::class, 'can only wrap action contracts'); })->with([ 'a concrete action' => [CoreDeleter::class], 'a framework contract' => [\Illuminate\Contracts\Cache\Repository::class], 'a missing interface' => [DeletesServers::class.'Missing'], 'an unbound panel interface' => [\Pterodactyl\Contracts\Models\Identifiable::class], 'a shared panel service' => [\Pterodactyl\Contracts\Extensions\HashidsInterface::class], 'an interface outside the contracts namespace' => [\Pterodactyl\Services\Extensions\Contracts\ManagesExtensionSettings::class], ]); test('registered commands reach artisan only for available extensions', function (): void { extensions('probe'); provider('probe')->consoleCommands([ProbeCommand::class]); provider('disabled')->consoleCommands([DisabledProbeCommand::class]); expect(Artisan::all())->toHaveKey('probe:run')->not->toHaveKey('disabled:run'); expect(Artisan::call('probe:run'))->toBe(7); }); test('only console commands can be registered', function (): void { expect(fn () => provider('probe')->consoleCommands([Server::class]))->toThrow(InvalidArgumentException::class, 'is not a console command'); }); test('scheduled tasks run only while the extension is available and failures are attributed', function (): void { extensions('probe'); provider('probe')->schedule(function (Schedule $schedule): void { $schedule->call(fn (): never => throw new RuntimeException('task failed'))->everyMinute()->description('probe task'); }); provider('disabled')->schedule(function (Schedule $schedule): void { $schedule->call(fn (): null => null)->everyMinute()->description('disabled task'); }); $schedule = new Schedule; $this->app->make(ExtensionConsoleRegistry::class)->schedule($schedule); expect($schedule->events())->toHaveCount(1); $event = $schedule->events()[0]; expect($event->description)->toBe('probe task'); expect($event->filtersPass($this->app))->toBeTrue(); expect(fn () => $event->run($this->app))->toThrow(RuntimeException::class, 'task failed'); expect($this->failures)->toBe([['probe', 'Scheduled task "probe task" failed.', 'schedule']]); extensions(); expect($event->filtersPass($this->app))->toBeFalse(); }); test('a schedule callback that throws is recorded and schedules nothing runnable', function (): void { extensions('probe'); provider('probe')->schedule(function (Schedule $schedule): void { $schedule->call(fn (): null => null)->everyMinute(); throw new RuntimeException('schedule failed'); }); $schedule = new Schedule; $this->app->make(ExtensionConsoleRegistry::class)->schedule($schedule); expect($this->failures)->toBe([['probe', 'schedule failed', 'schedule']]); expect($schedule->events()[0]->filtersPass($this->app))->toBeFalse(); }); test('head tags are rendered into the layout for guests and replace the panel defaults', function (): void { extensions('pwa'); provider('pwa')->headTags([ ['tag' => 'link', 'rel' => 'manifest', 'href' => '/extensions/pwa/manifest.webmanifest'], ['tag' => 'meta', 'name' => 'theme-color', 'content' => '#0f172a">