@testsprite/testsprite-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +190 -0
  3. package/dist/assets/agent-skill/testsprite-verify.codex.md +119 -0
  4. package/dist/assets/agent-skill/testsprite-verify.skill.md +423 -0
  5. package/dist/commands/agent.d.ts +51 -0
  6. package/dist/commands/agent.js +552 -0
  7. package/dist/commands/auth.d.ts +38 -0
  8. package/dist/commands/auth.js +247 -0
  9. package/dist/commands/init.d.ts +63 -0
  10. package/dist/commands/init.js +350 -0
  11. package/dist/commands/project.d.ts +72 -0
  12. package/dist/commands/project.js +400 -0
  13. package/dist/commands/test.d.ts +1245 -0
  14. package/dist/commands/test.js +6214 -0
  15. package/dist/commands/usage.d.ts +63 -0
  16. package/dist/commands/usage.js +156 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +146 -0
  19. package/dist/lib/agent-targets.d.ts +50 -0
  20. package/dist/lib/agent-targets.js +99 -0
  21. package/dist/lib/bundle.d.ts +178 -0
  22. package/dist/lib/bundle.js +600 -0
  23. package/dist/lib/client-factory.d.ts +72 -0
  24. package/dist/lib/client-factory.js +120 -0
  25. package/dist/lib/config.d.ts +24 -0
  26. package/dist/lib/config.js +30 -0
  27. package/dist/lib/credentials.d.ts +17 -0
  28. package/dist/lib/credentials.js +122 -0
  29. package/dist/lib/dry-run/fetch.d.ts +18 -0
  30. package/dist/lib/dry-run/fetch.js +52 -0
  31. package/dist/lib/dry-run/samples.d.ts +50 -0
  32. package/dist/lib/dry-run/samples.js +676 -0
  33. package/dist/lib/errors.d.ts +118 -0
  34. package/dist/lib/errors.js +388 -0
  35. package/dist/lib/facade.d.ts +48 -0
  36. package/dist/lib/facade.js +104 -0
  37. package/dist/lib/failing-fe-resolver.d.ts +60 -0
  38. package/dist/lib/failing-fe-resolver.js +103 -0
  39. package/dist/lib/http.d.ts +255 -0
  40. package/dist/lib/http.js +608 -0
  41. package/dist/lib/output.d.ts +55 -0
  42. package/dist/lib/output.js +70 -0
  43. package/dist/lib/pagination.d.ts +56 -0
  44. package/dist/lib/pagination.js +81 -0
  45. package/dist/lib/poll.d.ts +88 -0
  46. package/dist/lib/poll.js +221 -0
  47. package/dist/lib/prompt.d.ts +8 -0
  48. package/dist/lib/prompt.js +97 -0
  49. package/dist/lib/rate-throttle.d.ts +49 -0
  50. package/dist/lib/rate-throttle.js +75 -0
  51. package/dist/lib/render-error.d.ts +15 -0
  52. package/dist/lib/render-error.js +44 -0
  53. package/dist/lib/runs.types.d.ts +344 -0
  54. package/dist/lib/runs.types.js +25 -0
  55. package/dist/lib/target-url.d.ts +25 -0
  56. package/dist/lib/target-url.js +127 -0
  57. package/dist/lib/ticker.d.ts +37 -0
  58. package/dist/lib/ticker.js +63 -0
  59. package/dist/lib/validate.d.ts +82 -0
  60. package/dist/lib/validate.js +165 -0
  61. package/dist/version.d.ts +1 -0
  62. package/dist/version.js +2 -0
  63. package/package.json +65 -0
