$root . '/' . $path; foreach (array_merge($templatePaths, $browserPaths) as $path) { $assert(is_file($absolute($path)), 'User-copy inventory file is missing: ' . $path); } $discover = static function (string $pattern) use ($root): array { $files = glob($root . '/' . $pattern); if (!is_array($files)) return []; return array_map( static fn (string $path): string => substr($path, strlen($root) + 1), $files ); }; $viewRoot = $root . '/web/resources/views/venix'; $discoveredTemplates = []; $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($viewRoot, FilesystemIterator::SKIP_DOTS) ); foreach ($iterator as $file) { if (!$file->isFile() || strtolower($file->getExtension()) !== 'tpl') { continue; } $relative = substr($file->getPathname(), strlen($root) + 1); if (str_starts_with($relative, 'web/resources/views/venix/admin/')) { continue; } $discoveredTemplates[] = $relative; } sort($discoveredTemplates, SORT_STRING); $expectedTemplates = $templatePaths; sort($expectedTemplates, SORT_STRING); $assert($discoveredTemplates === $expectedTemplates, 'User-facing template inventory drifted. Add or remove the exact paths in ' . basename(__FILE__) . '.'); $cloudAdminOrInfrastructure = [ 'web/public/cloud/agent-settings.js', 'web/public/cloud/template-upload-hash-worker.js', 'web/public/cloud/template-upload-hash.js', ]; $allCloudJs = $discover('web/public/cloud/*.js'); $classifiedCloudJs = array_values(array_filter( $allCloudJs, static fn (string $path): bool => str_starts_with( basename($path), 'admin-' ) || in_array($path, $browserPaths, true) || in_array($path, $cloudAdminOrInfrastructure, true) )); sort($allCloudJs, SORT_STRING); sort($classifiedCloudJs, SORT_STRING); $assert($allCloudJs === $classifiedCloudJs, 'A cloud browser asset has no explicit user/admin/infrastructure ownership.'); $themeAdminVendorOrUnused = [ 'web/public/theme/venix/js/admin-announcements.js', 'web/public/theme/venix/js/admin-csrf.js', 'web/public/theme/venix/js/admin-home.js', 'web/public/theme/venix/js/admin-legal.js', 'web/public/theme/venix/js/fuck.js', 'web/public/theme/venix/js/jquery.js', 'web/public/theme/venix/js/qrcode.min.js', ]; $allThemeJs = $discover('web/public/theme/venix/js/*.js'); $classifiedThemeJs = array_values(array_filter( $allThemeJs, static fn (string $path): bool => in_array($path, $browserPaths, true) || in_array($path, $themeAdminVendorOrUnused, true) )); sort($allThemeJs, SORT_STRING); sort($classifiedThemeJs, SORT_STRING); $assert($allThemeJs === $classifiedThemeJs, 'A Venix browser asset has no explicit user/admin/vendor/unused ownership.'); $violations = UserCopyCoverageScanner::scanFiles(array_map( $absolute, array_merge($templatePaths, $browserPaths) )); if ($violations !== []) { $lines = array_map(static function (array $violation) use ($root): string { $path = (string) ($violation['path'] ?? ''); if (str_starts_with($path, $root . '/')) { $path = substr($path, strlen($root) + 1); } return sprintf( '%s:%d [%s] %s', $path, (int) ($violation['line'] ?? 0), (string) ($violation['rule'] ?? ''), (string) ($violation['snippet'] ?? '') ); }, $violations); throw new RuntimeException( "User-copy coverage gate found unregistered user-visible copy:\n" . implode("\n", $lines) ); } echo "All explicit user-facing templates and browser assets use the published copy catalog.\n";