@testsprite/testsprite-cli 0.17.0 → 0.18.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 +5 -4
- package/dist/commands/auth.js +2 -2
- package/dist/commands/conversation.js +52 -13
- package/dist/commands/project-env.js +48 -8
- package/dist/commands/project.d.ts +4 -0
- package/dist/commands/project.js +19 -2
- package/dist/commands/result.js +2 -1
- package/dist/commands/test.d.ts +9 -31
- package/dist/commands/test.js +73 -159
- package/dist/commands/testlist.d.ts +4 -2
- package/dist/commands/testlist.js +32 -4
- package/dist/commands/tunnel.d.ts +3 -3
- package/dist/commands/tunnel.js +3 -4
- package/dist/index.js +9 -6
- package/dist/lib/client-factory.d.ts +2 -2
- package/dist/lib/client-factory.js +3 -4
- package/dist/lib/conversation/api.d.ts +4 -0
- package/dist/lib/conversation/api.js +1 -0
- package/dist/lib/conversation/context.d.ts +10 -0
- package/dist/lib/conversation/context.js +17 -5
- package/dist/lib/conversation/environment.d.ts +3 -2
- package/dist/lib/conversation/environment.js +5 -17
- package/dist/lib/conversation/render.js +3 -0
- package/dist/lib/conversation/types.d.ts +2 -0
- package/dist/lib/download.d.ts +30 -1
- package/dist/lib/download.js +205 -71
- package/dist/lib/environment-tunnel.d.ts +3 -3
- package/dist/lib/environment-tunnel.js +9 -50
- package/dist/lib/first-suite-hint.d.ts +9 -13
- package/dist/lib/first-suite-hint.js +29 -35
- package/dist/lib/http.d.ts +1 -1
- package/dist/lib/http.js +5 -5
- package/dist/lib/local-target.d.ts +5 -4
- package/dist/lib/local-target.js +11 -10
- package/dist/lib/output.d.ts +1 -1
- package/dist/lib/output.js +2 -2
- package/dist/lib/presigned-url.js +2 -2
- package/dist/lib/removed-commands.js +17 -1
- package/dist/lib/result/evidence.d.ts +2 -0
- package/dist/lib/result/evidence.js +2 -0
- package/dist/lib/run-output.d.ts +3 -3
- package/dist/lib/target-url.d.ts +7 -7
- package/dist/lib/target-url.js +8 -8
- package/dist/lib/telemetry.d.ts +4 -4
- package/dist/lib/telemetry.js +1 -1
- package/dist/lib/transport-failure.js +2 -2
- package/dist/lib/tunnel-session.d.ts +1 -1
- package/dist/lib/tunnel-session.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/testsprite-ci.skill.md +4 -5
- package/skills/testsprite-onboard.skill.md +14 -12
- package/skills/testsprite-verify.codex.md +12 -14
- package/skills/testsprite-verify.skill.md +19 -21
|
@@ -11,7 +11,7 @@ import { buildJUnitReport, skippedRowFromSummary, writeJUnitReportFile } from '.
|
|
|
11
11
|
import { launchIds } from './run-render.js';
|
|
12
12
|
import { buildRunOutput, listResultReceipt, renderRunResults } from './run-output.js';
|
|
13
13
|
import { ApiError, InterruptError, RequestTimeoutError, localValidationError } from './errors.js';
|
|
14
|
-
import {
|
|
14
|
+
import { parseLoopbackTargetUrl } from './local-target.js';
|
|
15
15
|
import { terminalSafeLine, terminalSafeWriter } from './terminal-text.js';
|
|
16
16
|
export const ENVIRONMENT_PREFLIGHT_TIMEOUT_MS = 5_000;
|
|
17
17
|
/** Advisory-only reads must not inherit the run's long wait or retry budget. */
|
|
@@ -39,19 +39,19 @@ export function readEnvironmentPreflight(client, path) {
|
|
|
39
39
|
}
|
|
40
40
|
export function assertNoTunnelOptions(args) {
|
|
41
41
|
if (args.tunnelClientId !== undefined)
|
|
42
|
-
throw localValidationError('tunnel-client', '--tunnel-client only applies
|
|
43
|
-
'tunnel).
|
|
42
|
+
throw localValidationError('tunnel-client', '--tunnel-client only applies to a run on a local environment (it attaches the run to an ' +
|
|
43
|
+
'already-running tunnel). Run on one with --env <name>, or remove --tunnel-client');
|
|
44
44
|
if (args.cancelOnInterrupt === false)
|
|
45
|
-
throw localValidationError('cancel-on-interrupt', '--no-cancel-on-interrupt only applies
|
|
45
|
+
throw localValidationError('cancel-on-interrupt', '--no-cancel-on-interrupt only applies to a run on a local environment. An ordinary run is never ' +
|
|
46
46
|
'cancelled when this command stops waiting — Ctrl-C detaches, and `testsprite test ' +
|
|
47
47
|
'cancel <run-id>` is the way to stop one');
|
|
48
48
|
}
|
|
49
49
|
const announcedEnvironments = new WeakMap();
|
|
50
50
|
/** One resolver for fresh runs, replay, chained creation and test-list runs. */
|
|
51
51
|
export async function resolveEnvironmentRunTarget(args) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (args.targetUrl !== undefined
|
|
52
|
+
// A run aimed at an address of its own (a pull request preview) leaves the
|
|
53
|
+
// environment's address, and its tunnel, alone.
|
|
54
|
+
if (args.targetUrl !== undefined)
|
|
55
55
|
return undefined;
|
|
56
56
|
let test = args.knownTest;
|
|
57
57
|
if (!test && args.testId && !args.skipTestLookup) {
|
|
@@ -61,27 +61,11 @@ export async function resolveEnvironmentRunTarget(args) {
|
|
|
61
61
|
catch (err) {
|
|
62
62
|
if (err instanceof InterruptError)
|
|
63
63
|
throw err;
|
|
64
|
-
if (explicit) {
|
|
65
|
-
if (err instanceof ApiError &&
|
|
66
|
-
(err.httpStatus === 403 || err.httpStatus === 404 || err.code === 'UNAVAILABLE')) {
|
|
67
|
-
throw new ApiError({
|
|
68
|
-
code: err.code,
|
|
69
|
-
message: `Cannot read test ${args.testId} for --local preflight.`,
|
|
70
|
-
nextAction: 'Check the test ID and read:tests permission, then retry.',
|
|
71
|
-
requestId: err.requestId,
|
|
72
|
-
details: {},
|
|
73
|
-
}, err.httpStatus);
|
|
74
|
-
}
|
|
75
|
-
throw err;
|
|
76
|
-
}
|
|
77
64
|
return undefined;
|
|
78
65
|
}
|
|
79
66
|
}
|
|
80
|
-
if (test?.type === 'backend' && !args.includeBackend)
|
|
81
|
-
if (explicit)
|
|
82
|
-
throw localValidationError('local', `backend tests don't open a browser; the tunnel is not used. Run: testsprite run ${args.testId}`);
|
|
67
|
+
if (test?.type === 'backend' && !args.includeBackend)
|
|
83
68
|
return undefined;
|
|
84
|
-
}
|
|
85
69
|
const projectId = test?.projectId ?? args.projectId;
|
|
86
70
|
let environments;
|
|
87
71
|
if (projectId) {
|
|
@@ -106,10 +90,6 @@ export async function resolveEnvironmentRunTarget(args) {
|
|
|
106
90
|
const selected = args.environment === undefined
|
|
107
91
|
? (environments?.find(row => row.isDefault) ?? environments?.find(row => !row.isTemporary))
|
|
108
92
|
: environments?.find(row => row.name === args.environment);
|
|
109
|
-
if (explicit && args.environment !== undefined && environments && !selected) {
|
|
110
|
-
const available = environments.map(row => row.name).sort();
|
|
111
|
-
throw localValidationError('env', `unknown environment '${args.environment}'; use one of: ${available.join(', ')}`, available);
|
|
112
|
-
}
|
|
113
93
|
const localOf = (row) => {
|
|
114
94
|
if (!row || typeof row.url !== 'string')
|
|
115
95
|
return undefined;
|
|
@@ -130,28 +110,6 @@ export async function resolveEnvironmentRunTarget(args) {
|
|
|
130
110
|
args.stderr(line);
|
|
131
111
|
announced.add(key);
|
|
132
112
|
};
|
|
133
|
-
const explicitTarget = (target) => {
|
|
134
|
-
if (args.environment !== undefined && selected && !localOf(selected))
|
|
135
|
-
announce(`sign-in:${projectId}:${selected.name}:${target.targetUrl}`, `Using environment "${terminalSafeLine(selected.name)}" sign-in against ${terminalSafeLine(target.targetUrl)} through a tunnel.`);
|
|
136
|
-
return target;
|
|
137
|
-
};
|
|
138
|
-
if (explicitUrl)
|
|
139
|
-
return explicitTarget({ ...explicitUrl, targetUrl: args.targetUrl, automatic: false });
|
|
140
|
-
if (args.localPort !== undefined) {
|
|
141
|
-
const selectedHost = localOf(selected)?.host;
|
|
142
|
-
const matching = environments?.filter(row => !row.isTemporary && localOf(row)?.port === args.localPort) ?? [];
|
|
143
|
-
const hosts = new Set(matching.map(row => localOf(row).host));
|
|
144
|
-
const host = args.localHost ??
|
|
145
|
-
selectedHost ??
|
|
146
|
-
(hosts.size === 1 ? [...hosts][0] : undefined) ??
|
|
147
|
-
(environments === undefined ? '127.0.0.1' : DEFAULT_LOCAL_HOST);
|
|
148
|
-
return explicitTarget({
|
|
149
|
-
host,
|
|
150
|
-
port: args.localPort,
|
|
151
|
-
targetUrl: buildLocalTargetUrl(host, args.localPort),
|
|
152
|
-
automatic: false,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
113
|
const local = localOf(selected);
|
|
156
114
|
if (!local)
|
|
157
115
|
return undefined;
|
|
@@ -170,6 +128,7 @@ export async function resolveEnvironmentRunTarget(args) {
|
|
|
170
128
|
targetUrl: selected.url,
|
|
171
129
|
automatic: args.tunnelClientId === undefined,
|
|
172
130
|
environmentName: selected.name,
|
|
131
|
+
...(selected.isDefault !== undefined ? { environmentIsDefault: selected.isDefault } : {}),
|
|
173
132
|
};
|
|
174
133
|
}
|
|
175
134
|
export function unsupportedTunnelError(command) {
|
|
@@ -13,35 +13,31 @@
|
|
|
13
13
|
* charges nothing.
|
|
14
14
|
*
|
|
15
15
|
* Zero requests: each call site branches only on what it already knows.
|
|
16
|
-
* `project create` knows the type;
|
|
17
|
-
* on this machine. `test list` and a cloud `run --project` know neither, so
|
|
16
|
+
* `project create` knows the type; a project run on a local environment knows
|
|
17
|
+
* the app is on this machine. `test list` and a cloud `run --project` know neither, so
|
|
18
18
|
* their sentence names the backend API spec as a clause.
|
|
19
19
|
*/
|
|
20
|
-
import { type StoredLocalTarget } from './local-target.js';
|
|
21
20
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `--target-url`, and `environment` for `--env` or the saved environment the
|
|
26
|
-
* tunnel was resolved from.
|
|
21
|
+
* The local environment the run that found the project empty was going to: its
|
|
22
|
+
* name, and whether it is the project's default. The agent explores the default
|
|
23
|
+
* unless the request names another, so the planning advice names it otherwise.
|
|
27
24
|
*/
|
|
28
25
|
export type LocalHint = {
|
|
29
|
-
host?: StoredLocalTarget['host'];
|
|
30
|
-
port?: number;
|
|
31
|
-
targetUrl?: string;
|
|
32
26
|
environment?: string;
|
|
27
|
+
isDefault?: boolean;
|
|
33
28
|
};
|
|
34
29
|
/**
|
|
35
30
|
* Multi-line `[hint]` block for stderr after a real `project create` (text
|
|
36
31
|
* mode): a new project has no environment and no tests, so it names both
|
|
37
|
-
* steps.
|
|
32
|
+
* steps. A web app may be on this machine rather than deployed, so a frontend
|
|
33
|
+
* project is shown the local environment too; an API runs from the cloud only.
|
|
38
34
|
*/
|
|
39
35
|
export declare function firstSuiteNextSteps(wireProjectId: string, type: string): string;
|
|
40
36
|
/**
|
|
41
37
|
* One sentence for an EMPTY project; folded into an error message or a hint.
|
|
42
38
|
*
|
|
43
39
|
* Pass `local` only where the caller knows the project runs on this machine
|
|
44
|
-
* (
|
|
40
|
+
* (a project run on a local environment); see the module comment for why the other
|
|
45
41
|
* callers cannot.
|
|
46
42
|
*/
|
|
47
43
|
export declare function emptyProjectNextStep(wireProjectId: string, local?: LocalHint | null): string;
|
|
@@ -13,43 +13,16 @@
|
|
|
13
13
|
* charges nothing.
|
|
14
14
|
*
|
|
15
15
|
* Zero requests: each call site branches only on what it already knows.
|
|
16
|
-
* `project create` knows the type;
|
|
17
|
-
* on this machine. `test list` and a cloud `run --project` know neither, so
|
|
16
|
+
* `project create` knows the type; a project run on a local environment knows
|
|
17
|
+
* the app is on this machine. `test list` and a cloud `run --project` know neither, so
|
|
18
18
|
* their sentence names the backend API spec as a clause.
|
|
19
19
|
*/
|
|
20
|
-
import { quoteEnvironmentName } from './environment-tunnel.js';
|
|
21
|
-
import { DEFAULT_LOCAL_HOST } from './local-target.js';
|
|
22
20
|
import { terminalSafeLine } from './terminal-text.js';
|
|
23
|
-
/**
|
|
24
|
-
* `run <test-id>` with the target flags the empty run was given. A bare
|
|
25
|
-
* `run` would resolve the project's DEFAULT environment, which may be a
|
|
26
|
-
* deployed site rather than the app on this machine, so the environment is
|
|
27
|
-
* always named when one was used. `--local-host` is carried whenever the host
|
|
28
|
-
* is not the default: without it a `::1` or `localhost` app would be run
|
|
29
|
-
* against 127.0.0.1.
|
|
30
|
-
*/
|
|
31
|
-
function localRunCommand(local) {
|
|
32
|
-
const flags = [];
|
|
33
|
-
if (local.targetUrl !== undefined) {
|
|
34
|
-
flags.push(`--target-url ${shellWord(local.targetUrl)}`);
|
|
35
|
-
}
|
|
36
|
-
else if (local.port !== undefined) {
|
|
37
|
-
flags.push(`--local ${local.port}`);
|
|
38
|
-
if (local.host !== undefined && local.host !== DEFAULT_LOCAL_HOST)
|
|
39
|
-
flags.push(`--local-host ${local.host}`);
|
|
40
|
-
}
|
|
41
|
-
if (local.environment !== undefined)
|
|
42
|
-
flags.push(`--env ${quoteEnvironmentName(local.environment)}`);
|
|
43
|
-
return ['testsprite run <test-id>', ...flags].join(' ');
|
|
44
|
-
}
|
|
45
|
-
/** A URL as one shell word: as typed when it is plain, single-quoted otherwise. */
|
|
46
|
-
function shellWord(value) {
|
|
47
|
-
return /^[\w.:/@%+=,~-]+$/.test(value) ? value : quoteEnvironmentName(value);
|
|
48
|
-
}
|
|
49
21
|
/**
|
|
50
22
|
* Multi-line `[hint]` block for stderr after a real `project create` (text
|
|
51
23
|
* mode): a new project has no environment and no tests, so it names both
|
|
52
|
-
* steps.
|
|
24
|
+
* steps. A web app may be on this machine rather than deployed, so a frontend
|
|
25
|
+
* project is shown the local environment too; an API runs from the cloud only.
|
|
53
26
|
*/
|
|
54
27
|
export function firstSuiteNextSteps(wireProjectId, type) {
|
|
55
28
|
const projectId = terminalSafeLine(wireProjectId);
|
|
@@ -62,6 +35,11 @@ export function firstSuiteNextSteps(wireProjectId, type) {
|
|
|
62
35
|
return [
|
|
63
36
|
'[hint] Next: give the project an environment, then ask its agent for your first tests and apply them:',
|
|
64
37
|
` ${env}`,
|
|
38
|
+
...(type === 'backend'
|
|
39
|
+
? []
|
|
40
|
+
: [
|
|
41
|
+
` (an app on this machine: testsprite project env create ${projectId} --name local --url http://localhost:<port>)`,
|
|
42
|
+
]),
|
|
65
43
|
` ${plan}`,
|
|
66
44
|
' testsprite apply',
|
|
67
45
|
].join('\n');
|
|
@@ -70,21 +48,37 @@ export function firstSuiteNextSteps(wireProjectId, type) {
|
|
|
70
48
|
* One sentence for an EMPTY project; folded into an error message or a hint.
|
|
71
49
|
*
|
|
72
50
|
* Pass `local` only where the caller knows the project runs on this machine
|
|
73
|
-
* (
|
|
51
|
+
* (a project run on a local environment); see the module comment for why the other
|
|
74
52
|
* callers cannot.
|
|
75
53
|
*/
|
|
76
54
|
export function emptyProjectNextStep(wireProjectId, local) {
|
|
77
55
|
const projectId = terminalSafeLine(wireProjectId);
|
|
78
56
|
if (local) {
|
|
57
|
+
const plan = local.environment !== undefined && local.isDefault === false
|
|
58
|
+
? `testsprite plan "<what to test> on the ${nameForCommand(local.environment)} environment" --project ${projectId}`
|
|
59
|
+
: `testsprite plan --project ${projectId}`;
|
|
60
|
+
// No run command: `apply` prints the one for what it saves.
|
|
79
61
|
return (`This project has no tests yet. Ask the project's agent for a first set; its browser ` +
|
|
80
|
-
`
|
|
81
|
-
`
|
|
82
|
-
`then run them with ${localRunCommand(local)}`);
|
|
62
|
+
`opens the app on your machine through a tunnel, so keep testsprite tunnel start ` +
|
|
63
|
+
`running in another terminal: ${plan}, then testsprite apply`);
|
|
83
64
|
}
|
|
84
65
|
return (`This project has no tests yet. Ask the project's agent for a first set: ` +
|
|
85
66
|
`testsprite plan --project ${projectId}, then testsprite apply ` +
|
|
86
67
|
`(a backend project: attach its API spec with --file <spec>)`);
|
|
87
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* An environment name for inside the double-quoted request above, or a
|
|
71
|
+
* placeholder. Anyone who can edit the project's environments names them, and
|
|
72
|
+
* no escape is safe in every shell: inside double quotes a POSIX shell runs
|
|
73
|
+
* `$(…)` and backticks, PowerShell runs `$(…)` and escapes with a backtick, and
|
|
74
|
+
* cmd expands `%…%`. Letters, digits, spaces, `.`, `_` and `-` mean nothing to
|
|
75
|
+
* any of them, so such a name goes in as written; any other is the user's to
|
|
76
|
+
* type.
|
|
77
|
+
*/
|
|
78
|
+
function nameForCommand(name) {
|
|
79
|
+
const shown = terminalSafeLine(name);
|
|
80
|
+
return /^[\p{L}\p{N} ._-]+$/u.test(shown) ? shown : '<environment name>';
|
|
81
|
+
}
|
|
88
82
|
/** The same sentence as a stderr `[hint]` line. */
|
|
89
83
|
export function emptyProjectHint(projectId, local) {
|
|
90
84
|
return `[hint] ${emptyProjectNextStep(projectId, local)}`;
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -317,7 +317,7 @@ export declare class HttpClient {
|
|
|
317
317
|
signal?: AbortSignal;
|
|
318
318
|
}): Promise<RunResponse>;
|
|
319
319
|
/**
|
|
320
|
-
* POST /api/cli/v1/tunnel — mint a tunnel client for
|
|
320
|
+
* POST /api/cli/v1/tunnel — mint a tunnel client for a run on a local environment.
|
|
321
321
|
*
|
|
322
322
|
* The ONLY response on this surface that carries a secret. Deliberately NOT
|
|
323
323
|
* sent with an `Idempotency-Key`: the interceptor persists the response body
|
package/dist/lib/http.js
CHANGED
|
@@ -251,7 +251,7 @@ export class HttpClient {
|
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
253
|
/**
|
|
254
|
-
* POST /api/cli/v1/tunnel — mint a tunnel client for
|
|
254
|
+
* POST /api/cli/v1/tunnel — mint a tunnel client for a run on a local environment.
|
|
255
255
|
*
|
|
256
256
|
* The ONLY response on this surface that carries a secret. Deliberately NOT
|
|
257
257
|
* sent with an `Idempotency-Key`: the interceptor persists the response body
|
|
@@ -1040,8 +1040,8 @@ function nonApiResponseError(response, requestId, url) {
|
|
|
1040
1040
|
const contentType = response.headers.get('content-type');
|
|
1041
1041
|
return new TransportError(`Something between this machine and the TestSprite API answered HTTP ${response.status} ` +
|
|
1042
1042
|
`(content-type: ${contentType ?? 'none'}) instead of the API; the API key was not rejected.`, requestId, {
|
|
1043
|
-
nextAction: 'A proxy, firewall or captive portal probably answered. Check HTTPS_PROXY
|
|
1044
|
-
|
|
1043
|
+
nextAction: 'A proxy, firewall or captive portal probably answered. Check HTTPS_PROXY, ' +
|
|
1044
|
+
`or ask your network admin to allow ${new URL(url).host}, then retry.`,
|
|
1045
1045
|
details: { httpStatus: response.status, contentType },
|
|
1046
1046
|
});
|
|
1047
1047
|
}
|
|
@@ -1072,8 +1072,8 @@ export function malformedResponseError(response, requestId, cause) {
|
|
|
1072
1072
|
message: `The server returned a non-JSON response${contentTypeNote} for an HTTP ${response.status}. ` +
|
|
1073
1073
|
`This usually means the endpoint is not the TestSprite API — a proxy, captive portal, or ` +
|
|
1074
1074
|
`login page can return HTML with a success status.`,
|
|
1075
|
-
nextAction: 'Check that
|
|
1076
|
-
'
|
|
1075
|
+
nextAction: 'Check HTTPS_PROXY and that nothing on this network answers in place of the ' +
|
|
1076
|
+
'TestSprite API, then retry.',
|
|
1077
1077
|
requestId,
|
|
1078
1078
|
details: {
|
|
1079
1079
|
httpStatus: response.status,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Loopback target handling (`project env create --local <port>` / `--url`) and the pre-charge port probe.
|
|
3
3
|
*
|
|
4
4
|
* Separate from `target-url-preflight.ts` on purpose, even though both answer
|
|
5
5
|
* "is the thing I am about to bill a run against actually there". They probe
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* with `fetch()` (proxy dispatcher and all) is the closest local analogue,
|
|
10
10
|
* and an ambiguous result downgrades to a warning because the CLI is not
|
|
11
11
|
* the machine that will do the fetching.
|
|
12
|
-
* -
|
|
12
|
+
* - a local environment's address is dialled by the vendored tunnel client running *in
|
|
13
13
|
* this very process*, with `net.connect`, against the candidate set
|
|
14
14
|
* {@link resolveDialCandidates} produces. So the probe uses that same
|
|
15
15
|
* function and the same kind of socket. A pass means at least one TCP
|
|
@@ -87,7 +87,7 @@ export interface StoredLocalTarget {
|
|
|
87
87
|
host: LoopbackHost;
|
|
88
88
|
port: number;
|
|
89
89
|
}
|
|
90
|
-
/** Parse a loopback
|
|
90
|
+
/** Parse a loopback URL the stored-target API and tunnel can reach: host, port and, if any, the app's entry path. */
|
|
91
91
|
export declare function parseLoopbackTargetUrl(raw: string, field?: string): StoredLocalTarget | undefined;
|
|
92
92
|
/**
|
|
93
93
|
* Parse the `--local` / `--local-host` / `--url` trio a stored-target write
|
|
@@ -109,6 +109,7 @@ export declare function parseStoredLocalTarget(opts: {
|
|
|
109
109
|
*/
|
|
110
110
|
export declare function assertStoredLocalTargetListening(target: StoredLocalTarget, opts: {
|
|
111
111
|
skipPreflight?: boolean;
|
|
112
|
+
local?: string;
|
|
112
113
|
}, deps?: LocalPortProbeDeps): Promise<void>;
|
|
113
114
|
/** `http://<host>:<port>`, with IPv6 bracketed as the URL grammar requires. */
|
|
114
115
|
export declare function buildLocalTargetUrl(host: LoopbackHost, port: number): string;
|
|
@@ -126,7 +127,7 @@ export declare function probeLocalPort(host: string, port: number, deps?: LocalP
|
|
|
126
127
|
* measured 1,003 blocked-with-URL CLI runs, 55.5% of the third-party-tunnel
|
|
127
128
|
* ones blocked, every one of them charged, because the run row and its credit
|
|
128
129
|
* spend happen before the Lambda ever discovers the target is dead. A dev
|
|
129
|
-
* server that is not running is the single most likely
|
|
130
|
+
* server that is not running is the single most likely local-environment mistake, and
|
|
130
131
|
* this is the only place it can be caught for free.
|
|
131
132
|
*
|
|
132
133
|
* `skipPreflight: true` is a pure no-op with ZERO connection attempts.
|
package/dist/lib/local-target.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Loopback target handling (`project env create --local <port>` / `--url`) and the pre-charge port probe.
|
|
3
3
|
*
|
|
4
4
|
* Separate from `target-url-preflight.ts` on purpose, even though both answer
|
|
5
5
|
* "is the thing I am about to bill a run against actually there". They probe
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* with `fetch()` (proxy dispatcher and all) is the closest local analogue,
|
|
10
10
|
* and an ambiguous result downgrades to a warning because the CLI is not
|
|
11
11
|
* the machine that will do the fetching.
|
|
12
|
-
* -
|
|
12
|
+
* - a local environment's address is dialled by the vendored tunnel client running *in
|
|
13
13
|
* this very process*, with `net.connect`, against the candidate set
|
|
14
14
|
* {@link resolveDialCandidates} produces. So the probe uses that same
|
|
15
15
|
* function and the same kind of socket. A pass means at least one TCP
|
|
@@ -98,7 +98,7 @@ export function normalizeStoredLocalHost(raw) {
|
|
|
98
98
|
throw err;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
/** Parse a loopback
|
|
101
|
+
/** Parse a loopback URL the stored-target API and tunnel can reach: host, port and, if any, the app's entry path. */
|
|
102
102
|
export function parseLoopbackTargetUrl(raw, field = 'target-url') {
|
|
103
103
|
let parsed;
|
|
104
104
|
try {
|
|
@@ -111,11 +111,11 @@ export function parseLoopbackTargetUrl(raw, field = 'target-url') {
|
|
|
111
111
|
if (host === undefined)
|
|
112
112
|
return undefined;
|
|
113
113
|
// Read the explicit port from the input: URL.port drops the default :80.
|
|
114
|
-
const match = /^http:\/\/(localhost|127\.0\.0\.1|\[::1\]):([0-9]+)
|
|
114
|
+
const match = /^http:\/\/(localhost|127\.0\.0\.1|\[::1\]):([0-9]+)(?:\/[^?#]*)?$/.exec(raw);
|
|
115
115
|
const port = match === null ? 0 : Number(match[2]);
|
|
116
116
|
if (match === null || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
117
|
-
throw localValidationError(field, 'loopback URLs must use http://localhost:<port>, http://127.0.0.1:<port>, or http://[::1]:<port>, with a port between 1 and 65535
|
|
118
|
-
|
|
117
|
+
throw localValidationError(field, 'loopback URLs must use http://localhost:<port>, http://127.0.0.1:<port>, or http://[::1]:<port>, with a port between 1 and 65535; ' +
|
|
118
|
+
"a path may follow (the app's entry page), a query, fragment or credentials may not");
|
|
119
119
|
}
|
|
120
120
|
return { host, port };
|
|
121
121
|
}
|
|
@@ -164,14 +164,15 @@ export async function assertStoredLocalTargetListening(target, opts, deps = {})
|
|
|
164
164
|
const outcome = await probeLocalPort(target.host, target.port, deps);
|
|
165
165
|
if (outcome.verdict === 'refuse') {
|
|
166
166
|
const targetUrl = buildLocalTargetUrl(target.host, target.port);
|
|
167
|
+
const flag = opts.local !== undefined ? 'local' : 'url';
|
|
167
168
|
throw ApiError.fromEnvelope({
|
|
168
169
|
error: {
|
|
169
170
|
code: 'VALIDATION_ERROR',
|
|
170
171
|
message: `Nothing is listening on ${targetUrl}. Start your app first, or pass --skip-preflight.`,
|
|
171
|
-
nextAction:
|
|
172
|
+
nextAction: `Verify --${flag} names the port your app listens on.`,
|
|
172
173
|
requestId: 'local',
|
|
173
174
|
details: {
|
|
174
|
-
field:
|
|
175
|
+
field: flag,
|
|
175
176
|
reason: 'local-port-not-listening',
|
|
176
177
|
host: target.host,
|
|
177
178
|
port: target.port,
|
|
@@ -261,7 +262,7 @@ const SKIP_HINT = 'Skip this check with --skip-preflight.';
|
|
|
261
262
|
* measured 1,003 blocked-with-URL CLI runs, 55.5% of the third-party-tunnel
|
|
262
263
|
* ones blocked, every one of them charged, because the run row and its credit
|
|
263
264
|
* spend happen before the Lambda ever discovers the target is dead. A dev
|
|
264
|
-
* server that is not running is the single most likely
|
|
265
|
+
* server that is not running is the single most likely local-environment mistake, and
|
|
265
266
|
* this is the only place it can be caught for free.
|
|
266
267
|
*
|
|
267
268
|
* `skipPreflight: true` is a pure no-op with ZERO connection attempts.
|
|
@@ -279,7 +280,7 @@ export async function assertLocalPortListening(host, port, opts, _stderrFn, deps
|
|
|
279
280
|
: `Nothing is listening on ${host}:${port}, so a tunnel run would fail after being billed.`,
|
|
280
281
|
nextAction: opts.environmentName !== undefined
|
|
281
282
|
? `Start your app on ${host}:${port} (environment "${opts.environmentName}") or run with --skip-preflight.`
|
|
282
|
-
: `Start your app on port ${port} first, or point
|
|
283
|
+
: `Start your app on port ${port} first, or point the environment at the port it is actually ` +
|
|
283
284
|
`serving. ${SKIP_HINT}`,
|
|
284
285
|
requestId: 'local',
|
|
285
286
|
details: {
|
package/dist/lib/output.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type OutputMode = 'json' | 'text';
|
|
|
2
2
|
/**
|
|
3
3
|
* Help-text footer pointing at the global options surface so users
|
|
4
4
|
* looking at any subcommand `--help` don't miss `--dry-run`, `--output`,
|
|
5
|
-
* `--profile`, `--
|
|
5
|
+
* `--profile`, `--request-timeout`, `--debug`.
|
|
6
6
|
*/
|
|
7
7
|
export declare const GLOBAL_OPTS_HINT: string;
|
|
8
8
|
export declare function isOutputMode(value: unknown): value is OutputMode;
|
package/dist/lib/output.js
CHANGED
|
@@ -4,9 +4,9 @@ import { jsonForTerminal, terminalSafe, terminalSafeLine } from './terminal-text
|
|
|
4
4
|
/**
|
|
5
5
|
* Help-text footer pointing at the global options surface so users
|
|
6
6
|
* looking at any subcommand `--help` don't miss `--dry-run`, `--output`,
|
|
7
|
-
* `--profile`, `--
|
|
7
|
+
* `--profile`, `--request-timeout`, `--debug`.
|
|
8
8
|
*/
|
|
9
|
-
export const GLOBAL_OPTS_HINT = '\nGlobal options (--dry-run, --output, --profile, --
|
|
9
|
+
export const GLOBAL_OPTS_HINT = '\nGlobal options (--dry-run, --output, --profile, --request-timeout, --verbose, --debug):' +
|
|
10
10
|
'\n testsprite --help';
|
|
11
11
|
export function isOutputMode(value) {
|
|
12
12
|
return value === 'json' || value === 'text';
|
|
@@ -29,8 +29,8 @@ export function assertSafePresignedUploadUrl(uploadUrl, facadeBaseUrl) {
|
|
|
29
29
|
error: {
|
|
30
30
|
code: 'VALIDATION_ERROR',
|
|
31
31
|
message: `Refusing the presigned upload URL the server returned: ${reason}.`,
|
|
32
|
-
nextAction: 'No bytes were uploaded. This can indicate
|
|
33
|
-
'
|
|
32
|
+
nextAction: 'No bytes were uploaded. This can indicate an intercepted connection to the API — ' +
|
|
33
|
+
'check HTTPS_PROXY and your network, then retry.',
|
|
34
34
|
requestId: 'local',
|
|
35
35
|
details: { field: 'uploadUrl', reason: 'unsafe_presigned_url' },
|
|
36
36
|
},
|
|
@@ -89,7 +89,7 @@ export function removedCommandPointer(groupPath, name) {
|
|
|
89
89
|
const path = groupPath === '' ? name : `${groupPath} ${name}`;
|
|
90
90
|
return `\`${path}\` was removed in 0.17.0; ${replacement}`;
|
|
91
91
|
}
|
|
92
|
-
const ENV_CREATE = 'set it on an environment: testsprite project env create <project-id> --name default --url <url
|
|
92
|
+
const ENV_CREATE = 'set it on an environment: testsprite project env create <project-id> --name default --url <url>, which takes the sign-in flags';
|
|
93
93
|
const ENV_UPDATE = 'set it on an environment: testsprite project env update <project-id> <name> with the same flag';
|
|
94
94
|
const NO_RESULT_ON_A_CASE = 'a test case carries no result; read its results with testsprite result list --test <test-id> (--limit 1 for the latest)';
|
|
95
95
|
const ENVIRONMENT_OPTIONS = [
|
|
@@ -100,6 +100,19 @@ const ENVIRONMENT_OPTIONS = [
|
|
|
100
100
|
'--password-file',
|
|
101
101
|
'--skip-preflight',
|
|
102
102
|
];
|
|
103
|
+
const LOCAL_ENVIRONMENT = 'the address lives on the environment: testsprite project env create <project-id> --name local --url http://localhost:<port>, then testsprite run <test-id...> --env local (no flag when it is the default) opens the tunnel';
|
|
104
|
+
/** The options removed in 0.18.0, by the command that took them, and what replaced them. */
|
|
105
|
+
const REMOVED_OPTIONS_0_18 = new Map([
|
|
106
|
+
['run --local', LOCAL_ENVIRONMENT],
|
|
107
|
+
[
|
|
108
|
+
'run --local-host',
|
|
109
|
+
'the host lives on the environment: testsprite project env create <project-id> --name local --url http://127.0.0.1:<port> (or http://[::1]:<port>)',
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
'run --target-url',
|
|
113
|
+
"a run's address is its environment's: testsprite project env create <project-id> --name <name> --url <url>, then testsprite run <test-id...> --env <name>; for a pull request preview, testsprite ci run --env <name> --target-url <url>",
|
|
114
|
+
],
|
|
115
|
+
]);
|
|
103
116
|
/** Each removed option, by the command that took it, and what replaced it. */
|
|
104
117
|
const REMOVED_OPTIONS = new Map([
|
|
105
118
|
...ENVIRONMENT_OPTIONS.map((option) => [
|
|
@@ -146,6 +159,9 @@ export function removedOptionPointer(commandPath, message) {
|
|
|
146
159
|
const notOnRun = commandPath === 'run' ? NOT_ON_RUN.get(option) : undefined;
|
|
147
160
|
if (notOnRun !== undefined)
|
|
148
161
|
return `\`run\` takes no \`${option}\`; ${notOnRun}`;
|
|
162
|
+
const recent = REMOVED_OPTIONS_0_18.get(`${commandPath} ${option}`);
|
|
163
|
+
if (recent !== undefined)
|
|
164
|
+
return `\`${commandPath} ${option}\` was removed in 0.18.0; ${recent}`;
|
|
149
165
|
const replacement = REMOVED_OPTIONS.get(`${commandPath} ${option}`);
|
|
150
166
|
return replacement === undefined
|
|
151
167
|
? undefined
|
|
@@ -68,4 +68,6 @@ export declare function writeEvidence(result: ResultDetail, opts: {
|
|
|
68
68
|
fetchImpl?: FetchImpl;
|
|
69
69
|
signal?: AbortSignal;
|
|
70
70
|
sleep?: (ms: number) => Promise<void>;
|
|
71
|
+
/** How long one file may go without data before it is given up on. */
|
|
72
|
+
stallTimeoutMs?: number;
|
|
71
73
|
}): Promise<WrittenEvidence>;
|
|
@@ -96,6 +96,7 @@ export async function writeEvidence(result, opts) {
|
|
|
96
96
|
fetchImpl: opts.fetchImpl ?? globalThis.fetch.bind(globalThis),
|
|
97
97
|
signal: opts.signal ?? globalShutdown.signal,
|
|
98
98
|
sleep: opts.sleep,
|
|
99
|
+
stallTimeoutMs: opts.stallTimeoutMs,
|
|
99
100
|
};
|
|
100
101
|
// Critical work: a first Ctrl-C aborts the downloads and waits for the
|
|
101
102
|
// staging directory to go, rather than exiting with it half written.
|
|
@@ -262,6 +263,7 @@ async function downloadOne(url, path, deps) {
|
|
|
262
263
|
await streamUrlToFile(url, path, deps.fetchImpl, {
|
|
263
264
|
sleep: deps.sleep,
|
|
264
265
|
shutdownSignal: deps.signal,
|
|
266
|
+
stallTimeoutMs: deps.stallTimeoutMs,
|
|
265
267
|
});
|
|
266
268
|
return null;
|
|
267
269
|
}
|
package/dist/lib/run-output.d.ts
CHANGED
|
@@ -80,9 +80,9 @@ export declare function buildRunOutput(opts: RunOutputOptions): {
|
|
|
80
80
|
message?: string;
|
|
81
81
|
}[] | undefined;
|
|
82
82
|
environment?: import("./runs.types.js").RunEnvironmentRef | null | undefined;
|
|
83
|
-
enqueuedAt?: string | undefined;
|
|
84
83
|
total?: number | undefined;
|
|
85
84
|
autoHeal?: boolean | undefined;
|
|
85
|
+
enqueuedAt?: string | undefined;
|
|
86
86
|
maxConcurrency?: number | undefined;
|
|
87
87
|
tunnelClientId?: string | undefined;
|
|
88
88
|
held?: {
|
|
@@ -188,9 +188,9 @@ export declare function buildRunOutput(opts: RunOutputOptions): {
|
|
|
188
188
|
message?: string;
|
|
189
189
|
}[] | undefined;
|
|
190
190
|
environment?: import("./runs.types.js").RunEnvironmentRef | null | undefined;
|
|
191
|
-
enqueuedAt?: string | undefined;
|
|
192
191
|
total?: number | undefined;
|
|
193
192
|
autoHeal?: boolean | undefined;
|
|
193
|
+
enqueuedAt?: string | undefined;
|
|
194
194
|
maxConcurrency?: number | undefined;
|
|
195
195
|
tunnelClientId?: string | undefined;
|
|
196
196
|
held?: {
|
|
@@ -257,9 +257,9 @@ export declare function previewRun(requests: Array<{
|
|
|
257
257
|
message?: string;
|
|
258
258
|
}[] | undefined;
|
|
259
259
|
environment?: import("./runs.types.js").RunEnvironmentRef | null | undefined;
|
|
260
|
-
enqueuedAt?: string | undefined;
|
|
261
260
|
total?: number | undefined;
|
|
262
261
|
autoHeal?: boolean | undefined;
|
|
262
|
+
enqueuedAt?: string | undefined;
|
|
263
263
|
maxConcurrency?: number | undefined;
|
|
264
264
|
tunnelClientId?: string | undefined;
|
|
265
265
|
held?: {
|
package/dist/lib/target-url.d.ts
CHANGED
|
@@ -45,19 +45,19 @@ export declare function assertNotLocal(rawUrl: string, caller?: TargetUrlCaller)
|
|
|
45
45
|
* verbatim in the rejection message — unchanged wording, not a new
|
|
46
46
|
* classification) plus a `hintKind` telling `assertNotLocal` which hint, if
|
|
47
47
|
* any, is honest to attach:
|
|
48
|
-
* - `'loopback'` — exactly the host set
|
|
48
|
+
* - `'loopback'` — exactly the host set a local environment accepts
|
|
49
49
|
* (`localhost`, `127.0.0.1`, `::1`) plus the two unspecified addresses
|
|
50
|
-
* (`0.0.0.0`, `::`), which
|
|
51
|
-
* binding to "all interfaces" includes the loopback one; hint
|
|
50
|
+
* (`0.0.0.0`, `::`), which the tunnel's default dial also reaches because
|
|
51
|
+
* binding to "all interfaces" includes the loopback one; hint the tunnel.
|
|
52
52
|
* - `'loopback-other'` — the REST of `127.0.0.0/8` (e.g. `127.0.0.2`). This
|
|
53
53
|
* is loopback-range and unreachable from outside the machine, same as
|
|
54
|
-
* `'loopback'` above, but
|
|
54
|
+
* `'loopback'` above, but the tunnel cannot dial it by name — an app
|
|
55
55
|
* bound only to `127.0.0.2` does not answer on `127.0.0.1`. Hinting
|
|
56
|
-
*
|
|
56
|
+
* the tunnel here would recommend a command that cannot reach the address
|
|
57
57
|
* it was just told about, so this gets no hint (a caller who reads the
|
|
58
|
-
* reason can rebind their dev server onto `127.0.0.1` and get
|
|
58
|
+
* reason can rebind their dev server onto `127.0.0.1` and get the tunnel
|
|
59
59
|
* to work, but that's their call to make, not a claim this code asserts).
|
|
60
|
-
* - `'private'` —
|
|
60
|
+
* - `'private'` — a tunnel can never reach this class even in principle;
|
|
61
61
|
* hint that plainly, with no tunnel suggestion.
|
|
62
62
|
* - `'undecided'` — the address genuinely cannot be decoded safely (currently
|
|
63
63
|
* RFC 8215's `/48` NAT64 local-use range, whose embedded bit position differs
|
package/dist/lib/target-url.js
CHANGED
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
*/
|
|
27
27
|
import * as net from 'node:net';
|
|
28
28
|
import { ApiError } from './errors.js';
|
|
29
|
-
//
|
|
29
|
+
// A local environment's host is EXACTLY `localhost`, `127.0.0.1` or `::1` (mirroring
|
|
30
30
|
// the server's `isLoopbackString`) — not "anything loopback-shaped". This
|
|
31
31
|
// hint is only honest for those three literal hosts (`0.0.0.0` and `::`
|
|
32
32
|
// join them below because binding to the unspecified address also answers
|
|
33
|
-
// on `127.0.0.1`/`::1`, so
|
|
34
|
-
// the rest of `127.0.0.0/8`, which
|
|
33
|
+
// on `127.0.0.1`/`::1`, so the tunnel's default dial reaches it) — NOT for
|
|
34
|
+
// the rest of `127.0.0.0/8`, which the tunnel cannot dial by name at all. See
|
|
35
35
|
// `'loopback-other'` below for that distinction.
|
|
36
36
|
const LOCAL_DEV_RUNTIME_HINT = "This looks like a local-dev target. Save `--url http://localhost:<port>` on an environment, then run `testsprite run <test-id> --env <name>` — it tunnels this machine's loopback address to the test runner (frontend tests only; requires an API key with the `run:tunnel` scope).";
|
|
37
37
|
/**
|
|
@@ -51,12 +51,12 @@ const DEFAULT_TARGET_URL_CALLER = {
|
|
|
51
51
|
// the caller's own machine in general (a LAN or VPN address usually answers)
|
|
52
52
|
// — what is actually true, and all this hint claims, is that TestSprite's
|
|
53
53
|
// execution modes cannot target them: `--target-url` refuses them outright,
|
|
54
|
-
// and
|
|
54
|
+
// and a local environment's tunnel only ever dials `localhost` / `127.0.0.1` / `::1`
|
|
55
55
|
// on THIS machine, never a LAN/VPC address. Embedded IPv4 addresses inherit
|
|
56
56
|
// this hint only after their decoded IPv4 address lands in this class.
|
|
57
57
|
const PRIVATE_NETWORK_HINT = 'This is a private/reserved network address (private, link-local, multicast, or metadata). ' +
|
|
58
|
-
|
|
59
|
-
'reaches localhost, 127.0.0.1, or ::1 on this machine.';
|
|
58
|
+
"TestSprite cannot use it as --target-url, and a local environment's tunnel cannot reach it either — " +
|
|
59
|
+
'a tunnel only reaches localhost, 127.0.0.1, or ::1 on this machine.';
|
|
60
60
|
/**
|
|
61
61
|
* Throws a local `VALIDATION_ERROR` (exit 5) when `rawUrl` is a
|
|
62
62
|
* disallowed target — localhost or a private/reserved literal IP. Also rejects
|
|
@@ -87,7 +87,7 @@ export function assertNotLocal(rawUrl, caller = DEFAULT_TARGET_URL_CALLER) {
|
|
|
87
87
|
const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
|
|
88
88
|
// 'localhost' is a name, not an IP literal, so it sits outside
|
|
89
89
|
// `disallowedIpReason` below (which classifies IPv4/IPv6 address forms).
|
|
90
|
-
// It is also always loopback — the same class
|
|
90
|
+
// It is also always loopback — the same class a tunnel can reach.
|
|
91
91
|
if (host === 'localhost') {
|
|
92
92
|
throw localTargetError(field, 'localhost targets are not allowed', helpCommand, localDevHintFor(hintContext));
|
|
93
93
|
}
|
|
@@ -159,7 +159,7 @@ function disallowedIpv4Reason(address) {
|
|
|
159
159
|
if (address === '0.0.0.0') {
|
|
160
160
|
return { reason: UNSPECIFIED_ADDRESS_REASON, hintKind: 'loopback' };
|
|
161
161
|
}
|
|
162
|
-
// Only the literal 127.0.0.1 is in
|
|
162
|
+
// Only the literal 127.0.0.1 is in the loopback host set a tunnel dials.
|
|
163
163
|
if (ipv4LoopbackBlocklist.check(address, 'ipv4')) {
|
|
164
164
|
return {
|
|
165
165
|
reason: 'loopback addresses are not allowed',
|