@virtocommerce/test-automation-framework 0.0.0-stage → 0.1.0-alpha.1

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 (233) hide show
  1. package/.biome/formatter.json +11 -0
  2. package/.biome/imports.json +52 -0
  3. package/.biome/preset.json +4 -0
  4. package/.biome/rules.json +45 -0
  5. package/.claude/agents/qa-automation-expert.md +119 -0
  6. package/.claude/agents/qa-coverage.md +96 -0
  7. package/.claude/agents/qa-explorer.md +112 -0
  8. package/.claude/agents/qa-healer.md +88 -0
  9. package/.claude/agents/qa-judge.md +102 -0
  10. package/.claude/agents/qa-planner.md +104 -0
  11. package/.claude/agents/qa-reviewer.md +121 -0
  12. package/.claude/checks/browser-secrets.mts +107 -0
  13. package/.claude/checks/contract.mts +469 -0
  14. package/.claude/checks/expectation-guard.mts +665 -0
  15. package/.claude/checks/explore-extractors.mts +4 -0
  16. package/.claude/checks/judge-verdict.mts +165 -0
  17. package/.claude/checks/project-facts.mts +491 -0
  18. package/.claude/checks/prove-fails.mts +770 -0
  19. package/.claude/checks/rank-gaps.mts +177 -0
  20. package/.claude/checks/readonly-shell.mts +740 -0
  21. package/.claude/checks/reconcile-run.mts +270 -0
  22. package/.claude/checks/scan-prompts.mts +351 -0
  23. package/.claude/checks/stand.mts +45 -0
  24. package/.claude/checks/test-duration.mts +134 -0
  25. package/.claude/checks/test-shape.mts +224 -0
  26. package/.claude/checks/ticket-card.mts +195 -0
  27. package/.claude/commands/qa-coverage.md +13 -0
  28. package/.claude/commands/qa-explore.md +17 -0
  29. package/.claude/commands/qa-heal.md +44 -0
  30. package/.claude/commands/qa-implement.md +60 -0
  31. package/.claude/commands/qa-plan.md +55 -0
  32. package/.claude/commands/qa-review.md +90 -0
  33. package/.claude/commands/qa.md +156 -0
  34. package/.claude/hooks/readonly-shell.mts +65 -0
  35. package/.claude/settings.json +15 -0
  36. package/.claude/skills/coverage-analysis/SKILL.md +107 -0
  37. package/.claude/skills/create-graphql-layer/SKILL.md +159 -0
  38. package/.claude/skills/create-ui-layer/SKILL.md +189 -0
  39. package/.claude/skills/explore-api/SKILL.md +74 -0
  40. package/.claude/skills/explore-frontend/SKILL.md +85 -0
  41. package/.claude/skills/framework-rules/SKILL.md +189 -0
  42. package/.claude/skills/heal-tests/SKILL.md +197 -0
  43. package/.claude/skills/heal-tests/guard-recipe.md +53 -0
  44. package/.claude/skills/judge-criteria/SKILL.md +40 -0
  45. package/.claude/skills/judge-criteria/coverage.md +9 -0
  46. package/.claude/skills/judge-criteria/expert.md +23 -0
  47. package/.claude/skills/judge-criteria/explorer.md +9 -0
  48. package/.claude/skills/judge-criteria/healer.md +13 -0
  49. package/.claude/skills/judge-criteria/planner.md +12 -0
  50. package/.claude/skills/plan-implementation/SKILL.md +82 -0
  51. package/.claude/skills/plan-implementation/contract-template.md +72 -0
  52. package/.claude/skills/plan-test-strategy/SKILL.md +100 -0
  53. package/.claude/skills/project-facts/SKILL.md +130 -0
  54. package/.claude/skills/read-change/SKILL.md +64 -0
  55. package/.claude/skills/read-ticket/SKILL.md +63 -0
  56. package/.claude/skills/read-ticket/providers.md +58 -0
  57. package/.claude/skills/review-pr/SKILL.md +152 -0
  58. package/.claude/skills/review-test-code/SKILL.md +208 -0
  59. package/.claude/skills/write-e2e-test/SKILL.md +175 -0
  60. package/.claude/skills/write-graphql-test/SKILL.md +158 -0
  61. package/.claude/skills/write-rest-api-test/SKILL.md +182 -0
  62. package/.claude/skills/write-security-test/SKILL.md +253 -0
  63. package/.qa/project.example.json +71 -0
  64. package/CHANGELOG.md +1 -0
  65. package/LICENSE +12 -0
  66. package/README.md +53 -2
  67. package/bin/install-qa-agents.mjs +94 -0
  68. package/dist/auth/credentials.d.ts +10 -0
  69. package/dist/auth/credentials.js +2 -0
  70. package/dist/auth/credentials.js.map +1 -0
  71. package/dist/auth/frontend-browser-sessions.d.ts +71 -0
  72. package/dist/auth/frontend-browser-sessions.js +130 -0
  73. package/dist/auth/frontend-browser-sessions.js.map +1 -0
  74. package/dist/auth/index.d.ts +9 -0
  75. package/dist/auth/index.js +5 -0
  76. package/dist/auth/index.js.map +1 -0
  77. package/dist/auth/platform-browser-sessions.d.ts +47 -0
  78. package/dist/auth/platform-browser-sessions.js +92 -0
  79. package/dist/auth/platform-browser-sessions.js.map +1 -0
  80. package/dist/auth/sign-in-lock.d.ts +14 -0
  81. package/dist/auth/sign-in-lock.js +70 -0
  82. package/dist/auth/sign-in-lock.js.map +1 -0
  83. package/dist/auth/storage-state.d.ts +3 -0
  84. package/dist/auth/storage-state.js +2 -0
  85. package/dist/auth/storage-state.js.map +1 -0
  86. package/dist/auth/token-client.d.ts +82 -0
  87. package/dist/auth/token-client.js +111 -0
  88. package/dist/auth/token-client.js.map +1 -0
  89. package/dist/auth/token-manager.d.ts +67 -0
  90. package/dist/auth/token-manager.js +138 -0
  91. package/dist/auth/token-manager.js.map +1 -0
  92. package/dist/core/default-reporters.d.ts +31 -0
  93. package/dist/core/default-reporters.js +36 -0
  94. package/dist/core/default-reporters.js.map +1 -0
  95. package/dist/core/default-use.d.ts +28 -0
  96. package/dist/core/default-use.js +25 -0
  97. package/dist/core/default-use.js.map +1 -0
  98. package/dist/core/env.d.ts +24 -0
  99. package/dist/core/env.js +33 -0
  100. package/dist/core/env.js.map +1 -0
  101. package/dist/core/error-message.d.ts +10 -0
  102. package/dist/core/error-message.js +13 -0
  103. package/dist/core/error-message.js.map +1 -0
  104. package/dist/core/index.d.ts +16 -0
  105. package/dist/core/index.js +11 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/is-ci.d.ts +14 -0
  108. package/dist/core/is-ci.js +18 -0
  109. package/dist/core/is-ci.js.map +1 -0
  110. package/dist/core/parse-env.d.ts +13 -0
  111. package/dist/core/parse-env.js +21 -0
  112. package/dist/core/parse-env.js.map +1 -0
  113. package/dist/core/projects.d.ts +24 -0
  114. package/dist/core/projects.js +33 -0
  115. package/dist/core/projects.js.map +1 -0
  116. package/dist/core/run-options.d.ts +31 -0
  117. package/dist/core/run-options.js +43 -0
  118. package/dist/core/run-options.js.map +1 -0
  119. package/dist/core/secret.d.ts +105 -0
  120. package/dist/core/secret.js +167 -0
  121. package/dist/core/secret.js.map +1 -0
  122. package/dist/core/string-schemas.d.ts +39 -0
  123. package/dist/core/string-schemas.js +56 -0
  124. package/dist/core/string-schemas.js.map +1 -0
  125. package/dist/core/url-path.d.ts +7 -0
  126. package/dist/core/url-path.js +2 -0
  127. package/dist/core/url-path.js.map +1 -0
  128. package/dist/dataset/collection.d.ts +44 -0
  129. package/dist/dataset/collection.js +76 -0
  130. package/dist/dataset/collection.js.map +1 -0
  131. package/dist/dataset/index.d.ts +11 -0
  132. package/dist/dataset/index.js +6 -0
  133. package/dist/dataset/index.js.map +1 -0
  134. package/dist/dataset/load-dataset.d.ts +39 -0
  135. package/dist/dataset/load-dataset.js +62 -0
  136. package/dist/dataset/load-dataset.js.map +1 -0
  137. package/dist/dataset/manifest.d.ts +77 -0
  138. package/dist/dataset/manifest.js +10 -0
  139. package/dist/dataset/manifest.js.map +1 -0
  140. package/dist/dataset/placeholders.d.ts +66 -0
  141. package/dist/dataset/placeholders.js +87 -0
  142. package/dist/dataset/placeholders.js.map +1 -0
  143. package/dist/dataset/seed-collection.d.ts +53 -0
  144. package/dist/dataset/seed-collection.js +115 -0
  145. package/dist/dataset/seed-collection.js.map +1 -0
  146. package/dist/dataset/seed-dataset.d.ts +70 -0
  147. package/dist/dataset/seed-dataset.js +138 -0
  148. package/dist/dataset/seed-dataset.js.map +1 -0
  149. package/dist/dataset/seed-events.d.ts +81 -0
  150. package/dist/dataset/seed-events.js +2 -0
  151. package/dist/dataset/seed-events.js.map +1 -0
  152. package/dist/dataset/seed-requests.d.ts +102 -0
  153. package/dist/dataset/seed-requests.js +160 -0
  154. package/dist/dataset/seed-requests.js.map +1 -0
  155. package/dist/dataset/seed-scope.d.ts +39 -0
  156. package/dist/dataset/seed-scope.js +67 -0
  157. package/dist/dataset/seed-scope.js.map +1 -0
  158. package/dist/fixtures/default-fixtures.d.ts +93 -0
  159. package/dist/fixtures/default-fixtures.js +105 -0
  160. package/dist/fixtures/default-fixtures.js.map +1 -0
  161. package/dist/fixtures/index.d.ts +2 -0
  162. package/dist/fixtures/index.js +2 -0
  163. package/dist/fixtures/index.js.map +1 -0
  164. package/dist/graphql/graphql-client.d.ts +78 -0
  165. package/dist/graphql/graphql-client.js +83 -0
  166. package/dist/graphql/graphql-client.js.map +1 -0
  167. package/dist/graphql/graphql-codegen.d.ts +56 -0
  168. package/dist/graphql/graphql-codegen.js +42 -0
  169. package/dist/graphql/graphql-codegen.js.map +1 -0
  170. package/dist/graphql/graphql-error.d.ts +54 -0
  171. package/dist/graphql/graphql-error.js +74 -0
  172. package/dist/graphql/graphql-error.js.map +1 -0
  173. package/dist/graphql/index.d.ts +6 -0
  174. package/dist/graphql/index.js +4 -0
  175. package/dist/graphql/index.js.map +1 -0
  176. package/dist/http/authentication.d.ts +16 -0
  177. package/dist/http/authentication.js +2 -0
  178. package/dist/http/authentication.js.map +1 -0
  179. package/dist/http/http-client.d.ts +110 -0
  180. package/dist/http/http-client.js +237 -0
  181. package/dist/http/http-client.js.map +1 -0
  182. package/dist/http/http-error.d.ts +26 -0
  183. package/dist/http/http-error.js +34 -0
  184. package/dist/http/http-error.js.map +1 -0
  185. package/dist/http/http-method.d.ts +2 -0
  186. package/dist/http/http-method.js +2 -0
  187. package/dist/http/http-method.js.map +1 -0
  188. package/dist/http/http-response.d.ts +137 -0
  189. package/dist/http/http-response.js +166 -0
  190. package/dist/http/http-response.js.map +1 -0
  191. package/dist/http/index.d.ts +7 -0
  192. package/dist/http/index.js +4 -0
  193. package/dist/http/index.js.map +1 -0
  194. package/dist/http/request-options.d.ts +62 -0
  195. package/dist/http/request-options.js +2 -0
  196. package/dist/http/request-options.js.map +1 -0
  197. package/dist/modules/index.d.ts +2 -0
  198. package/dist/modules/index.js +2 -0
  199. package/dist/modules/index.js.map +1 -0
  200. package/dist/modules/installed-modules.d.ts +86 -0
  201. package/dist/modules/installed-modules.js +135 -0
  202. package/dist/modules/installed-modules.js.map +1 -0
  203. package/docs/README.md +43 -0
  204. package/docs/concepts/areas.md +38 -0
  205. package/docs/concepts/auth.md +92 -0
  206. package/docs/concepts/config.md +102 -0
  207. package/docs/concepts/dataset.md +183 -0
  208. package/docs/concepts/environment.md +54 -0
  209. package/docs/concepts/fixtures.md +109 -0
  210. package/docs/concepts/graphql.md +76 -0
  211. package/docs/concepts/http.md +88 -0
  212. package/docs/concepts/modules.md +63 -0
  213. package/docs/concepts/secrets.md +50 -0
  214. package/docs/contributing/architecture.md +67 -0
  215. package/docs/contributing/conventions.md +39 -0
  216. package/docs/contributing/documentation.md +37 -0
  217. package/docs/contributing/releasing.md +76 -0
  218. package/docs/examples/auth.ts +20 -0
  219. package/docs/examples/config.ts +36 -0
  220. package/docs/examples/dataset.ts +70 -0
  221. package/docs/examples/environment.ts +8 -0
  222. package/docs/examples/fixtures.ts +41 -0
  223. package/docs/examples/getting-started.ts +22 -0
  224. package/docs/examples/graphql-codegen.ts +9 -0
  225. package/docs/examples/graphql.ts +32 -0
  226. package/docs/examples/http.ts +18 -0
  227. package/docs/examples/modules.ts +19 -0
  228. package/docs/examples/secrets.ts +11 -0
  229. package/docs/examples/tsconfig.json +10 -0
  230. package/docs/getting-started.md +106 -0
  231. package/docs/guides/generating-types.md +75 -0
  232. package/docs/guides/qa-agents.md +66 -0
  233. package/package.json +156 -4
