MCPcopy Create free account
hub / github.com/TestSprite/testsprite-cli / runList

Function runList

src/commands/test.ts:419–475  ·  view source on GitHub ↗
(opts: ListOptions, deps: TestDeps = {})

Source from the content-addressed store, hash-verified

417}
418
419export async function runList(opts: ListOptions, deps: TestDeps = {}): Promise<Page<CliTest>> {
420 // Validate inputs before touching credentials so a missing `--project`
421 // surfaces as `VALIDATION_ERROR` (exit 5) rather than `AUTH_REQUIRED`
422 // (exit 3) when the caller also lacks a configured key. Order matters
423 // for the CLI error spec §2 — bad input is a caller bug, not an auth
424 // gate.
425 requireProjectId(opts.projectId);
426
427 const paginationFlags: PaginationFlags = validatePaginationFlags({
428 pageSize: opts.pageSize,
429 startingToken: opts.startingToken,
430 maxItems: opts.maxItems,
431 });
432
433 const out = makeOutput(opts.output, deps);
434 const client = makeClient(opts, deps);
435
436 // Match P2's "explicit pageSize ⇒ single-page" convention so an
437 // operator can grab one slice + cursor without auto-paging through a
438 // huge project.
439 const useSinglePage = opts.pageSize !== undefined && opts.maxItems === undefined;
440
441 // M2.1 piece 2: validate `--status` tokens client-side before
442 // sending. Friendlier error than waiting for the server's 400 with
443 // a list of accepted tokens — and lets the user fix typos without
444 // a round trip.
445 validateStatusFilter(opts.status);
446
447 const baseQuery: Record<string, string | number | boolean | undefined> = {
448 projectId: opts.projectId,
449 type: opts.type,
450 createdFrom: opts.createdFrom,
451 status: opts.status,
452 };
453
454 let page: Page<CliTest>;
455 if (useSinglePage) {
456 page = await fetchSinglePage<CliTest>(
457 client,
458 '/tests',
459 paginationFlags.pageSize!,
460 opts.startingToken,
461 baseQuery,
462 );
463 } else {
464 page = await paginate<CliTest>(
465 async ({ pageSize, cursor }) =>
466 client.get<Page<CliTest>>('/tests', {
467 query: { ...baseQuery, pageSize, cursor },
468 }),
469 paginationFlags,
470 );
471 }
472
473 out.print(page, data => renderTestListText(data as Page<CliTest>));
474 return page;
475}
476

Callers 4

test.test.tsFile · 0.70
createTestCommandFunction · 0.70
project.test.tsFile · 0.70
agent.test.tsFile · 0.70

Calls 8

requireProjectIdFunction · 0.85
validatePaginationFlagsFunction · 0.85
validateStatusFilterFunction · 0.85
renderTestListTextFunction · 0.85
printMethod · 0.80
makeOutputFunction · 0.70
makeClientFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected