feat: module architecture improvements — session keys, dependency graph, event dispatcher, deactivation hooks

Six targeted improvements to the modular monolith platform:

1. Fix AddressBook session key prefix to follow module.<id>.* convention
2. Move ADDRESS_BOOK_VIEW permission constant from core PermissionService into module
3. Add declarative JSON schema for module manifests (.agents/contracts/)
4. Add `requires` field with missing-dependency and circular-dependency detection
5. Add lightweight fire-and-forget event dispatcher (user.created/deleted/login/logout)
6. Add module deactivation hook interface and CLI script (bin/module-deactivate.php)

Includes 15 new architecture/unit tests covering all new functionality.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 18:20:13 +01:00
parent 866d43e15a
commit ef72b34c40
31 changed files with 1041 additions and 75 deletions

View File

@@ -364,7 +364,7 @@ class UserAuthorizationPolicyTest extends TestCase
public function testAvatarViewAllowsInScopeAddressBookViewer(): void
{
$permissionService = $this->permissionGatewayAllowing([
5 => [PermissionService::ADDRESS_BOOK_VIEW],
5 => ['address_book.view'],
]);
$scopeGateway = $this->createMock(TenantScopeService::class);

View File

@@ -34,7 +34,7 @@ class AuthSessionTenantContextServiceTest extends TestCase
$this->assertSame([], $_SESSION['available_tenants']);
$this->assertTrue((bool) $_SESSION['no_active_tenant']);
$this->assertArrayNotHasKey('current_tenant', $_SESSION);
$this->assertArrayNotHasKey('available_departments_by_tenant', $_SESSION);
$this->assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
}
public function testHydrateUsesFirstAvailableTenantAsFallback(): void
@@ -54,7 +54,7 @@ class AuthSessionTenantContextServiceTest extends TestCase
$this->assertSame($availableTenants, $_SESSION['available_tenants']);
$this->assertFalse((bool) $_SESSION['no_active_tenant']);
$this->assertSame(7, (int) ($_SESSION['current_tenant']['id'] ?? 0));
$this->assertArrayNotHasKey('available_departments_by_tenant', $_SESSION);
$this->assertArrayNotHasKey('module.addressbook.departments_by_tenant', $_SESSION);
}
public function testHydratePreservesThemeAndPolicyFieldsInSession(): void