From d7779748ab68582eb32d800ae7eca1db9d40296d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20F=C4=85ferek?= Date: Thu, 2 Apr 2026 22:06:34 +0200 Subject: [PATCH] fix: preserve underscores in fault entity_id from reporting_sources transformFault() was replacing underscores with hyphens in entity_id (e.g., tank_process -> tank-process). This broke fault detail fetching because the actual SOVD entity ID uses underscores. Remove the replace(/_/g, '-') call. ROS 2 node names use underscores and gateway SOVD IDs preserve them. Fixes #55 --- src/lib/transforms.test.ts | 6 +++--- src/lib/transforms.ts | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib/transforms.test.ts b/src/lib/transforms.test.ts index 364fe4f..3d9de3b 100644 --- a/src/lib/transforms.test.ts +++ b/src/lib/transforms.test.ts @@ -112,12 +112,12 @@ describe('transformFault', () => { describe('entity_id extraction from reporting_sources', () => { it('extracts last segment of node path', () => { const result = transformFault(makeFaultInput({ reporting_sources: ['/powertrain/engine_monitor'] })); - expect(result.entity_id).toBe('engine-monitor'); + expect(result.entity_id).toBe('engine_monitor'); }); - it('converts underscores to hyphens in entity_id', () => { + it('preserves underscores in entity_id', () => { const result = transformFault(makeFaultInput({ reporting_sources: ['/ns/my_node_name'] })); - expect(result.entity_id).toBe('my-node-name'); + expect(result.entity_id).toBe('my_node_name'); }); it('uses "unknown" when reporting_sources is empty', () => { diff --git a/src/lib/transforms.ts b/src/lib/transforms.ts index 34f8109..152ee86 100644 --- a/src/lib/transforms.ts +++ b/src/lib/transforms.ts @@ -83,7 +83,7 @@ export interface RawFaultItem { * - `severity` (number) + `severity_label` → `severity` (string) * - `status` (CONFIRMED / PREFAILED / ...) → `status` (active / pending / cleared / healed) * - `first_occurred` (unix seconds) → `timestamp` (ISO 8601) - * - `reporting_sources[0]` last path segment → `entity_id` (underscores replaced by hyphens) + * - `reporting_sources[0]` last path segment → `entity_id` */ export function transformFault(apiFault: RawFaultItem): Fault { // Map severity number/label to FaultSeverity. @@ -113,11 +113,9 @@ export function transformFault(apiFault: RawFaultItem): Fault { // Extract entity info from reporting_sources. // reporting_sources contains ROS 2 node paths like "/bridge/diagnostic_bridge". - // We take the last segment and convert underscores to hyphens to match - // the SOVD app ID convention (e.g., "diagnostic_bridge" → "diagnostic-bridge"). + // We take the last segment as entity_id (preserving underscores - they match SOVD IDs). const source = apiFault.reporting_sources?.[0] || ''; - const nodeName = source.split('/').pop() || 'unknown'; - const entity_id = nodeName.replace(/_/g, '-'); + const entity_id = source.split('/').pop() || 'unknown'; // Use entity_type from raw data if provided, otherwise default to 'app'. // The gateway's fault_to_json does not currently include entity_type, but