From c8201e11a688f1cc6aeb77d02ca521d624800e00 Mon Sep 17 00:00:00 2001 From: codex Date: Wed, 18 Nov 2026 03:56:33 +0800 Subject: [PATCH] fix(ui): distinguish booked traffic balances from the latest sample --- docs/TRAFFIC_POOL.md | 20 +++++----- docs/TRAFFIC_POOL_ROLLOUT.md | 19 ++++++--- web/app/Controllers/CloudPageController.php | 1 + .../Cloud/CloudAdminTrafficPoolService.php | 6 ++- .../Cloud/CloudTrafficPoolFreshness.php | 28 ++----------- .../Cloud/CloudTrafficPoolReadModel.php | 7 +--- web/app/Services/Cloud/CloudUserPageView.php | 35 +++++++++-------- web/public/cloud/runtime.js | 12 +++++- web/public/cloud/traffic-accounting.js | 39 +++++++++++++++++++ web/public/cloud/traffic.js | 39 +------------------ .../entries/backup-network.entries.php | 28 ++++++------- .../entries/detail-reinstall.entries.php | 2 +- web/resources/user-copy/manifest.php | 4 +- .../views/venix/admin/cloud/resources.tpl | 8 ++++ .../views/venix/cloud/pages/detail.tpl | 5 +++ .../views/venix/cloud/pages/traffic.tpl | 2 +- .../cloud/partials/traffic-accounting.tpl | 7 ++++ web/resources/views/venix/layout_assets.tpl | 2 +- .../CloudAdminTrafficPoolServiceTest.php | 9 +++-- .../CloudAdminTrafficPoolUiContractTest.php | 3 ++ web/tests/CloudInstancePageServiceTest.php | 14 +++++++ web/tests/CloudTrafficPoolFreshnessTest.php | 14 +++---- .../CloudTrafficPoolLineBehaviorTest.mjs | 10 +++-- .../CloudTrafficPoolUserReadModelTest.php | 1 - .../CloudTrafficPoolUserUiContractTest.php | 14 +++---- web/tests/CloudUserFirstPaintViewTest.php | 19 +++++++-- web/tests/UserCopyCompleteCoverageTest.php | 2 + web/tests/UserCopyManifestContractTest.php | 17 +++++++- 28 files changed, 216 insertions(+), 151 deletions(-) create mode 100644 web/public/cloud/traffic-accounting.js create mode 100644 web/resources/views/venix/cloud/partials/traffic-accounting.tpl diff --git a/docs/TRAFFIC_POOL.md b/docs/TRAFFIC_POOL.md index 13b15fa5..844ff102 100644 --- a/docs/TRAFFIC_POOL.md +++ b/docs/TRAFFIC_POOL.md @@ -155,16 +155,16 @@ The primary user values are: - the next expiry time and the unused bytes that will be forfeited then; - last trusted observation and network-restriction state. -The read model also projects one accounting-freshness state from the same -durable pool, cursor, scan-failure and settlement-bucket evidence. User and -administrator views must use that shared state; neither may infer freshness -from browser request time. The user surface exposes only `current`, `delayed` -or `attention` plus the last confirmed timestamp. Shared quota, consumption, -balance and overage are labelled as last-confirmed values whenever newer -instance counters are still settling or require review. Per-instance RX/TX -samples remain visible as raw observations and are never relabelled as settled -pool accounting. Internal failure codes, subject identifiers and repair -details are administrator-only evidence. +Pool balances and accounting status are read in one short database snapshot. +The quota, used bytes, available balance and overage are the amounts currently +booked in the ledger. The user sees the status (`current`, `delayed` or +`attention`) and, when available, the latest sample time among live members. +That timestamp dates an observation. Historical balances cannot be inferred +from it. Per-instance RX/TX are raw observations. A live sample with unchanged +counters requires no cursor write. Deleted instances keep their unexpired paid +entitlements and outstanding final bytes are settled. Once final counters match, +the deleted member no longer contributes to sample staleness. Administrator +views also show unsettled instances and failures requiring investigation. Lifetime or calendar-month usage is a separate statistic. It must not be divided by the currently active quota because expired entitlements legitimately diff --git a/docs/TRAFFIC_POOL_ROLLOUT.md b/docs/TRAFFIC_POOL_ROLLOUT.md index 53b89385..600874fc 100644 --- a/docs/TRAFFIC_POOL_ROLLOUT.md +++ b/docs/TRAFFIC_POOL_ROLLOUT.md @@ -212,14 +212,19 @@ checks in enforced mode with controlled test instances: `service_expired` or `admin_hold`; - the user page exposes only enforced groups and never presents shadow data as an active shared allowance; -- delayed or attention accounting is visible as a last-confirmed balance with - its confirmation time, while per-instance raw samples remain available; +- user pools, instance details and administrator lines distinguish the booked + balance from the latest live sample time, including delayed or attention states; - pool or cursor attention prevents an untrusted automatic network restore; - repeated lifecycle ticks neither double-charge usage nor create duplicate network mutations; - an Agent outage or unknown sample fails open for traffic accounting while ordinary service expiry remains enforceable. +After deploying, review the nine shared `traffic.freshness.*` entries under +user-interface translation feedback. Publish the target languages for the +pool list and instance detail together. Translations that display a sampling +time must preserve the `{sample_time}` placeholder. + Static and local checks do not replace a controlled Agent/network acceptance test. Record the release commit, group revision, involved instance IDs, sample timestamps, task IDs and operation IDs. @@ -352,7 +357,10 @@ exists. If the plan is clean, execute that exact generation once: php xcat cloudTrafficSettlementRecovery apply --plan-hash= --apply ``` -Any intervening state change invalidates the hash and requires a new inspect. +The writer checks each approved action again at settlement. A changed action +stops the run with a nonzero exit code and reports completed and remaining IDs. +An inspected scan failure is cleared only after its subject has settled and +only if the same failure generation still exists. Inspect again after a partial run. Apply uses only the ordinary bucket sealing, period reconciliation and usage settlement interfaces. It cannot delete or rewrite an immutable ledger event, change an entitlement balance manually, clear attention, or dispatch an Agent @@ -416,8 +424,9 @@ policy decision. Deploy it as a clean schema/code boundary: 6. Deploy the matching code and restart lifecycle. Open the administrator task page and run its read-only health check. The “流量结算与存储” row exposes overdue open buckets, longest accounting delay, event-identity conflicts, - unsettled and stale-cursor instances, recent accounting failures, due - compaction rows and cursor attention without exposing IDs or payloads. + unsettled instances, aging unbooked samples, live instances with stale + sampling, recent scan failures, due compaction rows and all attention + cursors without exposing IDs or payloads. 7. Keep the pool in its existing rollout state while observing at least one complete collection, accounting, settlement-compaction and checkpoint-compaction pass. A backlog less than one hour beyond its diff --git a/web/app/Controllers/CloudPageController.php b/web/app/Controllers/CloudPageController.php index dad648fe..9edcc65f 100644 --- a/web/app/Controllers/CloudPageController.php +++ b/web/app/Controllers/CloudPageController.php @@ -885,6 +885,7 @@ final class CloudPageController '.', '' )), + 'traffic_accounting' => CloudUserPageView::trafficAccounting($pool), 'traffic_pool_name' => $accountingMode === 'pooled' ? trim((string) ($pool['name'] ?? '')) : '', ]; diff --git a/web/app/Services/Cloud/CloudAdminTrafficPoolService.php b/web/app/Services/Cloud/CloudAdminTrafficPoolService.php index 25ead0db..87616fe2 100644 --- a/web/app/Services/Cloud/CloudAdminTrafficPoolService.php +++ b/web/app/Services/Cloud/CloudAdminTrafficPoolService.php @@ -506,6 +506,7 @@ final class CloudAdminTrafficPoolService } } $staleBefore = $now - self::SAMPLE_FRESHNESS_SECONDS; + $activeInstanceCount = 0; foreach ($activePeriods as $instanceId => $period) { $instance = $instances[$instanceId] ?? null; if ($instance === null || !in_array($instance->status, ['active', 'deleted'], true)) { @@ -513,6 +514,9 @@ final class CloudAdminTrafficPoolService continue; } $expectsSample = CloudTrafficAccountingEvidence::expectsSample($instance->status); + if ($expectsSample) { + $activeInstanceCount++; + } if ($expectsSample && !in_array((string) $instance->network_status, [ 'active', 'blocked_traffic', 'blocked_expired', ], true)) { @@ -612,7 +616,7 @@ final class CloudAdminTrafficPoolService 'line_count' => $lineCount, 'pool_count' => count($poolById), 'period_count' => count($periodIds), - 'active_instance_count' => count($activePeriods), + 'active_instance_count' => $activeInstanceCount, 'blockers' => $list, ]; } diff --git a/web/app/Services/Cloud/CloudTrafficPoolFreshness.php b/web/app/Services/Cloud/CloudTrafficPoolFreshness.php index 5ca4688a..7ac94c2b 100644 --- a/web/app/Services/Cloud/CloudTrafficPoolFreshness.php +++ b/web/app/Services/Cloud/CloudTrafficPoolFreshness.php @@ -180,7 +180,6 @@ final class CloudTrafficPoolFreshness $code = 'current'; $unsettled = []; $stale = []; - $confirmed = []; $latestSample = 0; $pendingEntitlement = false; if ((string) $snapshot['state'] === 'attention') { @@ -215,11 +214,6 @@ final class CloudTrafficPoolFreshness (int) $fact->lifetime_download_bytes, (int) $fact->lifetime_upload_bytes, (int) $fact->accounted_download_bytes, (int) $fact->accounted_upload_bytes ); - if ($expectsSample && (int) $fact->last_observed_at > 0) { - $confirmed[] = $counters === 'settled' - ? max((int) $fact->traffic_synced_at, (int) $fact->last_observed_at) - : (int) $fact->last_observed_at; - } if ($fact->cursor_state !== 'ready' || $counters === 'regression') { $unsettled[$instanceId] = true; $status = 'attention'; @@ -260,19 +254,12 @@ final class CloudTrafficPoolFreshness $status = 'delayed'; $code = 'settlement_delayed'; } - $lastConfirmed = $confirmed === [] - ? ((($factsByKey[$key] ?? []) === []) - ? (($snapshot['last_observed_at'] ?? null) === null - ? null : (int) $snapshot['last_observed_at']) - : null) - : min($confirmed); $result[$key] = [ 'status' => $status, - 'last_confirmed_at' => $lastConfirmed, 'last_sample_at' => $latestSample ?: null, 'projection_pending' => $pendingEntitlement, 'unsettled_instance_count' => count($unsettled), - 'stale_cursor_count' => count($stale), + 'stale_sample_count' => count($stale), 'overdue_bucket_count' => (int) $due['count'], 'safe_code' => $code, ]; @@ -356,7 +343,6 @@ final class CloudTrafficPoolFreshness } $rank = ['current' => 0, 'delayed' => 1, 'attention' => 2]; $status = 'current'; - $lastConfirmed = []; $latestSample = 0; $unsettled = 0; $stale = 0; @@ -366,20 +352,15 @@ final class CloudTrafficPoolFreshness $status = $snapshot['status']; } $latestSample = max($latestSample, (int) $snapshot['last_sample_at']); - if ($snapshot['last_confirmed_at'] !== null) { - $lastConfirmed[] = (int) $snapshot['last_confirmed_at']; - } $unsettled += (int) $snapshot['unsettled_instance_count']; - $stale += (int) $snapshot['stale_cursor_count']; + $stale += (int) $snapshot['stale_sample_count']; $overdue += (int) $snapshot['overdue_bucket_count']; } return [ 'status' => $status, 'last_sample_at' => $latestSample ?: null, - 'last_confirmed_at' => count($lastConfirmed) === count($snapshots) - ? min($lastConfirmed) : null, 'unsettled_instance_count' => $unsettled, - 'stale_cursor_count' => $stale, + 'stale_sample_count' => $stale, 'overdue_bucket_count' => $overdue, 'safe_code' => $status === 'current' ? 'current' : 'group_' . $status, @@ -392,11 +373,10 @@ final class CloudTrafficPoolFreshness { return [ 'status' => $code === 'no_pools' ? 'current' : 'delayed', - 'last_confirmed_at' => null, 'last_sample_at' => null, 'projection_pending' => $code === 'projection_pending', 'unsettled_instance_count' => 0, - 'stale_cursor_count' => 0, + 'stale_sample_count' => 0, 'overdue_bucket_count' => 0, 'safe_code' => $code, ]; diff --git a/web/app/Services/Cloud/CloudTrafficPoolReadModel.php b/web/app/Services/Cloud/CloudTrafficPoolReadModel.php index 5f2042ae..bb3c3f45 100644 --- a/web/app/Services/Cloud/CloudTrafficPoolReadModel.php +++ b/web/app/Services/Cloud/CloudTrafficPoolReadModel.php @@ -305,9 +305,6 @@ final class CloudTrafficPoolReadModel 'status' => !$projectionReady && ($freshness['status'] ?? '') === 'current' ? 'delayed' : (string) ($freshness['status'] ?? 'delayed'), 'last_sample_at' => $freshness['last_sample_at'] ?? null, - 'last_confirmed_at' => - ($freshness['last_confirmed_at'] ?? null) === null - ? null : (int) $freshness['last_confirmed_at'], ], 'network_restriction_state' => $networkState, 'instances' => array_values($instances), @@ -318,9 +315,9 @@ final class CloudTrafficPoolReadModel { return [ 'status' => 'delayed', - 'last_confirmed_at' => null, + 'last_sample_at' => null, 'unsettled_instance_count' => 0, - 'stale_cursor_count' => 0, + 'stale_sample_count' => 0, 'safe_code' => 'projection_pending', ]; } diff --git a/web/app/Services/Cloud/CloudUserPageView.php b/web/app/Services/Cloud/CloudUserPageView.php index 23f01c56..5e7988e6 100644 --- a/web/app/Services/Cloud/CloudUserPageView.php +++ b/web/app/Services/Cloud/CloudUserPageView.php @@ -128,23 +128,27 @@ final class CloudUserPageView ]; } + public static function trafficAccounting(array $pool): array + { + $evidence = $pool['accounting_freshness'] ?? []; + $status = $evidence['status'] ?? null; + if (!in_array($status, ['current', 'delayed', 'attention'], true)) { + $status = 'attention'; + } + $sample = (int) ($evidence['last_sample_at'] ?? 0); + $label = 'traffic.freshness.' . $status; + return [ + 'status' => $status, + 'label_key' => $label, + 'message_key' => $label . ($sample > 0 ? '_at' : '_without_time'), + 'sample_display' => $sample > 0 ? gmdate('Y-m-d H:i', $sample) . ' UTC' : '', + ]; + } + /** @return array */ private static function trafficPool(array $pool): array { $projectionReady = ($pool['projection_ready'] ?? false) === true; - $freshness = is_array($pool['accounting_freshness'] ?? null) - ? $pool['accounting_freshness'] : []; - $freshnessStatus = (string) ($freshness['status'] ?? 'delayed'); - if (!in_array( - $freshnessStatus, - ['current', 'delayed', 'attention'], - true - )) { - $freshnessStatus = 'attention'; - } - $confirmedAt = max(0, (int) ( - $freshness['last_confirmed_at'] ?? 0 - )); [$stateLabel, $stateClass] = self::state( (string) ($pool['state'] ?? ''), [ @@ -213,10 +217,7 @@ final class CloudUserPageView 'state_class' => $stateClass, 'network_label' => $networkLabel, 'network_class' => $networkClass, - 'accounting_status' => $freshnessStatus, - 'accounting_confirmed_display' => $confirmedAt > 0 - ? self::date($confirmedAt) : '', - 'accounting_has_confirmation' => $confirmedAt > 0, + 'accounting' => self::trafficAccounting($pool), 'entitlement_display' => $projectionReady ? self::bytes( $pool['active_entitlement_bytes'] ?? null ) : '正在准备', diff --git a/web/public/cloud/runtime.js b/web/public/cloud/runtime.js index b302b0f8..665ff35c 100644 --- a/web/public/cloud/runtime.js +++ b/web/public/cloud/runtime.js @@ -7,12 +7,14 @@ function versionedModuleUrl(path) { return url.href; } -const [toastModule, taskObserver, instanceService] = await Promise.all([ +const [toastModule, taskObserver, instanceService, trafficAccounting] = await Promise.all([ import(versionedModuleUrl('./toast.js')), import(versionedModuleUrl('./task-observer.js')), import(versionedModuleUrl('./instance-service.js')), + import(versionedModuleUrl('./traffic-accounting.js')), ]); const { toast } = toastModule; +const { renderAccountingFreshness } = trafficAccounting; const { formatServiceDate, servicePaused, serviceTimestamp } = instanceService; const i18n = globalThis.VenixUserCopy; const t = (key, parameters = {}) => i18n.text(key, parameters); @@ -447,6 +449,12 @@ function renderVmService(vm) { : unlimited ? t('instance_detail.traffic.unlimited_pair') : `${formatBytes(data.quota)} / ${formatBytes(data.remaining)}`); + const accounting = byId('vm-detail-traffic-accounting'); + if (accounting) { + accounting.hidden = !pooled; + if (pooled) accounting.replaceChildren(renderAccountingFreshness(data.pool)); + else accounting.replaceChildren(); + } const poolLink = byId('vm-detail-traffic-pool-link'); if (poolLink) { poolLink.hidden = !pooled; @@ -2492,7 +2500,7 @@ export { drawVmTrafficDaily, hydrateVmDetailBootstrap, initializeSession, loadGlobalTemplates, loadKeys, loadVmMetrics, loadVmTrafficDaily, loadVm, loadVmStatus, loadVms, navigate, openCreate, openReinstall, reinstall, - readBootstrap, renderVMs, renderVmDetail, renderVmMetrics, selectVmByApiId, selectedVm, + readBootstrap, renderAccountingFreshness, renderVMs, renderVmDetail, renderVmMetrics, selectVmByApiId, selectedVm, setVmDetailTab, showError, state, stopVmMetrics, stopVmTrafficDaily, toast, trafficDailyViewVisible, vmIp, vmPagePath, diff --git a/web/public/cloud/traffic-accounting.js b/web/public/cloud/traffic-accounting.js new file mode 100644 index 00000000..0c00b6e5 --- /dev/null +++ b/web/public/cloud/traffic-accounting.js @@ -0,0 +1,39 @@ +// Shared by the traffic-pool list and the instance detail status refresh. +export function accountingFreshness(pool, catalog = globalThis.VenixUserCopy) { + const evidence = pool?.accounting_freshness; + const status = ['current', 'delayed', 'attention'].includes(evidence?.status) + ? evidence.status : 'attention'; + const sample = Number(evidence?.last_sample_at); + const hasSample = Number.isFinite(sample) && sample > 0; + return { + status, + label: catalog.text(`traffic.freshness.${status}`), + message: catalog.text(`traffic.freshness.${status}_${hasSample ? 'at' : 'without_time'}`, + hasSample ? { sample_time: catalog.date(sample) } : {}), + }; +} + +export function renderAccountingFreshness(pool, document = globalThis.document, catalog = globalThis.VenixUserCopy) { + const freshness = accountingFreshness(pool, catalog); + function element(tag, className, text) { + const node = document.createElement(tag); + node.className = className; + if (text !== undefined) node.textContent = text; + return node; + } + const box = element('div', + `cloud-traffic-accounting cloud-traffic-accounting-${freshness.status}`); + const icon = element('span', 'cloud-traffic-accounting-icon'); + const marker = element('i', freshness.status === 'current' + ? 'mdi mdi-check-circle-outline' + : freshness.status === 'delayed' + ? 'mdi mdi-clock-alert-outline' + : 'mdi mdi-alert-circle-outline'); + marker.setAttribute('aria-hidden', 'true'); + icon.append(marker); + const copy = element('span', 'cloud-traffic-accounting-copy'); + copy.append(element('strong', '', freshness.label), + element('small', '', freshness.message)); + box.append(icon, copy); + return box; +} diff --git a/web/public/cloud/traffic.js b/web/public/cloud/traffic.js index 1e1c6fd9..2c360569 100644 --- a/web/public/cloud/traffic.js +++ b/web/public/cloud/traffic.js @@ -8,7 +8,7 @@ function versionedModuleUrl(path) { } const { - api, byId, initializeSession, readBootstrap, showError, + api, byId, initializeSession, readBootstrap, showError, renderAccountingFreshness, } = await import(versionedModuleUrl('./runtime.js')); const i18n = globalThis.VenixUserCopy; const t = (key, parameters = {}) => i18n.text(key, parameters); @@ -82,43 +82,6 @@ function linePoolState(value) { })[String(value || '')] || [t('traffic.status.unknown'), 'other']; } -function accountingFreshness(pool) { - const freshness = pool?.accounting_freshness; - const status = ['current', 'delayed', 'attention'].includes(freshness?.status) - ? freshness.status : 'attention'; - const confirmedAt = Number(freshness?.last_confirmed_at); - const hasConfirmation = Number.isFinite(confirmedAt) && confirmedAt > 0; - const labelKey = `traffic.freshness.${status}`; - const messageKey = `traffic.freshness.${status}_${hasConfirmation - ? 'at' : 'without_time'}`; - return { - status, - label: t(labelKey), - message: t(messageKey, hasConfirmation ? { - date: formatDate(confirmedAt, t('traffic.value.time_missing')), - } : {}), - }; -} - -function renderAccountingFreshness(pool) { - const freshness = accountingFreshness(pool); - const box = element('div', - `cloud-traffic-accounting cloud-traffic-accounting-${freshness.status}`); - const icon = element('span', 'cloud-traffic-accounting-icon'); - const marker = element('i', freshness.status === 'current' - ? 'mdi mdi-check-circle-outline' - : freshness.status === 'delayed' - ? 'mdi mdi-clock-alert-outline' - : 'mdi mdi-alert-circle-outline'); - marker.setAttribute('aria-hidden', 'true'); - icon.append(marker); - const copy = element('span', 'cloud-traffic-accounting-copy'); - copy.append(element('strong', '', freshness.label), - element('small', '', freshness.message)); - box.append(icon, copy); - return box; -} - function instanceNetwork(value) { return ({ active: [t('traffic.status.instance.active'), 'running'], diff --git a/web/resources/user-copy/entries/backup-network.entries.php b/web/resources/user-copy/entries/backup-network.entries.php index ddbea262..5c2beae0 100644 --- a/web/resources/user-copy/entries/backup-network.entries.php +++ b/web/resources/user-copy/entries/backup-network.entries.php @@ -124,22 +124,22 @@ return [ $entry('traffic.coverage.label', 'traffic', 'cloud.traffic', '覆盖:{regions}', 'description', ['regions' => 'string']), $entry('traffic.coverage.unknown', 'traffic', 'cloud.traffic', '覆盖地区待核查', 'status', []), $entry('traffic.intro', 'traffic', 'cloud.traffic', '最早到期的有效额度优先消耗;当前线路内的实例共同使用可用余额。', 'description', []), - $entry('traffic.fact.entitlement', 'traffic', 'cloud.traffic', '最后确认有效额度', 'label', []), - $entry('traffic.fact.consumed', 'traffic', 'cloud.traffic', '最后确认已消耗', 'label', []), - $entry('traffic.fact.available', 'traffic', 'cloud.traffic', '最后确认可用余额', 'label', []), - $entry('traffic.fact.overage', 'traffic', 'cloud.traffic', '最后确认超额流量', 'label', []), + $entry('traffic.fact.entitlement', 'traffic', 'cloud.traffic', '当前有效额度', 'label', []), + $entry('traffic.fact.consumed', 'traffic', 'cloud.traffic', '已入账用量', 'label', []), + $entry('traffic.fact.available', 'traffic', 'cloud.traffic', '已入账可用余额', 'label', []), + $entry('traffic.fact.overage', 'traffic', 'cloud.traffic', '已入账超额流量', 'label', []), $entry('traffic.fact.next_expiry', 'traffic', 'cloud.traffic', '下一批到期', 'label', []), $entry('traffic.fact.expiry_note', 'traffic', 'cloud.traffic', '届时作废 {amount}', 'help', ['amount' => 'string']), - $entry('traffic.fact.last_observed', 'traffic', 'cloud.traffic', '最近实例采样', 'label', []), - $entry('traffic.freshness.current', 'traffic', 'cloud.traffic', '账务已确认', 'status', []), - $entry('traffic.freshness.delayed', 'traffic', 'cloud.traffic', '账务结算延迟', 'status', []), - $entry('traffic.freshness.attention', 'traffic', 'cloud.traffic', '账务需要核对', 'status', []), - $entry('traffic.freshness.current_at', 'traffic', 'cloud.traffic', '共享额度已确认至 {date}。', 'help', ['date' => 'string']), - $entry('traffic.freshness.current_without_time', 'traffic', 'cloud.traffic', '共享额度已完成确认。', 'help', []), - $entry('traffic.freshness.delayed_at', 'traffic', 'cloud.traffic', '最新采样正在结算;以下共享额度为 {date} 的最后确认结果。', 'help', ['date' => 'string']), - $entry('traffic.freshness.delayed_without_time', 'traffic', 'cloud.traffic', '最新采样正在结算;以下共享额度为最后确认结果,确认时间暂未记录。', 'help', []), - $entry('traffic.freshness.attention_at', 'traffic', 'cloud.traffic', '账务正在核对;以下共享额度为 {date} 的最后确认结果。', 'help', ['date' => 'string']), - $entry('traffic.freshness.attention_without_time', 'traffic', 'cloud.traffic', '账务正在核对;以下共享额度为最后确认结果,确认时间暂未记录。', 'help', []), + $entry('traffic.fact.last_observed', 'traffic', 'cloud.traffic', '最近纳入结算的采样', 'label', []), + $entry('traffic.freshness.current', 'traffic_accounting', 'cloud.traffic', '账务已结算', 'status', []), + $entry('traffic.freshness.delayed', 'traffic_accounting', 'cloud.traffic', '结算延迟', 'status', []), + $entry('traffic.freshness.attention', 'traffic_accounting', 'cloud.traffic', '账务待核对', 'status', []), + $entry('traffic.freshness.current_at', 'traffic_accounting', 'cloud.traffic', '当前显示已入账余额。最近实例采样于 {sample_time}。', 'help', ['sample_time' => 'string'], 'required', false, null, 'feedback'), + $entry('traffic.freshness.current_without_time', 'traffic_accounting', 'cloud.traffic', '当前显示已入账余额。', 'help', [], 'required', false, null, 'feedback'), + $entry('traffic.freshness.delayed_at', 'traffic_accounting', 'cloud.traffic', '当前显示已入账余额,新的流量可能尚未计入。最近实例采样于 {sample_time}。', 'help', ['sample_time' => 'string'], 'required', false, null, 'feedback'), + $entry('traffic.freshness.delayed_without_time', 'traffic_accounting', 'cloud.traffic', '当前显示已入账余额,新的流量可能尚未计入。', 'help', [], 'required', false, null, 'feedback'), + $entry('traffic.freshness.attention_at', 'traffic_accounting', 'cloud.traffic', '当前显示已入账余额,核对后可能调整。最近实例采样于 {sample_time}。', 'help', ['sample_time' => 'string'], 'required', false, null, 'feedback'), + $entry('traffic.freshness.attention_without_time', 'traffic_accounting', 'cloud.traffic', '当前显示已入账余额,核对后可能调整。', 'help', [], 'required', false, null, 'feedback'), $entry('traffic.instances.title', 'traffic', 'cloud.traffic', '当前实例', 'label', []), $entry('traffic.instances.count', 'traffic', 'cloud.traffic', '{count} 台', 'status', ['count' => 'integer']), $entry('traffic.instances.aria', 'traffic', 'cloud.traffic', '{name} 的实例', 'aria_label', ['name' => 'string']), diff --git a/web/resources/user-copy/entries/detail-reinstall.entries.php b/web/resources/user-copy/entries/detail-reinstall.entries.php index 7e03854a..94a3f764 100644 --- a/web/resources/user-copy/entries/detail-reinstall.entries.php +++ b/web/resources/user-copy/entries/detail-reinstall.entries.php @@ -581,7 +581,7 @@ foreach ([ 'instance_detail.traffic.pooled_description' => '实例流量计入同线路共享池;余额与到期批次以流量池页面为准。', 'instance_detail.traffic.pool_initializing' => '共享流量池额度正在初始化,实例流量采样不受影响。', 'instance_detail.traffic.instance_sample_total' => '本实例本期采样合计', - 'instance_detail.traffic.pool_total_remaining' => '共享池有效额度 / 可用余额', + 'instance_detail.traffic.pool_total_remaining' => '共享池有效额度 / 已入账可用余额', 'instance_detail.traffic.preparing_pair' => '正在准备 / 正在准备', 'instance_detail.traffic.unlimited_pair' => '不限流量 / 不限流量', 'instance_detail.traffic.shared_pool' => '共享流量池', diff --git a/web/resources/user-copy/manifest.php b/web/resources/user-copy/manifest.php index 7940b3ee..9c261d09 100644 --- a/web/resources/user-copy/manifest.php +++ b/web/resources/user-copy/manifest.php @@ -61,7 +61,7 @@ return [ 'auth.register' => ['label' => '注册页', 'scopes' => ['common', 'auth']], 'cloud.backups' => ['label' => '云备份页', 'scopes' => ['common', 'backups']], 'cloud.deploy' => ['label' => '实例部署页', 'scopes' => ['common', 'deploy']], - 'cloud.detail' => ['label' => '实例详情页', 'scopes' => ['common', 'instance_detail']], + 'cloud.detail' => ['label' => '实例详情页', 'scopes' => ['common', 'instance_detail', 'traffic_accounting']], 'cloud.invoice_detail' => ['label' => '账单详情页', 'scopes' => ['common', 'billing']], 'cloud.invoices' => ['label' => '账单列表页', 'scopes' => ['common', 'billing']], 'cloud.instances' => ['label' => '实例列表页', 'scopes' => ['common', 'instances']], @@ -69,7 +69,7 @@ return [ 'cloud.keys' => ['label' => 'SSH公钥页', 'scopes' => ['common', 'ssh_keys']], 'cloud.reinstall' => ['label' => '重装系统页', 'scopes' => ['common', 'reinstall']], 'cloud.snapshots' => ['label' => '云快照页', 'scopes' => ['common', 'snapshots']], - 'cloud.traffic' => ['label' => '流量池页', 'scopes' => ['common', 'traffic']], + 'cloud.traffic' => ['label' => '流量池页', 'scopes' => ['common', 'traffic', 'traffic_accounting']], 'cloud.vpcs' => ['label' => 'VPC私网页', 'scopes' => ['common', 'vpc']], 'legal.privacy' => ['label' => '隐私政策页', 'scopes' => ['common', 'legal']], 'legal.terms' => ['label' => '服务条款页', 'scopes' => ['common', 'legal']], diff --git a/web/resources/views/venix/admin/cloud/resources.tpl b/web/resources/views/venix/admin/cloud/resources.tpl index 27c109ba..c7b27385 100644 --- a/web/resources/views/venix/admin/cloud/resources.tpl +++ b/web/resources/views/venix/admin/cloud/resources.tpl @@ -168,6 +168,14 @@
{foreach $resource_page.traffic_pools.lines as $line}{if $line.traffic_pool_group_id == $group.id}{$line.region_name|escape} · {$line.name|escape} {$line.code|escape}{/if}{foreachelse}尚无可用线路{/foreach}{if $group.line_count == 0}尚未绑定线路{/if}
+ {assign var=fresh value=$group.accounting_freshness} +

+ 流量结算 + {if $fresh.pool_count == 0 && $fresh.status == 'current'}暂无账本池{elseif $fresh.status == 'current'}已结算{elseif $fresh.status == 'delayed'}结算延迟{else}账务待核对{/if} + · 待结算实例 {$fresh.unsettled_instance_count|escape} 台 · 采样滞后 {$fresh.stale_sample_count|escape} 台 · 到期未封账 {$fresh.overdue_bucket_count|escape} 个 + {if $fresh.last_sample_at} · 最近实例采样 {$fresh.last_sample_at|date_format:'%Y-%m-%d %H:%M %Z'|escape}{/if} +

+ {if $group.readiness.ready}

{if $group.mode == 'shadow'}就绪门禁已通过,可以进入强制执行。{elseif $group.mode == 'enforced'}强制执行中的账本与网络状态已通过校验。{else}当前配置未发现就绪阻断项。{/if}

{else} diff --git a/web/resources/views/venix/cloud/pages/detail.tpl b/web/resources/views/venix/cloud/pages/detail.tpl index 651496b2..15309d01 100644 --- a/web/resources/views/venix/cloud/pages/detail.tpl +++ b/web/resources/views/venix/cloud/pages/detail.tpl @@ -266,6 +266,11 @@
{if $cloud_vm_view.traffic_used_label_copy_key|default:'' != ''}{user_copy key=$cloud_vm_view.traffic_used_label_copy_key}{else}{user_copy key='instance_detail.traffic.used'}{/if}
{if $cloud_vm_view.traffic_used_display|default:'' != ''}{$cloud_vm_view.traffic_used_display|escape:"html"}{else}{user_copy key='instance_detail.value.unavailable'}{/if}
{if $cloud_vm_view.traffic_total_label_copy_key|default:'' != ''}{user_copy key=$cloud_vm_view.traffic_total_label_copy_key}{else}{user_copy key='instance_detail.traffic.total_remaining'}{/if}
{if $cloud_vm_view.traffic_total_remaining_copy_key|default:'' != ''}{user_copy key=$cloud_vm_view.traffic_total_remaining_copy_key}{elseif $cloud_vm_view.traffic_total_remaining_display|default:'' != ''}{$cloud_vm_view.traffic_total_remaining_display|escape:"html"}{else}{user_copy key='instance_detail.value.unavailable'}{/if}
+
+ {if !empty($cloud_vm_view.traffic_accounting) && $cloud_vm_view.traffic_accounting_mode|default:'legacy' == 'pooled'} + {include file='cloud/partials/traffic-accounting.tpl' evidence=$cloud_vm_view.traffic_accounting} + {/if} +
diff --git a/web/resources/views/venix/cloud/pages/traffic.tpl b/web/resources/views/venix/cloud/pages/traffic.tpl index 10aa46b3..b6ed707f 100644 --- a/web/resources/views/venix/cloud/pages/traffic.tpl +++ b/web/resources/views/venix/cloud/pages/traffic.tpl @@ -27,7 +27,7 @@
{user_copy key='traffic.intro'}

{$pool.state_label|escape:'html'}{$pool.network_label|escape:'html'}
-
{if $pool.accounting_status == 'current'}{user_copy key='traffic.freshness.current'}{elseif $pool.accounting_status == 'delayed'}{user_copy key='traffic.freshness.delayed'}{else}{user_copy key='traffic.freshness.attention'}{/if}{if $pool.accounting_status == 'current'}{if $pool.accounting_has_confirmation}{user_copy key='traffic.freshness.current_at' date=$pool.accounting_confirmed_display}{else}{user_copy key='traffic.freshness.current_without_time'}{/if}{elseif $pool.accounting_status == 'delayed'}{if $pool.accounting_has_confirmation}{user_copy key='traffic.freshness.delayed_at' date=$pool.accounting_confirmed_display}{else}{user_copy key='traffic.freshness.delayed_without_time'}{/if}{else}{if $pool.accounting_has_confirmation}{user_copy key='traffic.freshness.attention_at' date=$pool.accounting_confirmed_display}{else}{user_copy key='traffic.freshness.attention_without_time'}{/if}{/if}
+ {include file='cloud/partials/traffic-accounting.tpl' evidence=$pool.accounting}
{user_copy key='traffic.fact.entitlement'}
{$pool.entitlement_display|escape:'html'}
{user_copy key='traffic.fact.consumed'}
{$pool.consumed_display|escape:'html'}
{user_copy key='traffic.fact.available'}
{$pool.available_display|escape:'html'}
{user_copy key='traffic.fact.overage'}
{$pool.overage_display|escape:'html'}
{user_copy key='traffic.fact.next_expiry'}
{$pool.next_expiry_display|escape:'html'}{$pool.next_expiry_note|escape:'html'}
{user_copy key='traffic.fact.last_observed'}
{$pool.last_observed_display|escape:'html'}
{user_copy key='traffic.instances.title'}{user_copy key='traffic.instances.count' count=$pool.instances|@count}
diff --git a/web/resources/views/venix/cloud/partials/traffic-accounting.tpl b/web/resources/views/venix/cloud/partials/traffic-accounting.tpl new file mode 100644 index 00000000..7fc34f8d --- /dev/null +++ b/web/resources/views/venix/cloud/partials/traffic-accounting.tpl @@ -0,0 +1,7 @@ +
+ + + {user_copy key=$evidence.label_key} + {if $evidence.sample_display != ''}{user_copy key=$evidence.message_key sample_time=$evidence.sample_display}{else}{user_copy key=$evidence.message_key}{/if} + +
diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 23a75aef..94125a87 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026111701' scope='global'} +{assign var=venix_asset_version value='2026111801' scope='global'} diff --git a/web/tests/CloudAdminTrafficPoolServiceTest.php b/web/tests/CloudAdminTrafficPoolServiceTest.php index 34a6baf7..0d718e5d 100644 --- a/web/tests/CloudAdminTrafficPoolServiceTest.php +++ b/web/tests/CloudAdminTrafficPoolServiceTest.php @@ -482,7 +482,7 @@ Capsule::table('cloud_traffic_ledger_events')->insert([ ]); $ready = CloudAdminTrafficPoolService::readiness($groupId, $now); -$assert($ready['ready'] === true && $ready['blockers'] === [], +$assert($ready['ready'] === true && $ready['blockers'] === [] && $ready['active_instance_count'] === 0, 'A complete shadow projection did not pass readiness.'); Capsule::table('cloud_traffic_entitlements')->where('id', 25)->update([ 'state' => 'active', @@ -599,7 +599,7 @@ Capsule::table('cloud_traffic_instance_cursors')->where( 'accounted_upload_bytes' => 20, ]); $ready = CloudAdminTrafficPoolService::readiness($groupId, $now); -$assert($ready['ready'] === true && $ready['blockers'] === [], +$assert($ready['ready'] === true && $ready['blockers'] === [] && $ready['active_instance_count'] === 1, 'A fully settled active projection did not pass readiness.'); $quietCursor = Capsule::table('cloud_traffic_instance_cursors')->where('instance_id', 100); $quietVm = Capsule::table('cloud_instances')->where('id', 100); @@ -607,8 +607,9 @@ $quietCursor->update(['last_observed_at' => $now - 9000]); $assert(CloudAdminTrafficPoolService::readiness($groupId, $now)['ready'], 'A quiet instance incorrectly blocks enforcement.'); $quietVm->update(['status' => 'deleted', 'traffic_synced_at' => $now - 8000]); -$assert(CloudAdminTrafficPoolService::readiness($groupId, $now)['ready'], - 'A deleted instance with a valid paid period incorrectly blocks enforcement.'); +$retired = CloudAdminTrafficPoolService::readiness($groupId, $now); +$assert($retired['ready'] && $retired['active_instance_count'] === 0, + 'A deleted instance with a valid paid period blocked enforcement or counted as active.'); $quietVm->update(['lifetime_upload_bytes' => 320]); $assert(in_array('usage_unsettled', array_column(CloudAdminTrafficPoolService::readiness($groupId, $now)['blockers'], 'code'), true), 'Deleted tail usage bypassed enforcement readiness.'); diff --git a/web/tests/CloudAdminTrafficPoolUiContractTest.php b/web/tests/CloudAdminTrafficPoolUiContractTest.php index 6cae5c8e..a9477ebc 100644 --- a/web/tests/CloudAdminTrafficPoolUiContractTest.php +++ b/web/tests/CloudAdminTrafficPoolUiContractTest.php @@ -110,4 +110,7 @@ $assert(str_contains($styles, && str_contains($styles, '@media (max-width: 767.98px)'), 'Traffic-pool administration must remain responsive.'); +$assert(str_contains($template, 'value=$group.accounting_freshness') && str_contains($template, '$fresh.last_sample_at') + && str_contains($template, '$fresh.unsettled_instance_count') && str_contains($template, '$group.readiness.ready'), + 'The separate line accounting and enforcement readiness projections must both be visible.'); echo "Administrator shared traffic-pool UI contracts passed.\n"; diff --git a/web/tests/CloudInstancePageServiceTest.php b/web/tests/CloudInstancePageServiceTest.php index 915e252f..3fde31b3 100644 --- a/web/tests/CloudInstancePageServiceTest.php +++ b/web/tests/CloudInstancePageServiceTest.php @@ -71,6 +71,9 @@ namespace { $table->integer('traffic_quota_bytes')->default(0); $table->integer('traffic_download_bytes')->default(0); $table->integer('traffic_upload_bytes')->default(0); + $table->integer('lifetime_download_bytes')->default(0); + $table->integer('lifetime_upload_bytes')->default(0); + $table->integer('traffic_synced_at')->default(0); $table->text('spec_json'); $table->text('sealed_credential')->nullable(); $table->integer('created_at'); @@ -141,6 +144,17 @@ namespace { $table->integer('version')->default(1); $table->integer('updated_at'); }); + $schema->create('cloud_traffic_scan_failures', static function (Blueprint $table): void { + $table->increments('id'); + $table->string('scan_kind'); + $table->integer('subject_id'); + }); + $schema->create('cloud_traffic_usage_settlement_buckets', static function (Blueprint $table): void { + $table->increments('id'); + $table->integer('pool_id'); + $table->string('state'); + $table->integer('seal_at'); + }); $schema->create('cloud_instance_network_restrictions', static function (Blueprint $table): void { $table->increments('id'); $table->integer('instance_id'); diff --git a/web/tests/CloudTrafficPoolFreshnessTest.php b/web/tests/CloudTrafficPoolFreshnessTest.php index 222a69b9..2a481b50 100644 --- a/web/tests/CloudTrafficPoolFreshnessTest.php +++ b/web/tests/CloudTrafficPoolFreshnessTest.php @@ -117,7 +117,7 @@ Capsule::table('cloud_traffic_instance_cursors')->insert([ $current = CloudTrafficPoolFreshness::snapshot(7, 3, $now); $assert($current['status'] === 'current' && $current['safe_code'] === 'current' - && $current['last_confirmed_at'] === $now - 60 + && $current['last_sample_at'] === $now - 60 && $current['unsettled_instance_count'] === 0, 'Fully accounted counters were not projected as current.'); @@ -129,8 +129,8 @@ $delayed = CloudTrafficPoolFreshness::snapshot(7, 3, $now); $assert($delayed['status'] === 'delayed' && $delayed['safe_code'] === 'settlement_delayed' && $delayed['unsettled_instance_count'] === 1 - && $delayed['last_confirmed_at'] === $now - 60, - 'Persisted but unsettled counters did not retain the last confirmation.'); + && $delayed['last_sample_at'] === $now - 10, + 'Persisted but unsettled counters did not expose the newest sample independently of booked balance.'); Capsule::table('cloud_traffic_instance_cursors')->where('instance_id', 20) ->update(['state' => 'attention']); @@ -156,11 +156,11 @@ $assert($stale['safe_code'] === 'sample_stale' && !$stale['unsettled_instance_co 'An old live sample was counted as pending traffic.'); $vm->update(['status' => 'deleted']); $retired = CloudTrafficPoolFreshness::snapshot(7, 3, $now); -$assert($retired['status'] === 'current' && !$retired['stale_cursor_count'] - && $retired['last_confirmed_at'] === null, 'A retired VM pinned pool freshness.'); +$assert($retired['status'] === 'current' && !$retired['stale_sample_count'] + && $retired['last_sample_at'] === null, 'A retired VM pinned pool freshness.'); $vm->update(['lifetime_download_bytes' => 400]); $tail = CloudTrafficPoolFreshness::snapshot(7, 3, $now); -$assert($tail['unsettled_instance_count'] === 1 && !$tail['stale_cursor_count'], +$assert($tail['unsettled_instance_count'] === 1 && !$tail['stale_sample_count'], 'A deleted VM lost its final unaccounted 300 bytes.'); $vm->update(['lifetime_download_bytes' => 99, 'lifetime_upload_bytes' => 21]); $assert(CloudTrafficPoolFreshness::snapshot(7, 3, $now)['status'] === 'attention', @@ -184,7 +184,7 @@ $assert($overdueAttention['status'] === 'attention' $pending = CloudTrafficPoolFreshness::snapshot(9, 3, $now); $assert($pending['status'] === 'delayed' && $pending['safe_code'] === 'projection_pending' - && $pending['last_confirmed_at'] === null, + && $pending['last_sample_at'] === null, 'Missing projection fabricated current accounting.'); $group = CloudTrafficPoolFreshness::forGroup(3, $now); $assert($group['status'] === 'attention' diff --git a/web/tests/CloudTrafficPoolLineBehaviorTest.mjs b/web/tests/CloudTrafficPoolLineBehaviorTest.mjs index b02ebda6..934fe692 100644 --- a/web/tests/CloudTrafficPoolLineBehaviorTest.mjs +++ b/web/tests/CloudTrafficPoolLineBehaviorTest.mjs @@ -1,6 +1,7 @@ import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import vm from 'node:vm'; +import { renderAccountingFreshness } from '../public/cloud/traffic-accounting.js'; const moduleSource = await readFile( new URL('../public/cloud/traffic.js', import.meta.url), @@ -62,7 +63,7 @@ const translate = (key, parameters = {}) => { if (key === 'traffic.coverage.regions') return `${parameters.count} 个地区`; if (key === 'traffic.coverage.instances') return `${parameters.count} 台实例`; if (key === 'traffic.instances.count') return `${parameters.count} 台`; - if (key.endsWith('_at')) return `confirmed ${parameters.date}`; + if (key.endsWith('_at')) return `sample ${parameters.sample_time}`; return key; }; const i18n = { @@ -82,6 +83,7 @@ const context = vm.createContext({ readBootstrap: () => ({}), showError() {}, i18n, + renderAccountingFreshness: pool => renderAccountingFreshness(pool, document, i18n), t: translate, }); vm.runInContext(`${source}\nglobalThis.traffic = { applyPayload };`, context, { @@ -101,7 +103,7 @@ const pool = (id, name = `线路 ${id}`) => ({ next_expiry_at: null, next_expiry_bytes: 0, last_observed_at: null, - accounting_freshness: { status: 'current', last_confirmed_at: 100 }, + accounting_freshness: { status: 'current', last_sample_at: 100 }, instances: [], key: `line-group:${id}`, coverage_regions: [{ code: 'hkg', name: '香港' }], @@ -173,7 +175,7 @@ assert.deepEqual(details().map(item => item.open), [false, true, true], context.traffic.applyPayload(payload([ linePool(4, { - accounting_freshness: { status: 'delayed', last_confirmed_at: 80 }, + accounting_freshness: { status: 'delayed', last_sample_at: 80 }, summary_state: 'delayed', requires_attention: true, default_open: true, instance_count: 1, instances: [{ @@ -187,7 +189,7 @@ context.traffic.applyPayload(payload([ const delayedContent = details()[0].textContent; assert.match(delayedContent, /traffic\.freshness\.delayed/, 'A delayed accounting projection was not made visible.'); -assert.match(delayedContent, /confirmed date-80/, +assert.match(delayedContent, /sample date-80/, 'The delayed projection hid its last confirmed timestamp.'); assert.match(delayedContent, /traffic\.instance\.period_quota/, 'Freshness messaging replaced the per-instance raw sample list.'); diff --git a/web/tests/CloudTrafficPoolUserReadModelTest.php b/web/tests/CloudTrafficPoolUserReadModelTest.php index 6e33826b..979c4d82 100644 --- a/web/tests/CloudTrafficPoolUserReadModelTest.php +++ b/web/tests/CloudTrafficPoolUserReadModelTest.php @@ -450,7 +450,6 @@ $assert($lineA['active_entitlement_bytes'] === 1500 $assert($lineA['accounting_freshness'] === [ 'status' => 'delayed', 'last_sample_at' => null, - 'last_confirmed_at' => $now - 5, ], 'User projection did not expose the bounded actor-safe freshness state.'); $assert(count($lineA['instances']) === 1 diff --git a/web/tests/CloudTrafficPoolUserUiContractTest.php b/web/tests/CloudTrafficPoolUserUiContractTest.php index e72acd3d..351a8146 100644 --- a/web/tests/CloudTrafficPoolUserUiContractTest.php +++ b/web/tests/CloudTrafficPoolUserUiContractTest.php @@ -38,7 +38,7 @@ $assert(str_contains($readModel, && str_contains($readModel, 'CloudTrafficPoolAccounting::snapshots(') && str_contains($readModel, 'CloudTrafficPoolFreshness::snapshots(') && str_contains($readModel, "'accounting_freshness' => [") - && str_contains($readModel, "'last_confirmed_at' =>") + && str_contains($readModel, "'last_sample_at' =>") && str_contains($freshness, 'public const DELAY_SECONDS = 300;') && str_contains($freshness, 'public const ATTENTION_SECONDS = 3600;') && str_contains($readModel, @@ -118,11 +118,8 @@ $assert(str_contains($sidebar, 'href="/user/cloud/traffic"') && str_contains($template, "{user_copy key='traffic.instance.expiry' region=\$instance.region_label date=\$instance.expires_display}") && str_contains($template, "{user_copy key='traffic.intro'}") - && str_contains($template, 'cloud-traffic-accounting-') - && str_contains($template, - "{user_copy key='traffic.freshness.delayed_at'") - && str_contains($template, - "{user_copy key='traffic.freshness.attention_without_time'}") + && str_contains($template, "cloud/partials/traffic-accounting.tpl") + && str_contains($read('resources/views/venix/cloud/partials/traffic-accounting.tpl'), 'user_copy key=$evidence.message_key') && !str_contains($template, 'cloud-traffic-region'), 'The user traffic-pool page lacks SSR first paint, navigation or clear shared-vs-instance copy.'); @@ -149,8 +146,9 @@ $assert(str_contains($script, && str_contains($script, 'pool.active_consumed_bytes') && str_contains($script, 'pool.available_bytes') && str_contains($script, 'pool.projection_ready === true') - && str_contains($script, 'function accountingFreshness(pool)') - && str_contains($script, 'function renderAccountingFreshness(pool)') + && str_contains($read('public/cloud/traffic-accounting.js'), 'function accountingFreshness(') + && str_contains($read('public/cloud/traffic-accounting.js'), 'export function renderAccountingFreshness(') + && str_contains($runtime, 'accounting.replaceChildren(renderAccountingFreshness(data.pool))') && str_contains($script, 'renderAccountingFreshness(pool), facts, instances') && str_contains($script, diff --git a/web/tests/CloudUserFirstPaintViewTest.php b/web/tests/CloudUserFirstPaintViewTest.php index 5f09f37d..18a63af8 100644 --- a/web/tests/CloudUserFirstPaintViewTest.php +++ b/web/tests/CloudUserFirstPaintViewTest.php @@ -96,7 +96,7 @@ $traffic = ['line_pools' => [[ 'next_expiry_at' => null, 'next_expiry_bytes' => 0, 'last_observed_at' => 1793404900, 'accounting_freshness' => [ - 'status' => 'delayed', 'last_confirmed_at' => 1793404800, + 'status' => 'delayed', 'last_sample_at' => 1793404800, ], 'coverage_regions' => [['code' => 'hkg', 'name' => '香港']], 'coverage_region_count' => 1, 'instance_count' => 1, @@ -114,13 +114,24 @@ $xpath = $render('traffic', [ ]); $trafficText = $one($xpath, 'cloud-traffic-list')->textContent; $assert($xpath->query('//*[contains(concat(" ", normalize-space(@class), " "), " cloud-traffic-accounting-delayed ")]')->length === 1 - && str_contains($trafficText, '账务结算延迟') - && str_contains($trafficText, '最后确认可用余额') - && str_contains($trafficText, '以下共享额度为') + && str_contains($trafficText, '结算延迟') + && str_contains($trafficText, '已入账可用余额') + && str_contains($trafficText, '新的流量可能尚未计入') && str_contains($trafficText, 'vm-traffic') && str_contains($trafficText, '512 B'), 'Traffic-pool first paint hid delayed accounting, confirmed balances or raw instance samples.'); +foreach (['current', 'delayed', 'attention'] as $status) { + foreach ([null, 1793404800] as $sample) { + $evidence = CloudUserPageView::trafficAccounting(['accounting_freshness' => ['status' => $status, 'last_sample_at' => $sample]]); + $xpath = $render('detail', ['cloud_vm_view' => ['traffic_accounting_mode' => 'pooled', 'traffic_accounting' => $evidence]]); + $card = $one($xpath, 'vm-detail-traffic-accounting'); + $assert(!$card->hasAttribute('hidden') && str_contains($card->textContent, '已入账余额') + && str_contains($card->textContent, ' UTC') === ($sample !== null), 'Instance SSR lost the booked balance or sample time.'); + } +} +$xpath = $render('detail', ['cloud_vm_view' => ['traffic_accounting_mode' => 'unlimited']]); +$assert($one($xpath, 'vm-detail-traffic-accounting')->hasAttribute('hidden'), 'Non-pooled VM displayed pool accounting.'); $vpc = ['vpc_key' => $key, 'name' => 'vpc-before-js', 'region_id' => 1, 'region_name' => '香港', 'cidr' => '10.0.1.0/24', 'gateway' => '10.0.1.1', 'state' => 'active', 'port_count' => 1]; $member = ['id' => '7', 'name' => 'vm-member', 'region_id' => 1, 'public_ipv4' => '192.0.2.7', diff --git a/web/tests/UserCopyCompleteCoverageTest.php b/web/tests/UserCopyCompleteCoverageTest.php index fd386a8c..00127541 100644 --- a/web/tests/UserCopyCompleteCoverageTest.php +++ b/web/tests/UserCopyCompleteCoverageTest.php @@ -40,6 +40,7 @@ $templatePaths = [ 'web/resources/views/venix/cloud/pages/keys.tpl', 'web/resources/views/venix/cloud/pages/reinstall.tpl', 'web/resources/views/venix/cloud/pages/traffic.tpl', + 'web/resources/views/venix/cloud/partials/traffic-accounting.tpl', 'web/resources/views/venix/cloud/pages/vpcs.tpl', 'web/resources/views/venix/components/site_brand_mark.tpl', 'web/resources/views/venix/home/language_switch.tpl', @@ -102,6 +103,7 @@ $browserPaths = [ 'web/public/cloud/ticket-upload.js', 'web/public/cloud/toast.js', 'web/public/cloud/traffic.js', + 'web/public/cloud/traffic-accounting.js', 'web/public/cloud/user-copy-runtime.js', 'web/public/cloud/user-dialog.js', 'web/public/cloud/vpcs.js', diff --git a/web/tests/UserCopyManifestContractTest.php b/web/tests/UserCopyManifestContractTest.php index 55fabe40..58c7c9a0 100644 --- a/web/tests/UserCopyManifestContractTest.php +++ b/web/tests/UserCopyManifestContractTest.php @@ -46,12 +46,25 @@ $assert($surfaceCounts === [ 'accessibility' => 102, 'admin' => 110, 'dialog' => 56, - 'feedback' => 618, - 'page' => 1477, + 'feedback' => 624, + 'page' => 1471, 'shared' => 38, 'task' => 53, ], 'User-copy authoring surface census drifted from the reviewed taxonomy.'); +foreach (['cloud.traffic', 'cloud.detail'] as $page) { + $assert(in_array('traffic_accounting', $manifest['pages'][$page]['scopes'], true), + 'The shared accounting status catalog is unavailable in ' . $page); +} +foreach (['current', 'delayed', 'attention'] as $status) { + foreach (['', '_at', '_without_time'] as $suffix) { + $key = 'traffic.freshness.' . $status . $suffix; + $entry = $loadedEntries[$key]; + $assert($entry['scope'] === 'traffic_accounting' && $entry['editor_surface'] === 'feedback' + && $entry['parameters'] === ($suffix === '_at' ? ['sample_time' => 'string'] : []), + 'The shared editable traffic message or its sampling-time placeholder drifted: ' . $key); + } +} foreach ($loadedEntries as $copyKey => $entry) { $assert(is_string($entry['editor_surface'] ?? null) && is_string($entry['editor_group'] ?? null),