@testsprite/testsprite-cli 0.4.0 → 0.6.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 (56) hide show
  1. package/README.md +27 -1
  2. package/dist/commands/agent.js +17 -6
  3. package/dist/commands/auth.d.ts +46 -0
  4. package/dist/commands/auth.js +37 -2
  5. package/dist/commands/completion.d.ts +36 -0
  6. package/dist/commands/completion.js +111 -0
  7. package/dist/commands/doctor.js +20 -2
  8. package/dist/commands/init.d.ts +32 -1
  9. package/dist/commands/init.js +40 -10
  10. package/dist/commands/project.d.ts +77 -3
  11. package/dist/commands/project.js +176 -43
  12. package/dist/commands/test.d.ts +200 -10
  13. package/dist/commands/test.js +1636 -351
  14. package/dist/commands/usage.d.ts +56 -17
  15. package/dist/commands/usage.js +144 -29
  16. package/dist/index.js +132 -26
  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 +125 -83
  21. package/dist/lib/client-factory.d.ts +23 -0
  22. package/dist/lib/client-factory.js +33 -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 +15 -1
  27. package/dist/lib/errors.d.ts +6 -1
  28. package/dist/lib/errors.js +70 -19
  29. package/dist/lib/flaky.d.ts +12 -1
  30. package/dist/lib/flaky.js +7 -12
  31. package/dist/lib/gh-output.d.ts +84 -0
  32. package/dist/lib/gh-output.js +202 -0
  33. package/dist/lib/http.d.ts +33 -15
  34. package/dist/lib/http.js +141 -7
  35. package/dist/lib/org-render.d.ts +52 -0
  36. package/dist/lib/org-render.js +59 -0
  37. package/dist/lib/poll.js +72 -36
  38. package/dist/lib/render-error.d.ts +14 -0
  39. package/dist/lib/render-error.js +30 -0
  40. package/dist/lib/response-schemas.d.ts +83 -0
  41. package/dist/lib/response-schemas.js +282 -0
  42. package/dist/lib/runs.types.d.ts +53 -8
  43. package/dist/lib/skill-nudge.d.ts +17 -0
  44. package/dist/lib/skill-nudge.js +19 -0
  45. package/dist/lib/telemetry.d.ts +90 -0
  46. package/dist/lib/telemetry.js +171 -0
  47. package/dist/lib/text-table.d.ts +14 -0
  48. package/dist/lib/text-table.js +45 -0
  49. package/dist/lib/v3-advisory.d.ts +30 -1
  50. package/dist/lib/v3-advisory.js +35 -4
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +17 -5
  54. package/schemas/plan.schema.json +61 -0
  55. package/skills/testsprite-verify.codex.md +2 -2
  56. package/skills/testsprite-verify.skill.md +3 -3
