@testsprite/testsprite-cli 0.3.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.
Files changed (63) hide show
  1. package/README.md +55 -29
  2. package/dist/commands/agent.js +17 -6
  3. package/dist/commands/auth.d.ts +51 -0
  4. package/dist/commands/auth.js +46 -2
  5. package/dist/commands/completion.d.ts +36 -0
  6. package/dist/commands/completion.js +111 -0
  7. package/dist/commands/doctor.js +56 -16
  8. package/dist/commands/init.d.ts +32 -1
  9. package/dist/commands/init.js +40 -10
  10. package/dist/commands/project.d.ts +102 -4
  11. package/dist/commands/project.js +250 -47
  12. package/dist/commands/test.d.ts +253 -11
  13. package/dist/commands/test.js +1822 -390
  14. package/dist/commands/usage.d.ts +56 -17
  15. package/dist/commands/usage.js +144 -29
  16. package/dist/index.js +172 -29
  17. package/dist/lib/browser.d.ts +6 -0
  18. package/dist/lib/browser.js +54 -0
  19. package/dist/lib/bundle.d.ts +32 -31
  20. package/dist/lib/bundle.js +144 -84
  21. package/dist/lib/client-factory.d.ts +29 -0
  22. package/dist/lib/client-factory.js +49 -1
  23. package/dist/lib/config.js +7 -3
  24. package/dist/lib/credentials.d.ts +17 -1
  25. package/dist/lib/credentials.js +175 -16
  26. package/dist/lib/dry-run/samples.js +51 -1
  27. package/dist/lib/errors.d.ts +33 -1
  28. package/dist/lib/errors.js +110 -19
  29. package/dist/lib/failing-fe-resolver.d.ts +15 -0
  30. package/dist/lib/failing-fe-resolver.js +49 -1
  31. package/dist/lib/flaky.d.ts +12 -1
  32. package/dist/lib/flaky.js +7 -12
  33. package/dist/lib/gh-output.d.ts +62 -0
  34. package/dist/lib/gh-output.js +99 -0
  35. package/dist/lib/http.d.ts +86 -16
  36. package/dist/lib/http.js +181 -11
  37. package/dist/lib/interrupt.d.ts +65 -10
  38. package/dist/lib/interrupt.js +94 -9
  39. package/dist/lib/org-render.d.ts +52 -0
  40. package/dist/lib/org-render.js +59 -0
  41. package/dist/lib/poll.d.ts +11 -0
  42. package/dist/lib/poll.js +71 -6
  43. package/dist/lib/render-error.d.ts +14 -0
  44. package/dist/lib/render-error.js +30 -0
  45. package/dist/lib/response-schemas.d.ts +83 -0
  46. package/dist/lib/response-schemas.js +272 -0
  47. package/dist/lib/runs.types.d.ts +62 -8
  48. package/dist/lib/skill-nudge.d.ts +17 -0
  49. package/dist/lib/skill-nudge.js +19 -0
  50. package/dist/lib/telemetry.d.ts +90 -0
  51. package/dist/lib/telemetry.js +171 -0
  52. package/dist/lib/text-table.d.ts +14 -0
  53. package/dist/lib/text-table.js +45 -0
  54. package/dist/lib/v3-advisory.d.ts +22 -0
  55. package/dist/lib/v3-advisory.js +32 -0
  56. package/dist/lib/version-notice.d.ts +37 -0
  57. package/dist/lib/version-notice.js +87 -0
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/package.json +16 -5
  61. package/schemas/plan.schema.json +61 -0
  62. package/skills/testsprite-verify.codex.md +8 -2
  63. package/skills/testsprite-verify.skill.md +18 -7
@@ -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, fromEnv: boolean): Promise<void>;
113
+ export declare function runConfigureViaSetup(command: Command, deps: InitDeps, cmdOpts: SetupCmdOpts): Promise<void>;
83
114
  export {};
