@testsprite/testsprite-cli 0.14.0 → 0.15.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 (40) hide show
  1. package/README.md +3 -1
  2. package/dist/commands/ci.d.ts +66 -17
  3. package/dist/commands/ci.js +466 -104
  4. package/dist/commands/doctor.d.ts +3 -0
  5. package/dist/commands/doctor.js +50 -9
  6. package/dist/commands/init.js +17 -3
  7. package/dist/commands/project.js +15 -1
  8. package/dist/commands/test.d.ts +74 -11
  9. package/dist/commands/test.js +579 -112
  10. package/dist/index.js +5 -1
  11. package/dist/lib/agent-targets.d.ts +8 -3
  12. package/dist/lib/agent-targets.js +15 -4
  13. package/dist/lib/ci-run.d.ts +11 -0
  14. package/dist/lib/ci-run.js +34 -0
  15. package/dist/lib/client-factory.d.ts +23 -0
  16. package/dist/lib/client-factory.js +7 -6
  17. package/dist/lib/config.d.ts +1 -0
  18. package/dist/lib/config.js +1 -1
  19. package/dist/lib/credentials.d.ts +0 -1
  20. package/dist/lib/credentials.js +51 -14
  21. package/dist/lib/dry-run/samples.js +42 -1
  22. package/dist/lib/first-suite-hint.d.ts +55 -0
  23. package/dist/lib/first-suite-hint.js +101 -0
  24. package/dist/lib/gh-output.d.ts +62 -4
  25. package/dist/lib/gh-output.js +149 -7
  26. package/dist/lib/github-context.d.ts +21 -0
  27. package/dist/lib/github-context.js +153 -0
  28. package/dist/lib/http.d.ts +10 -1
  29. package/dist/lib/http.js +9 -1
  30. package/dist/lib/plans.types.d.ts +1 -1
  31. package/dist/lib/response-schemas.d.ts +5 -1
  32. package/dist/lib/response-schemas.js +54 -0
  33. package/dist/lib/runs.types.d.ts +106 -0
  34. package/dist/lib/telemetry.d.ts +25 -1
  35. package/dist/lib/telemetry.js +45 -4
  36. package/dist/version.d.ts +1 -1
  37. package/dist/version.js +1 -1
  38. package/package.json +1 -1
  39. package/schemas/plan.schema.json +2 -2
  40. package/skills/testsprite-ci.skill.md +154 -0
package/dist/index.js CHANGED
@@ -75,7 +75,11 @@ program.addCommand(createTestCommand({
75
75
  },
76
76
  }));
77
77
  program.addCommand(createTestListCommand());
78
- program.addCommand(createCiCommand({}));
78
+ program.addCommand(createCiCommand({
79
+ onWaitTimeout: context => {
80
+ waitTimeoutTelemetry = context;
81
+ },
82
+ }));
79
83
  program.addCommand(createScheduleCommand({}));
80
84
  program.addCommand(createTunnelCommand({}));
81
85
  program.addCommand(createAgentCommand({}));
