feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support

Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.

New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering

New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
  module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
  FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 22:19:56 +01:00
parent c364e2b46d
commit c7b8fd516a
139 changed files with 7591 additions and 2535 deletions

View File

@@ -0,0 +1,130 @@
<?php
namespace MintyPHP\Tests\Service\Scheduler;
use MintyPHP\App\AppContainer;
use MintyPHP\App\Module\ModuleRegistry;
use MintyPHP\Service\Audit\SystemAuditService;
use MintyPHP\Service\Scheduler\Handler\ScheduledJobHandlerInterface;
use MintyPHP\Service\Scheduler\ScheduledJobRegistry;
use MintyPHP\Service\User\UserLifecycleService;
use PHPUnit\Framework\TestCase;
final class ScheduledJobRegistryTest extends TestCase
{
private string $fixturesDir = '';
protected function setUp(): void
{
$this->fixturesDir = sys_get_temp_dir() . '/scheduler-module-registry-' . uniqid();
mkdir($this->fixturesDir, 0777, true);
}
protected function tearDown(): void
{
$this->removeDir($this->fixturesDir);
}
public function testModuleJobAppearsInDefinitionsAndIsExecutable(): void
{
$moduleRegistry = $this->createRegistryWithModuleJob();
$container = new AppContainer();
$container->set(ModuleRegistry::class, static fn (): ModuleRegistry => $moduleRegistry);
$container->set(
DummyModuleScheduledJobHandler::class,
static fn (): DummyModuleScheduledJobHandler => new DummyModuleScheduledJobHandler()
);
$registry = new ScheduledJobRegistry(
$this->createMock(UserLifecycleService::class),
$this->createMock(SystemAuditService::class),
$container
);
$definitions = $registry->definitions();
self::assertArrayHasKey('addressbook.sync', $definitions);
self::assertSame('Address book sync', $definitions['addressbook.sync']['label'] ?? null);
$execution = $registry->execute('addressbook.sync', 123);
self::assertSame('success', $execution['status']);
self::assertSame(['actor' => 123], $execution['result']);
}
private function createRegistryWithModuleJob(): ModuleRegistry
{
mkdir($this->fixturesDir . '/mod-job', 0777, true);
file_put_contents(
$this->fixturesDir . '/mod-job/module.php',
'<?php return ' . var_export([
'id' => 'mod-job',
'scheduler_jobs' => [[
'job_key' => 'addressbook.sync',
'handler' => DummyModuleScheduledJobHandler::class,
'label' => 'Address book sync',
'description' => 'Sync job',
'default_enabled' => true,
'default_timezone' => 'UTC',
'default_schedule_type' => 'daily',
'default_schedule_interval' => 1,
'default_schedule_time' => '03:00',
'default_schedule_weekdays_csv' => null,
'default_catchup_once' => true,
'allowed_schedule_types' => ['daily', 'weekly'],
]],
], true) . ';'
);
return ModuleRegistry::boot($this->fixturesDir, ['mod-job']);
}
private function removeDir(string $dir): void
{
if (!is_dir($dir)) {
return;
}
$items = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($items as $item) {
if ($item->isDir()) {
rmdir($item->getPathname());
} else {
unlink($item->getPathname());
}
}
rmdir($dir);
}
}
final class DummyModuleScheduledJobHandler implements ScheduledJobHandlerInterface
{
public function definition(): array
{
return [
'label' => 'dummy',
'description' => 'dummy',
'default_enabled' => 1,
'default_timezone' => 'UTC',
'default_schedule_type' => 'daily',
'default_schedule_interval' => 1,
'default_schedule_time' => '00:00',
'default_schedule_weekdays_csv' => null,
'default_catchup_once' => 1,
'allowed_schedule_types' => ['daily'],
];
}
public function execute(?int $actorUserId): array
{
return [
'status' => 'success',
'error_code' => null,
'error_message' => null,
'result' => ['actor' => $actorUserId],
];
}
}

View File

@@ -11,6 +11,97 @@ use PHPUnit\Framework\TestCase;
class ScheduledJobServiceTest extends TestCase
{
public function testEnsureSystemJobsCreatesModuleJobDefinition(): void
{
$jobRepository = $this->createMock(ScheduledJobRepository::class);
$runRepository = $this->createMock(ScheduledJobRunRepository::class);
$registry = $this->createMock(ScheduledJobRegistry::class);
$calculator = new ScheduleCalculator();
$registry->expects($this->once())->method('definitions')->willReturn([
'addressbook.sync' => [
'label' => 'Addressbook Sync',
'description' => 'Syncs address book data',
'default_enabled' => 1,
'default_timezone' => 'UTC',
'default_schedule_type' => 'daily',
'default_schedule_interval' => 1,
'default_schedule_time' => '03:00',
'default_schedule_weekdays_csv' => null,
'default_catchup_once' => 1,
'allowed_schedule_types' => ['hourly', 'daily', 'weekly'],
],
]);
$jobRepository->expects($this->once())
->method('findByKey')
->with('addressbook.sync')
->willReturn(null);
$jobRepository->expects($this->once())
->method('create')
->with($this->callback(static function (array $job): bool {
return ($job['job_key'] ?? null) === 'addressbook.sync'
&& ($job['label'] ?? null) === 'Addressbook Sync'
&& ($job['timezone'] ?? null) === 'UTC'
&& ($job['schedule_type'] ?? null) === 'daily';
}))
->willReturn(99);
$jobRepository->expects($this->never())->method('updateJobMeta');
$service = new ScheduledJobService($jobRepository, $runRepository, $registry, $calculator);
$service->ensureSystemJobs();
}
public function testEnsureSystemJobsUpdatesExistingModuleJobMetadata(): void
{
$jobRepository = $this->createMock(ScheduledJobRepository::class);
$runRepository = $this->createMock(ScheduledJobRunRepository::class);
$registry = $this->createMock(ScheduledJobRegistry::class);
$calculator = new ScheduleCalculator();
$registry->expects($this->once())->method('definitions')->willReturn([
'addressbook.sync' => [
'label' => 'Addressbook Sync',
'description' => 'Syncs address book data',
'default_enabled' => 1,
'default_timezone' => 'UTC',
'default_schedule_type' => 'daily',
'default_schedule_interval' => 1,
'default_schedule_time' => '03:00',
'default_schedule_weekdays_csv' => null,
'default_catchup_once' => 1,
'allowed_schedule_types' => ['hourly', 'daily', 'weekly'],
],
]);
$jobRepository->expects($this->once())
->method('findByKey')
->with('addressbook.sync')
->willReturn([
'id' => 12,
'job_key' => 'addressbook.sync',
'label' => 'Old Label',
'description' => 'Old description',
'enabled' => 1,
'timezone' => 'UTC',
'schedule_type' => 'daily',
'schedule_interval' => 1,
'schedule_time' => '03:00',
'schedule_weekdays_csv' => null,
'catchup_once' => 1,
'next_run_at' => '2026-01-01 03:00:00',
]);
$jobRepository->expects($this->once())
->method('updateJobMeta')
->with(12, $this->callback(static function (array $job): bool {
return ($job['label'] ?? null) === 'Addressbook Sync'
&& ($job['description'] ?? null) === 'Syncs address book data';
}))
->willReturn(true);
$jobRepository->expects($this->never())->method('create');
$service = new ScheduledJobService($jobRepository, $runRepository, $registry, $calculator);
$service->ensureSystemJobs();
}
public function testUpdateFromAdminReturnsValidationErrorForWeeklyWithoutWeekdays(): void
{
$jobRepository = $this->createMock(ScheduledJobRepository::class);