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.

Remove dead frontend policy normalization

rcourtman028b620e80d1
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 9d97a9ecff..68037499db 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -271,14 +271,10 @@ that route through `frontend-modern/src/hooks/useUnifiedResources.ts` must
preserve canonical `policy` and `aiSafeSummary` fields so storage-bearing
resources do not silently lose their routing or redaction posture when they
cross from unified-resource ownership into storage or recovery presentation.
-That same decode path also trims `aiSafeSummary` through the shared policy
-normalizer, so storage and recovery surfaces keep the canonical summary text
-aligned with the policy-aware resource contract instead of reformatting it
-locally.
-That same decode path now delegates policy string and redaction normalization
-to `frontend-modern/src/utils/resourcePolicyNormalization.ts`, so storage and
-recovery surfaces do not reimplement sensitivity, routing, or redaction
-parsing locally.
+That same decode path now trusts the backend canonical `policy` and
+`aiSafeSummary` values directly, so storage and recovery surfaces keep the
+canonical summary text aligned with the policy-aware resource contract
+instead of reformatting or re-normalizing it locally.
That same shared `internal/api/` dependency now also routes resource-timeline
filters through the unified-resource change parser, so storage and recovery
surfaces do not inherit a second local decoder for `kind`, `sourceType`, or
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index 8fac7c14c0..f1ac37901e 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -78,7 +78,6 @@ import aiChatSource from '@/components/AI/Chat/index.tsx?raw';
import patrolStatusBarSource from '@/components/patrol/PatrolStatusBar.tsx?raw';
import patrolFormatSource from '@/utils/patrolFormat.ts?raw';
import aiFindingPresentationSource from '@/utils/aiFindingPresentation.ts?raw';
-import resourcePolicyNormalizationSource from '@/utils/resourcePolicyNormalization.ts?raw';
import diskListSource from '@/components/Storage/DiskList.tsx?raw';
import useDiskListModelSource from '@/components/Storage/useDiskListModel.ts?raw';
import diskDetailSource from '@/components/Storage/DiskDetail.tsx?raw';
@@ -1906,9 +1905,6 @@ describe('frontend resource type boundaries', () => {
expect(patrolRunPresentationSource).not.toContain("normalized.replace(/_/g, ' ')");
expect(patrolRunPresentationSource).not.toContain("normalized ? normalized.replace(/_/g, ' ') : 'unknown'");
expect(useUnifiedResourcesSource).not.toContain('normalizeResourcePolicyAISafeSummary(');
- expect(resourcePolicyNormalizationSource).toContain(
- 'normalizeResourcePolicyAISafeSummary',
- );
expect(useUnifiedResourcesSource).not.toContain('normalizeResourcePolicy(');
expect(useUnifiedResourcesSource).not.toContain('const resolvePolicySensitivity =');
expect(useUnifiedResourcesSource).not.toContain('const resolvePolicyRoutingScope =');
diff --git a/frontend-modern/src/utils/__tests__/resourcePolicyNormalization.test.ts b/frontend-modern/src/utils/__tests__/resourcePolicyNormalization.test.ts
deleted file mode 100644
index ad9bfbfc10..0000000000
--- a/frontend-modern/src/utils/__tests__/resourcePolicyNormalization.test.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { describe, expect, it } from 'vitest';
-
-import {
- normalizeResourcePolicyAISafeSummary,
- normalizeResourcePolicy,
- normalizeResourcePolicyRedactionHints,
- normalizeResourcePolicyRoutingScope,
- normalizeResourcePolicySensitivity,
-} from '../resourcePolicyNormalization';
-
-describe('resourcePolicyNormalization', () => {
- it('normalizes canonical policy fields from mixed-case API payloads', () => {
- expect(normalizeResourcePolicySensitivity(' PUBLIC ')).toBe('public');
- expect(normalizeResourcePolicyRoutingScope('LOCAL-FIRST')).toBe('local-first');
- expect(
- normalizeResourcePolicyRedactionHints(['HOSTNAME', ' ip-address ', 'platform-id']),
- ).toEqual(['hostname', 'ip-address', 'platform-id']);
-
- expect(
- normalizeResourcePolicy({
- sensitivity: 'restricted',
- routing: {
- scope: 'Local-Only',
- allowCloudSummary: true,
- allowCloudRawSignals: false,
- redact: ['alias', 'PATH'],
- },
- }),
- ).toEqual({
- sensitivity: 'restricted',
- routing: {
- scope: 'local-only',
- allowCloudSummary: true,
- allowCloudRawSignals: false,
- redact: ['alias', 'path'],
- },
- });
- });
-
- it('rejects incomplete policy payloads', () => {
- expect(normalizeResourcePolicySensitivity(undefined)).toBeUndefined();
- expect(normalizeResourcePolicyRoutingScope('')).toBeUndefined();
- expect(normalizeResourcePolicyRedactionHints([])).toBeUndefined();
- expect(normalizeResourcePolicy({ sensitivity: 'internal' })).toBeUndefined();
- });
-
- it('normalizes aiSafeSummary to a trimmed string', () => {
- expect(normalizeResourcePolicyAISafeSummary(' safe summary ')).toBe('safe summary');
- expect(normalizeResourcePolicyAISafeSummary(' ')).toBeUndefined();
- expect(normalizeResourcePolicyAISafeSummary(undefined)).toBeUndefined();
- });
-});
diff --git a/frontend-modern/src/utils/resourcePolicyNormalization.ts b/frontend-modern/src/utils/resourcePolicyNormalization.ts
deleted file mode 100644
index a4382a59b1..0000000000
--- a/frontend-modern/src/utils/resourcePolicyNormalization.ts
+++ /dev/null
@@ -1,95 +0,0 @@
-import type {
- ResourcePolicy,
- ResourceRedactionHint,
- ResourceRoutingScope,
- ResourceSensitivity,
-} from '@/types/resource';
-
-const asTrimmedLower = (value: unknown): string => {
- if (typeof value !== 'string') return '';
- return value.trim().toLowerCase();
-};
-
-export const normalizeResourcePolicySensitivity = (
- value?: unknown,
-): ResourceSensitivity | undefined => {
- switch (asTrimmedLower(value)) {
- case 'public':
- return 'public';
- case 'internal':
- return 'internal';
- case 'sensitive':
- return 'sensitive';
- case 'restricted':
- return 'restricted';
- default:
- return undefined;
- }
-};
-
-export const normalizeResourcePolicyRoutingScope = (
- value?: unknown,
-): ResourceRoutingScope | undefined => {
- switch (asTrimmedLower(value)) {
- case 'cloud-summary':
- return 'cloud-summary';
- case 'local-first':
- return 'local-first';
- case 'local-only':
- return 'local-only';
- default:
- return undefined;
- }
-};
-
-export const normalizeResourcePolicyRedactionHints = (
- value: unknown,
-): ResourceRedactionHint[] | undefined => {
- if (!Array.isArray(value)) return undefined;
- const hints = value.flatMap((entry) => {
- switch (asTrimmedLower(entry)) {
- case 'hostname':
- return 'hostname';
- case 'ip-address':
- return 'ip-address';
- case 'platform-id':
- return 'platform-id';
- case 'alias':
- return 'alias';
- case 'path':
- return 'path';
- default:
- return [];
- }
- });
- return hints.length > 0 ? hints : undefined;
-};
-
-export const normalizeResourcePolicyAISafeSummary = (value?: unknown): string | undefined => {
- if (typeof value !== 'string') return undefined;
- const trimmed = value.trim();
- return trimmed ? trimmed : undefined;
-};
-
-export const normalizeResourcePolicy = (policy?: {
- sensitivity?: unknown;
- routing?: {
- scope?: unknown;
- allowCloudSummary?: boolean;
- allowCloudRawSignals?: boolean;
- redact?: unknown;
- };
-}): ResourcePolicy | undefined => {
- const sensitivity = normalizeResourcePolicySensitivity(policy?.sensitivity);
- const scope = normalizeResourcePolicyRoutingScope(policy?.routing?.scope);
- if (!sensitivity || !scope) return undefined;
- return {
- sensitivity,
- routing: {
- scope,
- allowCloudSummary: policy?.routing?.allowCloudSummary === true,
- allowCloudRawSignals: policy?.routing?.allowCloudRawSignals === true,
- redact: normalizeResourcePolicyRedactionHints(policy?.routing?.redact),
- },
- };
-};