@testsprite/testsprite-cli 0.14.0 → 0.16.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 (61) hide show
  1. package/README.md +27 -17
  2. package/dist/commands/agent.js +7 -2
  3. package/dist/commands/auth.js +7 -3
  4. package/dist/commands/ci.d.ts +66 -17
  5. package/dist/commands/ci.js +486 -122
  6. package/dist/commands/completion.js +2 -1
  7. package/dist/commands/doctor.d.ts +3 -0
  8. package/dist/commands/doctor.js +52 -10
  9. package/dist/commands/init.js +25 -5
  10. package/dist/commands/project-env.js +39 -17
  11. package/dist/commands/project-sign-in.js +9 -4
  12. package/dist/commands/project.js +43 -22
  13. package/dist/commands/schedule.js +24 -15
  14. package/dist/commands/test.d.ts +105 -36
  15. package/dist/commands/test.js +1494 -847
  16. package/dist/commands/testlist.js +13 -3
  17. package/dist/commands/tunnel.js +23 -25
  18. package/dist/commands/usage.js +1 -0
  19. package/dist/index.js +14 -7
  20. package/dist/lib/agent-targets.d.ts +8 -3
  21. package/dist/lib/agent-targets.js +15 -4
  22. package/dist/lib/ci-run.d.ts +11 -0
  23. package/dist/lib/ci-run.js +34 -0
  24. package/dist/lib/client-factory.d.ts +23 -0
  25. package/dist/lib/client-factory.js +7 -6
  26. package/dist/lib/config.d.ts +1 -0
  27. package/dist/lib/config.js +1 -1
  28. package/dist/lib/conflict-reason.d.ts +24 -3
  29. package/dist/lib/conflict-reason.js +33 -2
  30. package/dist/lib/credentials.d.ts +0 -1
  31. package/dist/lib/credentials.js +51 -14
  32. package/dist/lib/deprecate.d.ts +22 -0
  33. package/dist/lib/deprecate.js +26 -0
  34. package/dist/lib/dry-run/samples.js +56 -5
  35. package/dist/lib/environment-tunnel.d.ts +2 -1
  36. package/dist/lib/environment-tunnel.js +1 -4
  37. package/dist/lib/first-suite-hint.d.ts +55 -0
  38. package/dist/lib/first-suite-hint.js +101 -0
  39. package/dist/lib/gh-output.d.ts +62 -4
  40. package/dist/lib/gh-output.js +149 -7
  41. package/dist/lib/github-context.d.ts +21 -0
  42. package/dist/lib/github-context.js +153 -0
  43. package/dist/lib/http.d.ts +10 -1
  44. package/dist/lib/http.js +29 -3
  45. package/dist/lib/junit-report.d.ts +3 -0
  46. package/dist/lib/junit-report.js +8 -1
  47. package/dist/lib/output.d.ts +11 -1
  48. package/dist/lib/output.js +17 -2
  49. package/dist/lib/plans.types.d.ts +1 -1
  50. package/dist/lib/response-schemas.d.ts +5 -1
  51. package/dist/lib/response-schemas.js +57 -0
  52. package/dist/lib/runs.types.d.ts +122 -0
  53. package/dist/lib/telemetry.d.ts +26 -2
  54. package/dist/lib/telemetry.js +47 -4
  55. package/dist/version.d.ts +1 -1
  56. package/dist/version.js +1 -1
  57. package/package.json +3 -3
  58. package/schemas/plan.schema.json +2 -2
  59. package/skills/testsprite-ci.skill.md +154 -0
  60. package/skills/testsprite-verify.codex.md +7 -7
  61. package/skills/testsprite-verify.skill.md +24 -21
@@ -1,4 +1,6 @@
1
1
  import { appendFileSync, writeFileSync } from 'node:fs';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
2
4
  import { describeConflict } from './conflict-reason.js';
3
5
  /**
4
6
  * Row statuses that mean "this test never ran" as opposed to "this run did not
@@ -48,9 +50,13 @@ function bucketRows(bucket, status, note) {
48
50
  * cannot read as "1/1 passed" with no annotation — but it counts as `skipped`,
49
51
  * never `failed`: whether non-dispatch fails the job is the exit-code
50
52
  * gates' call, and a `failed` count the gates disagree with is exactly the
51
- * artifacts-contradict-the-exit bug. (`skippedFrontend` / `skippedIntegration`
52
- * are NOT folded in — they exit 0 and are the Action layer's allow-partial
53
- * concern.)
53
+ * artifacts-contradict-the-exit bug.
54
+ *
55
+ * `skippedFrontend` / `skippedIntegration` are folded in only under
56
+ * `foldSkippedBuckets` (the `ci run` contract: ONE skipped number covering
57
+ * everything requested but not run). Default off — for `test run --all` they
58
+ * exit 0 and are the Action layer's allow-partial concern, and changing that
59
+ * default would silently change its artifacts.
54
60
  */
