@gonovus-ai/spec-flow-cli 1.4.0 → 1.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 +15 -3
- package/dist/cli.js +98 -61
- package/dist/cli.js.map +1 -1
- package/dist/commands/client-compatibility.d.ts +1 -1
- package/dist/commands/client-compatibility.js +3 -2
- package/dist/commands/client-compatibility.js.map +1 -1
- package/dist/commands/work-item-output.d.ts +56 -0
- package/dist/commands/work-item-output.js +1 -0
- package/dist/commands/work-item-output.js.map +1 -1
- package/dist/runner/adapters/codex-app-server.d.ts +14 -1
- package/dist/runner/adapters/codex-app-server.js +541 -292
- package/dist/runner/adapters/codex-app-server.js.map +1 -1
- package/dist/runner/adapters/exec-adapter.js +31 -11
- package/dist/runner/adapters/exec-adapter.js.map +1 -1
- package/dist/runner/orchestrator.d.ts +9 -0
- package/dist/runner/orchestrator.js +435 -11
- package/dist/runner/orchestrator.js.map +1 -1
- package/dist/runner/redact.d.ts +1 -0
- package/dist/runner/redact.js +1 -0
- package/dist/runner/redact.js.map +1 -1
- package/dist/runner/state-store.d.ts +4 -1
- package/dist/runner/state-store.js +61 -1
- package/dist/runner/state-store.js.map +1 -1
- package/dist/runner/telemetry-bridge.d.ts +23 -1
- package/dist/runner/telemetry-bridge.js +168 -4
- package/dist/runner/telemetry-bridge.js.map +1 -1
- package/dist/runner/types.d.ts +63 -1
- package/dist/runner/types.js +6 -0
- package/dist/runner/types.js.map +1 -1
- package/dist/runner/workflow.d.ts +5 -1
- package/dist/runner/workflow.js +58 -0
- package/dist/runner/workflow.js.map +1 -1
- package/dist/runtime/errors.d.ts +4 -0
- package/dist/runtime/errors.js +29 -0
- package/dist/runtime/errors.js.map +1 -1
- package/dist/version-commands.d.ts +26 -0
- package/dist/version-commands.js +966 -0
- package/dist/version-commands.js.map +1 -0
- package/dist/work-item-delivery-commands.js +1 -2
- package/dist/work-item-delivery-commands.js.map +1 -1
- package/guides/agent-sessions.md +5 -2
- package/guides/delivery.md +1 -1
- package/guides/discuss.md +1 -1
- package/guides/versions.md +82 -0
- package/guides/work-items.md +45 -1
- package/package.json +1 -1
|
@@ -0,0 +1,966 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { invalidArgument, parseDocumentVersion, parseIdempotencyKey, parseIdentity, readTextInput, writeOptions, } from "./context-command-support.js";
|
|
3
|
+
const parseWorkspaceId = parseIdentity("Workspace ID");
|
|
4
|
+
const parseVersionReference = parseIdentity("Version");
|
|
5
|
+
const parseItemReference = parseIdentity("Scope Item");
|
|
6
|
+
const parseUpdateId = parseIdentity("Progress Update ID");
|
|
7
|
+
const maximumTextBytes = 200_000;
|
|
8
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
9
|
+
const scenarioPattern = /^([A-Z]{2,10}-S[1-9]\d*)-[1-9]\d*$/u;
|
|
10
|
+
const collect = (parse) => (value, previous = []) => [...previous, parse(value)];
|
|
11
|
+
function parseWorkItemReference(value) {
|
|
12
|
+
const normalized = value.trim().toUpperCase();
|
|
13
|
+
if (!/^[A-Z]{2,10}-[1-9]\d*$/u.test(normalized))
|
|
14
|
+
throw invalidArgument("Work Item must be a public ID such as PAY-123");
|
|
15
|
+
return normalized;
|
|
16
|
+
}
|
|
17
|
+
function parseScenarioReference(value) {
|
|
18
|
+
const normalized = value.trim().toUpperCase();
|
|
19
|
+
const spec = scenarioPattern.exec(normalized)?.[1];
|
|
20
|
+
if (spec === undefined)
|
|
21
|
+
throw invalidArgument("Scenario must be a Scenario ID such as PAY-S12-3");
|
|
22
|
+
return { spec, scenarioId: normalized };
|
|
23
|
+
}
|
|
24
|
+
function parseSpecReference(value) {
|
|
25
|
+
const normalized = value.trim().toUpperCase();
|
|
26
|
+
if (!/^[A-Z]{2,10}-S[1-9]\d*$/u.test(normalized))
|
|
27
|
+
throw invalidArgument("Spec must be a Spec ID such as PAY-S12");
|
|
28
|
+
return normalized;
|
|
29
|
+
}
|
|
30
|
+
function parseChange(value) {
|
|
31
|
+
if (value === "added" || value === "modified" || value === "removed")
|
|
32
|
+
return value;
|
|
33
|
+
throw invalidArgument("Change must be added, modified or removed");
|
|
34
|
+
}
|
|
35
|
+
function parseHealth(value) {
|
|
36
|
+
const normalized = value
|
|
37
|
+
.trim()
|
|
38
|
+
.toLowerCase()
|
|
39
|
+
.replace(/[-_\s]/gu, "");
|
|
40
|
+
if (normalized === "ontrack")
|
|
41
|
+
return "onTrack";
|
|
42
|
+
if (normalized === "atrisk")
|
|
43
|
+
return "atRisk";
|
|
44
|
+
throw invalidArgument("Health must be on-track or at-risk");
|
|
45
|
+
}
|
|
46
|
+
function parseStatus(value) {
|
|
47
|
+
if (value === "planned" || value === "active")
|
|
48
|
+
return value;
|
|
49
|
+
throw invalidArgument("Status must be planned or active; sealing is its own command");
|
|
50
|
+
}
|
|
51
|
+
function parseCalendarDate(value) {
|
|
52
|
+
if (!/^\d{4}-\d{2}-\d{2}$/u.test(value.trim()))
|
|
53
|
+
throw invalidArgument("Date must be a calendar date such as 2026-12-31");
|
|
54
|
+
return value.trim();
|
|
55
|
+
}
|
|
56
|
+
/** A target is a date (2026-12-31), a month (2026-12) or a quarter (2026-Q4). */
|
|
57
|
+
function parseTarget(value) {
|
|
58
|
+
const trimmed = value.trim().toUpperCase();
|
|
59
|
+
if (/^\d{4}-\d{2}-\d{2}$/u.test(trimmed))
|
|
60
|
+
return { precision: "date", value: trimmed };
|
|
61
|
+
if (/^\d{4}-\d{2}$/u.test(trimmed))
|
|
62
|
+
return { precision: "month", value: trimmed };
|
|
63
|
+
if (/^\d{4}-Q[1-4]$/u.test(trimmed))
|
|
64
|
+
return { precision: "quarter", value: trimmed };
|
|
65
|
+
throw invalidArgument("Target must be a date (2026-12-31), a month (2026-12) or a quarter (2026-Q4)");
|
|
66
|
+
}
|
|
67
|
+
function parseLimit(value) {
|
|
68
|
+
const limit = Number(value);
|
|
69
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100)
|
|
70
|
+
throw invalidArgument("Limit must be an integer from 1 to 100");
|
|
71
|
+
return limit;
|
|
72
|
+
}
|
|
73
|
+
function notFound(code, message) {
|
|
74
|
+
return {
|
|
75
|
+
response: new Response(null, { status: 404 }),
|
|
76
|
+
error: { code, message },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function invalid(code, message) {
|
|
80
|
+
return {
|
|
81
|
+
response: new Response(null, { status: 400 }),
|
|
82
|
+
error: { code, message },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** A 204 answer carries no body; report what the command did instead. */
|
|
86
|
+
function withData(result, data) {
|
|
87
|
+
return result.response.ok && result.data === undefined ? { ...result, data } : result;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Version references are ids or names (`v2.4`); names are unique in a Workspace. Ids are
|
|
91
|
+
* used as given, so a command naming only ids reads nothing extra.
|
|
92
|
+
*/
|
|
93
|
+
export async function resolveVersions(client, workspaceId, references) {
|
|
94
|
+
if (references.every((reference) => uuid.test(reference)))
|
|
95
|
+
return { ids: references };
|
|
96
|
+
const listed = await client.GET("/v1/workspaces/{workspaceId}/versions", {
|
|
97
|
+
params: { path: { workspaceId } },
|
|
98
|
+
});
|
|
99
|
+
if (listed.data === undefined)
|
|
100
|
+
return { failure: { response: listed.response, error: listed.error } };
|
|
101
|
+
const versions = listed.data.versions;
|
|
102
|
+
const ids = [];
|
|
103
|
+
for (const reference of references) {
|
|
104
|
+
const match = versions.find((version) => version.id === reference) ??
|
|
105
|
+
versions.find((version) => version.name === reference) ??
|
|
106
|
+
(() => {
|
|
107
|
+
const folded = versions.filter((version) => version.name.toLowerCase() === reference.toLowerCase());
|
|
108
|
+
return folded.length === 1 ? folded[0] : undefined;
|
|
109
|
+
})();
|
|
110
|
+
if (match === undefined)
|
|
111
|
+
return {
|
|
112
|
+
failure: notFound("VERSION_NOT_FOUND", `No Version has the id or name ${reference}; run specflow version list`),
|
|
113
|
+
};
|
|
114
|
+
ids.push(match.id);
|
|
115
|
+
}
|
|
116
|
+
return { ids };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A Work Item command's `--version-id`: a Version id as given, or a Version name
|
|
120
|
+
* resolved in the Workspace of the Work Item's Project (ADR 0177).
|
|
121
|
+
*/
|
|
122
|
+
export async function resolveProjectVersion(client, projectId, reference) {
|
|
123
|
+
if (uuid.test(reference))
|
|
124
|
+
return { id: reference };
|
|
125
|
+
const context = await client.GET("/v1/projects/{projectId}/context", {
|
|
126
|
+
params: { path: { projectId } },
|
|
127
|
+
});
|
|
128
|
+
if (context.data === undefined)
|
|
129
|
+
return { failure: { response: context.response, error: context.error } };
|
|
130
|
+
const resolved = await resolveVersions(client, context.data.project.workspaceId, [reference]);
|
|
131
|
+
if ("failure" in resolved)
|
|
132
|
+
return resolved;
|
|
133
|
+
return { id: resolved.ids[0] ?? reference };
|
|
134
|
+
}
|
|
135
|
+
/** The scope item a reference names: its id, a Work Item, Scenario or Glossary entry id. */
|
|
136
|
+
function findItem(items, reference) {
|
|
137
|
+
const upper = reference.toUpperCase();
|
|
138
|
+
const byId = items.filter((item) => item.id === reference);
|
|
139
|
+
if (byId.length > 0)
|
|
140
|
+
return byId;
|
|
141
|
+
return items.filter((item) => (item.workItem?.readable === true && item.workItem.publicId === upper) ||
|
|
142
|
+
item.scenario?.scenarioId === upper ||
|
|
143
|
+
item.glossaryEntry?.entryId === reference);
|
|
144
|
+
}
|
|
145
|
+
async function resolveItems(client, workspaceId, versionId, references) {
|
|
146
|
+
const scope = await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/scope", {
|
|
147
|
+
params: { path: { workspaceId, versionId } },
|
|
148
|
+
});
|
|
149
|
+
if (scope.data === undefined)
|
|
150
|
+
return { failure: { response: scope.response, error: scope.error } };
|
|
151
|
+
const items = [];
|
|
152
|
+
for (const reference of references) {
|
|
153
|
+
const matches = findItem(scope.data.items, reference);
|
|
154
|
+
if (matches.length !== 1 || matches[0] === undefined)
|
|
155
|
+
return {
|
|
156
|
+
failure: matches.length === 0
|
|
157
|
+
? notFound("VERSION_SCOPE_ITEM_NOT_FOUND", `Nothing in this Version's scope matches ${reference}; run specflow version scope list`)
|
|
158
|
+
: invalid("VERSION_SCOPE_ITEM_AMBIGUOUS", `${reference} matches several Scope Items; pass the Scope Item id`),
|
|
159
|
+
};
|
|
160
|
+
items.push(matches[0]);
|
|
161
|
+
}
|
|
162
|
+
return { items };
|
|
163
|
+
}
|
|
164
|
+
/** One short line per item, enough to tell scope apart without reading every field. */
|
|
165
|
+
function itemLabel(item) {
|
|
166
|
+
if (item.kind === "workItem")
|
|
167
|
+
return item.workItem?.readable === true
|
|
168
|
+
? `${item.workItem.publicId} ${item.workItem.title}`
|
|
169
|
+
: "Work Item in a Project you cannot read";
|
|
170
|
+
if (item.kind === "scenario")
|
|
171
|
+
return `${item.change ?? ""} ${item.scenario?.scenarioId ?? item.scenario?.specPublicId ?? ""} ${item.scenario?.title ?? ""}`.trim();
|
|
172
|
+
return `${item.change ?? ""} ${item.glossaryEntry?.entryId ?? ""} ${item.glossaryEntry?.term ?? ""}`.trim();
|
|
173
|
+
}
|
|
174
|
+
export function registerVersionCommands(version, runtime) {
|
|
175
|
+
const json = (command) => command.option("--json", "Emit structured JSON (the default)");
|
|
176
|
+
const workspace = (command) => json(command).requiredOption("--workspace-id <workspaceId>", "Workspace ID", parseWorkspaceId);
|
|
177
|
+
const scoped = (command) => workspace(command).requiredOption("--version-id <version>", "Version id or name (such as v2.4)", parseVersionReference);
|
|
178
|
+
const expected = (command) => scoped(command).requiredOption("--expected-version <version>", "The Version's version number a read printed (its ETag)", parseDocumentVersion);
|
|
179
|
+
const read = { rejectWorkspaceReadToken: true };
|
|
180
|
+
const guard = () => {
|
|
181
|
+
if (runtime.canWrite())
|
|
182
|
+
return true;
|
|
183
|
+
runtime.setExitCode(runtime.rejectWrite());
|
|
184
|
+
return false;
|
|
185
|
+
};
|
|
186
|
+
/** An If-Match write is never repeated blindly; a lost answer is reported as unknown. */
|
|
187
|
+
const uncertain = (subject) => ({
|
|
188
|
+
rejectWorkspaceReadToken: true,
|
|
189
|
+
uncertainWrite: true,
|
|
190
|
+
ambiguousOutcomeMessage: `${subject} outcome is unknown: it may have been applied. Read the Version (specflow version get) before retrying`,
|
|
191
|
+
});
|
|
192
|
+
json(version.command("list"))
|
|
193
|
+
.description("List the Workspace's Versions in their manual order with progress counts")
|
|
194
|
+
.requiredOption("--workspace-id <workspaceId>", "Workspace ID", parseWorkspaceId)
|
|
195
|
+
.action(async (options) => {
|
|
196
|
+
runtime.setExitCode(await runtime.run((client) => client.GET("/v1/workspaces/{workspaceId}/versions", {
|
|
197
|
+
params: { path: { workspaceId: options.workspaceId } },
|
|
198
|
+
}), read));
|
|
199
|
+
});
|
|
200
|
+
scoped(version.command("get"))
|
|
201
|
+
.description("Read one Version with its three-track progress, forecast and health")
|
|
202
|
+
.action(async (options) => {
|
|
203
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
204
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
205
|
+
if ("failure" in resolved)
|
|
206
|
+
return resolved.failure;
|
|
207
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}", {
|
|
208
|
+
params: {
|
|
209
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}, read));
|
|
213
|
+
});
|
|
214
|
+
const fields = (command) => command
|
|
215
|
+
.option("--title <title>", "Version title")
|
|
216
|
+
.option("--description <markdown>", "Description text")
|
|
217
|
+
.option("--description-file <path>", "Description from a UTF-8 file, or - for standard input")
|
|
218
|
+
.option("--changelog-intro <markdown>", "Text that opens the Version's changelog")
|
|
219
|
+
.option("--changelog-intro-file <path>", "Changelog intro from a UTF-8 file, or - for standard input")
|
|
220
|
+
.option("--owner <userId>", "Owner: a Workspace member's User ID")
|
|
221
|
+
.option("--start-date <date>", "Start date such as 2026-11-01", parseCalendarDate)
|
|
222
|
+
.option("--target <target>", "Target date (2026-12-31), month (2026-12) or quarter (2026-Q4)", parseTarget)
|
|
223
|
+
.option("--status <status>", "planned or active", parseStatus);
|
|
224
|
+
const body = async (options) => {
|
|
225
|
+
if (options.description !== undefined && options.descriptionFile !== undefined)
|
|
226
|
+
throw invalidArgument("Pass --description or --description-file, not both");
|
|
227
|
+
if (options.changelogIntro !== undefined && options.changelogIntroFile !== undefined)
|
|
228
|
+
throw invalidArgument("Pass --changelog-intro or --changelog-intro-file, not both");
|
|
229
|
+
if (options.descriptionFile === "-" && options.changelogIntroFile === "-")
|
|
230
|
+
throw invalidArgument("Only one text can come from standard input");
|
|
231
|
+
for (const [set, clear, label] of [
|
|
232
|
+
[options.owner, options.clearOwner, "owner"],
|
|
233
|
+
[options.startDate, options.clearStartDate, "start date"],
|
|
234
|
+
[options.target, options.clearTarget, "target"],
|
|
235
|
+
])
|
|
236
|
+
if (set !== undefined && clear === true)
|
|
237
|
+
throw invalidArgument(`Cannot set and clear the ${label} together`);
|
|
238
|
+
const description = options.descriptionFile === undefined
|
|
239
|
+
? options.description
|
|
240
|
+
: await readTextInput(options.descriptionFile, maximumTextBytes, "Description");
|
|
241
|
+
const changelogIntro = options.changelogIntroFile === undefined
|
|
242
|
+
? options.changelogIntro
|
|
243
|
+
: await readTextInput(options.changelogIntroFile, maximumTextBytes, "Changelog intro");
|
|
244
|
+
return {
|
|
245
|
+
...(options.name === undefined ? {} : { name: options.name }),
|
|
246
|
+
...(options.title === undefined ? {} : { title: options.title }),
|
|
247
|
+
...(description === undefined ? {} : { description }),
|
|
248
|
+
...(changelogIntro === undefined ? {} : { changelogIntro }),
|
|
249
|
+
...(options.clearOwner === true
|
|
250
|
+
? { ownerUserId: null }
|
|
251
|
+
: options.owner === undefined
|
|
252
|
+
? {}
|
|
253
|
+
: { ownerUserId: options.owner }),
|
|
254
|
+
...(options.clearStartDate === true
|
|
255
|
+
? { startDate: null }
|
|
256
|
+
: options.startDate === undefined
|
|
257
|
+
? {}
|
|
258
|
+
: { startDate: options.startDate }),
|
|
259
|
+
...(options.clearTarget === true
|
|
260
|
+
? { target: null }
|
|
261
|
+
: options.target === undefined
|
|
262
|
+
? {}
|
|
263
|
+
: { target: options.target }),
|
|
264
|
+
...(options.status === undefined ? {} : { status: options.status }),
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
fields(workspace(version.command("create"))
|
|
268
|
+
.description("Create a planned or active Version; nothing carries over from other Versions")
|
|
269
|
+
.requiredOption("--name <name>", "Short unique name such as v2.4"))
|
|
270
|
+
.option("--idempotency-key <key>", "Reuse to retry the same create; a new one is generated and printed otherwise", parseIdempotencyKey)
|
|
271
|
+
.action(async (options) => {
|
|
272
|
+
if (!guard())
|
|
273
|
+
return;
|
|
274
|
+
const input = { ...(await body(options)), name: options.name ?? "" };
|
|
275
|
+
const idempotencyKey = options.idempotencyKey ?? randomUUID();
|
|
276
|
+
runtime.setExitCode(await runtime.run((client) => client.POST("/v1/workspaces/{workspaceId}/versions", {
|
|
277
|
+
params: {
|
|
278
|
+
path: { workspaceId: options.workspaceId },
|
|
279
|
+
header: { "idempotency-key": idempotencyKey },
|
|
280
|
+
},
|
|
281
|
+
body: input,
|
|
282
|
+
}), {
|
|
283
|
+
...writeOptions("Version create", idempotencyKey),
|
|
284
|
+
rejectWorkspaceReadToken: true,
|
|
285
|
+
ambiguousOutcomeMessage: "Version create outcome is unknown; retry with the same --idempotency-key and inputs, or run specflow version list",
|
|
286
|
+
project: (data) => ({ ...data, idempotencyKey }),
|
|
287
|
+
}));
|
|
288
|
+
});
|
|
289
|
+
// `version update` edits a Version; `version update post|reply|list` are Progress Updates.
|
|
290
|
+
// Commander checks an ancestor's mandatory options too, so the options of this command,
|
|
291
|
+
// which has subcommands, are optional to Commander and required here.
|
|
292
|
+
const update = fields(json(version.command("update"))
|
|
293
|
+
.description("Edit a Version's fields (planned or active), or use post|reply|list for Progress Updates")
|
|
294
|
+
.option("--workspace-id <workspaceId>", "Workspace ID (required)", parseWorkspaceId)
|
|
295
|
+
.option("--version-id <version>", "Version id or name such as v2.4 (required)", parseVersionReference)
|
|
296
|
+
.option("--expected-version <version>", "The Version's version number a read printed (required)", parseDocumentVersion)
|
|
297
|
+
.option("--name <name>", "Short unique name"))
|
|
298
|
+
.option("--clear-owner", "Remove the owner")
|
|
299
|
+
.option("--clear-start-date", "Remove the start date")
|
|
300
|
+
.option("--clear-target", "Remove the target")
|
|
301
|
+
.action(async (options) => {
|
|
302
|
+
for (const [value, flag] of [
|
|
303
|
+
[options.workspaceId, "--workspace-id <workspaceId>"],
|
|
304
|
+
[options.versionId, "--version-id <version>"],
|
|
305
|
+
[options.expectedVersion, "--expected-version <version>"],
|
|
306
|
+
])
|
|
307
|
+
if (value === undefined)
|
|
308
|
+
throw invalidArgument(`error: required option '${flag}' not specified`);
|
|
309
|
+
const { workspaceId = "", versionId = "", expectedVersion = "" } = options;
|
|
310
|
+
if (!guard())
|
|
311
|
+
return;
|
|
312
|
+
const input = await body(options);
|
|
313
|
+
if (Object.keys(input).length === 0)
|
|
314
|
+
throw invalidArgument("Version update requires a field");
|
|
315
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
316
|
+
const resolved = await resolveVersions(client, workspaceId, [versionId]);
|
|
317
|
+
if ("failure" in resolved)
|
|
318
|
+
return resolved.failure;
|
|
319
|
+
return await client.PATCH("/v1/workspaces/{workspaceId}/versions/{versionId}", {
|
|
320
|
+
params: {
|
|
321
|
+
path: { workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
322
|
+
header: { "if-match": expectedVersion },
|
|
323
|
+
},
|
|
324
|
+
body: input,
|
|
325
|
+
});
|
|
326
|
+
}, uncertain("Version update")));
|
|
327
|
+
});
|
|
328
|
+
// Commander gives options that `update` knows to `update` even after `post`, so the
|
|
329
|
+
// Progress Update commands read the Workspace and Version from the merged options.
|
|
330
|
+
const progress = (command) => json(command)
|
|
331
|
+
.option("--workspace-id <workspaceId>", "Workspace ID (required)", parseWorkspaceId)
|
|
332
|
+
.option("--version-id <version>", "Version id or name such as v2.4 (required)", parseVersionReference);
|
|
333
|
+
const scopeOf = (command) => {
|
|
334
|
+
const merged = command.optsWithGlobals();
|
|
335
|
+
if (merged.workspaceId === undefined)
|
|
336
|
+
throw invalidArgument("error: required option '--workspace-id <workspaceId>' not specified");
|
|
337
|
+
if (merged.versionId === undefined)
|
|
338
|
+
throw invalidArgument("error: required option '--version-id <version>' not specified");
|
|
339
|
+
return { workspaceId: merged.workspaceId, versionId: merged.versionId };
|
|
340
|
+
};
|
|
341
|
+
progress(update.command("list"))
|
|
342
|
+
.description("List a Version's Progress Updates with their replies, newest first")
|
|
343
|
+
.action(async (_options, command) => {
|
|
344
|
+
const options = scopeOf(command);
|
|
345
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
346
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
347
|
+
if ("failure" in resolved)
|
|
348
|
+
return resolved.failure;
|
|
349
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/updates", {
|
|
350
|
+
params: {
|
|
351
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
}, read));
|
|
355
|
+
});
|
|
356
|
+
const text = (command) => command
|
|
357
|
+
.option("--body <markdown>", "Markdown text")
|
|
358
|
+
.option("--body-file <path>", "Markdown text from a UTF-8 file, or - for standard input");
|
|
359
|
+
const readBody = async (options) => {
|
|
360
|
+
if ((options.body === undefined) === (options.bodyFile === undefined))
|
|
361
|
+
throw invalidArgument("Pass exactly one of --body or --body-file");
|
|
362
|
+
return options.body ?? (await readTextInput(options.bodyFile ?? "", maximumTextBytes, "Body"));
|
|
363
|
+
};
|
|
364
|
+
text(progress(update.command("post"))
|
|
365
|
+
.description("Post the owner's health judgement (on-track or at-risk) with Markdown text")
|
|
366
|
+
.requiredOption("--health <health>", "on-track or at-risk", parseHealth)).action(async (local, command) => {
|
|
367
|
+
const options = { ...local, ...scopeOf(command) };
|
|
368
|
+
if (!guard())
|
|
369
|
+
return;
|
|
370
|
+
const markdown = await readBody(options);
|
|
371
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
372
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
373
|
+
if ("failure" in resolved)
|
|
374
|
+
return resolved.failure;
|
|
375
|
+
return await client.POST("/v1/workspaces/{workspaceId}/versions/{versionId}/updates", {
|
|
376
|
+
params: {
|
|
377
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
378
|
+
},
|
|
379
|
+
body: { health: options.health, body: markdown },
|
|
380
|
+
});
|
|
381
|
+
}, uncertain("Progress Update")));
|
|
382
|
+
});
|
|
383
|
+
text(progress(update.command("reply"))
|
|
384
|
+
.description("Reply to a Progress Update")
|
|
385
|
+
.requiredOption("--update-id <updateId>", "Progress Update ID", parseUpdateId)).action(async (local, command) => {
|
|
386
|
+
const options = { ...local, ...scopeOf(command) };
|
|
387
|
+
if (!guard())
|
|
388
|
+
return;
|
|
389
|
+
const markdown = await readBody(options);
|
|
390
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
391
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
392
|
+
if ("failure" in resolved)
|
|
393
|
+
return resolved.failure;
|
|
394
|
+
return await client.POST("/v1/workspaces/{workspaceId}/versions/{versionId}/updates/{updateId}/replies", {
|
|
395
|
+
params: {
|
|
396
|
+
path: {
|
|
397
|
+
workspaceId: options.workspaceId,
|
|
398
|
+
versionId: resolved.ids[0] ?? "",
|
|
399
|
+
updateId: options.updateId,
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
body: { body: markdown },
|
|
403
|
+
});
|
|
404
|
+
}, uncertain("Progress Update reply")));
|
|
405
|
+
});
|
|
406
|
+
workspace(version.command("reorder"))
|
|
407
|
+
.description("Set the order of every unsealed Version; list each once, first to last")
|
|
408
|
+
.requiredOption("--version-id <version>", "Version id or name; repeat for every unsealed Version in order", collect(parseVersionReference))
|
|
409
|
+
.action(async (options) => {
|
|
410
|
+
if (!guard())
|
|
411
|
+
return;
|
|
412
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
413
|
+
const resolved = await resolveVersions(client, options.workspaceId, options.versionId);
|
|
414
|
+
if ("failure" in resolved)
|
|
415
|
+
return resolved.failure;
|
|
416
|
+
return await client.PUT("/v1/workspaces/{workspaceId}/versions/order", {
|
|
417
|
+
params: { path: { workspaceId: options.workspaceId } },
|
|
418
|
+
body: { versionIds: [...resolved.ids] },
|
|
419
|
+
});
|
|
420
|
+
}, uncertain("Version reorder")));
|
|
421
|
+
});
|
|
422
|
+
expected(version.command("delete"))
|
|
423
|
+
.description("Delete a planned or active Version; only scope membership goes, never a Work Item, Spec or term")
|
|
424
|
+
.action(async (options) => {
|
|
425
|
+
if (!guard())
|
|
426
|
+
return;
|
|
427
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
428
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
429
|
+
if ("failure" in resolved)
|
|
430
|
+
return resolved.failure;
|
|
431
|
+
const versionId = resolved.ids[0] ?? "";
|
|
432
|
+
return withData(await client.DELETE("/v1/workspaces/{workspaceId}/versions/{versionId}", {
|
|
433
|
+
params: {
|
|
434
|
+
path: { workspaceId: options.workspaceId, versionId },
|
|
435
|
+
header: { "if-match": options.expectedVersion },
|
|
436
|
+
},
|
|
437
|
+
}), { deleted: { versionId } });
|
|
438
|
+
}, uncertain("Version delete")));
|
|
439
|
+
});
|
|
440
|
+
scoped(version.command("seal"))
|
|
441
|
+
.description("Seal a Version: move or drop every unfinished item and write its Baseline (irreversible). --preview writes nothing")
|
|
442
|
+
.option("--expected-version <version>", "The Version's version number a read printed (required unless --preview)", parseDocumentVersion)
|
|
443
|
+
.option("--preview", "Show unfinished items, unpublished drafts and the plan; write nothing")
|
|
444
|
+
.option("--move <item=version>", "Move one unfinished item (Scope Item id, PAY-123, PAY-S12-3 or term id) to a Version; repeatable", collect((value) => {
|
|
445
|
+
const separator = value.lastIndexOf("=");
|
|
446
|
+
if (separator <= 0 || separator === value.length - 1)
|
|
447
|
+
throw invalidArgument("--move takes item=version, such as PAY-123=v2.5");
|
|
448
|
+
return {
|
|
449
|
+
item: parseItemReference(value.slice(0, separator)),
|
|
450
|
+
version: parseVersionReference(value.slice(separator + 1)),
|
|
451
|
+
};
|
|
452
|
+
}))
|
|
453
|
+
.option("--drop <item>", "Drop one unfinished item from scope; repeatable", collect(parseItemReference))
|
|
454
|
+
.option("--rest <action>", "What happens to unfinished items not named: move (default) or drop", (value) => {
|
|
455
|
+
if (value === "move" || value === "drop")
|
|
456
|
+
return value;
|
|
457
|
+
throw invalidArgument("--rest must be move or drop");
|
|
458
|
+
})
|
|
459
|
+
.option("--rest-to <version>", "Version that unnamed unfinished items move to (default: the next Version)", parseVersionReference)
|
|
460
|
+
.option("--idempotency-key <key>", "Reuse to retry the same seal; a new one is generated and printed otherwise", parseIdempotencyKey)
|
|
461
|
+
.action(async (options) => {
|
|
462
|
+
if (options.preview !== true && options.expectedVersion === undefined)
|
|
463
|
+
throw invalidArgument("Seal requires --expected-version; run with --preview first to see what it does");
|
|
464
|
+
if (options.rest === "drop" && options.restTo !== undefined)
|
|
465
|
+
throw invalidArgument("--rest-to applies only when the rest move");
|
|
466
|
+
if (options.preview !== true && !guard())
|
|
467
|
+
return;
|
|
468
|
+
const idempotencyKey = options.idempotencyKey ?? randomUUID();
|
|
469
|
+
const plan = async (client) => {
|
|
470
|
+
const resolved = await resolveVersions(client, options.workspaceId, [
|
|
471
|
+
options.versionId,
|
|
472
|
+
...(options.move ?? []).map((entry) => entry.version),
|
|
473
|
+
...(options.restTo === undefined ? [] : [options.restTo]),
|
|
474
|
+
]);
|
|
475
|
+
if ("failure" in resolved)
|
|
476
|
+
return resolved;
|
|
477
|
+
const [versionId = "", ...targets] = resolved.ids;
|
|
478
|
+
const preview = await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/seal-preview", { params: { path: { workspaceId: options.workspaceId, versionId } } });
|
|
479
|
+
if (preview.data === undefined)
|
|
480
|
+
return {
|
|
481
|
+
failure: {
|
|
482
|
+
response: preview.response,
|
|
483
|
+
// A retried seal finds the Version already sealed: that is the earlier seal.
|
|
484
|
+
error: preview.response.status === 409 &&
|
|
485
|
+
preview.error?.code === "VERSION_SEALED"
|
|
486
|
+
? {
|
|
487
|
+
code: "VERSION_SEALED",
|
|
488
|
+
message: "This Version is already sealed; read it with specflow version get or specflow version baseline get",
|
|
489
|
+
}
|
|
490
|
+
: preview.error,
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
const unfinished = preview.data.unfinished;
|
|
494
|
+
const named = new Map();
|
|
495
|
+
const name = (reference, decision) => {
|
|
496
|
+
const matches = findItem(unfinished, reference);
|
|
497
|
+
if (matches.length !== 1 || matches[0] === undefined)
|
|
498
|
+
return matches.length === 0
|
|
499
|
+
? notFound("VERSION_SCOPE_ITEM_NOT_FOUND", `No unfinished item of this Version matches ${reference}`)
|
|
500
|
+
: invalid("VERSION_SCOPE_ITEM_AMBIGUOUS", `${reference} matches several unfinished items; pass the Scope Item id`);
|
|
501
|
+
if (named.has(matches[0].id))
|
|
502
|
+
return invalid("VERSION_SEAL_PLAN_INVALID", `${reference} is named more than once`);
|
|
503
|
+
named.set(matches[0].id, decision);
|
|
504
|
+
return null;
|
|
505
|
+
};
|
|
506
|
+
for (const [index, entry] of (options.move ?? []).entries()) {
|
|
507
|
+
const failure = name(entry.item, {
|
|
508
|
+
action: "move",
|
|
509
|
+
targetVersionId: targets[index] ?? "",
|
|
510
|
+
});
|
|
511
|
+
if (failure !== null)
|
|
512
|
+
return { failure };
|
|
513
|
+
}
|
|
514
|
+
for (const reference of options.drop ?? []) {
|
|
515
|
+
const failure = name(reference, { action: "drop" });
|
|
516
|
+
if (failure !== null)
|
|
517
|
+
return { failure };
|
|
518
|
+
}
|
|
519
|
+
const restTarget = options.restTo === undefined
|
|
520
|
+
? preview.data.defaultTargetVersionId
|
|
521
|
+
: (targets[targets.length - 1] ?? null);
|
|
522
|
+
const rest = unfinished.filter((item) => !named.has(item.id));
|
|
523
|
+
if (rest.length > 0 && options.rest !== "drop" && restTarget === null)
|
|
524
|
+
return {
|
|
525
|
+
failure: invalid("VERSION_SEAL_PLAN_INVALID", "There is no next unsealed Version to move unfinished items to; pass --rest-to, --move or --drop, or --rest drop"),
|
|
526
|
+
};
|
|
527
|
+
const dispositions = unfinished.map((item) => {
|
|
528
|
+
const decision = named.get(item.id) ??
|
|
529
|
+
(options.rest === "drop"
|
|
530
|
+
? { action: "drop" }
|
|
531
|
+
: { action: "move", targetVersionId: restTarget ?? "" });
|
|
532
|
+
return { scopeItemId: item.id, ...decision };
|
|
533
|
+
});
|
|
534
|
+
// The default destination is named explicitly in the rerun the preview
|
|
535
|
+
// suggests, so the seal applies the previewed plan or fails, never a
|
|
536
|
+
// different next Version chosen at execution time.
|
|
537
|
+
const restMovesToDefault = rest.length > 0 && options.rest !== "drop" && options.restTo === undefined;
|
|
538
|
+
return {
|
|
539
|
+
versionId,
|
|
540
|
+
preview: preview.data,
|
|
541
|
+
dispositions,
|
|
542
|
+
restTo: restMovesToDefault ? restTarget : null,
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
const describe = (dispositions, unfinished) => dispositions.map((entry) => {
|
|
546
|
+
const item = unfinished.find((candidate) => candidate.id === entry.scopeItemId);
|
|
547
|
+
return {
|
|
548
|
+
...entry,
|
|
549
|
+
item: item === undefined ? null : itemLabel(item),
|
|
550
|
+
required: item?.required ?? null,
|
|
551
|
+
};
|
|
552
|
+
});
|
|
553
|
+
if (options.preview === true) {
|
|
554
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
555
|
+
const planned = await plan(client);
|
|
556
|
+
if ("failure" in planned)
|
|
557
|
+
return planned.failure;
|
|
558
|
+
return {
|
|
559
|
+
response: new Response(null, { status: 200 }),
|
|
560
|
+
data: {
|
|
561
|
+
...planned.preview,
|
|
562
|
+
plan: describe(planned.dispositions, planned.preview.unfinished),
|
|
563
|
+
next: `Nothing was written. To seal exactly this, rerun without --preview, with the same --move and --drop, and with --expected-version ${String(planned.preview.version.version)}${planned.restTo === null ? "" : ` --rest-to ${planned.restTo}`}`,
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
}, read));
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
let unfinished = [];
|
|
570
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
571
|
+
const planned = await plan(client);
|
|
572
|
+
if ("failure" in planned)
|
|
573
|
+
return planned.failure;
|
|
574
|
+
unfinished = planned.preview.unfinished;
|
|
575
|
+
const sealed = await client.POST("/v1/workspaces/{workspaceId}/versions/{versionId}/seal", {
|
|
576
|
+
params: {
|
|
577
|
+
path: { workspaceId: options.workspaceId, versionId: planned.versionId },
|
|
578
|
+
header: {
|
|
579
|
+
"if-match": options.expectedVersion ?? "",
|
|
580
|
+
"idempotency-key": idempotencyKey,
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
body: { dispositions: planned.dispositions },
|
|
584
|
+
});
|
|
585
|
+
return sealed.data === undefined
|
|
586
|
+
? sealed
|
|
587
|
+
: {
|
|
588
|
+
...sealed,
|
|
589
|
+
data: {
|
|
590
|
+
...sealed.data,
|
|
591
|
+
dispositions: describe(planned.dispositions, unfinished),
|
|
592
|
+
unpublishedDrafts: planned.preview.unpublishedDrafts,
|
|
593
|
+
idempotencyKey,
|
|
594
|
+
},
|
|
595
|
+
};
|
|
596
|
+
}, {
|
|
597
|
+
...writeOptions("Version seal", idempotencyKey),
|
|
598
|
+
rejectWorkspaceReadToken: true,
|
|
599
|
+
ambiguousOutcomeMessage: "Version seal outcome is unknown; read the Version (specflow version get): if it is sealed, the seal was applied",
|
|
600
|
+
}));
|
|
601
|
+
});
|
|
602
|
+
scoped(version.command("progress"))
|
|
603
|
+
.description("Read three-track progress, the forecast, signals and the derived burn-up")
|
|
604
|
+
.action(async (options) => {
|
|
605
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
606
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
607
|
+
if ("failure" in resolved)
|
|
608
|
+
return resolved.failure;
|
|
609
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/progress", {
|
|
610
|
+
params: {
|
|
611
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
612
|
+
},
|
|
613
|
+
});
|
|
614
|
+
}, read));
|
|
615
|
+
});
|
|
616
|
+
scoped(version.command("activity"))
|
|
617
|
+
.description("Read the Version feed merged with its items' own events, newest first")
|
|
618
|
+
.option("--limit <limit>", "Page size, 1 to 100", parseLimit)
|
|
619
|
+
.option("--cursor <cursor>", "The nextCursor of the previous page")
|
|
620
|
+
.action(async (options) => {
|
|
621
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
622
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
623
|
+
if ("failure" in resolved)
|
|
624
|
+
return resolved.failure;
|
|
625
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/activity", {
|
|
626
|
+
params: {
|
|
627
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
628
|
+
query: {
|
|
629
|
+
...(options.limit === undefined ? {} : { limit: options.limit }),
|
|
630
|
+
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
});
|
|
634
|
+
}, read));
|
|
635
|
+
});
|
|
636
|
+
const baseline = version.command("baseline").description("Read a sealed Version's Baseline");
|
|
637
|
+
scoped(baseline.command("get"))
|
|
638
|
+
.description("Read the Spec and Glossary Revisions a sealed Version recorded")
|
|
639
|
+
.action(async (options) => {
|
|
640
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
641
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
642
|
+
if ("failure" in resolved)
|
|
643
|
+
return resolved.failure;
|
|
644
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/baseline", {
|
|
645
|
+
params: {
|
|
646
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
}, read));
|
|
650
|
+
});
|
|
651
|
+
scoped(version.command("compare"))
|
|
652
|
+
.description("Compare a sealed Version with another sealed Version, or with the current published content")
|
|
653
|
+
.option("--to <version>", "Another sealed Version; omitted compares with current content", parseVersionReference)
|
|
654
|
+
.option("--planned-only <side>", "Only the planned scope of one side: from or to", (value) => {
|
|
655
|
+
if (value === "from" || value === "to")
|
|
656
|
+
return value;
|
|
657
|
+
throw invalidArgument("--planned-only must be from or to");
|
|
658
|
+
})
|
|
659
|
+
.action(async (options) => {
|
|
660
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
661
|
+
const resolved = await resolveVersions(client, options.workspaceId, [
|
|
662
|
+
options.versionId,
|
|
663
|
+
...(options.to === undefined ? [] : [options.to]),
|
|
664
|
+
]);
|
|
665
|
+
if ("failure" in resolved)
|
|
666
|
+
return resolved.failure;
|
|
667
|
+
const [versionId = "", to] = resolved.ids;
|
|
668
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/compare", {
|
|
669
|
+
params: {
|
|
670
|
+
path: { workspaceId: options.workspaceId, versionId },
|
|
671
|
+
query: {
|
|
672
|
+
...(to === undefined ? {} : { to }),
|
|
673
|
+
...(options.plannedOnly === undefined ? {} : { plannedOnly: options.plannedOnly }),
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
}, read));
|
|
678
|
+
});
|
|
679
|
+
workspace(version.command("references"))
|
|
680
|
+
.description("List the Versions whose scope names these Work Items, Specs or Glossary entries")
|
|
681
|
+
.option("--work-item <id>", "Work Item public id such as PAY-123; repeatable", collect(parseWorkItemReference))
|
|
682
|
+
.option("--spec <id>", "Spec id such as PAY-S12; repeatable", collect(parseSpecReference))
|
|
683
|
+
.option("--term <entryId>", "Glossary entry id; repeatable", collect(parseIdentity("Glossary entry ID")))
|
|
684
|
+
.action(async (options) => {
|
|
685
|
+
if ([options.workItem, options.spec, options.term].every((list) => list === undefined))
|
|
686
|
+
throw invalidArgument("Name at least one --work-item, --spec or --term");
|
|
687
|
+
runtime.setExitCode(await runtime.run((client) => client.GET("/v1/workspaces/{workspaceId}/version-references", {
|
|
688
|
+
params: {
|
|
689
|
+
path: { workspaceId: options.workspaceId },
|
|
690
|
+
query: {
|
|
691
|
+
...(options.workItem === undefined ? {} : { workItem: options.workItem }),
|
|
692
|
+
...(options.spec === undefined ? {} : { spec: options.spec }),
|
|
693
|
+
...(options.term === undefined ? {} : { glossaryEntry: options.term }),
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
}), read));
|
|
697
|
+
});
|
|
698
|
+
registerScopeCommands(version, runtime, { scoped, expected, guard, uncertain, read });
|
|
699
|
+
}
|
|
700
|
+
function registerScopeCommands(version, runtime, helpers) {
|
|
701
|
+
const { scoped, expected, guard, uncertain, read } = helpers;
|
|
702
|
+
const scope = version
|
|
703
|
+
.command("scope")
|
|
704
|
+
.description("Plan a Version's Work Items, Scenario changes and Glossary changes");
|
|
705
|
+
scoped(scope.command("list"))
|
|
706
|
+
.description("List every Scope Item with completion and signals")
|
|
707
|
+
.action(async (options) => {
|
|
708
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
709
|
+
const resolved = await resolveVersions(client, options.workspaceId, [options.versionId]);
|
|
710
|
+
if ("failure" in resolved)
|
|
711
|
+
return resolved.failure;
|
|
712
|
+
return await client.GET("/v1/workspaces/{workspaceId}/versions/{versionId}/scope", {
|
|
713
|
+
params: {
|
|
714
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
715
|
+
},
|
|
716
|
+
});
|
|
717
|
+
}, read));
|
|
718
|
+
});
|
|
719
|
+
expected(scope.command("add"))
|
|
720
|
+
.description("Add Work Items (moved here from another unsealed Version), Scenario changes or Glossary changes")
|
|
721
|
+
.option("--work-item <id>", "Work Item public id such as PAY-123; repeatable", collect(parseWorkItemReference))
|
|
722
|
+
.option("--scenario <id>", "Scenario id such as PAY-S12-3; repeatable; needs --change", collect(parseScenarioReference))
|
|
723
|
+
.option("--spec <id>", "Spec id for an added Scenario not written yet; needs --change added and --title", parseSpecReference)
|
|
724
|
+
.option("--term <entryId>", "Glossary entry id; repeatable; needs --change", collect(parseIdentity("Glossary entry ID")))
|
|
725
|
+
.option("--new-term <title>", "A term to be added that is not registered yet; needs --change added")
|
|
726
|
+
.option("--change <change>", "added, modified or removed (Scenarios and terms)", parseChange)
|
|
727
|
+
.option("--title <title>", "Working title of an added Scenario named only by --spec")
|
|
728
|
+
.option("--note <text>", "Note on the Scenario or term changes")
|
|
729
|
+
.option("--optional", "Add as optional (可选); items are required by default")
|
|
730
|
+
.action(async (options) => {
|
|
731
|
+
const changes = (options.scenario?.length ?? 0) +
|
|
732
|
+
(options.spec === undefined ? 0 : 1) +
|
|
733
|
+
(options.term?.length ?? 0) +
|
|
734
|
+
(options.newTerm === undefined ? 0 : 1);
|
|
735
|
+
if ((options.workItem?.length ?? 0) + changes === 0)
|
|
736
|
+
throw invalidArgument("Name at least one --work-item, --scenario, --spec, --term or --new-term");
|
|
737
|
+
if (changes > 0 && options.change === undefined)
|
|
738
|
+
throw invalidArgument("Scenario and Glossary changes need --change added|modified|removed");
|
|
739
|
+
if (changes === 0 && (options.change ?? options.note) !== undefined)
|
|
740
|
+
throw invalidArgument("--change and --note apply only to Scenario and Glossary changes");
|
|
741
|
+
if ((options.spec !== undefined || options.newTerm !== undefined) &&
|
|
742
|
+
options.change !== "added")
|
|
743
|
+
throw invalidArgument("--spec and --new-term register a change that is added");
|
|
744
|
+
if (options.spec !== undefined && options.title === undefined)
|
|
745
|
+
throw invalidArgument("--spec needs --title for the Scenario to be written");
|
|
746
|
+
if (options.title !== undefined && options.spec === undefined)
|
|
747
|
+
throw invalidArgument("--title applies only with --spec");
|
|
748
|
+
if (!guard())
|
|
749
|
+
return;
|
|
750
|
+
const change = options.change ?? "added";
|
|
751
|
+
const shared = {
|
|
752
|
+
change,
|
|
753
|
+
...(options.note === undefined ? {} : { note: options.note }),
|
|
754
|
+
...(options.optional === true ? { required: false } : {}),
|
|
755
|
+
};
|
|
756
|
+
const items = [
|
|
757
|
+
...(options.workItem ?? []).map((workItem) => ({
|
|
758
|
+
kind: "workItem",
|
|
759
|
+
workItem,
|
|
760
|
+
...(options.optional === true ? { required: false } : {}),
|
|
761
|
+
})),
|
|
762
|
+
...(options.scenario ?? []).map((scenario) => ({
|
|
763
|
+
kind: "scenario",
|
|
764
|
+
spec: scenario.spec,
|
|
765
|
+
scenarioId: scenario.scenarioId,
|
|
766
|
+
...shared,
|
|
767
|
+
})),
|
|
768
|
+
...(options.spec === undefined
|
|
769
|
+
? []
|
|
770
|
+
: [
|
|
771
|
+
{
|
|
772
|
+
kind: "scenario",
|
|
773
|
+
spec: options.spec,
|
|
774
|
+
title: options.title ?? "",
|
|
775
|
+
...shared,
|
|
776
|
+
},
|
|
777
|
+
]),
|
|
778
|
+
...(options.term ?? []).map((entryId) => ({
|
|
779
|
+
kind: "glossaryEntry",
|
|
780
|
+
entryId,
|
|
781
|
+
...shared,
|
|
782
|
+
})),
|
|
783
|
+
...(options.newTerm === undefined
|
|
784
|
+
? []
|
|
785
|
+
: [{ kind: "glossaryEntry", title: options.newTerm, ...shared }]),
|
|
786
|
+
];
|
|
787
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
788
|
+
const resolved = await resolveVersions(client, options.workspaceId, [
|
|
789
|
+
options.versionId,
|
|
790
|
+
]);
|
|
791
|
+
if ("failure" in resolved)
|
|
792
|
+
return resolved.failure;
|
|
793
|
+
return await client.POST("/v1/workspaces/{workspaceId}/versions/{versionId}/scope", {
|
|
794
|
+
params: {
|
|
795
|
+
path: { workspaceId: options.workspaceId, versionId: resolved.ids[0] ?? "" },
|
|
796
|
+
header: { "if-match": options.expectedVersion },
|
|
797
|
+
},
|
|
798
|
+
body: { items },
|
|
799
|
+
});
|
|
800
|
+
}, uncertain("Scope add")));
|
|
801
|
+
});
|
|
802
|
+
const itemCommand = (name, description) => expected(scope.command(name))
|
|
803
|
+
.description(description)
|
|
804
|
+
.requiredOption("--item <item>", "Scope Item id, or the Work Item (PAY-123), Scenario (PAY-S12-3) or Glossary entry id it plans", parseItemReference);
|
|
805
|
+
const withItem = async (client, options, more) => {
|
|
806
|
+
const resolved = await resolveVersions(client, options.workspaceId, [
|
|
807
|
+
options.versionId,
|
|
808
|
+
...more,
|
|
809
|
+
]);
|
|
810
|
+
if ("failure" in resolved)
|
|
811
|
+
return resolved;
|
|
812
|
+
const [versionId = "", ...others] = resolved.ids;
|
|
813
|
+
const found = await resolveItems(client, options.workspaceId, versionId, [options.item]);
|
|
814
|
+
if ("failure" in found)
|
|
815
|
+
return found;
|
|
816
|
+
return { versionId, others, itemId: found.items[0]?.id ?? "" };
|
|
817
|
+
};
|
|
818
|
+
itemCommand("remove", "Remove one item from a Version's scope").action(async (options) => {
|
|
819
|
+
if (!guard())
|
|
820
|
+
return;
|
|
821
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
822
|
+
const target = await withItem(client, options, []);
|
|
823
|
+
if ("failure" in target)
|
|
824
|
+
return target.failure;
|
|
825
|
+
return await client.DELETE("/v1/workspaces/{workspaceId}/versions/{versionId}/scope/{itemId}", {
|
|
826
|
+
params: {
|
|
827
|
+
path: {
|
|
828
|
+
workspaceId: options.workspaceId,
|
|
829
|
+
versionId: target.versionId,
|
|
830
|
+
itemId: target.itemId,
|
|
831
|
+
},
|
|
832
|
+
header: { "if-match": options.expectedVersion },
|
|
833
|
+
},
|
|
834
|
+
});
|
|
835
|
+
}, uncertain("Scope remove")));
|
|
836
|
+
});
|
|
837
|
+
itemCommand("move", "Move one item to another unsealed Version; it becomes required there")
|
|
838
|
+
.requiredOption("--to <version>", "Target Version id or name", parseVersionReference)
|
|
839
|
+
.action(async (options) => {
|
|
840
|
+
if (!guard())
|
|
841
|
+
return;
|
|
842
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
843
|
+
const target = await withItem(client, options, [options.to]);
|
|
844
|
+
if ("failure" in target)
|
|
845
|
+
return target.failure;
|
|
846
|
+
return await client.POST("/v1/workspaces/{workspaceId}/versions/{versionId}/scope/{itemId}/move", {
|
|
847
|
+
params: {
|
|
848
|
+
path: {
|
|
849
|
+
workspaceId: options.workspaceId,
|
|
850
|
+
versionId: target.versionId,
|
|
851
|
+
itemId: target.itemId,
|
|
852
|
+
},
|
|
853
|
+
header: { "if-match": options.expectedVersion },
|
|
854
|
+
},
|
|
855
|
+
body: { targetVersionId: target.others[0] ?? "" },
|
|
856
|
+
});
|
|
857
|
+
}, uncertain("Scope move")));
|
|
858
|
+
});
|
|
859
|
+
const patch = async (options, body, subject) => {
|
|
860
|
+
runtime.setExitCode(await runtime.run(async (client) => {
|
|
861
|
+
const target = await withItem(client, options, []);
|
|
862
|
+
if ("failure" in target)
|
|
863
|
+
return target.failure;
|
|
864
|
+
return await client.PATCH("/v1/workspaces/{workspaceId}/versions/{versionId}/scope/{itemId}", {
|
|
865
|
+
params: {
|
|
866
|
+
path: {
|
|
867
|
+
workspaceId: options.workspaceId,
|
|
868
|
+
versionId: target.versionId,
|
|
869
|
+
itemId: target.itemId,
|
|
870
|
+
},
|
|
871
|
+
header: { "if-match": options.expectedVersion },
|
|
872
|
+
},
|
|
873
|
+
body,
|
|
874
|
+
});
|
|
875
|
+
}, uncertain(subject)));
|
|
876
|
+
};
|
|
877
|
+
itemCommand("set-optional", "Mark one item optional (可选), or required again with --required; only required items count toward risk")
|
|
878
|
+
.option("--required", "Mark the item required (必须) instead")
|
|
879
|
+
.action(async (options) => {
|
|
880
|
+
if (!guard())
|
|
881
|
+
return;
|
|
882
|
+
await patch(options, { required: options.required === true }, "Scope optional change");
|
|
883
|
+
});
|
|
884
|
+
itemCommand("update", "Edit an item's note, or link an added item to its published Scenario or term")
|
|
885
|
+
.option("--note <text>", "New note")
|
|
886
|
+
.option("--clear-note", "Remove the note")
|
|
887
|
+
.option("--link <id>", "Scenario id (PAY-S12-3) or Glossary entry id the added item became")
|
|
888
|
+
.action(async (options) => {
|
|
889
|
+
if (options.note !== undefined && options.clearNote === true)
|
|
890
|
+
throw invalidArgument("Cannot set and clear the note together");
|
|
891
|
+
const body = {
|
|
892
|
+
...(options.clearNote === true
|
|
893
|
+
? { note: null }
|
|
894
|
+
: options.note === undefined
|
|
895
|
+
? {}
|
|
896
|
+
: { note: options.note }),
|
|
897
|
+
...(options.link === undefined ? {} : { link: options.link.trim() }),
|
|
898
|
+
};
|
|
899
|
+
if (Object.keys(body).length === 0)
|
|
900
|
+
throw invalidArgument("Scope update requires --note, --clear-note or --link");
|
|
901
|
+
if (!guard())
|
|
902
|
+
return;
|
|
903
|
+
await patch(options, body, "Scope update");
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
/** Spec Labels reference the Workspace's Label definitions; assigning one is not a Publish. */
|
|
907
|
+
export function registerSpecLabelCommands(spec, runtime) {
|
|
908
|
+
const labels = spec
|
|
909
|
+
.command("labels")
|
|
910
|
+
.description("Read and replace the Workspace Labels on Specs (not a Publish)");
|
|
911
|
+
labels
|
|
912
|
+
.command("list")
|
|
913
|
+
.description("List Specs with their Label ids, optionally only named Specs or those with every Label")
|
|
914
|
+
.requiredOption("--workspace-id <workspaceId>", "Workspace ID", parseWorkspaceId)
|
|
915
|
+
.option("--spec-id <specId>", "Only this Spec; repeatable", collect(parseSpecReference))
|
|
916
|
+
.option("--label-id <labelId>", "Only Specs carrying this Label; repeat to require every one", collect(parseIdentity("Label ID")))
|
|
917
|
+
.option("--json", "Emit structured JSON (the default)")
|
|
918
|
+
.action(async (options) => {
|
|
919
|
+
runtime.setExitCode(await runtime.run((client) => client.GET("/v1/workspaces/{workspaceId}/spec-labels", {
|
|
920
|
+
params: {
|
|
921
|
+
path: { workspaceId: options.workspaceId },
|
|
922
|
+
query: {
|
|
923
|
+
...(options.specId === undefined ? {} : { spec: options.specId }),
|
|
924
|
+
...(options.labelId === undefined ? {} : { labelId: options.labelId }),
|
|
925
|
+
},
|
|
926
|
+
},
|
|
927
|
+
}), { rejectWorkspaceReadToken: true }));
|
|
928
|
+
});
|
|
929
|
+
labels
|
|
930
|
+
.command("definitions")
|
|
931
|
+
.description("List the Workspace Label definitions (id, name, colour) a Spec Label references")
|
|
932
|
+
.requiredOption("--workspace-id <workspaceId>", "Workspace ID", parseWorkspaceId)
|
|
933
|
+
.option("--json", "Emit structured JSON (the default)")
|
|
934
|
+
.action(async (options) => {
|
|
935
|
+
runtime.setExitCode(await runtime.run((client) => client.GET("/v1/workspaces/{workspaceId}/labels", {
|
|
936
|
+
params: { path: { workspaceId: options.workspaceId } },
|
|
937
|
+
}), { rejectWorkspaceReadToken: true }));
|
|
938
|
+
});
|
|
939
|
+
labels
|
|
940
|
+
.command("set")
|
|
941
|
+
.description("Replace a Spec's Labels with exactly the given Label ids (--clear removes all)")
|
|
942
|
+
.requiredOption("--workspace-id <workspaceId>", "Workspace ID", parseWorkspaceId)
|
|
943
|
+
.requiredOption("--spec-id <specId>", "Spec ID such as PAY-S12")
|
|
944
|
+
.option("--label-id <labelId>", "Workspace Label definition id; repeat for several", collect(parseIdentity("Label ID")))
|
|
945
|
+
.option("--clear", "Remove every Label from the Spec")
|
|
946
|
+
.option("--json", "Emit structured JSON (the default)")
|
|
947
|
+
.action(async (options) => {
|
|
948
|
+
if ((options.labelId === undefined) === (options.clear !== true))
|
|
949
|
+
throw invalidArgument("Pass --label-id (repeatable) or --clear");
|
|
950
|
+
if (!runtime.canWrite()) {
|
|
951
|
+
runtime.setExitCode(runtime.rejectWrite());
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
runtime.setExitCode(await runtime.run((client) => client.PUT("/v1/workspaces/{workspaceId}/specs/{specId}/labels", {
|
|
955
|
+
params: { path: { workspaceId: options.workspaceId, specId: options.specId } },
|
|
956
|
+
body: { labelIds: [...new Set(options.labelId ?? [])] },
|
|
957
|
+
}),
|
|
958
|
+
// Replacing with the same set is idempotent, so a lost answer may be retried once.
|
|
959
|
+
{
|
|
960
|
+
rejectWorkspaceReadToken: true,
|
|
961
|
+
retryTransportOnce: true,
|
|
962
|
+
ambiguousOutcomeMessage: "Spec Label outcome is unknown; run specflow spec labels list --spec-id before retrying",
|
|
963
|
+
}));
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
//# sourceMappingURL=version-commands.js.map
|