@virtocommerce/test-automation-framework 0.1.0-alpha.1 → 0.2.0-alpha.20261127111327
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/.claude/agents/vc-qa-automation-expert.md +122 -0
- package/.claude/agents/{qa-coverage.md → vc-qa-coverage.md} +10 -7
- package/.claude/agents/{qa-explorer.md → vc-qa-explorer.md} +20 -15
- package/.claude/agents/{qa-healer.md → vc-qa-healer.md} +15 -13
- package/.claude/agents/{qa-judge.md → vc-qa-judge.md} +35 -35
- package/.claude/agents/{qa-planner.md → vc-qa-planner.md} +29 -16
- package/.claude/agents/{qa-reviewer.md → vc-qa-reviewer.md} +18 -11
- package/.claude/checks/browser-secrets.mts +45 -2
- package/.claude/checks/contract.mts +258 -33
- package/.claude/checks/facts-consistency.mts +335 -0
- package/.claude/checks/introspect.mts +157 -0
- package/.claude/checks/judge-verdict.mts +44 -3
- package/.claude/checks/probe.mts +91 -0
- package/.claude/checks/project-facts.mts +85 -6
- package/.claude/checks/prove-fails.mts +254 -59
- package/.claude/checks/prune.mts +584 -0
- package/.claude/checks/rank-gaps.mts +24 -5
- package/.claude/checks/readonly-shell.mts +137 -58
- package/.claude/checks/reconcile-run.mts +64 -7
- package/.claude/checks/run-record.mts +338 -0
- package/.claude/checks/stand-request.mts +76 -0
- package/.claude/checks/test-shape.mts +78 -14
- package/.claude/commands/vc-qa-coverage.md +20 -0
- package/.claude/commands/{qa-explore.md → vc-qa-explore.md} +4 -4
- package/.claude/commands/{qa-heal.md → vc-qa-heal.md} +6 -6
- package/.claude/commands/{qa-implement.md → vc-qa-implement.md} +7 -7
- package/.claude/commands/vc-qa-plan.md +64 -0
- package/.claude/commands/{qa-review.md → vc-qa-review.md} +12 -12
- package/.claude/commands/{qa.md → vc-qa.md} +31 -22
- package/.claude/hooks/readonly-shell.mts +1 -1
- package/.claude/skills/{coverage-analysis → vc-coverage-analysis}/SKILL.md +24 -15
- package/.claude/skills/{create-graphql-layer → vc-create-graphql-layer}/SKILL.md +5 -3
- package/.claude/skills/{create-ui-layer → vc-create-ui-layer}/SKILL.md +5 -3
- package/.claude/skills/vc-explore-api/SKILL.md +93 -0
- package/.claude/skills/{explore-frontend → vc-explore-frontend}/SKILL.md +15 -9
- package/.claude/skills/{framework-rules → vc-framework-rules}/SKILL.md +34 -11
- package/.claude/skills/{heal-tests → vc-heal-tests}/SKILL.md +21 -21
- package/.claude/skills/{heal-tests → vc-heal-tests}/guard-recipe.md +3 -3
- package/.claude/skills/{judge-criteria → vc-judge-criteria}/SKILL.md +5 -3
- package/.claude/skills/{judge-criteria → vc-judge-criteria}/expert.md +10 -5
- package/.claude/skills/{plan-implementation → vc-plan-implementation}/SKILL.md +23 -11
- package/.claude/skills/vc-plan-implementation/contract-template.md +86 -0
- package/.claude/skills/{plan-test-strategy → vc-plan-test-strategy}/SKILL.md +24 -14
- package/.claude/skills/{project-facts → vc-project-facts}/SKILL.md +58 -23
- package/.claude/skills/{read-change → vc-read-change}/SKILL.md +4 -4
- package/.claude/skills/{read-ticket → vc-read-ticket}/SKILL.md +3 -3
- package/.claude/skills/{review-pr → vc-review-pr}/SKILL.md +4 -4
- package/.claude/skills/{review-test-code → vc-review-test-code}/SKILL.md +29 -15
- package/.claude/skills/{write-e2e-test → vc-write-e2e-test}/SKILL.md +11 -7
- package/.claude/skills/{write-graphql-test → vc-write-graphql-test}/SKILL.md +11 -7
- package/.claude/skills/{write-rest-api-test → vc-write-rest-api-test}/SKILL.md +16 -11
- package/.claude/skills/{write-security-test → vc-write-security-test}/SKILL.md +15 -11
- package/CHANGELOG.md +121 -0
- package/README.md +17 -0
- package/bin/vc-qa-agents.mjs +595 -0
- package/dist/auth/browser-sessions.d.ts +88 -0
- package/dist/auth/browser-sessions.js +126 -0
- package/dist/auth/browser-sessions.js.map +1 -0
- package/dist/auth/index.d.ts +5 -5
- package/dist/auth/index.js +2 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/sign-in-strategies.d.ts +67 -0
- package/dist/auth/sign-in-strategies.js +121 -0
- package/dist/auth/sign-in-strategies.js.map +1 -0
- package/dist/auth/token-client.d.ts +9 -1
- package/dist/auth/token-client.js +9 -4
- package/dist/auth/token-client.js.map +1 -1
- package/dist/core/default-reporters.d.ts +9 -6
- package/dist/core/default-reporters.js +16 -16
- package/dist/core/default-reporters.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/secret-masking-reporter.d.ts +48 -0
- package/dist/core/secret-masking-reporter.js +78 -0
- package/dist/core/secret-masking-reporter.js.map +1 -0
- package/dist/fixtures/default-fixtures.d.ts +12 -9
- package/dist/fixtures/default-fixtures.js +12 -8
- package/dist/fixtures/default-fixtures.js.map +1 -1
- package/docs/README.md +3 -3
- package/docs/concepts/auth.md +68 -16
- package/docs/concepts/config.md +14 -6
- package/docs/concepts/dataset.md +5 -4
- package/docs/concepts/environment.md +17 -12
- package/docs/concepts/fixtures.md +23 -16
- package/docs/concepts/modules.md +2 -1
- package/docs/contributing/architecture.md +22 -15
- package/docs/contributing/documentation.md +10 -21
- package/docs/contributing/releasing.md +35 -21
- package/docs/examples/sign-in-strategies.ts +22 -0
- package/docs/getting-started.md +62 -1
- package/docs/guides/generating-types.md +5 -4
- package/docs/guides/qa-agents.md +193 -35
- package/package.json +4 -4
- package/templates/suite/.mcp.json +16 -0
- package/templates/suite/.qa/project.json +70 -0
- package/templates/suite/CLAUDE.template.md +62 -0
- package/templates/suite/allurerc.mjs +13 -0
- package/templates/suite/arrange/context.ts +15 -0
- package/templates/suite/arrange/index.ts +69 -0
- package/templates/suite/arrange/security.ts +78 -0
- package/templates/suite/biome.template.json +12 -0
- package/templates/suite/builders/security.ts +46 -0
- package/templates/suite/codegen.ts +27 -0
- package/templates/suite/env.example +10 -0
- package/templates/suite/env.ts +25 -0
- package/templates/suite/fixtures/index.ts +96 -0
- package/templates/suite/gitignore +13 -0
- package/templates/suite/pages/README.md +10 -0
- package/templates/suite/playwright.config.ts +48 -0
- package/templates/suite/scripts/generate-rest-types.ts +16 -0
- package/templates/suite/support/require-fields.ts +53 -0
- package/templates/suite/support/shopper.ts +51 -0
- package/templates/suite/support/store.ts +33 -0
- package/templates/suite/support/unique-id.ts +11 -0
- package/templates/suite/support/users.ts +6 -0
- package/templates/suite/tests/restapi/security/sign-in.spec.ts +23 -0
- package/templates/suite/tsconfig.json +33 -0
- package/.claude/agents/qa-automation-expert.md +0 -119
- package/.claude/commands/qa-coverage.md +0 -13
- package/.claude/commands/qa-plan.md +0 -55
- package/.claude/skills/explore-api/SKILL.md +0 -74
- package/.claude/skills/plan-implementation/contract-template.md +0 -72
- package/bin/install-qa-agents.mjs +0 -94
- package/dist/auth/frontend-browser-sessions.d.ts +0 -71
- package/dist/auth/frontend-browser-sessions.js +0 -130
- package/dist/auth/frontend-browser-sessions.js.map +0 -1
- package/dist/auth/platform-browser-sessions.d.ts +0 -47
- package/dist/auth/platform-browser-sessions.js +0 -92
- package/dist/auth/platform-browser-sessions.js.map +0 -1
- /package/.claude/skills/{judge-criteria → vc-judge-criteria}/coverage.md +0 -0
- /package/.claude/skills/{judge-criteria → vc-judge-criteria}/explorer.md +0 -0
- /package/.claude/skills/{judge-criteria → vc-judge-criteria}/healer.md +0 -0
- /package/.claude/skills/{judge-criteria → vc-judge-criteria}/planner.md +0 -0
- /package/.claude/skills/{read-ticket → vc-read-ticket}/providers.md +0 -0
|
@@ -4,15 +4,25 @@ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
|
4
4
|
|
|
5
5
|
import { passwordNames, runVariables } from "./browser-secrets.mts";
|
|
6
6
|
import { EXTRACTORS } from "./explore-extractors.mts";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
PROJECT_FACTS_PATH,
|
|
9
|
+
playwrightConfigArgs,
|
|
10
|
+
readProjectFactsIn,
|
|
11
|
+
SHORT_NAME_SEGMENT,
|
|
12
|
+
suitePackageDir,
|
|
13
|
+
toolLauncher,
|
|
14
|
+
} from "./project-facts.mts";
|
|
8
15
|
import { standOrigins } from "./stand.mts";
|
|
9
16
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
17
|
+
/**
|
|
18
|
+
* How the suite's tools start from the repository root (`toolLauncher`) and the suite's Playwright config arguments
|
|
19
|
+
* (`playwrightConfigArgs`), or undefined when the facts cannot be read.
|
|
20
|
+
*/
|
|
21
|
+
export type SuiteConfig = { launcher: readonly string[]; config: readonly string[] } | undefined;
|
|
12
22
|
|
|
13
|
-
export const READ_ONLY_AGENTS = ["qa-reviewer", "qa-explorer", "qa-coverage", "qa-judge"] as const;
|
|
23
|
+
export const READ_ONLY_AGENTS = ["vc-qa-reviewer", "vc-qa-explorer", "vc-qa-coverage", "vc-qa-judge"] as const;
|
|
14
24
|
|
|
15
|
-
export const HEALER_AGENT = "qa-healer";
|
|
25
|
+
export const HEALER_AGENT = "vc-qa-healer";
|
|
16
26
|
|
|
17
27
|
export const ALLOWED_QA_MODULES = [
|
|
18
28
|
"project-facts",
|
|
@@ -25,18 +35,27 @@ export const ALLOWED_QA_MODULES = [
|
|
|
25
35
|
"test-duration",
|
|
26
36
|
] as const;
|
|
27
37
|
|
|
28
|
-
export const JUDGE_AGENT = "qa-judge";
|
|
38
|
+
export const JUDGE_AGENT = "vc-qa-judge";
|
|
29
39
|
|
|
30
40
|
export const JUDGE_QA_MODULES = ["judge-verdict", "prove-fails"] as const;
|
|
31
41
|
|
|
32
42
|
export const JUDGE_WRITE_DIR = ".qa/judge";
|
|
33
43
|
|
|
34
|
-
export const EXPLORER_AGENT = "qa-explorer";
|
|
44
|
+
export const EXPLORER_AGENT = "vc-qa-explorer";
|
|
35
45
|
|
|
36
|
-
export const
|
|
46
|
+
export const EXPLORER_QA_MODULES = ["introspect", "probe"] as const;
|
|
47
|
+
|
|
48
|
+
export const COVERAGE_AGENT = "vc-qa-coverage";
|
|
37
49
|
|
|
38
50
|
export const EXPLORER_WRITE_DIR = ".qa/reports";
|
|
39
51
|
|
|
52
|
+
export const PROBE_DIR = ".qa/probes";
|
|
53
|
+
|
|
54
|
+
const PROBE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*[.](graphql|get)$/;
|
|
55
|
+
|
|
56
|
+
/** The probe files the explorer may write and `probe.mts` may send: `.qa/probes/<slug>.graphql` or `.get`. */
|
|
57
|
+
export const PROBE_FILE = new RegExp(`^${PROBE_DIR.replace(/[.]/g, "[.]")}/${PROBE_NAME.source.slice(1)}`);
|
|
58
|
+
|
|
40
59
|
export const HEALER_RUN_DIR = ".qa/runs";
|
|
41
60
|
|
|
42
61
|
export const BROWSER_TOOL_PREFIX = "mcp__playwright__browser_";
|
|
@@ -91,16 +110,21 @@ const TEST_DURATION_ARGUMENTS = [2, 3];
|
|
|
91
110
|
const PROVE_FAILS_PROJECT = /^--project=[\w.-]+$/;
|
|
92
111
|
const REPORTER_FLAG = /^--reporter=/;
|
|
93
112
|
const OUTPUT_VARIABLE = "PLAYWRIGHT_JSON_OUTPUT_FILE=";
|
|
94
|
-
const REVIEWER_AGENT = "qa-reviewer";
|
|
113
|
+
const REVIEWER_AGENT = "vc-qa-reviewer";
|
|
95
114
|
const REVIEWER_OUTPUT =
|
|
96
115
|
/^PLAYWRIGHT_JSON_OUTPUT_FILE=\.qa\/runs\/(?![Hh][Ee][Aa][Ll]-)[\w-]+\/review-list\.[\w-]+\.json$/;
|
|
97
116
|
const HEALER_REVIEW_OUTPUT =
|
|
98
117
|
/^PLAYWRIGHT_JSON_OUTPUT_FILE=\.qa\/runs\/heal-[a-z0-9]+(-[a-z0-9]+)*\/review-list\.[\w-]+\.json$/;
|
|
99
118
|
const NPX = "npx";
|
|
119
|
+
const NPM = "npm";
|
|
100
120
|
const NPX_NO_INSTALL = "--no";
|
|
101
121
|
const END_OF_OPTIONS = "--";
|
|
102
122
|
const QA_MODULE_PATH = modulePattern(ALLOWED_QA_MODULES);
|
|
103
123
|
const JUDGE_QA_MODULE_PATH = modulePattern([...ALLOWED_QA_MODULES, ...JUDGE_QA_MODULES]);
|
|
124
|
+
const EXPLORER_QA_MODULE_PATH = modulePattern([...ALLOWED_QA_MODULES, ...EXPLORER_QA_MODULES]);
|
|
125
|
+
const INTROSPECT_PATH = `${CHECKS_DIR}/introspect.mts`;
|
|
126
|
+
const PROBE_PATH = `${CHECKS_DIR}/probe.mts`;
|
|
127
|
+
const INTROSPECT_KINDS = ["graphql", "rest"];
|
|
104
128
|
const MAX_SHOWN_COMMAND = 80;
|
|
105
129
|
|
|
106
130
|
/**
|
|
@@ -168,6 +192,20 @@ function npxArgs(tokens: readonly string[]): readonly string[] | undefined {
|
|
|
168
192
|
return tokens[2] === END_OF_OPTIONS ? tokens.slice(3) : tokens.slice(2);
|
|
169
193
|
}
|
|
170
194
|
|
|
195
|
+
/**
|
|
196
|
+
* The words after the suite's tool launcher: `npx --no`, optionally then `--`, for the root's `node_modules` (also
|
|
197
|
+
* when the facts cannot be read), exactly `npm exec --prefix <suiteDir> --no --` for a suite that is its own npm
|
|
198
|
+
* project.
|
|
199
|
+
*/
|
|
200
|
+
function toolArgs(tokens: readonly string[], suite: SuiteConfig): readonly string[] | undefined {
|
|
201
|
+
const launcher = suite?.launcher;
|
|
202
|
+
if (launcher === undefined || launcher[0] === NPX) {
|
|
203
|
+
return npxArgs(tokens);
|
|
204
|
+
}
|
|
205
|
+
const launched = tokens.length > launcher.length && launcher.every((word, index) => tokens[index] === word);
|
|
206
|
+
return launched ? tokens.slice(launcher.length) : undefined;
|
|
207
|
+
}
|
|
208
|
+
|
|
171
209
|
function isConfigFlag(token: string): boolean {
|
|
172
210
|
return token === CONFIG_SHORT_FLAG || token.startsWith(CONFIG_FLAG);
|
|
173
211
|
}
|
|
@@ -176,7 +214,8 @@ function isConfigFlag(token: string): boolean {
|
|
|
176
214
|
* True when `args` carry exactly the suite's config arguments (`playwrightConfigArgs`): `--config=<suiteDir>` once,
|
|
177
215
|
* or no config flag for a suite at the repository root. An unknown config (the facts could not be read) never passes.
|
|
178
216
|
*/
|
|
179
|
-
function hasSuiteConfig(args: readonly string[],
|
|
217
|
+
function hasSuiteConfig(args: readonly string[], suite: SuiteConfig): boolean {
|
|
218
|
+
const config = suite?.config;
|
|
180
219
|
if (config === undefined) {
|
|
181
220
|
return false;
|
|
182
221
|
}
|
|
@@ -191,7 +230,7 @@ function namesEnvFile(path: string): boolean {
|
|
|
191
230
|
}
|
|
192
231
|
|
|
193
232
|
function isPlaywrightList(tokens: readonly string[], config: SuiteConfig): boolean {
|
|
194
|
-
const [tool, subcommand, ...rest] =
|
|
233
|
+
const [tool, subcommand, ...rest] = toolArgs(tokens, config) ?? [];
|
|
195
234
|
if (tool !== "playwright" || subcommand !== "test" || !rest.includes("--list")) {
|
|
196
235
|
return false;
|
|
197
236
|
}
|
|
@@ -231,11 +270,24 @@ function isQualityCall(tokens: readonly string[]): boolean {
|
|
|
231
270
|
return count && args.every(isRepoPath);
|
|
232
271
|
}
|
|
233
272
|
|
|
273
|
+
function qaModulePatternOf(agent: string | undefined): RegExp {
|
|
274
|
+
const bare = bareName(agent);
|
|
275
|
+
if (bare === JUDGE_AGENT) {
|
|
276
|
+
return JUDGE_QA_MODULE_PATH;
|
|
277
|
+
}
|
|
278
|
+
return bare === EXPLORER_AGENT ? EXPLORER_QA_MODULE_PATH : QA_MODULE_PATH;
|
|
279
|
+
}
|
|
280
|
+
|
|
234
281
|
function isQaModule(tokens: readonly string[], agent: string | undefined): boolean {
|
|
235
|
-
|
|
236
|
-
if (tokens[0] !== "node" || !pattern.test(tokens[1] ?? "")) {
|
|
282
|
+
if (tokens[0] !== "node" || !qaModulePatternOf(agent).test(tokens[1] ?? "")) {
|
|
237
283
|
return false;
|
|
238
284
|
}
|
|
285
|
+
if (tokens[1] === INTROSPECT_PATH) {
|
|
286
|
+
return tokens.length === 3 && INTROSPECT_KINDS.includes(tokens[2] ?? "");
|
|
287
|
+
}
|
|
288
|
+
if (tokens[1] === PROBE_PATH) {
|
|
289
|
+
return tokens.length === 3 && PROBE_FILE.test(tokens[2] ?? "");
|
|
290
|
+
}
|
|
239
291
|
if (tokens[1] === TEST_SHAPE_PATH || tokens[1] === TEST_DURATION_PATH) {
|
|
240
292
|
return isQualityCall(tokens);
|
|
241
293
|
}
|
|
@@ -259,19 +311,20 @@ function withoutOutputAssignment(tokens: readonly string[], agent: string | unde
|
|
|
259
311
|
}
|
|
260
312
|
|
|
261
313
|
/**
|
|
262
|
-
* True only for a single plain command on the allowlist:
|
|
314
|
+
* True only for a single plain command on the allowlist: `<launcher> playwright test --config=<suiteDir> --list
|
|
263
315
|
* --reporter=json|list|null …` (`--repeat-each=<1-2 digits>` allowed there, so a reviewer can list a series; the
|
|
264
316
|
* config flag exactly as `config` holds it, none for a suite at the repository root, and no path to a `.env` file),
|
|
265
317
|
* `git diff|log|show|status …`, `node .claude/checks/<module>.mts …` (`test-shape` and `test-duration` only with
|
|
266
|
-
* repository paths and a project name, as 1+ and 2-3 arguments); `qa-judge` also has `judge-verdict` and
|
|
267
|
-
* `prove-fails
|
|
268
|
-
*
|
|
318
|
+
* repository paths and a project name, as 1+ and 2-3 arguments); `vc-qa-judge` also has `judge-verdict` and
|
|
319
|
+
* `prove-fails`, and `vc-qa-explorer` has `introspect` (`graphql` or `rest`) and `probe` (one `.qa/probes/<slug>.graphql|get`
|
|
320
|
+
* file). The launcher is the suite's (`toolLauncher`): `npx --no`, optionally then `--` (npm 12 needs it before a
|
|
321
|
+
* tool whose next word is a flag), or `npm exec --prefix <suiteDir> --no --` for a suite that is its own npm project,
|
|
322
|
+
* so npm never fetches a package. Only `vc-qa-reviewer` may lead the listing with
|
|
269
323
|
* `PLAYWRIGHT_JSON_OUTPUT_FILE=.qa/runs/<contract-name>/review-list.<project>.json`, `<contract-name>` not starting
|
|
270
|
-
* with `heal-`, and `qa-healer` only with the directory `heal-<slug>`. No chaining, substitution, redirection, quoting,
|
|
324
|
+
* with `heal-`, and `vc-qa-healer` only with the directory `heal-<slug>`. No chaining, substitution, redirection, quoting,
|
|
271
325
|
* globbing or variable expansion.
|
|
272
326
|
*
|
|
273
|
-
* @param config the suite's Playwright config arguments
|
|
274
|
-
* command.
|
|
327
|
+
* @param config the suite's launcher and Playwright config arguments; undefined blocks every Playwright command.
|
|
275
328
|
*/
|
|
276
329
|
export function isReadOnlyCommand(command: string, agent: string | undefined, config: SuiteConfig): boolean {
|
|
277
330
|
const text = command.trim();
|
|
@@ -292,7 +345,7 @@ export function isReadOnlyCommand(command: string, agent: string | undefined, co
|
|
|
292
345
|
if (tokens[0] === "git") {
|
|
293
346
|
return isGitRead(tokens);
|
|
294
347
|
}
|
|
295
|
-
if (tokens[0] === NPX) {
|
|
348
|
+
if (tokens[0] === NPX || tokens[0] === NPM) {
|
|
296
349
|
return isPlaywrightList(tokens, config);
|
|
297
350
|
}
|
|
298
351
|
return isQaModule(tokens, agent);
|
|
@@ -310,7 +363,7 @@ function isRepoPath(token: string): boolean {
|
|
|
310
363
|
}
|
|
311
364
|
|
|
312
365
|
function isHealerPlaywright(tokens: readonly string[], config: SuiteConfig): boolean {
|
|
313
|
-
const [tool, subcommand, ...rest] =
|
|
366
|
+
const [tool, subcommand, ...rest] = toolArgs(tokens, config) ?? [];
|
|
314
367
|
if (tool !== "playwright" || subcommand !== "test" || !hasSuiteConfig(rest, config)) {
|
|
315
368
|
return false;
|
|
316
369
|
}
|
|
@@ -344,17 +397,18 @@ function isTypecheck(args: readonly string[], config: SuiteConfig): boolean {
|
|
|
344
397
|
if (args.length === 1) {
|
|
345
398
|
return args[0] === NO_EMIT;
|
|
346
399
|
}
|
|
347
|
-
const suiteDir = config?.[0]?.slice(CONFIG_PREFIX.length);
|
|
400
|
+
const suiteDir = config?.config[0]?.slice(CONFIG_PREFIX.length);
|
|
348
401
|
return suiteDir !== undefined && args.length === 3 && args[0] === "-p" && args[1] === suiteDir && args[2] === NO_EMIT;
|
|
349
402
|
}
|
|
350
403
|
|
|
351
404
|
/**
|
|
352
|
-
* True only for a single plain command the healer may run besides the read-only ones
|
|
353
|
-
* --config=<suiteDir>` (the config flag
|
|
405
|
+
* True only for a single plain command the healer may run besides the read-only ones, each tool started with the
|
|
406
|
+
* suite's launcher as {@link isReadOnlyCommand} takes it: `playwright test --config=<suiteDir>` (the config flag
|
|
407
|
+
* exactly as `config` holds it) on repository paths with `--project`,
|
|
354
408
|
* `--repeat-each`, `--retries=0`, `--reporter=list|json|null`, `--grep` or `-g` and `--list`, optionally led by
|
|
355
409
|
* `PLAYWRIGHT_JSON_OUTPUT_FILE=.qa/runs/heal-<slug>/<name>.json`; `node .claude/checks/expectation-guard.mts
|
|
356
|
-
* --snapshot|--base=<sha>`; `
|
|
357
|
-
*
|
|
410
|
+
* --snapshot|--base=<sha>`; `tsc --noEmit` and, for a suite in a directory, `tsc -p <suiteDir> --noEmit`; `biome
|
|
411
|
+
* check <paths>` with no flag. No path names a `.env` file. Nothing that fetches a package,
|
|
358
412
|
* writes to git, updates snapshots, picks another config or an output directory, and not the main session's
|
|
359
413
|
* `--repo-fingerprint`.
|
|
360
414
|
*/
|
|
@@ -376,7 +430,7 @@ export function isHealerCommand(command: string, config: SuiteConfig): boolean {
|
|
|
376
430
|
(third === "--snapshot" || GUARD_BASE.test(third))
|
|
377
431
|
);
|
|
378
432
|
}
|
|
379
|
-
const [tool, subcommand, ...args] =
|
|
433
|
+
const [tool, subcommand, ...args] = toolArgs(tokens, config) ?? [];
|
|
380
434
|
if (tool === "playwright") {
|
|
381
435
|
return isHealerPlaywright(tokens, config);
|
|
382
436
|
}
|
|
@@ -449,45 +503,62 @@ function isJudgeFile(segments: readonly string[]): boolean {
|
|
|
449
503
|
return segments.length >= 2 && JUDGE_FILE.test(segments.at(-1) ?? "") && !segments.some((name) => name.includes(":"));
|
|
450
504
|
}
|
|
451
505
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
506
|
+
type WriteRule = { dir: string; allows: (segments: readonly string[]) => boolean; shown: string };
|
|
507
|
+
|
|
508
|
+
function isProbeFile(segments: readonly string[]): boolean {
|
|
509
|
+
return segments.length === 1 && PROBE_NAME.test(segments[0] ?? "");
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function writeRulesOf(agent: string): WriteRule[] {
|
|
455
513
|
const bare = bareName(agent);
|
|
456
514
|
if (bare === JUDGE_AGENT) {
|
|
457
|
-
return
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
515
|
+
return [
|
|
516
|
+
{
|
|
517
|
+
dir: JUDGE_WRITE_DIR,
|
|
518
|
+
allows: isJudgeFile,
|
|
519
|
+
shown: `.json files under ${JUDGE_WRITE_DIR}/<contract-name>/`,
|
|
520
|
+
},
|
|
521
|
+
];
|
|
462
522
|
}
|
|
463
523
|
if (bare === EXPLORER_AGENT) {
|
|
464
|
-
return
|
|
524
|
+
return [
|
|
525
|
+
{ dir: EXPLORER_WRITE_DIR, allows: isReportFile, shown: `${EXPLORER_WRITE_DIR}/explore-<slug>.md` },
|
|
526
|
+
{ dir: PROBE_DIR, allows: isProbeFile, shown: `${PROBE_DIR}/<slug>.graphql|get` },
|
|
527
|
+
];
|
|
465
528
|
}
|
|
466
529
|
if (bare === COVERAGE_AGENT) {
|
|
467
|
-
return
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
530
|
+
return [
|
|
531
|
+
{
|
|
532
|
+
dir: EXPLORER_WRITE_DIR,
|
|
533
|
+
allows: isCoverageFile,
|
|
534
|
+
shown: `${EXPLORER_WRITE_DIR}/coverage-<yyyy-mm-dd>[-<slug>].md`,
|
|
535
|
+
},
|
|
536
|
+
];
|
|
472
537
|
}
|
|
473
|
-
return
|
|
538
|
+
return [];
|
|
474
539
|
}
|
|
475
540
|
|
|
476
541
|
function writeBlockReason(agent: string, toolInput: unknown, projectDir: string): string | undefined {
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
542
|
+
const rules = writeRulesOf(agent);
|
|
543
|
+
if (rules.length === 0) {
|
|
479
544
|
return `${agent} is read-only and may not write files; blocked`;
|
|
480
545
|
}
|
|
481
546
|
const file = isRecord(toolInput) ? toolInput["file_path"] : undefined;
|
|
482
|
-
const
|
|
483
|
-
|
|
547
|
+
const allowed =
|
|
548
|
+
typeof file === "string" &&
|
|
549
|
+
file !== "" &&
|
|
550
|
+
rules.some((rule) => {
|
|
551
|
+
const segments = pathInside(projectDir, rule.dir, file);
|
|
552
|
+
return segments !== undefined && rule.allows(segments);
|
|
553
|
+
});
|
|
554
|
+
if (allowed) {
|
|
484
555
|
const content = isRecord(toolInput) ? toolInput["content"] : undefined;
|
|
485
556
|
return bareName(agent) === EXPLORER_AGENT && typeof content === "string" && CREDENTIAL_SHAPE.test(content)
|
|
486
557
|
? `${agent} may not write a token, password or Bearer header into a report; blocked`
|
|
487
558
|
: undefined;
|
|
488
559
|
}
|
|
489
560
|
const shown = JSON.stringify(typeof file === "string" ? file.slice(0, MAX_SHOWN_COMMAND) : null);
|
|
490
|
-
return `${agent} may write ${rule.shown}; blocked: ${shown}`;
|
|
561
|
+
return `${agent} may write only ${rules.map((rule) => rule.shown).join(" and ")}; blocked: ${shown}`;
|
|
491
562
|
}
|
|
492
563
|
|
|
493
564
|
function cleanHealerSegments(segments: readonly string[] | undefined): readonly string[] | undefined {
|
|
@@ -515,23 +586,30 @@ function healerPathsOf(projectDir: string): readonly string[] | undefined {
|
|
|
515
586
|
|
|
516
587
|
function suiteConfigOf(projectDir: string): SuiteConfig {
|
|
517
588
|
try {
|
|
518
|
-
|
|
589
|
+
const { suiteDir } = readProjectFactsIn(projectDir);
|
|
590
|
+
return {
|
|
591
|
+
launcher: toolLauncher(suitePackageDir(projectDir, suiteDir)),
|
|
592
|
+
config: playwrightConfigArgs(suiteDir),
|
|
593
|
+
};
|
|
519
594
|
} catch {
|
|
520
595
|
return undefined;
|
|
521
596
|
}
|
|
522
597
|
}
|
|
523
598
|
|
|
599
|
+
function launcherShown(config: SuiteConfig): string {
|
|
600
|
+
return (config?.launcher ?? [NPX, NPX_NO_INSTALL]).join(" ");
|
|
601
|
+
}
|
|
602
|
+
|
|
524
603
|
function playwrightShown(config: SuiteConfig): string {
|
|
525
604
|
return config === undefined
|
|
526
605
|
? `npx --no playwright test (not now: ${PROJECT_FACTS_PATH} could not be read)`
|
|
527
|
-
: ["
|
|
606
|
+
: [launcherShown(config), "playwright test", ...config.config].join(" ");
|
|
528
607
|
}
|
|
529
608
|
|
|
530
609
|
function typecheckShown(config: SuiteConfig): string {
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
: `npx --no tsc ${NO_EMIT}, npx --no tsc -p ${suiteDir} ${NO_EMIT}`;
|
|
610
|
+
const tsc = `${launcherShown(config)} tsc`;
|
|
611
|
+
const suiteDir = config?.config[0]?.slice(CONFIG_PREFIX.length);
|
|
612
|
+
return suiteDir === undefined ? `${tsc} ${NO_EMIT}` : `${tsc} ${NO_EMIT}, ${tsc} -p ${suiteDir} ${NO_EMIT}`;
|
|
535
613
|
}
|
|
536
614
|
|
|
537
615
|
function healerMayWrite(file: string, projectDir: string, healerPaths: readonly string[]): boolean {
|
|
@@ -609,7 +687,7 @@ function healerBlockReason(agent: string, tool: unknown, toolInput: unknown, pro
|
|
|
609
687
|
return undefined;
|
|
610
688
|
}
|
|
611
689
|
const shown = JSON.stringify(typeof command === "string" ? command.slice(0, MAX_SHOWN_COMMAND) : null);
|
|
612
|
-
return `${agent} may run only git diff|log|show|status, node ${CHECKS_DIR}/<module>.mts, ${playwrightShown(config)} <specs> with --project, --no-deps, --repeat-each, --retries=0, --reporter, -g and --list, node ${GUARD_PATH} --snapshot|--base=<sha>, ${typecheckShown(config)} and
|
|
690
|
+
return `${agent} may run only git diff|log|show|status, node ${CHECKS_DIR}/<module>.mts, ${playwrightShown(config)} <specs> with --project, --no-deps, --repeat-each, --retries=0, --reporter, -g and --list, node ${GUARD_PATH} --snapshot|--base=<sha>, ${typecheckShown(config)} and ${launcherShown(config)} biome check <paths>, never on a .env file; blocked: ${shown}`;
|
|
613
691
|
}
|
|
614
692
|
|
|
615
693
|
function isWebUrl(value: unknown): boolean {
|
|
@@ -691,9 +769,10 @@ function browserBlockReason(agent: string, tool: string, toolInput: unknown, pro
|
|
|
691
769
|
/**
|
|
692
770
|
* Decides a PreToolUse hook call for the Bash, Write and Playwright browser tools: a one-line reason to block it, or
|
|
693
771
|
* undefined to let it pass. Only the read-only agents are limited; the main session and every other agent pass
|
|
694
|
-
* untouched. A read-only agent's Bash call must be on the allowlist, its Playwright commands with the suite's
|
|
695
|
-
* arguments from the project facts (`suiteDir`). Its Write call is allowed for `qa-judge` only as a `.json` file under
|
|
696
|
-
* `.qa/judge/<contract-name>/`, for `qa-explorer` only as `.qa/reports/explore-<slug>.md`
|
|
772
|
+
* untouched. A read-only agent's Bash call must be on the allowlist, its Playwright commands with the suite's
|
|
773
|
+
* launcher and config arguments from the project facts (`suiteDir`). Its Write call is allowed for `vc-qa-judge` only as a `.json` file under
|
|
774
|
+
* `.qa/judge/<contract-name>/`, for `vc-qa-explorer` only as `.qa/reports/explore-<slug>.md` or a probe file
|
|
775
|
+
* `.qa/probes/<slug>.graphql|get` and for `vc-qa-coverage` only
|
|
697
776
|
* as `.qa/reports/coverage-<yyyy-mm-dd>[-<slug>].md`, all under the
|
|
698
777
|
* real path of the project directory (a link that leaves it does not count). The other writing tools are blocked, and
|
|
699
778
|
* so is every `mcp__` tool but the fixed list of `mcp__playwright__browser_*` tools: `browser_evaluate` runs only the
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
-
import { basename } from "node:path";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { argvDifferences, DISK, deviationLines, staleSources } from "./run-record.mts";
|
|
3
5
|
|
|
4
6
|
export type RunFailure = {
|
|
5
7
|
test: string;
|
|
@@ -26,6 +28,9 @@ type Outcome = { status: string; expectedStatus: string; annotations: Annotation
|
|
|
26
28
|
type Listed = { test: string; project: string };
|
|
27
29
|
|
|
28
30
|
const CLI_FILE_NAME = "reconcile-run.mts";
|
|
31
|
+
const CONTRACT_FLAG = "--contract=";
|
|
32
|
+
const CONTRACT_PATH = /^\.qa\/contracts\/[\w.-]+\.md$/;
|
|
33
|
+
const USAGE = `reconcile: usage is node .claude/checks/reconcile-run.mts <list.json> <report.json> [${CONTRACT_FLAG}.qa/contracts/<name>.md]`;
|
|
29
34
|
const TITLE_SEPARATOR = " › ";
|
|
30
35
|
const SKIP_ANNOTATIONS = ["skip", "fixme"];
|
|
31
36
|
const FAIL_ANNOTATIONS = ["fail"];
|
|
@@ -252,17 +257,69 @@ export function readJson(file: string): unknown {
|
|
|
252
257
|
}
|
|
253
258
|
}
|
|
254
259
|
|
|
260
|
+
/**
|
|
261
|
+
* What the run record says beyond the tests: the `differences` between the series the report recorded and the
|
|
262
|
+
* contract's Verification, the `deviations` the dispatcher wrote to explain them, and the covered files edited after
|
|
263
|
+
* the run started (`stale`).
|
|
264
|
+
*/
|
|
265
|
+
export type RunRecordCheck = { differences: string[]; deviations: string[]; stale: string[] };
|
|
266
|
+
|
|
267
|
+
function readContract(argument: string | undefined): { text: string; deviationFile: string } | undefined {
|
|
268
|
+
if (argument === undefined) {
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
const path = argument.slice(CONTRACT_FLAG.length);
|
|
272
|
+
if (!CONTRACT_PATH.test(path)) {
|
|
273
|
+
throw new Error(`reconcile: --contract must be .qa/contracts/<name>.md, not "${path.slice(0, 80)}"`);
|
|
274
|
+
}
|
|
275
|
+
const text = DISK.read(path);
|
|
276
|
+
if (text === undefined) {
|
|
277
|
+
throw new InputError(`${path} cannot be read`);
|
|
278
|
+
}
|
|
279
|
+
return { text, deviationFile: join(".qa", "runs", basename(path, ".md"), "deviation.txt") };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Checks a run record's report against what it covers: the covered files must not have been edited after the run
|
|
284
|
+
* started, and, with the contract, the series' real command (`config.argv` of the report) must match the contract's
|
|
285
|
+
* Verification. Each difference is explained by its own `deviation: <reason>` line in
|
|
286
|
+
* `.qa/runs/<contract-name>/deviation.txt`, which the dispatcher writes; it is still listed.
|
|
287
|
+
*
|
|
288
|
+
* @throws Error when the contract argument is not `--contract=.qa/contracts/<name>.md` or the contract cannot be read.
|
|
289
|
+
*/
|
|
290
|
+
export function checkRunRecord(report: unknown, contractArgument: string | undefined): RunRecordCheck {
|
|
291
|
+
const contract = readContract(contractArgument);
|
|
292
|
+
return {
|
|
293
|
+
differences: contract === undefined ? [] : argvDifferences(report, contract.text),
|
|
294
|
+
deviations: contract === undefined ? [] : deviationLines(DISK.read(contract.deviationFile)),
|
|
295
|
+
stale: staleSources(report, DISK),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
255
299
|
if (basename(process.argv[1] ?? "") === CLI_FILE_NAME) {
|
|
256
300
|
try {
|
|
257
|
-
const [listFile, reportFile] = process.argv.slice(2);
|
|
258
|
-
|
|
259
|
-
|
|
301
|
+
const [listFile, reportFile, ...options] = process.argv.slice(2);
|
|
302
|
+
const contractArgument = options.find((option) => option.startsWith(CONTRACT_FLAG));
|
|
303
|
+
if (
|
|
304
|
+
listFile === undefined ||
|
|
305
|
+
reportFile === undefined ||
|
|
306
|
+
options.length > (contractArgument === undefined ? 0 : 1)
|
|
307
|
+
) {
|
|
308
|
+
throw new Error(USAGE);
|
|
260
309
|
}
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
310
|
+
const report = readJson(reportFile);
|
|
311
|
+
const verdict = reconcileRun(readJson(listFile), report);
|
|
312
|
+
const record = checkRunRecord(report, contractArgument);
|
|
313
|
+
process.stdout.write(`${JSON.stringify({ ...verdict, ...record }, null, 2)}\n`);
|
|
314
|
+
const unexplained = record.differences.length > record.deviations.length;
|
|
315
|
+
if (verdict.failures.length > 0 || record.stale.length > 0 || unexplained) {
|
|
264
316
|
process.exitCode = 1;
|
|
265
317
|
}
|
|
318
|
+
if (unexplained) {
|
|
319
|
+
process.stderr.write(
|
|
320
|
+
`reconcile: the series differs from the contract's Verification in ${record.differences.length} ways and the run record has ${record.deviations.length} deviation: lines (.qa/runs/<contract-name>/deviation.txt): one line per difference\n`,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
266
323
|
} catch (error) {
|
|
267
324
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
268
325
|
process.exitCode = 1;
|