55
61
  export function summarizeAcceptedPayload(capturedJson, opts = {}) {
56
62
  let parsed;
@@ -82,23 +88,41 @@ export function summarizeAcceptedPayload(capturedJson, opts = {}) {
82
88
  };
83
89
  })
84
90
  : [];
91
+ const notFoundConflicts = new Set(Array.isArray(payload.conflicts)
92
+ ? payload.conflicts
93
+ .filter(c => c?.reason === 'not_found')
94
+ .map(c => String(c.testId))
95
+ : []);
85
96
  const rows = [
86
97
  ...acceptedRows,
87
98
  ...bucketRows(payload.skipped, 'skipped', item => typeof item?.reason === 'string'
88
99
  ? item.reason
89
100
  : 'not dispatched'),
90
101
  ...bucketRows(payload.deferred, 'deferred', 'rate-deferred (not dispatched)'),
102
+ // One note per conflict, from its reason (HEAD); under `foldSkippedBuckets`
103
+ // a `not_found` conflict keeps its own status so the `ci run` gate can
104
+ // exit 4 for it instead of reading it as a transient conflict.
91
105
  ...bucketRows(payload.conflicts, 'conflict', item => {
92
106
  const conflict = item;
93
107
  return conflict && typeof conflict.testId === 'string' && conflict.reason
94
108
  ? `${describeConflict(conflict)} (not dispatched)`
95
109
  : 'already in flight (not dispatched)';
96
- }),
110
+ }).map(row => opts.foldSkippedBuckets === true && notFoundConflicts.has(row.testId)
111
+ ? { ...row, status: 'not_found' }
112
+ : row),
97
113
  // Default note is `test rerun`'s cause (a not-found id has no replayable
98
114
  // run). `testlist run` passes its own — a not-found `--case` id is one that
99
115
  // is not a member of the list — so the annotation/artifact don't state the
100
116
  // wrong reason on the surface this whole layer exists to serve.
101
117
  ...bucketRows(payload.notFound, 'not_found', opts.notFoundNote ?? 'no replayable run (not dispatched)'),
118
+ ...(opts.foldSkippedBuckets === true
119
+ ? [
120
+ // `bucketRows` handles both bucket shapes: `skippedFrontend` is bare
121
+ // testId strings, `skippedIntegration` is `{ testId }` objects.
122
+ ...bucketRows(payload.skippedFrontend, 'skipped', 'frontend test — not run by the batch engine'),
123
+ ...bucketRows(payload.skippedIntegration, 'skipped', 'assembled integration test — run it from the portal'),
124
+ ]
125
+ : []),
102
126
  ];
103
127
  const passed = rows.filter(row => row.status === 'passed').length;
104
128
  const timedOut = rows.filter(row => row.status === 'timeout').length;
