You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudInvoiceListPerformance...

50 lines
2.8 KiB
PHP

<?php
// Static contract: invoice first paint must remain a single server-rendered
// request and the list bundle must not regress to the all-feature VM runtime.
$root = dirname(__DIR__);
$assert = static function ($condition, $message) {
if (!$condition) {
throw new RuntimeException($message);
}
};
$controller = file_get_contents($root . '/app/Controllers/CloudPageController.php');
$service = file_get_contents($root . '/app/Services/Cloud/CloudInvoicePageService.php');
$shell = file_get_contents($root . '/resources/views/venix/cloud/page.tpl');
$template = file_get_contents($root . '/resources/views/venix/cloud/pages/invoices.tpl');
$topbar = file_get_contents($root . '/resources/views/venix/user/panel_topbar.tpl');
$module = file_get_contents($root . '/public/cloud/invoices.js');
$assert(str_contains($controller, 'CloudAccess::actor(false)')
&& str_contains($controller, "getAttribute('auth_user')")
&& str_contains($controller, 'CloudInvoicePageService::forUser')
&& str_contains($controller, 'JSON_HEX_TAG')
&& str_contains($controller, "'cloud_invoice_bootstrap_json'")
&& str_contains($controller, "withHeader('Cache-Control', 'private, no-store')"),
'Invoice page controller must safely embed an owner-scoped first page without a cloud session.');
$assert(str_contains($service, "CloudInvoice::where('user_id', \$userId)")
&& str_contains($service, 'CloudInvoiceService::listSummaries')
&& str_contains($service, "'per_page' => \$perPage")
&& str_contains($service, "->limit(\$perPage)"),
'Shared invoice pagination must remain owner scoped and bounded.');
$assert(str_contains($template, 'id="invoices-bootstrap"')
&& str_contains($template, '{foreach $cloud_invoice_rows as $invoice}')
&& !str_contains($template, '正在加载…'),
'Invoice HTML must contain the first records instead of a client-only loading placeholder.');
$assert(!str_contains($module, '/cloud/runtime.js')
&& !str_contains($module, '/api/v1/session')
&& str_contains($module, 'function hydrate()')
&& str_contains($module, 'state.invoices.some(invoiceNeedsPolling)')
&& str_contains($module, "['completed', 'succeeded', 'active', 'failed', 'refunded'")
&& str_contains($module, "'needs_attention'].includes(fulfillmentStatus(invoice))")
&& !str_contains($module, 'setInterval('),
'Invoice list module must be lightweight and stop polling terminal records.');
$assert(!str_contains($shell, '/theme/venix/js/qrcode.min.js'),
'The shared cloud shell must not block first paint on the QR code library.');
$assert(str_contains($topbar, "\$user->user_name|default:'账户'")
&& !str_contains($topbar, '{if $panel_cloud_mode}账户{else}'),
'Cloud pages must render the authenticated account name without a session API request.');
echo "Invoice server-rendered first-page performance contract passed.\n";