@testsprite/testsprite-cli 0.12.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 +11 -4
- 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 +436 -5
- 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.js +9 -9
- package/dist/commands/project.d.ts +5 -5
- package/dist/commands/project.js +42 -42
- package/dist/commands/schedule.d.ts +2 -0
- package/dist/commands/schedule.js +18 -10
- package/dist/commands/test.d.ts +73 -27
- package/dist/commands/test.js +1756 -413
- package/dist/commands/testlist.js +49 -19
- 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 +34 -20
- 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 +23 -2
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.js +20 -1
- package/dist/lib/conflict-reason.d.ts +27 -3
- package/dist/lib/conflict-reason.js +53 -4
- package/dist/lib/credentials.js +56 -14
- 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 +18 -11
- package/dist/lib/errors.js +111 -13
- 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 +1 -0
- package/dist/lib/gh-output.js +13 -4
- package/dist/lib/history-retention.d.ts +8 -0
- package/dist/lib/history-retention.js +24 -0
- package/dist/lib/http.d.ts +37 -19
- package/dist/lib/http.js +46 -24
- 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 +1 -1
- package/dist/lib/local-target.js +1 -1
- 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 +88 -7
- package/dist/lib/runs.types.d.ts +59 -10
- 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 +6 -6
- package/dist/lib/telemetry.d.ts +4 -1
- package/dist/lib/telemetry.js +13 -13
- 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/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 -38
|
@@ -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
|
}
|
|
@@ -218,6 +237,7 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
218
237
|
env,
|
|
219
238
|
requestTimeoutMs,
|
|
220
239
|
shutdownSignal: deps.shutdownSignal ?? globalShutdown.signal,
|
|
240
|
+
shutdown: deps.shutdown ?? globalShutdown,
|
|
221
241
|
};
|
|
222
242
|
}
|
|
223
243
|
const credentialsPath = deps.credentialsPath ?? defaultCredentialsPath();
|
|
@@ -232,7 +252,7 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
232
252
|
// VALIDATION_ERROR rather than an opaque URL throw or a retried "fetch failed".
|
|
233
253
|
assertValidEndpointUrl(config.apiUrl);
|
|
234
254
|
if (!config.apiKey)
|
|
235
|
-
throw ApiError.authRequired();
|
|
255
|
+
throw ApiError.authRequired(undefined, nameableProfile(config.profile));
|
|
236
256
|
assertValidApiKey(config.apiKey);
|
|
237
257
|
return {
|
|
238
258
|
baseUrl: facadeBaseUrl(config.apiUrl),
|
|
@@ -254,6 +274,7 @@ function resolveHttpClientOptions(opts, deps) {
|
|
|
254
274
|
env,
|
|
255
275
|
requestTimeoutMs,
|
|
256
276
|
shutdownSignal: deps.shutdownSignal ?? globalShutdown.signal,
|
|
277
|
+
shutdown: deps.shutdown ?? globalShutdown,
|
|
257
278
|
};
|
|
258
279
|
}
|
|
259
280
|
function formatDebug(event) {
|
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
|
|
@@ -7,16 +7,19 @@
|
|
|
7
7
|
* Absent ⇒ a legacy / pre-discriminator backend: treated as `in_flight` (the
|
|
8
8
|
* historical rendering) for backward compatibility.
|
|
9
9
|
*
|
|
10
|
-
* `insufficient_credits` / `
|
|
10
|
+
* `insufficient_credits` / `paused` (or `billing_hold`, the deprecated spelling
|
|
11
|
+
* older backends send) are billing refusals the backend folds
|
|
11
12
|
* into `conflicts[]` for a MIXED batch (some cases dispatched, some refused). A
|
|
12
13
|
* batch where nothing dispatched and every refusal was credits comes back as a
|
|
13
14
|
* plain 402 `INSUFFICIENT_CREDITS` envelope instead — the same shape the
|
|
14
15
|
* single-run route answers — so both surfaces exit 12.
|
|
15
16
|
*/
|
|
16
17
|
import { ApiError } from './errors.js';
|
|
17
|
-
export type ConflictReason = 'in_flight' | 'mcp_view_only' | 'local_address' | 'not_found' | 'insufficient_credits' | '
|
|
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';
|
|
18
21
|
/** A conflict entry on a run response. `message` carries actionable detail for
|
|
19
|
-
* `local_address` / `insufficient_credits` / `
|
|
22
|
+
* `local_address` / `insufficient_credits` / `paused` / `error` (the
|
|
20
23
|
* backend's nextAction). */
|
|
21
24
|
export interface RunConflict {
|
|
22
25
|
testId: string;
|
|
@@ -30,6 +33,15 @@ export interface RunConflict {
|
|
|
30
33
|
* bare `{testId, currentRunId?}` conflicts read exactly as they did before.
|
|
31
34
|
*/
|
|
32
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;
|
|
33
45
|
/**
|
|
34
46
|
* One-line summary of a conflict set grouped by reason, e.g.
|
|
35
47
|
* `2 already in flight, 1 environment not runnable`. Used where a single line
|
|
@@ -61,6 +73,18 @@ export declare function isAllCreditsRefusal(resp: {
|
|
|
61
73
|
deferred: readonly unknown[];
|
|
62
74
|
conflicts: readonly RunConflict[];
|
|
63
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;
|
|
64
88
|
/**
|
|
65
89
|
* The exit-12 refusal for an all-credits batch — the SAME `INSUFFICIENT_CREDITS`
|
|
66
90
|
* envelope the single-run route answers (code, exit code, billing `nextAction`),
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
* Absent ⇒ a legacy / pre-discriminator backend: treated as `in_flight` (the
|
|
8
8
|
* historical rendering) for backward compatibility.
|
|
9
9
|
*
|
|
10
|
-
* `insufficient_credits` / `
|
|
10
|
+
* `insufficient_credits` / `paused` (or `billing_hold`, the deprecated spelling
|
|
11
|
+
* older backends send) are billing refusals the backend folds
|
|
11
12
|
* into `conflicts[]` for a MIXED batch (some cases dispatched, some refused). A
|
|
12
13
|
* batch where nothing dispatched and every refusal was credits comes back as a
|
|
13
14
|
* plain 402 `INSUFFICIENT_CREDITS` envelope instead — the same shape the
|
|
14
15
|
* single-run route answers — so both surfaces exit 12.
|
|
15
16
|
*/
|
|
16
17
|
import { ApiError, insufficientCreditsNextAction } from './errors.js';
|
|
18
|
+
import { classifyBillingRefusal, isPausedReason } from './billing-refusal.js';
|
|
17
19
|
/**
|
|
18
20
|
* Short human label for a conflict's cause — the reason a case did NOT dispatch.
|
|
19
21
|
* Absent reason renders as the legacy "already in flight" so an old backend's
|
|
@@ -29,8 +31,9 @@ export function describeConflict(c) {
|
|
|
29
31
|
return 'not found in this workspace';
|
|
30
32
|
case 'insufficient_credits':
|
|
31
33
|
return c.message || 'insufficient credits';
|
|
34
|
+
case 'paused':
|
|
32
35
|
case 'billing_hold':
|
|
33
|
-
return c.message || '
|
|
36
|
+
return c.message || 'workspace paused';
|
|
34
37
|
case 'error':
|
|
35
38
|
return c.message || 'dispatch failed';
|
|
36
39
|
case 'in_flight':
|
|
@@ -44,9 +47,21 @@ const CONFLICT_LABELS = {
|
|
|
44
47
|
local_address: 'environment not runnable',
|
|
45
48
|
not_found: 'not found',
|
|
46
49
|
insufficient_credits: 'insufficient credits',
|
|
47
|
-
|
|
50
|
+
paused: 'workspace paused',
|
|
51
|
+
billing_hold: 'workspace paused',
|
|
48
52
|
error: 'dispatch error',
|
|
49
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* True when the set is non-empty and every entry is the legacy in-flight
|
|
56
|
+
* cause (absent reason ⇒ `in_flight` too). Callers use this to restore the
|
|
57
|
+
* original, pre-reason-aware "N test(s) already in flight" wording for the
|
|
58
|
+
* common pure case, while any OTHER reason present (paused,
|
|
59
|
+
* mcp_view_only, …) still falls through to `summarizeConflicts`'s
|
|
60
|
+
* reason-aware summary instead of a misleading blanket "in flight".
|
|
61
|
+
*/
|
|
62
|
+
export function allConflictsInFlight(conflicts) {
|
|
63
|
+
return conflicts.length > 0 && conflicts.every(c => (c.reason ?? 'in_flight') === 'in_flight');
|
|
64
|
+
}
|
|
50
65
|
/** Per-reason occurrence counts, insertion-ordered; absent reason ⇒ `in_flight`. */
|
|
51
66
|
function countByReason(conflicts) {
|
|
52
67
|
const counts = new Map();
|
|
@@ -105,6 +120,40 @@ export function isAllCreditsRefusal(resp) {
|
|
|
105
120
|
resp.deferred.length === 0 &&
|
|
106
121
|
everyConflictIs(resp.conflicts, 'insufficient_credits'));
|
|
107
122
|
}
|
|
123
|
+
export function isPausedRefusal(resp) {
|
|
124
|
+
// Paused takes precedence over credits: topping up cannot resume the workspace.
|
|
125
|
+
return (resp.accepted.length === 0 &&
|
|
126
|
+
resp.deferred.length === 0 &&
|
|
127
|
+
resp.conflicts.some(c => isPausedReason(c.reason)) &&
|
|
128
|
+
resp.conflicts.every(c => isPausedReason(c.reason) || c.reason === 'insufficient_credits'));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The exit-13 refusal for a batch refused because the workspace is paused —
|
|
132
|
+
* the same `FEATURE_GATED` envelope the backend answers a single run with. The server's message on the conflicts says why
|
|
133
|
+
* the workspace is paused; the fallback deliberately doesn't guess.
|
|
134
|
+
*/
|
|
135
|
+
export function pausedConflictError(conflicts, apiUrl) {
|
|
136
|
+
const message = conflicts.find(c => isPausedReason(c.reason) && c.message?.trim())?.message;
|
|
137
|
+
return ApiError.fromEnvelope({
|
|
138
|
+
error: {
|
|
139
|
+
code: 'FEATURE_GATED',
|
|
140
|
+
message: message ?? 'This workspace is paused.',
|
|
141
|
+
nextAction: '',
|
|
142
|
+
requestId: 'local',
|
|
143
|
+
details: { reason: 'paused', conflicts: conflicts.map(c => c.testId) },
|
|
144
|
+
},
|
|
145
|
+
}, 403, undefined, apiUrl);
|
|
146
|
+
}
|
|
147
|
+
export function billingConflictLink(conflicts, apiUrl) {
|
|
148
|
+
const hasPaused = conflicts.some(c => isPausedReason(c.reason));
|
|
149
|
+
const hasCredits = conflicts.some(c => c.reason === 'insufficient_credits');
|
|
150
|
+
if (!hasPaused && !hasCredits)
|
|
151
|
+
return '';
|
|
152
|
+
const refusal = classifyBillingRefusal(hasPaused
|
|
153
|
+
? pausedConflictError(conflicts, apiUrl)
|
|
154
|
+
: insufficientCreditsConflictError(conflicts, apiUrl));
|
|
155
|
+
return refusal ? ` Upgrade: ${refusal.links.pricing}; billing: ${refusal.links.billing}.` : '';
|
|
156
|
+
}
|
|
108
157
|
/**
|
|
109
158
|
* The exit-12 refusal for an all-credits batch — the SAME `INSUFFICIENT_CREDITS`
|
|
110
159
|
* envelope the single-run route answers (code, exit code, billing `nextAction`),
|
|
@@ -126,6 +175,6 @@ export function insufficientCreditsConflictError(conflicts, apiUrl) {
|
|
|
126
175
|
requestId: 'local',
|
|
127
176
|
details: { reason: 'insufficient_credits', conflicts: conflicts.map(c => c.testId) },
|
|
128
177
|
},
|
|
129
|
-
});
|
|
178
|
+
}, 402, undefined, apiUrl);
|
|
130
179
|
}
|
|
131
180
|
//# sourceMappingURL=conflict-reason.js.map
|