@@ -65,7 +65,12 @@ export interface SkillSpec {
65
65
  * `testsprite-onboard` codex contribution — a single always-on line. Kept here
66
66
  * (not in a `*.codex.md` asset) because it is one line; see {@link CodexContribution}.
67
67
  */
68
- export declare const ONBOARD_CODEX_LINE = "**First-time setup:** if this repo has no TestSprite tests yet, seed a *broad* first suite across its main user flows \u2014 not just one test \u2014 each with a concrete, observable assertion, before reporting setup as done.";
68
+ export declare const ONBOARD_CODEX_LINE = "**First-time setup:** if this repo has no TestSprite tests yet, seed a *broad* first suite across its main user flows \u2014 not just one test \u2014 each with a concrete, observable assertion, before reporting setup as done. Try `testsprite test plan generate --project <id>` then `test plan accept` first; author plans by hand only if generation is unavailable.";
69
+ /**
70
+ * `testsprite-ci` codex contribution — one always-on line; the full onboarding
71
+ * flow lives in the own-file body and the docs.
72
+ */
73
+ export declare const CI_CODEX_LINE = "**CI gate:** to run TestSprite on every pull request, use `testsprite ci init github --project <id> --env <name>`, finish the `REPLACE ME` step for how PRs deploy (platform-deployed previews \u2192 `on: deployment_status`; the workflow deploys \u2192 keep `pull_request`), set the `TESTSPRITE_API_KEY` secret, then prove it on one real, non-draft pull request. If the GitHub App already gates the project, ask before adding a second gate.";
69
74
  /**
70
75
  * The skill registry. Each entry owns its name, description (drift-guarded by a
71
76
  * byte-identity unit test against a template doc), own-file body asset, and codex
@@ -77,9 +82,9 @@ export declare const SKILLS: Record<string, SkillSpec>;
77
82
  /**
78
83
  * Skills installed by `setup` and by `agent install` when no `--skill` subset is
79
84
  * given. Order is significant for the codex aggregate (verify first, then the
80
- * onboard line as a short addendum).
85
+ * onboard and ci lines as short addenda).
81
86
  */
82
- export declare const DEFAULT_SKILLS: readonly ["testsprite-verify", "testsprite-onboard"];
87
+ export declare const DEFAULT_SKILLS: readonly ["testsprite-verify", "testsprite-onboard", "testsprite-ci"];
83
88
  /** @deprecated The canonical skill name. New code: iterate {@link SKILLS}. */
84
89
  export declare const SKILL_NAME = "testsprite-verify";
85
90
  /**
@@ -5,7 +5,12 @@ import { VERSION } from '../version.js';
5
5
  * `testsprite-onboard` codex contribution — a single always-on line. Kept here
6
6
  * (not in a `*.codex.md` asset) because it is one line; see {@link CodexContribution}.
7
7
  */
8
- export const ONBOARD_CODEX_LINE = '**First-time setup:** if this repo has no TestSprite tests yet, seed a *broad* first suite across its main user flows — not just one test — each with a concrete, observable assertion, before reporting setup as done.';
8
+ export const ONBOARD_CODEX_LINE = '**First-time setup:** if this repo has no TestSprite tests yet, seed a *broad* first suite across its main user flows — not just one test — each with a concrete, observable assertion, before reporting setup as done. Try `testsprite test plan generate --project <id>` then `test plan accept` first; author plans by hand only if generation is unavailable.';
9
+ /**
10
+ * `testsprite-ci` codex contribution — one always-on line; the full onboarding
11
+ * flow lives in the own-file body and the docs.
12
+ */
13
+ export const CI_CODEX_LINE = '**CI gate:** to run TestSprite on every pull request, use `testsprite ci init github --project <id> --env <name>`, finish the `REPLACE ME` step for how PRs deploy (platform-deployed previews → `on: deployment_status`; the workflow deploys → keep `pull_request`), set the `TESTSPRITE_API_KEY` secret, then prove it on one real, non-draft pull request. If the GitHub App already gates the project, ask before adding a second gate.';
9
14
  /**
10
15
  * The skill registry. Each entry owns its name, description (drift-guarded by a
11
16
  * byte-identity unit test against a template doc), own-file body asset, and codex
@@ -22,17 +27,23 @@ export const SKILLS = {
22
27
  },
23
28
  'testsprite-onboard': {
24
29
  name: 'testsprite-onboard',
25
- description: 'Stand up a complete, runnable TestSprite test suite for the current repo at first use — create a project (with a target URL and auth), derive a coherent set of tests from the codebase, batch-create them, and smoke-run a few to a green verdict so the user immediately has something worth running. Use ONLY when a repo has no TestSprite tests yet (a fresh project), right after `testsprite setup`, or when the user asks to "set up / bootstrap / seed tests". This is first-run setup, NOT change verification — once a project already has tests, use the testsprite-verify skill instead.',
30
+ description: 'Stand up a complete, runnable TestSprite test suite for the current repo at first use — create a project (with a target URL and auth), generate a coherent set of tests (or derive and batch-create them from the codebase), and smoke-run a few to a green verdict so the user has something worth running. Use ONLY when a repo has no TestSprite tests yet (a fresh project), right after `testsprite setup`, or when the user asks to "set up / bootstrap / seed tests". This is first-run setup, NOT change verification — once a project already has tests, use the testsprite-verify skill instead.',
26
31
  bodyFile: 'testsprite-onboard.skill.md',
27
32
  codex: { kind: 'line', text: ONBOARD_CODEX_LINE },
28
33
  },
34
+ 'testsprite-ci': {
35
+ name: 'testsprite-ci',
36
+ description: 'Gate pull requests with TestSprite in CI — work out how the repo deploys pull-request previews (platform-deployed → `on: deployment_status`; deployed in the workflow → `on: pull_request`), pick the environment the gate signs in with, generate the workflow with `testsprite ci init github`, finish its placeholder step, set the `TESTSPRITE_API_KEY` secret, and prove the gate on one real pull request. Use when the user asks to add TestSprite to CI or GitHub Actions, run the tests on every PR, or block merges on them. NOT for seeding a first suite (testsprite-onboard) or checking one change (testsprite-verify).',
37
+ bodyFile: 'testsprite-ci.skill.md',
38
+ codex: { kind: 'line', text: CI_CODEX_LINE },
39
+ },
29
40
  };
30
41
  /**
31
42
  * Skills installed by `setup` and by `agent install` when no `--skill` subset is
32
43
  * given. Order is significant for the codex aggregate (verify first, then the
33
- * onboard line as a short addendum).
44
+ * onboard and ci lines as short addenda).
34
45
  */
35
- export const DEFAULT_SKILLS = ['testsprite-verify', 'testsprite-onboard'];
46
+ export const DEFAULT_SKILLS = ['testsprite-verify', 'testsprite-onboard', 'testsprite-ci'];
36
47
  // ---------------------------------------------------------------------------
37
48
  // Back-compat single-skill exports (= the canonical `testsprite-verify` skill)
38
49
  // ---------------------------------------------------------------------------
@@ -0,0 +1,11 @@
1
+ import type { CiSummary } from './gh-output.js';
2
+ import type { RunConflict } from './conflict-reason.js';
3
+ import { type WaitMemberResult } from './wait-exit.js';
4
+ /** CI owns non-dispatch policy; operational poll failures retain their typed exit. */
5
+ export declare function resolveCiRunFailure(summary: CiSummary, accepted: readonly WaitMemberResult[], opts: {
6
+ timeoutSeconds: number;
7
+ allowEmpty?: boolean;
8
+ failOnSkipped?: boolean;
9
+ },
10
+ /** The batch's `conflicts[]`, with their reasons, when the caller has them. */
11
+ conflicts?: readonly RunConflict[]): Error | null;
@@ -0,0 +1,34 @@
1
+ import { CLIError } from './errors.js';
2
+ import { resolveWaitFailure } from './wait-exit.js';
3
+ /** CI owns non-dispatch policy; operational poll failures retain their typed exit. */
4
+ export function resolveCiRunFailure(summary, accepted, opts,
5
+ /** The batch's `conflicts[]`, with their reasons, when the caller has them. */
6
+ conflicts = []) {
7
+ const missing = summary.runs.filter(row => row.status === 'not_found');
8
+ if (missing.length > 0) {
9
+ return new CLIError(`Tests not found: ${missing.map(row => row.testId).join(', ')}`, 4);
10
+ }
11
+ const failure = resolveWaitFailure(accepted, opts);
12
+ if (failure)
13
+ return failure;
14
+ if (accepted.length === 0) {
15
+ // `--allow-empty` covers an empty selection: no tests, a filter that
16
+ // matched nothing, or runs already in flight elsewhere. A batch the
17
+ // backend REFUSED — an unknown environment, an un-runnable one, a
18
+ // view-only mirror, a billing hold — is not empty, and reading it as
19
+ // green is the false-green shape a gate exists to prevent.
20
+ const refused = conflicts.filter(c => c.reason !== undefined && c.reason !== 'in_flight' && c.reason !== 'not_found');
21
+ if (refused.length > 0) {
22
+ const first = refused[0];
23
+ return new CLIError(`No tests were dispatched: ${refused.length} refused (${first.reason}${first.message ? `: ${first.message}` : ''}).`, 5);
24
+ }
25
+ if (!opts.allowEmpty) {
26
+ return new CLIError('No tests were dispatched. Pass --allow-empty to allow an empty CI run.', 5);
27
+ }
28
+ }
29
+ if (summary.skipped > 0 && opts.failOnSkipped) {
30
+ return new CLIError(`${summary.skipped} tests were skipped (--fail-on-skipped).`, 1);
31
+ }
32
+ return null;
33
+ }
34
+ //# sourceMappingURL=ci-run.js.map
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Shared `HttpClient` factory used by every M2 command. Two reasons for
3
+ * the extraction:
4
+ *
5
+ * 1. Three command files (`auth`, `project`, `test`) had byte-equivalent
6
+ * `makeClient` helpers — drift between them would silently change
7
+ * behavior depending on which command you called.
8
+ * 2. P6's `--dry-run` branch needs to bypass `loadConfig` (so it works
9
+ * with no `~/.testsprite/credentials`) and substitute a canned-fetch
10
+ * impl. Doing that once here is safer than three near-copies.
11
+ *
12
+ * The factory is intentionally narrow: it only takes the HTTP-relevant
13
+ * deps. Per-command deps (auth's `prompt`, test's `rawStdout`) stay
14
+ * with the command.
15
+ */
16
+ import { type Config } from './config.js';
1
17
  import type { DebugEvent, FetchImpl, HttpClientOptions } from './http.js';
