@testsprite/testsprite-cli 0.6.0 → 0.8.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 (96) hide show
  1. package/README.md +52 -31
  2. package/dist/commands/agent.js +91 -45
  3. package/dist/commands/ci.d.ts +88 -0
  4. package/dist/commands/ci.js +429 -0
  5. package/dist/commands/doctor.d.ts +1 -1
  6. package/dist/commands/doctor.js +104 -8
  7. package/dist/commands/init.js +8 -0
  8. package/dist/commands/project.d.ts +78 -0
  9. package/dist/commands/project.js +429 -5
  10. package/dist/commands/schedule.d.ts +120 -0
  11. package/dist/commands/schedule.js +487 -0
  12. package/dist/commands/test.d.ts +176 -2
  13. package/dist/commands/test.js +2235 -609
  14. package/dist/commands/testlist.d.ts +88 -0
  15. package/dist/commands/testlist.js +753 -0
  16. package/dist/commands/tunnel.d.ts +72 -0
  17. package/dist/commands/tunnel.js +367 -0
  18. package/dist/index.js +113 -40
  19. package/dist/lib/agent-targets.d.ts +13 -4
  20. package/dist/lib/agent-targets.js +11 -2
  21. package/dist/lib/conflict-reason.d.ts +30 -0
  22. package/dist/lib/conflict-reason.js +45 -0
  23. package/dist/lib/credentials.js +42 -1
  24. package/dist/lib/cron.d.ts +40 -0
  25. package/dist/lib/cron.js +190 -0
  26. package/dist/lib/dry-run/samples.d.ts +9 -0
  27. package/dist/lib/dry-run/samples.js +293 -55
  28. package/dist/lib/errors.d.ts +9 -0
  29. package/dist/lib/errors.js +11 -0
  30. package/dist/lib/gh-output.d.ts +33 -1
  31. package/dist/lib/gh-output.js +97 -27
  32. package/dist/lib/http.d.ts +119 -0
  33. package/dist/lib/http.js +243 -2
  34. package/dist/lib/interrupt.d.ts +38 -13
  35. package/dist/lib/interrupt.js +130 -15
  36. package/dist/lib/junit-report.d.ts +20 -2
  37. package/dist/lib/junit-report.js +38 -5
  38. package/dist/lib/local-target.d.ts +95 -0
  39. package/dist/lib/local-target.js +184 -0
  40. package/dist/lib/plan-poll.d.ts +171 -0
  41. package/dist/lib/plan-poll.js +442 -0
  42. package/dist/lib/plans.types.d.ts +130 -0
  43. package/dist/lib/plans.types.js +31 -0
  44. package/dist/lib/poll-support.d.ts +26 -0
  45. package/dist/lib/poll-support.js +65 -0
  46. package/dist/lib/poll.d.ts +1 -0
  47. package/dist/lib/poll.js +2 -40
  48. package/dist/lib/proxy.d.ts +16 -0
  49. package/dist/lib/proxy.js +19 -1
  50. package/dist/lib/response-schemas.d.ts +20 -0
  51. package/dist/lib/response-schemas.js +55 -1
  52. package/dist/lib/run-progress.d.ts +41 -0
  53. package/dist/lib/run-progress.js +56 -0
  54. package/dist/lib/runs.types.d.ts +32 -3
  55. package/dist/lib/secret-file.d.ts +15 -0
  56. package/dist/lib/secret-file.js +82 -0
  57. package/dist/lib/target-url-preflight.d.ts +91 -0
  58. package/dist/lib/target-url-preflight.js +259 -0
  59. package/dist/lib/target-url.d.ts +63 -9
  60. package/dist/lib/target-url.js +283 -62
  61. package/dist/lib/telemetry.d.ts +11 -0
  62. package/dist/lib/telemetry.js +1 -0
  63. package/dist/lib/testlist.types.d.ts +77 -0
  64. package/dist/lib/testlist.types.js +9 -0
  65. package/dist/lib/ticker.d.ts +8 -0
  66. package/dist/lib/ticker.js +3 -0
  67. package/dist/lib/tunnel-session.d.ts +129 -0
  68. package/dist/lib/tunnel-session.js +232 -0
  69. package/dist/lib/tunnel.types.d.ts +54 -0
  70. package/dist/lib/tunnel.types.js +8 -0
  71. package/dist/lib/v3-advisory.d.ts +35 -22
  72. package/dist/lib/v3-advisory.js +44 -24
  73. package/dist/lib/wait-exit.d.ts +29 -0
  74. package/dist/lib/wait-exit.js +103 -0
  75. package/dist/vendor/tunnel-client/client.d.ts +83 -0
  76. package/dist/vendor/tunnel-client/client.js +871 -0
  77. package/dist/vendor/tunnel-client/config.d.ts +41 -0
  78. package/dist/vendor/tunnel-client/config.js +42 -0
  79. package/dist/vendor/tunnel-client/index.d.ts +9 -0
  80. package/dist/vendor/tunnel-client/index.js +9 -0
  81. package/dist/vendor/tunnel-client/lodash-lite.d.ts +14 -0
  82. package/dist/vendor/tunnel-client/lodash-lite.js +24 -0
  83. package/dist/vendor/tunnel-client/protocol.d.ts +60 -0
  84. package/dist/vendor/tunnel-client/protocol.js +143 -0
  85. package/dist/vendor/tunnel-client/types.d.ts +96 -0
  86. package/dist/vendor/tunnel-client/types.js +10 -0
  87. package/dist/vendor/tunnel-client/ws-compat.d.ts +206 -0
  88. package/dist/vendor/tunnel-client/ws-compat.js +316 -0
  89. package/dist/version-guard.d.ts +10 -7
  90. package/dist/version-guard.js +37 -9
  91. package/dist/version.d.ts +1 -1
  92. package/dist/version.js +1 -1
  93. package/package.json +2 -1
  94. package/skills/testsprite-onboard.skill.md +60 -4
  95. package/skills/testsprite-verify.codex.md +22 -16
  96. package/skills/testsprite-verify.skill.md +27 -18
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Cron helpers for the `schedule` commands.
3
+ *
4
+ * Everything here produces human-facing text only — none of it affects when a
5
+ * schedule fires.
6
+ *
7
+ * Field order is standard 5-field cron: minute hour day-of-month month day-of-week.
8
+ * That is the format the API takes on `schedule create`/`update` and hands back
9
+ * on `schedule get`, so an expression read from one command is valid input to
10
+ * the other.
11
+ */
12
+ const FIELD_COUNT = 5;
13
+ /** 365/12, which makes an hourly cron come out at exactly 730 runs/month. */
14
+ const DAYS_PER_MONTH = 365 / 12;
15
+ const WEEKS_PER_MONTH = DAYS_PER_MONTH / 7;
16
+ const MONTHS_PER_YEAR = 12;
17
+ const MINUTE = { min: 0, max: 59 };
18
+ const HOUR = { min: 0, max: 23 };
19
+ const DAY_OF_MONTH = { min: 1, max: 31 };
20
+ const MONTH = { min: 1, max: 12 };
21
+ /** 0 and 7 both mean Sunday, so wrap folds them together. */
22
+ const DAY_OF_WEEK = { min: 0, max: 7, wrap: 7 };
23
+ const DAYS_IN_MONTH_FIELD = DAY_OF_MONTH.max - DAY_OF_MONTH.min + 1;
24
+ const DAYS_IN_WEEK = 7;
25
+ function fields(cron) {
26
+ return cron.trim().split(/\s+/);
27
+ }
28
+ /** True for a field naming one value, e.g. `3`. */
29
+ function isPinned(field) {
30
+ return field !== undefined && /^\d+$/.test(field);
31
+ }
32
+ /** True for a field that varies rather than naming one value. */
33
+ function isWildcard(field) {
34
+ return field === undefined || field === '*';
35
+ }
36
+ /**
37
+ * The values a single cron field matches, or null when the field is not a shape
38
+ * we read (month/day names, the `L`/`W`/`#` extensions, a 6-field Quartz cron).
39
+ *
40
+ * A set rather than a count, so overlapping lists (`1-5,3`) and the two
41
+ * spellings of Sunday (`0,7`) are each counted once and steps are exact.
42
+ */
43
+ function expand(field, range) {
44
+ if (field === undefined)
45
+ return null;
46
+ const out = new Set();
47
+ for (const part of field.split(',')) {
48
+ const segments = part.split('/');
49
+ if (segments.length > 2)
50
+ return null;
51
+ const [spec, stepText] = segments;
52
+ let step = 1;
53
+ if (stepText !== undefined) {
54
+ if (!/^\d+$/.test(stepText))
55
+ return null;
56
+ step = Number(stepText);
57
+ if (step < 1)
58
+ return null;
59
+ }
60
+ let lo;
61
+ let hi;
62
+ if (spec === '*') {
63
+ lo = range.min;
64
+ hi = range.max;
65
+ }
66
+ else if (spec !== undefined && /^\d+$/.test(spec)) {
67
+ lo = Number(spec);
68
+ // A step on a single value means "from here to the end of the range".
69
+ hi = stepText === undefined ? lo : range.max;
70
+ }
71
+ else {
72
+ const bounds = /^(\d+)-(\d+)$/.exec(spec ?? '');
73
+ if (!bounds)
74
+ return null;
75
+ lo = Number(bounds[1]);
76
+ hi = Number(bounds[2]);
77
+ }
78
+ if (lo < range.min || hi > range.max || lo > hi)
79
+ return null;
80
+ for (let value = lo; value <= hi; value += step) {
81
+ out.add(range.wrap === undefined ? value : value % range.wrap);
82
+ }
83
+ }
84
+ return out.size > 0 ? out : null;
85
+ }
86
+ /**
87
+ * Approximate number of times a cron fires per month, or null when the
88
+ * expression is not a 5-field cron we can read.
89
+ *
90
+ * Every field is counted, so a cron that pins a coarse field and leaves a finer
91
+ * one open (`* 3 * * *` — every minute of 03:00) is not mistaken for its coarse
92
+ * unit. day-of-month and day-of-week are OR'd when both are restricted, which
93
+ * is what standard cron does.
94
+ */
95
+ export function runsPerMonth(cron) {
96
+ const f = fields(cron);
97
+ if (f.length !== FIELD_COUNT)
98
+ return null;
99
+ const minutes = expand(f[0], MINUTE);
100
+ const hours = expand(f[1], HOUR);
101
+ const daysOfMonth = expand(f[2], DAY_OF_MONTH);
102
+ const months = expand(f[3], MONTH);
103
+ const daysOfWeek = expand(f[4], DAY_OF_WEEK);
104
+ if (!minutes || !hours || !daysOfMonth || !months || !daysOfWeek)
105
+ return null;
106
+ const everyDayOfMonth = daysOfMonth.size === DAYS_IN_MONTH_FIELD;
107
+ const everyDayOfWeek = daysOfWeek.size === DAYS_IN_WEEK;
108
+ let days;
109
+ if (everyDayOfMonth && everyDayOfWeek) {
110
+ days = DAYS_PER_MONTH;
111
+ }
112
+ else if (everyDayOfWeek) {
113
+ // Short months make a high day number fire less often than once a month;
114
+ // capping at the average month length is close enough for an advisory.
115
+ days = Math.min(daysOfMonth.size, DAYS_PER_MONTH);
116
+ }
117
+ else if (everyDayOfMonth) {
118
+ days = daysOfWeek.size * WEEKS_PER_MONTH;
119
+ }
120
+ else {
121
+ // Restricting both means a day matching EITHER fires. Adding them can
122
+ // double-count a day that matches both, which errs high — the safe
123
+ // direction for a warning about cost.
124
+ days = Math.min(daysOfMonth.size + daysOfWeek.size * WEEKS_PER_MONTH, DAYS_PER_MONTH);
125
+ }
126
+ return minutes.size * hours.size * days * (months.size / MONTHS_PER_YEAR);
127
+ }
128
+ /**
129
+ * Human phrasing for a cron, or the expression itself when it names no exact
130
+ * time — a wrong description is worse than the raw expression.
131
+ */
132
+ export function describeCron(cron) {
133
+ const f = fields(cron);
134
+ if (f.length !== FIELD_COUNT)
135
+ return cron.trim();
136
+ const [minute, hour, dayOfMonth, , dayOfWeek] = f;
137
+ if (!isPinned(minute) || !isPinned(hour))
138
+ return cron.trim();
139
+ const at = `${hour.padStart(2, '0')}:${minute.padStart(2, '0')}`;
140
+ if (isWildcard(dayOfMonth) && isWildcard(dayOfWeek))
141
+ return `daily at ${at}`;
142
+ if (isWildcard(dayOfMonth) && isPinned(dayOfWeek)) {
143
+ return `weekly on ${dayName(Number(dayOfWeek))} at ${at}`;
144
+ }
145
+ if (isPinned(dayOfMonth) && isWildcard(dayOfWeek)) {
146
+ return `monthly on day ${Number(dayOfMonth)} at ${at}`;
147
+ }
148
+ return cron.trim();
149
+ }
150
+ /** Whole numbers read better here than decimals; under one, say it in words. */
151
+ function frequencyClause(runs) {
152
+ if (runs < 0.5)
153
+ return 'less than once a month';
154
+ return `~${Math.round(runs)} time(s)/month`;
155
+ }
156
+ /**
157
+ * Advisory shown before a schedule is created: how often it will run, and that
158
+ * each run is a full test run.
159
+ *
160
+ * States frequency only. Credit cost is deliberately not quoted — the API does
161
+ * not expose a per-action rate for the workspace wallet, and a figure derived
162
+ * from anything else would be wrong. Same reason `usage` does not print a
163
+ * "~N runs" estimate.
164
+ *
165
+ * An expression we cannot read still gets the advisory, without a frequency —
166
+ * the server is the authority on the cron, so refusing to say anything about a
167
+ * schedule we are about to create would be worse than saying less.
168
+ */
169
+ export function formatScheduleFrequencyAdvisory(cron) {
170
+ const tail = 'Each run is a full test run. Check your balance with `testsprite usage`.';
171
+ const runs = runsPerMonth(cron);
172
+ if (runs === null) {
173
+ return `This schedule will run on the cron \`${cron.trim()}\`. ${tail}`;
174
+ }
175
+ return `This schedule will run ${frequencyClause(runs)} (${describeCron(cron)}). ${tail}`;
176
+ }
177
+ const DAY_NAMES = [
178
+ 'Sunday',
179
+ 'Monday',
180
+ 'Tuesday',
181
+ 'Wednesday',
182
+ 'Thursday',
183
+ 'Friday',
184
+ 'Saturday',
185
+ ];
186
+ /** Cron allows both 0 and 7 for Sunday. */
187
+ function dayName(dow) {
188
+ return DAY_NAMES[dow % 7] ?? String(dow);
189
+ }
190
+ //# sourceMappingURL=cron.js.map
@@ -50,6 +50,15 @@ export interface DryRunSampleEntry {
50
50
  * `putPlanSteps`, `createTestBatch`) so their responses reflect the