@@ -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 ? 'flag' : opts.fromEnv ? 'env' : 'prompt'})`);
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({ ...opts, fromEnv: opts.apiKey ? false : opts.fromEnv },
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` alias. */
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, fromEnv) {
431
- await runSetupAction({ agent: 'claude', fromEnv }, command, deps, 'claude');
460
+ export async function runConfigureViaSetup(command, deps, cmdOpts) {
461
+ await runSetupAction(cmdOpts, command, deps, 'claude');
432
462
  }
433
463
  //# sourceMappingURL=init.js.map
@@ -9,6 +9,38 @@ export interface CliProject {
9
9
  createdFrom: 'portal' | 'mcp' | 'cli';
10
10
  createdAt: string;
11
11
  updatedAt: string;
12
+ /**
13
+ * Owning organization id + human-readable name. Additive + absent-safe:
14
+ * populated only for a membership-key (`sk-member-…`) caller on `project list`
15
+ * (org attribution across the caller's org-scoped view); `project get`
16
+ * does not populate them today even for a bound key. `orgName` may be
17
+ * absent even when `orgId` is present (best-effort name lookup). Legacy
18
+ * (unbound) callers never see either field.
19
+ */
20
+ orgId?: string;
21
+ orgName?: string;
22
+ /**
23
+ * The project's default target/environment URL, or `null` when the project has
24
+ * none configured.
25
+ *
26
+ * **Absent vs. `null` is load-bearing here.** `null` means "the server resolved
27
+ * it and this project has no URL configured" — actionable, so the renderer
28
+ * prints the `project update … --url` remedy. **Absent** means "no answer", and
29
+ * the server uses it for every case where a remedy would be a lie: an older
30
+ * backend, the `list` endpoint (which would pay an extra read per row), a
31
+ * resolution that failed (a transient outage must never be reported as "no URL
32
+ * set"), and a V2 backend project (V2 backend runs resolve no project URL at
33
+ * all, so there is nothing to report and nothing `--url` would change).
34
+ *
35
+ * So the renderer must key on presence, not truthiness: printing "(not set)"
36
+ * for an absent field would report every project on an older backend — and
37
+ * every project in a `list` — as having no URL, including the ones that do.
38
+ *
39
+ * A backend project with no URL is not merely cosmetic: on the V3 execution
40
+ * path the first run of any of its tests is rejected `no-target-resolvable`
41
+ * (see the `project create --type backend` note in CLAUDE.md).
42
+ */
43
+ targetUrl?: string | null;
12
44
  }
13
45
  export interface ProjectDeps {
14
46
  env?: NodeJS.ProcessEnv;
@@ -22,6 +54,8 @@ interface ListOptions extends CommonOptions {
22
54
  pageSize?: number;
23
55
  startingToken?: string;
24
56
  maxItems?: number;
57
+ columns?: string;
58
+ noHeader?: boolean;
25
59
  }
26
60
  export declare function runList(opts: ListOptions, deps?: ProjectDeps): Promise<Page<CliProject>>;
27
61
  interface GetOptions extends CommonOptions {
@@ -32,12 +66,38 @@ export interface CliCreateProjectRequest {
32
66
  type: 'frontend' | 'backend';
33
67
  name: string;
34
68
  targetUrl?: string;
35
- description?: string;
36
69
  username?: string;
37
70
  password?: string;
38
71
  instruction?: string;
39
72
  }
40
- export type CliCreateProjectResponse = CliProject;
73
+ /**
74
+ * Response shape for `POST /projects`.
75
+ *
76
+ * The validation sweep found the LIVE `POST /projects`
77
+ * response keying its id as `projectId` (matching `CliDeleteProjectResponse`'s
78
+ * convention), not `id` like the read paths (`GET /projects`, `GET
79
+ * /projects/{id}` — those are proven-`id` via the dev-e2e smoke test) — and
80
+ * possibly omitting `targetUrl`/`updatedAt` entirely. Rather than guess which
81
+ * single shape is "the real one" and risk flipping the drift instead of
82
+ * fixing it, both id field names are accepted here (and normalized — see
83
+ * `resolveCreatedProjectId` — so JSON consumers keyed on either `id` or
84
+ * `projectId` keep working), and `targetUrl`/`updatedAt` are optional.
85
+ */
86
+ export interface CliCreateProjectResponse {
87
+ /** Preferred — matches the live backend's response and `project delete`'s `projectId`. */
88
+ projectId?: string;
89
+ /** Legacy/fallback name; some responses (and the read paths) use this instead. */
90
+ id?: string;
91
+ name: string;
92
+ type: 'frontend' | 'backend';
93
+ createdFrom: 'portal' | 'mcp' | 'cli';
94
+ createdAt: string;
95
+ /** Absent-safe: not guaranteed on every backend response. */
96
+ updatedAt?: string;
97
+ targetUrl?: string;
98
+ }
99
+ /** Resolve the created project's id regardless of which field name the backend used. */
100
+ export declare function resolveCreatedProjectId(r: CliCreateProjectResponse): string | undefined;
41
101
  interface CreateOptions extends CommonOptions {
42
102
  type: 'frontend' | 'backend';
43
103
  name: string;
@@ -50,12 +110,25 @@ interface CreateOptions extends CommonOptions {
50
110
  idempotencyKey?: string;
51
111
  }
52
112
  export declare function runCreate(opts: CreateOptions, deps?: ProjectDeps): Promise<CliCreateProjectResponse>;
113
+ /**
114
+ * Response shape for `PATCH /projects/{id}`.
115
+ *
116
+ * Same `id`-field drift as `CliCreateProjectResponse` — both
117
+ * names are accepted and normalized (see `resolveUpdatedProjectId`), and
118
+ * `updatedAt` is optional since the live response may omit it.
119
+ */
53
120
  export interface CliUpdateProjectResponse {
54
- id: string;
121
+ /** Preferred — matches the live backend's response and `project delete`'s `projectId`. */
122
+ projectId?: string;
123
+ /** Legacy/fallback name; some responses use this instead. */
124
+ id?: string;
55
125
  /** Backend may omit this field; treat absence as no specific fields reported. */
56
126
  updatedFields?: string[];
57
- updatedAt: string;
127
+ /** Absent-safe: not guaranteed on every backend response. */
128
+ updatedAt?: string;
58
129
  }
130
+ /** Resolve the updated project's id regardless of which field name the backend used. */
131
+ export declare function resolveUpdatedProjectId(r: CliUpdateProjectResponse): string | undefined;
59
132
  interface UpdateOptions extends CommonOptions {
60
133
  projectId: string;
61
134
  name?: string;
@@ -67,6 +140,31 @@ interface UpdateOptions extends CommonOptions {
67
140
  idempotencyKey?: string;
68
141
  }
69
142
  export declare function runUpdate(opts: UpdateOptions, deps?: ProjectDeps): Promise<CliUpdateProjectResponse>;
143
+ export interface CliDeleteProjectResponse {
144
+ projectId: string;
145
+ deletedAt: string;
146
+ }
147
+ interface DeleteOptions extends CommonOptions {
148
+ projectId: string;
149
+ /** Hard gate — required (unless `--dry-run` is set). No interactive prompts. */
150
+ confirm: boolean;
151
+ /** Caller-supplied idempotency token; UUIDv4 minted client-side if absent. */
152
+ idempotencyKey?: string;
153
+ }
154
+ /**
155
+ * `project delete <project-id> --confirm` — permanent cascade delete via
156
+ * DELETE /projects/{id}.
157
+ *
158
+ * The server deletes the project together with everything under it — its
159
+ * frontend/backend sub-projects, all their tests, and backend fixtures —
160
+ * matching the Portal's own delete behavior. There is no restore window.
161
+ *
162
+ * **`--confirm` is required** (unless `--dry-run`). Without either, the CLI
163
+ * exits 5 `VALIDATION_ERROR` with a typed envelope explaining the convention.
164
+ * The CLI never prompts interactively (CI-friendly contract). Re-delete on an already-deleted (or missing) project returns 404 from
165
+ * the server; the CLI surfaces the envelope as-is (exit 4), no client branching.
166
+ */
167
+ export declare function runDelete(opts: DeleteOptions, deps?: ProjectDeps): Promise<CliDeleteProjectResponse>;
70
168
  export interface CliProjectCredentialResponse {
71
169
  projectId: string;
72
170
  authType: string;