From 5b11c1006bb0789ec8e6dd5ce25633778cea9067 Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 14:55:43 +0000 Subject: [PATCH 1/6] Show when TrueNAS protection readings are stale Pass the already-hydrated TrueNAS system resources from TrueNASPageSurface into TrueNASProtectionTable so /truenas/protection surfaces backend-owned TrueNAS collection errors, telemetry_stale health, and offline systems truthfully instead of leaving cached ZFS snapshots and replication tasks green Healthy or pulsing Running. - Match each TrueNAS recovery point to its owning TrueNAS system by connectionId/providerScope first (preserving DR-clone isolation across shared hostnames), then unambiguous hostname, then all-stale fallback when host metadata is absent. - Exclude stale healthy and running points from Healthy and Running filter counts, surface a dynamic amber Stale filter chip alongside Attention, rank stale events above fresh ones, and index stale details in search. - Render amber Stale data badges for stale healthy points (Stale on phone), preserve red Failed / Warning / non-pulsing muted Running / Unknown badges with an amber Stale data cue beneath the dataset name, and show an amber InlineNotice plus Status and Last reported rows inside the expanded detail drawer that clear reactively on live WebSocket recovery. Contract-Neutral: UI freshness presentation using existing TrueNAS system resources and /api/recovery/points fields without changing API payloads, polling, alerts, telemetry, or routes. Change-source: pulse-maintainer --- .../features/truenas/TrueNASPageSurface.tsx | 12 +- .../truenas/TrueNASProtectionTable.tsx | 169 +++++-- .../features/truenas/TrueNASTableFrame.tsx | 3 +- .../TrueNASPageSurface.contract.test.tsx | 9 +- .../TrueNASProtectionTable.freshness.test.tsx | 444 ++++++++++++++++++ .../src/features/truenas/truenasPageModel.ts | 250 +++++++++- 6 files changed, 841 insertions(+), 46 deletions(-) create mode 100644 frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx diff --git a/frontend-modern/src/features/truenas/TrueNASPageSurface.tsx b/frontend-modern/src/features/truenas/TrueNASPageSurface.tsx index 30990e3f78..251d210a89 100644 --- a/frontend-modern/src/features/truenas/TrueNASPageSurface.tsx +++ b/frontend-modern/src/features/truenas/TrueNASPageSurface.tsx @@ -252,7 +252,11 @@ export function TrueNASPageSurface() { /> - + @@ -289,13 +293,17 @@ function TrueNASStorage(props: TrueNASStorageProps) { } function TrueNASProtection( - props: { recoveryPoints: ReturnType } & TrueNASTableSearchProps, + props: { + recoveryPoints: ReturnType; + systems: Resource[]; + } & TrueNASTableSearchProps, ) { return ( void props.recoveryPoints.refetch()} diff --git a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx index 5d81c02da7..501a18f2b5 100644 --- a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx +++ b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx @@ -26,16 +26,24 @@ import { type PlatformTableFilterOption, type PlatformTableSortValue, } from '@/features/platformPage/sharedPlatformPage'; -import { TrueNASRowLead, TrueNASTableFrame, createTrueNASDetailState } from './TrueNASTableFrame'; +import { + TrueNASRowLead, + TrueNASStaleBadge, + TrueNASTableFrame, + createTrueNASDetailState, +} from './TrueNASTableFrame'; import { getPlatformResourceDetailRowClass } from '@/features/platformPage/PlatformResourceDetailTableRow'; import type { RecoveryPoint } from '@/types/recovery'; +import type { Resource } from '@/types/resource'; import { - filterTrueNASProtectionPoints, buildTrueNASProtectionPosture, + buildTrueNASProtectionStaleNoticeMap, + filterTrueNASProtectionPoints, mapTrueNASProtectionKind, mapTrueNASProtectionStatus, sortTrueNASProtectionPoints, type TrueNASProtectionKind, + type TrueNASProtectionStaleNotice, type TrueNASProtectionStatusBucket, type TrueNASProtectionStatusFilter, } from './truenasPageModel'; @@ -49,6 +57,13 @@ import { } from '@/components/shared/DetailSectionTable'; import { RecordOwnerLink } from '@/features/platformPage/RecordOwnerLink'; +const TRUENAS_PROTECTION_STALE_OPTION: PlatformTableFilterOption = { + value: 'stale', + label: 'Stale', + compactLabel: 'Stale', + tone: 'warning', +}; + const TRUENAS_PROTECTION_STATUS_OPTIONS: PlatformTableFilterOption[] = [ { value: 'all', label: 'All' }, @@ -191,6 +206,7 @@ type TrueNASProtectionSortKey = (typeof TRUENAS_PROTECTION_SORT_KEYS)[number]; const getTrueNASProtectionSortValue = ( point: RecoveryPoint, key: TrueNASProtectionSortKey, + staleNotice?: TrueNASProtectionStaleNotice, ): PlatformTableSortValue => { switch (key) { case 'dataset': @@ -207,8 +223,12 @@ const getTrueNASProtectionSortValue = ( return typeof point.sizeBytes === 'number' && Number.isFinite(point.sizeBytes) ? point.sizeBytes : null; - case 'outcome': - return getRecoveryOutcomeLabel(normalizeRecoveryOutcome(point.outcome)); + case 'outcome': { + const outcome = normalizeRecoveryOutcome(point.outcome); + return staleNotice && outcome === 'success' + ? staleNotice.badge + : getRecoveryOutcomeLabel(outcome); + } default: key satisfies never; return null; @@ -255,15 +275,23 @@ const sourceDatasetsLabel = (point: RecoveryPoint): string | null => { return datasets.length > 0 ? datasets.join(', ') : null; }; -const buildProtectionDetailSections = (point: RecoveryPoint): ProtectionDetailSection[] => { +const buildProtectionDetailSections = ( + point: RecoveryPoint, + staleNotice?: TrueNASProtectionStaleNotice | null, +): ProtectionDetailSection[] => { const kind = mapTrueNASProtectionKind(point); + const outcome = normalizeRecoveryOutcome(point.outcome); + const outcomeLabel = getRecoveryOutcomeLabel(outcome); const target = targetLabel(point); const targetSecondary = targetSecondaryLabel(point); const summaryRows = compactDetailRows([ detailRow('Kind', kindLabel(kind)), - detailRow('Outcome', getRecoveryOutcomeLabel(normalizeRecoveryOutcome(point.outcome)), { - tone: outcomeTone(point), - }), + ...(staleNotice + ? [ + detailRow('Status', staleNotice.badge, { tone: 'warning' }), + detailRow('Last reported', outcomeLabel, { tone: outcomeTone(point) }), + ] + : [detailRow('Outcome', outcomeLabel, { tone: outcomeTone(point) })]), detailRow('Dataset', datasetLabel(point)), detailRow('Host', hostLabel(point)), detailRow('Started', detailDateTime(point.startedAt)), @@ -305,6 +333,7 @@ const buildProtectionDetailSections = (point: RecoveryPoint): ProtectionDetailSe export const TrueNASProtectionTable: Component<{ points: RecoveryPoint[]; + systems?: Resource[]; loading?: boolean; error?: unknown; onRefresh?: () => void; @@ -316,29 +345,47 @@ export const TrueNASProtectionTable: Component<{ search?: () => string; onSearchChange?: (value: string) => void; }> = (props) => { - const rows = createMemo(() => sortTrueNASProtectionPoints(props.points)); - const posture = createMemo(() => buildTrueNASProtectionPosture(rows())); + const staleNoticeByPointId = createMemo(() => + buildTrueNASProtectionStaleNoticeMap(props.points, props.systems ?? []), + ); + const rows = createMemo(() => + sortTrueNASProtectionPoints(props.points, staleNoticeByPointId()), + ); + const posture = createMemo(() => + buildTrueNASProtectionPosture(rows(), staleNoticeByPointId()), + ); const detail = createTrueNASDetailState('truenas-protection-detail'); const tableState = createPlatformTableFilterState({ resources: rows, initialStatus: 'all' as TrueNASProtectionStatusFilter, - filter: filterTrueNASProtectionPoints, + filter: (items, search, status) => + filterTrueNASProtectionPoints(items, search, status, staleNoticeByPointId()), externalSearch: props.search, onExternalSearchChange: props.onSearchChange, }); - const statusOptions = createMemo(() => - withPlatformStatusCounts(TRUENAS_PROTECTION_STATUS_OPTIONS, tableState.countForStatus, { + const statusOptions = createMemo(() => { + const showStaleFilter = posture().stale > 0 || tableState.status() === 'stale'; + const baseOptions = showStaleFilter + ? [ + ...TRUENAS_PROTECTION_STATUS_OPTIONS.slice(0, 2), + TRUENAS_PROTECTION_STALE_OPTION, + ...TRUENAS_PROTECTION_STATUS_OPTIONS.slice(2), + ] + : TRUENAS_PROTECTION_STATUS_OPTIONS; + return withPlatformStatusCounts(baseOptions, tableState.countForStatus, { value: 'attention', tone: posture().failed > 0 ? 'danger' : 'warning', - }), - ); + }); + }); const sort = createPlatformTableSortState({ storageKey: 'truenasProtection', sortKeys: TRUENAS_PROTECTION_SORT_KEYS, descendingFirst: ['completed', 'size'], }); const sortedRows = createMemo(() => - sort.sortRows(tableState.filtered(), getTrueNASProtectionSortValue), + sort.sortRows(tableState.filtered(), (point, key) => + getTrueNASProtectionSortValue(point, key, staleNoticeByPointId().get(point.id)), + ), ); return ( @@ -459,6 +506,40 @@ export const TrueNASProtectionTable: Component<{ {(point) => { const outcome = () => normalizeRecoveryOutcome(point.outcome); + const statusBucket = () => mapTrueNASProtectionStatus(point); + const staleNotice = () => staleNoticeByPointId().get(point.id) ?? null; + const isStaleHealthy = () => Boolean(staleNotice()) && outcome() === 'success'; + const rowVariant = (): StatusIndicatorVariant => { + const stale = staleNotice(); + if (!stale) return protectionVariant(statusBucket()); + return outcome() === 'failed' ? 'danger' : 'warning'; + }; + const rowDotTitle = () => { + const stale = staleNotice(); + const outcomeLabel = getRecoveryOutcomeLabel(outcome()); + if (!stale) return outcomeLabel; + return isStaleHealthy() + ? `${stale.badge} · Last reported ${outcomeLabel} · ${stale.detail}` + : `${outcomeLabel} · ${stale.badge} · ${stale.detail}`; + }; + const outcomeBadgeClass = () => { + const stale = staleNotice(); + if (!stale) return getRecoveryOutcomeBadgeClass(outcome()); + if (outcome() === 'success') return getRecoveryOutcomeBadgeClass('warning'); + if (outcome() === 'running') return getRecoveryOutcomeBadgeClass('unknown'); + return getRecoveryOutcomeBadgeClass(outcome()); + }; + const detailStatus = () => { + const stale = staleNotice(); + const outcomeLabel = getRecoveryOutcomeLabel(outcome()); + if (!stale) { + return { variant: protectionVariant(statusBucket()), label: outcomeLabel }; + } + return { + variant: rowVariant(), + label: isStaleHealthy() ? stale.badge : `${outcomeLabel} · ${stale.badge}`, + }; + }; const artifact = () => artifactLabel(point); const artifactSecondary = () => artifactSecondaryLabel(point); const target = () => targetLabel(point); @@ -471,7 +552,8 @@ export const TrueNASProtectionTable: Component<{ class={`${getPlatformResourceDetailRowClass(isExpanded())} text-[11px] sm:text-xs`} data-truenas-protection-row={point.id} data-truenas-protection-kind={mapTrueNASProtectionKind(point)} - data-truenas-protection-outcome={mapTrueNASProtectionStatus(point)} + data-truenas-protection-outcome={statusBucket()} + data-truenas-protection-stale={staleNotice() ? 'true' : undefined} onClick={() => detail.toggle(point)} > @@ -479,9 +561,9 @@ export const TrueNASProtectionTable: Component<{ item={point} drawer={detail} label={datasetLabel(point)} - variant={protectionVariant(mapTrueNASProtectionStatus(point))} - pulse={mapTrueNASProtectionStatus(point) === 'running'} - dotTitle={getRecoveryOutcomeLabel(outcome())} + variant={rowVariant()} + pulse={!staleNotice() && statusBucket() === 'running'} + dotTitle={rowDotTitle()} >
{datasetLabel(point)}
+
@@ -532,8 +618,19 @@ export const TrueNASProtectionTable: Component<{ {sizeLabel(point)} - - {getRecoveryOutcomeLabel(outcome())} + + + + @@ -548,10 +645,7 @@ export const TrueNASProtectionTable: Component<{ testId="truenas-protection-detail" detailFor={point.id} title={datasetLabel(point)} - status={{ - variant: protectionVariant(mapTrueNASProtectionStatus(point)), - label: getRecoveryOutcomeLabel(outcome()), - }} + status={detailStatus()} summary={`${kindLabel(mapTrueNASProtectionKind(point))} on ${hostLabel(point)}`} actions={ } - sections={buildProtectionDetailSections(point)} + sections={buildProtectionDetailSections(point, staleNotice())} detailAttributes={{ 'data-truenas-protection-detail-for': point.id }} onClose={() => detail.close(point)} - /> + > + + {(notice) => ( + +

+ Readings from {notice().systemName} may be out of date. +

+

+ {notice().detail}. Showing the last reported protection event; + newer snapshots, replication runs, or failures may be missing. +

+
+ )} +
+ diff --git a/frontend-modern/src/features/truenas/TrueNASTableFrame.tsx b/frontend-modern/src/features/truenas/TrueNASTableFrame.tsx index a4161a237d..209ffec58a 100644 --- a/frontend-modern/src/features/truenas/TrueNASTableFrame.tsx +++ b/frontend-modern/src/features/truenas/TrueNASTableFrame.tsx @@ -109,7 +109,7 @@ export type TrueNASCommonTableProps = { export function TrueNASStaleBadge(props: { notice: TrueNASStaleNotice | null; - attr: 'system' | 'storage'; + attr: 'system' | 'storage' | 'protection'; }) { return ( @@ -119,6 +119,7 @@ export function TrueNASStaleBadge(props: { title={notice().detail} data-truenas-system-stale={props.attr === 'system' ? 'true' : undefined} data-truenas-storage-stale={props.attr === 'storage' ? 'true' : undefined} + data-truenas-protection-stale-cue={props.attr === 'protection' ? 'true' : undefined} > {notice().badge} diff --git a/frontend-modern/src/features/truenas/__tests__/TrueNASPageSurface.contract.test.tsx b/frontend-modern/src/features/truenas/__tests__/TrueNASPageSurface.contract.test.tsx index b17164c35f..ad838637d3 100644 --- a/frontend-modern/src/features/truenas/__tests__/TrueNASPageSurface.contract.test.tsx +++ b/frontend-modern/src/features/truenas/__tests__/TrueNASPageSurface.contract.test.tsx @@ -90,8 +90,12 @@ vi.mock('../TrueNASNetworkSharesTable', () => ({ })); vi.mock('../TrueNASProtectionTable', () => ({ - TrueNASProtectionTable: (props: { points: unknown[] }) => ( -
+ TrueNASProtectionTable: (props: { points: unknown[]; systems?: Resource[] }) => ( +
), })); @@ -210,6 +214,7 @@ describe('TrueNASPageSurface contract', () => { 'protection', ); expect(screen.getByTestId('protection-table')).toBeInTheDocument(); + expect(screen.getByTestId('protection-table')).toHaveAttribute('data-systems', '1'); }); it('hydrates only the active TrueNAS workflow resource family', () => { diff --git a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx new file mode 100644 index 0000000000..ea7712ae82 --- /dev/null +++ b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx @@ -0,0 +1,444 @@ +import { cleanup, fireEvent, render, screen, within } from '@solidjs/testing-library'; +import { Route, Router } from '@solidjs/router'; +import { createSignal, type JSX } from 'solid-js'; +import { afterEach, describe, expect, it } from 'vitest'; + +import { TrueNASProtectionTable } from '@/features/truenas/TrueNASProtectionTable'; +import { + buildTrueNASProtectionPosture, + buildTrueNASProtectionStaleNoticeMap, + filterTrueNASProtectionPoints, + getTrueNASProtectionStaleNotice, + sortTrueNASProtectionPoints, +} from '@/features/truenas/truenasPageModel'; +import type { RecoveryPoint } from '@/types/recovery'; +import type { Resource } from '@/types/resource'; + +const renderInRouter = (component: () => JSX.Element) => + render(() => ( + + + + )); + +const makeSystem = (overrides: Partial & Pick): Resource => + ({ + type: 'agent', + name: overrides.id, + displayName: overrides.id, + status: 'online', + platformId: 'truenas-primary', + platformType: 'truenas', + platformScopes: ['truenas'], + sourceType: 'agent', + sources: ['agent', 'truenas'], + lastSeen: 1_700_000_000_000, + ...overrides, + }) as Resource; + +const makePoint = ( + point: Partial & Pick, +): RecoveryPoint => ({ + outcome: 'success', + platform: 'truenas', + startedAt: '2026-11-27T12:00:00Z', + completedAt: '2026-11-27T12:05:00Z', + ...point, +}); + +afterEach(() => { + cleanup(); + localStorage.clear(); +}); + +describe('TrueNAS protection freshness model', () => { + it('isolates DR clones sharing a hostname by connectionId so healthy peers never turn stale', () => { + const stalePrimary = makeSystem({ + id: 'truenas:agent:system:conn-primary', + name: 'truenas', + displayName: 'truenas-primary', + platformId: 'conn-primary', + agent: { agentId: 'conn-primary', hostname: 'truenas' }, + truenas: { hostname: 'truenas' }, + sourceStatus: { + truenas: { status: 'error', error: 'websocket read timeout' }, + }, + health: { + verdict: 'stale', + reasons: [{ code: 'telemetry_stale', detail: '18m' }], + }, + }); + const healthyDr = makeSystem({ + id: 'truenas:agent:system:conn-dr', + name: 'truenas', + displayName: 'truenas-dr', + platformId: 'conn-dr', + agent: { agentId: 'conn-dr', hostname: 'truenas' }, + truenas: { hostname: 'truenas' }, + sourceStatus: { + truenas: { status: 'online' }, + }, + }); + + const primarySnap = makePoint({ + id: 'snap-primary', + kind: 'snapshot', + mode: 'snapshot', + details: { connectionId: 'conn-primary', hostname: 'truenas', dataset: 'tank/apps' }, + }); + const drSnap = makePoint({ + id: 'snap-dr', + kind: 'snapshot', + mode: 'snapshot', + details: { connectionId: 'conn-dr', hostname: 'truenas', dataset: 'vault/apps' }, + }); + const unknownConnSnap = makePoint({ + id: 'snap-unknown', + kind: 'snapshot', + mode: 'snapshot', + details: { connectionId: 'conn-other', hostname: 'truenas', dataset: 'other/apps' }, + }); + + const primaryNotice = getTrueNASProtectionStaleNotice(primarySnap, [stalePrimary, healthyDr]); + expect(primaryNotice).toEqual( + expect.objectContaining({ + badge: 'Stale data', + systemName: 'truenas-primary', + age: '18m', + detail: 'TrueNAS collection error: websocket read timeout (last report 18m ago)', + }), + ); + expect(getTrueNASProtectionStaleNotice(drSnap, [stalePrimary, healthyDr])).toBeNull(); + expect(getTrueNASProtectionStaleNotice(unknownConnSnap, [stalePrimary, healthyDr])).toBeNull(); + }); + + it('does not treat a live degraded ZFS pool as stale when TrueNAS polling is healthy', () => { + const degradedLiveSystem = makeSystem({ + id: 'truenas:agent:system:conn-live', + name: 'nas-live', + status: 'degraded', + agent: { agentId: 'conn-live', hostname: 'nas-live' }, + truenas: { hostname: 'nas-live' }, + sourceStatus: { truenas: { status: 'online' } }, + }); + const snap = makePoint({ + id: 'snap-live', + kind: 'snapshot', + mode: 'snapshot', + details: { connectionId: 'conn-live', hostname: 'nas-live', dataset: 'tank/media' }, + }); + + expect(getTrueNASProtectionStaleNotice(snap, [degradedLiveSystem])).toBeNull(); + }); + + it('detects backend telemetry_stale and offline systems even when sourceStatus is absent', () => { + const telemetryStale = makeSystem({ + id: 'agent:nas-telemetry', + name: 'nas-telemetry', + truenas: { hostname: 'nas-telemetry' }, + health: { + verdict: 'stale', + reasons: [{ code: 'telemetry_stale', detail: '24m' }], + }, + }); + const offlineSystem = makeSystem({ + id: 'agent:nas-offline', + name: 'nas-offline', + status: 'offline', + truenas: { hostname: 'nas-offline' }, + }); + + const telemetryPoint = makePoint({ + id: 'pt-telemetry', + kind: 'snapshot', + mode: 'snapshot', + display: { nodeHostLabel: 'nas-telemetry', itemLabel: 'tank/db' }, + }); + const offlinePoint = makePoint({ + id: 'pt-offline', + kind: 'snapshot', + mode: 'snapshot', + details: { hostname: 'nas-offline', dataset: 'tank/backups' }, + }); + + expect(getTrueNASProtectionStaleNotice(telemetryPoint, [telemetryStale, offlineSystem])).toEqual( + expect.objectContaining({ + badge: 'Stale data', + systemName: 'nas-telemetry', + age: '24m', + detail: 'No TrueNAS report from nas-telemetry for 24m', + }), + ); + expect(getTrueNASProtectionStaleNotice(offlinePoint, [telemetryStale, offlineSystem])).toEqual( + expect.objectContaining({ + badge: 'Stale data', + systemName: 'nas-offline', + detail: 'TrueNAS system nas-offline is offline in Pulse', + }), + ); + }); + + it('excludes stale success and running points from Healthy and Running posture, ranks stale above fresh, and searches stale details', () => { + const staleNas = makeSystem({ + id: 'truenas:agent:system:conn-stale', + name: 'nas-east', + agent: { agentId: 'conn-stale', hostname: 'nas-east' }, + truenas: { hostname: 'nas-east' }, + sourceStatus: { truenas: { status: 'error', error: 'dial tcp timeout' } }, + }); + const freshNas = makeSystem({ + id: 'truenas:agent:system:conn-fresh', + name: 'nas-west', + agent: { agentId: 'conn-fresh', hostname: 'nas-west' }, + truenas: { hostname: 'nas-west' }, + sourceStatus: { truenas: { status: 'online' } }, + }); + + const freshOk = makePoint({ + id: 'fresh-ok', + kind: 'snapshot', + mode: 'snapshot', + completedAt: '2026-11-27T13:00:00Z', + details: { connectionId: 'conn-fresh', hostname: 'nas-west', dataset: 'west/ok' }, + }); + const staleOk = makePoint({ + id: 'stale-ok', + kind: 'snapshot', + mode: 'snapshot', + completedAt: '2026-11-27T11:00:00Z', + details: { connectionId: 'conn-stale', hostname: 'nas-east', dataset: 'east/ok' }, + }); + const staleRunning = makePoint({ + id: 'stale-running', + kind: 'backup', + mode: 'remote', + outcome: 'running', + completedAt: undefined, + details: { connectionId: 'conn-stale', hostname: 'nas-east', taskName: 'rep-east' }, + }); + const staleFailed = makePoint({ + id: 'stale-failed', + kind: 'backup', + mode: 'remote', + outcome: 'failed', + completedAt: '2026-11-27T10:00:00Z', + details: { connectionId: 'conn-stale', hostname: 'nas-east', taskName: 'rep-fail' }, + }); + + const points = [freshOk, staleOk, staleRunning, staleFailed]; + const staleMap = buildTrueNASProtectionStaleNoticeMap(points, [staleNas, freshNas]); + const posture = buildTrueNASProtectionPosture(points, staleMap); + + expect(posture).toEqual({ + healthy: 1, + stale: 3, + warning: 0, + failed: 1, + running: 0, + unknown: 0, + attention: 3, + }); + + const sorted = sortTrueNASProtectionPoints(points, staleMap); + expect(sorted.map((p) => p.id)).toEqual([ + 'stale-failed', + 'stale-ok', + 'stale-running', + 'fresh-ok', + ]); + + expect(filterTrueNASProtectionPoints(points, '', 'success', staleMap).map((p) => p.id)).toEqual([ + 'fresh-ok', + ]); + expect(filterTrueNASProtectionPoints(points, '', 'running', staleMap)).toEqual([]); + expect(filterTrueNASProtectionPoints(points, '', 'stale', staleMap).map((p) => p.id)).toEqual([ + 'stale-ok', + 'stale-running', + 'stale-failed', + ]); + expect( + filterTrueNASProtectionPoints(points, '', 'attention', staleMap).map((p) => p.id), + ).toEqual(['stale-ok', 'stale-running', 'stale-failed']); + expect(filterTrueNASProtectionPoints(points, '', 'failed', staleMap).map((p) => p.id)).toEqual([ + 'stale-failed', + ]); + expect( + filterTrueNASProtectionPoints(points, 'dial tcp timeout', 'all', staleMap).map((p) => p.id), + ).toEqual(['stale-ok', 'stale-running', 'stale-failed']); + }); +}); + +describe('TrueNASProtectionTable stale-reading UI', () => { + it('surfaces stale healthy, running, and failed events truthfully and clears them reactively on live recovery', async () => { + const staleNas = makeSystem({ + id: 'truenas:agent:system:conn-east', + name: 'nas-east', + displayName: 'nas-east', + agent: { agentId: 'conn-east', hostname: 'nas-east' }, + truenas: { hostname: 'nas-east' }, + sourceStatus: { truenas: { status: 'error', error: 'API connection refused' } }, + health: { + verdict: 'stale', + reasons: [{ code: 'telemetry_stale', detail: '14m' }], + }, + }); + const freshNas = makeSystem({ + id: 'truenas:agent:system:conn-west', + name: 'nas-west', + displayName: 'nas-west', + agent: { agentId: 'conn-west', hostname: 'nas-west' }, + truenas: { hostname: 'nas-west' }, + sourceStatus: { truenas: { status: 'online' } }, + }); + + const points: RecoveryPoint[] = [ + makePoint({ + id: 'snap-east-ok', + kind: 'snapshot', + mode: 'snapshot', + outcome: 'success', + display: { itemLabel: 'tank/billing', nodeHostLabel: 'nas-east' }, + details: { + connectionId: 'conn-east', + hostname: 'nas-east', + dataset: 'tank/billing', + snapshot: 'auto-20261127-1200', + }, + }), + makePoint({ + id: 'rep-east-running', + kind: 'backup', + mode: 'remote', + outcome: 'running', + completedAt: undefined, + display: { itemLabel: 'tank/media', nodeHostLabel: 'nas-east' }, + details: { + connectionId: 'conn-east', + hostname: 'nas-east', + taskName: 'replicate-media', + lastState: 'RUNNING', + }, + }), + makePoint({ + id: 'rep-east-failed', + kind: 'backup', + mode: 'remote', + outcome: 'failed', + display: { itemLabel: 'tank/archive', nodeHostLabel: 'nas-east' }, + details: { + connectionId: 'conn-east', + hostname: 'nas-east', + taskName: 'replicate-archive', + lastState: 'FAILED', + }, + }), + makePoint({ + id: 'snap-west-ok', + kind: 'snapshot', + mode: 'snapshot', + outcome: 'success', + display: { itemLabel: 'vault/docs', nodeHostLabel: 'nas-west' }, + details: { + connectionId: 'conn-west', + hostname: 'nas-west', + dataset: 'vault/docs', + snapshot: 'auto-20261127-1205', + }, + }), + ]; + + const [systems, setSystems] = createSignal([staleNas, freshNas]); + + renderInRouter(() => ( + } + emptyTitle="No protection" + emptyDescription="No protection" + /> + )); + + // Filter chips: 1 fresh Healthy, 3 Stale, 3 Attention, 1 Failed, 0 Running + expect(screen.getByRole('button', { name: 'All, 4' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Attention, 3' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Stale, 3' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Healthy, 1' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Failed, 1' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Running, 0' })).toBeInTheDocument(); + + // Stale healthy row shows amber Stale data badge in Outcome and no redundant cue under Dataset + const staleOkRow = document.querySelector('[data-truenas-protection-row="snap-east-ok"]')!; + expect(staleOkRow).toHaveAttribute('data-truenas-protection-stale', 'true'); + expect(staleOkRow.querySelector('[data-truenas-protection-stale-badge="true"]')).toHaveTextContent( + 'Stale data', + ); + expect(staleOkRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toBeNull(); + + // Stale failed row preserves red Failed badge AND shows amber Stale data cue under Dataset + const staleFailedRow = document.querySelector( + '[data-truenas-protection-row="rep-east-failed"]', + )!; + expect(staleFailedRow).toHaveAttribute('data-truenas-protection-stale', 'true'); + expect(staleFailedRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toHaveTextContent( + 'Stale data', + ); + expect(staleFailedRow.querySelectorAll('td')[5]).toHaveTextContent('Failed'); + + // Stale running row preserves Running text without pulsing dot and shows amber Stale data cue + const staleRunningRow = document.querySelector( + '[data-truenas-protection-row="rep-east-running"]', + )!; + expect(staleRunningRow).toHaveAttribute('data-truenas-protection-stale', 'true'); + expect(staleRunningRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toHaveTextContent( + 'Stale data', + ); + expect(staleRunningRow.querySelector('.animate-pulse')).toBeNull(); + + // Fresh row stays Healthy without stale cues + const freshRow = document.querySelector('[data-truenas-protection-row="snap-west-ok"]')!; + expect(freshRow).not.toHaveAttribute('data-truenas-protection-stale'); + expect(freshRow.querySelectorAll('td')[5]).toHaveTextContent('Healthy'); + + // Open stale healthy detail drawer: shows amber InlineNotice, Status: Stale data, Last reported: Healthy + await fireEvent.click(staleOkRow); + const detail = within(screen.getByTestId('truenas-protection-detail')); + const staleNotice = detail.getByTestId('truenas-protection-stale-notice'); + expect(staleNotice).toHaveTextContent('Readings from nas-east may be out of date.'); + expect(staleNotice).toHaveTextContent( + 'TrueNAS collection error: API connection refused (last report 14m ago)', + ); + expect(detail.getByText('Status', { exact: true }).closest('tr')).toHaveTextContent('Stale data'); + expect(detail.getByText('Last reported', { exact: true }).closest('tr')).toHaveTextContent( + 'Healthy', + ); + + // Filter to Stale then recover live over WebSocket: Stale chip stays visible at 0 while active + await fireEvent.click(screen.getByRole('button', { name: 'Stale, 3' })); + expect(document.querySelectorAll('[data-truenas-protection-row]')).toHaveLength(3); + + setSystems([ + makeSystem({ + ...staleNas, + sourceStatus: { truenas: { status: 'online' } }, + health: { verdict: 'ok', reasons: [] }, + }), + freshNas, + ]); + + expect(screen.getByRole('button', { name: 'Stale, 0' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Healthy, 2' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Running, 1' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Attention, 1' })).toBeInTheDocument(); + + // Switching back to All removes the Stale chip and clears the open drawer stale banner + await fireEvent.click(screen.getByRole('button', { name: 'All, 4' })); + expect(screen.queryByRole('button', { name: /^Stale,/ })).not.toBeInTheDocument(); + expect(screen.queryByTestId('truenas-protection-stale-notice')).not.toBeInTheDocument(); + expect( + within(screen.getByTestId('truenas-protection-detail')) + .getByText('Outcome', { exact: true }) + .closest('tr'), + ).toHaveTextContent('Healthy'); + }); +}); diff --git a/frontend-modern/src/features/truenas/truenasPageModel.ts b/frontend-modern/src/features/truenas/truenasPageModel.ts index e21d83221c..a8523173b9 100644 --- a/frontend-modern/src/features/truenas/truenasPageModel.ts +++ b/frontend-modern/src/features/truenas/truenasPageModel.ts @@ -1,6 +1,7 @@ import { resolveResourcePlatformType } from '@/utils/sourcePlatforms'; import { asTrimmedString } from '@/utils/stringUtils'; import { parseBackupTimestampMs } from '@/utils/backupTimestamp'; +import { getResourceStaleness } from '@/features/platformPage/resourceStaleness'; import { getTrueNASDatasetStateSummary, getTrueNASStaleNotice, @@ -32,10 +33,10 @@ export type TrueNASIncidentSeverityFilter = 'all' | 'critical' | 'warning' | 'in export type TrueNASStorageStatusFilter = 'all' | 'healthy' | 'attention' | 'offline'; export type TrueNASStorageKindFilter = 'all' | 'volumes' | 'disks'; export type TrueNASProtectionStatusFilter = - 'all' | 'attention' | 'success' | 'warning' | 'failed' | 'running' | 'unknown'; + 'all' | 'attention' | 'stale' | 'success' | 'warning' | 'failed' | 'running' | 'unknown'; export type TrueNASProtectionStatusBucket = Exclude< TrueNASProtectionStatusFilter, - 'all' | 'attention' + 'all' | 'attention' | 'stale' >; export type TrueNASProtectionKind = 'snapshot' | 'replication' | 'other'; @@ -900,12 +901,195 @@ export function getTrueNASStorageIssue( return { status, label: TRUENAS_STORAGE_ISSUE_LABELS[status], reasons }; } +export type TrueNASProtectionStaleNotice = TrueNASStaleNotice & { + systemName: string; + age?: string; +}; + +const addConnectionTokens = (target: Set, value: unknown) => { + const normalized = normalize(value); + if (!normalized) return; + target.add(normalized); + const systemIndex = normalized.lastIndexOf('system:'); + if (systemIndex >= 0) { + const suffix = normalized.slice(systemIndex + 'system:'.length).trim(); + if (suffix) target.add(suffix); + } + if (normalized.startsWith('agent:')) { + const suffix = normalized.slice('agent:'.length).trim(); + if (suffix) target.add(suffix); + } +}; + +const buildTrueNASSystemStaleNotice = (system: Resource): TrueNASProtectionStaleNotice | null => { + const systemName = + asTrimmedString(system.displayName) || + asTrimmedString(system.name) || + asTrimmedString(system.truenas?.hostname) || + system.id; + const baseNotice = getTrueNASStaleNotice(system); + const staleness = getResourceStaleness(system); + const age = staleness?.age ?? undefined; + const ageSuffix = age ? ` (last report ${age} ago)` : ''; + if (baseNotice) { + const detail = + age && !baseNotice.detail.includes(age) ? `${baseNotice.detail}${ageSuffix}` : baseNotice.detail; + return { + ...baseNotice, + detail, + systemName, + ...(age ? { age } : {}), + }; + } + if (staleness) { + return { + badge: 'Stale data', + detail: age + ? `No TrueNAS report from ${systemName} for ${age}` + : `TrueNAS has not updated ${systemName} recently`, + systemName, + ...(age ? { age } : {}), + }; + } + if (!system.sourceStatus?.truenas && normalize(system.status) === 'offline') { + return { + badge: 'Stale data', + detail: `TrueNAS system ${systemName} is offline in Pulse`, + systemName, + }; + } + return null; +}; + +type IndexedTrueNASSystem = { + notice: TrueNASProtectionStaleNotice | null; + connectionIds: Set; + hasExplicitConnectionId: boolean; + hostnames: Set; +}; + +const indexTrueNASSystemsForProtection = ( + systems: readonly Resource[], +): IndexedTrueNASSystem[] => + systems.map((system) => { + const connectionIds = new Set(); + const explicitAgentId = normalize(system.agent?.agentId); + const explicitMetricId = normalize(system.metricsTarget?.resourceId); + addConnectionTokens(connectionIds, system.agent?.agentId); + addConnectionTokens(connectionIds, system.metricsTarget?.resourceId); + addConnectionTokens(connectionIds, system.platformId); + addConnectionTokens(connectionIds, system.canonical?.platformId); + addConnectionTokens(connectionIds, system.id); + for (const alias of system.canonical?.aliases ?? []) { + addConnectionTokens(connectionIds, alias); + } + const hostnames = new Set(); + for (const value of [ + system.truenas?.hostname, + system.agent?.hostname, + system.canonical?.hostname, + system.name, + system.displayName, + ]) { + const normalized = normalize(value); + if (normalized) hostnames.add(normalized); + } + return { + notice: buildTrueNASSystemStaleNotice(system), + connectionIds, + hasExplicitConnectionId: Boolean(explicitAgentId || explicitMetricId), + hostnames, + }; + }); + +const resolveStaleNoticeFromCandidates = ( + candidates: readonly IndexedTrueNASSystem[], +): TrueNASProtectionStaleNotice | null => { + if (candidates.length === 0) return null; + return candidates.every((entry) => entry.notice !== null) ? candidates[0].notice : null; +}; + +const resolveProtectionStaleNotice = ( + point: RecoveryPoint, + indexedSystems: readonly IndexedTrueNASSystem[], +): TrueNASProtectionStaleNotice | null => { + if (indexedSystems.length === 0) return null; + + const pointConnIds = [ + normalize(point.details?.connectionId), + (() => { + const scope = normalize(point.providerScope); + return scope && scope !== 'provider-default' ? scope : ''; + })(), + ].filter(Boolean); + + const pointHostnames = [ + normalize(point.details?.hostname), + normalize(point.display?.nodeHostLabel), + normalize(point.display?.nodeAgentLabel), + normalize(point.display?.clusterLabel), + normalize(point.node), + normalize(point.cluster), + ].filter(Boolean); + + if (pointConnIds.length > 0) { + const connMatches = indexedSystems.filter((entry) => + pointConnIds.some((id) => entry.connectionIds.has(id)), + ); + if (connMatches.length > 0) { + return resolveStaleNoticeFromCandidates(connMatches); + } + if (pointHostnames.length > 0) { + const hostMatches = indexedSystems.filter( + (entry) => + !entry.hasExplicitConnectionId && + pointHostnames.some((host) => entry.hostnames.has(host)), + ); + return resolveStaleNoticeFromCandidates(hostMatches); + } + return null; + } + + if (pointHostnames.length > 0) { + const hostMatches = indexedSystems.filter((entry) => + pointHostnames.some((host) => entry.hostnames.has(host)), + ); + return resolveStaleNoticeFromCandidates(hostMatches); + } + + return resolveStaleNoticeFromCandidates(indexedSystems); +}; + +export function getTrueNASProtectionStaleNotice( + point: RecoveryPoint, + systems: readonly Resource[], +): TrueNASProtectionStaleNotice | null { + if (systems.length === 0) return null; + return resolveProtectionStaleNotice(point, indexTrueNASSystemsForProtection(systems)); +} + +export function buildTrueNASProtectionStaleNoticeMap( + points: readonly RecoveryPoint[], + systems: readonly Resource[], +): Map { + const notices = new Map(); + if (points.length === 0 || systems.length === 0) return notices; + const indexed = indexTrueNASSystemsForProtection(systems); + if (!indexed.some((entry) => entry.notice !== null)) return notices; + for (const point of points) { + const notice = resolveProtectionStaleNotice(point, indexed); + if (notice) notices.set(point.id, notice); + } + return notices; +} + export function mapTrueNASProtectionStatus(point: RecoveryPoint): TrueNASProtectionStatusBucket { return normalizeProtectionOutcome(point.outcome); } export type TrueNASProtectionPosture = { healthy: number; + stale: number; warning: number; failed: number; running: number; @@ -915,9 +1099,11 @@ export type TrueNASProtectionPosture = { export function buildTrueNASProtectionPosture( points: readonly RecoveryPoint[], + staleNotices?: ReadonlyMap, ): TrueNASProtectionPosture { const posture: TrueNASProtectionPosture = { healthy: 0, + stale: 0, warning: 0, failed: 0, running: 0, @@ -926,10 +1112,19 @@ export function buildTrueNASProtectionPosture( }; for (const point of points) { const status = mapTrueNASProtectionStatus(point); - if (status === 'success') posture.healthy += 1; - else posture[status] += 1; + const isStale = Boolean(staleNotices?.get(point.id)); + if (isStale) posture.stale += 1; + if (status === 'success') { + if (!isStale) posture.healthy += 1; + } else if (status === 'running') { + if (!isStale) posture.running += 1; + } else { + posture[status] += 1; + } + if (status === 'failed' || status === 'warning' || isStale) { + posture.attention += 1; + } } - posture.attention = posture.warning + posture.failed; return posture; } @@ -949,7 +1144,10 @@ export function mapTrueNASProtectionKind(point: RecoveryPoint): TrueNASProtectio return 'other'; } -const trueNASProtectionSearchTokens = (point: RecoveryPoint): string => { +const trueNASProtectionSearchTokens = ( + point: RecoveryPoint, + staleNotice?: TrueNASProtectionStaleNotice, +): string => { const details = point.details ?? {}; const sourceDatasets = Array.isArray(details.sourceDatasets) ? details.sourceDatasets : []; return joinSearchTokens([ @@ -978,20 +1176,31 @@ const trueNASProtectionSearchTokens = (point: RecoveryPoint): string => { details.taskId, details.taskName, ...sourceDatasets, + staleNotice?.badge, + staleNotice?.detail, + staleNotice?.systemName, ]); }; -const trueNASProtectionAttentionRank = (point: RecoveryPoint): number => { +const trueNASProtectionAttentionRank = ( + point: RecoveryPoint, + staleNotices?: ReadonlyMap, +): number => { const status = mapTrueNASProtectionStatus(point); if (status === 'failed') return 0; if (status === 'warning') return 1; - return 2; + if (staleNotices?.has(point.id)) return 2; + return 3; }; -export function sortTrueNASProtectionPoints(points: readonly RecoveryPoint[]): RecoveryPoint[] { +export function sortTrueNASProtectionPoints( + points: readonly RecoveryPoint[], + staleNotices?: ReadonlyMap, +): RecoveryPoint[] { return [...points].sort((left, right) => { const attentionDelta = - trueNASProtectionAttentionRank(left) - trueNASProtectionAttentionRank(right); + trueNASProtectionAttentionRank(left, staleNotices) - + trueNASProtectionAttentionRank(right, staleNotices); if (attentionDelta !== 0) return attentionDelta; const leftTime = getRecoveryPointTimestampMs(left); const rightTime = getRecoveryPointTimestampMs(right); @@ -1013,17 +1222,32 @@ export function filterTrueNASProtectionPoints( points: RecoveryPoint[], search: string, status: TrueNASProtectionStatusFilter, + staleNotices?: ReadonlyMap, ): RecoveryPoint[] { const needle = search.trim().toLowerCase(); return points.filter((point) => { const pointStatus = mapTrueNASProtectionStatus(point); - if (status === 'attention' && pointStatus !== 'warning' && pointStatus !== 'failed') { + const staleNotice = staleNotices?.get(point.id); + const isStale = Boolean(staleNotice); + if (status === 'attention' && pointStatus !== 'warning' && pointStatus !== 'failed' && !isStale) { + return false; + } + if (status === 'stale' && !isStale) return false; + if (status === 'success' && (pointStatus !== 'success' || isStale)) return false; + if (status === 'running' && (pointStatus !== 'running' || isStale)) return false; + if ( + status !== 'all' && + status !== 'attention' && + status !== 'stale' && + status !== 'success' && + status !== 'running' && + pointStatus !== status + ) { return false; } - if (status !== 'all' && status !== 'attention' && pointStatus !== status) return false; if (!needle) return true; if (mapTrueNASProtectionKind(point).includes(needle)) return true; - return trueNASProtectionSearchTokens(point).includes(needle); + return trueNASProtectionSearchTokens(point, staleNotice).includes(needle); }); } From 1345d8bcb3531ee26b75b25033b73dc1541517bb Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:00:18 +0000 Subject: [PATCH 2/6] Call getRecoveryOutcomeBadgeClass directly in TrueNASProtectionTable Inline the canonical getRecoveryOutcomeBadgeClass call so canonical-platform-audit passes with no local recovery outcome badge helper. Contract-Neutral: presentation-only helper cleanup with no API, schema, or subsystem contract delta. Change-source: pulse-maintainer --- .../src/features/truenas/TrueNASProtectionTable.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx index 501a18f2b5..8864c66158 100644 --- a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx +++ b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx @@ -522,12 +522,12 @@ export const TrueNASProtectionTable: Component<{ ? `${stale.badge} · Last reported ${outcomeLabel} · ${stale.detail}` : `${outcomeLabel} · ${stale.badge} · ${stale.detail}`; }; - const outcomeBadgeClass = () => { + const effectiveOutcome = () => { const stale = staleNotice(); - if (!stale) return getRecoveryOutcomeBadgeClass(outcome()); - if (outcome() === 'success') return getRecoveryOutcomeBadgeClass('warning'); - if (outcome() === 'running') return getRecoveryOutcomeBadgeClass('unknown'); - return getRecoveryOutcomeBadgeClass(outcome()); + if (!stale) return outcome(); + if (outcome() === 'success') return 'warning'; + if (outcome() === 'running') return 'unknown'; + return outcome(); }; const detailStatus = () => { const stale = staleNotice(); @@ -619,7 +619,7 @@ export const TrueNASProtectionTable: Component<{ Date: Fri, 27 Nov 2026 15:26:20 +0000 Subject: [PATCH 3/6] Format TrueNAS protection freshness files with Prettier Apply Prettier 100-column line wrapping to truenasPageModel.ts, TrueNASProtectionTable.tsx, and TrueNASProtectionTable.freshness.test.tsx so format:check passes cleanly. Contract-Neutral: formatting only with no runtime, API, schema, or subsystem contract delta. Change-source: pulse-maintainer --- .../truenas/TrueNASProtectionTable.tsx | 8 +--- .../TrueNASProtectionTable.freshness.test.tsx | 38 ++++++++++--------- .../src/features/truenas/truenasPageModel.ts | 15 +++++--- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx index 8864c66158..952f34a5f7 100644 --- a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx +++ b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx @@ -348,12 +348,8 @@ export const TrueNASProtectionTable: Component<{ const staleNoticeByPointId = createMemo(() => buildTrueNASProtectionStaleNoticeMap(props.points, props.systems ?? []), ); - const rows = createMemo(() => - sortTrueNASProtectionPoints(props.points, staleNoticeByPointId()), - ); - const posture = createMemo(() => - buildTrueNASProtectionPosture(rows(), staleNoticeByPointId()), - ); + const rows = createMemo(() => sortTrueNASProtectionPoints(props.points, staleNoticeByPointId())); + const posture = createMemo(() => buildTrueNASProtectionPosture(rows(), staleNoticeByPointId())); const detail = createTrueNASDetailState('truenas-protection-detail'); const tableState = createPlatformTableFilterState({ resources: rows, diff --git a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx index ea7712ae82..6935cfedad 100644 --- a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx +++ b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx @@ -52,7 +52,7 @@ afterEach(() => { }); describe('TrueNAS protection freshness model', () => { - it('isolates DR clones sharing a hostname by connectionId so healthy peers never turn stale', () => { + it('isolates DR clones sharing a hostname by connectionId', () => { const stalePrimary = makeSystem({ id: 'truenas:agent:system:conn-primary', name: 'truenas', @@ -161,7 +161,9 @@ describe('TrueNAS protection freshness model', () => { details: { hostname: 'nas-offline', dataset: 'tank/backups' }, }); - expect(getTrueNASProtectionStaleNotice(telemetryPoint, [telemetryStale, offlineSystem])).toEqual( + expect( + getTrueNASProtectionStaleNotice(telemetryPoint, [telemetryStale, offlineSystem]), + ).toEqual( expect.objectContaining({ badge: 'Stale data', systemName: 'nas-telemetry', @@ -178,7 +180,7 @@ describe('TrueNAS protection freshness model', () => { ); }); - it('excludes stale success and running points from Healthy and Running posture, ranks stale above fresh, and searches stale details', () => { + it('excludes stale success/running from Healthy/Running and ranks stale first', () => { const staleNas = makeSystem({ id: 'truenas:agent:system:conn-stale', name: 'nas-east', @@ -247,9 +249,9 @@ describe('TrueNAS protection freshness model', () => { 'fresh-ok', ]); - expect(filterTrueNASProtectionPoints(points, '', 'success', staleMap).map((p) => p.id)).toEqual([ - 'fresh-ok', - ]); + expect( + filterTrueNASProtectionPoints(points, '', 'success', staleMap).map((p) => p.id), + ).toEqual(['fresh-ok']); expect(filterTrueNASProtectionPoints(points, '', 'running', staleMap)).toEqual([]); expect(filterTrueNASProtectionPoints(points, '', 'stale', staleMap).map((p) => p.id)).toEqual([ 'stale-ok', @@ -269,7 +271,7 @@ describe('TrueNAS protection freshness model', () => { }); describe('TrueNASProtectionTable stale-reading UI', () => { - it('surfaces stale healthy, running, and failed events truthfully and clears them reactively on live recovery', async () => { + it('surfaces stale events truthfully and clears them on live recovery', async () => { const staleNas = makeSystem({ id: 'truenas:agent:system:conn-east', name: 'nas-east', @@ -370,9 +372,9 @@ describe('TrueNASProtectionTable stale-reading UI', () => { // Stale healthy row shows amber Stale data badge in Outcome and no redundant cue under Dataset const staleOkRow = document.querySelector('[data-truenas-protection-row="snap-east-ok"]')!; expect(staleOkRow).toHaveAttribute('data-truenas-protection-stale', 'true'); - expect(staleOkRow.querySelector('[data-truenas-protection-stale-badge="true"]')).toHaveTextContent( - 'Stale data', - ); + expect( + staleOkRow.querySelector('[data-truenas-protection-stale-badge="true"]'), + ).toHaveTextContent('Stale data'); expect(staleOkRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toBeNull(); // Stale failed row preserves red Failed badge AND shows amber Stale data cue under Dataset @@ -380,9 +382,9 @@ describe('TrueNASProtectionTable stale-reading UI', () => { '[data-truenas-protection-row="rep-east-failed"]', )!; expect(staleFailedRow).toHaveAttribute('data-truenas-protection-stale', 'true'); - expect(staleFailedRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toHaveTextContent( - 'Stale data', - ); + expect( + staleFailedRow.querySelector('[data-truenas-protection-stale-cue="true"]'), + ).toHaveTextContent('Stale data'); expect(staleFailedRow.querySelectorAll('td')[5]).toHaveTextContent('Failed'); // Stale running row preserves Running text without pulsing dot and shows amber Stale data cue @@ -390,9 +392,9 @@ describe('TrueNASProtectionTable stale-reading UI', () => { '[data-truenas-protection-row="rep-east-running"]', )!; expect(staleRunningRow).toHaveAttribute('data-truenas-protection-stale', 'true'); - expect(staleRunningRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toHaveTextContent( - 'Stale data', - ); + expect( + staleRunningRow.querySelector('[data-truenas-protection-stale-cue="true"]'), + ).toHaveTextContent('Stale data'); expect(staleRunningRow.querySelector('.animate-pulse')).toBeNull(); // Fresh row stays Healthy without stale cues @@ -408,7 +410,9 @@ describe('TrueNASProtectionTable stale-reading UI', () => { expect(staleNotice).toHaveTextContent( 'TrueNAS collection error: API connection refused (last report 14m ago)', ); - expect(detail.getByText('Status', { exact: true }).closest('tr')).toHaveTextContent('Stale data'); + expect(detail.getByText('Status', { exact: true }).closest('tr')).toHaveTextContent( + 'Stale data', + ); expect(detail.getByText('Last reported', { exact: true }).closest('tr')).toHaveTextContent( 'Healthy', ); diff --git a/frontend-modern/src/features/truenas/truenasPageModel.ts b/frontend-modern/src/features/truenas/truenasPageModel.ts index a8523173b9..a4055de74a 100644 --- a/frontend-modern/src/features/truenas/truenasPageModel.ts +++ b/frontend-modern/src/features/truenas/truenasPageModel.ts @@ -933,7 +933,9 @@ const buildTrueNASSystemStaleNotice = (system: Resource): TrueNASProtectionStale const ageSuffix = age ? ` (last report ${age} ago)` : ''; if (baseNotice) { const detail = - age && !baseNotice.detail.includes(age) ? `${baseNotice.detail}${ageSuffix}` : baseNotice.detail; + age && !baseNotice.detail.includes(age) + ? `${baseNotice.detail}${ageSuffix}` + : baseNotice.detail; return { ...baseNotice, detail, @@ -968,9 +970,7 @@ type IndexedTrueNASSystem = { hostnames: Set; }; -const indexTrueNASSystemsForProtection = ( - systems: readonly Resource[], -): IndexedTrueNASSystem[] => +const indexTrueNASSystemsForProtection = (systems: readonly Resource[]): IndexedTrueNASSystem[] => systems.map((system) => { const connectionIds = new Set(); const explicitAgentId = normalize(system.agent?.agentId); @@ -1229,7 +1229,12 @@ export function filterTrueNASProtectionPoints( const pointStatus = mapTrueNASProtectionStatus(point); const staleNotice = staleNotices?.get(point.id); const isStale = Boolean(staleNotice); - if (status === 'attention' && pointStatus !== 'warning' && pointStatus !== 'failed' && !isStale) { + if ( + status === 'attention' && + pointStatus !== 'warning' && + pointStatus !== 'failed' && + !isStale + ) { return false; } if (status === 'stale' && !isStale) return false; From 30fa9d2ff25ae45a1d18213571b3588ea05351c9 Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:30:39 +0000 Subject: [PATCH 4/6] Format TrueNAS protection freshness test with Prettier Apply Prettier formatting to TrueNASProtectionTable.freshness.test.tsx so format:check passes on every touched file. Contract-Neutral: test formatting only with no runtime or contract delta. Change-source: pulse-maintainer --- .../__tests__/TrueNASProtectionTable.freshness.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx index 6935cfedad..93c124b15d 100644 --- a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx +++ b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx @@ -249,9 +249,9 @@ describe('TrueNAS protection freshness model', () => { 'fresh-ok', ]); - expect( - filterTrueNASProtectionPoints(points, '', 'success', staleMap).map((p) => p.id), - ).toEqual(['fresh-ok']); + expect(filterTrueNASProtectionPoints(points, '', 'success', staleMap).map((p) => p.id)).toEqual( + ['fresh-ok'], + ); expect(filterTrueNASProtectionPoints(points, '', 'running', staleMap)).toEqual([]); expect(filterTrueNASProtectionPoints(points, '', 'stale', staleMap).map((p) => p.id)).toEqual([ 'stale-ok', From 732a43fc7490502f500f0536c3cea881149df8e0 Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:51:00 +0000 Subject: [PATCH 5/6] Use canonicalIdentity, update copy punctuation, and align posture tests Read system.canonicalIdentity on Resource in truenasPageModel.ts for TypeScript strictness, replace the semicolon in the stale protection drawer notice with a sentence boundary for copy-style-audit, and update TrueNAS protection posture tests for the stale count field. Contract-Neutral: type-safety, user-copy punctuation, and unit-test alignment with no API, schema, or subsystem contract delta. Change-source: pulse-maintainer --- .../src/features/truenas/TrueNASProtectionTable.tsx | 4 ++-- .../__tests__/TrueNASProtectionTable.freshness.test.tsx | 3 ++- .../truenas/__tests__/truenasPageModel.coverage.test.ts | 2 ++ .../src/features/truenas/__tests__/truenasPageModel.test.ts | 1 + frontend-modern/src/features/truenas/truenasPageModel.ts | 6 +++--- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx index 952f34a5f7..e933b4f511 100644 --- a/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx +++ b/frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx @@ -668,8 +668,8 @@ export const TrueNASProtectionTable: Component<{ Readings from {notice().systemName} may be out of date.

- {notice().detail}. Showing the last reported protection event; - newer snapshots, replication runs, or failures may be missing. + {notice().detail}. Showing the last reported protection event. + Newer snapshots, replication runs, or failures may be missing.

)} diff --git a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx index 93c124b15d..a537fd2afe 100644 --- a/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx +++ b/frontend-modern/src/features/truenas/__tests__/TrueNASProtectionTable.freshness.test.tsx @@ -25,7 +25,7 @@ const makeSystem = (overrides: Partial & Pick): Resour ({ type: 'agent', name: overrides.id, - displayName: overrides.id, + displayName: overrides.name ?? overrides.id, status: 'online', platformId: 'truenas-primary', platformType: 'truenas', @@ -215,6 +215,7 @@ describe('TrueNAS protection freshness model', () => { kind: 'backup', mode: 'remote', outcome: 'running', + startedAt: '2026-11-27T10:30:00Z', completedAt: undefined, details: { connectionId: 'conn-stale', hostname: 'nas-east', taskName: 'rep-east' }, }); diff --git a/frontend-modern/src/features/truenas/__tests__/truenasPageModel.coverage.test.ts b/frontend-modern/src/features/truenas/__tests__/truenasPageModel.coverage.test.ts index fdbc91fde2..67860c6b6c 100644 --- a/frontend-modern/src/features/truenas/__tests__/truenasPageModel.coverage.test.ts +++ b/frontend-modern/src/features/truenas/__tests__/truenasPageModel.coverage.test.ts @@ -274,6 +274,7 @@ describe('truenasPageModel coverage', () => { ]); expect(posture).toEqual({ healthy: 1, + stale: 0, warning: 0, failed: 1, running: 0, @@ -285,6 +286,7 @@ describe('truenasPageModel coverage', () => { it('returns a fully zeroed posture for an empty recovery-point array', () => { expect(buildTrueNASProtectionPosture([])).toEqual({ healthy: 0, + stale: 0, warning: 0, failed: 0, running: 0, diff --git a/frontend-modern/src/features/truenas/__tests__/truenasPageModel.test.ts b/frontend-modern/src/features/truenas/__tests__/truenasPageModel.test.ts index cd78f3e21c..323bad252a 100644 --- a/frontend-modern/src/features/truenas/__tests__/truenasPageModel.test.ts +++ b/frontend-modern/src/features/truenas/__tests__/truenasPageModel.test.ts @@ -1275,6 +1275,7 @@ describe('truenasPageModel', () => { expect(mapTrueNASProtectionStatus(legacyReplication)).toBe('warning'); expect(buildTrueNASProtectionPosture([snapshot, replication, legacyReplication])).toEqual({ healthy: 1, + stale: 0, warning: 1, failed: 0, running: 1, diff --git a/frontend-modern/src/features/truenas/truenasPageModel.ts b/frontend-modern/src/features/truenas/truenasPageModel.ts index a4055de74a..60becd5cbb 100644 --- a/frontend-modern/src/features/truenas/truenasPageModel.ts +++ b/frontend-modern/src/features/truenas/truenasPageModel.ts @@ -978,16 +978,16 @@ const indexTrueNASSystemsForProtection = (systems: readonly Resource[]): Indexed addConnectionTokens(connectionIds, system.agent?.agentId); addConnectionTokens(connectionIds, system.metricsTarget?.resourceId); addConnectionTokens(connectionIds, system.platformId); - addConnectionTokens(connectionIds, system.canonical?.platformId); + addConnectionTokens(connectionIds, system.canonicalIdentity?.platformId); addConnectionTokens(connectionIds, system.id); - for (const alias of system.canonical?.aliases ?? []) { + for (const alias of system.canonicalIdentity?.aliases ?? []) { addConnectionTokens(connectionIds, alias); } const hostnames = new Set(); for (const value of [ system.truenas?.hostname, system.agent?.hostname, - system.canonical?.hostname, + system.canonicalIdentity?.hostname, system.name, system.displayName, ]) { From fdbc37ef9a2fa348b13e242cc12f3e9513c811e6 Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 15:52:16 +0000 Subject: [PATCH 6/6] Record browser verification for TrueNAS protection stale readings Records paired production-build Playwright verification (desktop Chromium 1440x940 light stale + live WebSocket recovery and touch phone WebKit 360x820 dark collapsed + expanded drawer) for TrueNASPageSurface.tsx, TrueNASProtectionTable.tsx, TrueNASTableFrame.tsx, and truenasPageModel.ts. Contract-Neutral: browser verification receipt only; no runtime or contract change. Change-source: pulse-maintainer --- .../b297813a5866ffe6.json | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 frontend-modern/browser-verification/b297813a5866ffe6.json diff --git a/frontend-modern/browser-verification/b297813a5866ffe6.json b/frontend-modern/browser-verification/b297813a5866ffe6.json new file mode 100644 index 0000000000..96eedd9ad2 --- /dev/null +++ b/frontend-modern/browser-verification/b297813a5866ffe6.json @@ -0,0 +1,42 @@ +{ + "version": 1, + "base_sha": "732a43fc7490502f500f0536c3cea881149df8e0", + "verified_at": "2026-11-27T15:52:12Z", + "result": "passed", + "changed_paths": [ + "frontend-modern/src/features/truenas/TrueNASPageSurface.tsx", + "frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx", + "frontend-modern/src/features/truenas/TrueNASTableFrame.tsx", + "frontend-modern/src/features/truenas/truenasPageModel.ts" + ], + "content_sha256": { + "frontend-modern/src/features/truenas/TrueNASPageSurface.tsx": "2607c299c5581f8a5e9b1370e8a6df9786c2e66d26a17d4e3f2c72084f0082a7", + "frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx": "4dcaf4998deafe4cb2febaf2f3953baf0046ef881d5246e855ae28de2560c3ad", + "frontend-modern/src/features/truenas/TrueNASTableFrame.tsx": "dac0de9ae517f8e1fac4ccf9f0205c81268210a955cd5ba584b421be9ddac785", + "frontend-modern/src/features/truenas/truenasPageModel.ts": "cef8ff4b77c9be5dba3fa14b043ebd94f89f02e90a09379eb98d455e05ad5f23" + }, + "routes": [ + "/truenas/protection" + ], + "viewports": [ + { + "width": 1440, + "height": 940 + }, + { + "width": 360, + "height": 820 + } + ], + "states": [ + "Playwright 1.56.1 paired production builds (before a366d7c0a708 vs after 732a43fc7490) on desktop Chromium 141.0.7390.37 (1440x940 light) and touch WebKit 26.0 (360x820 dark); all 8 paired screenshots visually inspected with 0 console errors, 0 page errors, 0 failed requests, 0 off-origin requests, and 0px horizontal overflow.", + "/truenas/protection stale appliance nas-east (18m telemetry_stale, API connection timed out) alongside fresh nas-west: chips shift from false All 4 / Attention 1 / Healthy 2 / Failed 1 / Running 1 to All 4 / Attention 3 / Stale 3 / Healthy 1 / Failed 1 / Running 0; tank/billing moves from false green Healthy to amber Stale data (compact Stale on 360px phone) above fresh vault/docs; tank/archive preserves red Failed pill and tank/media preserves non-pulsing muted Running pill alongside amber Stale data cue beneath dataset name; expanded tank/billing drawer renders amber warning banner, amber Status: Stale data, and preserved green Last reported: Healthy.", + "/truenas/protection live WebSocket rawData recovery frame (top-level sourceStatus.truenas online and health.verdict ok while platformData.sourceStatus remains stale) without reload: immediately clears all Stale data cues, Stale filter chip, and open drawer warning banner, restores green Healthy on tank/billing and pulsing blue Running on tank/media, and restores All 4 / Attention 1 / Healthy 2 / Failed 1 / Running 1.", + "/truenas/protection touch WebKit phone (360x820 dark): exact 32px row height on all 4 rows, 0px horizontal overflow in both collapsed list and expanded stale drawer, clean wrapped dark-amber warning notice." + ], + "interactions": [ + "Loaded /truenas/protection on desktop light (1440x940) and touch phone dark (360x820), verifying filter chip counts, row ordering, stale cues, non-pulsing stale running state, exact 32px phone row height, and 0px overflow.", + "Clicked/tapped tank/billing row on desktop and phone to expand its inline detail drawer and verified the amber stale warning banner, Status: Stale data, Last reported: Healthy, and preserved snapshot/target metadata.", + "Delivered live WebSocket rawData recovery frame on desktop while tank/billing drawer remained open and verified immediate clearance of stale cues, Stale filter chip, and open drawer banner without reload." + ] +}