Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Make approval expiry labels fail closed

rcourtmane7996a5914bb
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 53872e1c95..2b2acd7c16 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -783,7 +783,9 @@ order. Approval-linked findings must follow that same ordering so multi-approval
`Review` actions jump to the most urgent finding instead of an arbitrary one.
Malformed or missing approval timestamps must sort after valid timestamps and
must not produce non-deterministic comparator results in the shared urgency
-utility.
+utility. Patrol approval banners must apply the same fail-closed timestamp
+posture to visible countdown copy instead of rendering invalid math such as
+`NaN`.
Patrol fix approvals also inherit the unified action-governance preflight
contract: queued fixes must keep their plan-level dry-run availability, safety
checks, verification steps, approval policy, and action id in the shared
diff --git a/frontend-modern/src/components/patrol/ApprovalBanner.tsx b/frontend-modern/src/components/patrol/ApprovalBanner.tsx
index 2441f147dc..06ecd1ef3c 100644
--- a/frontend-modern/src/components/patrol/ApprovalBanner.tsx
+++ b/frontend-modern/src/components/patrol/ApprovalBanner.tsx
@@ -12,7 +12,10 @@ import { Component, Show, createMemo, createSignal, createEffect, onCleanup } fr
import { aiIntelligenceStore } from '@/stores/aiIntelligence';
import { notificationStore } from '@/stores/notifications';
import type { ApprovalRequest } from '@/api/ai';
-import { getApprovalRiskPresentation } from '@/utils/approvalRiskPresentation';
+import {
+ getApprovalExpiryStatusLabel,
+ getApprovalRiskPresentation,
+} from '@/utils/approvalRiskPresentation';
import ShieldAlertIcon from 'lucide-solid/icons/shield-alert';
import CheckIcon from 'lucide-solid/icons/check';
import XIcon from 'lucide-solid/icons/x';
@@ -37,14 +40,8 @@ export const ApprovalBanner: Component<ApprovalBannerProps> = (props) => {
const firstApproval = createMemo(() => pending()[0] ?? null);
- const timeRemaining = (expiresAt: string) => {
- void tick(); // subscribe to tick signal for reactivity
- const diff = new Date(expiresAt).getTime() - Date.now();
- if (diff <= 0) return 'expired';
- const mins = Math.floor(diff / 60000);
- const secs = Math.floor((diff % 60000) / 1000);
- if (mins > 0) return `${mins}m ${secs}s`;
- return `${secs}s`;
+ const expiryStatusLabel = (expiresAt?: string | null) => {
+ return getApprovalExpiryStatusLabel(expiresAt, tick());
};
const handleApprove = async (approval: ApprovalRequest) => {
@@ -106,7 +103,7 @@ export const ApprovalBanner: Component<ApprovalBannerProps> = (props) => {
{firstApprovalRisk()!.label} risk
</span>
<span class="text-xs text-amber-700 dark:text-amber-300">
- expires {timeRemaining(firstApproval()!.expiresAt)}
+ {expiryStatusLabel(firstApproval()!.expiresAt)}
</span>
</div>
<p
diff --git a/frontend-modern/src/components/patrol/__tests__/ApprovalBanner.test.tsx b/frontend-modern/src/components/patrol/__tests__/ApprovalBanner.test.tsx
index 92e06a7e83..2eeb04a12a 100644
--- a/frontend-modern/src/components/patrol/__tests__/ApprovalBanner.test.tsx
+++ b/frontend-modern/src/components/patrol/__tests__/ApprovalBanner.test.tsx
@@ -87,4 +87,49 @@ describe('ApprovalBanner', () => {
expect(onScrollToFinding).toHaveBeenCalledWith('finding-sooner');
});
+
+ it('renders a deterministic countdown label for a valid single approval expiry', () => {
+ state.pendingApprovals = [approvalRequest({ expiresAt: '2026-03-01T00:06:00Z' })];
+
+ render(() => <ApprovalBanner />);
+
+ expect(screen.getByText('expires 6m 0s')).toBeInTheDocument();
+ });
+
+ it('fails closed instead of rendering NaN when a single approval expiry is malformed', () => {
+ state.pendingApprovals = [approvalRequest({ expiresAt: 'not-a-date' })];
+
+ render(() => <ApprovalBanner />);
+
+ expect(screen.getByText('expiry unavailable')).toBeInTheDocument();
+ expect(screen.queryByText(/NaN/)).not.toBeInTheDocument();
+ });
+
+ it('fails closed instead of rendering NaN when a single approval expiry is missing', () => {
+ state.pendingApprovals = [
+ approvalRequest({ expiresAt: undefined } as Partial<ApprovalRequest>),
+ ];
+
+ render(() => <ApprovalBanner />);
+
+ expect(screen.getByText('expiry unavailable')).toBeInTheDocument();
+ expect(screen.queryByText(/NaN/)).not.toBeInTheDocument();
+ });
});
+
+function approvalRequest(overrides: Partial<ApprovalRequest> = {}): ApprovalRequest {
+ return {
+ id: 'approval-single',
+ toolId: 'investigation_fix',
+ command: 'restart service',
+ targetType: 'host',
+ targetId: 'finding-single',
+ targetName: 'node-201',
+ context: 'Single approval',
+ riskLevel: 'high',
+ status: 'pending',
+ requestedAt: '2026-03-01T00:01:00Z',
+ expiresAt: '2026-03-01T00:05:00Z',
+ ...overrides,
+ };
+}
diff --git a/frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts b/frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts
index 825dd1cd61..5f0d85c7b4 100644
--- a/frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/approvalRiskPresentation.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import {
+ getApprovalExpiryStatusLabel,
getApprovalRiskPresentation,
sortPendingApprovalsByUrgency,
} from '@/utils/approvalRiskPresentation';
@@ -90,6 +91,30 @@ describe('approvalRiskPresentation', () => {
'malformed-request',
]);
});
+
+ it('formats valid approval expiry countdowns', () => {
+ expect(
+ getApprovalExpiryStatusLabel('2026-05-07T10:06:00Z', Date.parse('2026-05-07T10:00:00Z')),
+ ).toBe('expires 6m 0s');
+ expect(
+ getApprovalExpiryStatusLabel('2026-05-07T10:00:45Z', Date.parse('2026-05-07T10:00:00Z')),
+ ).toBe('expires 45s');
+ });
+
+ it('formats expired approval expiries without duplicate expiry wording', () => {
+ expect(
+ getApprovalExpiryStatusLabel('2026-05-07T09:59:00Z', Date.parse('2026-05-07T10:00:00Z')),
+ ).toBe('expired');
+ });
+
+ it('fails closed for malformed or missing approval expiry labels', () => {
+ expect(getApprovalExpiryStatusLabel('not-a-date', Date.parse('2026-05-07T10:00:00Z'))).toBe(
+ 'expiry unavailable',
+ );
+ expect(getApprovalExpiryStatusLabel(undefined, Date.parse('2026-05-07T10:00:00Z'))).toBe(
+ 'expiry unavailable',
+ );
+ });
});
function approval(overrides: {
diff --git a/frontend-modern/src/utils/approvalRiskPresentation.ts b/frontend-modern/src/utils/approvalRiskPresentation.ts
index 6d6a64ac24..55435a097c 100644
--- a/frontend-modern/src/utils/approvalRiskPresentation.ts
+++ b/frontend-modern/src/utils/approvalRiskPresentation.ts
@@ -50,9 +50,13 @@ export function getApprovalRiskSortOrder(level?: string): number {
return APPROVAL_RISK_SORT_ORDER[normalized] ?? APPROVAL_RISK_SORT_ORDER.unknown;
}
-function getApprovalTimestampSortValue(value?: string | null): number {
+function parseApprovalTimestamp(value?: string | null): number | null {
const parsed = Date.parse(value ?? '');
- return Number.isFinite(parsed) ? parsed : Number.POSITIVE_INFINITY;
+ return Number.isFinite(parsed) ? parsed : null;
+}
+
+function getApprovalTimestampSortValue(value?: string | null): number {
+ return parseApprovalTimestamp(value) ?? Number.POSITIVE_INFINITY;
}
function compareApprovalTimestamps(a?: string | null, b?: string | null): number {
@@ -76,3 +80,16 @@ export function sortPendingApprovalsByUrgency<
return compareApprovalTimestamps(a.requestedAt, b.requestedAt);
});
}
+
+export function getApprovalExpiryStatusLabel(expiresAt?: string | null, now = Date.now()): string {
+ const expiryTime = parseApprovalTimestamp(expiresAt);
+ if (expiryTime === null) return 'expiry unavailable';
+
+ const diff = expiryTime - now;
+ if (diff <= 0) return 'expired';
+
+ const mins = Math.floor(diff / 60000);
+ const secs = Math.floor((diff % 60000) / 1000);
+ if (mins > 0) return `expires ${mins}m ${secs}s`;
+ return `expires ${secs}s`;
+}