@testsprite/testsprite-cli 0.13.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 +54 -49
- 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 +62 -20
- package/dist/commands/init.js +17 -3
- package/dist/commands/project-env.d.ts +11 -1
- package/dist/commands/project-env.js +399 -61
- package/dist/commands/project-sign-in.d.ts +60 -0
- package/dist/commands/project-sign-in.js +289 -0
- package/dist/commands/project.d.ts +9 -0
- package/dist/commands/project.js +82 -28
- package/dist/commands/schedule.d.ts +12 -0
- package/dist/commands/schedule.js +175 -5
- package/dist/commands/test.d.ts +126 -30
- package/dist/commands/test.js +1928 -447
- package/dist/commands/testlist.d.ts +10 -5
- package/dist/commands/testlist.js +170 -30
- package/dist/commands/tunnel.js +11 -5
- package/dist/index.js +17 -38
- 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 +35 -1
- package/dist/lib/client-factory.js +21 -10
- 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 +95 -1
- package/dist/lib/environment-tunnel.d.ts +109 -0
- package/dist/lib/environment-tunnel.js +465 -0
- package/dist/lib/errors.js +12 -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 +152 -7
- package/dist/lib/github-context.d.ts +21 -0
- package/dist/lib/github-context.js +153 -0
- package/dist/lib/http.d.ts +12 -1
- package/dist/lib/http.js +9 -1
- package/dist/lib/junit-report.d.ts +11 -7
- package/dist/lib/junit-report.js +13 -7
- package/dist/lib/local-target.d.ts +13 -3
- package/dist/lib/local-target.js +47 -12
- package/dist/lib/output.js +15 -1
- package/dist/lib/plan-poll.js +3 -4
- package/dist/lib/plans.types.d.ts +1 -1
- package/dist/lib/redact.d.ts +38 -0
- package/dist/lib/redact.js +140 -0
- package/dist/lib/render-error.d.ts +19 -5
- package/dist/lib/render-error.js +31 -0
- package/dist/lib/response-schemas.d.ts +5 -1
- package/dist/lib/response-schemas.js +54 -0
- package/dist/lib/runs.types.d.ts +115 -1
- package/dist/lib/target-url.js +5 -5
- package/dist/lib/telemetry.d.ts +31 -8
- package/dist/lib/telemetry.js +55 -7
- package/dist/lib/testlist.types.d.ts +1 -0
- package/dist/lib/ticker.d.ts +9 -0
- package/dist/lib/ticker.js +18 -0
- package/dist/lib/tunnel-session.d.ts +3 -4
- package/dist/lib/tunnel-session.js +3 -4
- package/dist/lib/v3-advisory.js +0 -1
- package/dist/vendor/tunnel-client/client.d.ts +15 -8
- package/dist/vendor/tunnel-client/client.js +477 -407
- package/dist/vendor/tunnel-client/config.d.ts +5 -5
- package/dist/vendor/tunnel-client/config.js +5 -5
- package/dist/vendor/tunnel-client/index.d.ts +4 -4
- package/dist/vendor/tunnel-client/index.js +4 -4
- package/dist/vendor/tunnel-client/types.d.ts +19 -34
- package/dist/vendor/tunnel-client/types.js +1 -0
- package/dist/vendor/tunnel-client/ws-compat.d.ts +13 -3
- package/dist/vendor/tunnel-client/ws-compat.js +70 -12
- 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/skills/testsprite-onboard.skill.md +4 -4
package/dist/commands/ci.js
CHANGED
|
@@ -3,24 +3,35 @@ import { spawnSync as nodeSpawnSync } from 'node:child_process';
|
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import { Command } from 'commander';
|
|
5
5
|
import { makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
6
|
-
import { CLIError, localValidationError } from '../lib/errors.js';
|
|
6
|
+
import { ApiError, CLIError, localValidationError } from '../lib/errors.js';
|
|
7
7
|
import { loadConfig, resolveProfileName } from '../lib/config.js';
|
|
8
8
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
9
9
|
import { assertNotLocal } from '../lib/target-url.js';
|
|
10
10
|
import { classifyLinkage, isValidRepoSlug, parseDeploymentsPayload, parseRepoSlug, } from '../lib/ci-linkage.js';
|
|
11
|
-
import { recordTelemetryExtras } from '../lib/telemetry.js';
|
|
12
|
-
import {
|
|
11
|
+
import { ciRefusalOutcome, recordTelemetryExtras } from '../lib/telemetry.js';
|
|
12
|
+
import { runTestRunAll } from './test.js';
|
|
13
|
+
import { emitCiStepOutputs } from '../lib/gh-output.js';
|
|
14
|
+
import { previewEnvironmentName, readGithubRunContext } from '../lib/github-context.js';
|
|
15
|
+
import { parseJUnitReportFormat } from '../lib/junit-report.js';
|
|
13
16
|
// ── constants ────────────────────────────────────────────────────────────────
|
|
14
17
|
/** Platforms `ci init` can scaffold. One today; the positional arg leaves room. */
|
|
15
18
|
const SUPPORTED_PLATFORMS = ['github'];
|
|
16
19
|
/** Default location a GitHub Actions workflow must live to be picked up. */
|
|
17
20
|
const DEFAULT_WORKFLOW_PATH = '.github/workflows/testsprite.yml';
|
|
21
|
+
/** Where GitHub Actions picks workflows up from; `--path` must stay inside it. */
|
|
22
|
+
const WORKFLOWS_DIR = '.github/workflows';
|
|
18
23
|
/** Default terminal-verdict wait, matching the CLI's own `test run` default. */
|
|
19
24
|
const DEFAULT_TIMEOUT_SECONDS = 600;
|
|
20
25
|
/** The repo secret the generated workflow reads the API key from. */
|
|
21
26
|
const API_KEY_SECRET_NAME = 'TESTSPRITE_API_KEY';
|
|
22
|
-
/**
|
|
23
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The CLI the generated workflow installs. Always `latest`: what a run means is
|
|
29
|
+
* decided by the backend, which is not versioned with the CLI, so a pinned
|
|
30
|
+
* client only freezes old semantics and is never bumped in practice.
|
|
31
|
+
*/
|
|
32
|
+
const CLI_PACKAGE_SPEC = '@testsprite/testsprite-cli@latest';
|
|
33
|
+
/** The machine summary `ci run` writes, and the artifact the workflow uploads. */
|
|
34
|
+
const SUMMARY_FILE = 'testsprite-summary.json';
|
|
24
35
|
/** The CLI's built-in production endpoint (mirrors `config.ts`). Used to decide
|
|
25
36
|
* whether the generated workflow needs an explicit `endpoint-url`. */
|
|
26
37
|
const DEFAULT_API_URL = 'https://api.testsprite.com';
|
|
@@ -35,8 +46,10 @@ const defaultCiFs = {
|
|
|
35
46
|
// eslint-disable-next-line security/detect-non-literal-fs-filename -- parent dir of the scaffold output path (above).
|
|
36
47
|
await nodeFs.mkdir(dir, { recursive: true });
|
|
37
48
|
},
|
|
38
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- reads back the scaffold output path
|
|
49
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- reads back the scaffold output path (identical-content check) or a sibling workflow in the same dir.
|
|
39
50
|
readFile: target => nodeFs.readFile(target, 'utf8'),
|
|
51
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- lists the workflows dir that holds the scaffold output path.
|
|
52
|
+
readdir: dir => nodeFs.readdir(dir),
|
|
40
53
|
};
|
|
41
54
|
const defaultSpawn = (cmd, args, opts) => nodeSpawnSync(cmd, args, {
|
|
42
55
|
input: opts.input,
|
|
@@ -75,12 +88,23 @@ export function parseTimeoutSeconds(raw) {
|
|
|
75
88
|
}
|
|
76
89
|
return n;
|
|
77
90
|
}
|
|
91
|
+
const DEFAULT_EXECUTION_REPORT_TIMEOUT_SECONDS = 60;
|
|
92
|
+
/** `--execution-report-timeout <s>`: same bounds as `--timeout`, its own default. */
|
|
93
|
+
export function parseExecutionReportTimeoutSeconds(raw) {
|
|
94
|
+
if (raw === undefined)
|
|
95
|
+
return DEFAULT_EXECUTION_REPORT_TIMEOUT_SECONDS;
|
|
96
|
+
const n = Number(raw);
|
|
97
|
+
if (!Number.isInteger(n) || n < 1 || n > 3600) {
|
|
98
|
+
throw localValidationError('execution-report-timeout', 'must be an integer between 1 and 3600 seconds');
|
|
99
|
+
}
|
|
100
|
+
return n;
|
|
101
|
+
}
|
|
78
102
|
/**
|
|
79
103
|
* Reject a value that will be interpolated into a double-quoted YAML scalar in
|
|
80
104
|
* the generated workflow. `"` breaks the scalar, a newline breaks the mapping,
|
|
81
105
|
* and `` ` ``/`$` (which also covers `${{ … }}`, evaluated by Actions before the
|
|
82
|
-
* job runs) or `\` could change what the workflow does. A
|
|
83
|
-
*
|
|
106
|
+
* job runs) or `\` could change what the workflow does. A project id, an
|
|
107
|
+
* environment name and an endpoint URL never need any of these, so refusing is
|
|
84
108
|
* safe and keeps the scaffold from ever emitting a workflow GitHub can't parse.
|
|
85
109
|
*/
|
|
86
110
|
function assertSafeWorkflowValue(field, value) {
|
|
@@ -107,70 +131,127 @@ function resolveEndpointUrl(opts, deps) {
|
|
|
107
131
|
return strip(apiUrl) === strip(DEFAULT_API_URL) ? undefined : apiUrl;
|
|
108
132
|
}
|
|
109
133
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (ref && !/[\r\n"`$\\[\]]/.test(ref))
|
|
120
|
-
return ref;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
/* fall through to the default */
|
|
125
|
-
}
|
|
126
|
-
return 'main';
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Build the GitHub Actions workflow. It delegates to the published
|
|
130
|
-
* `TestSprite/testsprite-action` (design A) rather than inlining the CLI, so the
|
|
131
|
-
* partial-run guard (`allow-partial: false` by default), the JUnit upload, the
|
|
132
|
-
* annotations, and the CLI-version pin all come from one maintained place.
|
|
134
|
+
* Build the GitHub Actions workflow. It calls the CLI directly (`ci run`), which
|
|
135
|
+
* owns every judgement — waiting, skipped counts, the exit code, the PR
|
|
136
|
+
* context — so the yml only moves data.
|
|
137
|
+
*
|
|
138
|
+
* One template covers both ways a PR gets a preview, because they differ only
|
|
139
|
+
* in where the URL comes from. The trigger, `if:` and concurrency already accept
|
|
140
|
+
* both events; the single placeholder step is the part only the repo owner can
|
|
141
|
+
* write, and it fails loudly until replaced so the gate can never run against a
|
|
142
|
+
* URL nobody chose.
|
|
133
143
|
*/
|
|
134
144
|
export function buildGithubWorkflow(input) {
|
|
135
145
|
assertSafeWorkflowValue('project', input.projectId);
|
|
136
|
-
|
|
137
|
-
assertSafeWorkflowValue('filter', input.filter);
|
|
146
|
+
assertSafeWorkflowValue('env', input.environment);
|
|
138
147
|
if (input.endpointUrl)
|
|
139
148
|
assertSafeWorkflowValue('endpoint-url', input.endpointUrl);
|
|
140
|
-
const
|
|
141
|
-
`
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
`
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
const envLines = [
|
|
150
|
+
` ${API_KEY_SECRET_NAME}: \${{ secrets.${API_KEY_SECRET_NAME} }}`,
|
|
151
|
+
' # ci run looks up the PR behind a deployment_status event with this token.',
|
|
152
|
+
' GITHUB_TOKEN: ${{ github.token }}',
|
|
153
|
+
...(input.endpointUrl ? [` TESTSPRITE_API_URL: "${input.endpointUrl}"`] : []),
|
|
154
|
+
];
|
|
155
|
+
const runLines = [
|
|
156
|
+
' testsprite ci run',
|
|
157
|
+
` --project "${input.projectId}"`,
|
|
158
|
+
` --env "${input.environment}"`,
|
|
159
|
+
' --target-url "$PREVIEW_URL"',
|
|
160
|
+
// A gate must not go green on tests that never ran (a deferred or
|
|
161
|
+
// refused test is "skipped", which only warns by default).
|
|
162
|
+
' --fail-on-skipped',
|
|
163
|
+
...(input.timeoutSeconds !== undefined ? [` --timeout ${input.timeoutSeconds}`] : []),
|
|
164
|
+
` --summary-file ${SUMMARY_FILE}`,
|
|
147
165
|
];
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
#
|
|
152
|
-
#
|
|
166
|
+
// Leave room for the CLI's own deadline plus install/deploy time.
|
|
167
|
+
const jobMinutes = Math.max(45, Math.ceil((input.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS) / 60) + 15);
|
|
168
|
+
return `# Generated by \`testsprite ci init github\`. Regenerate with --force (the previous file is kept as a .bak).
|
|
169
|
+
# Runs this project's TestSprite tests against each pull request's preview deployment.
|
|
170
|
+
# Before committing, replace the placeholder step marked "REPLACE ME" below.
|
|
153
171
|
name: TestSprite
|
|
154
172
|
|
|
155
173
|
on:
|
|
156
|
-
|
|
157
|
-
|
|
174
|
+
# B. You deploy in this workflow: keep this trigger.
|
|
175
|
+
# A. Your platform deploys every PR (e.g. the Vercel git integration):
|
|
176
|
+
# replace the pull_request trigger with \`deployment_status:\`.
|
|
158
177
|
pull_request:
|
|
178
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
159
179
|
|
|
160
|
-
# The job only needs to read the checkout metadata.
|
|
161
180
|
permissions:
|
|
162
181
|
contents: read
|
|
182
|
+
pull-requests: read
|
|
163
183
|
|
|
164
184
|
jobs:
|
|
165
|
-
testsprite:
|
|
185
|
+
testsprite-tests:
|
|
186
|
+
# B (pull_request): a new push to the pull request cancels the previous job.
|
|
187
|
+
# A (deployment_status): one group per COMMIT — Vercel sets deployment.ref to
|
|
188
|
+
# the commit sha, so a new push does not cancel the previous commit's job.
|
|
189
|
+
# Job-level, so events the if: below drops (pending, inactive, another
|
|
190
|
+
# project's deployment of the same commit) never cancel a running gate.
|
|
191
|
+
# Cancelling only stops this job's CLI: the TestSprite run it started keeps
|
|
192
|
+
# executing and reports in the Portal; the new push starts its own run.
|
|
193
|
+
concurrency:
|
|
194
|
+
group: testsprite-\${{ github.event.pull_request.number || github.event.deployment.sha }}
|
|
195
|
+
cancel-in-progress: true
|
|
196
|
+
# pull_request: skip fork PRs (they get no repository secrets) and draft PRs.
|
|
197
|
+
# deployment_status: only successful, non-production deployments. Vercel leaves
|
|
198
|
+
# production_environment false on production deployments, so the name is checked too
|
|
199
|
+
# (GitHub compares strings case-insensitively).
|
|
200
|
+
# deployment_status runs the workflow file AT THE DEPLOYED COMMIT, with this
|
|
201
|
+
# repository's secrets, and the event does not say whether that commit came
|
|
202
|
+
# from a fork. If your platform deploys pull requests from forks, turn that
|
|
203
|
+
# off there (e.g. Vercel's fork protection) or a fork's edit of this file
|
|
204
|
+
# runs with your TESTSPRITE_API_KEY.
|
|
205
|
+
# A repository that deploys SEVERAL projects (Vercel names them
|
|
206
|
+
# "Preview – <project>") gets one deployment_status per project for the
|
|
207
|
+
# same commit; pin the one to gate by adding
|
|
208
|
+
# && github.event.deployment.environment == 'Preview – <project>'
|
|
209
|
+
# to the deployment_status branch below.
|
|
210
|
+
if: >-
|
|
211
|
+
(github.event_name == 'pull_request' &&
|
|
212
|
+
github.event.pull_request.head.repo.full_name == github.repository &&
|
|
213
|
+
!github.event.pull_request.draft) ||
|
|
214
|
+
(github.event_name == 'deployment_status' &&
|
|
215
|
+
github.event.deployment_status.state == 'success' &&
|
|
216
|
+
!github.event.deployment.production_environment &&
|
|
217
|
+
github.event.deployment.environment != 'production')
|
|
166
218
|
runs-on: ubuntu-latest
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
219
|
+
timeout-minutes: ${jobMinutes}
|
|
220
|
+
env:
|
|
221
|
+
${envLines.join('\n')}
|
|
170
222
|
steps:
|
|
171
|
-
- uses:
|
|
223
|
+
- uses: actions/checkout@v4
|
|
224
|
+
|
|
225
|
+
- uses: actions/setup-node@v4
|
|
172
226
|
with:
|
|
173
|
-
|
|
227
|
+
node-version: '22'
|
|
228
|
+
|
|
229
|
+
- run: npm i -g ${CLI_PACKAGE_SPEC}
|
|
230
|
+
|
|
231
|
+
# REPLACE ME — where does this PR's preview URL come from? Pick one:
|
|
232
|
+
# A. Your platform deploys every PR: delete this step (and switch the trigger
|
|
233
|
+
# above). The next step then reads the URL from the deployment event.
|
|
234
|
+
# B. You deploy in this workflow: replace the run lines with your deploy
|
|
235
|
+
# commands and end with: echo "url=<preview address>" >> "$GITHUB_OUTPUT"
|
|
236
|
+
- name: Get this PR's preview URL
|
|
237
|
+
id: preview
|
|
238
|
+
run: |
|
|
239
|
+
echo "::error::Replace the placeholder step in ${input.workflowPath} (see the comment above it)."
|
|
240
|
+
exit 1
|
|
241
|
+
|
|
242
|
+
- name: Run TestSprite tests on this PR's preview
|
|
243
|
+
env:
|
|
244
|
+
PREVIEW_URL: \${{ steps.preview.outputs.url || github.event.deployment_status.environment_url }}
|
|
245
|
+
run: >-
|
|
246
|
+
${runLines.join('\n')}
|
|
247
|
+
|
|
248
|
+
- name: Upload TestSprite report
|
|
249
|
+
if: always()
|
|
250
|
+
uses: actions/upload-artifact@v4
|
|
251
|
+
with:
|
|
252
|
+
name: testsprite-results
|
|
253
|
+
path: ${SUMMARY_FILE}
|
|
254
|
+
if-no-files-found: ignore
|
|
174
255
|
`;
|
|
175
256
|
}
|
|
176
257
|
/**
|
|
@@ -198,21 +279,80 @@ async function resolveProjectId(opts, deps) {
|
|
|
198
279
|
}
|
|
199
280
|
return only.id;
|
|
200
281
|
}
|
|
201
|
-
/**
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
282
|
+
/**
|
|
283
|
+
* The environment written into `ci run --env`: its sign-in is what every PR run
|
|
284
|
+
* is cloned from. An explicit `--env` must exist (a typo would otherwise fail
|
|
285
|
+
* on every PR); without one the project's default is named explicitly, so a
|
|
286
|
+
* later change of the default never silently changes what this workflow runs.
|
|
287
|
+
* Under `--dry-run` nothing is looked up, so `authMode` is unknown.
|
|
288
|
+
*/
|
|
289
|
+
async function resolveEnvironment(opts, deps, projectId) {
|
|
290
|
+
const requested = opts.env?.trim();
|
|
291
|
+
if (opts.env !== undefined && !requested) {
|
|
292
|
+
throw localValidationError('env', 'must be a non-empty environment name (list them with: testsprite project env list <project-id>)');
|
|
293
|
+
}
|
|
294
|
+
if (opts.dryRun)
|
|
295
|
+
return { name: requested ?? '<your-env-name>' };
|
|
296
|
+
const client = makeClient(opts, deps);
|
|
297
|
+
const listed = await client.get(`/projects/${encodeURIComponent(projectId)}/env`);
|
|
298
|
+
const environments = listed.environments ?? [];
|
|
299
|
+
const names = environments.map(e => e.name).join(', ') || '(none)';
|
|
300
|
+
if (requested !== undefined) {
|
|
301
|
+
const match = environments.find(e => e.name === requested);
|
|
302
|
+
if (!match) {
|
|
303
|
+
throw localValidationError('env', `no environment named "${requested}" in project ${projectId} — available: ${names}`);
|
|
304
|
+
}
|
|
305
|
+
return { name: match.name, authMode: match.authMode };
|
|
306
|
+
}
|
|
307
|
+
const fallback = environments.find(e => e.isDefault);
|
|
308
|
+
if (!fallback) {
|
|
309
|
+
throw localValidationError('env', `project ${projectId} has no default environment — pass --env <name> (available: ${names})`);
|
|
310
|
+
}
|
|
311
|
+
return { name: fallback.name, authMode: fallback.authMode };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* `--path` relative to the repo, with forward slashes. GitHub only runs
|
|
315
|
+
* workflows from `.github/workflows/*.yml|yaml`; anywhere else the file is
|
|
316
|
+
* written and silently never runs, so it is refused.
|
|
317
|
+
*/
|
|
318
|
+
function resolveWorkflowPath(raw, cwd) {
|
|
319
|
+
// `join`, not `resolve`: the latter would prepend the drive letter on
|
|
320
|
+
// Windows and no longer line up with the caller's own `cwd`-based paths.
|
|
321
|
+
const absPath = path.isAbsolute(raw) ? path.normalize(raw) : path.join(cwd, raw);
|
|
322
|
+
const relPath = path.relative(cwd, absPath).split(path.sep).join('/');
|
|
323
|
+
const dir = path.posix.dirname(relPath);
|
|
324
|
+
if (dir !== WORKFLOWS_DIR || !/\.ya?ml$/.test(relPath)) {
|
|
325
|
+
throw localValidationError('path', `must be a .yml or .yaml file directly under ${WORKFLOWS_DIR}/ (GitHub never runs a workflow anywhere else)`, undefined, 'field');
|
|
326
|
+
}
|
|
327
|
+
return { relPath, absPath };
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Other workflows that already mention TestSprite (the CLI, or one of our
|
|
331
|
+
* actions). Two gates on one PR run every test twice and are billed twice, so
|
|
332
|
+
* the caller warns; it never blocks, because two workflows can be deliberate.
|
|
333
|
+
*/
|
|
334
|
+
async function findOtherTestspriteWorkflows(fs, absDir, absTarget) {
|
|
335
|
+
let entries;
|
|
336
|
+
try {
|
|
337
|
+
entries = await fs.readdir(absDir);
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
const hits = [];
|
|
343
|
+
for (const name of entries.sort()) {
|
|
344
|
+
const abs = path.join(absDir, name);
|
|
345
|
+
if (abs === absTarget || !/\.ya?ml$/.test(name))
|
|
346
|
+
continue;
|
|
205
347
|
try {
|
|
206
|
-
await fs.
|
|
207
|
-
|
|
348
|
+
if (/testsprite/i.test(await fs.readFile(abs)))
|
|
349
|
+
hits.push(`${WORKFLOWS_DIR}/${name}`);
|
|
208
350
|
}
|
|
209
|
-
catch
|
|
210
|
-
|
|
211
|
-
continue;
|
|
212
|
-
throw err;
|
|
351
|
+
catch {
|
|
352
|
+
/* unreadable or a directory: nothing to report */
|
|
213
353
|
}
|
|
214
354
|
}
|
|
215
|
-
|
|
355
|
+
return hits;
|
|
216
356
|
}
|
|
217
357
|
/**
|
|
218
358
|
* Optionally set the repo secret via `gh` (soft dependency — never fails the
|
|
@@ -266,7 +406,7 @@ export async function runCiInit(opts, deps = {}) {
|
|
|
266
406
|
}
|
|
267
407
|
const platform = opts.platform;
|
|
268
408
|
// Telemetry facts for this invocation (see lib/telemetry.ts — low-cardinality
|
|
269
|
-
// only: never the path, the project id, or the
|
|
409
|
+
// only: never the path, the project id, or the environment name). `workflowExisted` is
|
|
270
410
|
// learned only once the write is attempted, so it is filled in below and the
|
|
271
411
|
// whole set is recorded on every exit path, including a thrown error.
|
|
272
412
|
let workflowExisted;
|
|
@@ -295,28 +435,33 @@ async function runCiInitScaffold(opts, deps, platform, onExisted) {
|
|
|
295
435
|
const stdout = deps.stdout ?? ((line) => process.stdout.write(`${line}\n`));
|
|
296
436
|
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
297
437
|
const fs = deps.fs ?? defaultCiFs;
|
|
298
|
-
const spawn = deps.spawn ?? defaultSpawn;
|
|
299
438
|
const cwd = deps.cwd ?? process.cwd();
|
|
300
439
|
const out = new Output(opts.output, { stdout, stderr });
|
|
301
|
-
// Validate the caller's own inputs up front — BEFORE
|
|
302
|
-
//
|
|
303
|
-
if (opts.filter)
|
|
304
|
-
assertSafeWorkflowValue('filter', opts.filter);
|
|
440
|
+
// Validate the caller's own inputs up front — BEFORE any round trip — so a
|
|
441
|
+
// bad --project/--env/--path fails fast without a wasted request.
|
|
305
442
|
if (opts.project)
|
|
306
443
|
assertSafeWorkflowValue('project', opts.project);
|
|
444
|
+
if (opts.env)
|
|
445
|
+
assertSafeWorkflowValue('env', opts.env);
|
|
446
|
+
const { relPath, absPath } = resolveWorkflowPath(opts.workflowPath, cwd);
|
|
307
447
|
const projectId = await resolveProjectId(opts, deps);
|
|
448
|
+
const resolvedEnv = await resolveEnvironment(opts, deps, projectId);
|
|
449
|
+
const environment = resolvedEnv.name;
|
|
450
|
+
// A recorded (SSO/manual) session is bound to the environment's own address,
|
|
451
|
+
// so it cannot sign in on a preview; the backend refuses those PR runs before
|
|
452
|
+
// charging. Writing the workflow is still allowed — the user may change the
|
|
453
|
+
// environment's sign-in later — but say so now rather than on the first PR.
|
|
454
|
+
if (resolvedEnv.authMode === 'manual') {
|
|
455
|
+
stderr(`[warn] environment "${environment}" signs in with a recorded SSO session, which cannot follow a preview's address — PR runs against it will be refused. Prefer an environment with a test account or no sign-in (testsprite project env list ${projectId}).`);
|
|
456
|
+
}
|
|
308
457
|
const endpointUrl = resolveEndpointUrl(opts, deps);
|
|
309
|
-
const defaultBranch = detectDefaultBranch(cwd, spawn);
|
|
310
458
|
const workflow = buildGithubWorkflow({
|
|
311
459
|
projectId,
|
|
312
|
-
|
|
460
|
+
environment,
|
|
313
461
|
timeoutSeconds: opts.timeoutSeconds,
|
|
314
462
|
endpointUrl,
|
|
315
|
-
|
|
316
|
-
defaultBranch,
|
|
463
|
+
workflowPath: relPath,
|
|
317
464
|
});
|
|
318
|
-
const relPath = opts.workflowPath;
|
|
319
|
-
const absPath = path.isAbsolute(relPath) ? relPath : path.join(cwd, relPath);
|
|
320
465
|
// A loopback / private endpoint pinned into a committed workflow is
|
|
321
466
|
// unreachable from a GitHub-hosted runner (the check reds on first push with
|
|
322
467
|
// nothing explaining why). Reuse `assertNotLocal`'s classifier to WARN — not
|
|
@@ -334,15 +479,19 @@ async function runCiInitScaffold(opts, deps, platform, onExisted) {
|
|
|
334
479
|
stderr(`[warn] ${endpointWarning}`);
|
|
335
480
|
}
|
|
336
481
|
}
|
|
482
|
+
const otherTestspriteWorkflows = await findOtherTestspriteWorkflows(fs, path.dirname(absPath), absPath);
|
|
483
|
+
if (otherTestspriteWorkflows.length > 0) {
|
|
484
|
+
stderr(`[warn] ${otherTestspriteWorkflows.join(', ')} already run${otherTestspriteWorkflows.length === 1 ? 's' : ''} TestSprite — with this workflow too, each PR may run (and be billed for) its tests twice.`);
|
|
485
|
+
}
|
|
337
486
|
const baseSummary = {
|
|
338
487
|
platform,
|
|
339
488
|
path: relPath,
|
|
340
|
-
action: ACTION_REF,
|
|
341
489
|
projectId,
|
|
342
|
-
|
|
490
|
+
environment,
|
|
343
491
|
endpointUrl: endpointUrl ?? null,
|
|
344
492
|
endpointWarning,
|
|
345
|
-
timeoutSeconds: opts.timeoutSeconds,
|
|
493
|
+
timeoutSeconds: opts.timeoutSeconds ?? null,
|
|
494
|
+
otherTestspriteWorkflows,
|
|
346
495
|
};
|
|
347
496
|
// --dry-run: preview to stderr, emit the summary, and make no writes / no gh call.
|
|
348
497
|
if (opts.dryRun) {
|
|
@@ -354,15 +503,14 @@ async function runCiInitScaffold(opts, deps, platform, onExisted) {
|
|
|
354
503
|
...baseSummary,
|
|
355
504
|
wrote: false,
|
|
356
505
|
status: 'preview',
|
|
357
|
-
backupPath: null,
|
|
358
506
|
secret: { name: API_KEY_SECRET_NAME, attempted: false, set: false, reason: null },
|
|
359
507
|
};
|
|
360
508
|
out.print(summary, d => renderCiInitText(d));
|
|
361
509
|
return;
|
|
362
510
|
}
|
|
363
511
|
await fs.mkdir(path.dirname(absPath));
|
|
364
|
-
let backupPath = null;
|
|
365
512
|
let wrote = true;
|
|
513
|
+
let backupPath = null;
|
|
366
514
|
try {
|
|
367
515
|
await fs.writeFile(absPath, workflow, { exclusive: true });
|
|
368
516
|
onExisted(false);
|
|
@@ -377,16 +525,18 @@ async function runCiInitScaffold(opts, deps, platform, onExisted) {
|
|
|
377
525
|
onExisted(true);
|
|
378
526
|
const prior = await fs.readFile(absPath);
|
|
379
527
|
if (prior === workflow) {
|
|
380
|
-
// Already exactly what we'd write
|
|
381
|
-
//
|
|
382
|
-
// rather than an error, so it never burns a backup slot.
|
|
528
|
+
// Already exactly what we'd write: no rewrite, and re-running (with or
|
|
529
|
+
// without --force) on identical content is a no-op rather than an error.
|
|
383
530
|
wrote = false;
|
|
384
531
|
}
|
|
385
532
|
else if (!opts.force) {
|
|
386
|
-
throw localValidationError('path', `${relPath} already exists — re-run with --force to overwrite (
|
|
533
|
+
throw localValidationError('path', `${relPath} already exists — re-run with --force to overwrite it (git keeps the old version)`, undefined, 'field');
|
|
387
534
|
}
|
|
388
535
|
else {
|
|
389
|
-
|
|
536
|
+
// The template needs a hand edit (the preview step), so a --force to
|
|
537
|
+
// change one flag must not silently discard it: keep the old file.
|
|
538
|
+
backupPath = `${absPath}.bak`;
|
|
539
|
+
await fs.writeFile(backupPath, prior, { exclusive: false });
|
|
390
540
|
await fs.writeFile(absPath, workflow, { exclusive: false });
|
|
391
541
|
}
|
|
392
542
|
}
|
|
@@ -400,7 +550,8 @@ async function runCiInitScaffold(opts, deps, platform, onExisted) {
|
|
|
400
550
|
...baseSummary,
|
|
401
551
|
wrote,
|
|
402
552
|
status: wrote ? 'written' : 'unchanged',
|
|
403
|
-
|
|
553
|
+
// Relative like `path`, and forward-slashed on every OS for the same reason.
|
|
554
|
+
...(backupPath !== null ? { backupPath: `${relPath}.bak` } : {}),
|
|
404
555
|
secret: { name: API_KEY_SECRET_NAME, ...secret },
|
|
405
556
|
};
|
|
406
557
|
out.print(summary, d => renderCiInitText(d));
|
|
@@ -799,33 +950,222 @@ export function renderCiInitText(s) {
|
|
|
799
950
|
: s.status === 'preview'
|
|
800
951
|
? `Would write ${s.path}`
|
|
801
952
|
: `${s.path} is already up to date`;
|
|
802
|
-
lines.push(`${verb} (${s.
|
|
953
|
+
lines.push(`${verb} (project ${s.projectId}, environment ${s.environment}).`);
|
|
803
954
|
if (s.backupPath)
|
|
804
|
-
lines.push(`
|
|
955
|
+
lines.push(`The previous file was kept as ${s.backupPath}; re-apply your edits.`);
|
|
805
956
|
lines.push('');
|
|
806
957
|
lines.push('Next steps:');
|
|
958
|
+
lines.push(` 1. Replace the "REPLACE ME" step in ${s.path} with where this PR's preview URL`);
|
|
959
|
+
lines.push(' comes from (the comment on it shows both options). Until then the check fails.');
|
|
807
960
|
if (s.secret.set) {
|
|
808
|
-
lines.push(` ✓ ${s.secret.name} repo secret set via gh.`);
|
|
809
|
-
lines.push(` → Commit and push ${s.path}, then open a PR to see the check.`);
|
|
961
|
+
lines.push(` 2. ✓ ${s.secret.name} repo secret set via gh.`);
|
|
810
962
|
}
|
|
811
963
|
else {
|
|
812
|
-
lines.push(`
|
|
964
|
+
lines.push(` 2. Add the ${s.secret.name} repo secret (the workflow reads the key from it):`);
|
|
813
965
|
lines.push(` gh secret set ${s.secret.name} # paste your key when prompted`);
|
|
814
966
|
lines.push(' …or in the GitHub UI: Settings → Secrets and variables → Actions.');
|
|
815
|
-
lines.push(` 2. Commit and push ${s.path}, then open a PR to see the check.`);
|
|
816
967
|
}
|
|
968
|
+
lines.push(` 3. Commit and push ${s.path}, then open a PR and confirm the check runs`);
|
|
969
|
+
lines.push(" against that PR's preview. To block merges on it, make it a required check.");
|
|
817
970
|
return lines.join('\n');
|
|
818
971
|
}
|
|
819
|
-
|
|
972
|
+
/**
|
|
973
|
+
* `ci run` = `test run --all --wait` with CI's defaults, plus what only a CI
|
|
974
|
+
* job can add:
|
|
975
|
+
*
|
|
976
|
+
* - `admission: 'all'` — one request, one execution, server-side pacing (as
|
|
977
|
+
* for a GitHub App run), so a PR run is one row in the Portal and, in a
|
|
978
|
+
* pull request, one `github-pr-<N>` environment. The backend echoes the
|
|
979
|
+
* field; a backend that cannot honour it is refused (exit 7), never
|
|
980
|
+
* silently cut to the per-key budget and retried.
|
|
981
|
+
* - In a pull request (read off the Actions event, or looked up from the
|
|
982
|
+
* deployment's commit), `--env X --target-url U` runs in a temporary clone
|
|
983
|
+
* of X at U named `github-pr-<N>`, and the run is stamped with the PR so
|
|
984
|
+
* the Portal links back to it — the GitHub App's own mechanism.
|
|
985
|
+
* - Outside a pull request the run keeps `test run`'s semantics: X's sign-in
|
|
986
|
+
* against U, recorded under X.
|
|
987
|
+
*/
|
|
988
|
+
export async function runCiRun(opts, deps = {}) {
|
|
989
|
+
const env = deps.env ?? process.env;
|
|
990
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
991
|
+
if (opts.targetUrl !== undefined && opts.targetUrl.trim() === '') {
|
|
992
|
+
throw localValidationError('target-url', 'must be a non-empty URL');
|
|
993
|
+
}
|
|
994
|
+
// An unknown environment name is a configuration error, not an empty
|
|
995
|
+
// selection: refused here, before anything dispatches or charges, so it
|
|
996
|
+
// can never read as a green `--allow-empty` run.
|
|
997
|
+
try {
|
|
998
|
+
await assertCiEnvironmentExists(opts, deps);
|
|
999
|
+
}
|
|
1000
|
+
catch (err) {
|
|
1001
|
+
// The CLI's own "no such environment" refusal is `refused_env`; any API
|
|
1002
|
+
// refusal while listing (401, 402, 429, …) takes the shared mapping.
|
|
1003
|
+
if (err instanceof ApiError && err.code === 'VALIDATION_ERROR' && err.details.field === 'env') {
|
|
1004
|
+
recordTelemetryExtras({ ciRunOutcome: 'refused_env' });
|
|
1005
|
+
}
|
|
1006
|
+
else if (err instanceof ApiError) {
|
|
1007
|
+
recordTelemetryExtras({ ciRunOutcome: ciRefusalOutcome(err) });
|
|
1008
|
+
}
|
|
1009
|
+
throw err;
|
|
1010
|
+
}
|
|
1011
|
+
const github = await readGithubRunContext(env, { fetchImpl: deps.fetchImpl });
|
|
1012
|
+
let previewName;
|
|
1013
|
+
let githubTrigger;
|
|
1014
|
+
if (github.kind === 'pull_request') {
|
|
1015
|
+
if (github.draft) {
|
|
1016
|
+
recordTelemetryExtras({ ciRunOutcome: 'skipped_draft' });
|
|
1017
|
+
skipCiRun(`Skipping draft pull request #${github.trigger.prNumber}; the gate runs once it is ready for review.`, { env, stderr });
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
githubTrigger = github.trigger;
|
|
1021
|
+
// The clone needs a template to clone and an address to point at.
|
|
1022
|
+
if (opts.targetUrl !== undefined && opts.environment !== undefined) {
|
|
1023
|
+
previewName = previewEnvironmentName(github.trigger.prNumber);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
else if (github.kind === 'no_pull_request' && github.event === 'deployment_status') {
|
|
1027
|
+
// A deployment that belongs to no pull request has nothing to gate.
|
|
1028
|
+
recordTelemetryExtras({ ciRunOutcome: 'skipped_no_pr' });
|
|
1029
|
+
skipCiRun(`Skipping: ${github.reason}; nothing to gate.`, { env, stderr });
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
await runTestRunAll({
|
|
1033
|
+
...opts,
|
|
1034
|
+
timeoutSeconds: parseTimeoutSeconds(opts.timeoutSeconds),
|
|
1035
|
+
wait: true,
|
|
1036
|
+
ci: {
|
|
1037
|
+
failOnSkipped: opts.failOnSkipped,
|
|
1038
|
+
executionReportTimeoutSeconds: opts.executionReportTimeoutSeconds,
|
|
1039
|
+
...(opts.executionReport === false ? { executionReport: false } : {}),
|
|
1040
|
+
},
|
|
1041
|
+
admission: 'all',
|
|
1042
|
+
...(previewName !== undefined ? { previewName } : {}),
|
|
1043
|
+
...(githubTrigger !== undefined ? { githubTrigger } : {}),
|
|
1044
|
+
}, deps);
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* A `ci run` that has nothing to gate (a draft PR, a deployment with no pull
|
|
1048
|
+
* request) exits 0 with a `::notice::` — and still writes its step outputs, as
|
|
1049
|
+
* zeros, so a later step reading `steps.<id>.outputs.passed` sees a number
|
|
1050
|
+
* rather than an empty string. Nothing was dispatched, so nothing else (job
|
|
1051
|
+
* summary, summary file, report) is written: those describe runs.
|
|
1052
|
+
*/
|
|
1053
|
+
function skipCiRun(notice, io) {
|
|
1054
|
+
io.stderr(`::notice title=TestSprite::${notice}`);
|
|
1055
|
+
const nothing = { total: 0, passed: 0, failed: 0, skipped: 0, timedOut: 0, runs: [] };
|
|
1056
|
+
emitCiStepOutputs(nothing, io);
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Strict `--env`: the name must be one of the project's environments, read
|
|
1060
|
+
* off the same list `test run` reads before a batch. Fails closed: a list that
|
|
1061
|
+
* cannot be read is an error with that error's own exit code (bad key → 3,
|
|
1062
|
+
* backend down → 10, interrupted → the signal's code) — never a run that goes
|
|
1063
|
+
* on to dispatch and charge against an environment nobody checked. The one
|
|
1064
|
+
* read that is NOT an error is a backend answering that this project has no
|
|
1065
|
+
* environment surface at all (a V2 project's `UNSUPPORTED`, or an older
|
|
1066
|
+
* backend's 404 for the route): there is no list to check against, and the
|
|
1067
|
+
* batch's own `environment` validation is the only authority left. Nothing to
|
|
1068
|
+
* check without a name, and a dry run makes no request.
|
|
1069
|
+
*/
|
|
1070
|
+
async function assertCiEnvironmentExists(opts, deps) {
|
|
1071
|
+
const environment = opts.environment?.trim();
|
|
1072
|
+
const projectId = opts.projectId ?? (deps.env ?? process.env).TESTSPRITE_PROJECT_ID;
|
|
1073
|
+
if (!environment || !projectId || opts.dryRun)
|
|
1074
|
+
return;
|
|
1075
|
+
let listed;
|
|
1076
|
+
try {
|
|
1077
|
+
listed = await makeHttpClient(opts, {
|
|
1078
|
+
env: deps.env,
|
|
1079
|
+
credentialsPath: deps.credentialsPath,
|
|
1080
|
+
fetchImpl: deps.fetchImpl,
|
|
1081
|
+
stderr: deps.stderr,
|
|
1082
|
+
}).get(`/projects/${encodeURIComponent(projectId)}/env`);
|
|
1083
|
+
}
|
|
1084
|
+
catch (err) {
|
|
1085
|
+
if (err instanceof ApiError && (err.code === 'UNSUPPORTED' || err.httpStatus === 404)) {
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
throw err;
|
|
1089
|
+
}
|
|
1090
|
+
const names = (listed.environments ?? [])
|
|
1091
|
+
.map(e => e.name)
|
|
1092
|
+
.filter((n) => typeof n === 'string');
|
|
1093
|
+
if (names.includes(environment))
|
|
1094
|
+
return;
|
|
1095
|
+
throw localValidationError('env', `no environment named "${environment}" in project ${projectId} — available: ${names.join(', ') || '(none)'}`);
|
|
1096
|
+
}
|
|
820
1097
|
export function createCiCommand(deps = {}) {
|
|
821
|
-
const ci = new Command('ci').description('
|
|
1098
|
+
const ci = new Command('ci').description('Run tests in CI and scaffold CI integration');
|
|
1099
|
+
ci.command('run')
|
|
1100
|
+
.description('Run project tests, wait for results, and apply the CI gate')
|
|
1101
|
+
.allowExcessArguments(false)
|
|
1102
|
+
.option('--project <id>', 'project id (defaults to TESTSPRITE_PROJECT_ID)')
|
|
1103
|
+
.option('--all', 'run all project tests (already the default)')
|
|
1104
|
+
.option('--filter <substr>', 'only run tests whose name contains this substring')
|
|
1105
|
+
.option('--env <name>', 'the environment whose sign-in the run uses (unknown names fail). In a pull request, with --target-url, the run happens in a temporary clone of it at the preview address, named github-pr-<N> like a GitHub App run')
|
|
1106
|
+
.option('--target-url <url>', "frontend tests: the address to test, typically this pull request's preview deployment")
|
|
1107
|
+
.option('--skip-preflight', 'skip the pre-charge reachability probe for --target-url', false)
|
|
1108
|
+
.option('--timeout <s>', 'max seconds to wait for results (1-3600)', '600')
|
|
1109
|
+
.option('--execution-report-timeout <s>', 'max seconds to wait for the execution report that fills the job summary (1-3600)', '60')
|
|
1110
|
+
.option('--no-execution-report', 'keep the job summary to the local results table; read and write no execution report')
|
|
1111
|
+
.option('--max-concurrency <n>', 'maximum concurrent polls (1-100)', '50')
|
|
1112
|
+
.option('--idempotency-key <key>', 'idempotency key for the batch dispatch')
|
|
1113
|
+
.option('--fail-on-skipped', 'fail if any requested test was not run (default: warn)')
|
|
1114
|
+
.option('--allow-empty', 'allow zero dispatched tests (default: exit 5)')
|
|
1115
|
+
.option('--gh-output', 'force GitHub annotations and job summary outside Actions')
|
|
1116
|
+
.option('--summary-file <path>', 'write the unified CI summary JSON to this file')
|
|
1117
|
+
.option('--report <format>', 'also write a report (junit); disabled by default')
|
|
1118
|
+
.option('--report-file <path>', 'JUnit report destination (requires --report junit)')
|
|
1119
|
+
.option('--report-suite-name <name>', 'JUnit suite name (default: testsprite:<projectId>)')
|
|
1120
|
+
.addHelpText('after', '\nAlways waits for results. Failed tests and timeouts fail the gate.\n' +
|
|
1121
|
+
'Skipped tests warn unless --fail-on-skipped; missing test ids and unknown\n' +
|
|
1122
|
+
'environments always fail. Every selected test is seeded into ONE execution\n' +
|
|
1123
|
+
'and the server paces dispatch, as for a GitHub App run.\n' +
|
|
1124
|
+
'In GitHub Actions the pull request is read from the event (a deployment_status\n' +
|
|
1125
|
+
'event is looked up by commit with GITHUB_TOKEN); draft PRs and deployments\n' +
|
|
1126
|
+
'with no pull request are skipped with a notice and zero step outputs. The run\n' +
|
|
1127
|
+
'is stamped with the PR, so the Portal links back to it. ci run does not read\n' +
|
|
1128
|
+
"the deployment's state or environment: filter deployment_status events with\n" +
|
|
1129
|
+
"the job's `if:` (state == 'success', not production), or a failed or\n" +
|
|
1130
|
+
'production deployment is gated too.\n' +
|
|
1131
|
+
'Writes total, passed, failed, skipped, timedOut to GITHUB_OUTPUT when present.\n' +
|
|
1132
|
+
'On a supporting backend the job summary is the execution report — the same content\n' +
|
|
1133
|
+
'the GitHub App posts as its PR comment — and execution-report-file /\n' +
|
|
1134
|
+
'execution-report-markdown-file name its JSON and Markdown for later steps.\n' +
|
|
1135
|
+
'Reports and outputs are emitted before the exit code is decided.\n' +
|
|
1136
|
+
'Backend tests use the URL in their own code, not --target-url. PR comments are not yet supported.\n')
|
|
1137
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
1138
|
+
.action(async (cmdOpts, command) => {
|
|
1139
|
+
await runCiRun({
|
|
1140
|
+
...resolveCommonOptions(command),
|
|
1141
|
+
projectId: cmdOpts.project,
|
|
1142
|
+
nameFilter: cmdOpts.filter,
|
|
1143
|
+
environment: cmdOpts.env,
|
|
1144
|
+
targetUrl: cmdOpts.targetUrl,
|
|
1145
|
+
skipPreflight: cmdOpts.skipPreflight === true,
|
|
1146
|
+
timeoutSeconds: parseTimeoutSeconds(cmdOpts.timeout),
|
|
1147
|
+
executionReportTimeoutSeconds: parseExecutionReportTimeoutSeconds(cmdOpts.executionReportTimeout),
|
|
1148
|
+
// Commander's `--no-execution-report` sets `executionReport: false`
|
|
1149
|
+
// (true when absent).
|
|
1150
|
+
executionReport: cmdOpts.executionReport !== false,
|
|
1151
|
+
maxConcurrency: Number(cmdOpts.maxConcurrency),
|
|
1152
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
1153
|
+
failOnSkipped: cmdOpts.failOnSkipped === true,
|
|
1154
|
+
allowEmpty: cmdOpts.allowEmpty === true,
|
|
1155
|
+
ghOutput: cmdOpts.ghOutput === true,
|
|
1156
|
+
summaryFile: cmdOpts.summaryFile,
|
|
1157
|
+
report: parseJUnitReportFormat(cmdOpts.report),
|
|
1158
|
+
reportFile: cmdOpts.reportFile,
|
|
1159
|
+
reportSuiteName: cmdOpts.reportSuiteName,
|
|
1160
|
+
}, deps);
|
|
1161
|
+
});
|
|
822
1162
|
ci.command('init <platform>')
|
|
823
1163
|
.description('Write a CI workflow that runs your TestSprite tests (platform: github)')
|
|
824
1164
|
.option('--project <id>', 'project id to run (auto-detected if you have exactly one)')
|
|
825
|
-
.option('--
|
|
826
|
-
.option('--timeout <s>',
|
|
827
|
-
.option('--path <file>',
|
|
828
|
-
.option('--force', 'overwrite an existing workflow (a .bak
|
|
1165
|
+
.option('--env <name>', "environment whose sign-in each PR run uses (default: the project's default environment, written out by name)")
|
|
1166
|
+
.option('--timeout <s>', "max seconds ci run waits for a terminal verdict (1-3600; omitted: ci run's default)")
|
|
1167
|
+
.option('--path <file>', `workflow file to write, under ${WORKFLOWS_DIR}/ (.yml or .yaml)`, DEFAULT_WORKFLOW_PATH)
|
|
1168
|
+
.option('--force', 'overwrite an existing workflow with different content (keeps a .bak)', false)
|
|
829
1169
|
.option('--set-secret', `set the ${API_KEY_SECRET_NAME} repo secret via gh (if installed + authenticated); OVERWRITES an existing secret of that name`, false)
|
|
830
1170
|
.option('--repo <owner/name>', 'target repo for --set-secret (gh infers from the cwd if omitted)')
|
|
831
1171
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
@@ -835,8 +1175,8 @@ export function createCiCommand(deps = {}) {
|
|
|
835
1175
|
...common,
|
|
836
1176
|
platform,
|
|
837
1177
|
project: cmdOpts.project,
|
|
838
|
-
|
|
839
|
-
timeoutSeconds: parseTimeoutSeconds(cmdOpts.timeout),
|
|
1178
|
+
env: cmdOpts.env,
|
|
1179
|
+
timeoutSeconds: cmdOpts.timeout === undefined ? undefined : parseTimeoutSeconds(cmdOpts.timeout),
|
|
840
1180
|
workflowPath: cmdOpts.path ?? DEFAULT_WORKFLOW_PATH,
|
|
841
1181
|
force: cmdOpts.force ?? false,
|
|
842
1182
|
setSecret: cmdOpts.setSecret ?? false,
|
|
@@ -844,7 +1184,11 @@ export function createCiCommand(deps = {}) {
|
|
|
844
1184
|
};
|
|
845
1185
|
await runCiInit(opts, deps);
|
|
846
1186
|
});
|
|
847
|
-
ci
|
|
1187
|
+
// `ci doctor` and `ci connect` are hidden and deprecated (step 1 of 2).
|
|
1188
|
+
// Platform checks and linking belong to the agent skill (`testsprite-ci`),
|
|
1189
|
+
// which reads the same deployment history and runs the platform's own CLI.
|
|
1190
|
+
// Behaviour and exit codes are unchanged until the commands are removed.
|
|
1191
|
+
ci.command('doctor', { hidden: true })
|
|
848
1192
|
.description('Check that deployment events reach this repo — the precondition a deployment-gated workflow rests on')
|
|
849
1193
|
.option('--repo <owner/name>', 'repo to check (inferred from the `origin` remote if omitted)')
|
|
850
1194
|
.option('--wait', 'keep checking until a NEW deployment record arrives (use right after connecting + pushing)', false)
|
|
@@ -862,6 +1206,7 @@ export function createCiCommand(deps = {}) {
|
|
|
862
1206
|
' 10 could not read the history (gh missing / unauthenticated) — not a verdict')
|
|
863
1207
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
864
1208
|
.action(async (cmdOpts, command) => {
|
|
1209
|
+
emitCiDeprecationNotice('doctor', deps);
|
|
865
1210
|
const common = resolveCommonOptions(command, deps.env);
|
|
866
1211
|
await runCiDoctor({
|
|
867
1212
|
...common,
|
|
@@ -871,7 +1216,7 @@ export function createCiCommand(deps = {}) {
|
|
|
871
1216
|
waitTimeoutSeconds: cmdOpts.timeout === undefined ? undefined : parseTimeoutSeconds(cmdOpts.timeout),
|
|
872
1217
|
}, deps);
|
|
873
1218
|
});
|
|
874
|
-
ci.command('connect')
|
|
1219
|
+
ci.command('connect', { hidden: true })
|
|
875
1220
|
.description('Link your deploy platform (Vercel) to this repo so deployment events are emitted')
|
|
876
1221
|
.option('--project <name>', 'Vercel project to link when this directory is not linked yet (must already exist)')
|
|
877
1222
|
.addHelpText('after', "\nRuns the platform's own CLI (`npx vercel link` / `vercel git connect`) as a\n" +
|
|
@@ -885,9 +1230,26 @@ export function createCiCommand(deps = {}) {
|
|
|
885
1230
|
'`testsprite ci doctor --wait`.')
|
|
886
1231
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
887
1232
|
.action(async (cmdOpts, command) => {
|
|
1233
|
+
emitCiDeprecationNotice('connect', deps);
|
|
888
1234
|
const common = resolveCommonOptions(command, deps.env);
|
|
889
1235
|
await runCiConnect({ ...common, project: cmdOpts.project }, deps);
|
|
890
1236
|
});
|
|
891
1237
|
return ci;
|
|
892
1238
|
}
|
|
1239
|
+
/**
|
|
1240
|
+
* One stderr line per run of a deprecated `ci` subcommand, naming the
|
|
1241
|
+
* equivalent commands (stdout stays clean for JSON pipelines). The
|
|
1242
|
+
* replacements are not `testsprite` commands, so this does not reuse
|
|
1243
|
+
* `emitDeprecationNotice`.
|
|
1244
|
+
*/
|
|
1245
|
+
export const CI_DEPRECATION_NOTICES = {
|
|
1246
|
+
doctor: '[deprecated] `testsprite ci doctor` will be removed in a later release. Read the deployment history yourself: ' +
|
|
1247
|
+
'`gh api repos/<owner>/<repo>/deployments` — judge preview and production records separately; a real pull request is the proof.',
|
|
1248
|
+
connect: "[deprecated] `testsprite ci connect` will be removed in a later release. Run the platform's own CLI: " +
|
|
1249
|
+
'`npx vercel link --project <name> --non-interactive`, then `npx vercel git connect --non-interactive` (or link the repo in the Vercel dashboard).',
|
|
1250
|
+
};
|
|
1251
|
+
function emitCiDeprecationNotice(cmd, deps) {
|
|
1252
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
1253
|
+
stderr(CI_DEPRECATION_NOTICES[cmd]);
|
|
1254
|
+
}
|
|
893
1255
|
//# sourceMappingURL=ci.js.map
|