TenantAtlas/apps/platform/tests/Feature/TenantConfiguration/TenantConfigurationKernelSchemaTest.php
ahmido dfda397eb6 feat: migrate tcm first coverage core cutover (#481)
Automated PR provided by Codex via Gitea API.

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #481
2026-06-25 12:54:56 +00:00

79 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
it('Spec414 required kernel definition tables do not introduce ownership columns', function () {
foreach (['tenant_configuration_resource_types', 'tenant_configuration_supported_scopes'] as $table) {
expect(Schema::hasTable($table))->toBeTrue();
$columns = Schema::getColumnListing($table);
expect($columns)
->not->toContain('tenant_id')
->not->toContain('workspace_id')
->not->toContain('managed_environment_id')
->not->toContain('provider_connection_id');
}
});
it('Spec414 keeps provider-native tenant identifiers out of Coverage v2 ownership schema', function () {
$coverageColumns = collect([
...Schema::getColumnListing('tenant_configuration_resource_types'),
...Schema::getColumnListing('tenant_configuration_supported_scopes'),
]);
expect($coverageColumns->filter(
fn (string $column): bool => str_contains($column, 'tenant_id')
|| str_contains($column, 'entra_tenant_id')
|| str_contains($column, 'provider_tenant_id')
|| str_contains($column, 'source_tenant_id')
|| str_contains($column, 'external_tenant_id')
)->values()->all())->toBe([]);
});
it('Spec414 keeps historical migration seed semantics independent from mutable runtime defaults', function () {
$migration = file_get_contents(database_path('migrations/2026_06_25_000414_create_tenant_configuration_kernel_tables.php'));
expect($migration)->not->toContain('App\\Services\\TenantConfiguration\\ResourceTypeRegistry')
->not->toContain('App\\Services\\TenantConfiguration\\SupportedScopeResolver')
->not->toContain('App\\Support\\TenantConfiguration')
->and($migration)->toContain('private function resourceTypeDefinitions')
->toContain('private function supportedScopeDefinitions')
->toContain('private const SOURCE_CLASSES');
});
it('Spec414 proves PostgreSQL JSONB and check constraints for kernel definitions', function () {
if (DB::getDriverName() !== 'pgsql') {
$this->markTestSkipped('PostgreSQL-specific Coverage v2 kernel schema proof runs in the pgsql lane.');
}
$columns = collect(DB::select(<<<'SQL'
SELECT table_name, column_name, data_type
FROM information_schema.columns
WHERE table_name IN ('tenant_configuration_resource_types', 'tenant_configuration_supported_scopes')
AND column_name IN ('metadata', 'included_resource_types')
SQL))->mapWithKeys(
fn (object $row): array => [$row->table_name.'.'.$row->column_name => $row->data_type],
);
expect($columns['tenant_configuration_resource_types.metadata'])->toBe('jsonb')
->and($columns['tenant_configuration_supported_scopes.metadata'])->toBe('jsonb')
->and($columns['tenant_configuration_supported_scopes.included_resource_types'])->toBe('jsonb');
$constraints = collect(DB::select(<<<'SQL'
SELECT conname
FROM pg_constraint
WHERE conrelid IN (
'tenant_configuration_resource_types'::regclass,
'tenant_configuration_supported_scopes'::regclass
)
SQL))->pluck('conname')->all();
expect($constraints)
->toContain('tenant_config_resource_types_source_class_check')
->toContain('tenant_config_supported_scopes_denominator_array_check');
});