51
51
  * user's actual flags rather than static canned values.
52
52
  */
53
+ /**
54
+ * Like {@link findSample}, but a missing sample throws instead of returning
55
+ * `undefined`. For dry-run paths that resolve samples DIRECTLY (bypassing the
56
+ * dry-run fetch impl, which has its own loud INTERNAL envelope for this):
57
+ * without the throw, a lost registry entry surfaces as a raw TypeError deep
58
+ * in a renderer (DEV-384 review F6 — `samples.ts` is a real merge-conflict
59
+ * hotspot, so a silently dropped entry is a live hazard, not a hypothetical).
60
+ */
61
+ export declare function findSampleOrThrow(method: string, url: string, requestBody?: unknown): DryRunSampleEntry;
53
62
  export declare function findSample(method: string, url: string, requestBody?: unknown): DryRunSampleEntry | undefined;
54
63
  /** Test-only export so `samples.test.ts` can iterate the catalog. */
55
64
  export declare const DRY_RUN_SAMPLE_ENTRIES: ReadonlyArray<DryRunSampleEntry>;
@@ -1,3 +1,4 @@
1
+ import { ApiError } from '../errors.js';
1
2
  import { buildJUnitReport } from '../junit-report.js';
2
3
  const SAMPLE_USER_ID = '11111111-1111-4111-8111-111111111111';