@@ -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 {
@@ -36,7 +70,34 @@ export interface CliCreateProjectRequest {
36
70
  password?: string;
37
71
  instruction?: string;
38
72
  }
39
- 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;
40
101
  interface CreateOptions extends CommonOptions {
41
102
  type: 'frontend' | 'backend';
42
103
  name: string;
@@ -49,12 +110,25 @@ interface CreateOptions extends CommonOptions {
49
110
  idempotencyKey?: string;
50
111
  }
51
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
+ */
52
120
  export interface CliUpdateProjectResponse {
53
- 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;
54
125
  /** Backend may omit this field; treat absence as no specific fields reported. */
55
126
  updatedFields?: string[];
56
- updatedAt: string;
127
+ /** Absent-safe: not guaranteed on every backend response. */
128
+ updatedAt?: string;
57
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;
58
132
  interface UpdateOptions extends CommonOptions {
59
133
  projectId: string;
60
134
  name?: string;
@@ -5,6 +5,7 @@ import { emitDryRunBanner, makeHttpClient, parseRequestTimeoutFlag, } from '../l
5
5
  import { ApiError } from '../lib/errors.js';
6
6
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
7
7
  import { assertNotLocal } from '../lib/target-url.js';
8
+ import { renderTextTable, resolveTextColumns } from '../lib/text-table.js';
8
9
  import { assertIdempotencyKey } from '../lib/validate.js';
9
10
  import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
10
11
  export async function runList(opts, deps = {}) {
@@ -14,6 +15,9 @@ export async function runList(opts, deps = {}) {
14
15
  startingToken: opts.startingToken,
15
16
  maxItems: opts.maxItems,
16
17
  });
18
+ if (opts.output === 'text') {
19
+ resolveTextColumns(opts.columns, PROJECT_LIST_COLUMNS);
20
+ }
17
21
  const client = makeClient(opts, deps);
18
22
  // When the user explicitly passed a page-size flag and did NOT ask
19
23
  // for --max-items, treat that as a "give me one page and the cursor"
@@ -30,7 +34,7 @@ export async function runList(opts, deps = {}) {
30
34
  }
31
35
  out.print(page, data => {
32
36
  const p = data;
33
- return renderProjectListText(p);
37
+ return renderProjectListText(p, { columns: opts.columns, noHeader: opts.noHeader });
34
38
  });
35
39
  return page;
36
40
  }
@@ -41,6 +45,10 @@ export async function runGet(opts, deps = {}) {
41
45
  out.print(project, data => renderProjectText(data));
42
46
  return project;
43
47
  }
48
+ /** Resolve the created project's id regardless of which field name the backend used. */
49
+ export function resolveCreatedProjectId(r) {
50
+ return r.projectId ?? r.id;
51
+ }
44
52
  export async function runCreate(opts, deps = {}) {
45
53
  const out = makeOutput(opts.output, deps);
46
54
  const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
@@ -86,7 +94,11 @@ export async function runCreate(opts, deps = {}) {
86
94
  (opts.output === 'json' || opts.verbose || opts.debug)) {
87
95
  stderr(`idempotency-key: ${idempotencyKey}`);
88
96
  }
97
+ // Teach both id field names — `projectId` is the field the
98
+ // live backend actually sends; `id` is kept so this sample still matches
99
+ // callers written against the pre-fix shape.
89
100
  const sample = {
101
+ projectId: 'p_dryrun_2026',
90
102
  id: 'p_dryrun_2026',
91
103
  type: opts.type,
92
104
  name: opts.name,
@@ -95,7 +107,7 @@ export async function runCreate(opts, deps = {}) {
95
107
  createdAt: '2026-05-16T00:00:00.000Z',
96
108
  updatedAt: '2026-05-16T00:00:00.000Z',
97
109
  };
98
- out.print(sample, data => renderProjectText(data));
110
+ out.print(sample, data => renderCreateProjectText(data));
99
111
  return sample;
100
112
  }
101
113
  // Resolve password: flag > file > none
@@ -116,13 +128,64 @@ export async function runCreate(opts, deps = {}) {
116
128
  ...(opts.instruction !== undefined ? { instruction: opts.instruction } : {}),
117
129
  };
118
130
  const client = makeClient(opts, deps);
119
- const created = await client.post('/projects', {
131
+ const rawCreated = await client.post('/projects', {
120
132
  body,
121
133
  headers: { 'idempotency-key': idempotencyKey },
122
134
  });
123
- out.print(created, data => renderProjectText(data));
135
+ // Normalize whichever id field name the backend actually
136
+ // sent onto BOTH `projectId` and `id`, so JSON consumers keyed on either
137
+ // name keep working regardless of which one the live response used.
138
+ const resolvedId = resolveCreatedProjectId(rawCreated);
139
+ const created = {
140
+ ...rawCreated,
141
+ ...(resolvedId !== undefined ? { projectId: resolvedId, id: resolvedId } : {}),
142
+ };
143
+ out.print(created, data => renderCreateProjectText(data));
144
+ // A backend project created without --url has no default environment URL.
145
+ // On the V3 execution path, the shared admission guard (`runProjectGuarded`
146
+ // -> `assertProjectEnvNotLocal`, called by every V3 run/rerun/batch entry
147
+ // point, including `backendRun`) rejects the FIRST run of any test in the
148
+ // project with 400 no-target-resolvable. On the V2 path (`cli-run.service.ts`
149
+ // -> `resolveRunPrereqsFE`), this URL resolution is frontend-only and is
150
+ // never applied to a backend run, so a V2-routed backend project without a
151
+ // URL runs fine — V2 is the only execution path live in production today
152
+ // (V3 is dev-only pending its own GA release), so the wording below is
153
+ // conditioned on V3 rather than stated as a universal consequence.
154
+ // `--url` is intentionally NOT made mandatory here (that would break the
155
+ // published --help contract: npm 0.4.0 already ships text saying the URL
156
+ // is frontend-only), so this stays advisory-only. The CLI does not call
157
+ // GET /me here to check the caller's actual v3Enabled routing before
158
+ // deciding whether to print this — an extra round-trip on every create is
159
+ // not worth it just to gate a hint — so it points the reader at `auth
160
+ // status` (which already renders the routing: v2|v3 line) instead.
161
+ // Emitted in EVERY output mode, including --output json: this goes to
162
+ // stderr, which never touches JSON stdout, so there is nothing to protect
163
+ // by suppressing it (unlike `emitV3RoutingAdvisory`, which withholds
164
+ // account-context advisory in JSON mode because a JSON caller can read
165
+ // `v3Enabled` directly instead — there is no equivalent structured signal
166
+ // for this one). And --output json is precisely the case that needs it
167
+ // most: a script or agent creating a project non-interactively has no one
168
+ // watching a terminal, so a silent dead-on-arrival project only surfaces
169
+ // later as an unexplained 400 on the first run. Same family as the C1
170
+ // `--target-url` advisory above (a flag/setup the caller just made has a
171
+ // structural consequence) rather than the routing-advisory family.
172
+ // Real path only — NOT duplicated into the dry-run branch above, because
173
+ // the remedy command below embeds the created project id, and under
174
+ // --dry-run that id is the canned `p_dryrun_2026` sample: emitting a
175
+ // live-looking fix-it command against a fake resource is exactly what the
176
+ // `dashboardUrl` convention (see CLAUDE.md) already decided to suppress.
177
+ if (opts.type === 'backend' && !opts.targetUrl) {
178
+ stderr(`[advisory] this backend project has no default environment URL. On the V3 execution ` +
179
+ `path (check with \`testsprite auth status\`), test runs are rejected with ` +
180
+ `no-target-resolvable until one is set. Fix: testsprite project update ` +
181
+ `${resolvedId ?? '<project-id>'} --url <url>`);
182
+ }
124
183
  return created;
125
184
  }
185
+ /** Resolve the updated project's id regardless of which field name the backend used. */
186
+ export function resolveUpdatedProjectId(r) {
187
+ return r.projectId ?? r.id;
188
+ }
126
189
  export async function runUpdate(opts, deps = {}) {
127
190
  const out = makeOutput(opts.output, deps);
128
191
  const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
@@ -166,7 +229,11 @@ export async function runUpdate(opts, deps = {}) {
166
229
  (opts.output === 'json' || opts.verbose || opts.debug)) {
167
230
  stderr(`idempotency-key: ${idempotencyKey}`);
168
231
  }
232
+ // Teach both id field names — `projectId` is the field the
233
+ // live backend actually sends; `id` is kept so this sample still matches
234
+ // callers written against the pre-fix shape.
169
235
  const sample = {
236
+ projectId: opts.projectId,
170
237
  id: opts.projectId,
171
238
  updatedFields: presentFieldNames,
172
239
  updatedAt: '2026-05-16T00:00:00.000Z',
@@ -193,10 +260,20 @@ export async function runUpdate(opts, deps = {}) {
193
260
  };
194
261
  const body = Object.fromEntries(Object.entries(bodyFields).filter(([, v]) => v !== undefined));
195
262
  const client = makeClient(opts, deps);
196
- const updated = await client.patch(`/projects/${encodeURIComponent(opts.projectId)}`, {
263
+ const rawUpdated = await client.patch(`/projects/${encodeURIComponent(opts.projectId)}`, {
197
264
  body,
198
265
  headers: { 'idempotency-key': idempotencyKey },
199
266
  });
267
+ // Normalize whichever id field name the backend actually
268
+ // sent onto BOTH `projectId` and `id`, so JSON consumers keyed on either
269
+ // name keep working regardless of which one the live response used.
270
+ const resolvedUpdatedId = resolveUpdatedProjectId(rawUpdated);
271
+ const updated = {
272
+ ...rawUpdated,
273
+ ...(resolvedUpdatedId !== undefined
274
+ ? { projectId: resolvedUpdatedId, id: resolvedUpdatedId }
275
+ : {}),
276
+ };
200
277
  out.print(updated, data => renderUpdateText(data));
201
278
  return updated;
202
279
  }
@@ -388,6 +465,8 @@ export function createProjectCommand(deps = {}) {
388
465
  .option('--page-size <n>', 'service page-size hint (1-100, default 25)')
389
466
  .option('--starting-token <token>', 'opaque cursor from a previous list response')
390
467
  .option('--max-items <n>', 'stop after this many items across auto-paged pages')
468
+ .option('--columns <list>', 'select/reorder text table columns (comma-separated keys)')
469
+ .option('--no-header', 'suppress the text table header row')
391
470
  .addHelpText('after', GLOBAL_OPTS_HINT)
392
471
  .action(async (cmdOpts, command) => {
393
472
  // Don't parse numeric flags via Commander — its parser throws a
@@ -400,6 +479,8 @@ export function createProjectCommand(deps = {}) {
400
479
  pageSize: parseFlag(cmdOpts.pageSize, 'page-size'),
401
480
  startingToken: cmdOpts.startingToken,
402
481
  maxItems: parseFlag(cmdOpts.maxItems, 'max-items'),
482
+ columns: cmdOpts.columns,
483
+ noHeader: cmdOpts.header === false,
403
484
  }, deps);
404
485
  });
405
486
  project
@@ -414,7 +495,8 @@ export function createProjectCommand(deps = {}) {
414
495
  .description('Create a new project')
415
496
  .option('--type <frontend|backend>', 'project type (required)')
416
497
  .option('--name <name>', 'project name (required)')
417
- .option('--url <url>', 'target URL (required for frontend)')
498
+ .option('--url <url>', 'target URL (required for frontend; also required for backend on the V3 execution ' +
499
+ 'path — see `auth status` for your routing)')
418
500
  .option('--description <text>', 'not supported — projects have no description (test-level descriptions are set on `test create`)')
419
501
  .option('--username <user>', 'optional auth username')
420
502
  .option('--password <pw>', 'optional auth password (use --password-file for non-interactive)')
@@ -609,63 +691,114 @@ function makeClient(opts, deps) {
609
691
  function makeOutput(mode, deps) {
610
692
  return new Output(mode, { stdout: deps.stdout, stderr: deps.stderr });
611
693
  }
612
- function renderProjectListText(page) {
694
+ /**
695
+ * Master column set — includes ORG so `--columns` validation and explicit
696
+ * `--columns ...,org` selection both work regardless of whether any row in
697
+ * THIS response happens to carry org attribution. The default (no
698
+ * `--columns` flag) rendering uses {@link defaultProjectListColumns} instead,
699
+ * which drops ORG unless at least one row carries it — this keeps the table
700
+ * unchanged for legacy (non-org-scoped) callers.
701
+ */
702
+ const PROJECT_LIST_COLUMNS = [
703
+ {
704
+ header: 'ID',
705
+ width: rows => Math.max(2, ...rows.map(project => project.id.length)),
706
+ render: project => project.id,
707
+ },
708
+ {
709
+ header: 'NAME',
710
+ width: rows => Math.max(4, ...rows.map(project => project.name.length)),
711
+ render: project => project.name,
712
+ },
713
+ { header: 'TYPE', width: 8, render: project => project.type },
714
+ { header: 'FROM', width: 6, render: project => project.createdFrom },
715
+ {
716
+ header: 'ORG',
717
+ width: rows => Math.max(3, ...rows.map(project => (project.orgName ?? project.orgId ?? '').length)),
718
+ render: project => project.orgName ?? project.orgId ?? '',
719
+ },
720
+ { header: 'CREATED', width: 0, render: project => project.createdAt },
721
+ ];
722
+ const PROJECT_LIST_ORG_COLUMN = PROJECT_LIST_COLUMNS.find(c => c.header === 'ORG');
723
+ /**
724
+ * Default (no explicit `--columns`) column set. ORG is included only when
725
+ * at least one row in this page carries `orgId` — avoids widening the table
726
+ * for callers whose projects have no org attribution at all.
727
+ */
728
+ function defaultProjectListColumns(rows) {
729
+ const hasOrgInfo = rows.some(project => project.orgId !== undefined);
730
+ return hasOrgInfo
731
+ ? PROJECT_LIST_COLUMNS
732
+ : PROJECT_LIST_COLUMNS.filter(c => c !== PROJECT_LIST_ORG_COLUMN);
733
+ }
734
+ function renderProjectListText(page, options = {}) {
613
735
  if (page.items.length === 0) {
614
736
  return page.nextToken
615
737
  ? `No projects on this page.\nnextToken: ${page.nextToken}`
616
738
  : 'No projects.';
617
739
  }
618
- // Compact, AWS-CLI-grade columnar output. Column widths are computed
619
- // per-call so a single absurdly long project name doesn't push the
620
- // whole table off-screen.
621
- const idWidth = Math.max(2, ...page.items.map(p => p.id.length));
622
- const nameWidth = Math.max(4, ...page.items.map(p => p.name.length));
623
- const typeWidth = 8;
624
- const fromWidth = 6;
625
- const header = pad('ID', idWidth) +
626
- ' ' +
627
- pad('NAME', nameWidth) +
628
- ' ' +
629
- pad('TYPE', typeWidth) +
630
- ' ' +
631
- pad('FROM', fromWidth) +
632
- ' ' +
633
- 'CREATED';
634
- const rows = page.items.map(p => pad(p.id, idWidth) +
635
- ' ' +
636
- pad(p.name, nameWidth) +
637
- ' ' +
638
- pad(p.type, typeWidth) +
639
- ' ' +
640
- pad(p.createdFrom, fromWidth) +
641
- ' ' +
642
- p.createdAt);
643
- const lines = [header, ...rows];
740
+ // Explicit --columns: resolve against the FULL master set (so `org` can be
741
+ // requested even when this page happens to have no org-scoped rows).
742
+ // Default: only include ORG when the data actually carries it.
743
+ const columns = options.columns !== undefined ? PROJECT_LIST_COLUMNS : defaultProjectListColumns(page.items);
744
+ const lines = [
745
+ renderTextTable(page.items, columns, {
746
+ columns: options.columns,
747
+ noHeader: options.noHeader,
748
+ }),
749
+ ];
644
750
  if (page.nextToken)
645
751
  lines.push('', `nextToken: ${page.nextToken}`);
646
752
  return lines.join('\n');
647
753
  }
648
754
  function renderProjectText(p) {
649
- return [
755
+ const lines = [
650
756
  `id: ${p.id}`,
651
757
  `name: ${p.name}`,
652
758
  `type: ${p.type}`,
653
759
  `createdFrom: ${p.createdFrom}`,
654
760
  `createdAt: ${p.createdAt}`,
655
761
  `updatedAt: ${p.updatedAt}`,
656
- ].join('\n');
762
+ ];
763
+ if (p.orgId !== undefined) {
764
+ lines.push(`org: ${p.orgName ?? '(name unknown)'} (${p.orgId})`);
765
+ }
766
+ // Presence, not truthiness — see the `targetUrl` docstring on `CliProject`.
767
+ // `'targetUrl' in p` distinguishes "the backend answered 'no URL'" (render the
768
+ // hint) from "this endpoint doesn't report it" (say nothing).
769
+ if ('targetUrl' in p) {
770
+ lines.push(p.targetUrl
771
+ ? `targetUrl: ${p.targetUrl}`
772
+ : `targetUrl: (not set — set one with: testsprite project update ${p.id} --url <url>)`);
773
+ }
774
+ return lines.join('\n');
657
775
  }
658
- function pad(s, width) {
659
- if (s.length >= width)
660
- return s;
661
- return s + ' '.repeat(width - s.length);
776
+ /**
777
+ * `project create`'s text renderer. Distinct from
778
+ * `renderProjectText` (used by `project get`/`list`, where the live `id`
779
+ * field is proven reliable) because the create response's id field name and
780
+ * `updatedAt` presence are not guaranteed — see `CliCreateProjectResponse`.
781
+ */
782
+ function renderCreateProjectText(p) {
783
+ const lines = [
784
+ `id: ${resolveCreatedProjectId(p) ?? '(unknown)'}`,
785
+ `name: ${p.name}`,
786
+ `type: ${p.type}`,
787
+ `createdFrom: ${p.createdFrom}`,
788
+ `createdAt: ${p.createdAt}`,
789
+ ];
790
+ if (p.updatedAt !== undefined)
791
+ lines.push(`updatedAt: ${p.updatedAt}`);
792
+ return lines.join('\n');
662
793
  }
663
794
  function renderUpdateText(r) {
664
- return [
665
- `id: ${r.id}`,
795
+ const lines = [
796
+ `id: ${resolveUpdatedProjectId(r) ?? '(unknown)'}`,
666
797
  `updatedFields: ${r.updatedFields?.join(', ') ?? '(none)'}`,
667
- `updatedAt: ${r.updatedAt}`,
668
- ].join('\n');
798
+ ];
799
+ if (r.updatedAt !== undefined)
800
+ lines.push(`updatedAt: ${r.updatedAt}`);
801
+ return lines.join('\n');
669
802
  }
670
803
  function renderDeleteText(r) {
671
804
  return [`projectId ${r.projectId}`, `deletedAt ${r.deletedAt}`].join('\n');