Skip to content

Commit c611414

Browse files
committed
refactor(cli): second-pass audit fixes — DRY table helper, remove slop, strengthen assertions
1 parent dfb70ff commit c611414

4 files changed

Lines changed: 17 additions & 25 deletions

File tree

ui/cli/src/client/lifecycle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const createWsFactory = (): WebSocketFactory => {
2424
}
2525

2626
let activeClient: undefined | WebSocketClient
27-
let activeSpinner: ReturnType<typeof ora> | undefined
27+
let activeSpinner: null | ReturnType<typeof ora> | undefined
2828
let cleanupInProgress = false
2929

3030
export interface ExecuteOptions {
@@ -47,7 +47,7 @@ export const executeCommand = async (options: ExecuteOptions): Promise<void> =>
4747
? ora({ stream: process.stderr }).start(`Connecting to ${url}`)
4848
: null
4949

50-
activeSpinner = spinner ?? undefined
50+
activeSpinner = spinner
5151
activeClient = client
5252

5353
const budget = timeoutMs ?? UI_WEBSOCKET_REQUEST_TIMEOUT_MS

ui/cli/src/output/table.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import Table from 'cli-table3'
33
import process from 'node:process'
44
import { type ResponsePayload, ResponseStatus } from 'ui-common'
55

6+
const hashIdTable = (ids: string[]) => {
7+
const table = new Table({ head: [chalk.white('Hash ID')] })
8+
for (const id of ids) {
9+
table.push([id])
10+
}
11+
return table
12+
}
13+
614
export const outputTable = (payload: ResponsePayload): void => {
715
if (payload.hashIdsSucceeded != null && payload.hashIdsSucceeded.length > 0) {
816
process.stdout.write(chalk.green(`✓ Succeeded (${String(payload.hashIdsSucceeded.length)}):\n`))
9-
const table = new Table({ head: [chalk.white('Hash ID')] })
10-
for (const id of payload.hashIdsSucceeded) {
11-
table.push([id])
12-
}
17+
const table = hashIdTable(payload.hashIdsSucceeded)
1318
process.stdout.write(table.toString() + '\n')
1419
}
1520

@@ -22,10 +27,7 @@ export const outputTable = (payload: ResponsePayload): void => {
2227
}
2328
process.stderr.write(table.toString() + '\n')
2429
} else {
25-
const table = new Table({ head: [chalk.white('Hash ID')] })
26-
for (const id of payload.hashIdsFailed) {
27-
table.push([id])
28-
}
30+
const table = hashIdTable(payload.hashIdsFailed)
2931
process.stderr.write(table.toString() + '\n')
3032
}
3133
}

ui/cli/tests/ws-adapter.test.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ await describe('WS Adapter', async () => {
217217

218218
const adapter = createWsAdapter(mockWs as unknown as WebSocket)
219219

220-
const callback = (event: { data: string }): undefined => {
221-
// eslint-disable-next-line no-void
222-
void event
223-
return undefined
224-
}
220+
const callback = (event: { data: string }): undefined => undefined
225221
adapter.onmessage = callback
226222
assert.strictEqual(adapter.onmessage, callback)
227223

@@ -234,11 +230,7 @@ await describe('WS Adapter', async () => {
234230

235231
const adapter = createWsAdapter(mockWs as unknown as WebSocket)
236232

237-
const callback = (event: { error: unknown; message: string }): undefined => {
238-
// eslint-disable-next-line no-void
239-
void event
240-
return undefined
241-
}
233+
const callback = (_event: { error: unknown; message: string }): undefined => undefined
242234
adapter.onerror = callback
243235
assert.strictEqual(adapter.onerror, callback)
244236

@@ -251,11 +243,7 @@ await describe('WS Adapter', async () => {
251243

252244
const adapter = createWsAdapter(mockWs as unknown as WebSocket)
253245

254-
const callback = (event: { code: number; reason: string }): undefined => {
255-
// eslint-disable-next-line no-void
256-
void event
257-
return undefined
258-
}
246+
const callback = (_event: { code: number; reason: string }): undefined => undefined
259247
adapter.onclose = callback
260248
assert.strictEqual(adapter.onclose, callback)
261249

ui/common/tests/WebSocketClient.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ await describe('WebSocketClient', async () => {
416416
(error: unknown) => {
417417
assert.ok(error instanceof Error)
418418
assert.ok(error.message.includes('Invalid timeout'))
419+
assert.ok(error.message.includes('0ms'))
419420
return true
420421
}
421422
)
@@ -444,6 +445,7 @@ await describe('WebSocketClient', async () => {
444445
(error: unknown) => {
445446
assert.ok(error instanceof Error)
446447
assert.ok(error.message.includes('Invalid timeout'))
448+
assert.ok(error.message.includes('-1ms'))
447449
return true
448450
}
449451
)

0 commit comments

Comments
 (0)