@@ -238,7 +262,7 @@ export function emitGithubOutputs(summary, env, sinks, opts = {}) {
238
262
  const summaryPath = env.GITHUB_STEP_SUMMARY;
239
263
  if (typeof summaryPath === 'string' && summaryPath.length > 0) {
240
264
  try {
241
- sinks.appendFile(summaryPath, renderJobSummaryMarkdown(summary));
265
+ sinks.appendFile(summaryPath, opts.markdown ?? renderJobSummaryMarkdown(summary));
242
266
  }
243
267
  catch {
244
268
  sinks.stderr(`[${label}] could not append to GITHUB_STEP_SUMMARY; continuing`);
@@ -279,7 +303,7 @@ export function emitGithubOutputs(summary, env, sinks, opts = {}) {
279
303
  * command in the failure messages (`[run]` / `[rerun]` / `[testlist run]`).
280
304
  * Both writes are best-effort — a sink throwing must never change the exit code.
281
305
  */
282
- export function emitCiArtifacts(summary, opts, io, label) {
306
+ export function emitCiArtifacts(summary, opts, io, label, extra = {}) {
283
307
  const ghEnabled = opts.ghOutput === true || io.env.GITHUB_ACTIONS === 'true';
284
308
  if (!ghEnabled && opts.summaryFile === undefined)
285
309
  return;
@@ -301,7 +325,125 @@ export function emitCiArtifacts(summary, opts, io, label) {
301
325
  // Under --output json the run envelope owns stdout; workflow commands go
302
326
  // to stderr instead (the Actions runner parses both streams).
303
327
  annotations: opts.output === 'json' ? io.stderr : io.stdout,
304
- }, { force: opts.ghOutput === true, label });
328
+ }, { force: opts.ghOutput === true, label, markdown: extra.markdown });
329
+ }
330
+ }
331
+ /**
332
+ * Hand the execution report to later steps: its JSON and Markdown are written
333
+ * under `$RUNNER_TEMP` (else the OS temp dir) and their paths appended to
334
+ * `$GITHUB_OUTPUT` as `execution-report-file` / `execution-report-markdown-file`.
335
+ * Paths, not bodies — a step output is capped at 1 MiB and multi-line values
336
+ * need heredoc escaping. No-op without `GITHUB_OUTPUT` (nothing can consume
337
+ * them). Best-effort: a write failure is reported and never masks the gate.
338
+ */
339
+ export function emitExecutionReportOutputs(ready, io) {
340
+ const outputPath = io.env.GITHUB_OUTPUT;
341
+ if (!outputPath)
342
+ return undefined;
343
+ const dir = io.env.RUNNER_TEMP || tmpdir();
344
+ const safeId = ready.report.executionId.replace(/[^A-Za-z0-9_-]/g, '_');
345
+ const jsonPath = join(dir, `testsprite-execution-report-${safeId}.json`);
346
+ const markdownPath = join(dir, `testsprite-execution-report-${safeId}.md`);
347
+ // A `key=value` output line ends at a newline, so a path carrying one would
348
+ // smuggle a second output; such a path is skipped rather than escaped.
349
+ if (/[\r\n]/.test(jsonPath) || /[\r\n]/.test(markdownPath)) {
350
+ io.stderr('[ci run] execution report outputs skipped: the temp directory path contains a newline');
351
+ return undefined;
352
+ }
353
+ try {
354
+ // Owner-only: the report carries the run's narrative, error text, fix
355
+ // prompts and screenshot links, and the runner's temp dir is shared.
356
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- Runner temp directory (`$RUNNER_TEMP` or the OS temp dir) plus a sanitised execution id; never caller input.
357
+ writeFileSync(jsonPath, `${JSON.stringify(ready.report, null, 2)}\n`, {
358
+ encoding: 'utf8',
359
+ mode: 0o600,
360
+ });
361
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- Same runner temp directory and sanitised id as above.
362
+ writeFileSync(markdownPath, ready.markdown, { encoding: 'utf8', mode: 0o600 });
363
+ }
364
+ catch (err) {
365
+ io.stderr(`[ci run] execution report files not written (${err instanceof Error ? err.message : String(err)}); continuing`);
366
+ return undefined;
367
+ }
368
+ try {
369
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- GITHUB_OUTPUT is the runner-provided output path; only the two temp-file paths above are appended.
370
+ appendFileSync(outputPath, `execution-report-file=${jsonPath}\nexecution-report-markdown-file=${markdownPath}\n`, 'utf8');
371
+ }
372
+ catch {
373
+ io.stderr('[ci run] execution report outputs not appended to GITHUB_OUTPUT; continuing');
374
+ }
375
+ return { jsonPath, markdownPath };
376
+ }
377
+ /**
378
+ * The job-summary Markdown for a batch that has a server execution report.
379
+ *
380
+ * The exit code comes from the CLI's own poll of every run plus whatever did
381
+ * not dispatch; the report describes only the execution. Usually they agree
382
+ * and the summary is the report, byte for byte the App's comment. When they
383
+ * do not — a run the CLI could not read or that timed out, a test refused
384
+ * before dispatch, a retry error — the report alone would read "all passed"
385
+ * under a red check, so the local verdict is stated first and the rows the
386
+ * report cannot contain are appended. A red run whose failures the report
387
+ * also shows agrees — the counts match — and keeps the App's comment as is.
388
+ */
389
+ export function reconcileExecutionReportMarkdown(summary, ready) {
390
+ const localNonPassed = summary.runs.filter(row => row.status !== 'passed');
391
+ const { stats } = ready.report;
392
+ const agrees = summary.skipped === 0 &&
393
+ summary.timedOut === 0 &&
394
+ summary.passed === stats.passed &&
395
+ summary.failed === stats.failed + stats.blocked &&
396
+ summary.total === stats.total;
397
+ if (agrees)
398
+ return ready.markdown;
399
+ const reported = new Set(ready.report.tests.map(t => t.id));
400
+ const missing = localNonPassed.filter(row => !row.runId || !reported.has(row.runId));
401
+ const banner = [
402
+ '> [!WARNING]',
403
+ `> **CI gate: ${summary.passed} of ${summary.total} passed, ${summary.failed} failed, ${summary.skipped} skipped, ${summary.timedOut} timed out.**`,
404
+ "> The check's result comes from the CLI's own poll of each run. The report below is the server's view of execution " +
405
+ `\`${ready.report.executionId}\`` +
406
+ (missing.length > 0 ? ' and does not cover the rows listed at the end.' : '.'),
407
+ '',
408
+ ];
409
+ const appendix = missing.length > 0
410
+ ? [
411
+ '',
412
+ '### Not reflected in the execution report',
413
+ '',
414
+ '| Test | Status | Detail | Run |',
415
+ '| --- | --- | --- | --- |',
416
+ ...missing.map(row => {
417
+ const label = row.title?.trim() || row.testId;
418
+ const test = row.dashboardUrl
419
+ ? `[${escapeMarkdownLinkText(label)}](${escapeMarkdownUrl(row.dashboardUrl)})`
420
+ : escapeTableCell(label);
421
+ const runId = row.runId ?? '';
422
+ const run = row.executionUrl && runId
423
+ ? `[${escapeMarkdownLinkText(runId)}](${escapeMarkdownUrl(row.executionUrl)})`
424
+ : escapeTableCell(runId);
425
+ return `| ${test} | ${escapeTableCell(row.status)} | ${escapeTableCell(row.error ?? '')} | ${run} |`;
426
+ }),
427
+ '',
428
+ ]
429
+ : [];
430
+ return [...banner, ready.markdown.replace(/\s+$/, ''), ...appendix, ''].join('\n');
431
+ }
432
+ /** Numeric step outputs share the exact counters used by every other CI sink. */
433
+ export function emitCiStepOutputs(summary, io) {
434
+ const outputPath = io.env.GITHUB_OUTPUT;
435
+ if (!outputPath)
436
+ return;
437
+ const content = ['total', 'passed', 'failed', 'skipped', 'timedOut']
438
+ .map(key => `${key}=${summary[key]}\n`)
439
+ .join('');
440
+ try {
441
+ // Runner-provided output file; only numeric counter values are appended.
442
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- GITHUB_OUTPUT is an explicit runner/operator-provided output path, not API/test content; only computed numeric counters are appended.
443
+ appendFileSync(outputPath, content, 'utf8');
444
+ }
445
+ catch {
446
+ io.stderr('[ci run] could not append to GITHUB_OUTPUT; continuing');
305
447
  }
306
448
  }
307
449
  //# sourceMappingURL=gh-output.js.map
@@ -0,0 +1,21 @@
1
+ import type { FetchImpl } from './http.js';
2
+ import type { CiGithubTrigger } from './runs.types.js';
3
+ export type GithubRunContext = {
4
+ kind: 'pull_request';
5
+ trigger: CiGithubTrigger;
6
+ draft: boolean;
7
+ } | {
8
+ kind: 'no_pull_request';
9
+ event: string;
10
+ reason: string;
11
+ } | {
12
+ kind: 'outside_actions';
13
+ };
14
+ export interface GithubContextDeps {
15
+ /** Reads `$GITHUB_EVENT_PATH`; injectable so tests never touch the runner. */
16
+ readFile?: (path: string) => string;
17
+ fetchImpl?: FetchImpl;
18
+ }
19
+ /** The temporary environment a pull request's runs live in — shared with the GitHub App. */
20
+ export declare function previewEnvironmentName(prNumber: number): string;
21
+ export declare function readGithubRunContext(env: NodeJS.ProcessEnv, deps?: GithubContextDeps): Promise<GithubRunContext>;
@@ -0,0 +1,153 @@
1
+ /**
2
+ * What `ci run` can learn about the pull request it is gating, from the
3
+ * GitHub Actions runner alone — no secrets of ours, no flags in the yml.
4
+ *
5
+ * A `pull_request` event names the PR in its payload. A `deployment_status`
6
+ * event (the platform-deploys-every-PR shape) only names the commit, so the
7
+ * PR is looked up with the job's own `GITHUB_TOKEN` through the same call the
8
+ * GitHub App makes (`GET /repos/{owner}/{repo}/commits/{sha}/pulls`). A run
9
+ * that cannot be tied to a pull request is reported as such, never guessed:
10
+ * the caller decides whether that means "skip" or "run without a preview".
11
+ */
12
+ import { readFileSync } from 'node:fs';
13
+ import { CLIError, localValidationError } from './errors.js';
14
+ /** The temporary environment a pull request's runs live in — shared with the GitHub App. */
15
+ export function previewEnvironmentName(prNumber) {
16
+ return `github-pr-${prNumber}`;
17
+ }
18
+ const SHA_RE = /^[0-9a-f]{40}$/;
19
+ export async function readGithubRunContext(env, deps = {}) {
20
+ if (env.GITHUB_ACTIONS !== 'true')
21
+ return { kind: 'outside_actions' };
22
+ const event = env.GITHUB_EVENT_NAME ?? '';
23
+ const slug = env.GITHUB_REPOSITORY ?? '';
24
+ const [repoOwner, repoName, ...rest] = slug.split('/');
25
+ if (!repoOwner || !repoName || rest.length > 0) {
26
+ return { kind: 'no_pull_request', event, reason: 'GITHUB_REPOSITORY is not owner/name' };
27
+ }
28
+ const payload = readEvent(env, deps);
29
+ if (event === 'pull_request' || event === 'pull_request_target') {
30
+ const pr = asRecord(payload.pull_request);
31
+ const prNumber = pr?.number;
32
+ if (typeof prNumber !== 'number' || !Number.isInteger(prNumber) || prNumber < 1) {
33
+ throw localValidationError('github-event-path', `the ${event} event at $GITHUB_EVENT_PATH carries no pull_request.number`, undefined, 'field');
34
+ }
35
+ const head = asRecord(pr?.head);
36
+ return {
37
+ kind: 'pull_request',
38
+ draft: pr?.draft === true,
39
+ trigger: {
40
+ repoOwner,
41
+ repoName,
42
+ prNumber,
43
+ ...(typeof head?.ref === 'string' && head.ref !== '' ? { branchName: head.ref } : {}),
44
+ ...(typeof head?.sha === 'string' && SHA_RE.test(head.sha) ? { commitSha: head.sha } : {}),
45
+ },
46
+ };
47
+ }
48
+ if (event === 'deployment_status') {
49
+ const deployment = asRecord(payload.deployment);
50
+ const sha = typeof deployment?.sha === 'string' ? deployment.sha : '';
51
+ if (!SHA_RE.test(sha)) {
52
+ return { kind: 'no_pull_request', event, reason: 'the deployment names no commit' };
53
+ }
54
+ const token = env.GITHUB_TOKEN;
55
+ if (!token) {
56
+ throw localValidationError('GITHUB_TOKEN', 'a deployment_status event names only a commit; ci run looks up its pull request with the job token — add `GITHUB_TOKEN: ${{ github.token }}` to the step env', undefined, 'field');
57
+ }
58
+ const pulls = await listPullsForCommit({ env, repoOwner, repoName, sha, token }, deps.fetchImpl ?? globalThis.fetch);
59
+ // The PR whose head IS this commit is the one this deployment belongs to.
60
+ // Anything looser (several open PRs, a merged one) is not a gate target.
61
+ const exact = pulls.filter(p => p.headSha === sha);
62
+ const open = pulls.filter(p => p.state === 'open');
63
+ const chosen = exact[0] ?? (open.length === 1 ? open[0] : undefined);
64
+ if (!chosen) {
65
+ return {
66
+ kind: 'no_pull_request',
67
+ event,
68
+ reason: pulls.length === 0
69
+ ? `commit ${sha.slice(0, 7)} belongs to no pull request`
70
+ : `commit ${sha.slice(0, 7)} is not the head of an open pull request`,
71
+ };
72
+ }
73
+ const branch = typeof deployment?.ref === 'string' ? deployment.ref : chosen.headRef;
74
+ return {
75
+ kind: 'pull_request',
76
+ draft: chosen.draft,
77
+ trigger: {
78
+ repoOwner,
79
+ repoName,
80
+ prNumber: chosen.number,
81
+ commitSha: sha,
82
+ ...(branch ? { branchName: branch } : {}),
83
+ },
84
+ };
85
+ }
86
+ return {
87
+ kind: 'no_pull_request',
88
+ event,
89
+ reason: `a ${event || 'non-PR'} event has no pull request`,
90
+ };
91
+ }
92
+ function readEvent(env, deps) {
93
+ const path = env.GITHUB_EVENT_PATH;
94
+ if (!path)
95
+ return {};
96
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- `path` is the runner-provided `$GITHUB_EVENT_PATH` env path (read-only), never API/test content.
97
+ const read = deps.readFile ?? (p => readFileSync(p, 'utf8'));
98
+ try {
99
+ const parsed = JSON.parse(read(path));
100
+ return asRecord(parsed) ?? {};
101
+ }
102
+ catch (err) {
103
+ throw localValidationError('github-event-path', `cannot read the GitHub event at $GITHUB_EVENT_PATH: ${err instanceof Error ? err.message : String(err)}`, undefined, 'field');
104
+ }
105
+ }
106
+ async function listPullsForCommit(args, fetchImpl) {
107
+ const base = (args.env.GITHUB_API_URL ?? 'https://api.github.com').replace(/\/+$/, '');
108
+ const url = `${base}/repos/${encodeURIComponent(args.repoOwner)}/${encodeURIComponent(args.repoName)}/commits/${args.sha}/pulls`;
109
+ let response;
110
+ try {
111
+ response = await fetchImpl(url, {
112
+ method: 'GET',
113
+ headers: {
114
+ accept: 'application/vnd.github+json',
115
+ authorization: `Bearer ${args.token}`,
116
+ 'x-github-api-version': '2022-11-28',
117
+ },
118
+ });
119
+ }
120
+ catch (err) {
121
+ throw new CLIError(`Could not look up the pull request for commit ${args.sha.slice(0, 7)}: ${err instanceof Error ? err.message : String(err)}`, 10);
122
+ }
123
+ if (!response.ok) {
124
+ throw new CLIError(`Could not look up the pull request for commit ${args.sha.slice(0, 7)}: GitHub answered ${response.status}` +
125
+ (response.status === 403 || response.status === 401
126
+ ? ' — the job token needs `pull-requests: read`'
127
+ : ''), response.status === 401 || response.status === 403 ? 5 : 10);
128
+ }
129
+ const body = await response.json();
130
+ if (!Array.isArray(body))
131
+ return [];
132
+ return body.flatMap((item) => {
133
+ const pr = asRecord(item);
134
+ const head = asRecord(pr?.head);
135
+ if (typeof pr?.number !== 'number' || typeof head?.sha !== 'string')
136
+ return [];
137
+ return [
138
+ {
139
+ number: pr.number,
140
+ state: typeof pr.state === 'string' ? pr.state : '',
141
+ draft: pr.draft === true,
142
+ headSha: head.sha,
143
+ ...(typeof head.ref === 'string' ? { headRef: head.ref } : {}),
144
+ },
145
+ ];
146
+ });
147
+ }
148
+ function asRecord(value) {
149
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
150
+ ? value
151
+ : undefined;
152
+ }
153
+ //# sourceMappingURL=github-context.js.map
@@ -2,7 +2,7 @@ import * as v from 'valibot';
2
2
  import type { ErrorCode } from './errors.js';
3
3
  import { ApiError } from './errors.js';
4
4
  import type { CliTestListRunResponse } from './testlist.types.js';
5
- import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse, CancelRunResponse } from './runs.types.js';
5
+ import type { TriggerRunBody, TriggerRunResponse, RunResponse, RerunRequest, RerunResponse, BatchRerunRequest, BatchRerunResponse, BatchRunFreshRequest, BatchRunFreshResponse, ListRunsQuery, ListRunsResponse, CancelRunResponse, ExecutionReportResponse } from './runs.types.js';
6
6
  import type { CliAcceptPlansResponse, CliGeneratePlansResponse, CliGetPlansResponse } from './plans.types.js';
