@testsprite/testsprite-cli 0.11.0 → 0.13.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 +52 -44
- package/dist/commands/agent.js +16 -13
- package/dist/commands/auth.d.ts +19 -0
- package/dist/commands/auth.js +60 -24
- package/dist/commands/ci.d.ts +86 -1
- package/dist/commands/ci.js +470 -9
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +22 -9
- package/dist/commands/init.js +14 -11
- package/dist/commands/project-env.d.ts +90 -0
- package/dist/commands/project-env.js +486 -0
- package/dist/commands/project.d.ts +15 -5
- package/dist/commands/project.js +88 -92
- package/dist/commands/schedule.d.ts +2 -0
- package/dist/commands/schedule.js +18 -10
- package/dist/commands/test.d.ts +102 -30
- package/dist/commands/test.js +1949 -419
- package/dist/commands/testlist.js +77 -21
- package/dist/commands/tunnel.d.ts +26 -3
- package/dist/commands/tunnel.js +211 -14
- package/dist/commands/usage.d.ts +3 -0
- package/dist/commands/usage.js +12 -5
- package/dist/index.js +47 -23
- package/dist/lib/agent-targets.d.ts +3 -3
- package/dist/lib/agent-targets.js +2 -2
- package/dist/lib/billing-refusal.d.ts +43 -0
- package/dist/lib/billing-refusal.js +171 -0
- package/dist/lib/bundle.d.ts +5 -0
- package/dist/lib/bundle.js +43 -13
- package/dist/lib/ci-linkage.d.ts +90 -0
- package/dist/lib/ci-linkage.js +181 -0
- package/dist/lib/client-factory.d.ts +4 -1
- package/dist/lib/client-factory.js +25 -2
- package/dist/lib/client-tag.d.ts +13 -0
- package/dist/lib/client-tag.js +44 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +67 -2
- package/dist/lib/conflict-reason.js +148 -13
- package/dist/lib/credentials.js +56 -14
- package/dist/lib/cron.js +8 -1
- package/dist/lib/dry-run/samples.d.ts +13 -1
- package/dist/lib/dry-run/samples.js +51 -7
- package/dist/lib/errors.d.ts +62 -12
- package/dist/lib/errors.js +180 -25
- package/dist/lib/failing-fe-resolver.d.ts +1 -1
- package/dist/lib/failing-fe-resolver.js +3 -3
- package/dist/lib/gh-output.d.ts +26 -11
- package/dist/lib/gh-output.js +47 -15
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +44 -19
- package/dist/lib/http.js +53 -26
- package/dist/lib/interrupt.d.ts +21 -13
- package/dist/lib/interrupt.js +32 -21
- package/dist/lib/junit-report.d.ts +11 -1
- package/dist/lib/junit-report.js +15 -3
- package/dist/lib/local-target.d.ts +33 -1
- package/dist/lib/local-target.js +78 -1
- package/dist/lib/output.d.ts +27 -1
- package/dist/lib/output.js +22 -3
- package/dist/lib/plan-poll.d.ts +11 -11
- package/dist/lib/plan-poll.js +12 -12
- package/dist/lib/plans.types.d.ts +9 -9
- package/dist/lib/plans.types.js +3 -3
- package/dist/lib/poll.d.ts +2 -2
- package/dist/lib/poll.js +9 -3
- package/dist/lib/render-error.d.ts +2 -0
- package/dist/lib/render-error.js +13 -0
- package/dist/lib/response-schemas.d.ts +54 -12
- package/dist/lib/response-schemas.js +106 -7
- package/dist/lib/runs.types.d.ts +92 -6
- package/dist/lib/secret-file.js +72 -14
- package/dist/lib/skill-nudge.d.ts +6 -1
- package/dist/lib/skill-nudge.js +32 -5
- package/dist/lib/target-url-preflight.d.ts +6 -4
- package/dist/lib/target-url-preflight.js +64 -51
- package/dist/lib/target-url.js +31 -12
- package/dist/lib/telemetry.d.ts +172 -3
- package/dist/lib/telemetry.js +276 -15
- package/dist/lib/ticker.js +93 -4
- package/dist/lib/tunnel-session.d.ts +13 -0
- package/dist/lib/tunnel-session.js +4 -1
- package/dist/lib/tunnel.types.d.ts +12 -2
- package/dist/lib/tunnel.types.js +2 -2
- package/dist/lib/version-notice.d.ts +20 -1
- package/dist/lib/version-notice.js +59 -12
- package/dist/lib/wait-exit.d.ts +8 -0
- package/dist/lib/wait-exit.js +76 -4
- package/dist/lib/workspace-status.d.ts +23 -0
- package/dist/lib/workspace-status.js +15 -0
- package/dist/version-guard.d.ts +7 -1
- package/dist/version-guard.js +19 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/skills/testsprite-onboard.skill.md +4 -4
- package/skills/testsprite-verify.codex.md +59 -57
- package/skills/testsprite-verify.skill.md +53 -36
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment-linkage diagnosis for `ci doctor`.
|
|
3
|
+
*
|
|
4
|
+
* A deployment-gated workflow (`on: deployment_status`) only ever fires if the
|
|
5
|
+
* repo actually RECEIVES GitHub Deployment events. Those records are written by
|
|
6
|
+
* whatever deploys the app — Vercel's own GitHub App writes a `deployment` plus
|
|
7
|
+
* a `deployment_status`, GitHub broadcasts the event, and every subscriber
|
|
8
|
+
* (our workflow, the TestSprite GitHub App) sees the same one.
|
|
9
|
+
*
|
|
10
|
+
* When the deploy platform is not git-linked to the repo, nothing is ever
|
|
11
|
+
* written, so nothing ever fires — with no error anywhere. Measured on a real
|
|
12
|
+
* repo: the app deploys fine on Vercel while the repo's Deployments list is
|
|
13
|
+
* empty, which would leave a scaffolded gate permanently silent. This module
|
|
14
|
+
* turns that invisible state into a verdict.
|
|
15
|
+
*
|
|
16
|
+
* Pure functions only: the `gh`/`git` subprocess calls live in `commands/ci.ts`
|
|
17
|
+
* so this stays trivially testable.
|
|
18
|
+
*/
|
|
19
|
+
/** One GitHub Deployment record, reduced to what the verdict needs. */
|
|
20
|
+
export interface DeploymentRecord {
|
|
21
|
+
/** GitHub's environment label — "Preview", "Production", "preview", … */
|
|
22
|
+
environment: string;
|
|
23
|
+
/** ISO timestamp the record was created. */
|
|
24
|
+
createdAt: string;
|
|
25
|
+
/** Login that wrote the record (`vercel[bot]`, a user, a CI app). */
|
|
26
|
+
creator: string | null;
|
|
27
|
+
}
|
|
28
|
+
export type LinkageStatus =
|
|
29
|
+
/** Recent records exist — events reach this repo, a gate will fire. */
|
|
30
|
+
'linked'
|
|
31
|
+
/** Records exist but all are old — the link may have been removed since. */
|
|
32
|
+
| 'stale'
|
|
33
|
+
/** Records exist but none for a preview environment — a PR gate never fires. */
|
|
34
|
+
| 'production-only'
|
|
35
|
+
/** No records at all — either not linked, or linked and never deployed. */
|
|
36
|
+
| 'none';
|
|
37
|
+
export interface LinkageVerdict {
|
|
38
|
+
status: LinkageStatus;
|
|
39
|
+
/**
|
|
40
|
+
* Whether a deployment-gated workflow is safe to scaffold. Only `linked`
|
|
41
|
+
* qualifies: every other status means the gate would be silent or partial,
|
|
42
|
+
* which is the failure this check exists to prevent.
|
|
43
|
+
*/
|
|
44
|
+
ok: boolean;
|
|
45
|
+
/** One-line human explanation, ready to print. */
|
|
46
|
+
detail: string;
|
|
47
|
+
/**
|
|
48
|
+
* Timestamp of the record the verdict is ABOUT — the newest preview record
|
|
49
|
+
* for `linked`/`stale`, the newest record overall for `production-only` —
|
|
50
|
+
* or null when there are none.
|
|
51
|
+
*/
|
|
52
|
+
lastDeployAt: string | null;
|
|
53
|
+
/** Distinct creators seen, newest first — names who is writing the events. */
|
|
54
|
+
creators: string[];
|
|
55
|
+
/** Whether any record targets a preview environment. */
|
|
56
|
+
hasPreview: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** "3 days ago" / "5 months ago", for the human line. */
|
|
59
|
+
export declare function describeAge(iso: string, now: Date): string;
|
|
60
|
+
/**
|
|
61
|
+
* Turn a repo's deployment history into a verdict.
|
|
62
|
+
*
|
|
63
|
+
* Deliberately NOT Vercel-specific on the success path: the event is the same
|
|
64
|
+
* whoever writes it, so a repo fed by Netlify, a self-hosted pipeline, or a
|
|
65
|
+
* hand-rolled `gh api` call reads as linked just the same. The creator is
|
|
66
|
+
* reported, not required.
|
|
67
|
+
*
|
|
68
|
+
* `records` may be in any order; the newest is picked here.
|
|
69
|
+
*/
|
|
70
|
+
export declare function classifyLinkage(records: readonly DeploymentRecord[], now: Date): LinkageVerdict;
|
|
71
|
+
/**
|
|
72
|
+
* Whether a string is safe to use as an `owner/repo` slug in a `gh api` path.
|
|
73
|
+
* The character class matches what GitHub itself allows in owner/repo names,
|
|
74
|
+
* but admits `.`/`..` — which as path SEGMENTS would make `repos/../../…`
|
|
75
|
+
* resolve to a different endpoint — so those are refused explicitly.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isValidRepoSlug(slug: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* `owner/repo` from a git remote URL. Handles the three shapes a cloned repo
|
|
80
|
+
* actually carries — SSH (`git@github.com:o/r.git`), HTTPS, and the `ssh://`
|
|
81
|
+
* form — and returns null for anything not on github.com, since a GitLab or
|
|
82
|
+
* Bitbucket remote has no GitHub Deployments to read.
|
|
83
|
+
*/
|
|
84
|
+
export declare function parseRepoSlug(remoteUrl: string): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* Reduce `gh api .../deployments` output to `DeploymentRecord`s. Tolerates the
|
|
87
|
+
* field being absent or oddly typed: a diagnosis must not crash on a payload
|
|
88
|
+
* shape change, it should just report what it could read.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseDeploymentsPayload(raw: string): DeploymentRecord[];
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment-linkage diagnosis for `ci doctor`.
|
|
3
|
+
*
|
|
4
|
+
* A deployment-gated workflow (`on: deployment_status`) only ever fires if the
|
|
5
|
+
* repo actually RECEIVES GitHub Deployment events. Those records are written by
|
|
6
|
+
* whatever deploys the app — Vercel's own GitHub App writes a `deployment` plus
|
|
7
|
+
* a `deployment_status`, GitHub broadcasts the event, and every subscriber
|
|
8
|
+
* (our workflow, the TestSprite GitHub App) sees the same one.
|
|
9
|
+
*
|
|
10
|
+
* When the deploy platform is not git-linked to the repo, nothing is ever
|
|
11
|
+
* written, so nothing ever fires — with no error anywhere. Measured on a real
|
|
12
|
+
* repo: the app deploys fine on Vercel while the repo's Deployments list is
|
|
13
|
+
* empty, which would leave a scaffolded gate permanently silent. This module
|
|
14
|
+
* turns that invisible state into a verdict.
|
|
15
|
+
*
|
|
16
|
+
* Pure functions only: the `gh`/`git` subprocess calls live in `commands/ci.ts`
|
|
17
|
+
* so this stays trivially testable.
|
|
18
|
+
*/
|
|
19
|
+
/** How old the newest deployment may be before the link looks abandoned. */
|
|
20
|
+
const STALE_AFTER_DAYS = 90;
|
|
21
|
+
/** GitHub labels Vercel previews "Preview"; other platforms vary in case. */
|
|
22
|
+
function isPreviewEnvironment(environment) {
|
|
23
|
+
const env = environment.toLowerCase();
|
|
24
|
+
return env.includes('preview') || env.includes('staging');
|
|
25
|
+
}
|
|
26
|
+
function daysBetween(fromIso, now) {
|
|
27
|
+
const then = new Date(fromIso).getTime();
|
|
28
|
+
if (Number.isNaN(then))
|
|
29
|
+
return Number.POSITIVE_INFINITY;
|
|
30
|
+
return (now.getTime() - then) / 86_400_000;
|
|
31
|
+
}
|
|
32
|
+
/** "3 days ago" / "5 months ago", for the human line. */
|
|
33
|
+
export function describeAge(iso, now) {
|
|
34
|
+
const days = daysBetween(iso, now);
|
|
35
|
+
if (!Number.isFinite(days))
|
|
36
|
+
return 'at an unknown time';
|
|
37
|
+
if (days < 1)
|
|
38
|
+
return 'today';
|
|
39
|
+
if (days < 2)
|
|
40
|
+
return 'yesterday';
|
|
41
|
+
if (days < 45)
|
|
42
|
+
return `${Math.round(days)} days ago`;
|
|
43
|
+
return `${Math.round(days / 30)} months ago`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Turn a repo's deployment history into a verdict.
|
|
47
|
+
*
|
|
48
|
+
* Deliberately NOT Vercel-specific on the success path: the event is the same
|
|
49
|
+
* whoever writes it, so a repo fed by Netlify, a self-hosted pipeline, or a
|
|
50
|
+
* hand-rolled `gh api` call reads as linked just the same. The creator is
|
|
51
|
+
* reported, not required.
|
|
52
|
+
*
|
|
53
|
+
* `records` may be in any order; the newest is picked here.
|
|
54
|
+
*/
|
|
55
|
+
export function classifyLinkage(records, now) {
|
|
56
|
+
if (records.length === 0) {
|
|
57
|
+
return {
|
|
58
|
+
status: 'none',
|
|
59
|
+
ok: false,
|
|
60
|
+
// The two causes are indistinguishable from GitHub's side — we cannot
|
|
61
|
+
// query another App's installations — so the verdict names both rather
|
|
62
|
+
// than guessing. `ci connect` resolves either one the same way.
|
|
63
|
+
detail: 'No deployment events on this repo. Either the deploy platform is not linked to it, ' +
|
|
64
|
+
'or it is linked and has not deployed yet — a deployment-gated workflow would never fire.',
|
|
65
|
+
lastDeployAt: null,
|
|
66
|
+
creators: [],
|
|
67
|
+
hasPreview: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const sorted = [...records].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
71
|
+
const creators = [...new Set(sorted.map(r => r.creator).filter((c) => !!c))];
|
|
72
|
+
// Classify per environment, never off the newest record overall. A repo that
|
|
73
|
+
// deploys production daily but whose last preview is months old would
|
|
74
|
+
// otherwise read as freshly `linked` — and a gate scaffolded on that verdict
|
|
75
|
+
// never fires, which is the exact silent failure this classifier exists to
|
|
76
|
+
// catch. (Boundary this accepts: a repo whose whole fetched page is
|
|
77
|
+
// production deploys newer than its last preview reads `production-only`
|
|
78
|
+
// rather than `stale` — both mean "no PR gate", not worth paging for.)
|
|
79
|
+
const previews = sorted.filter(r => isPreviewEnvironment(r.environment));
|
|
80
|
+
if (previews.length === 0) {
|
|
81
|
+
const newest = sorted[0];
|
|
82
|
+
const age = describeAge(newest.createdAt, now);
|
|
83
|
+
const by = newest.creator ? ` by ${newest.creator}` : '';
|
|
84
|
+
return {
|
|
85
|
+
status: 'production-only',
|
|
86
|
+
ok: false,
|
|
87
|
+
// A PR gate keys on preview deployments; production-only records mean the
|
|
88
|
+
// workflow would fire on releases and never on a pull request.
|
|
89
|
+
detail: `Only production deployment events on this repo (newest ${age}${by}), none for a preview environment. ` +
|
|
90
|
+
'A PR gate keys on preview deployments — enable preview deployments on your deploy platform.',
|
|
91
|
+
lastDeployAt: newest.createdAt,
|
|
92
|
+
creators,
|
|
93
|
+
hasPreview: false,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const newestPreview = previews[0];
|
|
97
|
+
const age = describeAge(newestPreview.createdAt, now);
|
|
98
|
+
const by = newestPreview.creator ? ` by ${newestPreview.creator}` : '';
|
|
99
|
+
if (daysBetween(newestPreview.createdAt, now) > STALE_AFTER_DAYS) {
|
|
100
|
+
return {
|
|
101
|
+
status: 'stale',
|
|
102
|
+
ok: false,
|
|
103
|
+
detail: `Preview deployment events exist, but the newest is from ${age}${by}. ` +
|
|
104
|
+
'The link may have been removed since — push a commit and re-check before relying on a gate.',
|
|
105
|
+
lastDeployAt: newestPreview.createdAt,
|
|
106
|
+
creators,
|
|
107
|
+
hasPreview: true,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
status: 'linked',
|
|
112
|
+
ok: true,
|
|
113
|
+
detail: `Preview deployment events reach this repo (newest preview ${age}${by}).`,
|
|
114
|
+
lastDeployAt: newestPreview.createdAt,
|
|
115
|
+
creators,
|
|
116
|
+
hasPreview: true,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Whether a string is safe to use as an `owner/repo` slug in a `gh api` path.
|
|
121
|
+
* The character class matches what GitHub itself allows in owner/repo names,
|
|
122
|
+
* but admits `.`/`..` — which as path SEGMENTS would make `repos/../../…`
|
|
123
|
+
* resolve to a different endpoint — so those are refused explicitly.
|
|
124
|
+
*/
|
|
125
|
+
export function isValidRepoSlug(slug) {
|
|
126
|
+
if (!/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(slug))
|
|
127
|
+
return false;
|
|
128
|
+
return slug.split('/').every(segment => segment !== '.' && segment !== '..');
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* `owner/repo` from a git remote URL. Handles the three shapes a cloned repo
|
|
132
|
+
* actually carries — SSH (`git@github.com:o/r.git`), HTTPS, and the `ssh://`
|
|
133
|
+
* form — and returns null for anything not on github.com, since a GitLab or
|
|
134
|
+
* Bitbucket remote has no GitHub Deployments to read.
|
|
135
|
+
*/
|
|
136
|
+
export function parseRepoSlug(remoteUrl) {
|
|
137
|
+
const url = remoteUrl.trim();
|
|
138
|
+
if (!url)
|
|
139
|
+
return null;
|
|
140
|
+
const match = /^git@github\.com:(?<slug>[^/]+\/[^/]+?)(?:\.git)?$/.exec(url) ??
|
|
141
|
+
/^ssh:\/\/git@github\.com\/(?<slug>[^/]+\/[^/]+?)(?:\.git)?$/.exec(url) ??
|
|
142
|
+
/^https?:\/\/(?:[^@]+@)?github\.com\/(?<slug>[^/]+\/[^/]+?)(?:\.git)?\/?$/.exec(url);
|
|
143
|
+
const slug = match?.groups?.slug;
|
|
144
|
+
if (!slug)
|
|
145
|
+
return null;
|
|
146
|
+
return isValidRepoSlug(slug) ? slug : null;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Reduce `gh api .../deployments` output to `DeploymentRecord`s. Tolerates the
|
|
150
|
+
* field being absent or oddly typed: a diagnosis must not crash on a payload
|
|
151
|
+
* shape change, it should just report what it could read.
|
|
152
|
+
*/
|
|
153
|
+
export function parseDeploymentsPayload(raw) {
|
|
154
|
+
let parsed;
|
|
155
|
+
try {
|
|
156
|
+
parsed = JSON.parse(raw);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
if (!Array.isArray(parsed))
|
|
162
|
+
return [];
|
|
163
|
+
return (parsed
|
|
164
|
+
.filter((row) => row !== null && typeof row === 'object')
|
|
165
|
+
.map(row => {
|
|
166
|
+
const creator = row.creator;
|
|
167
|
+
const login = creator !== null && typeof creator === 'object'
|
|
168
|
+
? creator.login
|
|
169
|
+
: undefined;
|
|
170
|
+
return {
|
|
171
|
+
environment: typeof row.environment === 'string' ? row.environment : '',
|
|
172
|
+
createdAt: typeof row.created_at === 'string' ? row.created_at : '',
|
|
173
|
+
creator: typeof login === 'string' ? login : null,
|
|
174
|
+
};
|
|
175
|
+
})
|
|
176
|
+
// A row without a PARSEABLE timestamp can't be aged or ordered — one NaN
|
|
177
|
+
// in the sort comparator would make the whole ordering implementation-
|
|
178
|
+
// defined — so it is dropped rather than silently treated as epoch.
|
|
179
|
+
.filter(r => Number.isFinite(new Date(r.createdAt).getTime())));
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=ci-linkage.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FetchImpl, HttpClientOptions } from './http.js';
|
|
2
2
|
import { HttpClient } from './http.js';
|
|
3
|
+
import { type ShutdownHandle } from './interrupt.js';
|
|
3
4
|
import type { OutputMode } from './output.js';
|
|
4
5
|
export interface CommonOptions {
|
|
5
6
|
profile: string;
|
|
@@ -42,11 +43,13 @@ export interface ClientFactoryDeps {
|
|
|
42
43
|
fetchImpl?: FetchImpl;
|
|
43
44
|
stderr?: (line: string) => void;
|
|
44
45
|
/**
|
|
45
|
-
* Shutdown signal composed into every outgoing fetch
|
|
46
|
+
* Shutdown signal composed into every outgoing fetch.
|
|
46
47
|
* Defaults to `globalShutdown.signal` so an armed SIGINT/SIGTERM aborts an
|
|
47
48
|
* in-flight request; tests inject their own controller's signal.
|
|
48
49
|
*/
|
|
49
50
|
shutdownSignal?: AbortSignal;
|
|
51
|
+
/** Defaults to `globalShutdown` so disarmed signals can see in-flight requests. */
|
|
52
|
+
shutdown?: Pick<ShutdownHandle, 'runCriticalOperation'>;
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
55
|
* Accepted TestSprite API-key prefixes, in the order they are reported to the
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* with the command.
|
|
15
15
|
*/
|
|
16
16
|
import { loadConfig } from './config.js';
|
|
17
|
-
import { defaultCredentialsPath } from './credentials.js';
|
|
17
|
+
import { DEFAULT_PROFILE, defaultCredentialsPath } from './credentials.js';
|
|
18
18
|
import { ApiError, localValidationError } from './errors.js';
|
|
19
19
|
import { facadeBaseUrl } from './facade.js';
|
|
20
20
|
import { HttpClient, REQUEST_TIMEOUT_DEFAULT_MS, REQUEST_TIMEOUT_MAX_MS, REQUEST_TIMEOUT_MIN_MS, } from './http.js';
|
|
@@ -190,6 +190,25 @@ export function parseRequestTimeoutFlag(raw) {
|
|
|
190
190
|
}
|
|
191
191
|
return Math.round(n * 1000); // seconds → milliseconds
|
|
192
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* The profile name to echo in a missing-key error, or `undefined` to keep the
|
|
195
|
+
* generic wording.
|
|
196
|
+
*
|
|
197
|
+
* Two cases are deliberately not named. The default profile is the plain
|
|
198
|
+
* "not set up yet" case, where naming it adds nothing. And a name shaped like
|
|
199
|
+
* a TestSprite API key is withheld: the credentials-file guard only checks
|
|
200
|
+
* that a name is a safe INI section (`/^[A-Za-z0-9._-]+$/`), which every key
|
|
201
|
+
* format also satisfies, so `TESTSPRITE_PROFILE=$SOME_KEY_VAR` would otherwise
|
|
202
|
+
* print the key to stderr and into `details` under `--output json` — straight
|
|
203
|
+
* into a CI log.
|
|
204
|
+
*/
|
|
205
|
+
function nameableProfile(profile) {
|
|
206
|
+
if (profile === DEFAULT_PROFILE)
|
|
207
|
+
return undefined;
|
|
208
|
+
if (API_KEY_PREFIXES.some(prefix => profile.startsWith(prefix)))
|
|
209
|
+
return undefined;
|
|
210
|
+
return profile;
|
|
211
|
+
}
|
|
193
212
|
export function makeHttpClient(opts, deps = {}) {
|
|
194
213
|
return new HttpClient(resolveHttpClientOptions(opts, deps));
|
|
195
214
|
}
|
|
@@ -215,8 +234,10 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
215
234
|
fetchImpl: deps.fetchImpl ?? createDryRunFetch(),
|
|
216
235
|
onDebug: opts.debug ? (event) => stderr(formatDryRunDebug(event)) : undefined,
|
|
217
236
|
onTransition: opts.verbose ? (msg) => stderr(`[verbose] ${msg}`) : undefined,
|
|
237
|
+
env,
|
|
218
238
|
requestTimeoutMs,
|
|
219
239
|
shutdownSignal: deps.shutdownSignal ?? globalShutdown.signal,
|
|
240
|
+
shutdown: deps.shutdown ?? globalShutdown,
|
|
220
241
|
};
|
|
221
242
|
}
|
|
222
243
|
const credentialsPath = deps.credentialsPath ?? defaultCredentialsPath();
|
|
@@ -231,7 +252,7 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
231
252
|
// VALIDATION_ERROR rather than an opaque URL throw or a retried "fetch failed".
|
|
232
253
|
assertValidEndpointUrl(config.apiUrl);
|
|
233
254
|
if (!config.apiKey)
|
|
234
|
-
throw ApiError.authRequired();
|
|
255
|
+
throw ApiError.authRequired(undefined, nameableProfile(config.profile));
|
|
235
256
|
assertValidApiKey(config.apiKey);
|
|
236
257
|
return {
|
|
237
258
|
baseUrl: facadeBaseUrl(config.apiUrl),
|
|
@@ -250,8 +271,10 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
250
271
|
dryRun: opts.dryRun,
|
|
251
272
|
stderr,
|
|
252
273
|
}),
|
|
274
|
+
env,
|
|
253
275
|
requestTimeoutMs,
|
|
254
276
|
shutdownSignal: deps.shutdownSignal ?? globalShutdown.signal,
|
|
277
|
+
shutdown: deps.shutdown ?? globalShutdown,
|
|
255
278
|
};
|
|
256
279
|
}
|
|
257
280
|
function formatDebug(event) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Env var a wrapper (e.g. the GitHub Action) sets to identify itself. */
|
|
2
|
+
export declare const CLIENT_TAG_ENV = "TESTSPRITE_CLIENT";
|
|
3
|
+
/**
|
|
4
|
+
* The validated client tag from `env`, or undefined when unset or invalid.
|
|
5
|
+
* Pure — reads only the one variable it owns.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveClientTag(env: NodeJS.ProcessEnv): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The User-Agent every outgoing request (API + telemetry beacon) sends.
|
|
10
|
+
* `testsprite-cli/<version>`, with ` (<client>)` appended only for a valid
|
|
11
|
+
* {@link CLIENT_TAG_ENV} value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildUserAgent(env?: NodeJS.ProcessEnv): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional "client" identity a wrapper can stamp onto every request the CLI
|
|
3
|
+
* makes on its behalf — the GitHub Action sets `TESTSPRITE_CLIENT=github-action/<ref>`
|
|
4
|
+
* so the backend can tell an Action-driven run from a developer's shell without
|
|
5
|
+
* a second credential or a new header.
|
|
6
|
+
*
|
|
7
|
+
* Wire shape: the User-Agent becomes `testsprite-cli/<version> (<client>)`.
|
|
8
|
+
* Without the env var (or with an invalid value) the UA is byte-identical to
|
|
9
|
+
* what it has always been, `testsprite-cli/<version>`.
|
|
10
|
+
*
|
|
11
|
+
* The value is validated against a tight grammar — `<name>/<version>` where the
|
|
12
|
+
* name is lowercase alphanumeric plus `-` (≤32 chars) and the version is a
|
|
13
|
+
* short token of `[0-9A-Za-z._+-]` (≤40 chars) — so a caller can never smuggle
|
|
14
|
+
* header-breaking characters (spaces, parentheses, CR/LF) or free text into a
|
|
15
|
+
* request header. An invalid value is dropped silently and NEVER echoed: the
|
|
16
|
+
* tag rides on telemetry too, and a rejected value must not leak back into a
|
|
17
|
+
* log line either.
|
|
18
|
+
*/
|
|
19
|
+
import { VERSION } from '../version.js';
|
|
20
|
+
/** Env var a wrapper (e.g. the GitHub Action) sets to identify itself. */
|
|
21
|
+
export const CLIENT_TAG_ENV = 'TESTSPRITE_CLIENT';
|
|
22
|
+
/** `<name>/<version>`: e.g. `github-action/v1`, `github-action/1.2.0`. */
|
|
23
|
+
const CLIENT_TAG_RE = /^[a-z0-9][a-z0-9-]{0,31}\/[0-9A-Za-z][0-9A-Za-z._+-]{0,39}$/;
|
|
24
|
+
/**
|
|
25
|
+
* The validated client tag from `env`, or undefined when unset or invalid.
|
|
26
|
+
* Pure — reads only the one variable it owns.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveClientTag(env) {
|
|
29
|
+
const raw = env[CLIENT_TAG_ENV];
|
|
30
|
+
if (typeof raw !== 'string')
|
|
31
|
+
return undefined;
|
|
32
|
+
return CLIENT_TAG_RE.test(raw) ? raw : undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The User-Agent every outgoing request (API + telemetry beacon) sends.
|
|
36
|
+
* `testsprite-cli/<version>`, with ` (<client>)` appended only for a valid
|
|
37
|
+
* {@link CLIENT_TAG_ENV} value.
|
|
38
|
+
*/
|
|
39
|
+
export function buildUserAgent(env = process.env) {
|
|
40
|
+
const base = `testsprite-cli/${VERSION}`;
|
|
41
|
+
const client = resolveClientTag(env);
|
|
42
|
+
return client === undefined ? base : `${base} (${client})`;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=client-tag.js.map
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -12,6 +12,23 @@ export interface LoadConfigOptions {
|
|
|
12
12
|
/** Treat empty / whitespace-only env values as unset for `??` resolution chains. */
|
|
13
13
|
export declare function normalizeEnvVar(value: string | undefined): string | undefined;
|
|
14
14
|
export declare function defaultConfigPath(): string;
|
|
15
|
+
/**
|
|
16
|
+
* The single place the documented profile-resolution order lives:
|
|
17
|
+
*
|
|
18
|
+
* `--profile` flag > `TESTSPRITE_PROFILE` env var > `"default"`
|
|
19
|
+
*
|
|
20
|
+
* Every command needs the resolved name before it can build a client (and
|
|
21
|
+
* `auth` / `setup` need it to read and write the right credentials section), so
|
|
22
|
+
* each one used to inline `flag ?? 'default'`. That collapsed to the literal
|
|
23
|
+
* `'default'` whenever the flag was absent and made the env var unreachable
|
|
24
|
+
* from every entry point — `loadConfig` never got the `undefined` its own `??`
|
|
25
|
+
* chain needs. Resolving here keeps the order in one place and keeps the
|
|
26
|
+
* blank-value normalization ({@link normalizeEnvVar}) that a hand-written
|
|
27
|
+
* `flag ?? env.TESTSPRITE_PROFILE ?? 'default'` would drop: an empty or
|
|
28
|
+
* whitespace-only value must fall back to the default profile, not fail the
|
|
29
|
+
* INI section-name guard on every command.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveProfileName(flagValue: string | undefined, env?: NodeJS.ProcessEnv): string;
|
|
15
32
|
/**
|
|
16
33
|
* Resolves the active profile name and its (apiUrl, apiKey) pair.
|
|
17
34
|
*
|
package/dist/lib/config.js
CHANGED
|
@@ -9,6 +9,25 @@ export function normalizeEnvVar(value) {
|
|
|
9
9
|
export function defaultConfigPath() {
|
|
10
10
|
return join(homedir(), '.testsprite', 'config');
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* The single place the documented profile-resolution order lives:
|
|
14
|
+
*
|
|
15
|
+
* `--profile` flag > `TESTSPRITE_PROFILE` env var > `"default"`
|
|
16
|
+
*
|
|
17
|
+
* Every command needs the resolved name before it can build a client (and
|
|
18
|
+
* `auth` / `setup` need it to read and write the right credentials section), so
|
|
19
|
+
* each one used to inline `flag ?? 'default'`. That collapsed to the literal
|
|
20
|
+
* `'default'` whenever the flag was absent and made the env var unreachable
|
|
21
|
+
* from every entry point — `loadConfig` never got the `undefined` its own `??`
|
|
22
|
+
* chain needs. Resolving here keeps the order in one place and keeps the
|
|
23
|
+
* blank-value normalization ({@link normalizeEnvVar}) that a hand-written
|
|
24
|
+
* `flag ?? env.TESTSPRITE_PROFILE ?? 'default'` would drop: an empty or
|
|
25
|
+
* whitespace-only value must fall back to the default profile, not fail the
|
|
26
|
+
* INI section-name guard on every command.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveProfileName(flagValue, env = process.env) {
|
|
29
|
+
return flagValue ?? normalizeEnvVar(env.TESTSPRITE_PROFILE) ?? DEFAULT_PROFILE;
|
|
30
|
+
}
|
|
12
31
|
/**
|
|
13
32
|
* Resolves the active profile name and its (apiUrl, apiKey) pair.
|
|
14
33
|
*
|
|
@@ -22,7 +41,7 @@ export function defaultConfigPath() {
|
|
|
22
41
|
*/
|
|
23
42
|
export function loadConfig(options = {}) {
|
|
24
43
|
const env = options.env ?? process.env;
|
|
25
|
-
const profile = options.profile
|
|
44
|
+
const profile = resolveProfileName(options.profile, env);
|
|
26
45
|
const credentialsPath = options.credentialsPath ?? defaultCredentialsPath();
|
|
27
46
|
const fileEntry = readProfile(profile, { path: credentialsPath });
|
|
28
47
|
// Empty / whitespace-only env vars are treated as unset so they do not
|
|
@@ -6,10 +6,21 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Absent ⇒ a legacy / pre-discriminator backend: treated as `in_flight` (the
|
|
8
8
|
* historical rendering) for backward compatibility.
|
|
9
|
+
*
|
|
10
|
+
* `insufficient_credits` / `paused` (or `billing_hold`, the deprecated spelling
|
|
11
|
+
* older backends send) are billing refusals the backend folds
|
|
12
|
+
* into `conflicts[]` for a MIXED batch (some cases dispatched, some refused). A
|
|
13
|
+
* batch where nothing dispatched and every refusal was credits comes back as a
|
|
14
|
+
* plain 402 `INSUFFICIENT_CREDITS` envelope instead — the same shape the
|
|
15
|
+
* single-run route answers — so both surfaces exit 12.
|
|
9
16
|
*/
|
|
10
|
-
|
|
17
|
+
import { ApiError } from './errors.js';
|
|
18
|
+
export type ConflictReason = 'in_flight' | 'mcp_view_only' | 'local_address' | 'not_found' | 'insufficient_credits' | 'paused'
|
|
19
|
+
/** Deprecated spelling of `paused`, still sent by older backends. */
|
|
20
|
+
| 'billing_hold' | 'error';
|
|
11
21
|
/** A conflict entry on a run response. `message` carries actionable detail for
|
|
12
|
-
* `local_address` / `
|
|
22
|
+
* `local_address` / `insufficient_credits` / `paused` / `error` (the
|
|
23
|
+
* backend's nextAction). */
|
|
13
24
|
export interface RunConflict {
|
|
14
25
|
testId: string;
|
|
15
26
|
currentRunId?: string;
|
|
@@ -22,9 +33,63 @@ export interface RunConflict {
|
|
|
22
33
|
* bare `{testId, currentRunId?}` conflicts read exactly as they did before.
|
|
23
34
|
*/
|
|
24
35
|
export declare function describeConflict(c: RunConflict): string;
|
|
36
|
+
/**
|
|
37
|
+
* True when the set is non-empty and every entry is the legacy in-flight
|
|
38
|
+
* cause (absent reason ⇒ `in_flight` too). Callers use this to restore the
|
|
39
|
+
* original, pre-reason-aware "N test(s) already in flight" wording for the
|
|
40
|
+
* common pure case, while any OTHER reason present (paused,
|
|
41
|
+
* mcp_view_only, …) still falls through to `summarizeConflicts`'s
|
|
42
|
+
* reason-aware summary instead of a misleading blanket "in flight".
|
|
43
|
+
*/
|
|
44
|
+
export declare function allConflictsInFlight(conflicts: readonly RunConflict[]): boolean;
|
|
25
45
|
/**
|
|
26
46
|
* One-line summary of a conflict set grouped by reason, e.g.
|
|
27
47
|
* `2 already in flight, 1 environment not runnable`. Used where a single line
|
|
28
48
|
* must stand in for the whole `conflicts[]` (exit-message / advisory).
|
|
29
49
|
*/
|
|
30
50
|
export declare function summarizeConflicts(conflicts: readonly RunConflict[]): string;
|
|
51
|
+
/**
|
|
52
|
+
* The most frequent conflict reason in a batch (ties → the one seen first), as
|
|
53
|
+
* the raw wire string so a reason this CLI version does not know yet still
|
|
54
|
+
* surfaces. Undefined for an empty set. Feeds the telemetry `conflictReason`
|
|
55
|
+
* field, which allowlists the value before it is sent.
|
|
56
|
+
*/
|
|
57
|
+
export declare function dominantConflictReason(conflicts: readonly RunConflict[]): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* True when the set is non-empty and EVERY entry carries `reason`. Absent
|
|
60
|
+
* reasons never match (they are `in_flight` by the legacy rule above), so an old
|
|
61
|
+
* backend can never be read as "all insufficient credits".
|
|
62
|
+
*/
|
|
63
|
+
export declare function everyConflictIs(conflicts: readonly RunConflict[], reason: ConflictReason): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* True for the one batch shape that is really a credits refusal: nothing was
|
|
66
|
+
* dispatched, nothing is rate-deferred (that is exit 7 first), and every
|
|
67
|
+
* conflict says `insufficient_credits`. A newer backend answers this case with
|
|
68
|
+
* a plain 402 envelope itself; this covers a backend that still folds it into
|
|
69
|
+
* `conflicts[]`, so both wire shapes land on the same exit 12.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isAllCreditsRefusal(resp: {
|
|
72
|
+
accepted: readonly unknown[];
|
|
73
|
+
deferred: readonly unknown[];
|
|
74
|
+
conflicts: readonly RunConflict[];
|
|
75
|
+
}): boolean;
|
|
76
|
+
export declare function isPausedRefusal(resp: {
|
|
77
|
+
accepted: readonly unknown[];
|
|
78
|
+
deferred: readonly unknown[];
|
|
79
|
+
conflicts: readonly RunConflict[];
|
|
80
|
+
}): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The exit-13 refusal for a batch refused because the workspace is paused —
|
|
83
|
+
* the same `FEATURE_GATED` envelope the backend answers a single run with. The server's message on the conflicts says why
|
|
84
|
+
* the workspace is paused; the fallback deliberately doesn't guess.
|
|
85
|
+
*/
|
|
86
|
+
export declare function pausedConflictError(conflicts: readonly RunConflict[], apiUrl?: string): ApiError;
|
|
87
|
+
export declare function billingConflictLink(conflicts: readonly RunConflict[], apiUrl?: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* The exit-12 refusal for an all-credits batch — the SAME `INSUFFICIENT_CREDITS`
|
|
90
|
+
* envelope the single-run route answers (code, exit code, billing `nextAction`),
|
|
91
|
+
* so `index.ts` renders it identically and automation sees one shape. The
|
|
92
|
+
* server's own message (carried on the conflicts) is preferred over the local
|
|
93
|
+
* wording; `apiUrl` resolves the environment-correct portal link.
|
|
94
|
+
*/
|
|
95
|
+
export declare function insufficientCreditsConflictError(conflicts: readonly RunConflict[], apiUrl?: string): ApiError;
|