|
3 | 3 | */ |
4 | 4 | import { Command } from 'commander' |
5 | 5 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 6 | +import { CLI_CONTRACT } from '../../contract/commands' |
6 | 7 | import { type ListLogsResponse, V2_OPERATIONS } from '../../generated/v2-api' |
7 | 8 | import { SimApiError } from '../../http/client' |
8 | | -import { attachLogsFollow, type LogRow } from './logs-follow' |
| 9 | +import { attachLogsFollow, type LogRow, MAX_CELL_WIDTH } from './logs-follow' |
9 | 10 |
|
10 | 11 | const { mockRequest, mockSleep, profile } = vi.hoisted(() => ({ |
11 | 12 | mockRequest: vi.fn(), |
@@ -236,6 +237,90 @@ describe('sim logs follow', () => { |
236 | 237 | expect(stdout).toHaveLength(3) |
237 | 238 | }) |
238 | 239 |
|
| 240 | + it('keeps a run id whole when the follow started with an empty backlog', async () => { |
| 241 | + // `-n 0` seeds the writer with no rows, so the widths used to lock to the |
| 242 | + // header labels — RUN is three characters, and a 36-character run id |
| 243 | + // printed as `9f…`, uncopyable. |
| 244 | + profile.output = 'table' |
| 245 | + const runId = '9f5e9856-1801-4028-a85f-6e335e65d974' |
| 246 | + const arrival = row(runId, '2026-08-17T10:00:01.000Z') |
| 247 | + arrival.workflow = { |
| 248 | + id: 'wf_1', |
| 249 | + name: 'clitest-nightly-sync', |
| 250 | + description: null, |
| 251 | + deleted: false, |
| 252 | + } |
| 253 | + respondWith([page([]), page([arrival])]) |
| 254 | + |
| 255 | + await follow('-n', '0') |
| 256 | + |
| 257 | + const printed = stdout.join('\n') |
| 258 | + expect(printed).toContain(runId) |
| 259 | + expect(printed).toContain('clitest-nightly-sync') |
| 260 | + expect(printed).not.toContain('…') |
| 261 | + }) |
| 262 | + |
| 263 | + it('lines an arriving row up with the header it printed before any rows', async () => { |
| 264 | + // The floors are the half of this that keeps `-n 0` readable: without them |
| 265 | + // the columns lock to their header labels, and every cell of the first real |
| 266 | + // row overflows, so nothing below the header lines up for the life of the |
| 267 | + // follow. |
| 268 | + profile.output = 'table' |
| 269 | + const arrival = row('9f5e9856-1801-4028-a85f-6e335e65d974', '2026-08-17T10:00:01.000Z') |
| 270 | + respondWith([page([]), page([arrival])]) |
| 271 | + |
| 272 | + await follow('-n', '0') |
| 273 | + |
| 274 | + const [header, printed] = stdout |
| 275 | + expect(printed.indexOf('completed')).toBe(header.indexOf('STATUS')) |
| 276 | + expect(printed.indexOf('Nightly sync')).toBe(header.indexOf('WORKFLOW')) |
| 277 | + expect(printed.indexOf('9f5e9856')).toBe(header.indexOf('RUN')) |
| 278 | + }) |
| 279 | + |
| 280 | + it('keeps a later row wider than the batch that locked the widths', async () => { |
| 281 | + profile.output = 'table' |
| 282 | + const first = row('run_1', '2026-08-17T10:00:01.000Z') |
| 283 | + first.workflow = { id: 'wf_1', name: 'short', description: null, deleted: false } |
| 284 | + const second = row('run_2', '2026-08-17T10:00:02.000Z') |
| 285 | + second.workflow = { |
| 286 | + id: 'wf_2', |
| 287 | + name: 'a-considerably-longer-workflow-name', |
| 288 | + description: null, |
| 289 | + deleted: false, |
| 290 | + } |
| 291 | + respondWith([page([first]), page([second, first])]) |
| 292 | + |
| 293 | + await follow('-n', '1') |
| 294 | + |
| 295 | + expect(stdout.join('\n')).toContain('a-considerably-longer-workflow-name') |
| 296 | + }) |
| 297 | + |
| 298 | + it('still cuts a cell at the width one column may ever take', async () => { |
| 299 | + profile.output = 'table' |
| 300 | + const huge = 'x'.repeat(MAX_CELL_WIDTH + 40) |
| 301 | + const arrival = row('run_1', '2026-08-17T10:00:01.000Z') |
| 302 | + arrival.workflow = { id: 'wf_1', name: huge, description: null, deleted: false } |
| 303 | + respondWith([page([]), page([arrival])]) |
| 304 | + |
| 305 | + await follow('-n', '0') |
| 306 | + |
| 307 | + const printed = stdout.join('\n') |
| 308 | + expect(printed).not.toContain(huge) |
| 309 | + expect(printed).toContain(`${'x'.repeat(MAX_CELL_WIDTH - 1)}…`) |
| 310 | + }) |
| 311 | + |
| 312 | + it('asks for no column floor wider than a column may render', () => { |
| 313 | + // A floor above the cap is silently clamped, so an oversized spec would |
| 314 | + // read as deliberate and do nothing. |
| 315 | + const oversized = Object.entries(CLI_CONTRACT).flatMap(([operation, spec]) => |
| 316 | + [...(spec.columns ?? []), ...(spec.fields ?? [])] |
| 317 | + .filter((column) => (column.minWidth ?? 0) > MAX_CELL_WIDTH) |
| 318 | + .map((column) => `${operation}.${column.header}`) |
| 319 | + ) |
| 320 | + |
| 321 | + expect(oversized).toEqual([]) |
| 322 | + }) |
| 323 | + |
239 | 324 | it('keeps rows on stdout and retry notices on stderr', async () => { |
240 | 325 | Object.defineProperty(process.stderr, 'isTTY', { value: true, configurable: true }) |
241 | 326 | const first = row('run_1', '2026-08-17T10:00:01.000Z') |
|
0 commit comments