@testsprite/testsprite-cli 0.4.0 → 0.5.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 +26 -1
- package/dist/commands/agent.js +17 -6
- package/dist/commands/auth.d.ts +46 -0
- package/dist/commands/auth.js +37 -2
- package/dist/commands/completion.d.ts +36 -0
- package/dist/commands/completion.js +111 -0
- package/dist/commands/doctor.js +20 -2
- package/dist/commands/init.d.ts +32 -1
- package/dist/commands/init.js +40 -10
- package/dist/commands/project.d.ts +77 -3
- package/dist/commands/project.js +176 -43
- package/dist/commands/test.d.ts +160 -10
- package/dist/commands/test.js +1261 -303
- package/dist/commands/usage.d.ts +56 -17
- package/dist/commands/usage.js +144 -29
- package/dist/index.js +132 -26
- package/dist/lib/browser.d.ts +6 -0
- package/dist/lib/browser.js +54 -0
- package/dist/lib/bundle.d.ts +32 -31
- package/dist/lib/bundle.js +125 -83
- package/dist/lib/client-factory.d.ts +23 -0
- package/dist/lib/client-factory.js +33 -1
- package/dist/lib/config.js +7 -3
- package/dist/lib/credentials.d.ts +17 -1
- package/dist/lib/credentials.js +175 -16
- package/dist/lib/dry-run/samples.js +15 -1
- package/dist/lib/errors.d.ts +6 -1
- package/dist/lib/errors.js +70 -19
- package/dist/lib/flaky.d.ts +12 -1
- package/dist/lib/flaky.js +7 -12
- package/dist/lib/gh-output.d.ts +62 -0
- package/dist/lib/gh-output.js +99 -0
- package/dist/lib/http.d.ts +33 -15
- package/dist/lib/http.js +68 -6
- package/dist/lib/org-render.d.ts +52 -0
- package/dist/lib/org-render.js +59 -0
- package/dist/lib/poll.js +1 -1
- package/dist/lib/render-error.d.ts +14 -0
- package/dist/lib/render-error.js +30 -0
- package/dist/lib/response-schemas.d.ts +83 -0
- package/dist/lib/response-schemas.js +272 -0
- package/dist/lib/runs.types.d.ts +53 -8
- package/dist/lib/skill-nudge.d.ts +17 -0
- package/dist/lib/skill-nudge.js +19 -0
- package/dist/lib/telemetry.d.ts +90 -0
- package/dist/lib/telemetry.js +171 -0
- package/dist/lib/text-table.d.ts +14 -0
- package/dist/lib/text-table.js +45 -0
- package/dist/lib/v3-advisory.d.ts +10 -1
- package/dist/lib/v3-advisory.js +12 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +16 -5
- package/schemas/plan.schema.json +61 -0
- package/skills/testsprite-verify.codex.md +2 -2
- package/skills/testsprite-verify.skill.md +3 -3
package/README.md
CHANGED
|
@@ -87,6 +87,31 @@ testsprite test rerun test_3a9f21c7 --wait --output json
|
|
|
87
87
|
# → exits 0: passed. The test now lives in your durable suite.
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
`./checkout-flow.plan.json` (the `--plan-from` argument above) is a JSON file describing the test in plain language — no browser code required. This is the exact, byte-identical output of `testsprite test create --plan-template` (also embedded verbatim in `test create --help`):
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"$schema": "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.4.0/schemas/plan.schema.json",
|
|
95
|
+
"projectId": "prj_abc123",
|
|
96
|
+
"type": "frontend",
|
|
97
|
+
"name": "Login rejects an empty password",
|
|
98
|
+
"planSteps": [
|
|
99
|
+
{
|
|
100
|
+
"type": "action",
|
|
101
|
+
"description": "Navigate to /login and submit the form with an empty password"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"type": "assertion",
|
|
105
|
+
"description": "Verify an inline error says the password is required"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Get this exact skeleton without hand-copying it (and without the risk of it drifting from your installed version — see below): `testsprite test create --plan-template`. Full field reference (including the `{{...}}`-placeholder caveat, size caps, and the `$schema` hook for live editor validation): [Plan file format](./DOCUMENTATION.md#plan-file-format).
|
|
112
|
+
|
|
113
|
+
> The `$schema` URL above is pinned to the CLI version that generated this doc (`v0.4.0`) — `--plan-template`'s live output always pins to **your installed version** instead, which is what actually resolves. If you're reading this on a later release, run the command yourself rather than trusting this snippet verbatim.
|
|
114
|
+
|
|
90
115
|
Prefer to configure each step by hand (or learn the surface offline with `--dry-run` first)? See [Manual setup](./DOCUMENTATION.md#manual-setup) and [Install & verify](./DOCUMENTATION.md#install--verify).
|
|
91
116
|
|
|
92
117
|
## Commands
|
|
@@ -114,7 +139,7 @@ Prefer to configure each step by hand (or learn the surface offline with `--dry-
|
|
|
114
139
|
| | `project create` / `project update` / `project delete` | Manage projects; `delete` removes a project and everything under it (`--confirm` required, no restore window) |
|
|
115
140
|
| | `project credential` / `project auto-auth` | Configure backend-test auth: a static injected credential, or auto-refresh login (Pro) |
|
|
116
141
|
| **Run** | `test run` | Trigger a fresh run; `--wait` blocks until terminal; `--all --project <id>` runs all tests in a project in wave order |
|
|
117
|
-
| | `test rerun` |
|
|
142
|
+
| | `test rerun` | Replay one/many tests (FE verbatim; BE with deps); billed as a run (0.5 credits FE / 0.2 BE); `--all --project <id>` reruns all tests |
|
|
118
143
|
| | `test flaky` | Replay a test several times (auto-heal off) and report a stability score |
|
|
119
144
|
| | `test wait` | Block on one or more `runId`s until terminal |
|
|
120
145
|
| | `test cancel` | Cancel one or more in-flight runs (Ctrl-C during `--wait` only detaches — `cancel` is the real stop) |
|
package/dist/commands/agent.js
CHANGED
|
@@ -359,7 +359,7 @@ export async function runInstall(opts, deps = {}) {
|
|
|
359
359
|
const bytes = Buffer.byteLength(section, 'utf8');
|
|
360
360
|
let wouldBeContent = section;
|
|
361
361
|
if (dryRunSt !== null) {
|
|
362
|
-
let existing
|
|
362
|
+
let existing;
|
|
363
363
|
try {
|
|
364
364
|
existing = await agentFs.readFile(abs);
|
|
365
365
|
}
|
|
@@ -746,18 +746,29 @@ function collect(v, prev) {
|
|
|
746
746
|
export function createAgentCommand(deps = {}) {
|
|
747
747
|
const agent = new Command('agent').description('Install TestSprite guidance into coding-agent config (Claude Code, Cursor, Cline, Antigravity, Kiro, Windsurf, Copilot, Codex)');
|
|
748
748
|
agent
|
|
749
|
-
.command('install')
|
|
750
|
-
.description('Write the TestSprite agent skills (verification loop + first-run onboarding) into a project for a coding agent'
|
|
751
|
-
|
|
749
|
+
.command('install [targets...]')
|
|
750
|
+
.description('Write the TestSprite agent skills (verification loop + first-run onboarding) into a project for a coding agent. ' +
|
|
751
|
+
'Target(s) may be given positionally (e.g. `agent install cursor codex`) and/or via --target; the two are merged.')
|
|
752
|
+
.option('--target <t>', 'Agent target(s): claude, cursor, cline, antigravity, kiro, windsurf, copilot, codex (comma-separated or repeated). Merged with any positional target(s).', collect, [])
|
|
752
753
|
.option('--skill <name>', `Skill(s) to install: ${Object.keys(SKILLS).join(', ')} (comma-separated or repeated; default: all)`, collect, [])
|
|
753
754
|
.option('--dir <path>', 'Project root to write into (default: cwd)')
|
|
754
755
|
.option('--force', 'For own-file targets: overwrite existing file (a .bak backup is kept). ' +
|
|
755
756
|
'For codex (managed-section): replaces the section unconditionally; user content outside the section is never destroyed.')
|
|
756
757
|
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
757
|
-
.action(async (
|
|
758
|
+
.action(async (
|
|
759
|
+
// Positional targets: `agent install cursor` previously parsed
|
|
760
|
+
// as zero targets (Commander silently drops undeclared positionals),
|
|
761
|
+
// silently falling through to the non-TTY default-to-claude path — so
|
|
762
|
+
// 7 of the 8 documented one-liners installed the WRONG agent's skill
|
|
763
|
+
// with zero signal. Declaring `[targets...]` captures them; they are
|
|
764
|
+
// merged with `--target` (order: positional first, then flag values)
|
|
765
|
+
// and flow through runInstall's existing parse/validate/dedupe pipeline
|
|
766
|
+
// unchanged, so an unknown name (positional or flag) still rejects with
|
|
767
|
+
// exit 5 instead of silently defaulting.
|
|
768
|
+
positionalTargets, cmdOpts, command) => {
|
|
758
769
|
await runInstall({
|
|
759
770
|
...resolveCommonOptions(command),
|
|
760
|
-
target: cmdOpts.target,
|
|
771
|
+
target: [...positionalTargets, ...cmdOpts.target],
|
|
761
772
|
skills: cmdOpts.skill,
|
|
762
773
|
dir: cmdOpts.dir,
|
|
763
774
|
force: Boolean(cmdOpts.force),
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
3
3
|
import type { FetchImpl } from '../lib/http.js';
|
|
4
|
+
import type { CliOrgBinding, CliOrgSummary } from '../lib/org-render.js';
|
|
4
5
|
export interface MeResponse {
|
|
5
6
|
userId: string;
|
|
6
7
|
keyId: string;
|
|
@@ -20,6 +21,40 @@ export interface MeResponse {
|
|
|
20
21
|
* so it is only rendered when present.
|
|
21
22
|
*/
|
|
22
23
|
v3Enabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Legacy per-user billing projections. Absent-safe; superseded by
|
|
26
|
+
* `activeOrg` when both are present. Declared so shared fixtures typed as
|
|
27
|
+
* `MeResponse` can carry them (the `usage` command has its own richer view).
|
|
28
|
+
*/
|
|
29
|
+
credits?: number;
|
|
30
|
+
subPlan?: string;
|
|
31
|
+
creditsPerRun?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The caller's organization (org-based billing subject). Absent-safe:
|
|
34
|
+
* rendered as a single `org:` line when present (V3-routed callers only).
|
|
35
|
+
*/
|
|
36
|
+
activeOrg?: {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
plan: string;
|
|
40
|
+
role: string;
|
|
41
|
+
remaining: number;
|
|
42
|
+
includedCredits: number;
|
|
43
|
+
seats: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Every organization the underlying user belongs to (account-wide
|
|
47
|
+
* membership list, personal org included). Independent of `org` below.
|
|
48
|
+
* Absent-safe: omitted on a server-side lookup failure or an older
|
|
49
|
+
* backend.
|
|
50
|
+
*/
|
|
51
|
+
organizations?: CliOrgSummary[];
|
|
52
|
+
/**
|
|
53
|
+
* The calling key's own org binding. Present only when the request
|
|
54
|
+
* authenticated with a Postgres-backed membership key (`sk-member-…`);
|
|
55
|
+
* absent for a legacy envelope key, which has no binding to echo.
|
|
56
|
+
*/
|
|
57
|
+
org?: CliOrgBinding;
|
|
23
58
|
}
|
|
24
59
|
export interface AuthDeps {
|
|
25
60
|
env?: NodeJS.ProcessEnv;
|
|
@@ -45,6 +80,17 @@ export interface AuthDeps {
|
|
|
45
80
|
type CommonOptions = FactoryCommonOptions;
|
|
46
81
|
interface ConfigureOptions extends CommonOptions {
|
|
47
82
|
fromEnv: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* When true and the active profile already has a saved API key, skip the
|
|
85
|
+
* interactive key prompt and proceed directly to the skill-install step.
|
|
86
|
+
* A CI-safe flag: lets `setup` run idempotently without prompting on
|
|
87
|
+
* machines that already have credentials (e.g. re-running setup to
|
|
88
|
+
* refresh the agent skill without re-entering the key).
|
|
89
|
+
*
|
|
90
|
+
* Ignored when an explicit `--api-key` or `--from-env` key source is
|
|
91
|
+
* provided -- those paths always overwrite, regardless of existing state.
|
|
92
|
+
*/
|
|
93
|
+
skipIfConfigured?: boolean;
|
|
48
94
|
}
|
|
49
95
|
export declare function runConfigure(opts: ConfigureOptions, deps?: AuthDeps): Promise<void>;
|
|
50
96
|
export declare function runWhoami(opts: CommonOptions, deps?: AuthDeps): Promise<MeResponse>;
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { assertValidEndpointUrl, emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
2
|
+
import { assertValidApiKey, assertValidEndpointUrl, emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../lib/client-factory.js';
|
|
3
3
|
import { ApiError, CLIError } from '../lib/errors.js';
|
|
4
4
|
import { facadeBaseUrl } from '../lib/facade.js';
|
|
5
5
|
import { HttpClient } from '../lib/http.js';
|
|
@@ -8,6 +8,7 @@ import { loadConfig, normalizeEnvVar } from '../lib/config.js';
|
|
|
8
8
|
import { emitDeprecationNotice } from '../lib/deprecate.js';
|
|
9
9
|
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
10
10
|
import { promptSecret } from '../lib/prompt.js';
|
|
11
|
+
import { formatOrgBinding, formatOrgsSummary, formatPersonalScopeHint } from '../lib/org-render.js';
|
|
11
12
|
import { emitV3RoutingAdvisory, routingLabel } from '../lib/v3-advisory.js';
|
|
12
13
|
const DEFAULT_API_URL = 'https://api.testsprite.com';
|
|
13
14
|
const FROM_ENV_MISSING_KEY = 'TESTSPRITE_API_KEY is not set in the environment. Set it and re-run with --from-env, or omit --from-env to enter the key interactively.';
|
|
@@ -61,9 +62,22 @@ export async function runConfigure(opts, deps = {}) {
|
|
|
61
62
|
throw validationError('TESTSPRITE_API_KEY', FROM_ENV_MISSING_KEY);
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
65
|
+
// --skip-if-configured: when a non-empty API key is already saved for
|
|
66
|
+
// this profile, skip the interactive prompt and return early. The
|
|
67
|
+
// key is NOT re-validated via GET /me on this path -- the caller
|
|
68
|
+
// (runInit) only reaches this when no explicit key source was given,
|
|
69
|
+
// and the subsequent whoami call in runInit will surface an expired
|
|
70
|
+
// key to the user anyway.
|
|
71
|
+
if (opts.skipIfConfigured && existingProfile?.apiKey) {
|
|
72
|
+
out.print({ profile: opts.profile, apiUrl, status: 'already_configured' }, data => {
|
|
73
|
+
const d = data;
|
|
74
|
+
return `Profile "${d.profile}" already configured. Endpoint: ${d.apiUrl}`;
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
64
78
|
const promptApi = deps.prompt ?? { secret: (q) => promptSecret(q) };
|
|
65
79
|
prelude(`Configuring profile "${opts.profile}".\n`);
|
|
66
|
-
// Only the API key is prompted
|
|
80
|
+
// Only the API key is prompted -- the endpoint defaults to prod (see above).
|
|
67
81
|
apiKey = (await promptApi.secret('TestSprite API key: ')).trim();
|
|
68
82
|
if (!apiKey)
|
|
69
83
|
throw new CLIError('No API key provided.', 5);
|
|
@@ -77,6 +91,9 @@ export async function runConfigure(opts, deps = {}) {
|
|
|
77
91
|
resolvedFromProfile !== DEFAULT_API_URL) {
|
|
78
92
|
stderr(`[advisory] Inheriting api_url from existing profile: ${resolvedFromProfile}`);
|
|
79
93
|
}
|
|
94
|
+
// Reject a malformed key up front — before any network — so `setup` fails
|
|
95
|
+
// fast with a VALIDATION_ERROR instead of a live ping or a raw Headers error.
|
|
96
|
+
assertValidApiKey(apiKey);
|
|
80
97
|
// Verify the key is accepted before persisting. Build an HttpClient
|
|
81
98
|
// directly (bypassing loadConfig) so we can test the candidate key+url
|
|
82
99
|
// before it is written to disk. This ensures we never overwrite a
|
|
@@ -167,8 +184,26 @@ export async function runWhoami(opts, deps = {}) {
|
|
|
167
184
|
`endpoint: ${resolvedEndpoint}`,
|
|
168
185
|
`env: ${m.env}`,
|
|
169
186
|
`scopes: ${m.scopes.join(', ')}`,
|
|
187
|
+
// Org context — confirms whose wallet a billable command will draw
|
|
188
|
+
// from, so it renders only for V3-routed callers (`v3Enabled` is the
|
|
189
|
+
// authoritative routing bit; field presence alone is not trusted).
|
|
190
|
+
...(m.v3Enabled === true && m.activeOrg
|
|
191
|
+
? [`org: ${m.activeOrg.name} (${m.activeOrg.plan}, ${m.activeOrg.role})`]
|
|
192
|
+
: []),
|
|
170
193
|
// Authoritative routing mode, rendered only when the backend supplies it.
|
|
171
194
|
...(m.v3Enabled !== undefined ? [`routing: ${routingLabel(m.v3Enabled)}`] : []),
|
|
195
|
+
// Org attribution — account-wide membership list, rendered only when
|
|
196
|
+
// the backend supplies a non-empty list.
|
|
197
|
+
...(formatOrgsSummary(m.organizations)
|
|
198
|
+
? [`orgs: ${formatOrgsSummary(m.organizations)}`]
|
|
199
|
+
: []),
|
|
200
|
+
// The calling key's own org binding — membership keys only.
|
|
201
|
+
...(formatOrgBinding(m.org) ? [`org binding: ${formatOrgBinding(m.org)}`] : []),
|
|
202
|
+
// A personal-scoped key held by someone who is also in a team: say so
|
|
203
|
+
// here rather than letting the team's projects just not show up.
|
|
204
|
+
...(formatPersonalScopeHint(m.organizations, m.org)
|
|
205
|
+
? [`note: ${formatPersonalScopeHint(m.organizations, m.org)}`]
|
|
206
|
+
: []),
|
|
172
207
|
];
|
|
173
208
|
// C2: warn in text mode when key cannot write/run
|
|
174
209
|
const missingScopes = ['write:tests', 'run:tests'].filter(s => !m.scopes.includes(s));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `testsprite completion [bash|zsh|fish]` — emit a shell completion script.
|
|
3
|
+
*
|
|
4
|
+
* The command names, per-group subcommands, and global flags are NOT hardcoded:
|
|
5
|
+
* `index.ts` builds a {@link CompletionSpec} by walking the fully-assembled
|
|
6
|
+
* Commander program and passes it in, so the generated script can never drift
|
|
7
|
+
* from the real command tree. `renderCompletion` is a pure function of the spec,
|
|
8
|
+
* which keeps it unit-testable without a live program.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* bash: eval "$(testsprite completion bash)" (add to ~/.bashrc)
|
|
12
|
+
* zsh: testsprite completion zsh > ~/.zsh/_testsprite (on your fpath)
|
|
13
|
+
* fish: testsprite completion fish | source (add to config.fish)
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
export declare const SUPPORTED_SHELLS: readonly ["bash", "zsh", "fish"];
|
|
17
|
+
export type Shell = (typeof SUPPORTED_SHELLS)[number];
|
|
18
|
+
export interface CompletionSpec {
|
|
19
|
+
/** Binary name, e.g. "testsprite". */
|
|
20
|
+
program: string;
|
|
21
|
+
/** Top-level command names. */
|
|
22
|
+
commands: string[];
|
|
23
|
+
/** command name -> its subcommand names (only groups that have subcommands). */
|
|
24
|
+
subcommands: Record<string, string[]>;
|
|
25
|
+
/** Global long option flags (e.g. "--output"). */
|
|
26
|
+
globalFlags: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface CompletionDeps {
|
|
29
|
+
env?: NodeJS.ProcessEnv;
|
|
30
|
+
stdout?: (line: string) => void;
|
|
31
|
+
}
|
|
32
|
+
export declare function isShell(value: string): value is Shell;
|
|
33
|
+
/** Best-effort shell detection from `$SHELL` (e.g. "/bin/zsh" -> "zsh"). */
|
|
34
|
+
export declare function detectShell(env: NodeJS.ProcessEnv): Shell | undefined;
|
|
35
|
+
export declare function renderCompletion(shell: Shell, spec: CompletionSpec): string;
|
|
36
|
+
export declare function createCompletionCommand(getSpec: () => CompletionSpec, deps?: CompletionDeps): Command;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `testsprite completion [bash|zsh|fish]` — emit a shell completion script.
|
|
3
|
+
*
|
|
4
|
+
* The command names, per-group subcommands, and global flags are NOT hardcoded:
|
|
5
|
+
* `index.ts` builds a {@link CompletionSpec} by walking the fully-assembled
|
|
6
|
+
* Commander program and passes it in, so the generated script can never drift
|
|
7
|
+
* from the real command tree. `renderCompletion` is a pure function of the spec,
|
|
8
|
+
* which keeps it unit-testable without a live program.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* bash: eval "$(testsprite completion bash)" (add to ~/.bashrc)
|
|
12
|
+
* zsh: testsprite completion zsh > ~/.zsh/_testsprite (on your fpath)
|
|
13
|
+
* fish: testsprite completion fish | source (add to config.fish)
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import { localValidationError } from '../lib/errors.js';
|
|
17
|
+
export const SUPPORTED_SHELLS = ['bash', 'zsh', 'fish'];
|
|
18
|
+
export function isShell(value) {
|
|
19
|
+
return SUPPORTED_SHELLS.includes(value);
|
|
20
|
+
}
|
|
21
|
+
/** Best-effort shell detection from `$SHELL` (e.g. "/bin/zsh" -> "zsh"). */
|
|
22
|
+
export function detectShell(env) {
|
|
23
|
+
const shellPath = env.SHELL ?? '';
|
|
24
|
+
const rawBase = shellPath.split(/[/\\]/).pop() ?? '';
|
|
25
|
+
const base = rawBase.toLowerCase().replace(/\.exe$/, '');
|
|
26
|
+
return isShell(base) ? base : undefined;
|
|
27
|
+
}
|
|
28
|
+
export function renderCompletion(shell, spec) {
|
|
29
|
+
switch (shell) {
|
|
30
|
+
case 'bash':
|
|
31
|
+
return renderBash(spec);
|
|
32
|
+
case 'zsh':
|
|
33
|
+
return renderZsh(spec);
|
|
34
|
+
case 'fish':
|
|
35
|
+
return renderFish(spec);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function renderBash(spec) {
|
|
39
|
+
const fn = `_${spec.program}_completion`;
|
|
40
|
+
const lines = [
|
|
41
|
+
`# ${spec.program} bash completion. Enable with: eval "$(${spec.program} completion bash)"`,
|
|
42
|
+
`${fn}() {`,
|
|
43
|
+
' local cur prev',
|
|
44
|
+
' cur="${COMP_WORDS[COMP_CWORD]}"',
|
|
45
|
+
' prev="${COMP_WORDS[COMP_CWORD-1]}"',
|
|
46
|
+
` local commands="${spec.commands.join(' ')}"`,
|
|
47
|
+
` local global_flags="${spec.globalFlags.join(' ')}"`,
|
|
48
|
+
' case "$prev" in',
|
|
49
|
+
...Object.entries(spec.subcommands).map(([group, subs]) => ` ${group}) COMPREPLY=( $(compgen -W "${subs.join(' ')}" -- "$cur") ); return;;`),
|
|
50
|
+
' esac',
|
|
51
|
+
' if [[ "$cur" == -* ]]; then',
|
|
52
|
+
' COMPREPLY=( $(compgen -W "$global_flags" -- "$cur") ); return',
|
|
53
|
+
' fi',
|
|
54
|
+
' COMPREPLY=( $(compgen -W "$commands" -- "$cur") )',
|
|
55
|
+
'}',
|
|
56
|
+
`complete -F ${fn} ${spec.program}`,
|
|
57
|
+
];
|
|
58
|
+
return lines.join('\n');
|
|
59
|
+
}
|
|
60
|
+
function renderZsh(spec) {
|
|
61
|
+
const fn = `_${spec.program}`;
|
|
62
|
+
const lines = [
|
|
63
|
+
`#compdef ${spec.program}`,
|
|
64
|
+
`# ${spec.program} zsh completion. Enable with: ${spec.program} completion zsh > "$fpath[1]/_${spec.program}"`,
|
|
65
|
+
`${fn}() {`,
|
|
66
|
+
' local -a commands',
|
|
67
|
+
` commands=(${spec.commands.join(' ')})`,
|
|
68
|
+
' if (( CURRENT == 2 )); then',
|
|
69
|
+
" _describe 'command' commands",
|
|
70
|
+
' return',
|
|
71
|
+
' fi',
|
|
72
|
+
' case "${words[2]}" in',
|
|
73
|
+
...Object.entries(spec.subcommands).map(([group, subs]) => ` ${group}) local -a subs; subs=(${subs.join(' ')}); _describe 'subcommand' subs;;`),
|
|
74
|
+
' esac',
|
|
75
|
+
'}',
|
|
76
|
+
`compdef ${fn} ${spec.program}`,
|
|
77
|
+
];
|
|
78
|
+
return lines.join('\n');
|
|
79
|
+
}
|
|
80
|
+
function renderFish(spec) {
|
|
81
|
+
const lines = [
|
|
82
|
+
`# ${spec.program} fish completion. Enable with: ${spec.program} completion fish | source`,
|
|
83
|
+
`complete -c ${spec.program} -f`,
|
|
84
|
+
...spec.commands.map(command => `complete -c ${spec.program} -n '__fish_use_subcommand' -a '${command}'`),
|
|
85
|
+
...Object.entries(spec.subcommands).flatMap(([group, subs]) => subs.map(sub => `complete -c ${spec.program} -n '__fish_seen_subcommand_from ${group}' -a '${sub}'`)),
|
|
86
|
+
...spec.globalFlags.map(flag => `complete -c ${spec.program} -l ${flag.replace(/^--/, '')}`),
|
|
87
|
+
];
|
|
88
|
+
return lines.join('\n');
|
|
89
|
+
}
|
|
90
|
+
export function createCompletionCommand(getSpec, deps = {}) {
|
|
91
|
+
return new Command('completion')
|
|
92
|
+
.description('Print a shell completion script (bash|zsh|fish)')
|
|
93
|
+
.argument('[shell]', 'Shell to generate for (bash|zsh|fish); auto-detected from $SHELL when omitted')
|
|
94
|
+
.addHelpText('after', '\nExamples:\n' +
|
|
95
|
+
' eval "$(testsprite completion bash)" # bash, current session\n' +
|
|
96
|
+
' testsprite completion zsh > ~/.zsh/_testsprite\n' +
|
|
97
|
+
' testsprite completion fish | source # fish, current session')
|
|
98
|
+
.action((shellArg, _cmdOpts) => {
|
|
99
|
+
const env = deps.env ?? process.env;
|
|
100
|
+
const shell = shellArg ?? detectShell(env);
|
|
101
|
+
if (shell === undefined) {
|
|
102
|
+
throw localValidationError('shell', `could not detect the shell from $SHELL; pass one explicitly (${SUPPORTED_SHELLS.join(', ')})`, [...SUPPORTED_SHELLS]);
|
|
103
|
+
}
|
|
104
|
+
if (!isShell(shell)) {
|
|
105
|
+
throw localValidationError('shell', `unsupported shell "${shell}"; use one of: ${SUPPORTED_SHELLS.join(', ')}`, [...SUPPORTED_SHELLS]);
|
|
106
|
+
}
|
|
107
|
+
const write = deps.stdout ?? ((line) => process.stdout.write(`${line}\n`));
|
|
108
|
+
write(renderCompletion(shell, getSpec()));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=completion.js.map
|
package/dist/commands/doctor.js
CHANGED
|
@@ -18,7 +18,8 @@ import { Command } from 'commander';
|
|
|
18
18
|
import { assertValidEndpointUrl, makeHttpClient, } from '../lib/client-factory.js';
|
|
19
19
|
import { loadConfig } from '../lib/config.js';
|
|
20
20
|
import { ApiError, CLIError, localValidationError } from '../lib/errors.js';
|
|
21
|
-
import {
|
|
21
|
+
import { formatOrgBinding, formatOrgsSummary, formatPersonalScopeHint } from '../lib/org-render.js';
|
|
22
|
+
import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
|
|
22
23
|
import { isVerifySkillInstalled } from '../lib/skill-nudge.js';
|
|
23
24
|
import { emitV3RoutingAdvisory, routingLabel } from '../lib/v3-advisory.js';
|
|
24
25
|
import { VERSION } from '../version.js';
|
|
@@ -60,6 +61,21 @@ export async function runDoctor(opts, deps = {}) {
|
|
|
60
61
|
: `${label} (default routing)`,
|
|
61
62
|
});
|
|
62
63
|
}
|
|
64
|
+
// Org attribution lines — only when the backend reported them (no new call).
|
|
65
|
+
const orgsSummary = formatOrgsSummary(connectivity.organizations);
|
|
66
|
+
if (orgsSummary) {
|
|
67
|
+
checks.push({ name: 'Organizations', status: 'ok', detail: orgsSummary });
|
|
68
|
+
}
|
|
69
|
+
const orgBinding = formatOrgBinding(connectivity.org);
|
|
70
|
+
if (orgBinding) {
|
|
71
|
+
checks.push({ name: 'Org binding', status: 'ok', detail: orgBinding });
|
|
72
|
+
}
|
|
73
|
+
// Warn, not fail: the key works — it just cannot see the team's work, which
|
|
74
|
+
// otherwise looks like missing data rather than a scoping choice.
|
|
75
|
+
const personalScopeHint = formatPersonalScopeHint(connectivity.organizations, connectivity.org);
|
|
76
|
+
if (personalScopeHint) {
|
|
77
|
+
checks.push({ name: 'Workspace scope', status: 'warn', detail: personalScopeHint });
|
|
78
|
+
}
|
|
63
79
|
checks.push(checkSkill(cwd, deps));
|
|
64
80
|
const failures = checks.filter(check => check.status === 'fail').length;
|
|
65
81
|
const warnings = checks.filter(check => check.status === 'warn').length;
|
|
@@ -154,6 +170,8 @@ async function checkConnectivity(opts, deps, ctx) {
|
|
|
154
170
|
return {
|
|
155
171
|
check: { name, status: 'ok', detail: `reached GET /me, API key accepted${who}` },
|
|
156
172
|
v3Enabled: me.v3Enabled,
|
|
173
|
+
organizations: me.organizations,
|
|
174
|
+
org: me.org,
|
|
157
175
|
};
|
|
158
176
|
}
|
|
159
177
|
catch (error) {
|
|
@@ -208,7 +226,7 @@ function resolveCommonOptions(command) {
|
|
|
208
226
|
const globals = command.optsWithGlobals();
|
|
209
227
|
return {
|
|
210
228
|
profile: globals.profile ?? 'default',
|
|
211
|
-
output: globals.output
|
|
229
|
+
output: resolveOutputMode(globals.output),
|
|
212
230
|
endpointUrl: globals.endpointUrl,
|
|
213
231
|
debug: globals.debug ?? false,
|
|
214
232
|
verbose: globals.verbose ?? false,
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { Command } from 'commander';
|
|
|
13
13
|
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
14
14
|
import type { AuthDeps } from './auth.js';
|
|
15
15
|
import type { AgentFs } from './agent.js';
|
|
16
|
+
import { type AgentTarget } from '../lib/agent-targets.js';
|
|
16
17
|
import type { FetchImpl } from '../lib/http.js';
|
|
17
18
|
type CommonOptions = FactoryCommonOptions;
|
|
18
19
|
/**
|
|
@@ -43,6 +44,12 @@ interface InitOptions extends CommonOptions {
|
|
|
43
44
|
force: boolean;
|
|
44
45
|
dir?: string;
|
|
45
46
|
yes: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* When true and the active profile already has a saved API key, skip the
|
|
49
|
+
* interactive key prompt. Forwarded verbatim to runConfigure. Has no
|
|
50
|
+
* effect when --api-key or --from-env is also given.
|
|
51
|
+
*/
|
|
52
|
+
skipIfConfigured?: boolean;
|
|
46
53
|
/** Set by the command action when both --agent and --no-agent appear in rawArgs. */
|
|
47
54
|
rawArgConflict?: boolean;
|
|
48
55
|
}
|
|
@@ -65,6 +72,24 @@ export interface InitSummary {
|
|
|
65
72
|
status: 'initialized';
|
|
66
73
|
}
|
|
67
74
|
export declare function runInit(opts: InitOptions, deps?: InitDeps): Promise<void>;
|
|
75
|
+
/** Raw Commander options shared by `setup` and the deprecated `init`/`auth configure` aliases. */
|
|
76
|
+
export interface SetupCmdOpts {
|
|
77
|
+
apiKey?: string;
|
|
78
|
+
fromEnv?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Commander sets `agent: false` (boolean) when `--no-agent` is given,
|
|
81
|
+
* because `--no-agent` negates the `--agent <target>` option. Handle both
|
|
82
|
+
* string and false shapes.
|
|
83
|
+
*/
|
|
84
|
+
agent: string | false;
|
|
85
|
+
noAgent?: boolean;
|
|
86
|
+
force?: boolean;
|
|
87
|
+
dir?: string;
|
|
88
|
+
yes?: boolean;
|
|
89
|
+
skipIfConfigured?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** Attach the onboarding flags shared by `setup` and the `init`/`auth configure` aliases. */
|
|
92
|
+
export declare function addSetupOptions(cmd: Command, validTargets: AgentTarget[], defaultAgent: AgentTarget): Command;
|
|
68
93
|
export declare function createSetupCommand(deps?: InitDeps): Command;
|
|
69
94
|
/**
|
|
70
95
|
* Hidden, deprecated `init` alias → runs `setup`. Kept so existing scripts and
|
|
@@ -78,6 +103,12 @@ export declare function createDeprecatedInitCommand(deps?: InitDeps): Command;
|
|
|
78
103
|
* consolidation, `auth configure` now runs FULL setup (configure + install)
|
|
79
104
|
* so an agent that reaches for the old command still ends up with the skill.
|
|
80
105
|
* `setup` is the ONLY path that writes credentials.
|
|
106
|
+
*
|
|
107
|
+
* Accepts the SAME `SetupCmdOpts` shape `setup` does — the alias previously
|
|
108
|
+
* only wired up `--from-env`, so README's "runs the full setup" claim didn't
|
|
109
|
+
* hold: `--yes`/`--agent`/`--api-key`/`--force`/`--dir`/`--no-agent` were all
|
|
110
|
+
* rejected as unknown options. `index.ts` attaches the full flag set via
|
|
111
|
+
* `addSetupOptions` before wiring this action.
|
|
81
112
|
*/
|
|
82
|
-
export declare function runConfigureViaSetup(command: Command, deps: InitDeps,
|
|
113
|
+
export declare function runConfigureViaSetup(command: Command, deps: InitDeps, cmdOpts: SetupCmdOpts): Promise<void>;
|
|
83
114
|
export {};
|
package/dist/commands/init.js
CHANGED
|
@@ -121,16 +121,23 @@ export async function runInit(opts, deps = {}) {
|
|
|
121
121
|
// -------------------------------------------------------------------------
|
|
122
122
|
const isTTY = deps.isTTY ?? Boolean(process.stdin.isTTY);
|
|
123
123
|
const hasKeySource = Boolean(opts.apiKey) || opts.fromEnv;
|
|
124
|
+
// --skip-if-configured counts as a key source when a saved key already exists:
|
|
125
|
+
// runConfigure will short-circuit before prompting, so no TTY is needed.
|
|
126
|
+
const credentialsPath = deps.credentialsPath;
|
|
127
|
+
const savedKey = credentialsPath
|
|
128
|
+
? readProfile(opts.profile, { path: credentialsPath })?.apiKey
|
|
129
|
+
: readProfile(opts.profile)?.apiKey;
|
|
130
|
+
const skipWillApply = Boolean(opts.skipIfConfigured) && Boolean(savedKey) && !hasKeySource;
|
|
124
131
|
// Non-interactive guard: no TTY + no key source → exit 5. Skipped under
|
|
125
132
|
// --dry-run, which is documented to work without credentials or network.
|
|
126
|
-
if (!isTTY && !hasKeySource && !opts.dryRun) {
|
|
133
|
+
if (!isTTY && !hasKeySource && !skipWillApply && !opts.dryRun) {
|
|
127
134
|
throw new CLIError('No API key available in non-interactive mode. ' +
|
|
128
135
|
'Pass --api-key <key>, --from-env (reads TESTSPRITE_API_KEY), or run interactively.', 5);
|
|
129
136
|
}
|
|
130
137
|
// JSON-output guard: an interactive secret prompt writes to stdout and would
|
|
131
138
|
// corrupt init's single-JSON-object output contract. In --output json mode
|
|
132
139
|
// require a non-interactive key source. Skipped under --dry-run (never prompts).
|
|
133
|
-
if (opts.output === 'json' && !hasKeySource && !opts.dryRun) {
|
|
140
|
+
if (opts.output === 'json' && !hasKeySource && !skipWillApply && !opts.dryRun) {
|
|
134
141
|
throw new CLIError('Interactive API-key prompt is unavailable in --output json mode (it would corrupt JSON stdout). ' +
|
|
135
142
|
'Pass --api-key <key> or --from-env.', 5);
|
|
136
143
|
}
|
|
@@ -139,7 +146,13 @@ export async function runInit(opts, deps = {}) {
|
|
|
139
146
|
// -------------------------------------------------------------------------
|
|
140
147
|
if (opts.dryRun) {
|
|
141
148
|
stderrFn('[dry-run] no writes or network calls — preview only');
|
|
142
|
-
stderrFn(`[dry-run] would configure profile="${opts.profile}" (key source: ${opts.apiKey
|
|
149
|
+
stderrFn(`[dry-run] would configure profile="${opts.profile}" (key source: ${opts.apiKey
|
|
150
|
+
? 'flag'
|
|
151
|
+
: opts.fromEnv
|
|
152
|
+
? 'env'
|
|
153
|
+
: opts.skipIfConfigured
|
|
154
|
+
? 'skip-if-configured'
|
|
155
|
+
: 'prompt'})`);
|
|
143
156
|
const agentTarget = opts.noAgent ? null : opts.agent;
|
|
144
157
|
if (!opts.noAgent) {
|
|
145
158
|
// Delegate to runInstall's own dry-run for the file-listing preview.
|
|
@@ -170,7 +183,12 @@ export async function runInit(opts, deps = {}) {
|
|
|
170
183
|
// --api-key takes precedence over --from-env: when an explicit key is supplied,
|
|
171
184
|
// force fromEnv=false so runConfigure uses the injected key (toAuthDeps wires it
|
|
172
185
|
// as the prompt) instead of reading TESTSPRITE_API_KEY from the environment (codex).
|
|
173
|
-
await runConfigure({
|
|
186
|
+
await runConfigure({
|
|
187
|
+
...opts,
|
|
188
|
+
fromEnv: opts.apiKey ? false : opts.fromEnv,
|
|
189
|
+
// --api-key always overwrites; skip only applies when no explicit key source was given.
|
|
190
|
+
skipIfConfigured: opts.apiKey ? false : opts.skipIfConfigured,
|
|
191
|
+
},
|
|
174
192
|
// commandTag:'init' tags ONLY this configure-validate GET /me with
|
|
175
193
|
// `X-CLI-Command: init` → counted as cli.initialized. The whoami banner call
|
|
176
194
|
// below builds deps WITHOUT a tag, so init emits exactly one cli.initialized.
|
|
@@ -195,9 +213,13 @@ export async function runInit(opts, deps = {}) {
|
|
|
195
213
|
try {
|
|
196
214
|
me = await runWhoami(opts, whoamiDeps);
|
|
197
215
|
}
|
|
198
|
-
catch {
|
|
216
|
+
catch (err) {
|
|
199
217
|
// Whoami is display-only. If it fails after a successful configure,
|
|
200
218
|
// continue with a minimal placeholder so the summary still prints.
|
|
219
|
+
if (opts.debug) {
|
|
220
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
221
|
+
stderrFn(`[debug] setup identity lookup failed after configure: ${reason}`);
|
|
222
|
+
}
|
|
201
223
|
me = { userId: '', keyId: '', scopes: [], env: 'production' };
|
|
202
224
|
}
|
|
203
225
|
// -------------------------------------------------------------------------
|
|
@@ -339,8 +361,8 @@ function resolveCommonOptions(command) {
|
|
|
339
361
|
};
|
|
340
362
|
}
|
|
341
363
|
const SETUP_DESCRIPTION = 'Set up TestSprite: configure your API key and install the TestSprite agent skills for your coding agent';
|
|
342
|
-
/** Attach the onboarding flags shared by `setup` and the `init`
|
|
343
|
-
function addSetupOptions(cmd, validTargets, defaultAgent) {
|
|
364
|
+
/** Attach the onboarding flags shared by `setup` and the `init`/`auth configure` aliases. */
|
|
365
|
+
export function addSetupOptions(cmd, validTargets, defaultAgent) {
|
|
344
366
|
return cmd
|
|
345
367
|
.option('--api-key <key>', 'API key to configure (skips the interactive prompt)')
|
|
346
368
|
.option('--from-env', 'Read TESTSPRITE_API_KEY from the environment instead of prompting', false)
|
|
@@ -348,7 +370,8 @@ function addSetupOptions(cmd, validTargets, defaultAgent) {
|
|
|
348
370
|
.option('--no-agent', 'Skip the agent skill install (configure credentials only)')
|
|
349
371
|
.option('--force', 'Overwrite an existing skill file (a .bak backup is kept)')
|
|
350
372
|
.option('--dir <path>', 'Project root for the skill install (default: current directory)')
|
|
351
|
-
.option('-y, --yes', 'Non-interactive: accept all defaults, never prompt')
|
|
373
|
+
.option('-y, --yes', 'Non-interactive: accept all defaults, never prompt')
|
|
374
|
+
.option('--skip-if-configured', 'Skip the API key prompt when credentials already exist for this profile (CI-safe idempotent re-run)');
|
|
352
375
|
}
|
|
353
376
|
/** Build {@link InitOptions} from raw Commander opts + globals. */
|
|
354
377
|
function buildSetupOptions(cmdOpts, command, defaultAgent) {
|
|
@@ -380,6 +403,7 @@ function buildSetupOptions(cmdOpts, command, defaultAgent) {
|
|
|
380
403
|
force: Boolean(cmdOpts.force),
|
|
381
404
|
dir: cmdOpts.dir,
|
|
382
405
|
yes: Boolean(cmdOpts.yes),
|
|
406
|
+
skipIfConfigured: Boolean(cmdOpts.skipIfConfigured),
|
|
383
407
|
rawArgConflict,
|
|
384
408
|
};
|
|
385
409
|
}
|
|
@@ -426,8 +450,14 @@ export function createDeprecatedInitCommand(deps = {}) {
|
|
|
426
450
|
* consolidation, `auth configure` now runs FULL setup (configure + install)
|
|
427
451
|
* so an agent that reaches for the old command still ends up with the skill.
|
|
428
452
|
* `setup` is the ONLY path that writes credentials.
|
|
453
|
+
*
|
|
454
|
+
* Accepts the SAME `SetupCmdOpts` shape `setup` does — the alias previously
|
|
455
|
+
* only wired up `--from-env`, so README's "runs the full setup" claim didn't
|
|
456
|
+
* hold: `--yes`/`--agent`/`--api-key`/`--force`/`--dir`/`--no-agent` were all
|
|
457
|
+
* rejected as unknown options. `index.ts` attaches the full flag set via
|
|
458
|
+
* `addSetupOptions` before wiring this action.
|
|
429
459
|
*/
|
|
430
|
-
export async function runConfigureViaSetup(command, deps,
|
|
431
|
-
await runSetupAction(
|
|
460
|
+
export async function runConfigureViaSetup(command, deps, cmdOpts) {
|
|
461
|
+
await runSetupAction(cmdOpts, command, deps, 'claude');
|
|
432
462
|
}
|
|
433
463
|
//# sourceMappingURL=init.js.map
|