From: Jérôme Benoit Date: Wed, 15 Apr 2026 19:23:52 +0000 (+0200) Subject: refactor(cli): second-pass audit fixes — DRY table helper, remove slop, strengthen... X-Git-Tag: cli@v4.5.0~88 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c61141439920995fd3cf9e4ab8a46629fda627fa;p=e-mobility-charging-stations-simulator.git refactor(cli): second-pass audit fixes — DRY table helper, remove slop, strengthen assertions --- diff --git a/ui/cli/src/client/lifecycle.ts b/ui/cli/src/client/lifecycle.ts index b500f960..343e3238 100644 --- a/ui/cli/src/client/lifecycle.ts +++ b/ui/cli/src/client/lifecycle.ts @@ -24,7 +24,7 @@ const createWsFactory = (): WebSocketFactory => { } let activeClient: undefined | WebSocketClient -let activeSpinner: ReturnType | undefined +let activeSpinner: null | ReturnType | undefined let cleanupInProgress = false export interface ExecuteOptions { @@ -47,7 +47,7 @@ export const executeCommand = async (options: ExecuteOptions): Promise => ? ora({ stream: process.stderr }).start(`Connecting to ${url}`) : null - activeSpinner = spinner ?? undefined + activeSpinner = spinner activeClient = client const budget = timeoutMs ?? UI_WEBSOCKET_REQUEST_TIMEOUT_MS diff --git a/ui/cli/src/output/table.ts b/ui/cli/src/output/table.ts index b6392a99..4ba1f353 100644 --- a/ui/cli/src/output/table.ts +++ b/ui/cli/src/output/table.ts @@ -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') } } diff --git a/ui/cli/tests/ws-adapter.test.ts b/ui/cli/tests/ws-adapter.test.ts index c33ace98..1e50e91f 100644 --- a/ui/cli/tests/ws-adapter.test.ts +++ b/ui/cli/tests/ws-adapter.test.ts @@ -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) diff --git a/ui/common/tests/WebSocketClient.test.ts b/ui/common/tests/WebSocketClient.test.ts index 971a8984..ec9422c1 100644 --- a/ui/common/tests/WebSocketClient.test.ts +++ b/ui/common/tests/WebSocketClient.test.ts @@ -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 } )