@@ -0,0 +1,676 @@
1
+ const SAMPLE_USER_ID = '11111111-1111-4111-8111-111111111111';
2
+ const SAMPLE_KEY_ID = 'key_dryrun_2026';
3
+ const SAMPLE_PROJECT_ID = 'project_b3c91efa';
4
+ const SAMPLE_PROJECT_ID_BACKEND = 'project_a47b2c11';
5
+ const SAMPLE_TEST_ID_FAILED = 'test_8f2a4d10';
6
+ const SAMPLE_TEST_ID_PASSED = 'test_3a91bb02';
7
+ const SAMPLE_TEST_ID_BLOCKED = 'test_blocked_4f7a';
8
+ export const SAMPLE_RUN_ID = 'run_abc';
9
+ // M3.4 rerun dry-run sample IDs
10
+ const SAMPLE_RERUN_ID_BE_NAMED = 'run_rerun_be_named';
11
+ const SAMPLE_RERUN_ID_BE_PRODUCER = 'run_rerun_be_producer';
12
+ const SAMPLE_TEST_ID_BE_CONSUMER = 'test_be_consumer_01';
13
+ const SAMPLE_TEST_ID_BE_PRODUCER = 'test_be_producer_01';
14
+ const SAMPLE_RERUN_BATCH_ID_1 = 'run_batch_rerun_001';
15
+ const SAMPLE_RERUN_BATCH_ID_2 = 'run_batch_rerun_002';
16
+ const SAMPLE_TEST_ID_BATCH_1 = 'test_batch_01';
17
+ const SAMPLE_TEST_ID_BATCH_2 = 'test_batch_02';
18
+ const SAMPLE_TEST_ID_DEFERRED = 'test_deferred_01';
19
+ // M4 piece-2 — batch fresh run sample IDs
20
+ const SAMPLE_BATCH_FRESH_RUN_ID_1 = 'run_fresh_batch_001';
21
+ const SAMPLE_BATCH_FRESH_RUN_ID_2 = 'run_fresh_batch_002';
22
+ const SAMPLE_TEST_ID_FRESH_1 = 'test_fresh_wave_01';
23
+ const SAMPLE_TEST_ID_FRESH_2 = 'test_fresh_wave_02';
24
+ const SAMPLE_SNAPSHOT_ID = 'snap_2026_05_05_b2f9a1c8';
25
+ const SAMPLE_TARGET_URL = 'https://staging.example.com/checkout';
26
+ const SAMPLE_REQUEST_ID = 'req_dry-run';
27
+ export const SAMPLE_DRY_RUN_REQUEST_ID = SAMPLE_REQUEST_ID;
28
+ const me = {
29
+ userId: SAMPLE_USER_ID,
30
+ keyId: SAMPLE_KEY_ID,
31
+ scopes: ['read:projects', 'read:tests', 'write:tests', 'run:tests'],
32
+ env: 'development',
33
+ };
34
+ const projects = [
35
+ {
36
+ id: SAMPLE_PROJECT_ID,
37
+ name: 'Checkout',
38
+ type: 'frontend',
39
+ createdFrom: 'portal',
40
+ createdAt: '2026-04-15T10:23:00.000Z',
41
+ updatedAt: '2026-05-05T08:12:00.000Z',
42
+ },
43
+ {
44
+ id: SAMPLE_PROJECT_ID_BACKEND,
45
+ name: 'Internal API',
46
+ type: 'backend',
47
+ createdFrom: 'mcp',
48
+ createdAt: '2026-03-01T14:00:00.000Z',
49
+ updatedAt: '2026-05-04T19:30:00.000Z',
50
+ },
51
+ ];
52
+ const tests = [
53
+ {
54
+ id: SAMPLE_TEST_ID_FAILED,
55
+ projectId: SAMPLE_PROJECT_ID,
56
+ name: 'Checkout happy path',
57
+ type: 'frontend',
58
+ createdFrom: 'portal',
59
+ status: 'failed',
60
+ // G1a — priority label shown on one row so dry-run learners see the field.
61
+ priority: 'p1',
62
+ createdAt: '2026-04-20T11:00:00.000Z',
63
+ updatedAt: '2026-05-05T12:34:56.000Z',
64
+ details: {
65
+ processingStatus: 'Idle',
66
+ testStatus: 'Failed',
67
+ rawStatus: 'ps=Idle; ts=Failed',
68
+ },
69
+ },
70
+ {
71
+ id: SAMPLE_TEST_ID_PASSED,
72
+ projectId: SAMPLE_PROJECT_ID,
73
+ name: 'Checkout — declined card',
74
+ type: 'frontend',
75
+ createdFrom: 'portal',
76
+ status: 'passed',
77
+ priority: null,
78
+ createdAt: '2026-04-20T11:00:00.000Z',
79
+ updatedAt: '2026-05-05T08:00:00.000Z',
80
+ details: {
81
+ processingStatus: 'Idle',
82
+ testStatus: 'Passed',
83
+ rawStatus: 'ps=Idle; ts=Passed',
84
+ },
85
+ },
86
+ {
87
+ // M2.1 piece 1: distinct `blocked` status surfaces here so a
88
+ // dry-run learner sees how blocked rows render. Pre-M2.1 this
89
+ // would have shown up as `failed` and would have been
90
+ // indistinguishable from the row above.
91
+ id: SAMPLE_TEST_ID_BLOCKED,
92
+ projectId: SAMPLE_PROJECT_ID,
93
+ name: 'Checkout — coupon redemption',
94
+ type: 'frontend',
95
+ createdFrom: 'portal',
96
+ status: 'blocked',
97
+ priority: null,
98
+ createdAt: '2026-04-21T09:00:00.000Z',
99
+ updatedAt: '2026-05-05T13:01:12.000Z',
100
+ details: {
101
+ processingStatus: 'Idle',
102
+ testStatus: 'Blocked',
103
+ rawStatus: 'ps=Idle; ts=Blocked',
104
+ },
105
+ },
106
+ ];
107
+ const testCode = {
108
+ testId: SAMPLE_TEST_ID_FAILED,
109
+ language: 'typescript',
110
+ framework: 'playwright',
111
+ code: [
112
+ "import { test, expect } from '@playwright/test';",
113
+ "test('checkout happy path', async ({ page }) => {",
114
+ ' await page.goto(process.env.TARGET_URL!);',
115
+ ' await page.click(\'[data-testid="cart"]\');',
116
+ ' await page.click(\'[data-testid="submit"]\');',
117
+ " await expect(page.getByRole('heading', { name: 'Order placed' })).toBeVisible();",
118
+ '});',
119
+ '',
120
+ ].join('\n'),
121
+ codeVersion: 'v3',
122
+ etag: 'sha256:c7c4a4f6c1b8c2e5',
123
+ };
124
+ // Sample step list. Includes both `outcomeContributesToFailure` per-step
125
+ // flags (M2.1 piece 4) and the synthetic terminal "assertion" row
126
+ // (piece-4 follow-up — also surfaced on `/steps`, not just `/failure`).
127
+ // Step 5 is a real per-step failure → flag `true` only on that row;
128
+ // step 7 is the synthesizer's fallback for assertion-level failures
129
+ // where no per-step row caught the verdict, so dry-run learners see
130
+ // both shapes in one fixture rather than only the per-step case.
131
+ const testSteps = [
132
+ {
133
+ testId: SAMPLE_TEST_ID_FAILED,
134
+ stepIndex: 4,
135
+ action: 'click',
136
+ description: 'Click the cart icon',
137
+ status: 'passed',
138
+ screenshotUrl: 'https://s3-presigned.example.com/snap/04.png?X-Amz-dryrun',
139
+ htmlSnapshotUrl: 'https://s3-presigned.example.com/snap/04.html?X-Amz-dryrun',
140
+ runIdIfAvailable: SAMPLE_RUN_ID,
141
+ codeVersion: 'v3',
142
+ capturedAt: '2026-05-05T12:34:55.000Z',
143
+ updatedAt: '2026-05-05T12:34:56.000Z',
144
+ outcomeContributesToFailure: false,
145
+ },
146
+ {
147
+ testId: SAMPLE_TEST_ID_FAILED,
148
+ stepIndex: 5,
149
+ action: 'click',
150
+ description: 'Click the submit button',
151
+ status: 'failed',
152
+ screenshotUrl: 'https://s3-presigned.example.com/snap/05.png?X-Amz-dryrun',
153
+ htmlSnapshotUrl: 'https://s3-presigned.example.com/snap/05.html?X-Amz-dryrun',
154
+ runIdIfAvailable: SAMPLE_RUN_ID,
155
+ codeVersion: 'v3',
156
+ capturedAt: '2026-05-05T12:34:56.000Z',
157
+ updatedAt: '2026-05-05T12:34:56.000Z',
158
+ outcomeContributesToFailure: true,
159
+ },
160
+ {
161
+ testId: SAMPLE_TEST_ID_FAILED,
162
+ stepIndex: 6,
163
+ action: 'expect',
164
+ description: 'Expect order confirmation heading',
165
+ status: null,
166
+ screenshotUrl: null,
167
+ htmlSnapshotUrl: null,
168
+ runIdIfAvailable: SAMPLE_RUN_ID,
169
+ codeVersion: 'v3',
170
+ capturedAt: null,
171
+ updatedAt: '2026-05-05T12:34:58.000Z',
172
+ outcomeContributesToFailure: false,
173
+ },
174
+ ];
175
+ const latestResult = {
176
+ testId: SAMPLE_TEST_ID_FAILED,
177
+ status: 'failed',
178
+ startedAt: '2026-05-05T12:34:00.000Z',
179
+ finishedAt: '2026-05-05T12:34:58.000Z',
180
+ videoUrl: 'https://s3-presigned.example.com/video/run_abc.mp4?X-Amz-dryrun',
181
+ failureAnalysisUrl: 'https://s3-presigned.example.com/analysis/run_abc.json?X-Amz-dryrun',
182
+ snapshotId: SAMPLE_SNAPSHOT_ID,
183
+ runIdIfAvailable: SAMPLE_RUN_ID,
184
+ codeVersion: 'v3',
185
+ targetUrl: SAMPLE_TARGET_URL,
186
+ targetUrlSource: 'run',
187
+ failedStepIndex: 5,
188
+ failureKind: 'assertion',
189
+ summary: { passed: 4, failed: 1, skipped: 0 },
190
+ };
191
+ const failureContext = {
192
+ snapshotId: SAMPLE_SNAPSHOT_ID,
193
+ testId: SAMPLE_TEST_ID_FAILED,
194
+ projectId: SAMPLE_PROJECT_ID,
195
+ result: latestResult,
196
+ steps: testSteps,
197
+ code: testCode,
198
+ failure: {
199
+ rootCauseHypothesis: 'Submit button has `opacity: 0.4` and is rendered as disabled. The checkout ' +
200
+ "form's `isFormValid` predicate evaluates to false because the credit-card " +
201
+ 'field is empty.',
202
+ recommendedFixTarget: {
203
+ kind: 'code',
204
+ reference: 'src/components/CheckoutForm.tsx:412',
205
+ rationale: 'The disabled state originates from `isFormValid()` in CheckoutForm.tsx; the ' +
206
+ 'submit button only enables when `card.number.length === 16`. The test fixture ' +
207
+ 'leaves the card field empty.',
208
+ },
209
+ evidence: [
210
+ {
211
+ kind: 'screenshot',
212
+ stepIndex: 5,
213
+ url: 'https://s3-presigned.example.com/evidence/run_abc/05.png?X-Amz-dryrun',
214
+ summary: 'Submit button has `opacity: 0.4` and is rendered as disabled. Credit-card ' +
215
+ 'field is empty. No visible error message.',
216
+ },
217
+ {
218
+ kind: 'snapshot',
219
+ stepIndex: 5,
220
+ url: 'https://s3-presigned.example.com/evidence/run_abc/05.html?X-Amz-dryrun',
221
+ summary: '`<button data-testid="submit" disabled aria-disabled="true" ' +
222
+ 'style="pointer-events:none;opacity:0.4">`. DOM diff vs. step 4 shows the ' +
223
+ "`disabled` attribute being added by the form's onChange handler.",
224
+ },
225
+ ],
226
+ },
227
+ };
228
+ /**
229
+ * §5.2 / M2.1 piece 3 — sample for `GET /tests/{testId}/failure/summary`.
230
+ * Mirrors the analysis fields in `failureContext.failure` so a learner
231
+ * comparing dry-run outputs sees the same hypothesis on both surfaces.
232
+ */
233
+ const failureSummary = {
234
+ testId: SAMPLE_TEST_ID_FAILED,
235
+ status: 'failed',
236
+ failureKind: 'assertion',
237
+ snapshotId: SAMPLE_SNAPSHOT_ID,
238
+ rootCauseHypothesis: failureContext.failure.rootCauseHypothesis,
239
+ recommendedFixTarget: failureContext.failure.recommendedFixTarget,
240
+ };
241
+ const PATH_PREFIX = '/api/cli/v1';
242
+ const ENTRIES = [
243
+ entry('whoami', 'GET', '/me', me),
244
+ entry('listProjects', 'GET', '/projects', pageOf(projects)),
245
+ entry('getProject', 'GET', '/projects/{projectId}', projects[0]),
246
+ // P6 — POST /projects (create project). The id uses a stable dry-run
247
+ // sentinel so agents can see a coherent field shape without a real key.
248
+ entry('createProject', 'POST', '/projects', {
249
+ id: 'p_dryrun_create_2026',
250
+ type: 'frontend',
251
+ name: 'Dry-run project',
252
+ createdFrom: 'cli',
253
+ createdAt: '2026-05-16T00:00:00.000Z',
254
+ updatedAt: '2026-05-16T00:00:00.000Z',
255
+ }),
256
+ // P7 — PATCH /projects/{id} (update project).
257
+ entry('updateProject', 'PATCH', '/projects/{projectId}', {
258
+ id: SAMPLE_PROJECT_ID,
259
+ updatedFields: ['name'],
260
+ updatedAt: '2026-05-16T00:00:00.000Z',
261
+ }),
262
+ entry('listTests', 'GET', '/tests', pageOf(tests)),
263
+ entry('getTestCode', 'GET', '/tests/{testId}/code', testCode),
264
+ entry('listTestSteps', 'GET', '/tests/{testId}/steps', pageOf(testSteps)),
265
+ entry('getTestResult', 'GET', '/tests/{testId}/result', latestResult),
266
+ // `/failure/summary` MUST come before `/failure` so the regex matcher
267
+ // doesn't shadow it with the bundle endpoint.
268
+ entry('getTestFailureSummary', 'GET', '/tests/{testId}/failure/summary', failureSummary),
269
+ entry('getTestFailure', 'GET', '/tests/{testId}/failure', failureContext),
270
+ // M3.4 piece-5 — GET /tests/{testId}/runs (run-history list).
271
+ // **MUST appear BEFORE the `/tests/{testId}` catch-all** so the more
272
+ // specific `/runs` suffix wins the regex match. Shows two rows
273
+ // (fresh + rerun) so dry-run learners see both `isRerun: false` and
274
+ // `isRerun: true` shapes in one fixture.
275
+ entry('listTestRuns', 'GET', '/tests/{testId}/runs', {
276
+ runs: [
277
+ {
278
+ // G1b — fresh run with a real targetUrl stamped at trigger time.
279
+ runId: SAMPLE_RUN_ID,
280
+ status: 'passed',
281
+ source: 'cli',
282
+ isRerun: false,
283
+ createdFrom: null,
284
+ createdAt: '2026-06-03T10:00:00.000Z',
285
+ startedAt: '2026-06-03T10:00:05.000Z',
286
+ finishedAt: '2026-06-03T10:02:00.000Z',
287
+ codeVersion: 'v1',
288
+ failureKind: null,
289
+ targetUrl: SAMPLE_TARGET_URL,
290
+ targetUrlSource: 'run',
291
+ },
292
+ {
293
+ // G1b — rerun row where the URL could not be resolved (shows null shape).
294
+ runId: 'run_rerun_history_01',
295
+ status: 'failed',
296
+ source: 'cli',
297
+ isRerun: true,
298
+ createdFrom: `rerun:${SAMPLE_RUN_ID}`,
299
+ createdAt: '2026-06-02T14:30:00.000Z',
300
+ startedAt: '2026-06-02T14:30:10.000Z',
301
+ finishedAt: '2026-06-02T14:32:45.000Z',
302
+ codeVersion: 'v1',
303
+ failureKind: 'assertion',
304
+ targetUrl: null,
305
+ targetUrlSource: 'unresolved',
306
+ },
307
+ ],
308
+ nextCursor: null,
309
+ meta: { testKind: 'frontend' },
310
+ }),
311
+ // `getTest` is the catch-all for `/tests/{id}` — must appear AFTER the
312
+ // `/tests/{id}/{...}` siblings so the more specific patterns win.
313
+ entry('getTest', 'GET', '/tests/{testId}', tests[0]),
314
+ // M3.3 piece-4 — GET /runs/{runId}/failure (run-scoped artifact bundle).
315
+ // Must appear BEFORE the /runs/{runId} catch-all so the more specific
316
+ // /failure path wins the regex match.
317
+ entry('getRunFailure', 'GET', '/runs/{runId}/failure', failureContext),
318
+ // M3.2 piece-5 — POST /tests/batch (FE-only plan-steps batch create).
319
+ // **MUST appear before `/tests`** so the more-specific path wins the
320
+ // regex match. Input-derived response: one result per supplied spec so
321
+ // the caller can verify their JSONL file was parsed as the right count.
322
+ // FE specs are echoed as `created`; backend specs (which the live route
323
+ // rejects per `runCreateBatch`'s stderr advisory) are echoed as
324
+ // `validation_error` so a mixed-batch dry-run doesn't teach a
325
+ // false-positive contract (codex-review P2, 2026-05-28).
326
+ entry('createTestBatch', 'POST', '/tests/batch', (req) => {
327
+ const body = req != null && typeof req === 'object' ? req : {};
328
+ const tests = Array.isArray(body.tests) ? body.tests : [];
329
+ const count = tests.length;
330
+ if (count === 0) {
331
+ // No input detected — fall back to the illustrative 3-entry sample
332
+ // (2 created + 1 validation_error) so dry-run learners still see
333
+ // the mixed-status shape when run without body context.
334
+ return {
335
+ results: [
336
+ { specIndex: 0, testId: 'test_dryrun_batch_0', status: 'created' },
337
+ { specIndex: 1, testId: 'test_dryrun_batch_1', status: 'created' },
338
+ {
339
+ specIndex: 2,
340
+ status: 'validation_error',
341
+ error: {
342
+ code: 'VALIDATION_ERROR',
343
+ message: 'planSteps[0].type must be one of: "action", "assertion"',
344
+ field: 'planSteps[0].type',
345
+ },
346
+ },
347
+ ],
348
+ summary: { total: 3, created: 2, failed: 1 },
349
+ };
350
+ }
351
+ // Mirror runCreateBatch's real behavior — backend specs are rejected
352
+ // with `validation_error`, FE specs are created. A mixed-batch dry-run
353
+ // that marks BE specs as `created` would teach agents a false-positive
354
+ // contract (codex-review P2, 2026-05-28).
355
+ const results = tests.map((spec, i) => {
356
+ if (spec && typeof spec === 'object' && spec.type === 'backend') {
357
+ return {
358
+ specIndex: i,
359
+ testId: null,
360
+ status: 'validation_error',
361
+ error: {
362
+ code: 'VALIDATION_ERROR',
363
+ message: `spec[${i}]: backend specs are not supported on POST /tests/batch — use 'test create --type backend --code-file' instead.`,
364
+ field: 'type',
365
+ },
366
+ };
367
+ }
368
+ return {
369
+ specIndex: i,
370
+ testId: `test_dryrun_batch_${i}`,
371
+ status: 'created',
372
+ };
373
+ });
374
+ const created = results.filter(r => r.status === 'created').length;
375
+ const failed = results.filter(r => r.status === 'validation_error').length;
376
+ return {
377
+ results,
378
+ summary: { total: count, created, failed },
379
+ };
380
+ }),
381
+ // M3.2 piece-2 — POST /tests (code-based create). Input-derived response
382
+ // so the `type` field reflects what the caller actually passed (P3-12 fix:
383
+ // previously hardcoded to `"frontend"`, hiding BE test dry-run behaviour).
384
+ // The `planSteps` echo a real plan-from response would carry is omitted —
385
+ // agents see testId/codeVersion/createdAt which is enough to confirm shape.
386
+ entry('createTestFromCode', 'POST', '/tests', (req) => {
387
+ const body = req != null && typeof req === 'object' ? req : {};
388
+ const type = body.type === 'backend' ? 'backend' : 'frontend';
389
+ return {
390
+ testId: 'test_dryrun_create_2026',
391
+ type,
392
+ codeVersion: 'v1',
393
+ createdAt: '2026-05-13T00:00:00.000Z',
394
+ };
395
+ }),
396
+ // M3.2 piece-6 — PUT /tests/{id}/plan-steps (FE plan replace).
397
+ // Input-derived response: `stepCount` reflects the actual number of
398
+ // steps the caller supplied so they can verify their file was parsed
399
+ // correctly. `planStepsHash` stays canned (sha256 is not worth
400
+ // recomputing in dry-run).
401
+ entry('putPlanSteps', 'PUT', '/tests/{testId}/plan-steps', (req) => {
402
+ const body = req != null && typeof req === 'object' ? req : {};
403
+ const planSteps = Array.isArray(body.planSteps) ? body.planSteps : [];
404
+ return {
405
+ testId: 'test_dryrun_plan_put_2026',
406
+ planStepsHash: 'sha256:dryrun-plan-steps-hash',
407
+ stepCount: planSteps.length > 0 ? planSteps.length : 3,
408
+ updatedAt: '2026-05-14T00:00:00.000Z',
409
+ };
410
+ }),
411
+ // M3.2 piece-4 — PUT /tests/{id}/code (etag-guarded replace). Canned
412
+ // response shape per the code-put design spec. The
413
+ // `codeVersion` here is the bumped value (v3 → v4) so an agent
414
+ // dry-running the chain sees a coherent progression: the sample
415
+ // testCode.codeVersion is `v3`, so `put` advances to `v4`.
416
+ entry('putTestCode', 'PUT', '/tests/{testId}/code', {
417
+ testId: 'test_dryrun_code_put_2026',
418
+ codeVersion: 'v4',
419
+ updatedAt: '2026-05-13T00:00:00.000Z',
420
+ }),
421
+ // PUT /tests/{id} (metadata update). Input-derived response: `updatedFields`
422
+ // echoes the keys the caller actually passed so an agent can confirm their
423
+ // flags landed in the right fields. OpenAPI spec does not define either PATCH
424
+ // or PUT for this path; the wire truth is whatever the backend implements
425
+ // (currently PUT).
426
+ entry('updateTest', 'PUT', '/tests/{testId}', (req) => {
427
+ const body = req != null && typeof req === 'object' ? req : {};
428
+ const updatedFields = Object.keys(body).filter(k => body[k] !== undefined);
429
+ return {
430
+ testId: 'test_dryrun_update_2026',
431
+ updatedFields: updatedFields.length > 0 ? updatedFields : ['name', 'description'],
432
+ updatedAt: '2026-05-13T00:00:00.000Z',
433
+ };
434
+ }),
435
+ // delete-batch (DELETE /tests/<id> × N). The batch sub-command dispatches
436
+ // one DELETE /tests/{testId} per test (no batch endpoint) and aggregates
437
+ // results into CliBulkDeleteSummary. Under --dry-run the function has an
438
+ // inline early-exit (no network calls), so this sample is not consumed by
439
+ // the dry-run runner itself. It is registered here as documentation of the
440
+ // wire shape for agents learning the surface via `--dry-run --output json`,
441
+ // and it participates in the samples.test.ts shape-guard so drift against
442
+ // CliBulkDeleteSummary fails the build.
443
+ //
444
+ // **MUST appear before deleteTest** — `/tests/batch` is a literal path that
445
+ // would otherwise match the `/tests/{testId}` wildcard (first-match-wins).
446
+ entry('deleteBatch', 'DELETE', '/tests/batch', {
447
+ results: [
448
+ {
449
+ testId: 'test_dryrun_delete_2026',
450
+ status: 'deleted',
451
+ deletedAt: '2026-05-13T00:00:00.000Z',
452
+ },
453
+ { testId: 'test_dryrun_skip_2026', status: 'skipped', error: 'not found (already deleted?)' },
454
+ ],
455
+ summary: { total: 2, deleted: 1, skipped: 1, failed: 0 },
456
+ }),
457
+ // M3.2 piece-3 — DELETE /tests/{id} (permanent hard-delete). Canned
458
+ // response shape per the update/delete design spec.
459
+ // `deletedAt` is the delete-time ack (no restore window). Stable
460
+ // strings here so a `--dry-run` capture stays diff-able across runs.
461
+ entry('deleteTest', 'DELETE', '/tests/{testId}', {
462
+ testId: 'test_dryrun_delete_2026',
463
+ deletedAt: '2026-05-13T00:00:00.000Z',
464
+ }),
465
+ // M3.3 piece-3 — POST /tests/{testId}/runs (trigger run).
466
+ // **MUST appear before `/tests` and `/tests/{testId}` generic matchers**
467
+ // so the more-specific runs path wins. Canned response shape per the
468
+ // runs-trigger design spec.
469
+ entry('triggerRun', 'POST', '/tests/{testId}/runs', {
470
+ runId: SAMPLE_RUN_ID,
471
+ status: 'queued',
472
+ enqueuedAt: '2026-05-15T19:32:00.000Z',
473
+ codeVersion: 'v1',
474
+ targetUrl: SAMPLE_TARGET_URL,
475
+ }),
476
+ // M3.4 piece-3 — POST /tests/{testId}/runs/rerun (single rerun).
477
+ // **MUST appear before `/tests/{testId}/runs` and `/tests/{testId}`** so the
478
+ // more-specific `/runs/rerun` path wins over the generic runs trigger.
479
+ // Two shapes are possible (FE / BE). The sample shows a BE shape (with
480
+ // closure) so dry-run learners see the richer response; FE callers get the
481
+ // same response minus `closure`.
482
+ entry('triggerRerun', 'POST', '/tests/{testId}/runs/rerun', {
483
+ runId: SAMPLE_RERUN_ID_BE_NAMED,
484
+ status: 'queued',
485
+ enqueuedAt: '2026-06-03T10:00:00.000Z',
486
+ codeVersion: 'v1',
487
+ autoHeal: true,
488
+ closure: {
489
+ members: [
490
+ { testId: SAMPLE_TEST_ID_BE_CONSUMER, runId: SAMPLE_RERUN_ID_BE_NAMED, role: 'selected' },
491
+ {
492
+ testId: SAMPLE_TEST_ID_BE_PRODUCER,
493
+ runId: SAMPLE_RERUN_ID_BE_PRODUCER,
494
+ role: 'producer',
495
+ },
496
+ ],
497
+ addedProducers: [SAMPLE_TEST_ID_BE_PRODUCER],
498
+ addedTeardowns: [],
499
+ clearedCaptured: 0,
500
+ },
501
+ }),
502
+ // M4 piece-2 — POST /tests/batch/run (fresh wave-ordered batch run).
503
+ // **MUST appear before `/tests/batch/rerun` and `/tests/batch` (create)**
504
+ // so the more-specific `/batch/run` path wins. Shows `accepted[]` with
505
+ // per-test runIds + `skippedFrontend[]` so dry-run learners see both shapes.
506
+ entry('triggerBatchRunFresh', 'POST', '/tests/batch/run', {
507
+ accepted: [
508
+ {
509
+ testId: SAMPLE_TEST_ID_FRESH_1,
510
+ runId: SAMPLE_BATCH_FRESH_RUN_ID_1,
511
+ enqueuedAt: '2026-06-09T10:00:00.000Z',
512
+ },
513
+ {
514
+ testId: SAMPLE_TEST_ID_FRESH_2,
515
+ runId: SAMPLE_BATCH_FRESH_RUN_ID_2,
516
+ enqueuedAt: '2026-06-09T10:00:00.000Z',
517
+ },
518
+ ],
519
+ conflicts: [],
520
+ deferred: [],
521
+ skippedFrontend: [],
522
+ skippedIntegration: [],
523
+ }),
524
+ // M3.4 piece-3 — POST /tests/batch/rerun (batch rerun).
525
+ // **MUST appear before `/tests/batch` (create)** so the more-specific
526
+ // `/batch/rerun` path wins. Shows `accepted[]` with per-test runIds (C2)
527
+ // plus a `deferred[]` example (C1) so dry-run learners see both shapes.
528
+ entry('triggerBatchRerun', 'POST', '/tests/batch/rerun', {
529
+ accepted: [
530
+ {
531
+ testId: SAMPLE_TEST_ID_BATCH_1,
532
+ runId: SAMPLE_RERUN_BATCH_ID_1,
533
+ enqueuedAt: '2026-06-03T10:00:00.000Z',
534
+ },
535
+ {
536
+ testId: SAMPLE_TEST_ID_BATCH_2,
537
+ runId: SAMPLE_RERUN_BATCH_ID_2,
538
+ enqueuedAt: '2026-06-03T10:00:00.000Z',
539
+ },
540
+ ],
541
+ deferred: [{ testId: SAMPLE_TEST_ID_DEFERRED, reason: 'rate_limited' }],
542
+ conflicts: [],
543
+ closure: {
544
+ byProject: [
545
+ {
546
+ projectId: SAMPLE_PROJECT_ID_BACKEND,
547
+ testIds: [SAMPLE_TEST_ID_BATCH_2],
548
+ addedProducers: [],
549
+ addedTeardowns: [],
550
+ clearedCaptured: 0,
551
+ },
552
+ ],
553
+ },
554
+ }),
555
+ // M3.3 piece-3 — GET /runs/{runId} (live status / long-poll).
556
+ // A terminal `passed` row is the most useful dry-run shape: agents see
557
+ // what a completed run looks like, and `--wait` terminates immediately.
558
+ // fix(2026-05-21): a duplicate failed-shape entry that appeared before
559
+ // this entry was removed; findSample first-match-wins was always
560
+ // returning status: "failed" for `test wait --dry-run`.
561
+ entry('getRun', 'GET', '/runs/{runId}', {
562
+ runId: SAMPLE_RUN_ID,
563
+ testId: SAMPLE_TEST_ID_PASSED,
564
+ projectId: SAMPLE_PROJECT_ID,
565
+ userId: SAMPLE_USER_ID,
566
+ status: 'passed',
567
+ source: 'cli',
568
+ createdAt: '2026-05-15T19:32:00.000Z',
569
+ startedAt: '2026-05-15T19:32:05.000Z',
570
+ finishedAt: '2026-05-15T19:34:00.000Z',
571
+ codeVersion: 'v1',
572
+ targetUrl: SAMPLE_TARGET_URL,
573
+ createdFrom: null,
574
+ failedStepIndex: null,
575
+ failureKind: null,
576
+ error: null,
577
+ videoUrl: null,
578
+ stepSummary: {
579
+ total: 8,
580
+ completed: 8,
581
+ passedCount: 8,
582
+ failedCount: 0,
583
+ },
584
+ // Representative per-run steps so `test steps --run-id <id> --dry-run`
585
+ // demonstrates real output instead of an empty list (the generic
586
+ // `/runs/{runId}` sample is also used by `test wait`, which ignores steps).
587
+ steps: [
588
+ {
589
+ stepIndex: '0001',
590
+ type: 'action',
591
+ action: 'navigate',
592
+ status: 'passed',
593
+ description: 'Open the target URL',
594
+ error: null,
595
+ screenshotUrl: null,
596
+ htmlSnapshotUrl: null,
597
+ createdAt: '2026-05-15T19:32:10.000Z',
598
+ },
599
+ {
600
+ stepIndex: '0002',
601
+ type: 'assertion',
602
+ action: 'assert_visible',
603
+ status: 'passed',
604
+ description: 'Dashboard heading is visible',
605
+ error: null,
606
+ screenshotUrl: null,
607
+ htmlSnapshotUrl: null,
608
+ createdAt: '2026-05-15T19:32:20.000Z',
609
+ },
610
+ ],
611
+ }),
612
+ ];
613
+ function entry(operationId, method, pathTemplate, body) {
614
+ // Convert `/tests/{testId}/code` → /^\/tests\/[^/]+\/code$/
615
+ const regexSrc = pathTemplate.replace(/\{[^}]+\}/g, '[^/]+').replace(/\//g, '\\/');
616
+ const bodyFn = typeof body === 'function' ? body : () => body;
617
+ return {
618
+ operationId,
619
+ method,
620
+ pathTemplate,
621
+ pattern: new RegExp(`^${regexSrc}$`),
622
+ body: bodyFn,
623
+ };
624
+ }
625
+ function pageOf(items) {
626
+ // M2 dry-run always returns one page with `nextToken: null`. Auto-pagination
627
+ // therefore terminates after the first sample. If a future piece wants to
628
+ // exercise the cursor path in dry-run, branch on `cursor` query param in the
629
+ // fetch impl and return a synthetic next-page on the second call.
630
+ return { items, nextToken: null };
631
+ }
632
+ /**
633
+ * Resolve a fetch URL to its canned sample. Matches against the path
634
+ * portion only (query string is ignored — auto-pagination's `cursor`
635
+ * query is intentionally a no-op in M2 dry-run; see {@link pageOf}).
636
+ *
637
+ * Returns `undefined` when no pattern matches; the caller (the dry-run
638
+ * fetch impl) surfaces this as a 500 INTERNAL envelope so a missing
639
+ * sample is loud, not silent.
640
+ *
641
+ * `requestBody` is forwarded to input-derived entries (`updateTest`,
642
+ * `putPlanSteps`, `createTestBatch`) so their responses reflect the
643
+ * user's actual flags rather than static canned values.
644
+ */
645
+ export function findSample(method, url, requestBody) {
646
+ const upper = method.toUpperCase();
647
+ const pathOnly = extractPath(url);
648
+ for (const e of ENTRIES) {
649
+ if (e.method === upper && e.pattern.test(pathOnly)) {
650
+ // Rebind body so callers get the resolved value, not the factory.
651
+ // We return a new object with `body` already applied so downstream
652
+ // code can keep calling `e.body` as-before (no API break for tests
653
+ // that call `findSample` directly).
654
+ return { ...e, body: () => e.body(requestBody) };
655
+ }
656
+ }
657
+ return undefined;
658
+ }
659
+ function extractPath(url) {
660
+ // Strip protocol+host, then strip the `/api/cli/v1` facade prefix.
661
+ let path = url;
662
+ const protoIdx = path.indexOf('://');
663
+ if (protoIdx >= 0) {
664
+ const slashIdx = path.indexOf('/', protoIdx + 3);
665
+ path = slashIdx >= 0 ? path.slice(slashIdx) : '/';
666
+ }
667
+ const queryIdx = path.indexOf('?');
668
+ if (queryIdx >= 0)
669
+ path = path.slice(0, queryIdx);
670
+ if (path.startsWith(PATH_PREFIX))
671
+ path = path.slice(PATH_PREFIX.length) || '/';
672
+ return path;
673
+ }
674
+ /** Test-only export so `samples.test.ts` can iterate the catalog. */
675
+ export const DRY_RUN_SAMPLE_ENTRIES = ENTRIES;
676
+ //# sourceMappingURL=samples.js.map