7
7
  import type { MintTunnelBody, TunnelListResponse, TunnelMintResponse, TunnelStatusResponse } from './tunnel.types.js';
8
8
  import type { ShutdownHandle } from './interrupt.js';
@@ -398,6 +398,15 @@ export declare class HttpClient {
398
398
  signal?: AbortSignal;
399
399
  retry?: boolean;
400
400
  }): Promise<TunnelStatusResponse>;
401
+ /**
402
+ * The execution report — the GitHub App's PR-comment content — for one
403
+ * execution. `ready: false` asks the caller to poll again; the server keeps
404
+ * building the report meanwhile.
405
+ */
406
+ getExecutionReport(executionId: string, options?: {
407
+ signal?: AbortSignal;
408
+ retry?: boolean;
409
+ }): Promise<ExecutionReportResponse>;
401
410
  /**
402
411
  * DELETE /api/cli/v1/tunnel/{clientId} — destroy a binding. 204, idempotent.
403
412
  *
package/dist/lib/http.js CHANGED
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
  import * as v from 'valibot';
3
3
  import { ApiError, InterruptError, RequestTimeoutError, TransportError } from './errors.js';
4
4
  import { buildUserAgent } from './client-tag.js';
5
- import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, CANCEL_RUN_RESPONSE_SCHEMA, LIST_RUNS_RESPONSE_SCHEMA, RERUN_RESPONSE_SCHEMA, RUN_RESPONSE_SCHEMA, TESTLIST_RUN_RESPONSE_SCHEMA, TRIGGER_RUN_RESPONSE_SCHEMA, TUNNEL_LIST_RESPONSE_SCHEMA, TUNNEL_MINT_RESPONSE_SCHEMA, TUNNEL_STATUS_RESPONSE_SCHEMA, } from './response-schemas.js';
5
+ import { BATCH_RERUN_RESPONSE_SCHEMA, BATCH_RUN_FRESH_RESPONSE_SCHEMA, CANCEL_RUN_RESPONSE_SCHEMA, LIST_RUNS_RESPONSE_SCHEMA, RERUN_RESPONSE_SCHEMA, RUN_RESPONSE_SCHEMA, TESTLIST_RUN_RESPONSE_SCHEMA, TRIGGER_RUN_RESPONSE_SCHEMA, TUNNEL_LIST_RESPONSE_SCHEMA, TUNNEL_MINT_RESPONSE_SCHEMA, TUNNEL_STATUS_RESPONSE_SCHEMA, EXECUTION_REPORT_RESPONSE_SCHEMA, } from './response-schemas.js';
6
6
  /**
7
7
  * Default per-request timeout (120s). Comfortably covers every metadata/read
8
8
  * request and every <=25s long-poll request (`?waitSeconds` is capped at 25
@@ -221,7 +221,7 @@ export class HttpClient {
221
221
  signal: options.signal,
222
222
  schema: RERUN_RESPONSE_SCHEMA,
223
223
  retryOnConflict: false,
224
- }).then(r => r.body);
224
+ }).then(r => withoutDeprecationAdvisories(r.body));
225
225
  }
226
226
  /**
227
227
  * POST /api/cli/v1/tests/batch/rerun
@@ -237,7 +237,7 @@ export class HttpClient {
237
237
  signal: options.signal,
238
238
  schema: BATCH_RERUN_RESPONSE_SCHEMA,
239
239
  retryOnConflict: false,
240
- }).then(r => r.body);
240
+ }).then(r => withoutDeprecationAdvisories(r.body));
241
241
  }
242
242
  /**
243
243
  * POST /api/cli/v1/tests/batch/run
@@ -376,6 +376,14 @@ export class HttpClient {
376
376
  schema: TUNNEL_STATUS_RESPONSE_SCHEMA,
377
377
  });
378
378
  }
379
+ /**
380
+ * The execution report — the GitHub App's PR-comment content — for one
381
+ * execution. `ready: false` asks the caller to poll again; the server keeps
382
+ * building the report meanwhile.
383
+ */
384
+ async getExecutionReport(executionId, options = {}) {
385
+ return this.get(`/tests/executions/${encodeURIComponent(executionId)}/report`, { signal: options.signal, retry: options.retry, schema: EXECUTION_REPORT_RESPONSE_SCHEMA });
386
+ }
379
387
  /**
380
388
  * DELETE /api/cli/v1/tunnel/{clientId} — destroy a binding. 204, idempotent.
381
389
  *
@@ -1236,4 +1244,22 @@ function isTimeoutError(err) {
1236
1244
  }
1237
1245
  return false;
1238
1246
  }
1247
+ /**
1248
+ * Drop server-sent `feature: 'deprecation'` advisories from a rerun response.
1249
+ * The CLI owns the deprecation signal itself (one stderr line plus the JSON
1250
+ * `deprecations` key), so passing the server's through would announce the same
1251
+ * thing twice. Matched on the machine-readable `feature`, never on message
1252
+ * text; other advisories (autoHeal) are kept and an emptied list is removed.
1253
+ */
1254
+ function withoutDeprecationAdvisories(body) {
1255
+ if (!body.advisories)
1256
+ return body;
1257
+ const kept = body.advisories.filter(a => a.feature !== 'deprecation');
1258
+ if (kept.length === body.advisories.length)
1259
+ return body;
1260
+ const next = { ...body, advisories: kept };
1261
+ if (kept.length === 0)
1262
+ delete next.advisories;
1263
+ return next;
1264
+ }
1239
1265
  //# sourceMappingURL=http.js.map
