qatools-cli 1.2.14 → 1.2.17
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/impact.js +125 -0
- package/package.json +5 -3
- package/qatools.js +216 -3
package/impact.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// testing.regression-impact: which verified requirements does a range of commits touch?
|
|
2
|
+
// Line level: a commit puts requirement X at risk when it changes or deletes lines that X's commits wrote
|
|
3
|
+
// (found with git blame on the version before the commit). A commit's own requirements are not at risk
|
|
4
|
+
// from it, and pure additions put nobody at risk. A requirement's commits are those whose message names its
|
|
5
|
+
// key ("feat(key): …", "[req:key]") and those recorded on its evidence.
|
|
6
|
+
const { execFileSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const DEFAULT_IGNORE = [
|
|
9
|
+
/(^|\/)package-lock\.json$/, /(^|\/)yarn\.lock$/, /(^|\/)pnpm-lock\.yaml$/, /(^|\/)packages\.lock\.json$/,
|
|
10
|
+
/(^|\/)version\.(json|ts)$/, /\.md$/i, /(^|\/)\.firebase\//,
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function git(cwd, args) {
|
|
14
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", maxBuffer: 256 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isGitRepo(cwd) {
|
|
18
|
+
try { return git(cwd, ["rev-parse", "--is-inside-work-tree"]).trim() === "true"; } catch { return false; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Commits as { sha, parent, message }, newest first. range: "a..b" or a ref; maxCommits limits history.
|
|
22
|
+
function readCommits(cwd, range, maxCommits) {
|
|
23
|
+
const args = ["log", "--no-merges", "--format=%x1e%H%x1f%P%x1f%B"];
|
|
24
|
+
if (maxCommits) args.push(`-n${maxCommits}`);
|
|
25
|
+
if (range) args.push(range);
|
|
26
|
+
return git(cwd, args).split("\x1e").filter(s => s.trim()).map(chunk => {
|
|
27
|
+
const [sha, parents, message] = chunk.split("\x1f");
|
|
28
|
+
return { sha: sha.trim(), parent: (parents || "").trim().split(" ")[0] || "", message: message || "" };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Requirement keys named in a commit message, among the known keys.
|
|
33
|
+
function keysIn(message, knownKeys) {
|
|
34
|
+
const found = new Set();
|
|
35
|
+
for (const m of message.matchAll(/[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)+/g)) if (knownKeys.has(m[0])) found.add(m[0]);
|
|
36
|
+
for (const m of message.matchAll(/\[req:([\w.\-/]+)\]/gi)) if (knownKeys.has(m[1])) found.add(m[1]);
|
|
37
|
+
return found;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Lines a commit changed or deleted, as ranges in its parent's version: { file → [[start, count], …] }.
|
|
41
|
+
function changedOldLines(cwd, sha, parent) {
|
|
42
|
+
const out = git(cwd, ["diff", "-U0", "--no-color", "--no-renames", parent, sha]);
|
|
43
|
+
const byFile = new Map();
|
|
44
|
+
let file = null, hunk = null;
|
|
45
|
+
const close = () => {
|
|
46
|
+
// A release bump of "version" in package.json is not a change to anyone's code.
|
|
47
|
+
const versionOnly = /(^|\/)package\.json$/.test(hunk?.file || "") && hunk.removed.every(l => /^\s*"version"\s*:/.test(l));
|
|
48
|
+
if (hunk && hunk.count > 0 && !versionOnly) {
|
|
49
|
+
if (!byFile.has(hunk.file)) byFile.set(hunk.file, []);
|
|
50
|
+
byFile.get(hunk.file).push([hunk.start, hunk.count]);
|
|
51
|
+
}
|
|
52
|
+
hunk = null;
|
|
53
|
+
};
|
|
54
|
+
for (const line of out.split("\n")) {
|
|
55
|
+
if (line.startsWith("--- ")) { close(); file = line === "--- /dev/null" ? null : line.slice(6); continue; }
|
|
56
|
+
const m = line.match(/^@@ -(\d+)(?:,(\d+))? \+/);
|
|
57
|
+
if (m) { close(); if (file) hunk = { file, start: +m[1], count: m[2] === undefined ? 1 : +m[2], removed: [] }; continue; }
|
|
58
|
+
if (hunk && line.startsWith("-")) hunk.removed.push(line.slice(1));
|
|
59
|
+
}
|
|
60
|
+
close();
|
|
61
|
+
return byFile;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Which commits wrote the given line ranges of a file at a revision (one git blame call per file).
|
|
65
|
+
function blameCommits(cwd, rev, file, ranges) {
|
|
66
|
+
// --porcelain always prints full hashes (the default format shortens boundary commits to "^" + 39 chars).
|
|
67
|
+
const args = ["blame", "--porcelain"];
|
|
68
|
+
for (const [start, count] of ranges) args.push("-L", `${start},+${count}`);
|
|
69
|
+
args.push(rev, "--", file);
|
|
70
|
+
try {
|
|
71
|
+
const out = new Set();
|
|
72
|
+
for (const l of git(cwd, args).split("\n")) { const m = l.match(/^([0-9a-f]{40}) \d+ \d+/); if (m) out.add(m[1]); }
|
|
73
|
+
return out;
|
|
74
|
+
} catch { return new Set(); }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function baseForDate(cwd, date) {
|
|
78
|
+
return git(cwd, ["rev-list", "-1", `--before=${date}T00:00:00`, "HEAD"]).trim() || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {object} o
|
|
83
|
+
* @param {string} o.cwd repository
|
|
84
|
+
* @param {string} o.base range start (exclusive)
|
|
85
|
+
* @param {string} [o.head] range end, default HEAD
|
|
86
|
+
* @param {Array} o.requirements [{ id, key, status, evidenceLog }]
|
|
87
|
+
* @param {number} [o.maxCommits] history depth used to learn which commits belong to which requirement
|
|
88
|
+
* @param {RegExp[]} [o.ignore] files never considered
|
|
89
|
+
*/
|
|
90
|
+
function computeImpact({ cwd, base, head = "HEAD", requirements, maxCommits = 5000, ignore = DEFAULT_IGNORE }) {
|
|
91
|
+
const known = new Set(requirements.map(r => r.key));
|
|
92
|
+
const keep = (f) => !ignore.some(rx => rx.test(f));
|
|
93
|
+
// commit sha → requirement keys it was made for
|
|
94
|
+
const keysByCommit = new Map();
|
|
95
|
+
const addKey = (sha, key) => { if (!keysByCommit.has(sha)) keysByCommit.set(sha, new Set()); keysByCommit.get(sha).add(key); };
|
|
96
|
+
for (const c of readCommits(cwd, head, maxCommits)) for (const k of keysIn(c.message, known)) addKey(c.sha, k);
|
|
97
|
+
for (const r of requirements) for (const e of r.evidenceLog || []) {
|
|
98
|
+
if (!e.commit) continue;
|
|
99
|
+
try { addKey(git(cwd, ["rev-parse", e.commit]).trim(), r.key); } catch { /* commit not in this clone */ }
|
|
100
|
+
}
|
|
101
|
+
const verified = new Map(requirements.filter(r => r.status === "implemented" || r.status === "tested").map(r => [r.key, r]));
|
|
102
|
+
const hits = new Map(); // key → { files:Set, commits:Set }
|
|
103
|
+
const range = readCommits(cwd, `${base}..${head}`, 0);
|
|
104
|
+
for (const c of range) {
|
|
105
|
+
if (!c.parent) continue;
|
|
106
|
+
const own = keysIn(c.message, known);
|
|
107
|
+
for (const [file, ranges] of changedOldLines(cwd, c.sha, c.parent)) {
|
|
108
|
+
if (!keep(file)) continue;
|
|
109
|
+
for (const author of blameCommits(cwd, c.parent, file, ranges)) {
|
|
110
|
+
for (const key of keysByCommit.get(author) || []) {
|
|
111
|
+
if (own.has(key) || !verified.has(key)) continue;
|
|
112
|
+
if (!hits.has(key)) hits.set(key, { files: new Set(), commits: new Set() });
|
|
113
|
+
hits.get(key).files.add(file); hits.get(key).commits.add(c.sha);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const affected = [...hits].map(([key, h]) => {
|
|
119
|
+
const r = verified.get(key);
|
|
120
|
+
return { id: r.id, key, status: r.status, files: [...h.files].sort(), commits: [...h.commits] };
|
|
121
|
+
}).sort((a, b) => a.key.localeCompare(b.key));
|
|
122
|
+
return { base, head: git(cwd, ["rev-parse", head]).trim(), commitsInRange: range.length, mappedCommits: keysByCommit.size, affected };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = { computeImpact, isGitRepo, baseForDate, keysIn, DEFAULT_IGNORE };
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qatools-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
4
4
|
"description": "CLI for QA Tools — requirements, epics, sprints, sessions, App Context sync, project agenda. The companion to qa-tools.com.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"release": "npm version patch --no-git-tag-version && npm publish",
|
|
7
|
-
"release:minor": "npm version minor --no-git-tag-version && npm publish"
|
|
7
|
+
"release:minor": "npm version minor --no-git-tag-version && npm publish",
|
|
8
|
+
"test": "node --test \"test/*.test.js\""
|
|
8
9
|
},
|
|
9
10
|
"bin": {
|
|
10
11
|
"qatools": "qatools.js"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
|
-
"qatools.js"
|
|
14
|
+
"qatools.js",
|
|
15
|
+
"impact.js"
|
|
14
16
|
],
|
|
15
17
|
"keywords": [
|
|
16
18
|
"qa",
|
package/qatools.js
CHANGED
|
@@ -687,12 +687,13 @@ const REQ_TAG = /\[req:([\w.\-/]+)\]/i;
|
|
|
687
687
|
|
|
688
688
|
function parseJUnit(xml) {
|
|
689
689
|
const out = [];
|
|
690
|
-
|
|
690
|
+
// Attribute values may contain ">" (Node's JUnit reporter does not escape it), so quoted values are skipped whole.
|
|
691
|
+
for (const m of xml.matchAll(/<testcase\b((?:[^>"']|"[^"]*"|'[^']*')*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g)) {
|
|
691
692
|
const attrs = xmlAttrs(m[1]);
|
|
692
693
|
const body = m[2] || "";
|
|
693
694
|
const name = [attrs.classname, attrs.name].filter(Boolean).join(" › ") || "(unnamed test)";
|
|
694
695
|
let requirementKey = "";
|
|
695
|
-
for (const p of body.matchAll(/<property\b([^>]*?)\/?>/g)) {
|
|
696
|
+
for (const p of body.matchAll(/<property\b((?:[^>"']|"[^"]*"|'[^']*')*?)\/?>/g)) {
|
|
696
697
|
const pa = xmlAttrs(p[1]);
|
|
697
698
|
if (/^requirement[-_]?key$/i.test(pa.name || "")) requirementKey = pa.value || "";
|
|
698
699
|
}
|
|
@@ -761,6 +762,7 @@ program
|
|
|
761
762
|
for (const [k, rs] of Object.entries(byKey)) console.log(` ${k}: ${rs.map(r => `${r.status === "pass" ? "✓" : r.status === "fail" ? "✗" : "–"} ${r.name}`).join(", ")}`);
|
|
762
763
|
if (tagged.length < results.length) console.log(` (untagged: ${results.length - tagged.length})`);
|
|
763
764
|
console.log(`Run: ${meta.source} ${meta.commit ? meta.commit.slice(0, 8) : "(no commit)"} ${meta.branch || ""}`);
|
|
765
|
+
console.log("Dry run — nothing was uploaded. Without --dry-run, success ends with \"Uploaded run <id>\" and any failure exits with code 1.");
|
|
764
766
|
process.exit(0);
|
|
765
767
|
}
|
|
766
768
|
|
|
@@ -2623,6 +2625,7 @@ App Context → Epics → Requirements → Sprint → Implementation → Test
|
|
|
2623
2625
|
3. Implement according to acceptanceCriteria AND negativeCriteria.
|
|
2624
2626
|
Every piece of code must be traceable to a requirementKey.
|
|
2625
2627
|
When done and verified: \`--status implemented --evidence "<verification>"\`. If you stop without finishing, set it back to \`approved\` (clears the assignee).
|
|
2628
|
+
New requirements must not break old ones: when you changed shared code, run \`qatools impact --since <ref> --flag\` and verify the requirements it lists again.
|
|
2626
2629
|
|
|
2627
2630
|
4. If you discover something unexpected during implementation:
|
|
2628
2631
|
- Behavior doesn't match a requirement → create AVV: \`qatools backlog-create -d "..." -t bug --requirement-key <key>\`
|
|
@@ -3597,6 +3600,8 @@ const MCP_INSTRUCTIONS = `qa-tools: requirements-driven QA. Rules that apply to
|
|
|
3597
3600
|
- Backlog flow: open → in_progress → ready_for_test → resolved. Set ready_for_test when you believe a fix is done; resolved needs evidence (min 10 chars) and, except GAP, a prior ready_for_test.
|
|
3598
3601
|
- Requirement status implemented/tested needs evidence: test output, file:line, expected vs actual, or "no test applies because <reason>".
|
|
3599
3602
|
- Requirement flow: approved → in_progress → implemented → tested. When you start implementing an approved requirement, set status in_progress and assignedTo "me" (update_requirement); if you stop without finishing, set it back to approved.
|
|
3603
|
+
- Requirements with a libraryId inherit from the account's requirement library: never try to change their title, description, criteria, type or category — only applicability, status, sprint, epic and assignee are the project's. When get_agenda lists libraryReverify, verify those requirements again against the new library text.
|
|
3604
|
+
- New requirements must not break old ones: before completing a sprint or release, and after building something that touched shared code, run requirement_impact (sprint or since) with flag: true, and verify the listed requirements again. Put their manual tests in a "Regression" section of the sprint's test protocol.
|
|
3600
3605
|
- Sprint planning: plan approved, functional requirements only (update_requirement sprintId), never backlog items; non-functional requirements are continuous and never go into sprints. Gather facts first (list_sprints, sprint_velocity, list_epics, list_requirements), respect epic dependsOn, present the plan as a table (sprint | requirement | reason) and change NOTHING until the user approves it in this conversation. If the user isn't here or wants to decide later, save it with propose_sprint_plan instead — they approve in qa-tools. Full procedure: prompt plan_sprints.
|
|
3601
3606
|
- Every tool takes an optional projectId; without it the configured project (qatools setup) is used.`;
|
|
3602
3607
|
|
|
@@ -4043,6 +4048,44 @@ const mcpTools = [
|
|
|
4043
4048
|
return { updated: a.itemId, fields: Object.keys(u) };
|
|
4044
4049
|
},
|
|
4045
4050
|
},
|
|
4051
|
+
{
|
|
4052
|
+
name: "requirement_impact",
|
|
4053
|
+
description: "Regression check (testing.regression-impact): which implemented/tested requirements had their files changed by other work in a range of commits. Runs in the server's working directory, which must be the project's git repository. Use before completing a sprint or a release, and after building a requirement that touched shared code. flag: true records the risk in qa-tools; then verify those requirements again (tests, a session, or new evidence).",
|
|
4054
|
+
inputSchema: mcpSchema({ since: mcpStr("Range start: a git ref"), sprint: mcpStr("Range start: this sprint's start date (id or name)"), flag: { type: "boolean", description: "Record the risk in qa-tools" } }),
|
|
4055
|
+
run: async (a) => runImpact({ projectId: a.projectId || getCredentials()?.projectId, since: a.since, sprint: a.sprint, flag: !!a.flag }),
|
|
4056
|
+
},
|
|
4057
|
+
{
|
|
4058
|
+
name: "list_requirement_library",
|
|
4059
|
+
description: "The account's requirement library (library.shared-requirements): requirements shared by all projects of the same owner, with key, title, category, type and version.",
|
|
4060
|
+
inputSchema: mcpSchema({ category: mcpStr("Only this category") }),
|
|
4061
|
+
run: async (a) => {
|
|
4062
|
+
const { entries } = await mcpCall("listRequirementLibrary", { projectId: a.projectId });
|
|
4063
|
+
return a.category ? entries.filter(e => (e.category || "").toLowerCase() === a.category.toLowerCase()) : entries;
|
|
4064
|
+
},
|
|
4065
|
+
},
|
|
4066
|
+
{
|
|
4067
|
+
name: "share_requirement_to_library",
|
|
4068
|
+
description: "Share a project requirement into the account's library; the requirement then inherits from it. Give generic wording in text and keep what is specific to this project in applicability. You cannot change a library entry afterwards — only the owner can.",
|
|
4069
|
+
inputSchema: mcpSchema({
|
|
4070
|
+
requirementId: mcpStr("Requirement document ID"),
|
|
4071
|
+
text: { type: "object", description: "Generic wording for the library", properties: { title: mcpStr("Title"), description: mcpStr("Description"), acceptanceCriteria: mcpStr("Given/When/Then"), negativeCriteria: mcpStr("Negative Given/When/Then"), category: mcpStr("Category") }, additionalProperties: false },
|
|
4072
|
+
applicability: mcpStr("What is specific to this project, e.g. 'Applies to Twilio, SendGrid, Auth0'"),
|
|
4073
|
+
}, ["requirementId"]),
|
|
4074
|
+
run: async (a) => mcpCall("shareRequirementToLibrary", { projectId: a.projectId, ...mcpPick(a, ["requirementId", "text", "applicability"]) }),
|
|
4075
|
+
},
|
|
4076
|
+
{
|
|
4077
|
+
name: "inherit_library_requirements",
|
|
4078
|
+
description: "Inherit library entries into the project, by keys or a whole category. What you inherit is created as drafts for a member to approve.",
|
|
4079
|
+
inputSchema: mcpSchema({ keys: mcpStrArray("Library keys"), category: mcpStr("Every entry in this category"), applicability: mcpStr("What they apply to in this project") }),
|
|
4080
|
+
run: async (a) => {
|
|
4081
|
+
let libraryIds;
|
|
4082
|
+
if (a.keys?.length) {
|
|
4083
|
+
const { entries } = await mcpCall("listRequirementLibrary", { projectId: a.projectId });
|
|
4084
|
+
libraryIds = entries.filter(e => a.keys.includes(e.key)).map(e => e.id);
|
|
4085
|
+
}
|
|
4086
|
+
return mcpCall("inheritLibraryRequirements", { projectId: a.projectId, libraryIds, category: a.category, applicability: a.applicability });
|
|
4087
|
+
},
|
|
4088
|
+
},
|
|
4046
4089
|
{
|
|
4047
4090
|
name: "create_test_protocol",
|
|
4048
4091
|
description: "Create a sprint's manual test protocol after a plan was approved in this conversation (sprint.ai-planning-manual-tests). Only tests a person must perform — what you can verify yourself belongs in automated tests in the code. It is saved for review (pending_review); a project member approves it under Test protocols, never you.",
|
|
@@ -4168,7 +4211,7 @@ Follow these steps in order:
|
|
|
4168
4211
|
4. STOP and ask the user: approve here, or save it as a proposal to decide later in qa-tools? Change nothing before that. Apply any adjustments the user asks for and show the table again.
|
|
4169
4212
|
- If nobody is there to answer (an unattended run), or the user chooses "later": call propose_sprint_plan with the same rows, and report the result. Do not apply anything yourself.
|
|
4170
4213
|
5. After approval in this conversation: create_sprint for any new sprints, then update_requirement with sprintId for each planned requirement. Report each change and any refusal verbatim — never retry a refused change in a different way.
|
|
4171
|
-
6. Manual tests, per sprint: draft a test protocol with the tests a person must perform because you can't verify them yourself — look and feel, real mobile devices, e-mail/SMS actually arriving, BankID/Freja, printing/PDF, flows between several parties. Each test has requirementKey (a requirement planned in that sprint) and a purpose saying why a person must do it. What you can verify yourself goes into automated tests in the code, not here. Show the tests with the plan. With propose_sprint_plan, pass them as testProtocols (approved together with the proposal). After approval in the conversation, save each with create_test_protocol (pending review — a member approves it). A sprint with nothing that needs a person gets no protocol; say so.
|
|
4214
|
+
6. Manual tests, per sprint: draft a test protocol with the tests a person must perform because you can't verify them yourself — look and feel, real mobile devices, e-mail/SMS actually arriving, BankID/Freja, printing/PDF, flows between several parties. Each test has requirementKey (a requirement planned in that sprint) and a purpose saying why a person must do it. What you can verify yourself goes into automated tests in the code, not here. Show the tests with the plan. With propose_sprint_plan, pass them as testProtocols (approved together with the proposal). After approval in the conversation, save each with create_test_protocol (pending review — a member approves it). A sprint with nothing that needs a person gets no protocol; say so. Regression: run requirement_impact for the sprint; the approved manual tests of requirements it lists (or that get_agenda lists under regressionRisk) go into a section "Regression" of the same protocol.
|
|
4172
4215
|
7. End with get_sprint_items for each affected sprint so the user can see the result.`,
|
|
4173
4216
|
},
|
|
4174
4217
|
{
|
|
@@ -4271,6 +4314,176 @@ program
|
|
|
4271
4314
|
rl.on("close", () => process.exit(0));
|
|
4272
4315
|
});
|
|
4273
4316
|
|
|
4317
|
+
// ==================== REQUIREMENT LIBRARY (library.shared-requirements, library.inheritance) ====================
|
|
4318
|
+
const reqLibraryCmd = program
|
|
4319
|
+
.command("library")
|
|
4320
|
+
.description("The account's requirement library: requirements shared by all projects of the same owner");
|
|
4321
|
+
|
|
4322
|
+
function libraryProject(options) {
|
|
4323
|
+
const creds = getCredentials();
|
|
4324
|
+
const projectId = options.project || creds?.projectId;
|
|
4325
|
+
if (!projectId) { console.error("No project configured. Run: qatools setup, or pass --project <id>"); process.exit(1); }
|
|
4326
|
+
return projectId;
|
|
4327
|
+
}
|
|
4328
|
+
|
|
4329
|
+
reqLibraryCmd
|
|
4330
|
+
.command("list")
|
|
4331
|
+
.description("List the library of the project owner's account")
|
|
4332
|
+
.option("--category <name>", "Only this category")
|
|
4333
|
+
.option("--json", "Output as JSON")
|
|
4334
|
+
.option("--project <id>", "Project whose owner's library to show (default: configured project)")
|
|
4335
|
+
.action(async (options) => {
|
|
4336
|
+
await authenticate(options);
|
|
4337
|
+
const projectId = libraryProject(options);
|
|
4338
|
+
try {
|
|
4339
|
+
const { data } = await httpsCallable(functions, "listRequirementLibrary")({ projectId });
|
|
4340
|
+
let entries = data.entries;
|
|
4341
|
+
if (options.category) entries = entries.filter(e => (e.category || "").toLowerCase() === options.category.toLowerCase());
|
|
4342
|
+
if (options.json) { console.log(JSON.stringify(entries, null, 2)); process.exit(0); }
|
|
4343
|
+
console.log(`\nRequirement library of ${data.owner} — ${entries.length} entr${entries.length === 1 ? "y" : "ies"}:\n`);
|
|
4344
|
+
for (const e of entries) console.log(` [${e.key}] v${e.version} ${e.title} (${e.category || "no category"}, ${e.type}) id: ${e.id}`);
|
|
4345
|
+
} catch (e) { console.error("Failed:", e.message); process.exit(1); }
|
|
4346
|
+
process.exit(0);
|
|
4347
|
+
});
|
|
4348
|
+
|
|
4349
|
+
reqLibraryCmd
|
|
4350
|
+
.command("share")
|
|
4351
|
+
.description("Share a project requirement into the library; the requirement then inherits from it")
|
|
4352
|
+
.requiredOption("-i, --id <requirementId>", "Requirement to share")
|
|
4353
|
+
.option("-f, --file <path>", "JSON with generic wording for the library: { title, description, acceptanceCriteria, negativeCriteria, category }")
|
|
4354
|
+
.option("--applicability <text>", "What is specific to this project (kept on the project's requirement)")
|
|
4355
|
+
.option("--project <id>", "Target project ID")
|
|
4356
|
+
.action(async (options) => {
|
|
4357
|
+
await authenticate(options);
|
|
4358
|
+
const projectId = libraryProject(options);
|
|
4359
|
+
const payload = { projectId, requirementId: options.id };
|
|
4360
|
+
if (options.file) payload.text = JSON.parse(fs.readFileSync(path.resolve(options.file), "utf8"));
|
|
4361
|
+
if (options.applicability !== undefined) payload.applicability = options.applicability;
|
|
4362
|
+
try {
|
|
4363
|
+
const { data } = await httpsCallable(functions, "shareRequirementToLibrary")(payload);
|
|
4364
|
+
console.log(`Shared ${data.key} to the library as v${data.version} (id ${data.libraryId}). The requirement now inherits from it.`);
|
|
4365
|
+
} catch (e) { console.error("Failed:", e.message); process.exit(1); }
|
|
4366
|
+
process.exit(0);
|
|
4367
|
+
});
|
|
4368
|
+
|
|
4369
|
+
reqLibraryCmd
|
|
4370
|
+
.command("inherit")
|
|
4371
|
+
.description("Inherit library entries into the project (by key or a whole category)")
|
|
4372
|
+
.option("--key <keys>", "Comma-separated library keys")
|
|
4373
|
+
.option("--category <name>", "Every entry in this category")
|
|
4374
|
+
.option("--applicability <text>", "What the requirements apply to in this project")
|
|
4375
|
+
.option("--project <id>", "Target project ID")
|
|
4376
|
+
.action(async (options) => {
|
|
4377
|
+
await authenticate(options);
|
|
4378
|
+
const projectId = libraryProject(options);
|
|
4379
|
+
if (!options.key && !options.category) { console.error("Give --key or --category"); process.exit(1); }
|
|
4380
|
+
try {
|
|
4381
|
+
let libraryIds;
|
|
4382
|
+
if (options.key) {
|
|
4383
|
+
const { data } = await httpsCallable(functions, "listRequirementLibrary")({ projectId });
|
|
4384
|
+
const keys = options.key.split(",").map(k => k.trim()).filter(Boolean);
|
|
4385
|
+
const unknown = keys.filter(k => !data.entries.some(e => e.key === k));
|
|
4386
|
+
if (unknown.length) { console.error(`Not in the library: ${unknown.join(", ")}`); process.exit(1); }
|
|
4387
|
+
libraryIds = data.entries.filter(e => keys.includes(e.key)).map(e => e.id);
|
|
4388
|
+
}
|
|
4389
|
+
const { data } = await httpsCallable(functions, "inheritLibraryRequirements")({ projectId, libraryIds, category: options.category, applicability: options.applicability });
|
|
4390
|
+
console.log(`Inherited ${data.inherited.length} as ${data.status}: ${data.inherited.join(", ") || "—"}`);
|
|
4391
|
+
for (const s of data.skipped) console.log(` skipped ${s.key}: ${s.reason}`);
|
|
4392
|
+
} catch (e) { console.error("Failed:", e.message); process.exit(1); }
|
|
4393
|
+
process.exit(0);
|
|
4394
|
+
});
|
|
4395
|
+
|
|
4396
|
+
reqLibraryCmd
|
|
4397
|
+
.command("update")
|
|
4398
|
+
.description("Change a library entry (owner only). The new text reaches every project that inherits it.")
|
|
4399
|
+
.requiredOption("--key <key>", "Library key")
|
|
4400
|
+
.option("--title <text>", "New title")
|
|
4401
|
+
.option("--description <text>", "New description")
|
|
4402
|
+
.option("--ac <text>", "New acceptance criteria")
|
|
4403
|
+
.option("--negative <text>", "New negative criteria")
|
|
4404
|
+
.option("--category <name>", "New category")
|
|
4405
|
+
.option("--project <id>", "A project of the owner (default: configured project)")
|
|
4406
|
+
.action(async (options) => {
|
|
4407
|
+
await authenticate(options);
|
|
4408
|
+
const projectId = libraryProject(options);
|
|
4409
|
+
const updates = {};
|
|
4410
|
+
if (options.title) updates.title = options.title;
|
|
4411
|
+
if (options.description) updates.description = options.description;
|
|
4412
|
+
if (options.ac) updates.acceptanceCriteria = options.ac;
|
|
4413
|
+
if (options.negative) updates.negativeCriteria = options.negative;
|
|
4414
|
+
if (options.category) updates.category = options.category;
|
|
4415
|
+
try {
|
|
4416
|
+
const list = (await httpsCallable(functions, "listRequirementLibrary")({ projectId })).data.entries;
|
|
4417
|
+
const entry = list.find(e => e.key === options.key);
|
|
4418
|
+
if (!entry) { console.error(`Not in the library: ${options.key}`); process.exit(1); }
|
|
4419
|
+
const { data } = await httpsCallable(functions, "updateLibraryRequirement")({ projectId, libraryId: entry.id, updates });
|
|
4420
|
+
console.log(`${options.key} is now v${data.version}; ${data.updatedRequirements} inheriting requirement(s) in ${data.projects} project(s) got the new text.`);
|
|
4421
|
+
} catch (e) { console.error("Failed:", e.message); process.exit(1); }
|
|
4422
|
+
process.exit(0);
|
|
4423
|
+
});
|
|
4424
|
+
|
|
4425
|
+
// ==================== REGRESSION IMPACT (testing.regression-impact) ====================
|
|
4426
|
+
// Runs in the project's repository: which verified requirements did a range of commits touch?
|
|
4427
|
+
async function runImpact({ projectId, since, sprint, flag, cwd = process.cwd() }) {
|
|
4428
|
+
const { computeImpact, isGitRepo, baseForDate } = require("./impact");
|
|
4429
|
+
if (!isGitRepo(cwd)) throw new Error("qatools impact must run in the project's git repository");
|
|
4430
|
+
let base = since || null, rangeLabel = since ? `${since}..HEAD` : "";
|
|
4431
|
+
if (!base && sprint) {
|
|
4432
|
+
const { sprints } = (await httpsCallable(functions, "listSprints")({ projectId })).data;
|
|
4433
|
+
const s = sprints.find(x => x.id === sprint || x.name === sprint);
|
|
4434
|
+
if (!s) throw new Error(`Sprint not found: ${sprint}`);
|
|
4435
|
+
if (!s.startDate) throw new Error(`Sprint "${s.name}" has no start date — use --since <ref>`);
|
|
4436
|
+
base = baseForDate(cwd, s.startDate);
|
|
4437
|
+
rangeLabel = `since ${s.name} started (${s.startDate})`;
|
|
4438
|
+
if (!base) throw new Error(`No commit before ${s.startDate} — use --since <ref>`);
|
|
4439
|
+
}
|
|
4440
|
+
if (!base) throw new Error("Give --since <ref> or --sprint <id|name>");
|
|
4441
|
+
const { requirements } = (await httpsCallable(functions, "listRequirements")({ projectId, status: null })).data;
|
|
4442
|
+
const latest = new Map();
|
|
4443
|
+
for (const r of requirements) {
|
|
4444
|
+
if (r.status === "superseded") continue;
|
|
4445
|
+
const cur = latest.get(r.key);
|
|
4446
|
+
if (!cur || (r.version || 1) > (cur.version || 1)) latest.set(r.key, r);
|
|
4447
|
+
}
|
|
4448
|
+
const result = computeImpact({ cwd, base, requirements: [...latest.values()] });
|
|
4449
|
+
result.range = rangeLabel;
|
|
4450
|
+
if (flag && result.affected.length) {
|
|
4451
|
+
const res = (await httpsCallable(functions, "flagRegressionRisk")({
|
|
4452
|
+
projectId, base, head: result.head,
|
|
4453
|
+
items: result.affected.map(a => ({ requirementId: a.id, files: a.files })),
|
|
4454
|
+
})).data;
|
|
4455
|
+
result.flagged = res.flagged;
|
|
4456
|
+
result.skipped = res.skipped;
|
|
4457
|
+
}
|
|
4458
|
+
return result;
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
program
|
|
4462
|
+
.command("impact")
|
|
4463
|
+
.description("Verified requirements whose files changed in other work (run in the project's repository)")
|
|
4464
|
+
.option("--since <ref>", "Range start: a git ref (commit, tag, branch)")
|
|
4465
|
+
.option("--sprint <id>", "Range start: the sprint's start date (id or name)")
|
|
4466
|
+
.option("--flag", "Record the risk on the requirements in qa-tools (shown on cards, sprint view and agenda)")
|
|
4467
|
+
.option("--json", "Output as JSON")
|
|
4468
|
+
.option("--project <id>", "Target project ID")
|
|
4469
|
+
.action(async (options) => {
|
|
4470
|
+
await authenticate(options);
|
|
4471
|
+
const creds = getCredentials();
|
|
4472
|
+
const projectId = options.project || creds?.projectId;
|
|
4473
|
+
if (!projectId) { console.error("No project configured. Run: qatools setup, or pass --project <id>"); process.exit(1); }
|
|
4474
|
+
try {
|
|
4475
|
+
const r = await runImpact({ projectId, since: options.since, sprint: options.sprint, flag: options.flag });
|
|
4476
|
+
if (options.json) { console.log(JSON.stringify(r, null, 2)); process.exit(0); }
|
|
4477
|
+
console.log(`\n${r.commitsInRange} commit(s) ${r.range}; ${r.mappedCommits} commit(s) linked to requirements through their messages and evidence.`);
|
|
4478
|
+
if (!r.affected.length) { console.log("No verified requirement had its files changed by other work."); process.exit(0); }
|
|
4479
|
+
console.log(`\n${r.affected.length} verified requirement(s) touched by other work — verify again:\n`);
|
|
4480
|
+
for (const a of r.affected) console.log(` ${a.key} (${a.status}): ${a.files.slice(0, 5).join(", ")}${a.files.length > 5 ? ` +${a.files.length - 5}` : ""}`);
|
|
4481
|
+
if (options.flag) console.log(`\nFlagged in qa-tools: ${(r.flagged || []).length}${(r.skipped || []).length ? `, skipped ${r.skipped.length}` : ""}.`);
|
|
4482
|
+
else console.log("\nAdd --flag to record this in qa-tools.");
|
|
4483
|
+
} catch (e) { console.error("Failed:", e.message); process.exit(1); }
|
|
4484
|
+
process.exit(0);
|
|
4485
|
+
});
|
|
4486
|
+
|
|
4274
4487
|
program.hook("preAction", async (_root, cmd) => {
|
|
4275
4488
|
if (cmd.name() === "mcp") return; // the MCP server reports through instructions and get_agenda
|
|
4276
4489
|
for (const w of await staleWarnings({ skipSkills: cmd.name() === "init" })) console.error(`⚠ ${w}`);
|