Files
adam-acs/app/services/cwmp/immediate_command_state_machine.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

65 lines
1.9 KiB
TypeScript

import { Device } from '../../domain/device/device.js'
import { CWMPTaskQueue } from './task_queue.js'
import { DeviceActionExecutor } from './device_action_executor.js'
import { ExecutingCommandsState, DeviceContext, DeviceStateResult } from './main_state_machine.js'
import logger from '@adonisjs/core/services/logger'
/**
* State machine for "6 CONNECTION REQUEST" events.
* Only executes pending Immediate (I) commands - does NOT include NI commands.
*/
export class ImmediateCommandStateMachine {
private currentState: ExecutingCommandsState
private context: DeviceContext
constructor(device: Device, session: string, taskQueue: CWMPTaskQueue) {
// includeNI = false: only execute Immediate commands
this.currentState = new ExecutingCommandsState(false)
this.context = {
device,
session,
taskQueue,
services: {
deviceAction: new DeviceActionExecutor(taskQueue),
},
}
}
async start(): Promise<string> {
logger.info(`Starting immediate-command state machine for device ${this.context.device.deviceId?.serialNumber}`)
return this.execute()
}
async handleResponse(success: boolean, message: any): Promise<string> {
this.context.message = { success, data: message }
return this.execute()
}
getCurrentStateName(): string {
return this.currentState.name
}
isCompleted(): boolean {
return this.currentState.name === 'completed' || this.currentState.name === 'operational' || this.currentState.name === 'partial_operational'
}
private async execute(): Promise<string> {
try {
const result: DeviceStateResult = await this.currentState.handle(this.context)
if (result.isComplete) {
return ''
}
if (result.response && result.response !== '') {
return result.response
}
return ''
} catch (error) {
logger.error(`Immediate-command state machine error: ${error}`)
return ''
}
}
}