(string) file_get_contents($root . '/' . $path); $assert = static function ($condition, string $message): void { if (!$condition) { throw new RuntimeException($message); } }; $controller = $read('app/Controllers/CloudPageController.php'); $pageService = $read('app/Services/Cloud/CloudVpcPageService.php'); $middleware = $read('app/Middleware/CloudApi.php'); $routes = $read('config/routes.php'); $shell = $read('resources/views/venix/cloud/page.tpl'); $template = $read('resources/views/venix/cloud/pages/vpcs.tpl'); $sidebar = $read('resources/views/venix/user/panel_sidebar.tpl'); $app = $read('public/cloud/app.js'); $script = $read('public/cloud/vpc.js'); $styles = $read('public/cloud/vpc.css'); $controllerStart = strpos($controller, 'public function vpcs('); $controllerEnd = strpos($controller, 'public function detail(', $controllerStart ?: 0); $controllerSection = $controllerStart !== false && $controllerEnd !== false ? substr($controller, $controllerStart, $controllerEnd - $controllerStart) : ''; $assert($controllerSection !== '' && str_contains($controllerSection, 'CloudAccess::actor(false)') && str_contains($controllerSection, 'CloudVpcPageService::bootstrap($actor)') && str_contains($controllerSection, 'CloudVpcService::listing($actor)') && str_contains($controllerSection, "'cloud_vpc_bootstrap_json'") && str_contains($controllerSection, '$this->safeJson($payload)'), 'VPC page must use an owner-scoped, safe database bootstrap and the typed listing projection.'); $assert(str_contains($controller, 'use App\\Services\\Cloud\\CloudVpcPageService;') && str_contains($controller, "'cloud_vpc_bootstrap_json', '{}'") && !str_contains($controllerSection, 'CloudEngineClient') && !str_contains($controllerSection, 'CloudHost'), 'VPC first paint must not contact libvirt or expose host inventory.'); $assert(str_contains($pageService, 'CloudRegionFabric') && str_contains($pageService, "->where('cloud_region_fabrics.state', 'active')") && str_contains($pageService, "->where('cloud_region_fabrics.fabric_revision', '>', 0)") && str_contains($pageService, "->where('region.status', 'active')") && str_contains($pageService, "->where('user_id', \$userId)") && str_contains($pageService, "->where('status', 'active')") && str_contains($pageService, "(string) \$row->service_status === 'active'") && str_contains($pageService, "(int) \$row->expires_at > time()") && str_contains($pageService, '->limit(200)') && !str_contains($pageService, 'CloudEngineClient') && !str_contains($pageService, "'host_id'"), 'VPC bootstrap must expose only active Fabric regions and bounded owner-scoped instances.'); $assert(str_contains($routes, "\$this->get('/cloud/vpcs', 'App\\Controllers\\CloudPageController:vpcs');"), 'Authenticated user routes must expose the VPC page.'); $assert(str_contains($middleware, "^/api/v1/vpcs(?:/[0-9a-f]{32}(?:/.*)?)?\$#D") && str_contains($middleware, 'CloudAccess::actor(!$databaseOnly)'), 'VPC API requests must stay in the PHP/database-only auth lane.'); $assert(str_contains($sidebar, 'href="/user/cloud/vpcs"') && str_contains($sidebar, "panel_cloud_active_key == 'vpcs'") && str_contains($sidebar, 'VPC 私网'), 'The user cloud navigation must expose and mark the VPC page.'); $assert(str_contains($shell, "cloud_page == 'vpcs'") && str_contains($shell, "cloud/pages/vpcs.tpl") && str_contains($shell, '/cloud/vpc.css'), 'The cloud shell must load the dedicated VPC view and styles.'); $assert(str_contains($app, "vpcs: '/cloud/vpc.js'"), 'Cloud page module routing must load the VPC module.'); foreach ([ 'vpc-create-form', 'vpc-create-region', 'vpc-create-cidr', 'vpc-create-subnet', 'vpc-list', 'vpc-detail', 'vpc-list-reconcile', 'vpc-bootstrap', ] as $id) { $assert(str_contains($template, 'id="' . $id . '"'), 'VPC view is missing required control ' . $id . '.'); } foreach (['子网与 CIDR', '成员与私网 IP', 'Route', 'VPC ACL', '最近操作'] as $label) { $assert(str_contains($script, $label), 'VPC module is missing section ' . $label . '.'); } $assert(str_contains($template, '创建 VPC'), 'VPC view is missing the create form.'); $assert(str_contains($script, "'/api/v1/vpcs'") && str_contains($script, '/subnets') && str_contains($script, '/members') && str_contains($script, '/reconcile') && str_contains($script, "kind === 'routes'") && str_contains($script, ": 'acl'") && str_contains($script, "'DELETE'") && str_contains($script, "'PUT'"), 'VPC module must cover create, subnet, member, route, ACL, reconcile and deletion APIs.'); $assert(str_contains($script, 'X-CSRF-Token') && str_contains($script, 'credentials: \'same-origin\'') && str_contains($script, 'request_key') && str_contains($script, 'function entityKey()') && str_contains($script, 'route_key: row.dataset.routeKey') && str_contains($script, 'rule_key: row.dataset.aclKey'), 'VPC mutations must use same-origin CSRF protection and separate idempotency/entity keys.'); foreach (['applying', 'degraded', 'uncertain', 'waiting', 'active'] as $status) { $assert(str_contains($script, $status), 'VPC UI lost state projection for ' . $status . '.'); } $assert(str_contains($script, 'usable === true') && str_contains($script, 'desired_revision') && str_contains($script, 'observed_revision') && str_contains($script, 'setTimeout') && str_contains($script, 'visibilitychange') && str_contains($script, 'AbortController') && str_contains($script, 'loadDetail(state.selectedKey, true)') && str_contains($script, 'state.detailDirty') && str_contains($script, 'allowDirty = false'), 'VPC UI must poll desired/observed state, pause hidden tabs and only show active after usable readback.'); $assert(str_contains($script, 'data-vpc-tombstone-state="deleting"') && str_contains($script, 'pendingTombstones') && str_contains($script, 'sameRegion') && str_contains($script, 'alreadyAttached') && str_contains($script, 'option.disabled') && str_contains($script, 'requestFingerprint') && str_contains($script, 'confirmDetailMutation'), 'VPC editors must preserve dirty drafts, block only in-flight tombstones and constrain member choices.'); $assert(!str_contains($script, '/internal/v1/') && !str_contains($script, 'host_id') && !str_contains($script, 'credential_cipher'), 'Tenant VPC JavaScript must not call private engine endpoints or expose host credentials.'); $assert(str_contains($styles, '.vpc-state-pill') && str_contains($styles, '.vpc-columns') && str_contains($styles, '@media'), 'VPC page needs dedicated state/list/detail responsive styling.'); echo "Tenant VPC page, API wiring and state-polling contract passed.\n";