2
18
  import { HttpClient } from './http.js';
3
19
  import { type ShutdownHandle } from './interrupt.js';
@@ -48,6 +64,13 @@ export interface ClientFactoryDeps {
48
64
  * in-flight request; tests inject their own controller's signal.
49
65
  */
50
66
  shutdownSignal?: AbortSignal;
67
+ /**
68
+ * Pre-resolved config. When supplied, the factory skips its own `loadConfig`
69
+ * call entirely. Callers that already resolved config (e.g. doctor, which
70
+ * must survive an unreadable credentials file) pass it through so the client
71
+ * never re-reads — and re-fails on — the file.
72
+ */
73
+ config?: Config;
51
74
  /** Defaults to `globalShutdown` so disarmed signals can see in-flight requests. */
52
75
  shutdown?: Pick<ShutdownHandle, 'runCriticalOperation'>;
53
76
  }
@@ -242,12 +242,13 @@ function resolveHttpClientOptions(opts, deps) {
242
242
  };
243
243
  }
244
244
  const credentialsPath = deps.credentialsPath ?? defaultCredentialsPath();
245
- const config = loadConfig({
246
- profile: opts.profile,
247
- endpointUrl: opts.endpointUrl,
248
- env,
249
- credentialsPath,
250
- });
245
+ const config = deps.config ??
246
+ loadConfig({
247
+ profile: opts.profile,
248
+ endpointUrl: opts.endpointUrl,
249
+ env,
250
+ credentialsPath,
251
+ });
251
252
  // Catch a malformed endpoint (from --endpoint-url / TESTSPRITE_API_URL /
