]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(cli): second-pass audit fixes — DRY table helper, remove slop, strengthen...
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 15 Apr 2026 19:23:52 +0000 (21:23 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 15 Apr 2026 19:23:52 +0000 (21:23 +0200)
ui/cli/src/client/lifecycle.ts
ui/cli/src/output/table.ts
ui/cli/tests/ws-adapter.test.ts
ui/common/tests/WebSocketClient.test.ts

index b500f9608128ee732ddcf653c347537600cfa669..343e3238857a9b0b843c40952885348d8f4461ae 100644 (file)
@@ -24,7 +24,7 @@ const createWsFactory = (): WebSocketFactory => {
 }
 
 let activeClient: undefined | WebSocketClient
-let activeSpinner: ReturnType<typeof ora> | undefined
+let activeSpinner: null | ReturnType<typeof ora> | undefined
 let cleanupInProgress = false
 
 export interface ExecuteOptions {
@@ -47,7 +47,7 @@ export const executeCommand = async (options: ExecuteOptions): Promise<void> =>
     ? ora({ stream: process.stderr }).start(`Connecting to ${url}`)
     : null
 
-  activeSpinner = spinner ?? undefined
+  activeSpinner = spinner
   activeClient = client
 
   const budget = timeoutMs ?? UI_WEBSOCKET_REQUEST_TIMEOUT_MS
index b6392a9910de09df7b7af09b17fb81610c141ac2..4ba1f353656135545e6401826b3022c463bcf981 100644 (file)
@@ -3,13 +3,18 @@ import Table from 'cli-table3'
 import process from 'node:process'
 import { type ResponsePayload, ResponseStatus } from 'ui-common'
 
+const hashIdTable = (ids: string[]) => {
+  const table = new Table({ head: [chalk.white('Hash ID')] })
+  for (const id of ids) {
+    table.push([id])
+  }
+  return table
+}
+
 export const outputTable = (payload: ResponsePayload): void => {
   if (payload.hashIdsSucceeded != null && payload.hashIdsSucceeded.length > 0) {
     process.stdout.write(chalk.green(`✓ Succeeded (${String(payload.hashIdsSucceeded.length)}):\n`))
-    const table = new Table({ head: [chalk.white('Hash ID')] })
-    for (const id of payload.hashIdsSucceeded) {
-      table.push([id])
-    }
+    const table = hashIdTable(payload.hashIdsSucceeded)
     process.stdout.write(table.toString() + '\n')
   }
 
@@ -22,10 +27,7 @@ export const outputTable = (payload: ResponsePayload): void => {
       }
       process.stderr.write(table.toString() + '\n')
     } else {
-      const table = new Table({ head: [chalk.white('Hash ID')] })
-      for (const id of payload.hashIdsFailed) {
-        table.push([id])
-      }
+      const table = hashIdTable(payload.hashIdsFailed)
       process.stderr.write(table.toString() + '\n')
     }
   }
index c33ace9827e4f746f34464a02f70b342fe8a10f4..1e50e91fa4d746208dc68027ddac965820734a03 100644 (file)
@@ -217,11 +217,7 @@ await describe('WS Adapter', async () => {
 
     const adapter = createWsAdapter(mockWs as unknown as WebSocket)
 
-    const callback = (event: { data: string }): undefined => {
-      // eslint-disable-next-line no-void
-      void event
-      return undefined
-    }
+    const callback = (event: { data: string }): undefined => undefined
     adapter.onmessage = callback
     assert.strictEqual(adapter.onmessage, callback)
 
@@ -234,11 +230,7 @@ await describe('WS Adapter', async () => {
 
     const adapter = createWsAdapter(mockWs as unknown as WebSocket)
 
-    const callback = (event: { error: unknown; message: string }): undefined => {
-      // eslint-disable-next-line no-void
-      void event
-      return undefined
-    }
+    const callback = (_event: { error: unknown; message: string }): undefined => undefined
     adapter.onerror = callback
     assert.strictEqual(adapter.onerror, callback)
 
@@ -251,11 +243,7 @@ await describe('WS Adapter', async () => {
 
     const adapter = createWsAdapter(mockWs as unknown as WebSocket)
 
-    const callback = (event: { code: number; reason: string }): undefined => {
-      // eslint-disable-next-line no-void
-      void event
-      return undefined
-    }
+    const callback = (_event: { code: number; reason: string }): undefined => undefined
     adapter.onclose = callback
     assert.strictEqual(adapter.onclose, callback)
 
index 971a89841e489cb094b4fb3ef97d851c0e9cbc26..ec9422c19d99670d5fc305af9de0fc5eefa7a536 100644 (file)
@@ -416,6 +416,7 @@ await describe('WebSocketClient', async () => {
       (error: unknown) => {
         assert.ok(error instanceof Error)
         assert.ok(error.message.includes('Invalid timeout'))
+        assert.ok(error.message.includes('0ms'))
         return true
       }
     )
@@ -444,6 +445,7 @@ await describe('WebSocketClient', async () => {
       (error: unknown) => {
         assert.ok(error instanceof Error)
         assert.ok(error.message.includes('Invalid timeout'))
+        assert.ok(error.message.includes('-1ms'))
         return true
       }
     )