@@ -7,6 +7,8 @@ export interface JUnitTestResult {
7
7
  status: string;
8
8
  /** Observed on polled runs; used for classname when --project is omitted. */
9
9
  projectId?: string;
10
+ /** This row's own `classname`, when the batch spans several projects. */
11
+ classname?: string;
10
12
  error?: {
11
13
  code: string;
12
14
  message: string;
@@ -61,6 +63,7 @@ export declare function assertJUnitReportOptions(opts: JUnitReportFlagOptions):
61
63
  */
62
64
  export declare function resolveBatchReportProjectId(opts: {
63
65
  projectId?: string;
66
+ projectIdByTestId?: ReadonlyMap<string, string>;
64
67
  }, results: ReadonlyArray<{
65
68
  projectId?: string;
66
69
  }>): string;
@@ -68,9 +68,16 @@ export function assertJUnitReportOptions(opts) {
68
68
  export function resolveBatchReportProjectId(opts, results) {
69
69
  if (opts.projectId)
70
70
  return opts.projectId;
71
+ // Explicit ids that span several projects have no single `--project`; each
72
+ // row carries its own project as its classname and the suite gets this token.
73
+ const known = new Set(opts.projectIdByTestId?.values());
74
+ if (known.size > 1)
75
+ return 'multiple-projects';
71
76
  const fromPoll = results.map(r => r.projectId).find((id) => !!id);
72
77
  if (fromPoll)
73
78
  return fromPoll;
79
+ if (known.size === 1)
80
+ return [...known][0];
74
81
  throw localValidationError('project', '--report junit requires --project <id> when the project cannot be inferred from run results');
75
82
  }
76
83
  /**
@@ -168,7 +175,7 @@ export function buildJUnitReport(opts) {
168
175
  }
169
176
  }
170
177
  const suiteName = escapeXml(opts.suiteName);
171
- const testcases = results.map(r => renderTestcase(r, opts.classname)).join('\n');
178
+ const testcases = results.map(r => renderTestcase(r, r.classname ?? opts.classname)).join('\n');
172
179
  return [
173
180
  XML_DECL,
174
181
  '<testsuites>',
@@ -1,3 +1,4 @@
1
+ import type { DeprecationEntry } from './deprecate.js';
1
2
  export type OutputMode = 'json' | 'text';
2
3
  /**
3
4
  * Help-text footer pointing at the global options surface so users
@@ -72,7 +73,16 @@ export declare class Output {
72
73
  private readonly stdoutWrite;
73
74
  private readonly stderrWrite;
74
75
  private readonly rawStdoutWrite;
75
- constructor(mode?: OutputMode, streams?: OutputStreams);
76
+ private readonly deprecations;
77
+ /**
78
+ * `options.deprecations` is appended as the LAST key of a JSON object
79
+ * payload from `print` (text mode, arrays and error envelopes are never
80
+ * touched), so a deprecated command's output stays the same document plus
81
+ * one trailing key.
82
+ */
83
+ constructor(mode?: OutputMode, streams?: OutputStreams, options?: {
84
+ deprecations?: readonly DeprecationEntry[];
85
+ });
76
86
  print(data: unknown, textRenderer?: (data: unknown) => string): void;
77
87
  /**
78
88
  * Write a chunk of bytes to stdout verbatim. Awaits any
@@ -36,8 +36,16 @@ export class Output {
36
36
  stdoutWrite;
37
37
  stderrWrite;
38
38
  rawStdoutWrite;
39
- constructor(mode = 'text', streams = {}) {
39
+ deprecations;
40
+ /**
41
+ * `options.deprecations` is appended as the LAST key of a JSON object
42
+ * payload from `print` (text mode, arrays and error envelopes are never
43
+ * touched), so a deprecated command's output stays the same document plus
44
+ * one trailing key.
45
+ */
46
+ constructor(mode = 'text', streams = {}, options = {}) {
40
47
  this.mode = mode;
48
+ this.deprecations = options.deprecations?.length ? options.deprecations : undefined;
41
49
  this.stdoutWrite =
42
50
  streams.stdout ??
43
51
  (line => {
@@ -61,7 +69,14 @@ export class Output {
61
69
  // `index.ts`, and `--debug` tracing in `client-factory.ts` — never to a
62
70
  // success payload.
63
71
  if (this.mode === 'json' || !textRenderer) {
64
- this.stdoutWrite(JSON.stringify(data, null, 2));
72
+ const withDeprecations = this.mode === 'json' &&
73
+ this.deprecations &&
74
+ typeof data === 'object' &&
75
+ data !== null &&
76
+ !Array.isArray(data)
77
+ ? { ...data, deprecations: this.deprecations }
78
+ : data;
79
+ this.stdoutWrite(JSON.stringify(withDeprecations, null, 2));
65
80
  return;
66
81
  }
67
82
  this.stdoutWrite(textRenderer(data));
@@ -58,7 +58,7 @@ export interface CliPlanProposal {
58
58
  proposalId: string;
59
59
  title: string;
60
60
  description: string;
61
- /** CLI priority vocabulary (`p1`..`p3`, mapped from V3 High/Medium/Low). */
61
+ /** Priority as the CLI shows it: `p0` (High), `p1` (Medium), `p2` (Low). */
62
62
  priority: string;
63
63
  category: string;
64
64
  feature: string;
@@ -36,7 +36,7 @@
36
36
  import * as v from 'valibot';
37
37
  import type { MeResponse } from '../commands/auth.js';
38
38
  import type { UsageResponse } from '../commands/usage.js';
39
- import type { BatchRerunResponse, BatchRunFreshResponse, CancelRunResponse, ListRunsResponse, RerunResponse, RunResponse, TriggerRunResponse } from './runs.types.js';
39
+ import type { BatchRerunResponse, BatchRunFreshResponse, CancelRunResponse, ListRunsResponse, RerunResponse, RunResponse, TriggerRunResponse, ExecutionReport, ExecutionReportResponse } from './runs.types.js';
40
40
  import type { CliTestListRunResponse } from './testlist.types.js';
41
41
  import type { TunnelListResponse, TunnelMintResponse, TunnelStatusResponse } from './tunnel.types.js';
42
42
  /** Mirrors `RunResponse` (runs.types.ts): `GET /api/cli/v1/runs/{runId}`. */
@@ -146,3 +146,7 @@ export declare const TUNNEL_MINT_RESPONSE_SCHEMA: v.GenericSchema<unknown, Tunne
146
146
  export declare const TUNNEL_STATUS_RESPONSE_SCHEMA: v.GenericSchema<unknown, TunnelStatusResponse>;
147
147
  /** Mirrors `TunnelListResponse`: a server may add status values or omit creation time. */
148
148
  export declare const TUNNEL_LIST_RESPONSE_SCHEMA: v.GenericSchema<unknown, TunnelListResponse>;
149
+ /** Mirrors `ExecutionReport` — the server's report model, kept loose so new fields pass through. */
150
+ export declare const EXECUTION_REPORT_SCHEMA: v.GenericSchema<unknown, ExecutionReport>;
151
+ /** Mirrors `ExecutionReportResponse`: `report`/`markdown` only travel with `ready: true`. */
152
+ export declare const EXECUTION_REPORT_RESPONSE_SCHEMA: v.GenericSchema<unknown, ExecutionReportResponse>;