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.

Keep resource-change boundary checks compatible with close metadata

pulse-triage[bot]c6c7babd505e
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index dd056e05e3..871862305e 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from 'vitest';
+import ts from 'typescript';
import appSource from '@/App.tsx?raw';
import resourceTypeCompatSource from '@/utils/resourceTypeCompat.ts?raw';
import discoveryTypesSource from '@/types/discovery.ts?raw';
@@ -513,6 +514,55 @@ const resourceDetailDrawerSource = [
resourceDetailDrawerStateSource,
].join('\n');
+// Assert the shared boundary, not a retired helper spelling. Once the adapter
+// supports close metadata, timeline consumers must use it: kind-only labels can
+// incorrectly describe a moved alert as recovered (PR #2607).
+function usesSharedChangePresentation(consumer: string, adapter: string): boolean {
+ const parse = (source: string) =>
+ ts.createSourceFile('boundary.tsx', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
+ const metadataAware = parse(adapter).statements.some(
+ (node) =>
+ ts.isFunctionDeclaration(node) &&
+ node.name?.text === 'getResourceChangePresentation' &&
+ node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword),
+ );
+ const required = metadataAware
+ ? 'getResourceChangePresentation'
+ : 'getResourceChangeKindPresentation';
+ const tree = parse(consumer);
+ const bindings = new Set<string>();
+ for (const node of tree.statements) {
+ if (
+ !ts.isImportDeclaration(node) ||
+ !ts.isStringLiteral(node.moduleSpecifier) ||
+ node.moduleSpecifier.text !== '@/utils/resourceChangePresentation' ||
+ node.importClause?.isTypeOnly
+ ) continue;
+ const imports = node.importClause?.namedBindings;
+ if (!imports || !ts.isNamedImports(imports)) continue;
+ for (const item of imports.elements) {
+ if (!item.isTypeOnly && (item.propertyName ?? item.name).text === required) {
+ bindings.add(item.name.text);
+ }
+ }
+ }
+ let called = false;
+ const visit = (node: ts.Node) => {
+ if (
+ ts.isCallExpression(node) &&
+ ts.isIdentifier(node.expression) &&
+ bindings.has(node.expression.text) &&
+ node.arguments.length > 0 &&
+ // The metadata-aware adapter needs the change, not just its kind.
+ !(metadataAware && ts.isPropertyAccessExpression(node.arguments[0]) &&
+ node.arguments[0].name.text === 'kind')
+ ) called = true;
+ ts.forEachChild(node, visit);
+ };
+ visit(tree);
+ return called;
+}
+
describe('frontend resource type boundaries', () => {
it('keeps the shared compatibility adapter narrow and explicit', () => {
expect(resourceTypeCompatSource).toContain('export const canonicalizeFrontendResourceType');
@@ -2140,10 +2190,10 @@ describe('frontend resource type boundaries', () => {
expect(resourceDetailDrawerSource).toContain('RESOURCE_CHANGE_KIND_ORDER');
expect(resourceDetailDrawerSource).toContain('RESOURCE_CHANGE_SOURCE_TYPE_ORDER');
expect(resourceDetailDrawerSource).toContain('RESOURCE_CHANGE_SOURCE_ADAPTER_ORDER');
- expect(resourceDetailDrawerSource).toContain('getResourceChangeKindPresentation');
+ expect(usesSharedChangePresentation(resourceDetailDrawerOverviewSource, resourceChangePresentationSource)).toBe(true);
expect(resourceDetailDrawerSource).toContain('getResourceChangeSourceTypePresentation');
expect(resourceDetailDrawerSource).toContain('getResourceChangeSourceAdapterPresentation');
- expect(resourceChangeSummarySource).toContain('getResourceChangeKindPresentation');
+ expect(usesSharedChangePresentation(resourceChangeSummarySource, resourceChangePresentationSource)).toBe(true);
expect(resourceChangeSummarySource).toContain('getResourceChangeSourceTypePresentation');
expect(resourceChangeSummarySource).toContain('getResourceChangeSourceAdapterPresentation');
expect(resourceDetailDrawerSource).not.toContain('healthToneClass(');
@@ -4354,3 +4404,34 @@ describe('frontend resource type boundaries', () => {
expect(alertWebhookPresentationSource).toContain('export function getAlertWebhookSubmitLabel');
});
});
+
+
+describe('shared resource change presentation boundary controls', () => {
+ const kindAdapter = 'export function getResourceChangeKindPresentation(kind) {}';
+ const metadataAdapter = `${kindAdapter}\nexport function getResourceChangePresentation(change) {}`;
+ const consumer = (name: string, argument = 'change') =>
+ `import { ${name} } from '@/utils/resourceChangePresentation'; ${name}(${argument});`;
+
+ it('accepts the kind adapter before the metadata-aware API exists', () => {
+ expect(usesSharedChangePresentation(consumer('getResourceChangeKindPresentation', 'change.kind'), kindAdapter)).toBe(true);
+ });
+
+ it('requires the whole-change adapter once available, even if the old helper still exists', () => {
+ expect(usesSharedChangePresentation(consumer('getResourceChangePresentation'), metadataAdapter)).toBe(true);
+ expect(usesSharedChangePresentation(consumer('getResourceChangeKindPresentation', 'change.kind'), metadataAdapter)).toBe(false);
+ expect(usesSharedChangePresentation(consumer('getResourceChangePresentation', 'change.kind'), metadataAdapter)).toBe(false);
+ });
+
+ it('resolves named import aliases without accepting an inline lookalike', () => {
+ expect(usesSharedChangePresentation("import { getResourceChangePresentation as present } from '@/utils/resourceChangePresentation'; present(change);", metadataAdapter)).toBe(true);
+ expect(usesSharedChangePresentation('function getResourceChangePresentation(change) {} getResourceChangePresentation(change);', metadataAdapter)).toBe(false);
+ expect(usesSharedChangePresentation(consumer('getResourceChangePresentation').replace("@/utils/resourceChangePresentation", '@/utils/localCopy'), metadataAdapter)).toBe(false);
+ });
+
+ it('rejects comment-only, unused and type-only imports', () => {
+ expect(usesSharedChangePresentation('// ' + consumer('getResourceChangePresentation'), metadataAdapter)).toBe(false);
+ expect(usesSharedChangePresentation("import { getResourceChangePresentation } from '@/utils/resourceChangePresentation';", metadataAdapter)).toBe(false);
+ expect(usesSharedChangePresentation(consumer('getResourceChangePresentation').replace('import {', 'import type {'), metadataAdapter)).toBe(false);
+ expect(usesSharedChangePresentation(consumer('getResourceChangePresentation').replace('{ getResource', '{ type getResource'), metadataAdapter)).toBe(false);
+ });
+});