@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.
- package/README.md +3 -1
- package/dist/commands/ci.d.ts +66 -17
- package/dist/commands/ci.js +466 -104
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.js +50 -9
- package/dist/commands/init.js +17 -3
- package/dist/commands/project.js +15 -1
- package/dist/commands/test.d.ts +74 -11
- package/dist/commands/test.js +579 -112
- package/dist/index.js +5 -1
- package/dist/lib/agent-targets.d.ts +8 -3
- package/dist/lib/agent-targets.js +15 -4
- package/dist/lib/ci-run.d.ts +11 -0
- package/dist/lib/ci-run.js +34 -0
- package/dist/lib/client-factory.d.ts +23 -0
- package/dist/lib/client-factory.js +7 -6
- package/dist/lib/config.d.ts +1 -0
- package/dist/lib/config.js +1 -1
- package/dist/lib/credentials.d.ts +0 -1
- package/dist/lib/credentials.js +51 -14
- package/dist/lib/dry-run/samples.js +42 -1
- package/dist/lib/first-suite-hint.d.ts +55 -0
- package/dist/lib/first-suite-hint.js +101 -0
- package/dist/lib/gh-output.d.ts +62 -4
- package/dist/lib/gh-output.js +149 -7
- package/dist/lib/github-context.d.ts +21 -0
- package/dist/lib/github-context.js +153 -0
- package/dist/lib/http.d.ts +10 -1
- package/dist/lib/http.js +9 -1
- package/dist/lib/plans.types.d.ts +1 -1
- package/dist/lib/response-schemas.d.ts +5 -1
- package/dist/lib/response-schemas.js +54 -0
- package/dist/lib/runs.types.d.ts +106 -0
- package/dist/lib/telemetry.d.ts +25 -1
- package/dist/lib/telemetry.js +45 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schemas/plan.schema.json +2 -2
- package/skills/testsprite-ci.skill.md +154 -0
package/dist/lib/gh-output.js
CHANGED
|
@@ -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.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -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
|
|
@@ -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
|
*
|
|
@@ -58,7 +58,7 @@ export interface CliPlanProposal {
|
|
|
58
58
|
proposalId: string;
|
|
59
59
|
title: string;
|
|
60
60
|
description: string;
|
|
61
|
-
/** CLI
|
|
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>;
|
|
@@ -110,6 +110,13 @@ export const RUN_RESPONSE_SCHEMA = v.looseObject({
|
|
|
110
110
|
error: v.nullish(v.string(), null),
|
|
111
111
|
videoUrl: v.nullish(v.string(), null),
|
|
112
112
|
stepSummary: RUN_STEP_SUMMARY_SCHEMA,
|
|
113
|
+
// Optional with no default: absent on older backends. `reason` / `caveat` are
|
|
114
|
+
// `null` on the wire when the run carries no routing reason or caveat.
|
|
115
|
+
replay: v.optional(v.looseObject({
|
|
116
|
+
path: v.string(),
|
|
117
|
+
reason: v.nullish(v.string()),
|
|
118
|
+
caveat: v.nullish(v.string()),
|
|
119
|
+
})),
|
|
113
120
|
retryAfterSeconds: v.optional(v.number()),
|
|
114
121
|
// Portal link. Three-state wire contract (pinned): **absent** — an older
|
|
115
122
|
// backend that predates this field, and cannot have produced a V3-native/
|
|
@@ -286,6 +293,8 @@ export const BATCH_RUN_FRESH_RESPONSE_SCHEMA = v.looseObject({
|
|
|
286
293
|
runId: v.string(),
|
|
287
294
|
enqueuedAt: v.string(),
|
|
288
295
|
dashboardUrl: v.optional(v.string()),
|
|
296
|
+
// V3-served runs name their execution; an older backend omits it.
|
|
297
|
+
executionId: v.optional(v.string()),
|
|
289
298
|
})),
|
|
290
299
|
conflicts: v.array(v.looseObject({
|
|
291
300
|
testId: v.string(),
|
|
@@ -296,6 +305,12 @@ export const BATCH_RUN_FRESH_RESPONSE_SCHEMA = v.looseObject({
|
|
|
296
305
|
deferred: v.array(v.looseObject({ testId: v.string() })),
|
|
297
306
|
skippedFrontend: v.array(v.string()),
|
|
298
307
|
skippedIntegration: v.array(v.looseObject({ testId: v.string() })),
|
|
308
|
+
// Optional with no default: absent on older backends and frontend projects.
|
|
309
|
+
integration: v.optional(v.looseObject({
|
|
310
|
+
existing: v.number(),
|
|
311
|
+
runsAfterWave: v.boolean(),
|
|
312
|
+
mayGenerate: v.boolean(),
|
|
313
|
+
})),
|
|
299
314
|
// Project-level closing link. Absent-key-preserving like `RUN_RESPONSE_SCHEMA`'s
|
|
300
315
|
// `dashboardUrl` (see the note there): omitted stays ABSENT so the client
|
|
301
316
|
// keeps computing its legacy template for an older backend / the V2 engine;
|
|
@@ -303,6 +318,10 @@ export const BATCH_RUN_FRESH_RESPONSE_SCHEMA = v.looseObject({
|
|
|
303
318
|
dashboardUrl: v.nullish(v.string(), undefined),
|
|
304
319
|
// An exact echo confirms that the backend read the target URL override.
|
|
305
320
|
targetUrl: v.optional(v.string()),
|
|
321
|
+
// Same contract for the CI fields: a client that sent one and gets no
|
|
322
|
+
// echo was served by a backend that cut the batch / ran a plain override.
|
|
323
|
+
admission: v.optional(v.picklist(['budget', 'all'])),
|
|
324
|
+
previewName: v.optional(v.string()),
|
|
306
325
|
});
|
|
307
326
|
/**
|
|
308
327
|
* `POST /api/cli/v1/testlist/{listId}/run`. Mirrors the batch-run-fresh shape so
|
|
@@ -466,4 +485,39 @@ export const TUNNEL_LIST_RESPONSE_SCHEMA = v.looseObject({
|
|
|
466
485
|
createdAt: v.optional(v.nullable(v.string())),
|
|
467
486
|
})),
|
|
468
487
|
});
|
|
488
|
+
/** Mirrors `ExecutionReport` — the server's report model, kept loose so new fields pass through. */
|
|
489
|
+
export const EXECUTION_REPORT_SCHEMA = v.looseObject({
|
|
490
|
+
projectId: v.string(),
|
|
491
|
+
executionId: v.string(),
|
|
492
|
+
projectName: v.string(),
|
|
493
|
+
orgId: v.nullish(v.string(), null),
|
|
494
|
+
stats: v.looseObject({
|
|
495
|
+
passed: v.number(),
|
|
496
|
+
failed: v.number(),
|
|
497
|
+
blocked: v.number(),
|
|
498
|
+
total: v.number(),
|
|
499
|
+
}),
|
|
500
|
+
allPassed: v.boolean(),
|
|
501
|
+
narrative: v.nullish(v.string(), null),
|
|
502
|
+
whatCouldBeBetter: v.nullish(v.string(), null),
|
|
503
|
+
recommendedNextStep: v.nullish(v.string(), null),
|
|
504
|
+
tests: v.array(v.looseObject({
|
|
505
|
+
id: v.string(),
|
|
506
|
+
title: v.string(),
|
|
507
|
+
slug: v.nullish(v.string(), null),
|
|
508
|
+
status: openWireLiteral(),
|
|
509
|
+
screenshotUrl: v.nullish(v.string(), null),
|
|
510
|
+
error: v.nullish(v.string(), null),
|
|
511
|
+
fix: v.nullish(v.string(), null),
|
|
512
|
+
resultUrl: v.optional(v.string()),
|
|
513
|
+
})),
|
|
514
|
+
resultUrl: v.string(),
|
|
515
|
+
});
|
|
516
|
+
/** Mirrors `ExecutionReportResponse`: `report`/`markdown` only travel with `ready: true`. */
|
|
517
|
+
export const EXECUTION_REPORT_RESPONSE_SCHEMA = v.looseObject({
|
|
518
|
+
ready: v.boolean(),
|
|
519
|
+
retryAfterSeconds: v.optional(v.number()),
|
|
520
|
+
report: v.optional(EXECUTION_REPORT_SCHEMA),
|
|
521
|
+
markdown: v.optional(v.string()),
|
|
522
|
+
});
|
|
469
523
|
//# sourceMappingURL=response-schemas.js.map
|