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

Function runDelete

src/commands/test.ts:1310–1349  ·  view source on GitHub ↗
(
  opts: DeleteOptions,
  deps: TestDeps = {},
)

Source from the content-addressed store, hash-verified

1308 * server. The CLI surfaces the envelope as-is; no client-side branching.
1309 */
1310export async function runDelete(
1311 opts: DeleteOptions,
1312 deps: TestDeps = {},
1313): Promise<CliDeleteTestResponse> {
1314 assertIdempotencyKey(opts.idempotencyKey);
1315 requireNonEmpty('test-id', opts.testId);
1316
1317 if (!opts.confirm && !opts.dryRun) {
1318 throw ApiError.fromEnvelope({
1319 error: {
1320 code: 'VALIDATION_ERROR',
1321 message: 'Refusing to delete without --confirm.',
1322 nextAction:
1323 'This permanently deletes the test (no restore window), and the CLI ' +
1324 'convention is explicit confirmation for destructive operations. ' +
1325 'Re-run with --confirm. (--dry-run also works without --confirm.)',
1326 requestId: 'local',
1327 details: { field: 'confirm', reason: 'required for destructive operation' },
1328 },
1329 });
1330 }
1331
1332 const idempotencyKey = opts.idempotencyKey ?? `cli-delete-${randomUUID()}`;
1333 if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
1334 const stderr = deps.stderr ?? ((line: string) => process.stderr.write(`${line}\n`));
1335 stderr(`idempotency-key: ${idempotencyKey}`);
1336 }
1337
1338 const client = makeClient(opts, deps);
1339 const out = makeOutput(opts.output, deps);
1340 const response = await client.delete<CliDeleteTestResponse>(
1341 `/tests/${encodeURIComponent(opts.testId)}`,
1342 {
1343 headers: { 'idempotency-key': idempotencyKey },
1344 },
1345 );
1346
1347 out.print(response, data => renderDeleteText(data as CliDeleteTestResponse));
1348 return response;
1349}
1350
1351function renderDeleteText(response: CliDeleteTestResponse): string {
1352 return [`testId ${response.testId}`, `deletedAt ${response.deletedAt}`].join('\n');

Callers 2

test.test.tsFile · 0.85
createTestCommandFunction · 0.85

Calls 8

assertIdempotencyKeyFunction · 0.85
requireNonEmptyFunction · 0.85
stderrFunction · 0.85
renderDeleteTextFunction · 0.85
fromEnvelopeMethod · 0.80
printMethod · 0.80
makeClientFunction · 0.70
makeOutputFunction · 0.70

Tested by

no test coverage detected