Files
adam-acs/app/utils/cwmp-events.ts
T
Kevin L'HereecandContinue aad93911e4 feat: TR-069 CWMP state machine hardening + exchange viewer improvements
- TR-069 CWMP state machine hardening (14 phases): shared event utility,
  multi-event routing, GPN circuit breaker, IdleState GPN guard, expanded
  GPN fault codes, CriticalReadsState, ConfigEval GPN guard, task queue
  race condition fix, explicit error handling, terminal states
  (OperationalState/PartialOperationalState), consolidated reclassify,
  crash pattern detection, removed enqueueImmediate, state flow wiring
- Fix SOAP Fault not processed by state machine (soap-env:Fault detection)
- Fix GPN circuit breaker not persisting after session drops
- Fix CriticalReadsState GPV response parsing (xsi:type normalization)
- Fix CriticalReadsState not processing GPV response values
- Skip SPV when device is already compliant (ProvisioningCode check)
- Add Device.DeviceInfo.ModelName to critical reads GPV
- Fix TypeError on DeviceDetail parameters view (null guards)
- Log empty 204 responses in exchange trace UI
- TR-181 catalog: type corrections and new entries (+6640 lines)
- SequenceViewer: replace session-nav buttons with compact dropdown select
- SequenceViewer: fix CPE/ACS lifeline headers wrapping to 2 lines
- Add 20 unit tests for state machine fixes (SOAP Fault, GPN circuit
  breaker, CriticalReads, stale session, ConfigEval/ComplianceUpdate skips)

Generated with [Continue](https://continue.dev)

Co-Authored-By: Continue <noreply@continue.dev>
2026-06-08 12:49:00 +00:00

68 lines
1.9 KiB
TypeScript

/**
* Shared CWMP event normalization and priority resolution utilities.
* Single source of truth for event code handling (fixes MINEUR-9).
*/
export const EVENT_PRIORITY: Record<string, number> = {
'BOOTSTRAP': 100,
'BOOT': 90,
'CONNECTION REQUEST': 80,
'PERIODIC': 70,
'VALUE CHANGE': 60,
'DIAGNOSTICS COMPLETE': 50,
'TRANSFER COMPLETE': 40,
'SCHEDULE': 30,
}
/**
* Normalize an EventCode from an Inform message.
* Strips numeric prefix and normalizes the label.
* Examples: '0 BOOTSTRAP' → 'BOOTSTRAP', '1 BOOT' → 'BOOT', '6' → 'CONNECTION REQUEST'
*/
export function normalizeEventCode(raw: string): string {
const trimmed = raw.trim().toUpperCase()
// Already a known label without numeric prefix
if (EVENT_PRIORITY[trimmed] !== undefined) return trimmed
// Full format like "0 BOOTSTRAP" → strip numeric prefix
const match = trimmed.match(/^\d+\s+(.+)$/)
if (match) return match[1]
// Numeric-only → expand to standard label
switch (trimmed) {
case '0': return 'BOOTSTRAP'
case '1': return 'BOOT'
case '2': return 'PERIODIC'
case '3': return 'SCHEDULED'
case '4': return 'VALUE CHANGE'
case '5': return 'KICKED'
case '6': return 'CONNECTION REQUEST'
case '7': return 'TRANSFER COMPLETE'
case '8': return 'DIAGNOSTICS COMPLETE'
default: return trimmed
}
}
/**
* Resolve the highest priority event from a list of raw event codes.
* Returns the normalized name of the highest-priority event.
*/
export function resolveHighestPriorityEvent(events: string[]): string {
if (events.length === 0) return ''
let highest = ''
let highestPriority = -1
for (const raw of events) {
const normalized = normalizeEventCode(raw)
const priority = EVENT_PRIORITY[normalized] ?? 0
if (priority > highestPriority) {
highestPriority = priority
highest = normalized
}
}
return highest
}