@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.
- package/README.md +27 -17
- package/dist/commands/agent.js +7 -2
- package/dist/commands/auth.js +7 -3
- package/dist/commands/ci.d.ts +66 -17
- package/dist/commands/ci.js +486 -122
- package/dist/commands/completion.js +2 -1
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.js +52 -10
- package/dist/commands/init.js +25 -5
- package/dist/commands/project-env.js +39 -17
- package/dist/commands/project-sign-in.js +9 -4
- package/dist/commands/project.js +43 -22
- package/dist/commands/schedule.js +24 -15
- package/dist/commands/test.d.ts +105 -36
- package/dist/commands/test.js +1494 -847
- package/dist/commands/testlist.js +13 -3
- package/dist/commands/tunnel.js +23 -25
- package/dist/commands/usage.js +1 -0
- package/dist/index.js +14 -7
- 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/conflict-reason.d.ts +24 -3
- package/dist/lib/conflict-reason.js +33 -2
- package/dist/lib/credentials.d.ts +0 -1
- package/dist/lib/credentials.js +51 -14
- package/dist/lib/deprecate.d.ts +22 -0
- package/dist/lib/deprecate.js +26 -0
- package/dist/lib/dry-run/samples.js +56 -5
- package/dist/lib/environment-tunnel.d.ts +2 -1
- package/dist/lib/environment-tunnel.js +1 -4
- 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 +29 -3
- package/dist/lib/junit-report.d.ts +3 -0
- package/dist/lib/junit-report.js +8 -1
- package/dist/lib/output.d.ts +11 -1
- package/dist/lib/output.js +17 -2
- package/dist/lib/plans.types.d.ts +1 -1
- package/dist/lib/response-schemas.d.ts +5 -1
- package/dist/lib/response-schemas.js +57 -0
- package/dist/lib/runs.types.d.ts +122 -0
- package/dist/lib/telemetry.d.ts +26 -2
- package/dist/lib/telemetry.js +47 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/schemas/plan.schema.json +2 -2
- package/skills/testsprite-ci.skill.md +154 -0
- package/skills/testsprite-verify.codex.md +7 -7
- package/skills/testsprite-verify.skill.md +24 -21
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,225 @@ 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
|
+
.summary('Write a CI workflow that runs your test cases on pull requests (github)')
|
|
1164
|
+
.description("Write a CI workflow (platform: github) that runs the project's TestSprite test cases against each\n" +
|
|
1165
|
+
'pull request\'s preview deployment; each run spends credits. Replace the "REPLACE ME" step in the\n' +
|
|
1166
|
+
`generated file with your preview URL. Needs the ${API_KEY_SECRET_NAME} repo secret (see --set-secret).`)
|
|
824
1167
|
.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
|
|
1168
|
+
.option('--env <name>', "environment whose sign-in each PR run uses (default: the project's default environment, written out by name)")
|
|
1169
|
+
.option('--timeout <s>', "max seconds ci run waits for a terminal verdict (1-3600; omitted: ci run's default)")
|
|
1170
|
+
.option('--path <file>', `workflow file to write, under ${WORKFLOWS_DIR}/ (.yml or .yaml)`, DEFAULT_WORKFLOW_PATH)
|
|
1171
|
+
.option('--force', 'overwrite an existing workflow with different content (keeps a .bak)', false)
|
|
829
1172
|
.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
1173
|
.option('--repo <owner/name>', 'target repo for --set-secret (gh infers from the cwd if omitted)')
|
|
831
1174
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
@@ -835,8 +1178,8 @@ export function createCiCommand(deps = {}) {
|
|
|
835
1178
|
...common,
|
|
836
1179
|
platform,
|
|
837
1180
|
project: cmdOpts.project,
|
|
838
|
-
|
|
839
|
-
timeoutSeconds: parseTimeoutSeconds(cmdOpts.timeout),
|
|
1181
|
+
env: cmdOpts.env,
|
|
1182
|
+
timeoutSeconds: cmdOpts.timeout === undefined ? undefined : parseTimeoutSeconds(cmdOpts.timeout),
|
|
840
1183
|
workflowPath: cmdOpts.path ?? DEFAULT_WORKFLOW_PATH,
|
|
841
1184
|
force: cmdOpts.force ?? false,
|
|
842
1185
|
setSecret: cmdOpts.setSecret ?? false,
|
|
@@ -844,24 +1187,29 @@ export function createCiCommand(deps = {}) {
|
|
|
844
1187
|
};
|
|
845
1188
|
await runCiInit(opts, deps);
|
|
846
1189
|
});
|
|
847
|
-
ci
|
|
848
|
-
|
|
1190
|
+
// `ci doctor` and `ci connect` are hidden and deprecated (step 1 of 2).
|
|
1191
|
+
// Platform checks and linking belong to the agent skill (`testsprite-ci`),
|
|
1192
|
+
// which reads the same deployment history and runs the platform's own CLI.
|
|
1193
|
+
// Behaviour and exit codes are unchanged until the commands are removed.
|
|
1194
|
+
ci.command('doctor', { hidden: true })
|
|
1195
|
+
.description('Check that deployment events reach this repo — the precondition for a deployment-gated workflow.\n' +
|
|
1196
|
+
'Needs the GitHub CLI (`gh`), installed and authenticated.')
|
|
849
1197
|
.option('--repo <owner/name>', 'repo to check (inferred from the `origin` remote if omitted)')
|
|
850
1198
|
.option('--wait', 'keep checking until a NEW deployment record arrives (use right after connecting + pushing)', false)
|
|
851
1199
|
.option('--timeout <s>', 'with --wait, how long to keep checking (1-3600, default 600)')
|
|
852
|
-
.addHelpText('after', '\
|
|
853
|
-
'
|
|
854
|
-
|
|
855
|
-
' nothing is ever written and the gate stays silent — with no error anywhere.\n' +
|
|
856
|
-
'\n--wait succeeds when any new deployment record arrives, whatever its\n' +
|
|
857
|
-
'environment — a new record is the hard fact that events reach this repo.\n' +
|
|
1200
|
+
.addHelpText('after', '\nA deployment-triggered workflow only fires if the repo receives GitHub Deployment events;\n' +
|
|
1201
|
+
'if the deploy platform is not linked, the gate stays silent with no error.\n' +
|
|
1202
|
+
'--wait succeeds when any new deployment record arrives, whatever its environment.\n' +
|
|
858
1203
|
'\nExit codes:\n' +
|
|
859
|
-
' 0 events reach this repo (a gate will fire), or --wait saw a new record\n' +
|
|
1204
|
+
' 0 events reach this repo (a gate will fire), or --wait saw a new record. With --wait and\n' +
|
|
1205
|
+
' no new record before --timeout it is still 0 if earlier events exist: check the output\n' +
|
|
1206
|
+
' (JSON: newDeployment)\n' +
|
|
860
1207
|
' 1 no usable events yet — see the printed next steps\n' +
|
|
861
1208
|
' 5 validation error (bad --repo, or no GitHub remote here)\n' +
|
|
862
1209
|
' 10 could not read the history (gh missing / unauthenticated) — not a verdict')
|
|
863
1210
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
864
1211
|
.action(async (cmdOpts, command) => {
|
|
1212
|
+
emitCiDeprecationNotice('doctor', deps);
|
|
865
1213
|
const common = resolveCommonOptions(command, deps.env);
|
|
866
1214
|
await runCiDoctor({
|
|
867
1215
|
...common,
|
|
@@ -871,23 +1219,39 @@ export function createCiCommand(deps = {}) {
|
|
|
871
1219
|
waitTimeoutSeconds: cmdOpts.timeout === undefined ? undefined : parseTimeoutSeconds(cmdOpts.timeout),
|
|
872
1220
|
}, deps);
|
|
873
1221
|
});
|
|
874
|
-
ci.command('connect')
|
|
1222
|
+
ci.command('connect', { hidden: true })
|
|
875
1223
|
.description('Link your deploy platform (Vercel) to this repo so deployment events are emitted')
|
|
876
1224
|
.option('--project <name>', 'Vercel project to link when this directory is not linked yet (must already exist)')
|
|
877
|
-
.addHelpText('after',
|
|
878
|
-
'
|
|
879
|
-
'to link) it refuses
|
|
880
|
-
'
|
|
881
|
-
'
|
|
882
|
-
'
|
|
883
|
-
'
|
|
884
|
-
'\nLinking only affects FUTURE pushes: push a commit
|
|
885
|
-
'`testsprite ci doctor --wait`.')
|
|
1225
|
+
.addHelpText('after', `\nRuns \`npx ${VERCEL_CLI_SPEC}\` (downloads the Vercel CLI) non-interactively to link this directory\n` +
|
|
1226
|
+
'and connect the repo (`vercel link` / `vercel git connect`); if a decision is needed (which\n' +
|
|
1227
|
+
'project to link) it refuses rather than create anything you did not pick. Your Vercel\n' +
|
|
1228
|
+
'credentials stay with the Vercel CLI; this command never asks for or stores a platform token.\n' +
|
|
1229
|
+
'`vercel link` itself writes `.vercel/`, may add VERCEL_OIDC_TOKEN to `.env.local` and may\n' +
|
|
1230
|
+
'update `.gitignore`. --dry-run is not honored: the link is made.\n' +
|
|
1231
|
+
'\nExit codes: 0 connected, 1 could not connect\n' +
|
|
1232
|
+
'\nLinking only affects FUTURE pushes: push a commit, then confirm with `testsprite ci doctor --wait`.')
|
|
886
1233
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
887
1234
|
.action(async (cmdOpts, command) => {
|
|
1235
|
+
emitCiDeprecationNotice('connect', deps);
|
|
888
1236
|
const common = resolveCommonOptions(command, deps.env);
|
|
889
1237
|
await runCiConnect({ ...common, project: cmdOpts.project }, deps);
|
|
890
1238
|
});
|
|
891
1239
|
return ci;
|
|
892
1240
|
}
|
|
1241
|
+
/**
|
|
1242
|
+
* One stderr line per run of a deprecated `ci` subcommand, naming the
|
|
1243
|
+
* equivalent commands (stdout stays clean for JSON pipelines). The
|
|
1244
|
+
* replacements are not `testsprite` commands, so this does not reuse
|
|
1245
|
+
* `emitDeprecationNotice`.
|
|
1246
|
+
*/
|
|
1247
|
+
export const CI_DEPRECATION_NOTICES = {
|
|
1248
|
+
doctor: '[deprecated] `testsprite ci doctor` will be removed in a later release. Read the deployment history yourself: ' +
|
|
1249
|
+
'`gh api repos/<owner>/<repo>/deployments` — judge preview and production records separately; a real pull request is the proof.',
|
|
1250
|
+
connect: "[deprecated] `testsprite ci connect` will be removed in a later release. Run the platform's own CLI: " +
|
|
1251
|
+
'`npx vercel link --project <name> --non-interactive`, then `npx vercel git connect --non-interactive` (or link the repo in the Vercel dashboard).',
|
|
1252
|
+
};
|
|
1253
|
+
function emitCiDeprecationNotice(cmd, deps) {
|
|
1254
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
1255
|
+
stderr(CI_DEPRECATION_NOTICES[cmd]);
|
|
1256
|
+
}
|
|
893
1257
|
//# sourceMappingURL=ci.js.map
|