3
4
  const SAMPLE_KEY_ID = 'key_dryrun_2026';
@@ -7,6 +8,12 @@ const SAMPLE_TEST_ID_FAILED = 'test_8f2a4d10';
7
8
  const SAMPLE_TEST_ID_PASSED = 'test_3a91bb02';
8
9
  const SAMPLE_TEST_ID_BLOCKED = 'test_blocked_4f7a';
9
10
  export const SAMPLE_RUN_ID = 'run_abc';
11
+ const SAMPLE_SCHEDULE_ID = 'sch_7d21ac48';
12
+ const SAMPLE_SCHEDULE_RUN_ID = 'exec_5c08f1b2';
13
+ // Documented sentinel for `test steps --run-id run_failed_sample --dry-run`:
14
+ // keeps wait flows on the default passed sample while still demonstrating a
15
+ // run-scoped failed step offline.
16
+ const SAMPLE_FAILED_RUN_ID = 'run_failed_sample';
10
17
  // M3.4 rerun dry-run sample IDs
11
18
  const SAMPLE_RERUN_ID_BE_NAMED = 'run_rerun_be_named';
12
19
  const SAMPLE_RERUN_ID_BE_PRODUCER = 'run_rerun_be_producer';
@@ -87,6 +94,34 @@ const projects = [
87
94
  updatedAt: '2026-05-04T19:30:00.000Z',
88
95
  },
