@testsprite/testsprite-cli 0.1.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/LICENSE +201 -0
- package/README.md +190 -0
- package/dist/assets/agent-skill/testsprite-verify.codex.md +119 -0
- package/dist/assets/agent-skill/testsprite-verify.skill.md +423 -0
- package/dist/commands/agent.d.ts +51 -0
- package/dist/commands/agent.js +552 -0
- package/dist/commands/auth.d.ts +38 -0
- package/dist/commands/auth.js +247 -0
- package/dist/commands/init.d.ts +63 -0
- package/dist/commands/init.js +350 -0
- package/dist/commands/project.d.ts +72 -0
- package/dist/commands/project.js +400 -0
- package/dist/commands/test.d.ts +1245 -0
- package/dist/commands/test.js +6214 -0
- package/dist/commands/usage.d.ts +63 -0
- package/dist/commands/usage.js +156 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +146 -0
- package/dist/lib/agent-targets.d.ts +50 -0
- package/dist/lib/agent-targets.js +99 -0
- package/dist/lib/bundle.d.ts +178 -0
- package/dist/lib/bundle.js +600 -0
- package/dist/lib/client-factory.d.ts +72 -0
- package/dist/lib/client-factory.js +120 -0
- package/dist/lib/config.d.ts +24 -0
- package/dist/lib/config.js +30 -0
- package/dist/lib/credentials.d.ts +17 -0
- package/dist/lib/credentials.js +122 -0
- package/dist/lib/dry-run/fetch.d.ts +18 -0
- package/dist/lib/dry-run/fetch.js +52 -0
- package/dist/lib/dry-run/samples.d.ts +50 -0
- package/dist/lib/dry-run/samples.js +676 -0
- package/dist/lib/errors.d.ts +118 -0
- package/dist/lib/errors.js +388 -0
- package/dist/lib/facade.d.ts +48 -0
- package/dist/lib/facade.js +104 -0
- package/dist/lib/failing-fe-resolver.d.ts +60 -0
- package/dist/lib/failing-fe-resolver.js +103 -0
- package/dist/lib/http.d.ts +255 -0
- package/dist/lib/http.js +608 -0
- package/dist/lib/output.d.ts +55 -0
- package/dist/lib/output.js +70 -0
- package/dist/lib/pagination.d.ts +56 -0
- package/dist/lib/pagination.js +81 -0
- package/dist/lib/poll.d.ts +88 -0
- package/dist/lib/poll.js +221 -0
- package/dist/lib/prompt.d.ts +8 -0
- package/dist/lib/prompt.js +97 -0
- package/dist/lib/rate-throttle.d.ts +49 -0
- package/dist/lib/rate-throttle.js +75 -0
- package/dist/lib/render-error.d.ts +15 -0
- package/dist/lib/render-error.js +44 -0
- package/dist/lib/runs.types.d.ts +344 -0
- package/dist/lib/runs.types.js +25 -0
- package/dist/lib/target-url.d.ts +25 -0
- package/dist/lib/target-url.js +127 -0
- package/dist/lib/ticker.d.ts +37 -0
- package/dist/lib/ticker.js +63 -0
- package/dist/lib/validate.d.ts +82 -0
- package/dist/lib/validate.js +165 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/package.json +65 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `testsprite usage` — show the account's credit balance and plan/entitlement
|
|
3
|
+
* info as a proactive pre-flight before a large `test run` fan-out.
|
|
4
|
+
*
|
|
5
|
+
* Backend note: the `GET /me` endpoint does NOT currently return credit balance
|
|
6
|
+
* or plan info. This command calls `/me` for auth-identity fields and surfaces
|
|
7
|
+
* the `credits` / `subPlan` fields when and only when the backend supplies them
|
|
8
|
+
* (forward-compat / absent-safe). A dedicated backend endpoint is a required
|
|
9
|
+
* follow-up.
|
|
10
|
+
*
|
|
11
|
+
* BACKEND FOLLOW-UP REQUIRED:
|
|
12
|
+
* Add `credits`, `subPlan` to the `/me` response, or add a dedicated
|
|
13
|
+
* `GET /api/cli/v1/usage` endpoint returning `{ credits, subPlan, creditsPerRun }`.
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
17
|
+
import type { FetchImpl } from '../lib/http.js';
|
|
18
|
+
/**
|
|
19
|
+
* Usage/balance response from `/me` (when the backend supplies it) or a future
|
|
20
|
+
* `/usage` endpoint.
|
|
21
|
+
*
|
|
22
|
+
* All fields except `userId`/`keyId`/`env` are forward-compat: the backend
|
|
23
|
+
* does not return them today. They are rendered only when present.
|
|
24
|
+
*/
|
|
25
|
+
export interface UsageResponse {
|
|
26
|
+
userId: string;
|
|
27
|
+
keyId: string;
|
|
28
|
+
env: 'development' | 'staging' | 'production';
|
|
29
|
+
/**
|
|
30
|
+
* Remaining credit balance. Present only when the backend /me (or /usage)
|
|
31
|
+
* includes the User.credits projection. BACKEND FOLLOW-UP: me.controller.ts.
|
|
32
|
+
*/
|
|
33
|
+
credits?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Subscription plan name (e.g. "Free", "Standard", "Pro"). Present only when
|
|
36
|
+
* the backend /me (or /usage) includes the User.subPlan projection.
|
|
37
|
+
* BACKEND FOLLOW-UP: me.controller.ts.
|
|
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
|
+
export interface UsageDeps {
|
|
47
|
+
env?: NodeJS.ProcessEnv;
|
|
48
|
+
credentialsPath?: string;
|
|
49
|
+
fetchImpl?: FetchImpl;
|
|
50
|
+
stdout?: (line: string) => void;
|
|
51
|
+
stderr?: (line: string) => void;
|
|
52
|
+
}
|
|
53
|
+
type CommonOptions = FactoryCommonOptions;
|
|
54
|
+
/** Dry-run canned response — matches what the real /me + User lookup would return. */
|
|
55
|
+
export declare const DRY_RUN_USAGE_SAMPLE: UsageResponse;
|
|
56
|
+
/**
|
|
57
|
+
* Run the `usage` command. Calls `GET /me`, surfaces identity + any
|
|
58
|
+
* credits/plan fields the backend supplies. Absent fields are silently
|
|
59
|
+
* omitted (forward-compat until the backend adds the projection).
|
|
60
|
+
*/
|
|
61
|
+
export declare function runUsage(opts: CommonOptions, deps?: UsageDeps): Promise<UsageResponse>;
|
|
62
|
+
export declare function createUsageCommand(deps?: UsageDeps): Command;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `testsprite usage` — show the account's credit balance and plan/entitlement
|
|
3
|
+
* info as a proactive pre-flight before a large `test run` fan-out.
|
|
4
|
+
*
|
|
5
|
+
* Backend note: the `GET /me` endpoint does NOT currently return credit balance
|
|
6
|
+
* or plan info. This command calls `/me` for auth-identity fields and surfaces
|
|
7
|
+
* the `credits` / `subPlan` fields when and only when the backend supplies them
|
|
8
|
+
* (forward-compat / absent-safe). A dedicated backend endpoint is a required
|
|
9
|
+
* follow-up.
|
|
10
|
+
*
|
|
11
|
+
* BACKEND FOLLOW-UP REQUIRED:
|
|
12
|
+
* Add `credits`, `subPlan` to the `/me` response, or add a dedicated
|
|
13
|
+
* `GET /api/cli/v1/usage` endpoint returning `{ credits, subPlan, creditsPerRun }`.
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import { emitDryRunBanner, makeHttpClient, } from '../lib/client-factory.js';
|
|
17
|
+
import { loadConfig } from '../lib/config.js';
|
|
18
|
+
import { resolvePortalBase } from '../lib/facade.js';
|
|
19
|
+
import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
|
|
20
|
+
/** Dry-run canned response — matches what the real /me + User lookup would return. */
|
|
21
|
+
export const DRY_RUN_USAGE_SAMPLE = {
|
|
22
|
+
userId: '11111111-1111-4111-8111-111111111111',
|
|
23
|
+
keyId: 'key_dryrun_2026',
|
|
24
|
+
env: 'development',
|
|
25
|
+
credits: 42,
|
|
26
|
+
subPlan: 'Standard',
|
|
27
|
+
creditsPerRun: 2,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Run the `usage` command. Calls `GET /me`, surfaces identity + any
|
|
31
|
+
* credits/plan fields the backend supplies. Absent fields are silently
|
|
32
|
+
* omitted (forward-compat until the backend adds the projection).
|
|
33
|
+
*/
|
|
34
|
+
export async function runUsage(opts, deps = {}) {
|
|
35
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
36
|
+
const out = makeOutput(opts.output, deps);
|
|
37
|
+
if (opts.dryRun) {
|
|
38
|
+
emitDryRunBanner(stderr);
|
|
39
|
+
stderr('[note] credit balance requires a backend update — showing dry-run sample values');
|
|
40
|
+
out.print(DRY_RUN_USAGE_SAMPLE, data => renderUsage(data));
|
|
41
|
+
return DRY_RUN_USAGE_SAMPLE;
|
|
42
|
+
}
|
|
43
|
+
const client = makeHttpClient(opts, {
|
|
44
|
+
env: deps.env,
|
|
45
|
+
credentialsPath: deps.credentialsPath,
|
|
46
|
+
fetchImpl: deps.fetchImpl,
|
|
47
|
+
stderr: deps.stderr,
|
|
48
|
+
});
|
|
49
|
+
// Environment-correct portal origin for billing/upgrade links (dev and prod
|
|
50
|
+
// portals live on different domains — never hardcode). Resolved from the
|
|
51
|
+
// same credentials the client was just built from; undefined for unknown
|
|
52
|
+
// hosts (links then render as routes only).
|
|
53
|
+
const portalBase = resolvePortalBase(loadConfig({
|
|
54
|
+
profile: opts.profile,
|
|
55
|
+
endpointUrl: opts.endpointUrl,
|
|
56
|
+
env: deps.env,
|
|
57
|
+
credentialsPath: deps.credentialsPath,
|
|
58
|
+
}).apiUrl);
|
|
59
|
+
const billingUrl = portalBase !== undefined
|
|
60
|
+
? `${portalBase}/dashboard/settings/billing`
|
|
61
|
+
: 'the portal Billing page (/dashboard/settings/billing)';
|
|
62
|
+
// /me is the only available source of credits/plan today.
|
|
63
|
+
// When the backend adds credits/subPlan to MeResponse (or adds /usage),
|
|
64
|
+
// this single get call is sufficient — no code change needed in the CLI.
|
|
65
|
+
const me = await client.get('/me');
|
|
66
|
+
out.print(me, data => renderUsage(data, portalBase));
|
|
67
|
+
// In text mode, emit a backend-gap note when credits are missing so the
|
|
68
|
+
// user knows why the balance isn't shown (instead of assuming zero or error).
|
|
69
|
+
if (opts.output === 'text' && me.credits === undefined) {
|
|
70
|
+
stderr('[note] credit balance not available — backend does not yet expose credits on /me.' +
|
|
71
|
+
` Check ${billingUrl} for your current balance.`);
|
|
72
|
+
}
|
|
73
|
+
return me;
|
|
74
|
+
}
|
|
75
|
+
function renderUsage(u, portalBase) {
|
|
76
|
+
const lines = [];
|
|
77
|
+
// Identity block (always present)
|
|
78
|
+
lines.push(`userId: ${u.userId}`);
|
|
79
|
+
lines.push(`keyId: ${u.keyId}`);
|
|
80
|
+
lines.push(`env: ${u.env}`);
|
|
81
|
+
// Balance block — shown only when the backend supplies it
|
|
82
|
+
const hasBalanceData = u.credits !== undefined || u.subPlan !== undefined;
|
|
83
|
+
if (hasBalanceData) {
|
|
84
|
+
lines.push('');
|
|
85
|
+
lines.push('--- credits & plan ---');
|
|
86
|
+
if (u.subPlan !== undefined) {
|
|
87
|
+
lines.push(`plan: ${u.subPlan}`);
|
|
88
|
+
}
|
|
89
|
+
if (u.credits !== undefined) {
|
|
90
|
+
lines.push(`credits: ${u.credits}`);
|
|
91
|
+
}
|
|
92
|
+
if (u.creditsPerRun !== undefined) {
|
|
93
|
+
lines.push(`cost per frontend run: ${u.creditsPerRun} credit(s)`);
|
|
94
|
+
lines.push(`cost per backend run: 0 credit(s) (backend tests bill at code-generation, not at run time)`);
|
|
95
|
+
}
|
|
96
|
+
// Pre-flight hint: how many runs the current balance can fund
|
|
97
|
+
if (u.credits !== undefined && u.creditsPerRun !== undefined && u.creditsPerRun > 0) {
|
|
98
|
+
const maxRuns = Math.floor(u.credits / u.creditsPerRun);
|
|
99
|
+
lines.push(`can trigger: ~${maxRuns} run(s) at current balance`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Actionable upgrade line for Free or low-balance keys
|
|
103
|
+
const isLowBalance = u.credits !== undefined && u.creditsPerRun !== undefined && u.credits < u.creditsPerRun;
|
|
104
|
+
const isFree = u.subPlan?.toLowerCase() === 'free';
|
|
105
|
+
if (isLowBalance) {
|
|
106
|
+
lines.push('');
|
|
107
|
+
lines.push('warning: credit balance is below the per-run cost. Top up at:' +
|
|
108
|
+
` ${portalBase !== undefined ? `${portalBase}/dashboard/settings/billing` : 'the portal Billing page (/dashboard/settings/billing)'}`);
|
|
109
|
+
}
|
|
110
|
+
else if (isFree) {
|
|
111
|
+
lines.push('');
|
|
112
|
+
lines.push('note: on Free plan — upgrade for more credits and higher run limits:' +
|
|
113
|
+
` ${portalBase !== undefined ? `${portalBase}/pricing` : 'the portal Pricing page (/pricing)'}`);
|
|
114
|
+
}
|
|
115
|
+
return lines.join('\n');
|
|
116
|
+
}
|
|
117
|
+
export function createUsageCommand(deps = {}) {
|
|
118
|
+
const cmd = new Command('usage')
|
|
119
|
+
.alias('credits')
|
|
120
|
+
.description('Show credit balance and plan/entitlement info (proactive pre-flight before a large test run)')
|
|
121
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
122
|
+
.addHelpText('after', '\nExamples:\n' +
|
|
123
|
+
' testsprite usage # show balance + plan\n' +
|
|
124
|
+
' testsprite usage --output json # machine-readable balance\n' +
|
|
125
|
+
' testsprite credits # alias for usage\n' +
|
|
126
|
+
'\nNote: credit balance requires a backend update to /me. Until shipped,\n' +
|
|
127
|
+
" check your portal's Billing page (/dashboard/settings/billing) for your balance.")
|
|
128
|
+
.action(async (_cmdOpts, command) => {
|
|
129
|
+
await runUsage(resolveCommonOptions(command), deps);
|
|
130
|
+
});
|
|
131
|
+
return cmd;
|
|
132
|
+
}
|
|
133
|
+
function resolveCommonOptions(command) {
|
|
134
|
+
const globals = command.optsWithGlobals();
|
|
135
|
+
return {
|
|
136
|
+
profile: globals.profile ?? 'default',
|
|
137
|
+
output: globals.output ?? 'text',
|
|
138
|
+
endpointUrl: globals.endpointUrl,
|
|
139
|
+
debug: globals.debug ?? false,
|
|
140
|
+
verbose: globals.verbose ?? false,
|
|
141
|
+
dryRun: globals.dryRun ?? false,
|
|
142
|
+
requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function parseRequestTimeoutFlag(raw) {
|
|
146
|
+
if (raw === undefined)
|
|
147
|
+
return undefined;
|
|
148
|
+
const n = Number(raw);
|
|
149
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
150
|
+
return undefined;
|
|
151
|
+
return Math.round(n * 1000);
|
|
152
|
+
}
|
|
153
|
+
function makeOutput(mode, deps) {
|
|
154
|
+
return new Output(mode, { stdout: deps.stdout, stderr: deps.stderr });
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=usage.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command, CommanderError } from 'commander';
|
|
3
|
+
import { createAgentCommand } from './commands/agent.js';
|
|
4
|
+
import { createAuthCommand } from './commands/auth.js';
|
|
5
|
+
import { createInitCommand } from './commands/init.js';
|
|
6
|
+
import { createProjectCommand } from './commands/project.js';
|
|
7
|
+
import { createTestCommand } from './commands/test.js';
|
|
8
|
+
import { createUsageCommand } from './commands/usage.js';
|
|
9
|
+
import { ApiError, CLIError, RequestTimeoutError } from './lib/errors.js';
|
|
10
|
+
import { Output, isOutputMode } from './lib/output.js';
|
|
11
|
+
import { rephraseUnknownOption } from './lib/render-error.js';
|
|
12
|
+
import { VERSION } from './version.js';
|
|
13
|
+
const program = new Command();
|
|
14
|
+
// exitOverride() causes Commander to throw CommanderError instead of calling
|
|
15
|
+
// process.exit() directly, giving our catch block a chance to remap error
|
|
16
|
+
// exit codes (e.g. missing-argument → exit 5 per taxonomy).
|
|
17
|
+
program.exitOverride();
|
|
18
|
+
program
|
|
19
|
+
.name('testsprite')
|
|
20
|
+
.description('Official TestSprite command-line interface')
|
|
21
|
+
.version(VERSION)
|
|
22
|
+
.option('--output <mode>', 'Output format (json|text)', 'text')
|
|
23
|
+
.option('--profile <name>', 'Configuration profile to use')
|
|
24
|
+
.option('--endpoint-url <url>', 'Override the API endpoint host')
|
|
25
|
+
.option('--verbose', 'Emit human-readable HTTP retry / backoff / polling-mode transitions to stderr. Less noisy than --debug; useful for diagnosing hangs without the full trace.')
|
|
26
|
+
.option('--debug', 'Print HTTP method/path, request id, latency, retry decisions to stderr')
|
|
27
|
+
.option('--dry-run', 'Skip the network, credentials, and filesystem; emit a canned sample matching the OpenAPI contract. Useful for learning the CLI surface without an API key.')
|
|
28
|
+
.option('--request-timeout <seconds>', 'Client-side per-request timeout in seconds (default: 120). Aborts any single fetch that does not complete within this deadline. ' +
|
|
29
|
+
'Override via TESTSPRITE_REQUEST_TIMEOUT_MS env var (milliseconds). ' +
|
|
30
|
+
'Range: 1–600. Does not affect the --timeout polling ceiling for `test run/wait`.');
|
|
31
|
+
program.addCommand(createAgentCommand({}));
|
|
32
|
+
program.addCommand(createAuthCommand());
|
|
33
|
+
program.addCommand(createInitCommand({}));
|
|
34
|
+
program.addCommand(createProjectCommand({}));
|
|
35
|
+
program.addCommand(createTestCommand());
|
|
36
|
+
program.addCommand(createUsageCommand());
|
|
37
|
+
// Propagate exitOverride to every subcommand in the tree.
|
|
38
|
+
// Commander's addCommand() does NOT inherit exitOverride from the parent,
|
|
39
|
+
// so commands built externally (createTestCommand, createProjectCommand, …)
|
|
40
|
+
// and attached via addCommand() still have _exitCallback = null and call
|
|
41
|
+
// process.exit directly. Recursively set exitOverride so CommanderError
|
|
42
|
+
// bubbles up to our catch block for every leaf subcommand.
|
|
43
|
+
function applyExitOverrideDeep(cmd) {
|
|
44
|
+
cmd.exitOverride();
|
|
45
|
+
for (const child of cmd.commands) {
|
|
46
|
+
applyExitOverrideDeep(child);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
applyExitOverrideDeep(program);
|
|
50
|
+
program.configureOutput({
|
|
51
|
+
outputError(str, write) {
|
|
52
|
+
const rephrased = rephraseUnknownOption(str);
|
|
53
|
+
write(rephrased !== null ? `${rephrased}\n` : str);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
try {
|
|
57
|
+
await program.parseAsync(process.argv);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
const rawMode = program.opts().output;
|
|
61
|
+
const mode = isOutputMode(rawMode) ? rawMode : 'text';
|
|
62
|
+
if (err instanceof ApiError) {
|
|
63
|
+
if (mode === 'json') {
|
|
64
|
+
const envelope = {
|
|
65
|
+
error: {
|
|
66
|
+
code: err.code,
|
|
67
|
+
message: err.message,
|
|
68
|
+
nextAction: err.nextAction,
|
|
69
|
+
requestId: err.requestId,
|
|
70
|
+
details: err.details,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
process.stderr.write(`${JSON.stringify(envelope, null, 2)}\n`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
77
|
+
if (err.nextAction)
|
|
78
|
+
process.stderr.write(`${err.nextAction}\n`);
|
|
79
|
+
if (err.requestId && err.requestId !== 'local')
|
|
80
|
+
process.stderr.write(`requestId: ${err.requestId}\n`);
|
|
81
|
+
// C1: surface requiredScopes / grantedScopes on AUTH_FORBIDDEN
|
|
82
|
+
if (err.code === 'AUTH_FORBIDDEN') {
|
|
83
|
+
const required = err.getDetail('requiredScopes');
|
|
84
|
+
const granted = err.getDetail('grantedScopes');
|
|
85
|
+
if (Array.isArray(required) && required.length > 0) {
|
|
86
|
+
process.stderr.write(` required: ${required.join(', ')}\n`);
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(granted)) {
|
|
89
|
+
process.stderr.write(` granted: ${granted.join(', ')}\n`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
process.exit(err.exitCode);
|
|
94
|
+
}
|
|
95
|
+
const output = new Output(mode);
|
|
96
|
+
if (err instanceof RequestTimeoutError) {
|
|
97
|
+
// Structured rendering for per-request timeouts: JSON mode emits a
|
|
98
|
+
// machine-readable envelope; text mode emits the message with a hint.
|
|
99
|
+
if (mode === 'json') {
|
|
100
|
+
const envelope = {
|
|
101
|
+
error: {
|
|
102
|
+
code: 'REQUEST_TIMEOUT',
|
|
103
|
+
message: err.message,
|
|
104
|
+
nextAction: 'Increase --request-timeout <seconds> or set TESTSPRITE_REQUEST_TIMEOUT_MS. ' +
|
|
105
|
+
'Check that the backend is reachable and not overloaded.',
|
|
106
|
+
requestId: err.requestId,
|
|
107
|
+
details: { timeoutMs: err.timeoutMs },
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
process.stderr.write(`${JSON.stringify(envelope, null, 2)}\n`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
114
|
+
}
|
|
115
|
+
process.exit(err.exitCode);
|
|
116
|
+
}
|
|
117
|
+
if (err instanceof CommanderError) {
|
|
118
|
+
// Commander already wrote the error message (via configureOutput) or the
|
|
119
|
+
// help/version text to stdout. Map exit codes per the CLI taxonomy:
|
|
120
|
+
// help / version → 0 (user asked for it — no error)
|
|
121
|
+
// parse errors → 5 (VALIDATION_ERROR family: missing arg, invalid
|
|
122
|
+
// option, unknown command, etc.)
|
|
123
|
+
//
|
|
124
|
+
// Two distinct help codes exist in Commander 12:
|
|
125
|
+
// 'commander.helpDisplayed' — thrown by `-h/--help` flag handler
|
|
126
|
+
// 'commander.help' — thrown by the built-in `help [command]`
|
|
127
|
+
// subcommand (used by `test help`, `project
|
|
128
|
+
// help`, `help test`, etc.)
|
|
129
|
+
// Both are user-initiated "show me help" requests and must exit 0 per the
|
|
130
|
+
// AWS-CLI convention. Failing to map 'commander.help' caused these paths
|
|
131
|
+
// to fall through to the generic `process.exit(5)` branch (dogfood P1-4).
|
|
132
|
+
if (err.code === 'commander.helpDisplayed' ||
|
|
133
|
+
err.code === 'commander.help' ||
|
|
134
|
+
err.code === 'commander.version') {
|
|
135
|
+
process.exit(0);
|
|
136
|
+
}
|
|
137
|
+
process.exit(5);
|
|
138
|
+
}
|
|
139
|
+
if (err instanceof CLIError) {
|
|
140
|
+
output.error(err.message);
|
|
141
|
+
process.exit(err.exitCode);
|
|
142
|
+
}
|
|
143
|
+
output.error(err instanceof Error ? err.message : String(err));
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type AgentTarget = 'claude' | 'cursor' | 'cline' | 'antigravity' | 'codex';
|
|
2
|
+
export interface TargetSpec {
|
|
3
|
+
status: 'ga' | 'experimental';
|
|
4
|
+
/** repo-relative landing path, POSIX separators */
|
|
5
|
+
path: string;
|
|
6
|
+
/**
|
|
7
|
+
* 'own-file': the CLI owns the whole file (existing 4 targets).
|
|
8
|
+
* 'managed-section': the CLI writes only a sentinel-delimited section inside
|
|
9
|
+
* a potentially user-authored file (codex target, AGENTS.md).
|
|
10
|
+
*/
|
|
11
|
+
mode: 'own-file' | 'managed-section';
|
|
12
|
+
/** wrap the canonical body in this target's frontmatter/header */
|
|
13
|
+
wrap(body: string): string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SKILL_NAME = "testsprite-verify";
|
|
16
|
+
/**
|
|
17
|
+
* Mirrors skill-template.md frontmatter `description`. ≤1536 chars (claude cap).
|
|
18
|
+
* A unit test asserts byte-identity with the template file.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SKILL_DESCRIPTION = "TestSprite verification loop \u2014 after finishing a feature or fix in a TestSprite-tested repo, use the `testsprite` CLI to run the relevant TestSprite tests against the change and inspect any failure artifacts before reporting the work as done. Use whenever code has changed outside docs/config and is about to be reported complete \u2014 by running an existing test that covers the change, or by creating a new TestSprite test (a frontend plan, or a backend Python assertion) and running it to a terminal verdict.";
|
|
21
|
+
export declare const TARGETS: Record<AgentTarget, TargetSpec>;
|
|
22
|
+
/** Sentinel pair that bounds our managed section in AGENTS.md. */
|
|
23
|
+
export declare const MANAGED_SECTION_BEGIN = "<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->";
|
|
24
|
+
export declare const MANAGED_SECTION_END = "<!-- END TESTSPRITE AGENT SECTION -->";
|
|
25
|
+
type ReadFn = (url: URL) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Load the canonical skill body. `../assets/...` resolves to `src/assets/...`
|
|
28
|
+
* under vitest (source) and `dist/assets/...` in the built binary — postbuild
|
|
29
|
+
* copies the tree so both paths exist.
|
|
30
|
+
*
|
|
31
|
+
* Injectable `read` fn keeps unit tests off disk.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadSkillBody(read?: ReadFn): string;
|
|
34
|
+
/**
|
|
35
|
+
* Load the trimmed codex skill body (plain Markdown, no frontmatter).
|
|
36
|
+
* Designed for AGENTS.md managed-section injection.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadCodexSkillBody(read?: ReadFn): string;
|
|
39
|
+
/**
|
|
40
|
+
* Convenience for piece-2: returns the exact bytes to write for a target.
|
|
41
|
+
*
|
|
42
|
+
* For own-file targets, `body` defaults to the full skill body.
|
|
43
|
+
* For the codex managed-section target, the trimmed codex body is used instead —
|
|
44
|
+
* pass an explicit `body` to override in tests.
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderForTarget(t: AgentTarget, body?: string): {
|
|
47
|
+
path: string;
|
|
48
|
+
content: string;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
export const SKILL_NAME = 'testsprite-verify';
|
|
3
|
+
/**
|
|
4
|
+
* Mirrors skill-template.md frontmatter `description`. ≤1536 chars (claude cap).
|
|
5
|
+
* A unit test asserts byte-identity with the template file.
|
|
6
|
+
*/
|
|
7
|
+
export const SKILL_DESCRIPTION = 'TestSprite verification loop — after finishing a feature or fix in a TestSprite-tested repo, use the `testsprite` CLI to run the relevant TestSprite tests against the change and inspect any failure artifacts before reporting the work as done. Use whenever code has changed outside docs/config and is about to be reported complete — by running an existing test that covers the change, or by creating a new TestSprite test (a frontend plan, or a backend Python assertion) and running it to a terminal verdict.';
|
|
8
|
+
function wrapSkill(body) {
|
|
9
|
+
return `---\nname: ${SKILL_NAME}\ndescription: ${SKILL_DESCRIPTION}\n---\n\n${body}\n`;
|
|
10
|
+
}
|
|
11
|
+
function wrapMdc(body) {
|
|
12
|
+
return `---\ndescription: ${SKILL_DESCRIPTION}\nalwaysApply: false\n---\n\n${body}\n`;
|
|
13
|
+
}
|
|
14
|
+
export const TARGETS = {
|
|
15
|
+
claude: {
|
|
16
|
+
status: 'ga',
|
|
17
|
+
path: '.claude/skills/testsprite-verify/SKILL.md',
|
|
18
|
+
mode: 'own-file',
|
|
19
|
+
wrap: wrapSkill,
|
|
20
|
+
},
|
|
21
|
+
antigravity: {
|
|
22
|
+
status: 'experimental',
|
|
23
|
+
path: '.agents/skills/testsprite-verify/SKILL.md',
|
|
24
|
+
mode: 'own-file',
|
|
25
|
+
wrap: wrapSkill,
|
|
26
|
+
},
|
|
27
|
+
cursor: {
|
|
28
|
+
status: 'experimental',
|
|
29
|
+
path: '.cursor/rules/testsprite-verify.mdc',
|
|
30
|
+
mode: 'own-file',
|
|
31
|
+
wrap: wrapMdc,
|
|
32
|
+
},
|
|
33
|
+
cline: {
|
|
34
|
+
status: 'experimental',
|
|
35
|
+
path: '.clinerules/testsprite-verify.md',
|
|
36
|
+
mode: 'own-file',
|
|
37
|
+
wrap: body => body,
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* codex target — managed-section mode.
|
|
41
|
+
*
|
|
42
|
+
* Codex auto-loads AGENTS.md from the project root (always-on, 32 KiB budget
|
|
43
|
+
* for the whole file). Unlike own-file targets, we must NOT clobber a user's
|
|
44
|
+
* existing AGENTS.md: we write only a sentinel-delimited section so other
|
|
45
|
+
* project instructions coexist. The sentinel pair is the canonical identity
|
|
46
|
+
* marker; the content between them is ours to replace.
|
|
47
|
+
*
|
|
48
|
+
* --force with managed-section: replaces the section unconditionally but
|
|
49
|
+
* NEVER destroys content outside the sentinels. No whole-file .bak is written
|
|
50
|
+
* for a section-only change — only a whole-file backup makes sense if the
|
|
51
|
+
* entire file was ours to own (own-file mode). User content is never at risk.
|
|
52
|
+
*/
|
|
53
|
+
codex: {
|
|
54
|
+
status: 'experimental',
|
|
55
|
+
path: 'AGENTS.md',
|
|
56
|
+
mode: 'managed-section',
|
|
57
|
+
// wrap is a no-op for managed-section — content is authored as plain Markdown
|
|
58
|
+
// with no frontmatter (AGENTS.md is plain prose, not a skill schema).
|
|
59
|
+
wrap: body => body,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/** Sentinel pair that bounds our managed section in AGENTS.md. */
|
|
63
|
+
export const MANAGED_SECTION_BEGIN = '<!-- BEGIN TESTSPRITE AGENT SECTION (testsprite agent install codex) -->';
|
|
64
|
+
export const MANAGED_SECTION_END = '<!-- END TESTSPRITE AGENT SECTION -->';
|
|
65
|
+
const defaultRead = (url) => readFileSync(url, 'utf8');
|
|
66
|
+
/**
|
|
67
|
+
* Load the canonical skill body. `../assets/...` resolves to `src/assets/...`
|
|
68
|
+
* under vitest (source) and `dist/assets/...` in the built binary — postbuild
|
|
69
|
+
* copies the tree so both paths exist.
|
|
70
|
+
*
|
|
71
|
+
* Injectable `read` fn keeps unit tests off disk.
|
|
72
|
+
*/
|
|
73
|
+
export function loadSkillBody(read = defaultRead) {
|
|
74
|
+
return read(new URL('../assets/agent-skill/testsprite-verify.skill.md', import.meta.url));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Load the trimmed codex skill body (plain Markdown, no frontmatter).
|
|
78
|
+
* Designed for AGENTS.md managed-section injection.
|
|
79
|
+
*/
|
|
80
|
+
export function loadCodexSkillBody(read = defaultRead) {
|
|
81
|
+
return read(new URL('../assets/agent-skill/testsprite-verify.codex.md', import.meta.url));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Convenience for piece-2: returns the exact bytes to write for a target.
|
|
85
|
+
*
|
|
86
|
+
* For own-file targets, `body` defaults to the full skill body.
|
|
87
|
+
* For the codex managed-section target, the trimmed codex body is used instead —
|
|
88
|
+
* pass an explicit `body` to override in tests.
|
|
89
|
+
*/
|
|
90
|
+
export function renderForTarget(t, body) {
|
|
91
|
+
const spec = TARGETS[t];
|
|
92
|
+
const resolvedBody = body !== undefined
|
|
93
|
+
? body
|
|
94
|
+
: spec.mode === 'managed-section'
|
|
95
|
+
? loadCodexSkillBody()
|
|
96
|
+
: loadSkillBody();
|
|
97
|
+
return { path: spec.path, content: spec.wrap(resolvedBody) };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=agent-targets.js.map
|