Skip to content

Commit c59ecd0

Browse files
Michał Fąferekmfaferek93
authored andcommitted
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
1 parent 3af00be commit c59ecd0

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/lib/transforms.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ describe('transformFault', () => {
112112
describe('entity_id extraction from reporting_sources', () => {
113113
it('extracts last segment of node path', () => {
114114
const result = transformFault(makeFaultInput({ reporting_sources: ['/powertrain/engine_monitor'] }));
115-
expect(result.entity_id).toBe('engine-monitor');
115+
expect(result.entity_id).toBe('engine_monitor');
116116
});
117117

118-
it('converts underscores to hyphens in entity_id', () => {
118+
it('preserves underscores in entity_id', () => {
119119
const result = transformFault(makeFaultInput({ reporting_sources: ['/ns/my_node_name'] }));
120-
expect(result.entity_id).toBe('my-node-name');
120+
expect(result.entity_id).toBe('my_node_name');
121121
});
122122

123123
it('uses "unknown" when reporting_sources is empty', () => {

src/lib/transforms.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export interface RawFaultItem {
8383
* - `severity` (number) + `severity_label` → `severity` (string)
8484
* - `status` (CONFIRMED / PREFAILED / ...) → `status` (active / pending / cleared / healed)
8585
* - `first_occurred` (unix seconds) → `timestamp` (ISO 8601)
86-
* - `reporting_sources[0]` last path segment → `entity_id` (underscores replaced by hyphens)
86+
* - `reporting_sources[0]` last path segment → `entity_id`
8787
*/
8888
export function transformFault(apiFault: RawFaultItem): Fault {
8989
// Map severity number/label to FaultSeverity.
@@ -113,11 +113,9 @@ export function transformFault(apiFault: RawFaultItem): Fault {
113113

114114
// Extract entity info from reporting_sources.
115115
// reporting_sources contains ROS 2 node paths like "/bridge/diagnostic_bridge".
116-
// We take the last segment and convert underscores to hyphens to match
117-
// the SOVD app ID convention (e.g., "diagnostic_bridge" → "diagnostic-bridge").
116+
// We take the last segment as entity_id (preserving underscores - they match SOVD IDs).
118117
const source = apiFault.reporting_sources?.[0] || '';
119-
const nodeName = source.split('/').pop() || 'unknown';
120-
const entity_id = nodeName.replace(/_/g, '-');
118+
const entity_id = source.split('/').pop() || 'unknown';
121119

122120
// Use entity_type from raw data if provided, otherwise default to 'app'.
123121
// The gateway's fault_to_json does not currently include entity_type, but

0 commit comments

Comments
 (0)