252
253
  // credentials) before the auth check so a config typo surfaces as a clear
253
254
  // VALIDATION_ERROR rather than an opaque URL throw or a retried "fetch failed".
@@ -9,6 +9,7 @@ export interface LoadConfigOptions {
9
9
  env?: NodeJS.ProcessEnv;
10
10
  credentialsPath?: string;
11
11
  }
12
+ export declare const DEFAULT_API_URL = "https://api.testsprite.com";
12
13
  /** Treat empty / whitespace-only env values as unset for `??` resolution chains. */
13
14
  export declare function normalizeEnvVar(value: string | undefined): string | undefined;
14
15
  export declare function defaultConfigPath(): string;
@@ -1,7 +1,7 @@
1
1
  import { homedir } from 'node:os';
2
2
  import { join } from 'node:path';
3
3
  import { DEFAULT_PROFILE, defaultCredentialsPath, readProfile } from './credentials.js';
4
- const DEFAULT_API_URL = 'https://api.testsprite.com';
4
+ export const DEFAULT_API_URL = 'https://api.testsprite.com';
5
5
  /** Treat empty / whitespace-only env values as unset for `??` resolution chains. */
6
6
  export function normalizeEnvVar(value) {
7
7
  return value?.trim() || undefined;
@@ -22,7 +22,6 @@ type CredentialsWritePermissionError = NodeJS.ErrnoException & {
22
22
  export declare function isCredentialsWritePermissionError(error: unknown): error is CredentialsWritePermissionError;
23
23
  interface RestrictiveModeOptions {
24
24
  platform?: NodeJS.Platform;
25
- env?: NodeJS.ProcessEnv;
26
25
  spawnSync?: (command: string, args: readonly string[], options: {
27
26
  shell: false;
28
27
  stdio: 'ignore';
@@ -63,6 +63,8 @@ const CREDENTIALS_LOCK_WAIT_MS = 5_000;
63
63
  // problem and is surfaced as such.
64
64
  const CREDENTIALS_LOCK_TRANSIENT_WAIT_MS = 1_000;
65
65
  const CREDENTIALS_LOCK_STALE_MS = 30_000;
66
+ // How long a transient Windows error on replacing the credentials file is retried.
67
+ const CREDENTIALS_RENAME_TRANSIENT_WAIT_MS = 2_000;
66
68
  export function parseCredentials(content) {
67
69
  const result = {};
68
70
  let currentEntry = null;
@@ -181,27 +183,43 @@ export function ensureRestrictiveMode(path, options = {}) {
181
183
  chmodSync(path, 0o600);
182
184
  }
183
185
  /**
184
- * Restrict a Windows credentials file to the current user using icacls.
186
+ * Restrict a Windows credentials file to the file owner using icacls.
185
187
  * The command is invoked with an args array so credential paths are never shell-interpreted.
188
+ *
189
+ * Uses /reset to clear any broken inheritance state, followed by
190
+ * /inheritance:r /grant:r *S-1-3-4:F which decouples the file from parent ACLs
191
+ * and grants Full Control to the OWNER RIGHTS SID (S-1-3-4). This avoids
192
+ * dependency on resolving %USERNAME% (which fails on Microsoft Account or
193
+ * domain-joined machines).
186
194
  */
187
195
  function ensureWindowsRestrictiveAcl(path, options) {
188
- const username = (options.env ?? process.env).USERNAME?.trim();
189
- if (!username) {
190
- warnWindowsAcl('could not determine the Windows username; credentials file permissions were not tightened', options);
191
- return;
192
- }
193
196
  const run = options.spawnSync ?? spawnSync;
194
- const result = run('icacls', [path, '/inheritance:r', '/grant:r', `${username}:F`], {
197
+ const icaclsOptions = {
195
198
  shell: false,
196
199
  stdio: 'ignore',
197
200
  windowsHide: true,
198
- });
199
- if (result.error) {
200
- warnWindowsAcl(`icacls failed while tightening credentials file permissions: ${result.error.message}`, options);
201
+ };
202
+ const resetResult = run('icacls', [path, '/reset'], icaclsOptions);
203
+ if (resetResult.error) {
204
+ warnWindowsAcl(`icacls failed while resetting credentials file permissions: ${resetResult.error.message}`, options);
201
205
  return;
202
206
  }
203
- if (result.status !== 0) {
204
- warnWindowsAcl(`icacls exited with status ${result.status ?? 'unknown'}; credentials file permissions may be too broad`, options);
207
+ if (resetResult.status !== 0) {
208
+ warnWindowsAcl(`icacls /reset exited with status ${resetResult.status ?? 'unknown'}; credentials file permissions may be too broad`, options);
209
+ return;
210
+ }
211
+ // The trailing :F is load-bearing, not incidental: after /inheritance:r the
212
+ // file carries exactly this one ACE, and Full Control is what leaves
213
+ // WRITE_DAC with the owner — which is what makes a later `icacls /reset`
214
+ // possible at all. Tightening this to :R would leave the file unrepairable
215
+ // without taking ownership.
216
+ const grantResult = run('icacls', [path, '/inheritance:r', '/grant:r', '*S-1-3-4:F'], icaclsOptions);
217
+ if (grantResult.error) {
218
+ warnWindowsAcl(`icacls failed while tightening credentials file permissions: ${grantResult.error.message}`, options);
219
+ return;
220
+ }
221
+ if (grantResult.status !== 0) {
222
+ warnWindowsAcl(`icacls exited with status ${grantResult.status ?? 'unknown'}; credentials file permissions may be too broad`, options);
205
223
  }
206
224
  }
207
225
  /** Emit an explicit warning when Windows ACL tightening cannot be completed. */
@@ -238,8 +256,7 @@ function writeCredentialsAtomic(path, file) {
238
256
  try {
239
257
  // eslint-disable-next-line security/detect-non-literal-fs-filename -- `tmp` is `${path}.tmp.${pid}`, derived from the same internal credentials-file path; same baselined risk profile as the other fs calls in this file.
240
258
  writeFileSync(tmp, serializeCredentials(file), { mode: 0o600, encoding: 'utf8' });
241
- // eslint-disable-next-line security/detect-non-literal-fs-filename -- both operands derive from the internal credentials-file path (see above).
242
- renameSync(tmp, path);
259
+ renameCredentialsFile(tmp, path);
243
260
  }
244
261
  catch (error) {
245
262
  try {
@@ -259,6 +276,26 @@ function writeCredentialsAtomic(path, file) {
259
276
  }
260
277
  ensureRestrictiveMode(path);
261
278
  }
279
+ /**
280
+ * Replace the credentials file with the temp file. On Windows a transient
281
+ * EPERM/EBUSY/EACCES (another program briefly holding the file) is retried for a
282
+ * short window; anything else, or an error that persists, is thrown.
283
+ */
284
+ function renameCredentialsFile(tmp, path) {
285
+ const deadline = Date.now() + CREDENTIALS_RENAME_TRANSIENT_WAIT_MS;
286
+ while (true) {
287
+ try {
288
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- both operands derive from the internal credentials-file path (see writeCredentialsAtomic).
289
+ renameSync(tmp, path);
290
+ return;
291
+ }
292
+ catch (error) {
293
+ if (!isWindowsLockContention(error) || Date.now() >= deadline)
294
+ throw error;
295
+ sleepSync(CREDENTIALS_LOCK_RETRY_MS);
296
+ }
297
+ }
298
+ }
262
299
  function acquireCredentialsLock(path) {
263
300
  const lockPath = `${path}.lock`;
264
301
  const deadline = Date.now() + CREDENTIALS_LOCK_WAIT_MS;
@@ -134,7 +134,7 @@ const tests = [
134
134
  createdFrom: 'portal',
135
135
  status: 'failed',
136
136
  // G1a — priority label shown on one row so dry-run learners see the field.
137
- priority: 'p1',
137
+ priority: 'Medium',
138
138
  createdAt: '2026-04-20T11:00:00.000Z',
139
139
  updatedAt: '2026-05-05T12:34:56.000Z',
140
140
  details: {
@@ -331,6 +331,44 @@ const failureSummary = {
331
331
  rootCauseHypothesis: failureContext.failure.rootCauseHypothesis,
332
332
  recommendedFixTarget: failureContext.failure.recommendedFixTarget,
333
333
  };
334
+ const SAMPLE_EXECUTION_ID = 'exec_dryrun0001';
335
+ /** A ready execution report: one failed and one passed row, the App's Markdown shape in miniature. */
336
+ const executionReportSample = {
337
+ ready: true,
338
+ report: {
339
+ projectId: SAMPLE_PROJECT_ID,
340
+ executionId: SAMPLE_EXECUTION_ID,
341
+ projectName: 'Sample project',
342
+ orgId: null,
343
+ stats: { passed: 1, failed: 1, blocked: 0, total: 2 },
344
+ allPassed: false,
345
+ narrative: 'Dry-run sample: one regression in checkout, login passed.',
346
+ whatCouldBeBetter: 'Add coverage for password reset.',
347
+ recommendedNextStep: 'Fix the checkout selector and rerun.',
348
+ tests: [
349
+ {
350
+ id: SAMPLE_RUN_ID,
351
+ title: 'Checkout applies a coupon',
352
+ slug: 'CHK-002',
353
+ status: 'FAILED',
354
+ screenshotUrl: null,
355
+ error: 'AssertionError: expected the order total to drop',
356
+ fix: 'Apply the coupon before computing the total.',
357
+ },
358
+ {
359
+ id: `${SAMPLE_RUN_ID}-2`,
360
+ title: 'Login with a valid account',
361
+ slug: 'AUTH-001',
362
+ status: 'PASSED',
363
+ screenshotUrl: null,
364
+ error: null,
365
+ fix: null,
366
+ },
367
+ ],
368
+ resultUrl: `https://www.testsprite.com/dashboard-v3/projects/${SAMPLE_PROJECT_ID}/execution/${SAMPLE_EXECUTION_ID}`,
369
+ },
370
+ markdown: '> [!WARNING]\n> ### Ran into trouble — 1 failed\n>\n> Dry-run sample: one regression in checkout, login passed.\n',
371
+ };
334
372
  const passedRunSample = {
335
373
  runId: SAMPLE_RUN_ID,
336
374
  testId: SAMPLE_TEST_ID_PASSED,
@@ -647,6 +685,9 @@ const ENTRIES = [
647
685
  entry('getTestCode', 'GET', '/tests/{testId}/code', testCode),
648
686
  entry('listTestSteps', 'GET', '/tests/{testId}/steps', pageOf(testSteps)),
649
687
  entry('getTestResult', 'GET', '/tests/{testId}/result', latestResult),
688
+ // Execution report — static `executions/` prefix, four segments, so no
689
+ // `/tests/{testId}/…` pattern can shadow it; kept beside the other reads.
690
+ entry('getExecutionReport', 'GET', '/tests/executions/{executionId}/report', executionReportSample),
650
691
  // `/failure/summary` MUST come before `/failure` so the regex matcher
651
692
  // doesn't shadow it with the bundle endpoint.
652
693
  entry('getTestFailureSummary', 'GET', '/tests/{testId}/failure/summary', failureSummary),
@@ -0,0 +1,55 @@
1
+ /**
2
+ * "You have a project, but no tests yet" signposts.
3
+ *
4
+ * A user who is not driving a coding agent otherwise never learns that
5
+ * `test plan generate` exists: `project create` used to print the record and
6
+ * stop, and the empty-project outputs said only "No tests." Every variant also
7
+ * names the hand-authored fallback, because an account not yet on the new
8
+ * platform is refused by generate and pointed at the Portal.
9
+ *
10
+ * Text mode only at every call site: a JSON caller already holds the project
11
+ * id, and stdout and the JSON error envelope must stay unchanged. Never under
12
+ * --dry-run (the id there is the canned sample). Printing a hint runs and
13
+ * charges nothing; the generation it points at does use credits.
14
+ *
15
+ * Zero requests: each call site branches only on what it already knows.
16
+ * `project create` knows the type and whether the app is local; `test run
17
+ * --all --local` knows it is local. `test list` and a cloud `test run --all`
18
+ * know neither, so their sentence names the backend prerequisite as a clause
19
+ * and leaves a local project to the backend's own pre-charge refusal, which
20
+ * carries the same hand-written-plan next step.
21
+ */
22
+ import { type StoredLocalTarget } from './local-target.js';
23
+ /**
24
+ * How the run that found the project empty chose its local target, so the
25
+ * suggested `test run` reaches the same app with the same environment:
26
+ * `port`/`host` only for an explicit `--local`, `targetUrl` for an explicit
27
+ * `--target-url`, and `environment` for `--env` or the saved environment the
28
+ * tunnel was resolved from.
29
+ */
30
+ export type LocalHint = {
31
+ host?: StoredLocalTarget['host'];
32
+ port?: number;
33
+ targetUrl?: string;
34
+ environment?: string;
35
+ };
36
+ export declare const FIRST_SUITE_FALLBACK = "testsprite test create --plan-template";
37
+ /**
38
+ * Multi-line `[hint]` block for stderr after a real `project create` of a
39
+ * deployed (non-`--local`) project. A `--local` project gets no hint here:
40
+ * its text record already ends with the hand-written-plan next steps (plan
41
+ * generation explores from the cloud with no tunnel, and the backend refuses
42
+ * it for a local-origin project before any charge), and two "Next" blocks
43
+ * would disagree.
44
+ */
45
+ export declare function firstSuiteNextSteps(projectId: string, type: string): string;
46
+ /**
47
+ * One sentence for an EMPTY project; folded into an error message or a hint.
48
+ *
49
+ * Pass `local` only where the caller knows the project runs on this machine
50
+ * (`test run --all --local`); see the module comment for why the other
51
+ * callers cannot.
52
+ */
53
+ export declare function emptyProjectNextStep(projectId: string, local?: LocalHint | null): string;
54
+ /** The same sentence as a stderr `[hint]` line. */
55
+ export declare function emptyProjectHint(projectId: string, local?: LocalHint | null): string;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * "You have a project, but no tests yet" signposts.
3
+ *
4
+ * A user who is not driving a coding agent otherwise never learns that
5
+ * `test plan generate` exists: `project create` used to print the record and
6
+ * stop, and the empty-project outputs said only "No tests." Every variant also
7
+ * names the hand-authored fallback, because an account not yet on the new
8
+ * platform is refused by generate and pointed at the Portal.
9
+ *
10
+ * Text mode only at every call site: a JSON caller already holds the project
11
+ * id, and stdout and the JSON error envelope must stay unchanged. Never under
12
+ * --dry-run (the id there is the canned sample). Printing a hint runs and
13
+ * charges nothing; the generation it points at does use credits.
14
+ *
15
+ * Zero requests: each call site branches only on what it already knows.
16
+ * `project create` knows the type and whether the app is local; `test run
17
+ * --all --local` knows it is local. `test list` and a cloud `test run --all`
18
+ * know neither, so their sentence names the backend prerequisite as a clause
19
+ * and leaves a local project to the backend's own pre-charge refusal, which
20
+ * carries the same hand-written-plan next step.
21
+ */
22
+ import { quoteEnvironmentName } from './environment-tunnel.js';
23
+ import { DEFAULT_LOCAL_HOST } from './local-target.js';
24
+ export const FIRST_SUITE_FALLBACK = 'testsprite test create --plan-template';
25
+ /**
26
+ * `test run <test-id>` with the target flags the empty run was given. A bare
27
+ * `test run` would resolve the project's DEFAULT environment, which may be a
28
+ * deployed site rather than the app on this machine, so the environment is
29
+ * always named when one was used. `--local-host` is carried whenever the host
30
+ * is not the default: without it a `::1` or `localhost` app would be run
31
+ * against 127.0.0.1.
32
+ */
33
+ function localRunCommand(local) {
34
+ const flags = [];
35
+ if (local.targetUrl !== undefined) {
36
+ flags.push(`--target-url ${shellWord(local.targetUrl)}`);
37
+ }
38
+ else if (local.port !== undefined) {
39
+ flags.push(`--local ${local.port}`);
40
+ if (local.host !== undefined && local.host !== DEFAULT_LOCAL_HOST)
41
+ flags.push(`--local-host ${local.host}`);
42
+ }
43
+ if (local.environment !== undefined)
44
+ flags.push(`--env ${quoteEnvironmentName(local.environment)}`);
45
+ return ['testsprite test run <test-id>', ...flags].join(' ');
46
+ }
47
+ /** A URL as one shell word: as typed when it is plain, single-quoted otherwise. */
48
+ function shellWord(value) {
49
+ return /^[\w.:/@%+=,~-]+$/.test(value) ? value : quoteEnvironmentName(value);
50
+ }
51
+ /**
52
+ * Multi-line `[hint]` block for stderr after a real `project create` of a
53
+ * deployed (non-`--local`) project. A `--local` project gets no hint here:
54
+ * its text record already ends with the hand-written-plan next steps (plan
55
+ * generation explores from the cloud with no tunnel, and the backend refuses
56
+ * it for a local-origin project before any charge), and two "Next" blocks
57
+ * would disagree.
58
+ */
59
+ export function firstSuiteNextSteps(projectId, type) {
60
+ const backend = type === 'backend';
61
+ const lead = backend
62
+ ? 'Next: upload your API spec, then let TestSprite propose your first tests (uses credits), review them, then accept:'
63
+ : 'Next: let TestSprite propose your first tests (uses credits), review them, then accept:';
64
+ const steps = [
65
+ ...(backend ? [`testsprite project docs upload <api-spec.yaml> --project ${projectId}`] : []),
66
+ `testsprite test plan generate --project ${projectId}`,
67
+ `testsprite test plan accept --project ${projectId}`,
68
+ ];
69
+ return [
70
+ `[hint] ${lead}`,
71
+ ...steps.map(s => ` ${s}`),
72
+ ` Prefer to write one yourself: ${FIRST_SUITE_FALLBACK}`,
73
+ ].join('\n');
74
+ }
75
+ /**
76
+ * One sentence for an EMPTY project; folded into an error message or a hint.
77
+ *
78
+ * Pass `local` only where the caller knows the project runs on this machine
79
+ * (`test run --all --local`); see the module comment for why the other
80
+ * callers cannot.
81
+ */
82
+ export function emptyProjectNextStep(projectId, local) {
83
+ if (local) {
84
+ return (`This project has no tests yet, and plan generation cannot reach an app on your machine yet. ` +
85
+ `Write a plan yourself: ${FIRST_SUITE_FALLBACK} > first.plan.json, ` +
86
+ `set projectId to ${projectId} in it and edit the steps, create it with ` +
87
+ `testsprite test create --plan-from first.plan.json, ` +
88
+ `then run it with ${localRunCommand(local)}`);
89
+ }
90
+ return (`This project has no tests yet. Get a first set: ` +
91
+ `testsprite test plan generate --project ${projectId}, then ` +
92
+ `testsprite test plan accept --project ${projectId} ` +
93
+ `(generation uses credits; a backend project needs its API spec uploaded first: ` +
94
+ `testsprite project docs upload <spec> --project ${projectId}). ` +
95
+ `Or write one yourself: ${FIRST_SUITE_FALLBACK}`);
96
+ }
97
+ /** The same sentence as a stderr `[hint]` line. */
98
+ export function emptyProjectHint(projectId, local) {
99
+ return `[hint] ${emptyProjectNextStep(projectId, local)}`;
100
+ }
101
+ //# sourceMappingURL=first-suite-hint.js.map
@@ -1,3 +1,4 @@
1
+ import type { ExecutionReport } from './runs.types.js';
1
2
  /**
2
3
  * CI-native output layer for the run path (issue #99, reshaped from
3
4
  * the withdrawn top-level `ci` command per the #264 review). Covers both a
@@ -42,6 +43,12 @@ export interface CiSummary {
42
43
  skipped: number;
43
44
  timedOut: number;
44
45
  runs: CiRunRow[];
46
+ /**
47
+ * The server's execution report (the GitHub App comment content) when the
48
+ * backend could provide one for this batch. Absent otherwise — never null —
49
+ * so a summary from an older backend is byte-identical to before.
50
+ */
51
+ executionReport?: ExecutionReport;
45
52
  }
46
53
  export declare function isNonDispatchedStatus(status: string): boolean;
47
54
  /**
@@ -55,12 +62,17 @@ export declare function isNonDispatchedStatus(status: string): boolean;
55
62
  * cannot read as "1/1 passed" with no annotation — but it counts as `skipped`,
56
63
  * never `failed`: whether non-dispatch fails the job is the exit-code
57
64
  * gates' call, and a `failed` count the gates disagree with is exactly the
58
- * artifacts-contradict-the-exit bug. (`skippedFrontend` / `skippedIntegration`
59
- * are NOT folded in — they exit 0 and are the Action layer's allow-partial
60
- * concern.)
65
+ * artifacts-contradict-the-exit bug.
66
+ *
67
+ * `skippedFrontend` / `skippedIntegration` are folded in only under
68
+ * `foldSkippedBuckets` (the `ci run` contract: ONE skipped number covering
69
+ * everything requested but not run). Default off — for `test run --all` they
70
+ * exit 0 and are the Action layer's allow-partial concern, and changing that
71
+ * default would silently change its artifacts.
61
72
  */
62
73
  export declare function summarizeAcceptedPayload(capturedJson: string, opts?: {
63
74
  notFoundNote?: string;
75
+ foldSkippedBuckets?: boolean;
64
76
  }): CiSummary;
65
77
  /**
66
78
  * Reduce a single `test run <test-id> --wait` result into the same CI summary
@@ -106,6 +118,11 @@ export declare function emitGithubOutputs(summary: CiSummary, env: NodeJS.Proces
106
118
  }, opts?: {
107
119
  force?: boolean;
108
120
  label?: string;
121
+ /**
122
+ * Pre-rendered job-summary Markdown (the execution report) that replaces
123
+ * the local results table when the backend provided one.
124
+ */
125
+ markdown?: string;
109
126
  }): void;
110
127
  /**
111
128
  * Emit the CI artifacts for a `--wait` run: the machine summary file (when
@@ -128,4 +145,45 @@ export declare function emitCiArtifacts(summary: CiSummary, opts: {
128
145
  env: NodeJS.ProcessEnv;
129
146
  stdout: (line: string) => void;
130
147
  stderr: (line: string) => void;
131
- }, label: string): void;
148
+ }, label: string, extra?: {
149
+ markdown?: string;
150
+ }): void;
151
+ /**
152
+ * Hand the execution report to later steps: its JSON and Markdown are written
153
+ * under `$RUNNER_TEMP` (else the OS temp dir) and their paths appended to
154
+ * `$GITHUB_OUTPUT` as `execution-report-file` / `execution-report-markdown-file`.
155
+ * Paths, not bodies — a step output is capped at 1 MiB and multi-line values
156
+ * need heredoc escaping. No-op without `GITHUB_OUTPUT` (nothing can consume
157
+ * them). Best-effort: a write failure is reported and never masks the gate.
158
+ */
159
+ export declare function emitExecutionReportOutputs(ready: {
160
+ report: ExecutionReport;
161
+ markdown: string;
162
+ }, io: {
163
+ env: NodeJS.ProcessEnv;
164
+ stderr: (line: string) => void;
165
+ }): {
166
+ jsonPath: string;
167
+ markdownPath: string;
168
+ } | undefined;
169
+ /**
170
+ * The job-summary Markdown for a batch that has a server execution report.
171
+ *
172
+ * The exit code comes from the CLI's own poll of every run plus whatever did
173
+ * not dispatch; the report describes only the execution. Usually they agree
174
+ * and the summary is the report, byte for byte the App's comment. When they
175
+ * do not — a run the CLI could not read or that timed out, a test refused
176
+ * before dispatch, a retry error — the report alone would read "all passed"
177
+ * under a red check, so the local verdict is stated first and the rows the
178
+ * report cannot contain are appended. A red run whose failures the report
179
+ * also shows agrees — the counts match — and keeps the App's comment as is.
180
+ */
181
+ export declare function reconcileExecutionReportMarkdown(summary: CiSummary, ready: {
182
+ report: ExecutionReport;
183
+ markdown: string;
184
+ }): string;
185
+ /** Numeric step outputs share the exact counters used by every other CI sink. */
186
+ export declare function emitCiStepOutputs(summary: CiSummary, io: {
187
+ env: NodeJS.ProcessEnv;
188
+ stderr: (line: string) => void;
189
+ }): void;