89
96
  ];
97
+ const schedule = {
98
+ scheduleId: SAMPLE_SCHEDULE_ID,
99
+ name: 'Nightly checkout',
100
+ enabled: true,
101
+ targetType: 'project',
102
+ targetId: SAMPLE_PROJECT_ID,
103
+ cron: '0 3 * * *',
104
+ timezone: 'UTC',
105
+ startAt: '2026-05-01T00:00:00.000Z',
106
+ endAt: null,
107
+ sendTo: null,
108
+ autoPausedAt: null,
109
+ lastRunId: SAMPLE_SCHEDULE_RUN_ID,
110
+ createdAt: '2026-05-01T00:00:00.000Z',
111
+ updatedAt: '2026-05-02T00:00:00.000Z',
112
+ };
113
+ // A finished run with one failure — more instructive for a dry-run learner than
114
+ // an all-green one, since it shows how the per-status counts relate to `status`.
115
+ const scheduleRun = {
116
+ runId: SAMPLE_SCHEDULE_RUN_ID,
117
+ scheduleId: SAMPLE_SCHEDULE_ID,
118
+ status: 'failed',
119
+ projectId: SAMPLE_PROJECT_ID,
120
+ testListId: null,
121
+ stats: { total: 4, passed: 3, failed: 1, blocked: 0, running: 0, cancelled: 0 },
122
+ createdAt: '2026-05-02T03:00:00.000Z',
123
+ updatedAt: '2026-05-02T03:06:41.000Z',
124
+ };
90
125
  const tests = [
91
126
  {
92
127
  id: SAMPLE_TEST_ID_FAILED,
@@ -293,10 +328,211 @@ const failureSummary = {
293
328
  rootCauseHypothesis: failureContext.failure.rootCauseHypothesis,
294
329
  recommendedFixTarget: failureContext.failure.recommendedFixTarget,
295
330
  };
331
+ const passedRunSample = {
332
+ runId: SAMPLE_RUN_ID,
333
+ testId: SAMPLE_TEST_ID_PASSED,
334
+ projectId: SAMPLE_PROJECT_ID,
335
+ userId: SAMPLE_USER_ID,
336
+ status: 'passed',
337
+ source: 'cli',
338
+ createdAt: '2026-05-15T19:32:00.000Z',
339
+ startedAt: '2026-05-15T19:32:05.000Z',
340
+ finishedAt: '2026-05-15T19:34:00.000Z',
341
+ codeVersion: 'v1',
342
+ targetUrl: SAMPLE_TARGET_URL,
343
+ createdFrom: null,
344
+ failedStepIndex: null,
345
+ failureKind: null,
346
+ error: null,
347
+ videoUrl: null,
348
+ stepSummary: {
349
+ total: 2,
350
+ completed: 2,
351
+ passedCount: 2,
352
+ failedCount: 0,
353
+ },
354
+ // Representative per-run steps so `test steps --run-id <id> --dry-run`
355
+ // demonstrates real output instead of an empty list (the generic
356
+ // `/runs/{runId}` sample is also used by `test wait`, which ignores steps).
357
+ steps: [
358
+ {
359
+ stepIndex: '0001',
360
+ type: 'action',
361
+ action: 'navigate',
362
+ status: 'passed',
363
+ description: 'Open the target URL',
364
+ error: null,
365
+ screenshotUrl: null,
366
+ htmlSnapshotUrl: null,
367
+ createdAt: '2026-05-15T19:32:10.000Z',
368
+ },
369
+ {
370
+ stepIndex: '0002',
371
+ type: 'assertion',
372
+ action: 'assert_visible',
373
+ status: 'passed',
374
+ description: 'Dashboard heading is visible',
375
+ error: null,
376
+ screenshotUrl: null,
377
+ htmlSnapshotUrl: null,
378
+ createdAt: '2026-05-15T19:32:20.000Z',
379
+ },
380
+ ],
381
+ };
382
+ const failedRunSample = {
383
+ runId: SAMPLE_FAILED_RUN_ID,
384
+ testId: SAMPLE_TEST_ID_FAILED,
385
+ projectId: SAMPLE_PROJECT_ID,
386
+ userId: SAMPLE_USER_ID,
387
+ status: 'failed',
388
+ source: 'cli',
389
+ createdAt: '2026-05-15T19:32:00.000Z',
390
+ startedAt: '2026-05-15T19:32:05.000Z',
391
+ finishedAt: '2026-05-15T19:34:00.000Z',
392
+ codeVersion: 'v1',
393
+ targetUrl: SAMPLE_TARGET_URL,
394
+ createdFrom: null,
395
+ failedStepIndex: 3,
396
+ failureKind: 'assertion',
397
+ error: 'Expected billing status badge to be visible, but it was not found.',
398
+ videoUrl: null,
399
+ stepSummary: {
400
+ total: 3,
401
+ completed: 3,
402
+ passedCount: 2,
403
+ failedCount: 1,
404
+ },
405
+ steps: [
406
+ {
407
+ stepIndex: '0001',
408
+ type: 'action',
409
+ action: 'navigate',
410
+ status: 'passed',
411
+ description: 'Open the target URL',
412
+ error: null,
413
+ screenshotUrl: null,
414
+ htmlSnapshotUrl: null,
415
+ createdAt: '2026-05-15T19:32:10.000Z',
416
+ },
417
+ {
418
+ stepIndex: '0002',
419
+ type: 'assertion',
420
+ action: 'assert_visible',
421
+ status: 'passed',
422
+ description: 'Dashboard heading is visible',
423
+ error: null,
424
+ screenshotUrl: null,
425
+ htmlSnapshotUrl: null,
426
+ createdAt: '2026-05-15T19:32:20.000Z',
427
+ },
428
+ {
429
+ stepIndex: '0003',
430
+ type: 'assertion',
431
+ action: 'assert_visible',
432
+ status: 'failed',
433
+ description: 'Billing status badge is visible',
434
+ error: 'Expected billing status badge to be visible, but it was not found.',
435
+ screenshotUrl: null,
436
+ htmlSnapshotUrl: null,
437
+ createdAt: '2026-05-15T19:32:30.000Z',
438
+ },
439
+ ],
440
+ };
296
441
  const PATH_PREFIX = '/api/cli/v1';
297
442
  const ENTRIES = [
298
443
  entry('whoami', 'GET', '/me', me),
299
444
  entry('listProjects', 'GET', '/projects', pageOf(projects)),
445
+ // DEV-384 V3-B — plan-generation surface. All three MUST be registered
446
+ // BEFORE `getProject`: findSample is first-match-wins and the projects/*
447
+ // family shares the `/projects/…` prefix, so the more specific plans
448
+ // paths are listed first (same defensive convention as `/tests/{id}/runs`
449
+ // before the `/tests/{id}` catch-all; `samples.test.ts` proves the
450
+ // ordering with shadowing tests).
451
+ //
452
+ // The trigger sample reports the PROPOSALS rung starting
453
+ // (`stagesRemaining: []`) and the plans sample shows the settled result
454
+ // (idle + two staged proposals), so a dry-run learner sees a coherent
455
+ // story: trigger → stage runs → staged batch with stable proposalIds.
456
+ entry('generatePlans', 'POST', '/projects/{projectId}/plans/generate', {
457
+ status: 'accepted',
458
+ projectId: SAMPLE_PROJECT_ID,
459
+ stage: 'proposals',
460
+ stagesRemaining: [],
461
+ enqueuedAt: '2026-07-28T09:00:00.000Z',
462
+ }),
463
+ // One frontend proposal (with action/assertion steps) and one backend
464
+ // proposal (with endpointPath/captures/consumes) so both wire shapes are
465
+ // learnable offline. `credits` shows the charged-actions breakdown the
466
+ // real facade fills best-effort.
467
+ entry('getPlans', 'GET', '/projects/{projectId}/plans', {
468
+ generation: { status: 'idle', errorCode: null, errorMessage: null },
469
+ proposals: [
470
+ {
471
+ proposalId: 'prop_1',
472
+ title: 'Login happy path',
473
+ description: 'Sign in with valid credentials and land on the dashboard.',
474
+ priority: 'p1',
475
+ category: 'auth',
476
+ feature: 'login',
477
+ type: 'frontend',
478
+ steps: [
479
+ { type: 'action', description: 'Enter valid credentials and submit the login form' },
480
+ { type: 'assertion', description: 'Dashboard heading is visible' },
481
+ ],
482
+ },
483
+ {
484
+ proposalId: 'prop_2',
485
+ title: 'Create order — success',
486
+ description: 'POST a valid order and capture its id for downstream tests.',
487
+ priority: 'p2',
488
+ category: 'orders',
489
+ feature: 'create-order',
490
+ type: 'backend',
491
+ endpointPath: '/v1/orders',
492
+ captures: ['orderId'],
493
+ consumes: ['authToken'],
494
+ },
495
+ ],
496
+ credits: {
497
+ charged: [
498
+ { action: 'strategy', amount: 1 },
499
+ { action: 'proposals', amount: 2 },
500
+ ],
501
+ balance: 147,
502
+ },
503
+ }),
504
+ // Input-derived: echoes the explicit id list the CLI always sends (never
505
+ // the omitted or empty forms — §3.3 safety rules), so `accept --only
506
+ // prop_2 --dry-run` shows acceptedCount: 1 rather than a canned 2.
507
+ entry('acceptPlans', 'POST', '/projects/{projectId}/plans/accept', (req) => {
508
+ const body = req != null && typeof req === 'object' ? req : {};
509
+ const only = Array.isArray(body.only)
510
+ ? body.only.filter((id) => typeof id === 'string')
511
+ : null;
512
+ const ids = only !== null && only.length > 0 ? only : ['prop_1', 'prop_2'];
513
+ return {
514
+ acceptedCount: ids.length,
515
+ caseKeys: ids.map(id => `case_dryrun_${id}`),
516
+ };
517
+ }),
518
+ // DEV-384 piece V3-D — `project docs upload` two-step facade routes.
519
+ // Registered BEFORE the broader project patterns (design doc §7 ordering
520
+ // rule; findSample is first-match-wins) and with `/docs/upload-url` before
521
+ // `/docs`. NOT consumed by the command's dry-run path: `project docs
522
+ // upload --dry-run` is an inline early-exit (zero network, stat only —
523
+ // the presigned S3 PUT leg cannot be expressed as a canned fetch sample).
524
+ // These are documentation/shape-guards, same family as `deleteBatch`.
525
+ entry('docsUploadUrl', 'POST', '/projects/{projectId}/docs/upload-url', {
526
+ uploadUrl: 'https://s3.dry-run.invalid/testsprite-usercontent/u_dryrun/p_dryrun_2026/openapi.yaml?X-Amz-Signature=dryrun',
527
+ s3Key: 'u_dryrun/p_dryrun_2026/openapi.yaml',
528
+ expiresInSeconds: 3600,
529
+ }),
530
+ entry('docsRegister', 'POST', '/projects/{projectId}/docs', {
531
+ resourceId: 'res_dryrun_2026',
532
+ displayName: 'openapi.yaml',
533
+ docRole: 'API_DOC',
534
+ processStatus: 'Pending',
535
+ }),
300
536
  entry('getProject', 'GET', '/projects/{projectId}', projects[0]),
301
537
  // P6 — POST /projects (create project). The id uses a stable dry-run
302
538
  // sentinel so agents can see a coherent field shape without a real key.
@@ -623,57 +859,8 @@ const ENTRIES = [
623
859
  // fix(2026-05-21): a duplicate failed-shape entry that appeared before
624
860
  // this entry was removed; findSample first-match-wins was always
625
861
  // returning status: "failed" for `test wait --dry-run`.
626
- entry('getRun', 'GET', '/runs/{runId}', {
627
- runId: SAMPLE_RUN_ID,
628
- testId: SAMPLE_TEST_ID_PASSED,
629
- projectId: SAMPLE_PROJECT_ID,
630
- userId: SAMPLE_USER_ID,
631
- status: 'passed',
632
- source: 'cli',
633
- createdAt: '2026-05-15T19:32:00.000Z',
634
- startedAt: '2026-05-15T19:32:05.000Z',
635
- finishedAt: '2026-05-15T19:34:00.000Z',
636
- codeVersion: 'v1',
637
- targetUrl: SAMPLE_TARGET_URL,
638
- createdFrom: null,
639
- failedStepIndex: null,
640
- failureKind: null,
641
- error: null,
642
- videoUrl: null,
643
- stepSummary: {
644
- total: 8,
645
- completed: 8,
646
- passedCount: 8,
647
- failedCount: 0,
648
- },
649
- // Representative per-run steps so `test steps --run-id <id> --dry-run`
650
- // demonstrates real output instead of an empty list (the generic
651
- // `/runs/{runId}` sample is also used by `test wait`, which ignores steps).
652
- steps: [
653
- {
654
- stepIndex: '0001',
655
- type: 'action',
656
- action: 'navigate',
657
- status: 'passed',
658
- description: 'Open the target URL',
659
- error: null,
660
- screenshotUrl: null,
661
- htmlSnapshotUrl: null,
662
- createdAt: '2026-05-15T19:32:10.000Z',
663
- },
664
- {
665
- stepIndex: '0002',
666
- type: 'assertion',
667
- action: 'assert_visible',
668
- status: 'passed',
669
- description: 'Dashboard heading is visible',
670
- error: null,
671
- screenshotUrl: null,
672
- htmlSnapshotUrl: null,
673
- createdAt: '2026-05-15T19:32:20.000Z',
674
- },
675
- ],
676
- }),
862
+ entry('getRun', 'GET', `/runs/${SAMPLE_FAILED_RUN_ID}`, failedRunSample),
863
+ entry('getRun', 'GET', '/runs/{runId}', passedRunSample),
677
864
  // DEV-331 piece 3 — POST /runs/{runId}/cancel. Method-guarded in
678
865
  // `findSample` (POST vs `getRun`'s GET), so this can't be shadowed by the
679
866
  // broader `/runs/{runId}` pattern above despite sharing its path prefix.
@@ -704,6 +891,35 @@ const ENTRIES = [
704
891
  },
705
892
  alreadyCancelled: false,
706
893
  }),
894
+ // Schedules. The `/schedules/{id}/runs` entry MUST come before the
895
+ // `/schedules/{id}` entries so the more specific path wins the regex match
896
+ // (first-match-wins).
897
+ entry('listScheduleRuns', 'GET', '/schedules/{scheduleId}/runs', {
898
+ runs: [scheduleRun],
899
+ }),
900
+ entry('listSchedules', 'GET', '/schedules', { schedules: [schedule] }),
901
+ // `schedule create --dry-run` exits before the HTTP client is built, so this
902
+ // sample is not fetched. Registered as a shape-guard only, same as
903
+ // `deleteBatch` above.
904
+ entry('createSchedule', 'POST', '/schedules', { scheduleId: 'sch_dryrun_2026' }),
905
+ entry('getSchedule', 'GET', '/schedules/{scheduleId}', schedule),
906
+ // Echoes the requested change so a caller can confirm the flags they passed
907
+ // reached the body, rather than showing an unrelated canned schedule.
908
+ entry('updateSchedule', 'PATCH', '/schedules/{scheduleId}', (req) => {
909
+ const patch = req != null && typeof req === 'object' ? req : {};
910
+ return {
911
+ ...schedule,
912
+ ...(typeof patch.name === 'string' ? { name: patch.name } : {}),
913
+ ...(typeof patch.enabled === 'boolean' ? { enabled: patch.enabled } : {}),
914
+ ...(typeof patch.cron === 'string' ? { cron: patch.cron } : {}),
915
+ ...(typeof patch.timezone === 'string' ? { timezone: patch.timezone } : {}),
916
+ ...(typeof patch.sendTo === 'string' ? { sendTo: patch.sendTo } : {}),
917
+ updatedAt: '2026-05-16T00:00:00.000Z',
918
+ };
919
+ }),
920
+ entry('deleteSchedule', 'DELETE', '/schedules/{scheduleId}', {
921
+ scheduleId: SAMPLE_SCHEDULE_ID,
922
+ }),
707
923
  ];
708
924
  function entry(operationId, method, pathTemplate, body) {
709
925
  // Convert `/tests/{testId}/code` → /^\/tests\/[^/]+\/code$/
@@ -737,15 +953,37 @@ function pageOf(items) {
737
953
  * `putPlanSteps`, `createTestBatch`) so their responses reflect the
738
954
  * user's actual flags rather than static canned values.
739
955
  */
956
+ /**
957
+ * Like {@link findSample}, but a missing sample throws instead of returning
958
+ * `undefined`. For dry-run paths that resolve samples DIRECTLY (bypassing the
959
+ * dry-run fetch impl, which has its own loud INTERNAL envelope for this):
960
+ * without the throw, a lost registry entry surfaces as a raw TypeError deep
961
+ * in a renderer (DEV-384 review F6 — `samples.ts` is a real merge-conflict
962
+ * hotspot, so a silently dropped entry is a live hazard, not a hypothetical).
963
+ */
964
+ export function findSampleOrThrow(method, url, requestBody) {
965
+ const entry = findSample(method, url, requestBody);
966
+ if (entry === undefined) {
967
+ throw ApiError.fromEnvelope({
968
+ error: {
969
+ code: 'INTERNAL',
970
+ message: `dry-run sample registry has no entry for ${method.toUpperCase()} ${extractPath(url)} — ` +
971
+ 'a sample was removed or shadowed in src/lib/dry-run/samples.ts (internal CLI bug).',
972
+ nextAction: 'Please report this to support@testsprite.com.',
973
+ requestId: SAMPLE_DRY_RUN_REQUEST_ID,
974
+ details: { method: method.toUpperCase(), path: extractPath(url) },
975
+ },
976
+ });
977
+ }
978
+ return entry;
979
+ }
740
980
  export function findSample(method, url, requestBody) {
741
981
  const upper = method.toUpperCase();
742
982
  const pathOnly = extractPath(url);
743
983
  for (const e of ENTRIES) {
744
984
  if (e.method === upper && e.pattern.test(pathOnly)) {
745
- // Rebind body so callers get the resolved value, not the factory.
746
- // We return a new object with `body` already applied so downstream
747
- // code can keep calling `e.body` as-before (no API break for tests
748
- // that call `findSample` directly).
985
+ // Rebind body so downstream code can call `e.body` as before while
986
+ // still preserving the original lazy factory semantics.
749
987
  return { ...e, body: () => e.body(requestBody) };
750
988
  }
751
989
  }
@@ -11,6 +11,15 @@ export declare function isErrorCode(value: unknown): value is ErrorCode;
11
11
  * not by exit code.
12
12
  */
13
13
  export declare function exitCodeFor(code: ErrorCode): number;
14
+ /**
15
+ * Whether an error code is an authentication failure. DERIVED from the single
16
+ * `exitCodeFor` mapping (auth === exit 3) rather than a second hand-maintained
17
+ * list of code strings: a future `AUTH_*` code gets classified as auth the
18
+ * moment it is given an exit-3 row, so it can never be present in one place and
19
+ * missing in the other. The `ERROR_CODES` membership check keeps `exitCodeFor`
20
+ * off unknown/out-of-contract strings (its switch has no default).
21
+ */
22
+ export declare function isAuthCode(code: string): boolean;
14
23
  export declare class CLIError extends Error {
15
24
  readonly exitCode: number;
16
25
  constructor(message: string, exitCode?: number);
@@ -102,6 +102,17 @@ export function exitCodeFor(code) {
102
102
  return 1;
103
103
  }
104
104
  }
105
+ /**
106
+ * Whether an error code is an authentication failure. DERIVED from the single
107
+ * `exitCodeFor` mapping (auth === exit 3) rather than a second hand-maintained
108
+ * list of code strings: a future `AUTH_*` code gets classified as auth the
109
+ * moment it is given an exit-3 row, so it can never be present in one place and
110
+ * missing in the other. The `ERROR_CODES` membership check keeps `exitCodeFor`
111
+ * off unknown/out-of-contract strings (its switch has no default).
112
+ */
113
+ export function isAuthCode(code) {
114
+ return ERROR_CODES.includes(code) && exitCodeFor(code) === 3;
115
+ }
105
116
  export class CLIError extends Error {
106
117
  exitCode;
107
118
  constructor(message, exitCode = 1) {