This commit is contained in:
Kevin L'Hereec committed 2026-06-08 15:15:24 +02:00
1 parent ca24b469d3
commit b0a3f52df7
2 files changed
+20 -23

No files matched your search

@@ -49,24 +49,18 @@ describe('DeviceActionExecutor — coverage', () => {
it('getParameterValues wrappedCallback updates device on success', async () => {
const device = makeDevice()
let capturedCallback: any
const origAddTask = taskQueue.addTask.bind(taskQueue)
vi.spyOn(taskQueue, 'addTask').mockImplementation((deviceId, type, props, cb) => {
capturedCallback = cb
return origAddTask(deviceId, type, props, cb)
})
await executor.getParameterValues(device, ['Device.Info.SW'], async () => '')
// Execute the wrapped callback with success
await capturedCallback({
status: ResultStatus.Success,
data: {
ParameterList: {
ParameterValueStruct: [
{ Name: 'Device.Info.SW', Value: { _: '5.0.1', $: { Type: 'xsd:string' } } },
],
},
// Execute the callback directly via executeTaskCallback
const taskCallbacks = (taskQueue as any).taskCallbacks as Map<string, any>
const taskId = Array.from(taskCallbacks.keys())[0]
expect(taskId).toBeDefined()
await taskQueue.executeTaskCallback(taskId!, ResultStatus.Success, {
ParameterList: {
ParameterValueStruct: [
{ Name: 'Device.Info.SW', Value: { _: '5.0.1', $: { Type: 'xsd:string' } } },
],
},
})
@@ -74,8 +68,6 @@ describe('DeviceActionExecutor — coverage', () => {
const prop = device.getProperty('Device.Info.SW')
expect(prop).not.toBeNull()
expect(prop!.value).toBe('5.0.1')
// Should have persisted
expect(mockCreateOrUpdate).toHaveBeenCalled()
})
// --- getParameterNames ---
@@ -81,15 +81,15 @@ describe('StateMachineManager — coverage', () => {
expect(machine.stateMachine.getCurrentStateName()).toBe('idle')
})
it('preempts ImmediateCommandStateMachine on BOOT event', async () => {
it('preempts ImmediateCommandStateMachine on BOOT event with same session', async () => {
const device = makeDevice()
// First: create ImmediateCommandStateMachine
const machine1 = await manager.startStateMachine(device, 'sess-5', { events: ['6 CONNECTION REQUEST'] })
expect(machine1.stateMachine.getCurrentStateName()).toBe('executing-commands')
// Second: BOOT event arrives on same session
// Second: BOOT event arrives on same session (same TCP connection, new Inform)
const machine2 = await manager.startStateMachine(device, 'sess-5', { events: ['1 BOOT'] })
// Should have preempted to MainStateMachine
// Should have preempted to MainStateMachine (same machine instance, new state machine inside)
expect(machine2.stateMachine.getCurrentStateName()).toBe('idle')
})
@@ -183,12 +183,17 @@ describe('StateMachineManager — coverage', () => {
it('cleanupCompletedMachines removes old completed machines', async () => {
const device = makeDevice()
const machine = await manager.startStateMachine(device, 'sess-11', { events: ['0 BOOTSTRAP'] })
// Force complete
// Force complete and set old completion date
;(machine as any).status = MachineStatus.COMPLETED
;(machine as any).completedAt = new Date(Date.now() - 2 * 60 * 60 * 1000) // 2h ago
// Verify machine exists in internal map before cleanup
const machinesMap = (manager as any).machines as Map<string, any>
expect(machinesMap.has(machine.id)).toBe(true)
manager.cleanupCompletedMachines(1)
// Machine should be removed from internal map
expect(manager.hasSession('sess-11')).toBe(false)
expect(machinesMap.has(machine.id)).toBe(false)
})
})