@@ -0,0 +1,177 @@
1
+ import type { ProjectFacts } from "./project-facts.mts";
2
+
3
+ import { readFileSync } from "node:fs";
4
+ import { basename } from "node:path";
5
+
6
+ import { PROJECT_FACTS_PATH, readProjectFacts } from "./project-facts.mts";
7
+
8
+ export type Weights = ProjectFacts["coverageWeights"];
9
+
10
+ export type Gap = {
11
+ area: string;
12
+ surface: "graphql" | "rest" | "frontend";
13
+ name: string;
14
+ critical: boolean;
15
+ enabledOnStand: boolean;
16
+ uiWithoutApi: boolean;
17
+ factors?: Partial<Record<keyof Weights, number>>;
18
+ };
19
+
20
+ export type RankedGap = Gap & { score: number };
21
+
22
+ const CLI_FILE_NAME = "rank-gaps.mts";
23
+ const STDIN = 0;
24
+ const SCORE_PRECISION = 1e9;
25
+ const CRITICAL_RISK = 1;
26
+ const UI_WITHOUT_API_RISK = 0.5;
27
+ const SURFACES: readonly string[] = ["graphql", "rest", "frontend"];
28
+ const WEIGHT_KEYS: readonly (keyof Weights)[] = ["risk", "callFrequency", "runFrequency", "stability", "cost"];
29
+ const INPUT_DIR = /^\.qa\/[\w./-]+$/;
30
+ const FENCED_JSON = /```json\s*\n([\s\S]*?)\n```/;
31
+
32
+ function factorOf(gap: Gap, key: keyof Weights): number {
33
+ const value = gap.factors?.[key] ?? 0;
34
+ if (!Number.isFinite(value) || value < 0 || value > 1) {
35
+ throw new Error(`rank-gaps: factor ${key} of "${gap.name}" must be a number from 0 to 1`);
36
+ }
37
+ return value;
38
+ }
39
+
40
+ function scoreOf(gap: Gap, weights: Weights): number {
41
+ const risk =
42
+ factorOf(gap, "risk") + (gap.critical ? CRITICAL_RISK : 0) + (gap.uiWithoutApi ? UI_WITHOUT_API_RISK : 0);
43
+ const score =
44
+ weights.risk * risk +
45
+ weights.callFrequency * factorOf(gap, "callFrequency") +
46
+ weights.runFrequency * factorOf(gap, "runFrequency") +
47
+ weights.stability * factorOf(gap, "stability") -
48
+ weights.cost * factorOf(gap, "cost");
49
+ return Math.round(score * SCORE_PRECISION) / SCORE_PRECISION;
50
+ }
51
+
52
+ function compareText(left: string, right: string): number {
53
+ if (left === right) {
54
+ return 0;
55
+ }
56
+ return left < right ? -1 : 1;
57
+ }
58
+
59
+ function compareRanked(left: RankedGap, right: RankedGap): number {
60
+ if (left.enabledOnStand !== right.enabledOnStand) {
61
+ return left.enabledOnStand ? -1 : 1;
62
+ }
63
+ if (left.critical !== right.critical) {
64
+ return left.critical ? -1 : 1;
65
+ }
66
+ return (
67
+ right.score - left.score ||
68
+ compareText(left.name, right.name) ||
69
+ compareText(left.area, right.area) ||
70
+ compareText(left.surface, right.surface)
71
+ );
72
+ }
73
+
74
+ /**
75
+ * Ranks the coverage gaps, highest priority first. A gap's score is the weighted sum of its factors, each from 0 to
76
+ * 1: `risk` (raised by 1 when the gap is a critical flow and by 0.5 when a UI test has no API test under it),
77
+ * `callFrequency`, `runFrequency` and `stability` add to it, and `cost` (automation cost) takes from it, so a cheap gap
78
+ * comes first; scores are rounded to nine decimals so equal scores tie. The order is strict: gaps enabled on the stand
79
+ * before gaps that are not (a module or flag that is off), then critical flows before the others, then by score, highest
80
+ * first, then by name, then area, then surface. A critical gap therefore outranks a non-critical one whatever the
81
+ * scores and weights.
82
+ *
83
+ * @throws Error when a factor is not a number from 0 to 1.
84
+ */
85
+ export function rankGaps(gaps: readonly Gap[], weights: Weights): RankedGap[] {
86
+ return gaps.map((gap) => ({ ...gap, score: scoreOf(gap, weights) })).sort(compareRanked);
87
+ }
88
+
89
+ /** Marks a gap critical when its name or its area is one of the project's critical flows (case-insensitive). */
90
+ export function markCritical(gaps: readonly Gap[], critical: readonly string[]): Gap[] {
91
+ const flows = new Set(critical.map((flow) => flow.trim().toLowerCase()));
92
+ return gaps.map((gap) => ({
93
+ ...gap,
94
+ critical: gap.critical || flows.has(gap.name.toLowerCase()) || flows.has(gap.area.toLowerCase()),
95
+ }));
96
+ }
97
+
98
+ function isRecord(value: unknown): value is Record<string, unknown> {
99
+ return typeof value === "object" && value !== null && !Array.isArray(value);
100
+ }
101
+
102
+ function parseGap(value: unknown, index: number): Gap {
103
+ const path = `gaps[${index}]`;
104
+ if (!isRecord(value)) {
105
+ throw new Error(`rank-gaps: ${path} is not an object`);
106
+ }
107
+ const { area, surface, name, critical, enabledOnStand, uiWithoutApi, factors } = value;
108
+ if (typeof area !== "string" || typeof name !== "string" || name === "") {
109
+ throw new Error(`rank-gaps: ${path} needs a text area and name`);
110
+ }
111
+ if (typeof surface !== "string" || !SURFACES.includes(surface)) {
112
+ throw new Error(`rank-gaps: ${path}.surface must be graphql, rest or frontend`);
113
+ }
114
+ if (typeof critical !== "boolean" || typeof enabledOnStand !== "boolean" || typeof uiWithoutApi !== "boolean") {
115
+ throw new Error(`rank-gaps: ${path} needs true or false for critical, enabledOnStand and uiWithoutApi`);
116
+ }
117
+ const base = { area, name, critical, enabledOnStand, uiWithoutApi };
118
+ const gapSurface = surface === "graphql" || surface === "rest" ? surface : "frontend";
119
+ if (factors === undefined) {
120
+ return { ...base, surface: gapSurface };
121
+ }
122
+ if (!isRecord(factors)) {
123
+ throw new Error(`rank-gaps: ${path}.factors is not an object`);
124
+ }
125
+ const parsed: Partial<Record<keyof Weights, number>> = {};
126
+ for (const key of WEIGHT_KEYS) {
127
+ const factor = factors[key];
128
+ if (factor === undefined) {
129
+ continue;
130
+ }
131
+ if (typeof factor !== "number") {
132
+ throw new Error(`rank-gaps: ${path}.factors.${key} is not a number`);
133
+ }
134
+ parsed[key] = factor;
135
+ }
136
+ return { ...base, surface: gapSurface, factors: parsed };
137
+ }
138
+
139
+ /** Reads the gap list from a JSON array, a `{ "gaps": [...] }` object, or the first ```json block of a Markdown file. */
140
+ export function parseGaps(text: string): Gap[] {
141
+ let json: unknown;
142
+ try {
143
+ json = JSON.parse(FENCED_JSON.exec(text)?.[1] ?? text);
144
+ } catch {
145
+ throw new Error("rank-gaps: the input is not valid JSON");
146
+ }
147
+ const list = isRecord(json) ? json["gaps"] : json;
148
+ if (!Array.isArray(list)) {
149
+ throw new Error("rank-gaps: the input is not a list of gaps");
150
+ }
151
+ return list.map(parseGap);
152
+ }
153
+
154
+ function readInput(file: string | undefined): string {
155
+ if (file === undefined) {
156
+ return readFileSync(STDIN, "utf8");
157
+ }
158
+ if (!INPUT_DIR.test(file) || file.split("/").includes("..")) {
159
+ throw new Error("rank-gaps: the input file must be a path under .qa/");
160
+ }
161
+ try {
162
+ return readFileSync(file, "utf8");
163
+ } catch {
164
+ throw new Error("rank-gaps: the input file cannot be read");
165
+ }
166
+ }
167
+
168
+ if (basename(process.argv[1] ?? "") === CLI_FILE_NAME) {
169
+ try {
170
+ const facts = readProjectFacts(PROJECT_FACTS_PATH);
171
+ const gaps = markCritical(parseGaps(readInput(process.argv[2])), facts.critical);
172
+ process.stdout.write(`${JSON.stringify(rankGaps(gaps, facts.coverageWeights), null, 2)}\n`);
173
+ } catch (error) {
174
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
175
+ process.exitCode = 1;
176
+ }
177
+ }