@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
|
@@ -3,22 +3,23 @@ import { Command } from 'commander';
|
|
|
3
3
|
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
4
4
|
import { ApiError, CLIError, InterruptError, RequestTimeoutError, localValidationError, } from '../lib/errors.js';
|
|
5
5
|
import { REQUEST_TIMEOUT_DEFAULT_MS, REQUEST_TIMEOUT_MAX_MS, } from '../lib/http.js';
|
|
6
|
+
import { resolveProfileName } from '../lib/config.js';
|
|
6
7
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
7
8
|
import { pollRunUntilTerminal, TimeoutError } from '../lib/poll.js';
|
|
8
9
|
import { emitCiArtifacts, summarizeAcceptedPayload } from '../lib/gh-output.js';
|
|
9
|
-
import { describeConflict, insufficientCreditsConflictError, isAllCreditsRefusal, summarizeConflicts, } from '../lib/conflict-reason.js';
|
|
10
|
+
import { billingConflictLink, describeConflict, insufficientCreditsConflictError, isAllCreditsRefusal, isPausedRefusal, pausedConflictError, summarizeConflicts, } from '../lib/conflict-reason.js';
|
|
10
11
|
import { recordBatchOutcome } from '../lib/telemetry.js';
|
|
11
12
|
import { formatRunProgressLine } from '../lib/run-progress.js';
|
|
12
13
|
import { createTicker } from '../lib/ticker.js';
|
|
13
|
-
import { buildJUnitReport, parseJUnitReportFormat, writeJUnitReportFile, } from '../lib/junit-report.js';
|
|
14
|
+
import { buildJUnitReport, parseJUnitReportFormat, skippedJUnitResultsFromSummary, writeJUnitReportFile, } from '../lib/junit-report.js';
|
|
14
15
|
import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
|
|
15
16
|
import { assertIdempotencyKey } from '../lib/validate.js';
|
|
16
|
-
import { resolveWaitFailure } from '../lib/wait-exit.js';
|
|
17
|
+
import { resolveWaitFailure, waitMemberError } from '../lib/wait-exit.js';
|
|
17
18
|
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
18
|
-
function resolveCommonOptions(command) {
|
|
19
|
+
function resolveCommonOptions(command, env) {
|
|
19
20
|
const g = command.optsWithGlobals();
|
|
20
21
|
return {
|
|
21
|
-
profile: g.profile
|
|
22
|
+
profile: resolveProfileName(g.profile, env),
|
|
22
23
|
output: resolveOutputMode(g.output),
|
|
23
24
|
endpointUrl: g.endpointUrl,
|
|
24
25
|
debug: g.debug ?? false,
|
|
@@ -333,6 +334,11 @@ export async function runTestlistRun(opts, deps = {}) {
|
|
|
333
334
|
if (resp.notFound && resp.notFound.length > 0) {
|
|
334
335
|
stderrFn(`warning: ${resp.notFound.length} --case id(s) not in this list, skipped: ${resp.notFound.join(' ')}`);
|
|
335
336
|
}
|
|
337
|
+
if (resp.accepted.length > 0) {
|
|
338
|
+
const link = billingConflictLink(resp.conflicts, client.resolvedBaseUrl);
|
|
339
|
+
if (link)
|
|
340
|
+
stderrFn(`[advisory] Billing refusal for some tests.${link}`);
|
|
341
|
+
}
|
|
336
342
|
// All-conflict: nothing new dispatched because every targeted case is already
|
|
337
343
|
// in flight → exit 6, for BOTH --wait and non-wait (a --wait over zero accepted
|
|
338
344
|
// would otherwise no-op straight to exit 0). Distinct from the empty/no-match
|
|
@@ -352,7 +358,7 @@ export async function runTestlistRun(opts, deps = {}) {
|
|
|
352
358
|
// into the summary as non-passed rows. The non-wait path never emits CI
|
|
353
359
|
// artifacts, matching the main tail below.
|
|
354
360
|
if (opts.wait) {
|
|
355
|
-
|
|
361
|
+
const summary = summarizeAcceptedPayload(JSON.stringify({
|
|
356
362
|
accepted: [],
|
|
357
363
|
conflicts: resp.conflicts,
|
|
358
364
|
deferred: resp.deferred,
|
|
@@ -361,7 +367,16 @@ export async function runTestlistRun(opts, deps = {}) {
|
|
|
361
367
|
// CI summary must report the whole requested set (same reason the
|
|
362
368
|
// main --wait envelope threads it). Undefined ⇒ JSON.stringify drops it.
|
|
363
369
|
notFound: resp.notFound,
|
|
364
|
-
}), { notFoundNote: 'not a member of this list (not dispatched)' })
|
|
370
|
+
}), { notFoundNote: 'not a member of this list (not dispatched)' });
|
|
371
|
+
if (opts.report === 'junit' && opts.reportFile !== undefined) {
|
|
372
|
+
const suiteName = opts.reportSuiteName ?? `testsprite:testlist:${opts.listId}`;
|
|
373
|
+
await writeJUnitReportFile(opts.reportFile, buildJUnitReport({
|
|
374
|
+
suiteName,
|
|
375
|
+
classname: `testlist:${opts.listId}`,
|
|
376
|
+
results: skippedJUnitResultsFromSummary(summary),
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
emitCiArtifacts(summary, opts, {
|
|
365
380
|
env: deps.env ?? process.env,
|
|
366
381
|
stdout: deps.stdout ?? ((line) => process.stdout.write(`${line}\n`)),
|
|
367
382
|
stderr: stderrFn,
|
|
@@ -373,16 +388,24 @@ export async function runTestlistRun(opts, deps = {}) {
|
|
|
373
388
|
if (isAllCreditsRefusal(resp)) {
|
|
374
389
|
throw insufficientCreditsConflictError(resp.conflicts, client.resolvedBaseUrl);
|
|
375
390
|
}
|
|
391
|
+
if (isPausedRefusal(resp)) {
|
|
392
|
+
throw pausedConflictError(resp.conflicts, client.resolvedBaseUrl);
|
|
393
|
+
}
|
|
376
394
|
const pollIds = resp.conflicts
|
|
377
395
|
.map(c => c.currentRunId)
|
|
378
396
|
.filter((id) => Boolean(id));
|
|
379
397
|
// Name the causes instead of blanket "already in flight" — a list pinned to
|
|
380
398
|
// a local env or a view-only project is not something to poll. The poll hint
|
|
381
|
-
// is emitted only for the cases that actually have an in-flight run.
|
|
399
|
+
// is emitted only for the cases that actually have an in-flight run. A
|
|
400
|
+
// paused (`billing_hold`) / insufficient_credits conflict riding along a NON-uniform
|
|
401
|
+
// mix (the uniform cases already threw above) still needs its upgrade
|
|
402
|
+
// link — `accepted.length` is 0 in this whole branch, so the advisory
|
|
403
|
+
// printed earlier (guarded on `accepted.length > 0`) never showed it.
|
|
382
404
|
throw new CLIError(`Nothing dispatched — ${resp.conflicts.length} conflict(s): ${summarizeConflicts(resp.conflicts)}` +
|
|
383
405
|
(pollIds.length > 0
|
|
384
406
|
? `. Poll in-flight runs: testsprite test wait ${pollIds.join(' ')}`
|
|
385
|
-
: '')
|
|
407
|
+
: '') +
|
|
408
|
+
billingConflictLink(resp.conflicts, client.resolvedBaseUrl), 6);
|
|
386
409
|
}
|
|
387
410
|
if (!opts.wait) {
|
|
388
411
|
// Print what dispatched, or the empty/no-match reason. Exit 0.
|
|
@@ -486,7 +509,7 @@ export async function runTestlistRun(opts, deps = {}) {
|
|
|
486
509
|
testId: entry.testId,
|
|
487
510
|
runId: entry.runId,
|
|
488
511
|
status: 'error',
|
|
489
|
-
error:
|
|
512
|
+
error: waitMemberError(err),
|
|
490
513
|
};
|
|
491
514
|
}
|
|
492
515
|
throw err;
|
|
@@ -546,7 +569,14 @@ export async function runTestlistRun(opts, deps = {}) {
|
|
|
546
569
|
// Multi-project list: name the suite/classname by the LIST, not one project
|
|
547
570
|
// (`resolveBatchReportProjectId`'s single-project assumption doesn't hold).
|
|
548
571
|
const suiteName = opts.reportSuiteName ?? `testsprite:testlist:${opts.listId}`;
|
|
549
|
-
const
|
|
572
|
+
const summary = summarizeAcceptedPayload(JSON.stringify(jsonPayload), {
|
|
573
|
+
notFoundNote: 'not a member of this list (not dispatched)',
|
|
574
|
+
});
|
|
575
|
+
const xml = buildJUnitReport({
|
|
576
|
+
suiteName,
|
|
577
|
+
classname: `testlist:${opts.listId}`,
|
|
578
|
+
results: [...results, ...skippedJUnitResultsFromSummary(summary)],
|
|
579
|
+
});
|
|
550
580
|
await writeJUnitReportFile(opts.reportFile, xml);
|
|
551
581
|
}
|
|
552
582
|
out.print(jsonPayload, () => results.map(r => `${r.runId} ${r.status}`).join('\n'));
|
|
@@ -658,7 +688,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
658
688
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
659
689
|
.action(async (cmdOpts, command) => {
|
|
660
690
|
await runTestlistList({
|
|
661
|
-
...resolveCommonOptions(command),
|
|
691
|
+
...resolveCommonOptions(command, deps.env),
|
|
662
692
|
columns: cmdOpts.columns,
|
|
663
693
|
noHeader: cmdOpts.header === false,
|
|
664
694
|
}, deps);
|
|
@@ -668,7 +698,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
668
698
|
.description('Get a test list with its cases')
|
|
669
699
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
670
700
|
.action(async (listId, _cmdOpts, command) => {
|
|
671
|
-
await runTestlistGet({ ...resolveCommonOptions(command), listId }, deps);
|
|
701
|
+
await runTestlistGet({ ...resolveCommonOptions(command, deps.env), listId }, deps);
|
|
672
702
|
});
|
|
673
703
|
testlist
|
|
674
704
|
.command('create')
|
|
@@ -679,7 +709,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
679
709
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
680
710
|
.action(async (cmdOpts, command) => {
|
|
681
711
|
await runTestlistCreate({
|
|
682
|
-
...resolveCommonOptions(command),
|
|
712
|
+
...resolveCommonOptions(command, deps.env),
|
|
683
713
|
name: cmdOpts.name,
|
|
684
714
|
projectEnv: cmdOpts.projectEnv,
|
|
685
715
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
@@ -695,7 +725,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
695
725
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
696
726
|
.action(async (listId, cmdOpts, command) => {
|
|
697
727
|
await runTestlistUpdate({
|
|
698
|
-
...resolveCommonOptions(command),
|
|
728
|
+
...resolveCommonOptions(command, deps.env),
|
|
699
729
|
listId,
|
|
700
730
|
name: cmdOpts.name,
|
|
701
731
|
projectEnv: cmdOpts.projectEnv,
|
|
@@ -711,7 +741,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
711
741
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
712
742
|
.action(async (listId, cmdOpts, command) => {
|
|
713
743
|
await runTestlistDelete({
|
|
714
|
-
...resolveCommonOptions(command),
|
|
744
|
+
...resolveCommonOptions(command, deps.env),
|
|
715
745
|
listId,
|
|
716
746
|
confirm: cmdOpts.confirm,
|
|
717
747
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
@@ -724,7 +754,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
724
754
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
725
755
|
.action(async (listId, testIds, cmdOpts, command) => {
|
|
726
756
|
await runTestlistAdd({
|
|
727
|
-
...resolveCommonOptions(command),
|
|
757
|
+
...resolveCommonOptions(command, deps.env),
|
|
728
758
|
listId,
|
|
729
759
|
testIds,
|
|
730
760
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
@@ -737,7 +767,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
737
767
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
738
768
|
.action(async (listId, testIds, cmdOpts, command) => {
|
|
739
769
|
await runTestlistRemove({
|
|
740
|
-
...resolveCommonOptions(command),
|
|
770
|
+
...resolveCommonOptions(command, deps.env),
|
|
741
771
|
listId,
|
|
742
772
|
testIds,
|
|
743
773
|
idempotencyKey: cmdOpts.idempotencyKey,
|
|
@@ -760,7 +790,7 @@ export function createTestListCommand(deps = {}) {
|
|
|
760
790
|
.action(async (listId, cmdOpts, command) => {
|
|
761
791
|
const wait = cmdOpts.wait === true;
|
|
762
792
|
await runTestlistRun({
|
|
763
|
-
...resolveCommonOptions(command),
|
|
793
|
+
...resolveCommonOptions(command, deps.env),
|
|
764
794
|
listId,
|
|
765
795
|
cases: cmdOpts.case,
|
|
766
796
|
wait,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `testsprite tunnel start | status | stop
|
|
2
|
+
* `testsprite tunnel start | list | status | stop`.
|
|
3
3
|
*
|
|
4
4
|
* The out-of-band primitive under `test run --local`, which is sugar over it.
|
|
5
5
|
* Two things it buys that the sugar cannot:
|
|
@@ -22,7 +22,7 @@ import { Command } from 'commander';
|
|
|
22
22
|
import type { CommonOptions } from '../lib/client-factory.js';
|
|
23
23
|
import { type ShutdownHandle } from '../lib/interrupt.js';
|
|
24
24
|
import { type TunnelClientHandle } from '../lib/tunnel-session.js';
|
|
25
|
-
import type { TunnelStatusResponse } from '../lib/tunnel.types.js';
|
|
25
|
+
import type { TunnelListResponse, TunnelStatusResponse } from '../lib/tunnel.types.js';
|
|
26
26
|
import { type TunnelClientOptions } from '../vendor/tunnel-client/index.js';
|
|
27
27
|
export interface TunnelDeps {
|
|
28
28
|
env?: NodeJS.ProcessEnv;
|
|
@@ -41,6 +41,28 @@ export interface TunnelStartOptions extends CommonOptions {
|
|
|
41
41
|
export interface TunnelClientIdOptions extends CommonOptions {
|
|
42
42
|
clientId: string;
|
|
43
43
|
}
|
|
44
|
+
export interface TunnelStopOptions extends CommonOptions {
|
|
45
|
+
clientId?: string;
|
|
46
|
+
all?: boolean;
|
|
47
|
+
confirm?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface TunnelStopResult {
|
|
50
|
+
clientId: string;
|
|
51
|
+
stopped: boolean;
|
|
52
|
+
error?: {
|
|
53
|
+
code: string;
|
|
54
|
+
message: string;
|
|
55
|
+
exitCode: number;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface TunnelStopSummary {
|
|
59
|
+
results: TunnelStopResult[];
|
|
60
|
+
summary: {
|
|
61
|
+
total: number;
|
|
62
|
+
stopped: number;
|
|
63
|
+
failed: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
44
66
|
/**
|
|
45
67
|
* Open a tunnel and hold it until the command is stopped.
|
|
46
68
|
*
|
|
@@ -60,6 +82,7 @@ export declare function runTunnelStart(opts: TunnelStartOptions, deps?: TunnelDe
|
|
|
60
82
|
* defect backend-v2.0 #1068 fixed on the server side of this same question.
|
|
61
83
|
*/
|
|
62
84
|
export declare function runTunnelStatus(opts: TunnelClientIdOptions, deps?: TunnelDeps): Promise<TunnelStatusResponse>;
|
|
85
|
+
export declare function runTunnelList(opts: CommonOptions, deps?: TunnelDeps): Promise<TunnelListResponse>;
|
|
63
86
|
/**
|
|
64
87
|
* Destroy a binding. Idempotent by contract — deleting an unknown or
|
|
65
88
|
* already-deleted binding is a success, because the requested end state holds.
|
|
@@ -68,5 +91,5 @@ export declare function runTunnelStatus(opts: TunnelClientIdOptions, deps?: Tunn
|
|
|
68
91
|
* removes the client from the tunnel server. A running `tunnel start`
|
|
69
92
|
* observes the revocation on its next status check and exits.
|
|
70
93
|
*/
|
|
71
|
-
export declare function runTunnelStop(opts:
|
|
94
|
+
export declare function runTunnelStop(opts: TunnelStopOptions, deps?: TunnelDeps): Promise<void>;
|
|
72
95
|
export declare function createTunnelCommand(deps?: TunnelDeps): Command;
|
package/dist/commands/tunnel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `testsprite tunnel start | status | stop
|
|
2
|
+
* `testsprite tunnel start | list | status | stop`.
|
|
3
3
|
*
|
|
4
4
|
* The out-of-band primitive under `test run --local`, which is sugar over it.
|
|
5
5
|
* Two things it buys that the sugar cannot:
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import { Command } from 'commander';
|
|
22
22
|
import * as v from 'valibot';
|
|
23
|
+
import { resolveProfileName } from '../lib/config.js';
|
|
23
24
|
import { createHttpClientFactory, emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, resolveRequestTimeoutMs, } from '../lib/client-factory.js';
|
|
24
|
-
import { ApiError, RequestTimeoutError } from '../lib/errors.js';
|
|
25
|
+
import { ApiError, CLIError, InterruptError, RequestTimeoutError } from '../lib/errors.js';
|
|
25
26
|
import { globalShutdown } from '../lib/interrupt.js';
|
|
26
27
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
28
|
+
import { renderTextTable } from '../lib/text-table.js';
|
|
27
29
|
import { formatDataPlaneUnreachableMessage, formatDataPlaneUnreachableNextAction, openTunnelSession, } from '../lib/tunnel-session.js';
|
|
28
30
|
import { TunnelClient } from '../vendor/tunnel-client/index.js';
|
|
29
31
|
const TUNNEL_CLIENT_ID_SCHEMA = v.pipe(v.string(), v.uuid());
|
|
@@ -50,7 +52,7 @@ function makeClient(opts, deps, shutdownSignal = (deps.shutdown ?? globalShutdow
|
|
|
50
52
|
return makeHttpClient(opts, {
|
|
51
53
|
env: deps.env,
|
|
52
54
|
credentialsPath: deps.credentialsPath,
|
|
53
|
-
fetchImpl: deps.fetchImpl,
|
|
55
|
+
fetchImpl: opts.dryRun ? undefined : deps.fetchImpl,
|
|
54
56
|
stderr: deps.stderr,
|
|
55
57
|
shutdownSignal,
|
|
56
58
|
});
|
|
@@ -228,6 +230,7 @@ export async function runTunnelStart(opts, deps = {}) {
|
|
|
228
230
|
log: stderr,
|
|
229
231
|
logLevel: opts.debug ? 'debug' : opts.verbose ? 'info' : 'error',
|
|
230
232
|
...(opts.ttlSeconds !== undefined ? { ttlSeconds: opts.ttlSeconds } : {}),
|
|
233
|
+
onMinted: minted => stderr(`Minted tunnel client ${minted.clientId} (expires ${minted.expiresAt}); connecting…`),
|
|
231
234
|
onFatal: (reason, message) => {
|
|
232
235
|
fatal = true;
|
|
233
236
|
fatalReason = reason;
|
|
@@ -363,6 +366,66 @@ function renderStatus(status) {
|
|
|
363
366
|
}
|
|
364
367
|
return lines.join('\n');
|
|
365
368
|
}
|
|
369
|
+
async function listTunnelsForAccount(opts, deps) {
|
|
370
|
+
try {
|
|
371
|
+
return await makeClient(opts, deps).listTunnels();
|
|
372
|
+
}
|
|
373
|
+
catch (err) {
|
|
374
|
+
if (err instanceof ApiError && err.httpStatus === 404) {
|
|
375
|
+
throw ApiError.fromEnvelope({
|
|
376
|
+
error: {
|
|
377
|
+
code: 'NOT_FOUND',
|
|
378
|
+
message: 'This TestSprite server cannot list tunnels yet.',
|
|
379
|
+
nextAction: 'Stop a tunnel you know the id of with `testsprite tunnel stop <client-id>`, or wait for it to expire.',
|
|
380
|
+
requestId: err.requestId,
|
|
381
|
+
details: err.details,
|
|
382
|
+
},
|
|
383
|
+
}, 404);
|
|
384
|
+
}
|
|
385
|
+
throw err;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
export async function runTunnelList(opts, deps = {}) {
|
|
389
|
+
const response = await listTunnelsForAccount(opts, deps);
|
|
390
|
+
makeOutput(opts.output, deps).print(response, data => renderTunnelList(data));
|
|
391
|
+
return response;
|
|
392
|
+
}
|
|
393
|
+
function renderTunnelList(response) {
|
|
394
|
+
if (response.tunnels.length === 0)
|
|
395
|
+
return 'No live tunnels.';
|
|
396
|
+
const columns = [
|
|
397
|
+
{
|
|
398
|
+
header: 'CLIENT ID',
|
|
399
|
+
width: (rows) => Math.max(9, ...rows.map(item => item.clientId.length)),
|
|
400
|
+
render: (item) => item.clientId,
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
header: 'STATUS',
|
|
404
|
+
width: (rows) => Math.max(6, ...rows.map(item => item.status.length)),
|
|
405
|
+
render: (item) => item.status,
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
header: 'CREATED',
|
|
409
|
+
width: (rows) => Math.max(7, ...rows.map(item => (item.createdAt ?? '-').length)),
|
|
410
|
+
render: (item) => item.createdAt ?? '-',
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
header: 'EXPIRES',
|
|
414
|
+
width: (rows) => Math.max(7, ...rows.map(item => item.expiresAt.length)),
|
|
415
|
+
render: (item) => item.expiresAt,
|
|
416
|
+
},
|
|
417
|
+
];
|
|
418
|
+
return [
|
|
419
|
+
renderTextTable(response.tunnels, columns),
|
|
420
|
+
'hint Stop one: testsprite tunnel stop <client-id>',
|
|
421
|
+
'hint Stop all of them: testsprite tunnel stop --all --confirm',
|
|
422
|
+
...(response.tunnels.some(item => item.status === 'unknown')
|
|
423
|
+
? [
|
|
424
|
+
'note "unknown" means TestSprite could not check that connection just now; the tunnel may still be up.',
|
|
425
|
+
]
|
|
426
|
+
: []),
|
|
427
|
+
].join('\n');
|
|
428
|
+
}
|
|
366
429
|
/**
|
|
367
430
|
* Destroy a binding. Idempotent by contract — deleting an unknown or
|
|
368
431
|
* already-deleted binding is a success, because the requested end state holds.
|
|
@@ -372,6 +435,109 @@ function renderStatus(status) {
|
|
|
372
435
|
* observes the revocation on its next status check and exits.
|
|
373
436
|
*/
|
|
374
437
|
export async function runTunnelStop(opts, deps = {}) {
|
|
438
|
+
if (opts.clientId !== undefined && opts.all) {
|
|
439
|
+
throw ApiError.fromEnvelope({
|
|
440
|
+
error: {
|
|
441
|
+
code: 'VALIDATION_ERROR',
|
|
442
|
+
message: 'Pass either a <client-id> or --all, not both.',
|
|
443
|
+
nextAction: 'Choose one tunnel to stop, or use --all --confirm.',
|
|
444
|
+
requestId: 'local',
|
|
445
|
+
details: { field: 'all', reason: 'mutually exclusive with clientId' },
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (opts.confirm && !opts.all) {
|
|
450
|
+
throw ApiError.fromEnvelope({
|
|
451
|
+
error: {
|
|
452
|
+
code: 'VALIDATION_ERROR',
|
|
453
|
+
message: '--confirm only applies with --all.',
|
|
454
|
+
nextAction: 'Remove --confirm, or use --all --confirm.',
|
|
455
|
+
requestId: 'local',
|
|
456
|
+
details: { field: 'confirm', reason: 'requires --all' },
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
if (opts.clientId === undefined && !opts.all) {
|
|
461
|
+
throw ApiError.fromEnvelope({
|
|
462
|
+
error: {
|
|
463
|
+
code: 'VALIDATION_ERROR',
|
|
464
|
+
message: 'provide a <client-id>, or use --all --confirm to stop every tunnel on this account',
|
|
465
|
+
nextAction: 'Run testsprite tunnel list to see your tunnel client ids.',
|
|
466
|
+
requestId: 'local',
|
|
467
|
+
details: { field: 'clientId', reason: 'required unless --all is set' },
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
if (opts.all) {
|
|
472
|
+
if (!opts.confirm && !opts.dryRun) {
|
|
473
|
+
throw ApiError.fromEnvelope({
|
|
474
|
+
error: {
|
|
475
|
+
code: 'VALIDATION_ERROR',
|
|
476
|
+
message: 'Refusing to stop every tunnel without --confirm.',
|
|
477
|
+
nextAction: 'This revokes every live tunnel on this account, including ones another terminal or a CI job is using — their runs lose their route to your machine. Re-run with --confirm. To see what would be stopped: testsprite tunnel list.',
|
|
478
|
+
requestId: 'local',
|
|
479
|
+
details: { field: 'confirm', reason: 'required for destructive operation' },
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (opts.dryRun) {
|
|
484
|
+
stderrOf(deps)("[dry-run] WARNING: the preview below uses sample data and does NOT reflect the real tunnels on this account. Run 'testsprite tunnel list' to see them.");
|
|
485
|
+
}
|
|
486
|
+
const response = await listTunnelsForAccount(opts, deps);
|
|
487
|
+
const out = makeOutput(opts.output, deps);
|
|
488
|
+
if (opts.dryRun) {
|
|
489
|
+
const requests = response.tunnels.map(item => ({
|
|
490
|
+
method: 'DELETE',
|
|
491
|
+
path: `/api/cli/v1/tunnel/${item.clientId}`,
|
|
492
|
+
}));
|
|
493
|
+
out.print({ requests }, () => requests.map(item => `${item.method} ${item.path}`).join('\n'));
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (response.tunnels.length === 0) {
|
|
497
|
+
out.print({ results: [], summary: { total: 0, stopped: 0, failed: 0 } }, () => 'No live tunnels — nothing to stop.');
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const client = makeClient(opts, deps);
|
|
501
|
+
const results = [];
|
|
502
|
+
for (const item of response.tunnels) {
|
|
503
|
+
try {
|
|
504
|
+
// Sequential and one id at a time, with the HTTP layer's normal retries:
|
|
505
|
+
// the delete is idempotent, so a transient failure is worth retrying.
|
|
506
|
+
await client.deleteTunnel(item.clientId);
|
|
507
|
+
results.push({ clientId: item.clientId, stopped: true });
|
|
508
|
+
}
|
|
509
|
+
catch (err) {
|
|
510
|
+
if (err instanceof InterruptError)
|
|
511
|
+
throw err;
|
|
512
|
+
const failure = err instanceof CLIError ? err : new CLIError(String(err), 1);
|
|
513
|
+
results.push({
|
|
514
|
+
clientId: item.clientId,
|
|
515
|
+
stopped: false,
|
|
516
|
+
error: {
|
|
517
|
+
code: failure.code,
|
|
518
|
+
message: failure.message,
|
|
519
|
+
exitCode: failure.exitCode,
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
const stopped = results.filter(result => result.stopped).length;
|
|
525
|
+
const bulk = {
|
|
526
|
+
results,
|
|
527
|
+
summary: { total: results.length, stopped, failed: results.length - stopped },
|
|
528
|
+
};
|
|
529
|
+
out.print(bulk, () => [
|
|
530
|
+
...results.map(result => result.stopped
|
|
531
|
+
? `stopped ${result.clientId}`
|
|
532
|
+
: `failed ${result.clientId} ${result.error?.message}`),
|
|
533
|
+
`Stopped ${stopped} of ${results.length} tunnels.`,
|
|
534
|
+
'hint A running `tunnel start` notices a revoked credential within ~15 s and exits.',
|
|
535
|
+
].join('\n'));
|
|
536
|
+
if (bulk.summary.failed > 0) {
|
|
537
|
+
throw new CLIError(`${bulk.summary.failed} tunnel stop${bulk.summary.failed === 1 ? '' : 's'} failed. See results for details.`, 1);
|
|
538
|
+
}
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
375
541
|
assertTunnelClientId(opts.clientId);
|
|
376
542
|
const out = makeOutput(opts.output, deps);
|
|
377
543
|
if (opts.dryRun) {
|
|
@@ -394,8 +560,10 @@ export function createTunnelCommand(deps = {}) {
|
|
|
394
560
|
'\nExamples:\n' +
|
|
395
561
|
' testsprite tunnel start # hold a tunnel open (Ctrl-C to stop)\n' +
|
|
396
562
|
' testsprite test run <id> --local 5173 --tunnel-client <id>\n' +
|
|
563
|
+
' testsprite tunnel list\n' +
|
|
397
564
|
' testsprite tunnel status <id>\n' +
|
|
398
|
-
' testsprite tunnel stop <id>\n'
|
|
565
|
+
' testsprite tunnel stop <id>\n' +
|
|
566
|
+
' testsprite tunnel stop --all --confirm\n');
|
|
399
567
|
tunnel
|
|
400
568
|
.command('start')
|
|
401
569
|
// One-line description: Commander prints it in the parent's command list,
|
|
@@ -405,7 +573,8 @@ export function createTunnelCommand(deps = {}) {
|
|
|
405
573
|
.option('--ttl <seconds>', 'requested lifetime of the tunnel credential (60–28800). The server clamps this, and the ' +
|
|
406
574
|
'credential is deleted when the command exits regardless — the lifetime only matters if ' +
|
|
407
575
|
'this process is killed without cleaning up.')
|
|
408
|
-
.addHelpText('after', '\nPrints the client id to
|
|
576
|
+
.addHelpText('after', '\nPrints the client id to stderr as soon as it is minted, before connecting; pass it\n' +
|
|
577
|
+
'to `test run --local <port> --tunnel-client <id>`.\n' +
|
|
409
578
|
'\nExit codes:\n' +
|
|
410
579
|
' 0 you stopped it (Ctrl-C is the normal way to end this command)\n' +
|
|
411
580
|
' 3 auth error — the key needs the `run:tunnel` scope; mint a new key\n' +
|
|
@@ -415,10 +584,23 @@ export function createTunnelCommand(deps = {}) {
|
|
|
415
584
|
.action(async (cmdOpts, command) => {
|
|
416
585
|
const ttlSeconds = parseTtl(cmdOpts.ttl);
|
|
417
586
|
await runTunnelStart({
|
|
418
|
-
...resolveCommonOptions(command),
|
|
587
|
+
...resolveCommonOptions(command, deps.env),
|
|
419
588
|
...(ttlSeconds !== undefined ? { ttlSeconds } : {}),
|
|
420
589
|
}, deps);
|
|
421
590
|
});
|
|
591
|
+
tunnel
|
|
592
|
+
.command('list')
|
|
593
|
+
.description('List live tunnel bindings for this account')
|
|
594
|
+
.addHelpText('after', '\nShows each tunnel client id, connection status, creation time and expiry.\n' +
|
|
595
|
+
'\nExit codes:\n' +
|
|
596
|
+
' 0 listed (possibly empty)\n' +
|
|
597
|
+
' 3 auth error — the key needs the `run:tunnel` scope\n' +
|
|
598
|
+
' 4 server too old to list tunnels\n' +
|
|
599
|
+
' 10 could not reach TestSprite\n')
|
|
600
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
601
|
+
.action(async (_cmdOpts, command) => {
|
|
602
|
+
await runTunnelList(resolveCommonOptions(command, deps.env), deps);
|
|
603
|
+
});
|
|
422
604
|
tunnel
|
|
423
605
|
.command('status <client-id>')
|
|
424
606
|
.description('Report whether a tunnel client of yours is connected')
|
|
@@ -430,23 +612,38 @@ export function createTunnelCommand(deps = {}) {
|
|
|
430
612
|
' 10 could not reach TestSprite to ask\n')
|
|
431
613
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
432
614
|
.action(async (clientId, _cmdOpts, command) => {
|
|
433
|
-
await runTunnelStatus({ ...resolveCommonOptions(command), clientId }, deps);
|
|
615
|
+
await runTunnelStatus({ ...resolveCommonOptions(command, deps.env), clientId }, deps);
|
|
434
616
|
});
|
|
435
617
|
tunnel
|
|
436
|
-
.command('stop
|
|
437
|
-
.description('Destroy
|
|
618
|
+
.command('stop [client-id]')
|
|
619
|
+
.description('Destroy one tunnel credential or stop every live tunnel')
|
|
620
|
+
.option('--all', 'stop every live tunnel on this account', false)
|
|
621
|
+
.option('--confirm', 'required with --all for this destructive operation', false)
|
|
438
622
|
.addHelpText('after', '\nStopping one that is already gone succeeds. Revoking the credential\n' +
|
|
439
|
-
'also makes a running `tunnel start` exit within ~15 s.\n'
|
|
623
|
+
'also makes a running `tunnel start` exit within ~15 s.\n' +
|
|
624
|
+
'Stopping all requires --confirm; --dry-run previews sample ids without it.\n' +
|
|
625
|
+
'\nExit codes:\n' +
|
|
626
|
+
' 0 stopped (or already absent), including an empty --all result\n' +
|
|
627
|
+
' 1 at least one tunnel could not be stopped\n' +
|
|
628
|
+
' 3 auth error — the key needs the `run:tunnel` scope\n' +
|
|
629
|
+
' 4 server too old to list tunnels (with --all)\n' +
|
|
630
|
+
' 5 invalid arguments or --all without --confirm\n' +
|
|
631
|
+
' 10 could not reach TestSprite\n')
|
|
440
632
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
441
|
-
.action(async (clientId,
|
|
442
|
-
await runTunnelStop({
|
|
633
|
+
.action(async (clientId, cmdOpts, command) => {
|
|
634
|
+
await runTunnelStop({
|
|
635
|
+
...resolveCommonOptions(command, deps.env),
|
|
636
|
+
clientId,
|
|
637
|
+
all: cmdOpts.all,
|
|
638
|
+
confirm: cmdOpts.confirm,
|
|
639
|
+
}, deps);
|
|
443
640
|
});
|
|
444
641
|
return tunnel;
|
|
445
642
|
}
|
|
446
|
-
function resolveCommonOptions(command) {
|
|
643
|
+
function resolveCommonOptions(command, env) {
|
|
447
644
|
const globals = command.optsWithGlobals();
|
|
448
645
|
return {
|
|
449
|
-
profile: globals.profile
|
|
646
|
+
profile: resolveProfileName(globals.profile, env),
|
|
450
647
|
output: resolveOutputMode(globals.output),
|
|
451
648
|
endpointUrl: globals.endpointUrl,
|
|
452
649
|
debug: globals.debug ?? false,
|
package/dist/commands/usage.d.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* has no server-side source at all today).
|
|
12
12
|
*/
|
|
13
13
|
import { Command } from 'commander';
|
|
14
|
+
import { type WorkspaceStatus } from '../lib/workspace-status.js';
|
|
14
15
|
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
15
16
|
import type { FetchImpl } from '../lib/http.js';
|
|
16
17
|
import type { CliOrgBinding, CliOrgSummary } from '../lib/org-render.js';
|
|
@@ -80,6 +81,8 @@ export interface ActiveOrg {
|
|
|
80
81
|
/** Monthly per-seat credit allowance for the org's plan. */
|
|
81
82
|
includedCredits: number;
|
|
82
83
|
seats: number;
|
|
84
|
+
/** Billing standing (paused / pending / ok). Absent on an older backend. */
|
|
85
|
+
workspace?: WorkspaceStatus;
|
|
83
86
|
}
|
|
84
87
|
export interface UsageDeps {
|
|
85
88
|
env?: NodeJS.ProcessEnv;
|
package/dist/commands/usage.js
CHANGED
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
* has no server-side source at all today).
|
|
12
12
|
*/
|
|
13
13
|
import { Command } from 'commander';
|
|
14
|
+
import { formatWorkspaceStatus } from '../lib/workspace-status.js';
|
|
14
15
|
import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
15
|
-
import { loadConfig } from '../lib/config.js';
|
|
16
|
+
import { loadConfig, resolveProfileName } from '../lib/config.js';
|
|
16
17
|
import { resolvePortalBase } from '../lib/facade.js';
|
|
17
18
|
import { formatOrgBinding, formatOrgsSummary } from '../lib/org-render.js';
|
|
18
19
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
20
|
+
import { USAGE_RESPONSE_SCHEMA } from '../lib/response-schemas.js';
|
|
19
21
|
/** Dry-run canned response — matches what the real /me + User lookup would return. */
|
|
20
22
|
export const DRY_RUN_USAGE_SAMPLE = {
|
|
21
23
|
userId: '11111111-1111-4111-8111-111111111111',
|
|
@@ -72,7 +74,7 @@ export async function runUsage(opts, deps = {}) {
|
|
|
72
74
|
// /me is the only available source of credits/plan today. If the backend
|
|
73
75
|
// adds a dedicated /usage endpoint later, this single get call is where
|
|
74
76
|
// it would be swapped in — no other code change needed in the CLI.
|
|
75
|
-
const me = await client.get('/me');
|
|
77
|
+
const me = await client.get('/me', { schema: USAGE_RESPONSE_SCHEMA });
|
|
76
78
|
out.print(me, data => renderUsage(data, portalBase));
|
|
77
79
|
// In text mode, emit a note when NO balance was shown at all — neither the
|
|
78
80
|
// legacy per-user `credits` nor an org wallet. A V3-routed org account can
|
|
@@ -146,6 +148,11 @@ function renderUsage(u, portalBase) {
|
|
|
146
148
|
lines.push('--- organization ---');
|
|
147
149
|
lines.push(`org: ${org.name} (${org.role})`);
|
|
148
150
|
lines.push(`plan: ${org.plan}`);
|
|
151
|
+
// A paused workspace cannot spend this balance at all; a payment-pending
|
|
152
|
+
// one keeps spending but gets no refill. Both are worth a line here.
|
|
153
|
+
const standing = formatWorkspaceStatus(org.workspace);
|
|
154
|
+
if (standing)
|
|
155
|
+
lines.push(`state: ${standing}`);
|
|
149
156
|
// Labeled `balance:` (not `credits:`) — `--output json` exposes the
|
|
150
157
|
// legacy per-user number under `.credits`, and giving the org wallet the
|
|
151
158
|
// same label in text mode would make one word mean two different values.
|
|
@@ -250,14 +257,14 @@ export function createUsageCommand(deps = {}) {
|
|
|
250
257
|
' organization billing settings (ask an org admin) if this key is\n' +
|
|
251
258
|
' organization-bound.')
|
|
252
259
|
.action(async (_cmdOpts, command) => {
|
|
253
|
-
await runUsage(resolveCommonOptions(command), deps);
|
|
260
|
+
await runUsage(resolveCommonOptions(command, deps.env), deps);
|
|
254
261
|
});
|
|
255
262
|
return cmd;
|
|
256
263
|
}
|
|
257
|
-
function resolveCommonOptions(command) {
|
|
264
|
+
function resolveCommonOptions(command, env) {
|
|
258
265
|
const globals = command.optsWithGlobals();
|
|
259
266
|
return {
|
|
260
|
-
profile: globals.profile
|
|
267
|
+
profile: resolveProfileName(globals.profile, env),
|
|
261
268
|
output: resolveOutputMode(globals.output),
|
|
262
269
|
endpointUrl: globals.endpointUrl,
|
|
263
270
|
debug: globals.debug ?? false,
|