@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
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import type { ProjectFacts } from "./project-facts.mts";
|
|
2
|
+
|
|
3
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
const PLACEHOLDER_ACCOUNT_SUFFIX = "@your-company.test";
|
|
7
|
+
const PLACEHOLDER_PROJECT_KEY = /\bPROJ\b/;
|
|
8
|
+
const COMMAND_SEPARATOR = /[;&|]+/;
|
|
9
|
+
const QUOTES = /["']/g;
|
|
10
|
+
const PREFIX_FLAGS = ["--prefix", "-C"];
|
|
11
|
+
const PREFIX_ASSIGNMENT = "--prefix=";
|
|
12
|
+
const RUN_COMMANDS = ["run", "run-script"];
|
|
13
|
+
const TEST_COMMANDS = ["test", "t"];
|
|
14
|
+
const PACKAGE_FILE = "package.json";
|
|
15
|
+
const ROOT_DIR = ".";
|
|
16
|
+
const PROJECT_FLAG = /--project(?:=|\s+)([^\s&|;"']+)/g;
|
|
17
|
+
const CONFIG_FILE = /^playwright\.config\.[cm]?[jt]s$/;
|
|
18
|
+
const COMMAND_ONLY_TEST_KEYS: readonly string[] = ["unit", "all"];
|
|
19
|
+
const TEST_SCRIPT = "test";
|
|
20
|
+
|
|
21
|
+
export type BabelParser = typeof import("@babel/parser");
|
|
22
|
+
|
|
23
|
+
/** What the facts are checked against: the `package.json` scripts, the suite's projects and its directories. */
|
|
24
|
+
export type SuiteWorld = {
|
|
25
|
+
/**
|
|
26
|
+
* The directory, relative to the repository root, whose `package.json` an `npm` command without `--prefix` runs:
|
|
27
|
+
* the suite directory when the suite is its own npm project, else the root (`.`).
|
|
28
|
+
*/
|
|
29
|
+
packageDir: string;
|
|
30
|
+
/** The script names of `<dir>/package.json`, or `undefined` when the file is missing or unreadable. */
|
|
31
|
+
scripts: (dir: string) => ReadonlySet<string> | undefined;
|
|
32
|
+
/** The Playwright project names the suite's config defines, or `undefined` when they could not be read. */
|
|
33
|
+
projects: ReadonlySet<string> | undefined;
|
|
34
|
+
/** Why `projects` is `undefined`, or an empty text. */
|
|
35
|
+
projectsNote: string;
|
|
36
|
+
/** Whether the suite directory holds a Playwright config. */
|
|
37
|
+
hasConfig: boolean;
|
|
38
|
+
/** Whether a repository-relative path is a directory. */
|
|
39
|
+
isDirectory: (path: string) => boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type Consistency = { problems: string[]; notes: string[] };
|
|
43
|
+
|
|
44
|
+
type Command = { path: string; text: string };
|
|
45
|
+
|
|
46
|
+
type NpmRun = { script: string; prefix: string | undefined };
|
|
47
|
+
|
|
48
|
+
/** How {@link readSuiteWorld} reads the suite: the directory of its `package.json` and the import of `@babel/parser`. */
|
|
49
|
+
export type SuiteWorldOptions = { packageDir?: string; loadParser?: () => Promise<BabelParser> };
|
|
50
|
+
|
|
51
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
52
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Lists the values of the facts that are still the template's examples: a role account in the example domain and the
|
|
57
|
+
* example `PROJ` tracker key. They are what `.qa/project.example.json` and the suite template write; an agent that
|
|
58
|
+
* plans against them plans against a tracker and accounts that do not exist.
|
|
59
|
+
*/
|
|
60
|
+
export function placeholderProblems(facts: ProjectFacts): string[] {
|
|
61
|
+
const problems = Object.entries(facts.roles)
|
|
62
|
+
.filter(([, account]) => account.toLowerCase().endsWith(PLACEHOLDER_ACCOUNT_SUFFIX))
|
|
63
|
+
.map(
|
|
64
|
+
([role]) =>
|
|
65
|
+
`roles["${role}"] is the template's example account: replace it with an account of this repository's stand`,
|
|
66
|
+
);
|
|
67
|
+
if (PLACEHOLDER_PROJECT_KEY.test(facts.tracker.keyPattern)) {
|
|
68
|
+
problems.push(
|
|
69
|
+
"tracker.keyPattern is the template's example key pattern (PROJ): replace it with this tracker's project key",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return problems;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function commandsOf(facts: ProjectFacts): Command[] {
|
|
76
|
+
const { typecheck, lint, seed, test } = facts.commands;
|
|
77
|
+
return [
|
|
78
|
+
{ path: "commands.typecheck", text: typecheck },
|
|
79
|
+
...(lint === undefined ? [] : [{ path: "commands.lint", text: lint }]),
|
|
80
|
+
...(seed === undefined ? [] : [{ path: "commands.seed", text: seed }]),
|
|
81
|
+
...Object.entries(test).map(([project, text]) => ({ path: `commands.test["${project}"]`, text })),
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function prefixDir(dir: string): string {
|
|
86
|
+
const plain = dir.replace(/^(\.\/)+/, "").replace(/\/+$/, "");
|
|
87
|
+
return plain === "" ? ROOT_DIR : plain;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The npm scripts a command runs: `npm run <script>` (or `run-script`, flags before the script allowed) and `npm test`,
|
|
92
|
+
* each with the directory of a `--prefix <dir>`, `--prefix=<dir>` or `-C <dir>` before or after the script (not
|
|
93
|
+
* after `--`, which passes it to the script).
|
|
94
|
+
*/
|
|
95
|
+
function npmRunsOf(text: string): NpmRun[] {
|
|
96
|
+
const runs: NpmRun[] = [];
|
|
97
|
+
for (const segment of text.split(COMMAND_SEPARATOR)) {
|
|
98
|
+
const words = segment.replace(QUOTES, "").trim().split(/\s+/);
|
|
99
|
+
const start = words.indexOf("npm");
|
|
100
|
+
if (start < 0) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const rest = words.slice(start + 1);
|
|
104
|
+
const end = rest.indexOf("--");
|
|
105
|
+
const own = end < 0 ? rest : rest.slice(0, end);
|
|
106
|
+
let prefix: string | undefined;
|
|
107
|
+
const positional: string[] = [];
|
|
108
|
+
for (let index = 0; index < own.length; index += 1) {
|
|
109
|
+
const word = own[index] ?? "";
|
|
110
|
+
if (PREFIX_FLAGS.includes(word)) {
|
|
111
|
+
index += 1;
|
|
112
|
+
const dir = own[index];
|
|
113
|
+
prefix = dir === undefined ? prefix : prefixDir(dir);
|
|
114
|
+
} else if (word.startsWith(PREFIX_ASSIGNMENT)) {
|
|
115
|
+
prefix = prefixDir(word.slice(PREFIX_ASSIGNMENT.length));
|
|
116
|
+
} else if (!word.startsWith("-")) {
|
|
117
|
+
positional.push(word);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const [command = "", script] = positional;
|
|
121
|
+
if (RUN_COMMANDS.includes(command) && script !== undefined) {
|
|
122
|
+
runs.push({ script, prefix });
|
|
123
|
+
} else if (TEST_COMMANDS.includes(command)) {
|
|
124
|
+
runs.push({ script: TEST_SCRIPT, prefix });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return runs;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function packageFileOf(dir: string): string {
|
|
131
|
+
return dir === ROOT_DIR ? PACKAGE_FILE : `${dir}/${PACKAGE_FILE}`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function projectFlagsOf(text: string): string[] {
|
|
135
|
+
return [...text.matchAll(PROJECT_FLAG)].flatMap((match) => (match[1] === undefined ? [] : [match[1]]));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function scriptProblems(commands: readonly Command[], world: SuiteWorld): string[] {
|
|
139
|
+
const used = commands.flatMap((command) =>
|
|
140
|
+
npmRunsOf(command.text).map(({ script, prefix }) => ({ command, script, dir: prefix ?? world.packageDir })),
|
|
141
|
+
);
|
|
142
|
+
return [...new Set(used.map(({ dir }) => dir))].flatMap((dir) => {
|
|
143
|
+
const scripts = world.scripts(dir);
|
|
144
|
+
const file = packageFileOf(dir);
|
|
145
|
+
if (scripts === undefined) {
|
|
146
|
+
return [`commands run npm scripts, but ${file} is missing or cannot be read`];
|
|
147
|
+
}
|
|
148
|
+
return used
|
|
149
|
+
.filter((run) => run.dir === dir && !scripts.has(run.script))
|
|
150
|
+
.map(({ command, script }) => `${command.path} runs "npm run ${script}", which ${file} does not define`);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function projectProblems(facts: ProjectFacts, commands: readonly Command[], projects: ReadonlySet<string>): string[] {
|
|
155
|
+
const known = [...projects].join(", ");
|
|
156
|
+
const problems: string[] = [];
|
|
157
|
+
for (const key of Object.keys(facts.commands.test)) {
|
|
158
|
+
if (!(COMMAND_ONLY_TEST_KEYS.includes(key) || projects.has(key))) {
|
|
159
|
+
problems.push(`commands.test["${key}"] is not a project of the suite's Playwright config (${known})`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const key of Object.keys(facts.quality.durationBudgetMs)) {
|
|
163
|
+
if (!projects.has(key)) {
|
|
164
|
+
problems.push(`quality.durationBudgetMs["${key}"] is not a project of the suite's Playwright config (${known})`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const command of commands) {
|
|
168
|
+
for (const flag of projectFlagsOf(command.text)) {
|
|
169
|
+
if (!projects.has(flag)) {
|
|
170
|
+
problems.push(`${command.path} runs --project=${flag}, which the suite's Playwright config does not define`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return problems;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Checks the facts against the repository: every `npm run` script a command names is in the `package.json` it runs
|
|
179
|
+
* against (of its `--prefix` directory, else of the suite when it is its own npm project, else of the root); every key of
|
|
180
|
+
* `commands.test` (except `unit` and `all`), every key of `quality.durationBudgetMs` and every `--project` a command
|
|
181
|
+
* passes is a project of the suite's Playwright config; every `healerPaths` entry is an existing directory. What
|
|
182
|
+
* could not be read is a note, not a problem.
|
|
183
|
+
*/
|
|
184
|
+
export function crossCheck(facts: ProjectFacts, world: SuiteWorld): Consistency {
|
|
185
|
+
const commands = commandsOf(facts);
|
|
186
|
+
const problems = scriptProblems(commands, world);
|
|
187
|
+
const notes: string[] = [];
|
|
188
|
+
if (!world.hasConfig) {
|
|
189
|
+
problems.push(`suiteDir "${facts.suiteDir}" holds no playwright.config`);
|
|
190
|
+
} else if (world.projects === undefined) {
|
|
191
|
+
notes.push(`the suite's projects were not checked: ${world.projectsNote}`);
|
|
192
|
+
} else {
|
|
193
|
+
problems.push(...projectProblems(facts, commands, world.projects));
|
|
194
|
+
}
|
|
195
|
+
facts.healerPaths.forEach((path, index) => {
|
|
196
|
+
if (!world.isDirectory(path)) {
|
|
197
|
+
problems.push(
|
|
198
|
+
`healerPaths[${index}] "${path}" is not a directory of the repository: create it or remove the entry`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return { problems, notes };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function visit(node: unknown, found: (node: Record<string, unknown>) => void): void {
|
|
206
|
+
if (Array.isArray(node)) {
|
|
207
|
+
for (const child of node) {
|
|
208
|
+
visit(child, found);
|
|
209
|
+
}
|
|
210
|
+
} else if (isRecord(node)) {
|
|
211
|
+
found(node);
|
|
212
|
+
for (const child of Object.values(node)) {
|
|
213
|
+
visit(child, found);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function keyName(node: unknown): string | undefined {
|
|
219
|
+
if (!isRecord(node)) {
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
if (node["type"] === "Identifier" && typeof node["name"] === "string") {
|
|
223
|
+
return node["name"];
|
|
224
|
+
}
|
|
225
|
+
return node["type"] === "StringLiteral" && typeof node["value"] === "string" ? node["value"] : undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function nameIn(object: unknown): string | undefined {
|
|
229
|
+
if (!isRecord(object) || object["type"] !== "ObjectExpression" || !Array.isArray(object["properties"])) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
for (const property of object["properties"]) {
|
|
233
|
+
if (isRecord(property) && property["type"] === "ObjectProperty" && keyName(property["key"]) === "name") {
|
|
234
|
+
const value = property["value"];
|
|
235
|
+
return isRecord(value) && value["type"] === "StringLiteral" && typeof value["value"] === "string"
|
|
236
|
+
? value["value"]
|
|
237
|
+
: undefined;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function projectName(element: unknown): string | undefined {
|
|
244
|
+
if (!isRecord(element)) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
if (element["type"] === "ObjectExpression") {
|
|
248
|
+
return nameIn(element);
|
|
249
|
+
}
|
|
250
|
+
if (element["type"] === "CallExpression" && Array.isArray(element["arguments"])) {
|
|
251
|
+
return element["arguments"].map(nameIn).find((name) => name !== undefined);
|
|
252
|
+
}
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The project names of a Playwright config's source: the `name` of each entry of its `projects` list, an object or a
|
|
258
|
+
* call (such as `apiProject(env, { name: "restapi" })`) with an object argument that has a literal `name`. A text, not
|
|
259
|
+
* a set, says why the names could not be read: `@babel/parser` is missing, the source cannot be parsed, there is not
|
|
260
|
+
* exactly one `projects` list, or an entry has no literal name.
|
|
261
|
+
*
|
|
262
|
+
* @param loadParser imports `@babel/parser`; by default as the checks resolve it.
|
|
263
|
+
*/
|
|
264
|
+
export async function playwrightProjectNames(
|
|
265
|
+
source: string,
|
|
266
|
+
loadParser: () => Promise<BabelParser> = () => import("@babel/parser"),
|
|
267
|
+
): Promise<ReadonlySet<string> | string> {
|
|
268
|
+
let program: unknown;
|
|
269
|
+
try {
|
|
270
|
+
const { parse } = await loadParser();
|
|
271
|
+
program = parse(source, { sourceType: "module", plugins: ["typescript"] }).program;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const missing = error instanceof Error && "code" in error && error.code === "ERR_MODULE_NOT_FOUND";
|
|
274
|
+
return missing ? "@babel/parser is not installed" : "the Playwright config cannot be parsed";
|
|
275
|
+
}
|
|
276
|
+
const lists: unknown[][] = [];
|
|
277
|
+
visit(program, (node) => {
|
|
278
|
+
const list = node["value"];
|
|
279
|
+
if (
|
|
280
|
+
node["type"] === "ObjectProperty" &&
|
|
281
|
+
keyName(node["key"]) === "projects" &&
|
|
282
|
+
isRecord(list) &&
|
|
283
|
+
list["type"] === "ArrayExpression" &&
|
|
284
|
+
Array.isArray(list["elements"])
|
|
285
|
+
) {
|
|
286
|
+
lists.push(list["elements"]);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const [only, ...others] = lists;
|
|
290
|
+
if (only === undefined || others.length > 0) {
|
|
291
|
+
return "the Playwright config has no single `projects` list";
|
|
292
|
+
}
|
|
293
|
+
const names = only.map(projectName);
|
|
294
|
+
return names.every((name) => name !== undefined)
|
|
295
|
+
? new Set(names.filter((name) => name !== undefined))
|
|
296
|
+
: "an entry of the `projects` list has no literal name";
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function readScripts(projectDir: string, dir: string): ReadonlySet<string> | undefined {
|
|
300
|
+
try {
|
|
301
|
+
const manifest: unknown = JSON.parse(readFileSync(resolve(projectDir, dir, PACKAGE_FILE), "utf8"));
|
|
302
|
+
const scripts = isRecord(manifest) ? manifest["scripts"] : undefined;
|
|
303
|
+
return new Set(isRecord(scripts) ? Object.keys(scripts) : []);
|
|
304
|
+
} catch {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function isDirectoryIn(projectDir: string, path: string): boolean {
|
|
310
|
+
const full = join(projectDir, path);
|
|
311
|
+
return existsSync(full) && statSync(full).isDirectory();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Reads what {@link crossCheck} needs from the repository at `projectDir`: the `package.json` files, and the
|
|
316
|
+
* Playwright config in the suite directory, which every suite has.
|
|
317
|
+
*/
|
|
318
|
+
export async function readSuiteWorld(
|
|
319
|
+
projectDir: string,
|
|
320
|
+
suiteDir: string,
|
|
321
|
+
{ packageDir = ROOT_DIR, loadParser }: SuiteWorldOptions = {},
|
|
322
|
+
): Promise<SuiteWorld> {
|
|
323
|
+
const dir = join(projectDir, suiteDir);
|
|
324
|
+
const config = existsSync(dir) ? readdirSync(dir).find((name) => CONFIG_FILE.test(name)) : undefined;
|
|
325
|
+
const source = config === undefined ? "" : readFileSync(join(dir, config), "utf8");
|
|
326
|
+
const found = config === undefined ? "" : await playwrightProjectNames(source, loadParser);
|
|
327
|
+
return {
|
|
328
|
+
packageDir,
|
|
329
|
+
scripts: (scriptDir) => readScripts(projectDir, scriptDir),
|
|
330
|
+
projects: typeof found === "string" ? undefined : found,
|
|
331
|
+
projectsNote: typeof found === "string" ? found : "",
|
|
332
|
+
hasConfig: config !== undefined,
|
|
333
|
+
isDirectory: (path) => isDirectoryIn(projectDir, path),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { GraphQLObjectType, IntrospectionQuery } from "graphql";
|
|
2
|
+
|
|
3
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
import { runVariables } from "./browser-secrets.mts";
|
|
7
|
+
import { importSuiteDependency, readProjectFactsIn } from "./project-facts.mts";
|
|
8
|
+
import { standOrigins } from "./stand.mts";
|
|
9
|
+
import { anonymousRequest, verifiesSsl } from "./stand-request.mts";
|
|
10
|
+
|
|
11
|
+
const CLI_FILE_NAME = "introspect.mts";
|
|
12
|
+
const GRAPHQL_PATH = "/graphql";
|
|
13
|
+
const REST_PATH = "/docs/PlatformUI/swagger.json";
|
|
14
|
+
const GRAPHQL_FILE = "schema-graphql.graphql";
|
|
15
|
+
const REST_FILE = "schema-rest.txt";
|
|
16
|
+
const KINDS = ["graphql", "rest"] as const;
|
|
17
|
+
const HTTP_METHODS = ["get", "put", "post", "delete", "patch", "head", "options"];
|
|
18
|
+
const INTROSPECTION_QUERY =
|
|
19
|
+
"query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }";
|
|
20
|
+
|
|
21
|
+
type Kind = (typeof KINDS)[number];
|
|
22
|
+
|
|
23
|
+
function problem(text: string): Error {
|
|
24
|
+
return new Error(`introspect: ${text}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
28
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseJson(text: string, route: string): unknown {
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(text);
|
|
34
|
+
} catch {
|
|
35
|
+
throw problem(`${route} did not answer JSON`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function fieldCount(type: GraphQLObjectType | null | undefined): number {
|
|
40
|
+
return Object.keys(type?.getFields() ?? {}).length;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The GraphQL schema as text (SDL) from an introspection answer, with a summary of its size.
|
|
45
|
+
*
|
|
46
|
+
* @throws Error when the answer holds no schema, or the `graphql` package (a peer dependency of the framework) is
|
|
47
|
+
* missing.
|
|
48
|
+
*/
|
|
49
|
+
export async function schemaText(answer: unknown): Promise<{ text: string; summary: string }> {
|
|
50
|
+
const data = isRecord(answer) ? answer["data"] : undefined;
|
|
51
|
+
if (!isRecord(data) || !isRecord(data["__schema"])) {
|
|
52
|
+
throw problem(`${GRAPHQL_PATH} answered no schema (introspection may be switched off or need a sign-in)`);
|
|
53
|
+
}
|
|
54
|
+
let graphql: typeof import("graphql");
|
|
55
|
+
try {
|
|
56
|
+
graphql = await importSuiteDependency<typeof import("graphql")>("graphql");
|
|
57
|
+
} catch {
|
|
58
|
+
throw problem("the graphql package is not installed: install it, or generate the schema with the suite's codegen");
|
|
59
|
+
}
|
|
60
|
+
const schema = graphql.buildClientSchema(data as unknown as IntrospectionQuery);
|
|
61
|
+
const types = Object.keys(schema.getTypeMap()).filter((name) => !name.startsWith("__")).length;
|
|
62
|
+
return {
|
|
63
|
+
text: graphql.printSchema(schema),
|
|
64
|
+
summary: `${types} types, ${fieldCount(schema.getQueryType())} queries, ${fieldCount(schema.getMutationType())} mutations`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function parametersOf(operation: Record<string, unknown>): string {
|
|
69
|
+
const parameters = Array.isArray(operation["parameters"]) ? operation["parameters"] : [];
|
|
70
|
+
return parameters
|
|
71
|
+
.filter(isRecord)
|
|
72
|
+
.map((parameter) => {
|
|
73
|
+
const required = parameter["required"] === true ? ",required" : "";
|
|
74
|
+
return `${String(parameter["name"])}(${String(parameter["in"])}${required})`;
|
|
75
|
+
})
|
|
76
|
+
.join(" ");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* One line per operation of an OpenAPI document, `<METHOD> <path> | <operationId> | <summary> | <parameters> |
|
|
81
|
+
* <response codes>`, the form the agents search with `Grep`.
|
|
82
|
+
*
|
|
83
|
+
* @throws Error when the document holds no paths.
|
|
84
|
+
*/
|
|
85
|
+
export function operationLines(document: unknown): string[] {
|
|
86
|
+
const paths = isRecord(document) ? document["paths"] : undefined;
|
|
87
|
+
if (!isRecord(paths)) {
|
|
88
|
+
throw problem(`${REST_PATH} holds no paths`);
|
|
89
|
+
}
|
|
90
|
+
const lines: string[] = [];
|
|
91
|
+
for (const [path, item] of Object.entries(paths)) {
|
|
92
|
+
for (const [method, operation] of Object.entries(isRecord(item) ? item : {})) {
|
|
93
|
+
if (HTTP_METHODS.includes(method) && isRecord(operation)) {
|
|
94
|
+
const responses = isRecord(operation["responses"]) ? Object.keys(operation["responses"]).join(",") : "";
|
|
95
|
+
const summary = String(operation["summary"] ?? "")
|
|
96
|
+
.replace(/\s+/g, " ")
|
|
97
|
+
.trim();
|
|
98
|
+
const id = String(operation["operationId"] ?? "");
|
|
99
|
+
lines.push(`${method.toUpperCase()} ${path} | ${id} | ${summary} | ${parametersOf(operation)} | ${responses}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return lines;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function fetchSchema(
|
|
107
|
+
kind: Kind,
|
|
108
|
+
origin: string,
|
|
109
|
+
verifySsl: boolean,
|
|
110
|
+
): Promise<{ file: string; text: string; summary: string }> {
|
|
111
|
+
const graphql = kind === "graphql";
|
|
112
|
+
const route = graphql ? GRAPHQL_PATH : REST_PATH;
|
|
113
|
+
const answer = await anonymousRequest(origin, route, {
|
|
114
|
+
method: graphql ? "POST" : "GET",
|
|
115
|
+
...(graphql ? { body: JSON.stringify({ query: INTROSPECTION_QUERY }) } : {}),
|
|
116
|
+
verifySsl,
|
|
117
|
+
});
|
|
118
|
+
if (answer.status !== 200) {
|
|
119
|
+
throw problem(
|
|
120
|
+
`${route} answered ${answer.status} to an anonymous request: take the schema from the suite's own codegen, or report not reached: needs a sign-in`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const body = parseJson(answer.text, route);
|
|
124
|
+
if (graphql) {
|
|
125
|
+
const { text, summary } = await schemaText(body);
|
|
126
|
+
return { file: GRAPHQL_FILE, text, summary };
|
|
127
|
+
}
|
|
128
|
+
const lines = operationLines(body);
|
|
129
|
+
return { file: REST_FILE, text: lines.join("\n"), summary: `${lines.length} operations` };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function main(args: readonly string[]): Promise<void> {
|
|
133
|
+
const [kind, extra] = args;
|
|
134
|
+
const known = KINDS.find((name) => name === kind);
|
|
135
|
+
if (extra !== undefined || known === undefined) {
|
|
136
|
+
throw problem(`usage is node .claude/checks/${CLI_FILE_NAME} ${KINDS.join("|")}`);
|
|
137
|
+
}
|
|
138
|
+
const projectDir = process.cwd();
|
|
139
|
+
const vars = runVariables(projectDir);
|
|
140
|
+
const { knowledgeDir } = readProjectFactsIn(projectDir);
|
|
141
|
+
const { file, text, summary } = await fetchSchema(known, standOrigins(vars).backend, verifiesSsl(vars));
|
|
142
|
+
const target = resolve(projectDir, knowledgeDir, file);
|
|
143
|
+
const inside = relative(projectDir, target);
|
|
144
|
+
if (inside.startsWith("..") || isAbsolute(inside)) {
|
|
145
|
+
throw problem("knowledgeDir of the project facts is outside the repository");
|
|
146
|
+
}
|
|
147
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
148
|
+
writeFileSync(target, `# captured ${new Date().toISOString().slice(0, 10)} from the stand's backend\n${text}\n`);
|
|
149
|
+
process.stdout.write(`introspect: wrote ${join(knowledgeDir, file).replaceAll("\\", "/")} (${summary})\n`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (basename(process.argv[1] ?? "") === CLI_FILE_NAME) {
|
|
153
|
+
main(process.argv.slice(2)).catch((error: unknown) => {
|
|
154
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
155
|
+
process.exitCode = 1;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
@@ -13,8 +13,11 @@ export type JudgeVerdict = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
const CLI_FILE_NAME = "judge-verdict.mts";
|
|
16
|
-
const DEFAULT_CRITERIA_DIR = ".claude/skills/judge-criteria";
|
|
16
|
+
const DEFAULT_CRITERIA_DIR = ".claude/skills/vc-judge-criteria";
|
|
17
17
|
const CRITERION_LINE = /^- `([a-z][a-z0-9-]*)`/;
|
|
18
|
+
const PROOF_ROLE: JudgeRole = "expert";
|
|
19
|
+
const PROOF_CRITERION = "fails-when-behaviour-breaks";
|
|
20
|
+
const PROOF_KINDS = ["mechanical", "reasoned"] as const;
|
|
18
21
|
|
|
19
22
|
function problem(text: string): string {
|
|
20
23
|
return `judge verdict: ${text}`;
|
|
@@ -48,6 +51,41 @@ export function criteriaOf(role: JudgeRole, directory: string = DEFAULT_CRITERIA
|
|
|
48
51
|
return names;
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The expert's verdict records how its cases were proved: `proofs` holds the whole numbers `mechanical` (cases proved
|
|
56
|
+
* with `prove-fails`) and `reasoned` (cases judged from the assertion), at least one case in all. Without a single
|
|
57
|
+
* mechanical proof the criterion `fails-when-behaviour-breaks` may pass only with a non-empty `proofs.explanation` of why none
|
|
58
|
+
* could be.
|
|
59
|
+
*/
|
|
60
|
+
function proofProblems(json: Record<string, unknown>, criteria: readonly unknown[]): string[] {
|
|
61
|
+
const proofs = json["proofs"];
|
|
62
|
+
if (!isRecord(proofs)) {
|
|
63
|
+
return [
|
|
64
|
+
problem(
|
|
65
|
+
`proofs is missing: write "proofs": { "mechanical": <cases proved with prove-fails>, "reasoned": <cases judged from the assertion>, "explanation": "<why none could be proved, when mechanical is 0>" }`,
|
|
66
|
+
),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const counts = PROOF_KINDS.map((kind) => proofs[kind]);
|
|
70
|
+
const bad = PROOF_KINDS.filter((_, index) => !Number.isInteger(counts[index]) || Number(counts[index]) < 0);
|
|
71
|
+
if (bad.length > 0) {
|
|
72
|
+
return bad.map((kind) => problem(`proofs.${kind} is not a whole number of cases`));
|
|
73
|
+
}
|
|
74
|
+
const [mechanical = 0, reasoned = 0] = counts.map(Number);
|
|
75
|
+
if (mechanical + reasoned === 0) {
|
|
76
|
+
return [problem("proofs counts no case")];
|
|
77
|
+
}
|
|
78
|
+
const explanation = typeof proofs["explanation"] === "string" ? proofs["explanation"].trim() : "";
|
|
79
|
+
const answer = criteria.find((entry) => isRecord(entry) && entry["name"] === PROOF_CRITERION);
|
|
80
|
+
return mechanical === 0 && explanation === "" && isRecord(answer) && answer["pass"] === true
|
|
81
|
+
? [
|
|
82
|
+
problem(
|
|
83
|
+
`criterion "${PROOF_CRITERION}" passes with no case proved mechanically and no proofs.explanation saying why`,
|
|
84
|
+
),
|
|
85
|
+
]
|
|
86
|
+
: [];
|
|
87
|
+
}
|
|
88
|
+
|
|
51
89
|
type Criterion = { name: string; pass: boolean | undefined; evidence: unknown };
|
|
52
90
|
|
|
53
91
|
function criteriaProblems(entries: readonly unknown[], expected: readonly string[], role: JudgeRole): string[] {
|
|
@@ -84,8 +122,8 @@ function criteriaProblems(entries: readonly unknown[], expected: readonly string
|
|
|
84
122
|
|
|
85
123
|
/**
|
|
86
124
|
* Checks a judge's verdict file against its role's criteria file: the role matches, the subject is named, every
|
|
87
|
-
* criterion of the role answered once with true or false and non-empty evidence, no other criterion,
|
|
88
|
-
*
|
|
125
|
+
* criterion of the role answered once with true or false and non-empty evidence, no other criterion, the verdict is
|
|
126
|
+
* `pass` exactly when every criterion passes, and, for the expert, the `proofs` record of `proofProblems`. Returns one line per problem; an empty list is a good file.
|
|
89
127
|
*
|
|
90
128
|
* @throws Error when the role's criteria file cannot be read or lists no criteria.
|
|
91
129
|
*/
|
|
@@ -111,6 +149,9 @@ export function checkJudgeVerdict(json: unknown, role: JudgeRole, directory: str
|
|
|
111
149
|
return problems;
|
|
112
150
|
}
|
|
113
151
|
problems.push(...criteriaProblems(criteria, criteriaOf(role, directory), role));
|
|
152
|
+
if (role === PROOF_ROLE) {
|
|
153
|
+
problems.push(...proofProblems(json, criteria));
|
|
154
|
+
}
|
|
114
155
|
const answers = criteria.flatMap((entry) => (isRecord(entry) && typeof entry["pass"] === "boolean" ? [entry] : []));
|
|
115
156
|
const failed = answers.find((entry) => entry["pass"] === false);
|
|
116
157
|
if (verdict === "pass" && failed !== undefined) {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { basename } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { runVariables } from "./browser-secrets.mts";
|
|
5
|
+
import { importSuiteDependency } from "./project-facts.mts";
|
|
6
|
+
import { CREDENTIAL_SHAPE, PROBE_FILE } from "./readonly-shell.mts";
|
|
7
|
+
import { standOrigins } from "./stand.mts";
|
|
8
|
+
import { anonymousRequest, verifiesSsl } from "./stand-request.mts";
|
|
9
|
+
|
|
10
|
+
const CLI_FILE_NAME = "probe.mts";
|
|
11
|
+
const GRAPHQL_PATH = "/graphql";
|
|
12
|
+
const MAX_SHOWN = 8000;
|
|
13
|
+
|
|
14
|
+
function problem(text: string): Error {
|
|
15
|
+
return new Error(`probe: ${text}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Checks that a GraphQL document is exactly one `query` operation, so the probe can never send a mutation or a
|
|
20
|
+
* subscription.
|
|
21
|
+
*
|
|
22
|
+
* @throws Error when the document does not parse, holds no operation or more than one, or its operation is not a query.
|
|
23
|
+
*/
|
|
24
|
+
export async function checkQuery(document: string): Promise<void> {
|
|
25
|
+
let graphql: typeof import("graphql");
|
|
26
|
+
try {
|
|
27
|
+
graphql = await importSuiteDependency<typeof import("graphql")>("graphql");
|
|
28
|
+
} catch {
|
|
29
|
+
throw problem("the graphql package is not installed");
|
|
30
|
+
}
|
|
31
|
+
let parsed: ReturnType<typeof graphql.parse>;
|
|
32
|
+
try {
|
|
33
|
+
parsed = graphql.parse(document);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw problem(`the query does not parse: ${error instanceof Error ? (error.message.split("\n")[0] ?? "") : ""}`);
|
|
36
|
+
}
|
|
37
|
+
const operations = parsed.definitions.filter((definition) => definition.kind === graphql.Kind.OPERATION_DEFINITION);
|
|
38
|
+
const [only] = operations;
|
|
39
|
+
if (operations.length !== 1 || only?.kind !== graphql.Kind.OPERATION_DEFINITION || only.operation !== "query") {
|
|
40
|
+
throw problem("a probe file holds exactly one query operation, never a mutation or a subscription");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The path a `.get` probe file names: one line that starts with `/`, with no space.
|
|
46
|
+
*
|
|
47
|
+
* @throws Error when the file holds anything else.
|
|
48
|
+
*/
|
|
49
|
+
export function getPath(text: string): string {
|
|
50
|
+
const path = text.trim();
|
|
51
|
+
if (!/^\/[^\s/][^\s]*$/.test(path)) {
|
|
52
|
+
throw problem("a .get probe file holds one line: the path and query to GET, starting with /");
|
|
53
|
+
}
|
|
54
|
+
return path;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function main(args: readonly string[]): Promise<void> {
|
|
58
|
+
const [file, extra] = args;
|
|
59
|
+
if (file === undefined || extra !== undefined || !PROBE_FILE.test(file)) {
|
|
60
|
+
throw problem(`usage is node .claude/checks/${CLI_FILE_NAME} .qa/probes/<slug>.graphql|.get`);
|
|
61
|
+
}
|
|
62
|
+
let text: string;
|
|
63
|
+
try {
|
|
64
|
+
text = readFileSync(file, "utf8");
|
|
65
|
+
} catch {
|
|
66
|
+
throw problem(`${file} cannot be read`);
|
|
67
|
+
}
|
|
68
|
+
const vars = runVariables(process.cwd());
|
|
69
|
+
const origin = standOrigins(vars).backend;
|
|
70
|
+
const verifySsl = verifiesSsl(vars);
|
|
71
|
+
const graphql = file.endsWith(".graphql");
|
|
72
|
+
if (graphql) {
|
|
73
|
+
await checkQuery(text);
|
|
74
|
+
}
|
|
75
|
+
const answer = graphql
|
|
76
|
+
? await anonymousRequest(origin, GRAPHQL_PATH, { method: "POST", body: JSON.stringify({ query: text }), verifySsl })
|
|
77
|
+
: await anonymousRequest(origin, getPath(text), { method: "GET", verifySsl });
|
|
78
|
+
if (CREDENTIAL_SHAPE.test(answer.text)) {
|
|
79
|
+
process.stdout.write(`probe: ${answer.status}, the answer looks like a credential, so it is not shown\n`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const shown = answer.text.length > MAX_SHOWN ? `${answer.text.slice(0, MAX_SHOWN)} ...(cut)` : answer.text;
|
|
83
|
+
process.stdout.write(`probe: ${answer.status} (anonymous)\n${shown}\n`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (basename(process.argv[1] ?? "") === CLI_FILE_NAME) {
|
|
87
|
+
main(process.argv.slice(2)).catch((error: unknown) => {
|
|
88
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
});
|
|
91
|
+
}
|