@testsprite/testsprite-cli 0.16.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 +52 -147
- package/dist/commands/agent.d.ts +12 -4
- package/dist/commands/agent.js +48 -63
- package/dist/commands/auth.d.ts +6 -10
- package/dist/commands/auth.js +40 -56
- package/dist/commands/ci.d.ts +23 -100
- package/dist/commands/ci.js +293 -487
- package/dist/commands/conversation.d.ts +27 -0
- package/dist/commands/conversation.js +741 -0
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.js +129 -34
- package/dist/commands/init.d.ts +4 -45
- package/dist/commands/init.js +108 -66
- package/dist/commands/project-env.d.ts +62 -2
- package/dist/commands/project-env.js +434 -43
- package/dist/commands/project-sign-in.d.ts +0 -48
- package/dist/commands/project-sign-in.js +1 -229
- package/dist/commands/project.d.ts +19 -186
- package/dist/commands/project.js +108 -926
- package/dist/commands/result.d.ts +10 -0
- package/dist/commands/result.js +216 -0
- package/dist/commands/schedule.d.ts +0 -29
- package/dist/commands/schedule.js +28 -87
- package/dist/commands/test.d.ts +301 -1838
- package/dist/commands/test.js +1880 -13917
- package/dist/commands/testlist.d.ts +130 -5
- package/dist/commands/testlist.js +300 -342
- package/dist/commands/tunnel.d.ts +3 -3
- package/dist/commands/tunnel.js +23 -20
- package/dist/commands/usage.d.ts +12 -45
- package/dist/commands/usage.js +50 -131
- package/dist/index.js +191 -110
- package/dist/lib/agent-detect.js +9 -5
- package/dist/lib/agent-targets.d.ts +21 -2
- package/dist/lib/agent-targets.js +88 -11
- package/dist/lib/args.d.ts +13 -0
- package/dist/lib/args.js +49 -0
- package/dist/lib/basic-auth.d.ts +3 -0
- package/dist/lib/basic-auth.js +15 -0
- package/dist/lib/billing-refusal.js +4 -3
- package/dist/lib/ci-linkage.d.ts +4 -82
- package/dist/lib/ci-linkage.js +4 -157
- package/dist/lib/ci-run.js +1 -1
- package/dist/lib/client-factory.d.ts +12 -4
- package/dist/lib/client-factory.js +41 -30
- package/dist/lib/commit-signal.d.ts +65 -0
- package/dist/lib/commit-signal.js +305 -0
- package/dist/lib/concurrency-limiter.d.ts +6 -0
- package/dist/lib/concurrency-limiter.js +29 -0
- package/dist/lib/config.js +10 -5
- package/dist/lib/conflict-reason.d.ts +9 -3
- package/dist/lib/conflict-reason.js +6 -3
- package/dist/lib/conversation/answers.d.ts +9 -0
- package/dist/lib/conversation/answers.js +49 -0
- package/dist/lib/conversation/api.d.ts +75 -0
- package/dist/lib/conversation/api.js +151 -0
- package/dist/lib/conversation/change.d.ts +31 -0
- package/dist/lib/conversation/change.js +124 -0
- package/dist/lib/conversation/context.d.ts +29 -0
- package/dist/lib/conversation/context.js +82 -0
- package/dist/lib/conversation/environment.d.ts +16 -0
- package/dist/lib/conversation/environment.js +21 -0
- package/dist/lib/conversation/follow.d.ts +24 -0
- package/dist/lib/conversation/follow.js +42 -0
- package/dist/lib/conversation/render.d.ts +33 -0
- package/dist/lib/conversation/render.js +318 -0
- package/dist/lib/conversation/title.d.ts +2 -0
- package/dist/lib/conversation/title.js +18 -0
- package/dist/lib/conversation/types.d.ts +158 -0
- package/dist/lib/conversation/types.js +6 -0
- package/dist/lib/credentials.js +67 -11
- package/dist/lib/cron.d.ts +1 -1
- package/dist/lib/cron.js +2 -2
- package/dist/lib/dispatch-stop.d.ts +20 -0
- package/dist/lib/dispatch-stop.js +30 -0
- package/dist/lib/download.d.ts +100 -0
- package/dist/lib/download.js +408 -0
- package/dist/lib/dry-run/fetch.d.ts +10 -0
- package/dist/lib/dry-run/fetch.js +20 -0
- package/dist/lib/dry-run/samples.d.ts +6 -34
- package/dist/lib/dry-run/samples.js +375 -747
- package/dist/lib/environment-tunnel.d.ts +19 -30
- package/dist/lib/environment-tunnel.js +168 -202
- package/dist/lib/errors.d.ts +20 -4
- package/dist/lib/errors.js +36 -16
- package/dist/lib/facade.d.ts +7 -29
- package/dist/lib/facade.js +7 -36
- package/dist/lib/failing-fe-resolver.d.ts +13 -58
- package/dist/lib/failing-fe-resolver.js +47 -132
- package/dist/lib/first-suite-hint.d.ts +20 -30
- package/dist/lib/first-suite-hint.js +57 -72
- package/dist/lib/gh-output.d.ts +76 -21
- package/dist/lib/gh-output.js +171 -90
- package/dist/lib/git-utils.d.ts +56 -0
- package/dist/lib/git-utils.js +212 -0
- package/dist/lib/github-context.d.ts +2 -0
- package/dist/lib/github-context.js +40 -8
- package/dist/lib/history-retention.d.ts +6 -2
- package/dist/lib/history-retention.js +10 -7
- package/dist/lib/http.d.ts +58 -134
- package/dist/lib/http.js +354 -291
- package/dist/lib/interrupt.d.ts +14 -8
- package/dist/lib/interrupt.js +28 -10
- package/dist/lib/junit-report.d.ts +57 -4
- package/dist/lib/junit-report.js +202 -32
- package/dist/lib/local-target.d.ts +8 -7
- package/dist/lib/local-target.js +14 -13
- package/dist/lib/output.d.ts +2 -41
- package/dist/lib/output.js +13 -51
- package/dist/lib/pagination.d.ts +2 -5
- package/dist/lib/pagination.js +2 -5
- package/dist/lib/presigned-url.d.ts +22 -0
- package/dist/lib/presigned-url.js +90 -0
- package/dist/lib/prompt.js +36 -2
- package/dist/lib/proxy.js +2 -1
- package/dist/lib/redact.d.ts +2 -2
- package/dist/lib/redact.js +3 -4
- package/dist/lib/removed-commands.d.ts +18 -0
- package/dist/lib/removed-commands.js +170 -0
- package/dist/lib/render-error.d.ts +31 -6
- package/dist/lib/render-error.js +88 -25
- package/dist/lib/response-schemas.d.ts +38 -30
- package/dist/lib/response-schemas.js +207 -207
- package/dist/lib/result/api.d.ts +24 -0
- package/dist/lib/result/api.js +28 -0
- package/dist/lib/result/evidence.d.ts +73 -0
- package/dist/lib/result/evidence.js +422 -0
- package/dist/lib/result/render.d.ts +20 -0
- package/dist/lib/result/render.js +194 -0
- package/dist/lib/result/types.d.ts +122 -0
- package/dist/lib/result/types.js +19 -0
- package/dist/lib/run-output.d.ts +275 -0
- package/dist/lib/run-output.js +227 -0
- package/dist/lib/run-render.d.ts +101 -0
- package/dist/lib/run-render.js +183 -0
- package/dist/lib/run-wait.d.ts +192 -0
- package/dist/lib/run-wait.js +452 -0
- package/dist/lib/runs.types.d.ts +118 -367
- package/dist/lib/runs.types.js +0 -14
- package/dist/lib/secret-file.d.ts +1 -1
- package/dist/lib/secret-file.js +11 -2
- package/dist/lib/skill-nudge.d.ts +7 -27
- package/dist/lib/skill-nudge.js +9 -37
- package/dist/lib/target-path.d.ts +15 -0
- package/dist/lib/target-path.js +35 -0
- package/dist/lib/target-url-advisory.d.ts +19 -0
- package/dist/lib/target-url-advisory.js +31 -0
- package/dist/lib/target-url-preflight.d.ts +9 -0
- package/dist/lib/target-url-preflight.js +214 -106
- package/dist/lib/target-url.d.ts +8 -8
- package/dist/lib/target-url.js +14 -24
- package/dist/lib/telemetry.d.ts +35 -15
- package/dist/lib/telemetry.js +38 -9
- package/dist/lib/terminal-text.d.ts +41 -0
- package/dist/lib/terminal-text.js +127 -0
- package/dist/lib/testlist.types.d.ts +16 -8
- package/dist/lib/testlist.types.js +1 -1
- package/dist/lib/text-equality.d.ts +2 -0
- package/dist/lib/text-equality.js +5 -0
- package/dist/lib/text-file.d.ts +16 -0
- package/dist/lib/text-file.js +41 -0
- package/dist/lib/text-table.d.ts +46 -0
- package/dist/lib/text-table.js +72 -4
- package/dist/lib/ticker.d.ts +9 -2
- package/dist/lib/ticker.js +16 -3
- package/dist/lib/transport-failure.d.ts +22 -0
- package/dist/lib/transport-failure.js +126 -0
- package/dist/lib/tunnel-session.d.ts +8 -2
- package/dist/lib/tunnel-session.js +24 -11
- package/dist/lib/update-check.js +3 -2
- package/dist/lib/url-template.d.ts +43 -0
- package/dist/lib/url-template.js +151 -0
- package/dist/lib/validate.d.ts +0 -64
- package/dist/lib/validate.js +2 -131
- package/dist/lib/version-notice.js +4 -3
- package/dist/lib/wait-exit.d.ts +37 -2
- package/dist/lib/wait-exit.js +88 -30
- package/dist/lib/workspace-status.js +10 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -3
- package/skills/testsprite-ci.skill.md +52 -23
- package/skills/testsprite-onboard.skill.md +70 -153
- package/skills/testsprite-verify.codex.md +54 -58
- package/skills/testsprite-verify.skill.md +189 -358
- package/dist/lib/browser.d.ts +0 -6
- package/dist/lib/browser.js +0 -54
- package/dist/lib/bundle.d.ts +0 -234
- package/dist/lib/bundle.js +0 -781
- package/dist/lib/deprecate.d.ts +0 -32
- package/dist/lib/deprecate.js +0 -39
- package/dist/lib/flaky.d.ts +0 -91
- package/dist/lib/flaky.js +0 -71
- package/dist/lib/plan-poll.d.ts +0 -171
- package/dist/lib/plan-poll.js +0 -441
- package/dist/lib/plans.types.d.ts +0 -130
- package/dist/lib/plans.types.js +0 -31
- package/dist/lib/poll.d.ts +0 -100
- package/dist/lib/poll.js +0 -290
- package/dist/lib/rate-throttle.d.ts +0 -49
- package/dist/lib/rate-throttle.js +0 -75
- package/dist/lib/run-progress.d.ts +0 -41
- package/dist/lib/run-progress.js +0 -56
- package/dist/lib/v3-advisory.d.ts +0 -55
- package/dist/lib/v3-advisory.js +0 -74
- package/schemas/plan.schema.json +0 -61
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `testsprite tunnel start | list | status | stop`.
|
|
3
3
|
*
|
|
4
|
-
* The out-of-band primitive under
|
|
5
|
-
* Two things it buys that the
|
|
4
|
+
* The out-of-band primitive under a run on a local environment, which opens
|
|
5
|
+
* its own tunnel otherwise. Two things it buys that the automatic one cannot:
|
|
6
6
|
*
|
|
7
7
|
* - **One tunnel, many runs.** `tunnel start` in one terminal, then
|
|
8
|
-
* `
|
|
8
|
+
* `run <id> --env <name> --tunnel-client <id>` as many times as you
|
|
9
9
|
* like in another. Each run would otherwise mint and tear down its own
|
|
10
10
|
* credential, and the per-principal live-binding cap is small.
|
|
11
11
|
* - **A place to look when a run says the tunnel is down.** `tunnel status`
|
package/dist/commands/tunnel.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `testsprite tunnel start | list | status | stop`.
|
|
3
3
|
*
|
|
4
|
-
* The out-of-band primitive under
|
|
5
|
-
* Two things it buys that the
|
|
4
|
+
* The out-of-band primitive under a run on a local environment, which opens
|
|
5
|
+
* its own tunnel otherwise. Two things it buys that the automatic one cannot:
|
|
6
6
|
*
|
|
7
7
|
* - **One tunnel, many runs.** `tunnel start` in one terminal, then
|
|
8
|
-
* `
|
|
8
|
+
* `run <id> --env <name> --tunnel-client <id>` as many times as you
|
|
9
9
|
* like in another. Each run would otherwise mint and tear down its own
|
|
10
10
|
* credential, and the per-principal live-binding cap is small.
|
|
11
11
|
* - **A place to look when a run says the tunnel is down.** `tunnel status`
|
|
@@ -28,6 +28,7 @@ import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
|
28
28
|
import { renderTextTable } from '../lib/text-table.js';
|
|
29
29
|
import { formatDataPlaneUnreachableMessage, formatDataPlaneUnreachableNextAction, openTunnelSession, } from '../lib/tunnel-session.js';
|
|
30
30
|
import { TunnelClient } from '../vendor/tunnel-client/index.js';
|
|
31
|
+
import { terminalSafeLine, terminalSafeWriter } from '../lib/terminal-text.js';
|
|
31
32
|
const TUNNEL_CLIENT_ID_SCHEMA = v.pipe(v.string(), v.uuid());
|
|
32
33
|
function assertTunnelClientId(clientId) {
|
|
33
34
|
if (v.is(TUNNEL_CLIENT_ID_SCHEMA, clientId))
|
|
@@ -46,7 +47,7 @@ function stdoutOf(deps) {
|
|
|
46
47
|
return deps.stdout ?? ((line) => process.stdout.write(`${line}\n`));
|
|
47
48
|
}
|
|
48
49
|
function stderrOf(deps) {
|
|
49
|
-
return deps.stderr
|
|
50
|
+
return terminalSafeWriter(deps.stderr);
|
|
50
51
|
}
|
|
51
52
|
function makeClient(opts, deps, shutdownSignal = (deps.shutdown ?? globalShutdown).signal) {
|
|
52
53
|
return makeHttpClient(opts, {
|
|
@@ -127,6 +128,8 @@ async function withTeardownDeadline(createClient, shutdown, operation) {
|
|
|
127
128
|
async function deleteTunnelForCleanup(createClient, shutdown, clientId) {
|
|
128
129
|
await withTeardownDeadline(createClient, shutdown, client => client.delete(`/tunnel/${encodeURIComponent(clientId)}`, {
|
|
129
130
|
allowNoContent: true,
|
|
131
|
+
retryOnConflict: false,
|
|
132
|
+
replaySafe: true,
|
|
130
133
|
}));
|
|
131
134
|
}
|
|
132
135
|
const TEARDOWN_OPERATION_TIMEOUT_MS = 10_000;
|
|
@@ -230,7 +233,7 @@ export async function runTunnelStart(opts, deps = {}) {
|
|
|
230
233
|
log: stderr,
|
|
231
234
|
logLevel: opts.debug ? 'debug' : opts.verbose ? 'info' : 'error',
|
|
232
235
|
...(opts.ttlSeconds !== undefined ? { ttlSeconds: opts.ttlSeconds } : {}),
|
|
233
|
-
onMinted: minted => stderr(`Minted tunnel client ${minted.clientId} (expires ${minted.expiresAt}); connecting…`),
|
|
236
|
+
onMinted: minted => stderr(`Minted tunnel client ${terminalSafeLine(minted.clientId)} (expires ${terminalSafeLine(minted.expiresAt)}); connecting…`),
|
|
234
237
|
onFatal: (reason, message) => {
|
|
235
238
|
fatal = true;
|
|
236
239
|
fatalReason = reason;
|
|
@@ -259,13 +262,14 @@ export async function runTunnelStart(opts, deps = {}) {
|
|
|
259
262
|
transport: session.transport,
|
|
260
263
|
}, data => {
|
|
261
264
|
const d = data;
|
|
265
|
+
const clientId = terminalSafeLine(d.clientId);
|
|
262
266
|
return [
|
|
263
|
-
`clientId ${
|
|
264
|
-
`expiresAt ${d.expiresAt}`,
|
|
267
|
+
`clientId ${clientId}`,
|
|
268
|
+
`expiresAt ${terminalSafeLine(d.expiresAt)}`,
|
|
265
269
|
`status online`,
|
|
266
270
|
`transport ${d.transport}`,
|
|
267
|
-
`hint Attach a run: testsprite
|
|
268
|
-
`hint Stop it: press Ctrl-C here, or run 'testsprite tunnel stop ${
|
|
271
|
+
`hint Attach a run: testsprite run <test-id> --env <name> --tunnel-client ${clientId}`,
|
|
272
|
+
`hint Stop it: press Ctrl-C here, or run 'testsprite tunnel stop ${clientId}' from another terminal`,
|
|
269
273
|
].join('\n');
|
|
270
274
|
});
|
|
271
275
|
void stdout;
|
|
@@ -301,7 +305,7 @@ export async function runTunnelStart(opts, deps = {}) {
|
|
|
301
305
|
if ((fatal || revoked) && !shutdown.signal.aborted) {
|
|
302
306
|
const dataPlaneUnreachable = fatalReason === 'data-plane-unreachable';
|
|
303
307
|
if (revoked) {
|
|
304
|
-
stderr(`Tunnel credential ${session.clientId} was revoked, expired, or taken over by another process.`);
|
|
308
|
+
stderr(`Tunnel credential ${terminalSafeLine(session.clientId)} was revoked, expired, or taken over by another process.`);
|
|
305
309
|
}
|
|
306
310
|
throw ApiError.fromEnvelope({
|
|
307
311
|
error: {
|
|
@@ -327,7 +331,7 @@ export async function runTunnelStart(opts, deps = {}) {
|
|
|
327
331
|
},
|
|
328
332
|
});
|
|
329
333
|
}
|
|
330
|
-
stderr(`Tunnel ${session.clientId} closed.`);
|
|
334
|
+
stderr(`Tunnel ${terminalSafeLine(session.clientId)} closed.`);
|
|
331
335
|
}
|
|
332
336
|
/**
|
|
333
337
|
* Is a client of mine connected?
|
|
@@ -357,9 +361,9 @@ export async function runTunnelStatus(opts, deps = {}) {
|
|
|
357
361
|
}
|
|
358
362
|
function renderStatus(status) {
|
|
359
363
|
const lines = [
|
|
360
|
-
`clientId ${status.clientId}`,
|
|
361
|
-
`status ${status.status}`,
|
|
362
|
-
`expiresAt ${status.expiresAt}`,
|
|
364
|
+
`clientId ${terminalSafeLine(status.clientId)}`,
|
|
365
|
+
`status ${terminalSafeLine(status.status)}`,
|
|
366
|
+
`expiresAt ${terminalSafeLine(status.expiresAt)}`,
|
|
363
367
|
];
|
|
364
368
|
if (status.status !== 'online') {
|
|
365
369
|
lines.push('hint Nothing is connected with this id. Start one with: testsprite tunnel start');
|
|
@@ -490,7 +494,7 @@ export async function runTunnelStop(opts, deps = {}) {
|
|
|
490
494
|
method: 'DELETE',
|
|
491
495
|
path: `/api/cli/v1/tunnel/${item.clientId}`,
|
|
492
496
|
}));
|
|
493
|
-
out.print({ requests }, () => requests.map(item => `${item.method} ${item.path}`).join('\n'));
|
|
497
|
+
out.print({ requests }, () => requests.map(item => `${item.method} ${terminalSafeLine(item.path)}`).join('\n'));
|
|
494
498
|
return;
|
|
495
499
|
}
|
|
496
500
|
if (response.tunnels.length === 0) {
|
|
@@ -528,8 +532,8 @@ export async function runTunnelStop(opts, deps = {}) {
|
|
|
528
532
|
};
|
|
529
533
|
out.print(bulk, () => [
|
|
530
534
|
...results.map(result => result.stopped
|
|
531
|
-
? `stopped ${result.clientId}`
|
|
532
|
-
: `failed ${result.clientId} ${result.error?.message}`),
|
|
535
|
+
? `stopped ${terminalSafeLine(result.clientId)}`
|
|
536
|
+
: `failed ${terminalSafeLine(result.clientId)} ${terminalSafeLine(String(result.error?.message))}`),
|
|
533
537
|
`Stopped ${stopped} of ${results.length} tunnels.`,
|
|
534
538
|
'hint A running `tunnel start` notices a revoked credential within ~15 s and exits.',
|
|
535
539
|
].join('\n'));
|
|
@@ -557,8 +561,7 @@ export function createTunnelCommand(deps = {}) {
|
|
|
557
561
|
'daemon, because its credential is never written to disk.\n' +
|
|
558
562
|
'\nExamples:\n' +
|
|
559
563
|
' testsprite tunnel start # hold a tunnel open (Ctrl-C to stop)\n' +
|
|
560
|
-
' testsprite
|
|
561
|
-
' testsprite test run <test-id> --local 3000 --tunnel-client <client-id>\n' +
|
|
564
|
+
' testsprite run <test-id> --env <name> --tunnel-client <client-id>\n' +
|
|
562
565
|
' testsprite tunnel stop --all --confirm\n');
|
|
563
566
|
tunnel
|
|
564
567
|
.command('start')
|
|
@@ -570,7 +573,7 @@ export function createTunnelCommand(deps = {}) {
|
|
|
570
573
|
.option('--ttl <seconds>', 'requested credential lifetime (60–28800), clamped by the server; the credential is deleted ' +
|
|
571
574
|
'on exit regardless, so this only matters if the process is killed')
|
|
572
575
|
.addHelpText('after', '\nPrints the client id to stderr as soon as it is minted; pass it to\n' +
|
|
573
|
-
'`
|
|
576
|
+
'`run <test-id> --env <name> --tunnel-client <client-id>` for an environment on this machine.\n' +
|
|
574
577
|
'\nDev servers can take a minute per page through the tunnel; for a heavy one, test a built\n' +
|
|
575
578
|
"server (`npm run build`, then your framework's preview/start command).\n" +
|
|
576
579
|
'\nExit codes:\n' +
|
package/dist/commands/usage.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `testsprite usage` — show the
|
|
3
|
-
*
|
|
2
|
+
* `testsprite usage` — show the caller's organization wallet (balance, plan,
|
|
3
|
+
* seats) as a proactive pre-flight before a large `run` fan-out.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the `credits` / `subPlan` / `creditsPerRun` fields when and only when the
|
|
9
|
-
* backend response includes them — kept absent-safe/forward-compat since not
|
|
10
|
-
* every account shape is guaranteed to populate all three (e.g. `creditsPerRun`
|
|
11
|
-
* has no server-side source at all today).
|
|
5
|
+
* Reads `GET /me`. The wallet is the `activeOrg` block, which the backend
|
|
6
|
+
* enriches best-effort and omits on a lookup failure; every field beyond the
|
|
7
|
+
* identity core stays absent-safe.
|
|
12
8
|
*/
|
|
13
9
|
import { Command } from 'commander';
|
|
14
10
|
import { type WorkspaceStatus } from '../lib/workspace-status.js';
|
|
@@ -16,46 +12,19 @@ import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factor
|
|
|
16
12
|
import type { FetchImpl } from '../lib/http.js';
|
|
17
13
|
import type { CliOrgBinding, CliOrgSummary } from '../lib/org-render.js';
|
|
18
14
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `credits` / `subPlan` now ship on `/me` (live). Still
|
|
23
|
-
* kept optional/absent-safe: `userId`/`keyId`/`env` are the only fields every
|
|
24
|
-
* backend and account shape is guaranteed to populate.
|
|
15
|
+
* The `/me` projection the `usage` command reads. `userId`/`keyId`/`env` are
|
|
16
|
+
* the only fields every account shape is guaranteed to populate.
|
|
25
17
|
*/
|
|
26
18
|
export interface UsageResponse {
|
|
27
19
|
userId: string;
|
|
28
20
|
keyId: string;
|
|
29
21
|
env: 'development' | 'staging' | 'production';
|
|
30
22
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
credits?: number;
|
|
35
|
-
/**
|
|
36
|
-
* Subscription plan name (e.g. "Free", "Standard", "Pro"). Present when
|
|
37
|
-
* the backend /me (or /usage) includes the User.subPlan projection (live).
|
|
38
|
-
*/
|
|
39
|
-
subPlan?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Credit cost per test run trigger (informational). Present only when the
|
|
42
|
-
* backend supplies it.
|
|
43
|
-
*/
|
|
44
|
-
creditsPerRun?: number;
|
|
45
|
-
/**
|
|
46
|
-
* The caller's organization wallet — the billing subject on org-based
|
|
47
|
-
* accounts. Rendered only together with `v3Enabled: true` (see
|
|
48
|
-
* `renderUsage`): the org wallet supersedes the legacy `credits`/`subPlan`
|
|
49
|
-
* pair only for callers whose commands actually bill it. Absent-safe like
|
|
50
|
-
* every other optional field.
|
|
23
|
+
* The caller's organization wallet — the billing subject. The backend
|
|
24
|
+
* resolves it from the key's org binding, else the personal org, and omits
|
|
25
|
+
* it when that lookup fails.
|
|
51
26
|
*/
|
|
52
27
|
activeOrg?: ActiveOrg;
|
|
53
|
-
/**
|
|
54
|
-
* Authoritative per-caller routing bit: true when this caller's commands
|
|
55
|
-
* run (and bill) on the V3 platform. Always present on current backends;
|
|
56
|
-
* absent on older ones.
|
|
57
|
-
*/
|
|
58
|
-
v3Enabled?: boolean;
|
|
59
28
|
/**
|
|
60
29
|
* Every organization the underlying user belongs to (account-wide
|
|
61
30
|
* membership list, personal org included). Absent-safe: omitted on a
|
|
@@ -95,10 +64,8 @@ type CommonOptions = FactoryCommonOptions;
|
|
|
95
64
|
/** Dry-run canned response — matches what the real /me + User lookup would return. */
|
|
96
65
|
export declare const DRY_RUN_USAGE_SAMPLE: UsageResponse;
|
|
97
66
|
/**
|
|
98
|
-
* Run the `usage` command. Calls `GET /me
|
|
99
|
-
*
|
|
100
|
-
* omitted (forward-compat in case a given account/backend version doesn't
|
|
101
|
-
* populate them).
|
|
67
|
+
* Run the `usage` command. Calls `GET /me` and surfaces identity plus the org
|
|
68
|
+
* wallet when the backend supplies it. Absent fields are silently omitted.
|
|
102
69
|
*/
|
|
103
70
|
export declare function runUsage(opts: CommonOptions, deps?: UsageDeps): Promise<UsageResponse>;
|
|
104
71
|
export declare function createUsageCommand(deps?: UsageDeps): Command;
|
package/dist/commands/usage.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `testsprite usage` — show the
|
|
3
|
-
*
|
|
2
|
+
* `testsprite usage` — show the caller's organization wallet (balance, plan,
|
|
3
|
+
* seats) as a proactive pre-flight before a large `run` fan-out.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the `credits` / `subPlan` / `creditsPerRun` fields when and only when the
|
|
9
|
-
* backend response includes them — kept absent-safe/forward-compat since not
|
|
10
|
-
* every account shape is guaranteed to populate all three (e.g. `creditsPerRun`
|
|
11
|
-
* has no server-side source at all today).
|
|
5
|
+
* Reads `GET /me`. The wallet is the `activeOrg` block, which the backend
|
|
6
|
+
* enriches best-effort and omits on a lookup failure; every field beyond the
|
|
7
|
+
* identity core stays absent-safe.
|
|
12
8
|
*/
|
|
13
9
|
import { Command } from 'commander';
|
|
14
10
|
import { formatWorkspaceStatus } from '../lib/workspace-status.js';
|
|
@@ -18,15 +14,12 @@ import { resolvePortalBase } from '../lib/facade.js';
|
|
|
18
14
|
import { formatOrgBinding, formatOrgsSummary } from '../lib/org-render.js';
|
|
19
15
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
20
16
|
import { USAGE_RESPONSE_SCHEMA } from '../lib/response-schemas.js';
|
|
17
|
+
import { terminalSafeLine, terminalSafeWriter } from '../lib/terminal-text.js';
|
|
21
18
|
/** Dry-run canned response — matches what the real /me + User lookup would return. */
|
|
22
19
|
export const DRY_RUN_USAGE_SAMPLE = {
|
|
23
20
|
userId: '11111111-1111-4111-8111-111111111111',
|
|
24
21
|
keyId: 'key_dryrun_2026',
|
|
25
22
|
env: 'development',
|
|
26
|
-
credits: 42,
|
|
27
|
-
subPlan: 'Standard',
|
|
28
|
-
creditsPerRun: 2,
|
|
29
|
-
v3Enabled: true,
|
|
30
23
|
activeOrg: {
|
|
31
24
|
id: '22222222-2222-4222-8222-222222222222',
|
|
32
25
|
name: 'Dry Run Workspace',
|
|
@@ -38,13 +31,11 @@ export const DRY_RUN_USAGE_SAMPLE = {
|
|
|
38
31
|
},
|
|
39
32
|
};
|
|
40
33
|
/**
|
|
41
|
-
* Run the `usage` command. Calls `GET /me
|
|
42
|
-
*
|
|
43
|
-
* omitted (forward-compat in case a given account/backend version doesn't
|
|
44
|
-
* populate them).
|
|
34
|
+
* Run the `usage` command. Calls `GET /me` and surfaces identity plus the org
|
|
35
|
+
* wallet when the backend supplies it. Absent fields are silently omitted.
|
|
45
36
|
*/
|
|
46
37
|
export async function runUsage(opts, deps = {}) {
|
|
47
|
-
const stderr = deps.stderr
|
|
38
|
+
const stderr = terminalSafeWriter(deps.stderr);
|
|
48
39
|
const out = makeOutput(opts.output, deps);
|
|
49
40
|
if (opts.dryRun) {
|
|
50
41
|
emitDryRunBanner(stderr);
|
|
@@ -69,18 +60,11 @@ export async function runUsage(opts, deps = {}) {
|
|
|
69
60
|
credentialsPath: deps.credentialsPath,
|
|
70
61
|
}).apiUrl);
|
|
71
62
|
const billingUrl = portalBase !== undefined
|
|
72
|
-
? `${portalBase}
|
|
73
|
-
:
|
|
74
|
-
// /me is the only available source of credits/plan today. If the backend
|
|
75
|
-
// adds a dedicated /usage endpoint later, this single get call is where
|
|
76
|
-
// it would be swapped in — no other code change needed in the CLI.
|
|
63
|
+
? `${portalBase}${BILLING_PAGE_PATH}`
|
|
64
|
+
: `the portal Billing page (${BILLING_PAGE_PATH})`;
|
|
77
65
|
const me = await client.get('/me', { schema: USAGE_RESPONSE_SCHEMA });
|
|
78
66
|
out.print(me, data => renderUsage(data, portalBase));
|
|
79
|
-
// In text mode, emit a note when
|
|
80
|
-
// legacy per-user `credits` nor an org wallet. A V3-routed org account can
|
|
81
|
-
// legitimately have no DDB `credits` field (org-native members never get a
|
|
82
|
-
// legacy user row), and its balance already rendered in the organization
|
|
83
|
-
// block — the note would contradict the output right above it.
|
|
67
|
+
// In text mode, emit a note when no balance was shown at all.
|
|
84
68
|
//
|
|
85
69
|
// "Is this key org-bound" and "do I have a balance number to show" are two
|
|
86
70
|
// different questions and must not be conflated. `me.org` is the key's own
|
|
@@ -88,14 +72,10 @@ export async function runUsage(opts, deps = {}) {
|
|
|
88
72
|
// authenticated with a membership key (`sk-member-…`). `activeOrg` is the
|
|
89
73
|
// *enriched* org balance: the backend does a best-effort Postgres read for
|
|
90
74
|
// it and swallows the exception on failure, so `org` can be present while
|
|
91
|
-
// `activeOrg`
|
|
92
|
-
//
|
|
93
|
-
// (i.e. `orgWalletShown`) alone means that degraded state falls through to
|
|
94
|
-
// this personal-billing note — pointing an org-key operator at the wrong
|
|
95
|
-
// wallet in exactly the situation this whole surface exists to prevent.
|
|
75
|
+
// `activeOrg` is absent. An org-bound key in that state must be told its
|
|
76
|
+
// org balance is unavailable, never pointed at a generic billing page.
|
|
96
77
|
const isOrgBound = me.org !== undefined;
|
|
97
|
-
|
|
98
|
-
if (opts.output === 'text' && me.credits === undefined && !orgWalletShown) {
|
|
78
|
+
if (opts.output === 'text' && me.activeOrg === undefined) {
|
|
99
79
|
stderr(isOrgBound
|
|
100
80
|
? "[note] this key is organization-bound, but the org balance could not be loaded right now. Retry `testsprite usage`, or check the Portal's organization billing settings (ask an org admin if you don't have access)."
|
|
101
81
|
: `[note] credit balance not returned for this account. Check ${billingUrl} for your current balance.`);
|
|
@@ -108,128 +88,68 @@ export async function runUsage(opts, deps = {}) {
|
|
|
108
88
|
* AI-assisted operation may fail; cheaper actions can still succeed.
|
|
109
89
|
*/
|
|
110
90
|
const LOW_ORG_BALANCE_CREDITS = 2;
|
|
91
|
+
/**
|
|
92
|
+
* Org-less Portal billing route: the Portal re-anchors it under the viewer's
|
|
93
|
+
* active workspace.
|
|
94
|
+
*/
|
|
95
|
+
const BILLING_PAGE_PATH = '/dashboard-v3/settings/billing';
|
|
111
96
|
function renderUsage(u, portalBase) {
|
|
112
97
|
const lines = [];
|
|
113
98
|
// Identity block (always present)
|
|
114
|
-
lines.push(`userId: ${u.userId}`);
|
|
115
|
-
lines.push(`keyId: ${u.keyId}`);
|
|
116
|
-
lines.push(`env: ${u.env}`);
|
|
99
|
+
lines.push(`userId: ${terminalSafeLine(u.userId)}`);
|
|
100
|
+
lines.push(`keyId: ${terminalSafeLine(u.keyId)}`);
|
|
101
|
+
lines.push(`env: ${terminalSafeLine(u.env)}`);
|
|
117
102
|
// Org attribution — rendered only when the backend supplies it.
|
|
118
103
|
const orgsSummary = formatOrgsSummary(u.organizations);
|
|
119
104
|
if (orgsSummary)
|
|
120
|
-
lines.push(`orgs: ${orgsSummary}`);
|
|
105
|
+
lines.push(`orgs: ${terminalSafeLine(orgsSummary)}`);
|
|
121
106
|
const orgBinding = formatOrgBinding(u.org);
|
|
122
107
|
if (orgBinding)
|
|
123
|
-
lines.push(`org binding: ${orgBinding}`);
|
|
108
|
+
lines.push(`org binding: ${terminalSafeLine(orgBinding)}`);
|
|
124
109
|
// Whether the CALLING KEY is org-bound — read from `u.org` (the key's own
|
|
125
|
-
// membership binding
|
|
126
|
-
//
|
|
127
|
-
// `activeOrg` is the *enriched* org balance: the backend does a best-effort
|
|
128
|
-
// Postgres read for it and swallows the exception on failure, so a caller
|
|
129
|
-
// can be genuinely org-bound (`org` present) while `activeOrg` — and, for a
|
|
130
|
-
// V3-native user with no legacy DynamoDB row, `credits` too — is absent.
|
|
131
|
-
// "Is this key org-bound" and "do I have a balance number to show" are two
|
|
132
|
-
// different questions; conflating them (deciding org-boundedness from
|
|
133
|
-
// `orgWallet`/`activeOrg` alone) sends a degraded-enrichment org caller
|
|
134
|
-
// down the personal-wallet branches below.
|
|
110
|
+
// membership binding), NOT from `activeOrg`, which is a best-effort
|
|
111
|
+
// enrichment the backend omits on a lookup failure (see `runUsage`).
|
|
135
112
|
const isOrgBound = u.org !== undefined;
|
|
136
|
-
// Org wallet block — the billing subject
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
// billable commands still charge the legacy wallet); older backends send
|
|
141
|
-
// neither field and degrade the same way.
|
|
142
|
-
// `?? undefined` also normalizes a hypothetical explicit `null` from the
|
|
143
|
-
// wire so the block below can't dereference it.
|
|
144
|
-
const orgWallet = u.v3Enabled === true ? (u.activeOrg ?? undefined) : undefined;
|
|
113
|
+
// Org wallet block — the billing subject. `?? undefined` also normalizes a
|
|
114
|
+
// hypothetical explicit `null` from the wire so the block below can't
|
|
115
|
+
// dereference it.
|
|
116
|
+
const orgWallet = u.activeOrg ?? undefined;
|
|
145
117
|
if (orgWallet !== undefined) {
|
|
146
118
|
const org = orgWallet;
|
|
147
119
|
lines.push('');
|
|
148
120
|
lines.push('--- organization ---');
|
|
149
|
-
lines.push(`org: ${org.name} (${org.role})`);
|
|
150
|
-
lines.push(`plan: ${org.plan}`);
|
|
121
|
+
lines.push(`org: ${terminalSafeLine(org.name)} (${terminalSafeLine(org.role)})`);
|
|
122
|
+
lines.push(`plan: ${terminalSafeLine(org.plan)}`);
|
|
151
123
|
// A paused workspace cannot spend this balance at all; a payment-pending
|
|
152
124
|
// one keeps spending but gets no refill. Both are worth a line here.
|
|
153
125
|
const standing = formatWorkspaceStatus(org.workspace);
|
|
154
126
|
if (standing)
|
|
155
127
|
lines.push(`state: ${standing}`);
|
|
156
|
-
// Labeled `balance:` (not `credits:`) — `--output json` exposes the
|
|
157
|
-
// legacy per-user number under `.credits`, and giving the org wallet the
|
|
158
|
-
// same label in text mode would make one word mean two different values.
|
|
159
128
|
lines.push(`balance: ${org.remaining} remaining (${org.includedCredits}/mo per seat)`);
|
|
160
129
|
lines.push(`seats: ${org.seats}`);
|
|
161
|
-
// No "~N runs" estimate here: org billing prices actions individually
|
|
162
|
-
//
|
|
163
|
-
// computed from the legacy frontend rate would be wrong.
|
|
130
|
+
// No "~N runs" estimate here: org billing prices actions individually,
|
|
131
|
+
// so a single per-run rate would be wrong for most fan-outs.
|
|
164
132
|
}
|
|
165
133
|
else if (isOrgBound) {
|
|
166
134
|
// Org-bound key, but the enrichment that would have populated `activeOrg`
|
|
167
|
-
// degraded (best-effort Postgres read failed server-side
|
|
168
|
-
//
|
|
169
|
-
// the legacy per-user blocks below (this key's commands bill the org
|
|
170
|
-
// wallet, not the personal one, regardless of whether we could load its
|
|
171
|
-
// number just now), and never fabricate an org-scoped URL.
|
|
135
|
+
// degraded (best-effort Postgres read failed server-side). Say so
|
|
136
|
+
// honestly, and never fabricate an org-scoped URL.
|
|
172
137
|
lines.push('');
|
|
173
138
|
lines.push('--- organization ---');
|
|
174
139
|
lines.push("balance: could not be loaded right now. Retry `testsprite usage`, or check the Portal's organization billing settings (ask an org admin if you don't have access).");
|
|
175
140
|
}
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
// even if a legacy row happens to still carry them).
|
|
180
|
-
const hasBalanceData = u.credits !== undefined || u.subPlan !== undefined;
|
|
181
|
-
if (orgWallet === undefined && !isOrgBound && hasBalanceData) {
|
|
182
|
-
lines.push('');
|
|
183
|
-
lines.push('--- credits & plan ---');
|
|
184
|
-
if (u.subPlan !== undefined) {
|
|
185
|
-
lines.push(`plan: ${u.subPlan}`);
|
|
186
|
-
}
|
|
187
|
-
if (u.credits !== undefined) {
|
|
188
|
-
lines.push(`credits: ${u.credits}`);
|
|
189
|
-
}
|
|
190
|
-
if (u.creditsPerRun !== undefined) {
|
|
191
|
-
lines.push(`cost per frontend run: ${u.creditsPerRun} credit(s)`);
|
|
192
|
-
// Backend runs DO consume credits (confirmed by design 2026-06-30).
|
|
193
|
-
// The API exposes no backend-specific per-run cost field, and it differs from
|
|
194
|
-
// the frontend rate, so state that it bills without asserting a possibly-wrong
|
|
195
|
-
// number — check your balance before/after, or see the billing page.
|
|
196
|
-
lines.push(`cost per backend run: also consumes credits (exact amount not reported by the API)`);
|
|
197
|
-
}
|
|
198
|
-
// Pre-flight hint: how many runs the current balance can fund
|
|
199
|
-
if (u.credits !== undefined && u.creditsPerRun !== undefined && u.creditsPerRun > 0) {
|
|
200
|
-
const maxRuns = Math.floor(u.credits / u.creditsPerRun);
|
|
201
|
-
lines.push(`can trigger: ~${maxRuns} run(s) at current balance`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
// Actionable upgrade line for Free or low-balance keys. Prefer the org
|
|
205
|
-
// wallet's plan/balance when present. `!isOrgBound` guards the personal
|
|
206
|
-
// branch of each: an org-bound key with degraded enrichment has no
|
|
207
|
-
// `orgWallet` to compute from, but must not fall back to reading `u.credits`
|
|
208
|
-
// / `u.subPlan` either (a legacy row that happens to coexist with an org
|
|
209
|
-
// binding is not what this key's commands actually bill).
|
|
210
|
-
const isLowBalance = orgWallet !== undefined
|
|
211
|
-
? orgWallet.remaining < LOW_ORG_BALANCE_CREDITS
|
|
212
|
-
: !isOrgBound &&
|
|
213
|
-
u.credits !== undefined &&
|
|
214
|
-
u.creditsPerRun !== undefined &&
|
|
215
|
-
u.credits < u.creditsPerRun;
|
|
216
|
-
const isFree = orgWallet !== undefined
|
|
217
|
-
? orgWallet.plan.toLowerCase() === 'free'
|
|
218
|
-
: !isOrgBound && u.subPlan?.toLowerCase() === 'free';
|
|
141
|
+
// Upgrade line for Free or low-balance wallets.
|
|
142
|
+
const isLowBalance = orgWallet !== undefined && orgWallet.remaining < LOW_ORG_BALANCE_CREDITS;
|
|
143
|
+
const isFree = orgWallet !== undefined && orgWallet.plan.toLowerCase() === 'free';
|
|
219
144
|
if (isLowBalance) {
|
|
220
145
|
lines.push('');
|
|
221
|
-
//
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
lines.push(
|
|
228
|
-
? // Org billing prices actions individually, and cheaper actions (e.g.
|
|
229
|
-
// a 1-credit backend run) may still succeed below the threshold —
|
|
230
|
-
// so this is "low", not "cannot run".
|
|
231
|
-
`warning: organization balance is low (under the ${LOW_ORG_BALANCE_CREDITS}-credit cost of a generation action). Top up in the Portal's organization billing settings (ask an org admin if you don't have access).`
|
|
232
|
-
: `warning: credit balance is below the per-run cost. Top up at: ${portalBase !== undefined ? `${portalBase}/dashboard/settings/billing` : 'the portal Billing page (/dashboard/settings/billing)'}`);
|
|
146
|
+
// No URL here: the Portal's org-less billing route re-anchors under the
|
|
147
|
+
// viewer's ACTIVE workspace in the browser, which need not be the org
|
|
148
|
+
// this key bills, so "the organization billing settings" is the honest
|
|
149
|
+
// pointer. Org billing prices actions individually, and cheaper actions
|
|
150
|
+
// (e.g. a 1-credit backend run) may still succeed below the threshold —
|
|
151
|
+
// so this is "low", not "cannot run".
|
|
152
|
+
lines.push(`warning: organization balance is low (under the ${LOW_ORG_BALANCE_CREDITS}-credit cost of a generation action). Top up in the Portal's organization billing settings (ask an org admin if you don't have access).`);
|
|
233
153
|
}
|
|
234
154
|
else if (isFree) {
|
|
235
155
|
lines.push('');
|
|
@@ -242,7 +162,7 @@ export function createUsageCommand(deps = {}) {
|
|
|
242
162
|
const cmd = new Command('usage')
|
|
243
163
|
.alias('credits')
|
|
244
164
|
.summary('Show credit balance and plan info')
|
|
245
|
-
.description('Show credit balance and plan/entitlement info (proactive pre-flight before a large
|
|
165
|
+
.description('Show credit balance and plan/entitlement info (proactive pre-flight before a large run)')
|
|
246
166
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
247
167
|
.addHelpText('after', '\nExamples:\n' +
|
|
248
168
|
' testsprite usage # show balance + plan\n' +
|
|
@@ -253,9 +173,8 @@ export function createUsageCommand(deps = {}) {
|
|
|
253
173
|
' 0 success (or --dry-run)\n' +
|
|
254
174
|
' 3 auth error — run `testsprite setup` to configure credentials\n' +
|
|
255
175
|
' 10 transport/network failure (UNAVAILABLE) — retry the command\n' +
|
|
256
|
-
"\nNote: if
|
|
257
|
-
'
|
|
258
|
-
' organization billing settings (ask an org admin) if this key is\n' +
|
|
176
|
+
"\nNote: if the balance isn't shown, check the portal's Billing page\n" +
|
|
177
|
+
' (/dashboard-v3/settings/billing), or ask an org admin if this key is\n' +
|
|
259
178
|
' organization-bound.')
|
|
260
179
|
.action(async (_cmdOpts, command) => {
|
|
261
180
|
await runUsage(resolveCommonOptions(command, deps.env), deps);
|