From c61141439920995fd3cf9e4ab8a46629fda627fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 15 Apr 2026 21:23:52 +0200 Subject: [PATCH] =?utf8?q?refactor(cli):=20second-pass=20audit=20fixes=20?= =?utf8?q?=E2=80=94=20DRY=20table=20helper,=20remove=20slop,=20strengthen?= =?utf8?q?=20assertions?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ui/cli/src/client/lifecycle.ts | 4 ++-- ui/cli/src/output/table.ts | 18 ++++++++++-------- ui/cli/tests/ws-adapter.test.ts | 18 +++--------------- ui/common/tests/WebSocketClient.test.ts | 2 ++ 4 files changed, 17 insertions(+), 25 deletions(-) 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 } ) -- 2.53.0