@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.
- package/.biome/formatter.json +11 -0
- package/.biome/imports.json +52 -0
- package/.biome/preset.json +4 -0
- package/.biome/rules.json +45 -0
- package/.claude/agents/qa-automation-expert.md +119 -0
- package/.claude/agents/qa-coverage.md +96 -0
- package/.claude/agents/qa-explorer.md +112 -0
- package/.claude/agents/qa-healer.md +88 -0
- package/.claude/agents/qa-judge.md +102 -0
- package/.claude/agents/qa-planner.md +104 -0
- package/.claude/agents/qa-reviewer.md +121 -0
- package/.claude/checks/browser-secrets.mts +107 -0
- package/.claude/checks/contract.mts +469 -0
- package/.claude/checks/expectation-guard.mts +665 -0
- package/.claude/checks/explore-extractors.mts +4 -0
- package/.claude/checks/judge-verdict.mts +165 -0
- package/.claude/checks/project-facts.mts +491 -0
- package/.claude/checks/prove-fails.mts +770 -0
- package/.claude/checks/rank-gaps.mts +177 -0
- package/.claude/checks/readonly-shell.mts +740 -0
- package/.claude/checks/reconcile-run.mts +270 -0
- package/.claude/checks/scan-prompts.mts +351 -0
- package/.claude/checks/stand.mts +45 -0
- package/.claude/checks/test-duration.mts +134 -0
- package/.claude/checks/test-shape.mts +224 -0
- package/.claude/checks/ticket-card.mts +195 -0
- package/.claude/commands/qa-coverage.md +13 -0
- package/.claude/commands/qa-explore.md +17 -0
- package/.claude/commands/qa-heal.md +44 -0
- package/.claude/commands/qa-implement.md +60 -0
- package/.claude/commands/qa-plan.md +55 -0
- package/.claude/commands/qa-review.md +90 -0
- package/.claude/commands/qa.md +156 -0
- package/.claude/hooks/readonly-shell.mts +65 -0
- package/.claude/settings.json +15 -0
- package/.claude/skills/coverage-analysis/SKILL.md +107 -0
- package/.claude/skills/create-graphql-layer/SKILL.md +159 -0
- package/.claude/skills/create-ui-layer/SKILL.md +189 -0
- package/.claude/skills/explore-api/SKILL.md +74 -0
- package/.claude/skills/explore-frontend/SKILL.md +85 -0
- package/.claude/skills/framework-rules/SKILL.md +189 -0
- package/.claude/skills/heal-tests/SKILL.md +197 -0
- package/.claude/skills/heal-tests/guard-recipe.md +53 -0
- package/.claude/skills/judge-criteria/SKILL.md +40 -0
- package/.claude/skills/judge-criteria/coverage.md +9 -0
- package/.claude/skills/judge-criteria/expert.md +23 -0
- package/.claude/skills/judge-criteria/explorer.md +9 -0
- package/.claude/skills/judge-criteria/healer.md +13 -0
- package/.claude/skills/judge-criteria/planner.md +12 -0
- package/.claude/skills/plan-implementation/SKILL.md +82 -0
- package/.claude/skills/plan-implementation/contract-template.md +72 -0
- package/.claude/skills/plan-test-strategy/SKILL.md +100 -0
- package/.claude/skills/project-facts/SKILL.md +130 -0
- package/.claude/skills/read-change/SKILL.md +64 -0
- package/.claude/skills/read-ticket/SKILL.md +63 -0
- package/.claude/skills/read-ticket/providers.md +58 -0
- package/.claude/skills/review-pr/SKILL.md +152 -0
- package/.claude/skills/review-test-code/SKILL.md +208 -0
- package/.claude/skills/write-e2e-test/SKILL.md +175 -0
- package/.claude/skills/write-graphql-test/SKILL.md +158 -0
- package/.claude/skills/write-rest-api-test/SKILL.md +182 -0
- package/.claude/skills/write-security-test/SKILL.md +253 -0
- package/.qa/project.example.json +71 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE +12 -0
- package/README.md +53 -2
- package/bin/install-qa-agents.mjs +94 -0
- package/dist/auth/credentials.d.ts +10 -0
- package/dist/auth/credentials.js +2 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/frontend-browser-sessions.d.ts +71 -0
- package/dist/auth/frontend-browser-sessions.js +130 -0
- package/dist/auth/frontend-browser-sessions.js.map +1 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/platform-browser-sessions.d.ts +47 -0
- package/dist/auth/platform-browser-sessions.js +92 -0
- package/dist/auth/platform-browser-sessions.js.map +1 -0
- package/dist/auth/sign-in-lock.d.ts +14 -0
- package/dist/auth/sign-in-lock.js +70 -0
- package/dist/auth/sign-in-lock.js.map +1 -0
- package/dist/auth/storage-state.d.ts +3 -0
- package/dist/auth/storage-state.js +2 -0
- package/dist/auth/storage-state.js.map +1 -0
- package/dist/auth/token-client.d.ts +82 -0
- package/dist/auth/token-client.js +111 -0
- package/dist/auth/token-client.js.map +1 -0
- package/dist/auth/token-manager.d.ts +67 -0
- package/dist/auth/token-manager.js +138 -0
- package/dist/auth/token-manager.js.map +1 -0
- package/dist/core/default-reporters.d.ts +31 -0
- package/dist/core/default-reporters.js +36 -0
- package/dist/core/default-reporters.js.map +1 -0
- package/dist/core/default-use.d.ts +28 -0
- package/dist/core/default-use.js +25 -0
- package/dist/core/default-use.js.map +1 -0
- package/dist/core/env.d.ts +24 -0
- package/dist/core/env.js +33 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/error-message.d.ts +10 -0
- package/dist/core/error-message.js +13 -0
- package/dist/core/error-message.js.map +1 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/is-ci.d.ts +14 -0
- package/dist/core/is-ci.js +18 -0
- package/dist/core/is-ci.js.map +1 -0
- package/dist/core/parse-env.d.ts +13 -0
- package/dist/core/parse-env.js +21 -0
- package/dist/core/parse-env.js.map +1 -0
- package/dist/core/projects.d.ts +24 -0
- package/dist/core/projects.js +33 -0
- package/dist/core/projects.js.map +1 -0
- package/dist/core/run-options.d.ts +31 -0
- package/dist/core/run-options.js +43 -0
- package/dist/core/run-options.js.map +1 -0
- package/dist/core/secret.d.ts +105 -0
- package/dist/core/secret.js +167 -0
- package/dist/core/secret.js.map +1 -0
- package/dist/core/string-schemas.d.ts +39 -0
- package/dist/core/string-schemas.js +56 -0
- package/dist/core/string-schemas.js.map +1 -0
- package/dist/core/url-path.d.ts +7 -0
- package/dist/core/url-path.js +2 -0
- package/dist/core/url-path.js.map +1 -0
- package/dist/dataset/collection.d.ts +44 -0
- package/dist/dataset/collection.js +76 -0
- package/dist/dataset/collection.js.map +1 -0
- package/dist/dataset/index.d.ts +11 -0
- package/dist/dataset/index.js +6 -0
- package/dist/dataset/index.js.map +1 -0
- package/dist/dataset/load-dataset.d.ts +39 -0
- package/dist/dataset/load-dataset.js +62 -0
- package/dist/dataset/load-dataset.js.map +1 -0
- package/dist/dataset/manifest.d.ts +77 -0
- package/dist/dataset/manifest.js +10 -0
- package/dist/dataset/manifest.js.map +1 -0
- package/dist/dataset/placeholders.d.ts +66 -0
- package/dist/dataset/placeholders.js +87 -0
- package/dist/dataset/placeholders.js.map +1 -0
- package/dist/dataset/seed-collection.d.ts +53 -0
- package/dist/dataset/seed-collection.js +115 -0
- package/dist/dataset/seed-collection.js.map +1 -0
- package/dist/dataset/seed-dataset.d.ts +70 -0
- package/dist/dataset/seed-dataset.js +138 -0
- package/dist/dataset/seed-dataset.js.map +1 -0
- package/dist/dataset/seed-events.d.ts +81 -0
- package/dist/dataset/seed-events.js +2 -0
- package/dist/dataset/seed-events.js.map +1 -0
- package/dist/dataset/seed-requests.d.ts +102 -0
- package/dist/dataset/seed-requests.js +160 -0
- package/dist/dataset/seed-requests.js.map +1 -0
- package/dist/dataset/seed-scope.d.ts +39 -0
- package/dist/dataset/seed-scope.js +67 -0
- package/dist/dataset/seed-scope.js.map +1 -0
- package/dist/fixtures/default-fixtures.d.ts +93 -0
- package/dist/fixtures/default-fixtures.js +105 -0
- package/dist/fixtures/default-fixtures.js.map +1 -0
- package/dist/fixtures/index.d.ts +2 -0
- package/dist/fixtures/index.js +2 -0
- package/dist/fixtures/index.js.map +1 -0
- package/dist/graphql/graphql-client.d.ts +78 -0
- package/dist/graphql/graphql-client.js +83 -0
- package/dist/graphql/graphql-client.js.map +1 -0
- package/dist/graphql/graphql-codegen.d.ts +56 -0
- package/dist/graphql/graphql-codegen.js +42 -0
- package/dist/graphql/graphql-codegen.js.map +1 -0
- package/dist/graphql/graphql-error.d.ts +54 -0
- package/dist/graphql/graphql-error.js +74 -0
- package/dist/graphql/graphql-error.js.map +1 -0
- package/dist/graphql/index.d.ts +6 -0
- package/dist/graphql/index.js +4 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/http/authentication.d.ts +16 -0
- package/dist/http/authentication.js +2 -0
- package/dist/http/authentication.js.map +1 -0
- package/dist/http/http-client.d.ts +110 -0
- package/dist/http/http-client.js +237 -0
- package/dist/http/http-client.js.map +1 -0
- package/dist/http/http-error.d.ts +26 -0
- package/dist/http/http-error.js +34 -0
- package/dist/http/http-error.js.map +1 -0
- package/dist/http/http-method.d.ts +2 -0
- package/dist/http/http-method.js +2 -0
- package/dist/http/http-method.js.map +1 -0
- package/dist/http/http-response.d.ts +137 -0
- package/dist/http/http-response.js +166 -0
- package/dist/http/http-response.js.map +1 -0
- package/dist/http/index.d.ts +7 -0
- package/dist/http/index.js +4 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/request-options.d.ts +62 -0
- package/dist/http/request-options.js +2 -0
- package/dist/http/request-options.js.map +1 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +2 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/installed-modules.d.ts +86 -0
- package/dist/modules/installed-modules.js +135 -0
- package/dist/modules/installed-modules.js.map +1 -0
- package/docs/README.md +43 -0
- package/docs/concepts/areas.md +38 -0
- package/docs/concepts/auth.md +92 -0
- package/docs/concepts/config.md +102 -0
- package/docs/concepts/dataset.md +183 -0
- package/docs/concepts/environment.md +54 -0
- package/docs/concepts/fixtures.md +109 -0
- package/docs/concepts/graphql.md +76 -0
- package/docs/concepts/http.md +88 -0
- package/docs/concepts/modules.md +63 -0
- package/docs/concepts/secrets.md +50 -0
- package/docs/contributing/architecture.md +67 -0
- package/docs/contributing/conventions.md +39 -0
- package/docs/contributing/documentation.md +37 -0
- package/docs/contributing/releasing.md +76 -0
- package/docs/examples/auth.ts +20 -0
- package/docs/examples/config.ts +36 -0
- package/docs/examples/dataset.ts +70 -0
- package/docs/examples/environment.ts +8 -0
- package/docs/examples/fixtures.ts +41 -0
- package/docs/examples/getting-started.ts +22 -0
- package/docs/examples/graphql-codegen.ts +9 -0
- package/docs/examples/graphql.ts +32 -0
- package/docs/examples/http.ts +18 -0
- package/docs/examples/modules.ts +19 -0
- package/docs/examples/secrets.ts +11 -0
- package/docs/examples/tsconfig.json +10 -0
- package/docs/getting-started.md +106 -0
- package/docs/guides/generating-types.md +75 -0
- package/docs/guides/qa-agents.md +66 -0
- package/package.json +156 -4
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export const JUDGE_ROLES = ["planner", "expert", "explorer", "healer", "coverage"] as const;
|
|
5
|
+
|
|
6
|
+
export type JudgeRole = (typeof JUDGE_ROLES)[number];
|
|
7
|
+
|
|
8
|
+
export type JudgeVerdict = {
|
|
9
|
+
role: JudgeRole;
|
|
10
|
+
subject: string;
|
|
11
|
+
criteria: { name: string; pass: boolean; evidence: string }[];
|
|
12
|
+
verdict: "pass" | "fail";
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const CLI_FILE_NAME = "judge-verdict.mts";
|
|
16
|
+
const DEFAULT_CRITERIA_DIR = ".claude/skills/judge-criteria";
|
|
17
|
+
const CRITERION_LINE = /^- `([a-z][a-z0-9-]*)`/;
|
|
18
|
+
|
|
19
|
+
function problem(text: string): string {
|
|
20
|
+
return `judge verdict: ${text}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isRole(value: unknown): value is JudgeRole {
|
|
28
|
+
return JUDGE_ROLES.some((role) => role === value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The criteria of a role, in the order its file lists them: every list line that starts with a name in backticks.
|
|
33
|
+
*
|
|
34
|
+
* @throws Error when the role's file cannot be read or lists no criteria.
|
|
35
|
+
*/
|
|
36
|
+
export function criteriaOf(role: JudgeRole, directory: string = DEFAULT_CRITERIA_DIR): string[] {
|
|
37
|
+
const file = join(directory, `${role}.md`);
|
|
38
|
+
let text: string;
|
|
39
|
+
try {
|
|
40
|
+
text = readFileSync(file, "utf8");
|
|
41
|
+
} catch {
|
|
42
|
+
throw new Error(problem(`the criteria file ${file} cannot be read`));
|
|
43
|
+
}
|
|
44
|
+
const names = text.split(/\r?\n/).flatMap((line) => CRITERION_LINE.exec(line)?.[1] ?? []);
|
|
45
|
+
if (names.length === 0) {
|
|
46
|
+
throw new Error(problem(`the criteria file ${file} lists no criteria`));
|
|
47
|
+
}
|
|
48
|
+
return names;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type Criterion = { name: string; pass: boolean | undefined; evidence: unknown };
|
|
52
|
+
|
|
53
|
+
function criteriaProblems(entries: readonly unknown[], expected: readonly string[], role: JudgeRole): string[] {
|
|
54
|
+
const problems: string[] = [];
|
|
55
|
+
const seen = new Set<string>();
|
|
56
|
+
const parsed: Criterion[] = [];
|
|
57
|
+
entries.forEach((entry, index) => {
|
|
58
|
+
if (!isRecord(entry)) {
|
|
59
|
+
problems.push(problem(`criteria[${index}] is not an object`));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const name = typeof entry["name"] === "string" ? entry["name"] : "";
|
|
63
|
+
const pass = entry["pass"];
|
|
64
|
+
parsed.push({ name, pass: typeof pass === "boolean" ? pass : undefined, evidence: entry["evidence"] });
|
|
65
|
+
if (seen.has(name)) {
|
|
66
|
+
problems.push(problem(`criterion "${name}" appears twice`));
|
|
67
|
+
}
|
|
68
|
+
seen.add(name);
|
|
69
|
+
});
|
|
70
|
+
for (const name of expected.filter((wanted) => !seen.has(wanted))) {
|
|
71
|
+
problems.push(problem(`criterion "${name}" is missing`));
|
|
72
|
+
}
|
|
73
|
+
for (const criterion of parsed) {
|
|
74
|
+
if (!expected.includes(criterion.name)) {
|
|
75
|
+
problems.push(problem(`criterion "${criterion.name}" is not a criterion of the ${role}`));
|
|
76
|
+
} else if (criterion.pass === undefined) {
|
|
77
|
+
problems.push(problem(`criterion "${criterion.name}" has no true or false pass`));
|
|
78
|
+
} else if (typeof criterion.evidence !== "string" || criterion.evidence.trim() === "") {
|
|
79
|
+
problems.push(problem(`criterion "${criterion.name}" has no evidence`));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return problems;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 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, and the
|
|
88
|
+
* verdict is `pass` exactly when every criterion passes. Returns one line per problem; an empty list is a good file.
|
|
89
|
+
*
|
|
90
|
+
* @throws Error when the role's criteria file cannot be read or lists no criteria.
|
|
91
|
+
*/
|
|
92
|
+
export function checkJudgeVerdict(json: unknown, role: JudgeRole, directory: string = DEFAULT_CRITERIA_DIR): string[] {
|
|
93
|
+
if (!isRecord(json)) {
|
|
94
|
+
return [problem("not a JSON object")];
|
|
95
|
+
}
|
|
96
|
+
const problems: string[] = [];
|
|
97
|
+
if (json["role"] !== role) {
|
|
98
|
+
problems.push(problem(`role is ${JSON.stringify(json["role"])}, expected "${role}"`));
|
|
99
|
+
}
|
|
100
|
+
const subject = json["subject"];
|
|
101
|
+
if (typeof subject !== "string" || subject.trim() === "") {
|
|
102
|
+
problems.push(problem("subject is not a non-empty string"));
|
|
103
|
+
}
|
|
104
|
+
const verdict = json["verdict"];
|
|
105
|
+
if (verdict !== "pass" && verdict !== "fail") {
|
|
106
|
+
problems.push(problem('verdict is not "pass" or "fail"'));
|
|
107
|
+
}
|
|
108
|
+
const criteria = json["criteria"];
|
|
109
|
+
if (!Array.isArray(criteria)) {
|
|
110
|
+
problems.push(problem("criteria is not a list"));
|
|
111
|
+
return problems;
|
|
112
|
+
}
|
|
113
|
+
problems.push(...criteriaProblems(criteria, criteriaOf(role, directory), role));
|
|
114
|
+
const answers = criteria.flatMap((entry) => (isRecord(entry) && typeof entry["pass"] === "boolean" ? [entry] : []));
|
|
115
|
+
const failed = answers.find((entry) => entry["pass"] === false);
|
|
116
|
+
if (verdict === "pass" && failed !== undefined) {
|
|
117
|
+
problems.push(problem(`verdict is "pass" but criterion "${String(failed["name"])}" failed`));
|
|
118
|
+
}
|
|
119
|
+
if (verdict === "fail" && answers.length === criteria.length && failed === undefined && problems.length === 0) {
|
|
120
|
+
problems.push(problem('verdict is "fail" but every criterion passed'));
|
|
121
|
+
}
|
|
122
|
+
return problems;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function readJson(file: string): unknown {
|
|
126
|
+
let text: string;
|
|
127
|
+
try {
|
|
128
|
+
text = readFileSync(file, "utf8");
|
|
129
|
+
} catch {
|
|
130
|
+
throw new Error(problem(`${file} cannot be read`));
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return JSON.parse(text);
|
|
134
|
+
} catch {
|
|
135
|
+
throw new Error(problem(`${file} is not valid JSON`));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function roleOf(json: unknown, argument: string | undefined): JudgeRole {
|
|
140
|
+
const role = argument ?? (isRecord(json) ? json["role"] : undefined);
|
|
141
|
+
if (!isRole(role)) {
|
|
142
|
+
throw new Error(problem(`role ${JSON.stringify(role)} is not one of ${JUDGE_ROLES.join(", ")}`));
|
|
143
|
+
}
|
|
144
|
+
return role;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (basename(process.argv[1] ?? "") === CLI_FILE_NAME) {
|
|
148
|
+
try {
|
|
149
|
+
const [command, file, roleArgument] = process.argv.slice(2);
|
|
150
|
+
if (command !== "check" || file === undefined) {
|
|
151
|
+
throw new Error(problem("usage is node .claude/checks/judge-verdict.mts check <file> [role]"));
|
|
152
|
+
}
|
|
153
|
+
const json = readJson(file);
|
|
154
|
+
const problems = checkJudgeVerdict(json, roleOf(json, roleArgument));
|
|
155
|
+
if (problems.length === 0) {
|
|
156
|
+
process.stdout.write("ok\n");
|
|
157
|
+
} else {
|
|
158
|
+
process.stderr.write(`${problems.join("\n")}\n`);
|
|
159
|
+
process.exitCode = 1;
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
163
|
+
process.exitCode = 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export type Route = "command" | "cli" | "api" | "mcp" | "paste";
|
|
5
|
+
|
|
6
|
+
export const ROLE_PURPOSES = ["admin", "customer", "otherCustomer"] as const;
|
|
7
|
+
|
|
8
|
+
export type RolePurpose = (typeof ROLE_PURPOSES)[number];
|
|
9
|
+
|
|
10
|
+
export type ProjectFacts = {
|
|
11
|
+
suiteDir: string;
|
|
12
|
+
tracker: { kind: string; keyPattern: string; acceptanceCriteriaField?: string; routes: Route[] };
|
|
13
|
+
docSources: { name: string; route: Route; where: string }[];
|
|
14
|
+
commands: { typecheck: string; lint: string; seed?: string; test: Record<string, string> };
|
|
15
|
+
critical: string[];
|
|
16
|
+
knowledgeDir: string;
|
|
17
|
+
roles: Record<string, string>;
|
|
18
|
+
roleFor: { admin: string; customer: string; otherCustomer?: string };
|
|
19
|
+
rolePermissions?: Record<string, string[]>;
|
|
20
|
+
passwordFor?: Record<string, string>;
|
|
21
|
+
coverageWeights: { risk: number; callFrequency: number; runFrequency: number; stability: number; cost: number };
|
|
22
|
+
flakyRunSeries: number;
|
|
23
|
+
quality: {
|
|
24
|
+
maxSteps: number;
|
|
25
|
+
maxLines: number;
|
|
26
|
+
maxExpects: number;
|
|
27
|
+
maxNesting: number;
|
|
28
|
+
maxConditionals: number;
|
|
29
|
+
stableSeries: number;
|
|
30
|
+
durationBudgetMs: Record<string, number>;
|
|
31
|
+
slowdownRatio: number;
|
|
32
|
+
slowdownMinMs: number;
|
|
33
|
+
};
|
|
34
|
+
autonomy: Record<string, "apply" | "propose">;
|
|
35
|
+
healerPaths: string[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const DEFAULT_CLIENT_ROUTES: readonly Route[] = ["paste"];
|
|
39
|
+
|
|
40
|
+
const MIN_FLAKY_RUN_SERIES = 2;
|
|
41
|
+
const MIN_STABLE_SERIES = 2;
|
|
42
|
+
const MIN_SLOWDOWN_RATIO = 1;
|
|
43
|
+
export const PROJECT_FACTS_PATH = ".qa/project.json";
|
|
44
|
+
export const ROOT_SUITE_DIR = ".";
|
|
45
|
+
export const ENV_FILE = ".env";
|
|
46
|
+
const DEFAULT_AUTONOMY_KEY = "*";
|
|
47
|
+
const CLI_FILE_NAME = "project-facts.mts";
|
|
48
|
+
const HEALER_PATH = /^[A-Za-z0-9_-]+(\/[A-Za-z0-9_.-]+)*\/?$/;
|
|
49
|
+
const TRAILING_SLASHES = /\/+$/;
|
|
50
|
+
const FORBIDDEN_HEALER_SEGMENTS = ["qa", "node_modules", ".claude"];
|
|
51
|
+
const PROJECT_KEY_WORD = /(?<!\\)[A-Z][A-Z0-9_]+/g;
|
|
52
|
+
const PROJECT_KEY_SUFFIXES = ["", "1", "12"];
|
|
53
|
+
const SAMPLE_NUMBERS = ["1", "12", "123", "1234", "12345", "123456", "1234567"];
|
|
54
|
+
const WORK_ITEM_PREFIXES = ["", "AB#", "#"];
|
|
55
|
+
const LOST_ESCAPE = /(?<![\\A-Za-z0-9])[dws][+*{]/;
|
|
56
|
+
|
|
57
|
+
export const SHORT_NAME_SEGMENT = /~\d/;
|
|
58
|
+
|
|
59
|
+
function fail(path: string, problem: string): never {
|
|
60
|
+
throw new Error(`project.json: ${path} ${problem}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
64
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function present(source: Record<string, unknown>, key: string, path: string): unknown {
|
|
68
|
+
const value = source[key];
|
|
69
|
+
if (value === undefined) {
|
|
70
|
+
fail(path, "is missing");
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function asRecord(value: unknown, path: string): Record<string, unknown> {
|
|
76
|
+
if (!isRecord(value)) {
|
|
77
|
+
fail(path, "is not an object");
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function asString(value: unknown, path: string): string {
|
|
83
|
+
if (typeof value !== "string" || value === "") {
|
|
84
|
+
fail(path, "is not a non-empty string");
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function asList(value: unknown, path: string): unknown[] {
|
|
90
|
+
if (!Array.isArray(value)) {
|
|
91
|
+
fail(path, "is not a list");
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function asStringList(value: unknown, path: string): string[] {
|
|
97
|
+
return asList(value, path).map((item, index) => asString(item, `${path}[${index}]`));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function asStringMap(value: unknown, path: string): Record<string, string> {
|
|
101
|
+
return Object.fromEntries(
|
|
102
|
+
Object.entries(asRecord(value, path)).map(([key, item]) => [key, asString(item, `${path}["${key}"]`)]),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function asRoute(value: unknown, path: string): Route {
|
|
107
|
+
switch (value) {
|
|
108
|
+
case "command":
|
|
109
|
+
case "cli":
|
|
110
|
+
case "api":
|
|
111
|
+
case "mcp":
|
|
112
|
+
case "paste":
|
|
113
|
+
return value;
|
|
114
|
+
default:
|
|
115
|
+
return fail(path, "is not a route");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function asWeight(value: unknown, path: string): number {
|
|
120
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
121
|
+
fail(path, "must be a number of at least 0");
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Keys of the tracker kind's shape, one of which a plausible `keyPattern` matches, and how to name them in a message.
|
|
128
|
+
* jira: `<project>-<number>`, the project `PROJ` or an upper-case word of the pattern (also with `1` or `12` after
|
|
129
|
+
* it), the number 1 to 7 digits. azure-boards: an id of 1 to 7 digits, bare or after `AB#` or `#`. Any other kind:
|
|
130
|
+
* `undefined`, not checked.
|
|
131
|
+
*/
|
|
132
|
+
function sampleKeys(kind: string, keyPattern: string): { keys: string[]; shown: string } | undefined {
|
|
133
|
+
switch (kind) {
|
|
134
|
+
case "jira": {
|
|
135
|
+
const projects = [...new Set(["PROJ", ...(keyPattern.match(PROJECT_KEY_WORD) ?? [])])];
|
|
136
|
+
const keys = projects.flatMap((project) =>
|
|
137
|
+
PROJECT_KEY_SUFFIXES.flatMap((suffix) => SAMPLE_NUMBERS.map((number) => `${project}${suffix}-${number}`)),
|
|
138
|
+
);
|
|
139
|
+
return { keys, shown: `${projects.join(", ")}, then -1 to -1234567` };
|
|
140
|
+
}
|
|
141
|
+
case "azure-boards":
|
|
142
|
+
return {
|
|
143
|
+
keys: WORK_ITEM_PREFIXES.flatMap((prefix) => SAMPLE_NUMBERS.map((number) => `${prefix}${number}`)),
|
|
144
|
+
shown: "1 to 1234567, AB#12345, #12345",
|
|
145
|
+
};
|
|
146
|
+
default:
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function parseTracker(value: unknown): ProjectFacts["tracker"] {
|
|
152
|
+
const tracker = asRecord(value, "tracker");
|
|
153
|
+
const keyPattern = asString(present(tracker, "keyPattern", "tracker.keyPattern"), "tracker.keyPattern");
|
|
154
|
+
let pattern: RegExp;
|
|
155
|
+
try {
|
|
156
|
+
pattern = new RegExp(keyPattern);
|
|
157
|
+
} catch {
|
|
158
|
+
return fail("tracker.keyPattern", "is not a valid regular expression");
|
|
159
|
+
}
|
|
160
|
+
const kind = asString(present(tracker, "kind", "tracker.kind"), "tracker.kind");
|
|
161
|
+
const lostEscape = LOST_ESCAPE.exec(keyPattern)?.[0];
|
|
162
|
+
if (lostEscape !== undefined) {
|
|
163
|
+
fail(
|
|
164
|
+
"tracker.keyPattern",
|
|
165
|
+
`has "${lostEscape}" with no backslash before it: a lost escape, write "\\${lostEscape}"`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
const samples = sampleKeys(kind, keyPattern);
|
|
169
|
+
if (samples !== undefined && !samples.keys.some((key) => pattern.test(key))) {
|
|
170
|
+
fail("tracker.keyPattern", `matches no sample ${kind} key (${samples.shown})`);
|
|
171
|
+
}
|
|
172
|
+
const routes =
|
|
173
|
+
tracker["routes"] === undefined
|
|
174
|
+
? [...DEFAULT_CLIENT_ROUTES]
|
|
175
|
+
: asList(tracker["routes"], "tracker.routes").map((item, index) => asRoute(item, `tracker.routes[${index}]`));
|
|
176
|
+
if (routes.length === 0) {
|
|
177
|
+
fail("tracker.routes", "is empty");
|
|
178
|
+
}
|
|
179
|
+
const field = tracker["acceptanceCriteriaField"];
|
|
180
|
+
return field === undefined
|
|
181
|
+
? { kind, keyPattern, routes }
|
|
182
|
+
: { kind, keyPattern, acceptanceCriteriaField: asString(field, "tracker.acceptanceCriteriaField"), routes };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function parseDocSources(value: unknown): ProjectFacts["docSources"] {
|
|
186
|
+
return asList(value, "docSources").map((item, index) => {
|
|
187
|
+
const path = `docSources[${index}]`;
|
|
188
|
+
const source = asRecord(item, path);
|
|
189
|
+
return {
|
|
190
|
+
name: asString(present(source, "name", `${path}.name`), `${path}.name`),
|
|
191
|
+
route: asRoute(present(source, "route", `${path}.route`), `${path}.route`),
|
|
192
|
+
where: asString(present(source, "where", `${path}.where`), `${path}.where`),
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function parseCommands(value: unknown): ProjectFacts["commands"] {
|
|
198
|
+
const commands = asRecord(value, "commands");
|
|
199
|
+
const seed = commands["seed"];
|
|
200
|
+
return {
|
|
201
|
+
typecheck: asString(present(commands, "typecheck", "commands.typecheck"), "commands.typecheck"),
|
|
202
|
+
lint: asString(present(commands, "lint", "commands.lint"), "commands.lint"),
|
|
203
|
+
...(seed === undefined ? {} : { seed: asString(seed, "commands.seed") }),
|
|
204
|
+
test: asStringMap(present(commands, "test", "commands.test"), "commands.test"),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function asRoleName(value: unknown, path: string, roles: Record<string, string>): string {
|
|
209
|
+
const name = asString(value, path);
|
|
210
|
+
if (!Object.hasOwn(roles, name)) {
|
|
211
|
+
fail(path, "is not a key of roles");
|
|
212
|
+
}
|
|
213
|
+
return name;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function isRolePurpose(key: string): key is RolePurpose {
|
|
217
|
+
return ROLE_PURPOSES.some((purpose) => purpose === key);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function parseRoleFor(value: unknown, roles: Record<string, string>): ProjectFacts["roleFor"] {
|
|
221
|
+
const roleFor = asRecord(value, "roleFor");
|
|
222
|
+
const stray = Object.keys(roleFor).find((key) => !isRolePurpose(key));
|
|
223
|
+
if (stray !== undefined) {
|
|
224
|
+
fail(`roleFor["${stray}"]`, `is not a purpose (${ROLE_PURPOSES.join(", ")})`);
|
|
225
|
+
}
|
|
226
|
+
const role = (purpose: RolePurpose): string =>
|
|
227
|
+
asRoleName(present(roleFor, purpose, `roleFor.${purpose}`), `roleFor.${purpose}`, roles);
|
|
228
|
+
const parsed = { admin: role("admin"), customer: role("customer") };
|
|
229
|
+
if (roleFor["otherCustomer"] === undefined) {
|
|
230
|
+
return parsed;
|
|
231
|
+
}
|
|
232
|
+
const otherCustomer = role("otherCustomer");
|
|
233
|
+
if (parsed.customer === otherCustomer) {
|
|
234
|
+
fail("roleFor.otherCustomer", `is the same role as roleFor.customer ("${parsed.customer}")`);
|
|
235
|
+
}
|
|
236
|
+
if (sameAccount(roles[parsed.customer], roles[otherCustomer])) {
|
|
237
|
+
fail("roleFor.otherCustomer", `is the same account as roleFor.customer (roles["${parsed.customer}"])`);
|
|
238
|
+
}
|
|
239
|
+
return { ...parsed, otherCustomer };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Accounts are compared without regard to case, as a sign-in name is. */
|
|
243
|
+
function sameAccount(first: string | undefined, second: string | undefined): boolean {
|
|
244
|
+
return first !== undefined && second !== undefined && first.toLowerCase() === second.toLowerCase();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function parsePermissionList(value: unknown, path: string): string[] {
|
|
248
|
+
const permissions = asStringList(value, path);
|
|
249
|
+
const repeated = permissions.find((permission, index) => permissions.indexOf(permission) !== index);
|
|
250
|
+
if (repeated !== undefined) {
|
|
251
|
+
fail(path, `lists "${repeated}" twice`);
|
|
252
|
+
}
|
|
253
|
+
return permissions;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function sameSet(first: readonly string[], second: readonly string[]): boolean {
|
|
257
|
+
return first.length === second.length && first.every((item) => second.includes(item));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function parseRolePermissions(value: unknown, roles: Record<string, string>): Record<string, string[]> {
|
|
261
|
+
const parsed = Object.fromEntries(
|
|
262
|
+
Object.entries(asRecord(value, "rolePermissions")).map(([role, permissions]) => {
|
|
263
|
+
const path = `rolePermissions["${role}"]`;
|
|
264
|
+
if (!Object.hasOwn(roles, role)) {
|
|
265
|
+
return fail(path, "is not a key of roles");
|
|
266
|
+
}
|
|
267
|
+
return [role, parsePermissionList(permissions, path)];
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
const listed = Object.keys(parsed);
|
|
271
|
+
for (const [index, role] of listed.entries()) {
|
|
272
|
+
const other = listed
|
|
273
|
+
.slice(index + 1)
|
|
274
|
+
.find((name) => sameAccount(roles[role], roles[name]) && !sameSet(parsed[role] ?? [], parsed[name] ?? []));
|
|
275
|
+
if (other !== undefined) {
|
|
276
|
+
fail(`rolePermissions["${other}"]`, `differs from rolePermissions["${role}"], though both roles are one account`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return parsed;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const SECRET_NAME = /^[A-Z][A-Z0-9_]*$/;
|
|
283
|
+
|
|
284
|
+
function parsePasswordFor(value: unknown, roles: Record<string, string>): Record<string, string> {
|
|
285
|
+
const parsed: Record<string, string> = Object.fromEntries(
|
|
286
|
+
Object.entries(asRecord(value, "passwordFor")).map(([role, name]) => {
|
|
287
|
+
const path = `passwordFor["${role}"]`;
|
|
288
|
+
if (!Object.hasOwn(roles, role)) {
|
|
289
|
+
return fail(path, "is not a key of roles");
|
|
290
|
+
}
|
|
291
|
+
const secret = asString(name, path);
|
|
292
|
+
if (!SECRET_NAME.test(secret)) {
|
|
293
|
+
fail(path, "must be a variable name in upper case letters, digits and _, such as PASSWORD_NAME");
|
|
294
|
+
}
|
|
295
|
+
return [role, secret];
|
|
296
|
+
}),
|
|
297
|
+
);
|
|
298
|
+
const listed = Object.keys(parsed);
|
|
299
|
+
for (const [index, role] of listed.entries()) {
|
|
300
|
+
const other = listed
|
|
301
|
+
.slice(index + 1)
|
|
302
|
+
.find((name) => sameAccount(roles[role], roles[name]) && parsed[role] !== parsed[name]);
|
|
303
|
+
if (other !== undefined) {
|
|
304
|
+
fail(`passwordFor["${other}"]`, `differs from passwordFor["${role}"], though both roles are one account`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return parsed;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function parseCoverageWeights(value: unknown): ProjectFacts["coverageWeights"] {
|
|
311
|
+
const weights = asRecord(value, "coverageWeights");
|
|
312
|
+
const weight = (key: string): number =>
|
|
313
|
+
asWeight(present(weights, key, `coverageWeights.${key}`), `coverageWeights.${key}`);
|
|
314
|
+
return {
|
|
315
|
+
risk: weight("risk"),
|
|
316
|
+
callFrequency: weight("callFrequency"),
|
|
317
|
+
runFrequency: weight("runFrequency"),
|
|
318
|
+
stability: weight("stability"),
|
|
319
|
+
cost: weight("cost"),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function parseFlakyRunSeries(value: unknown): number {
|
|
324
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < MIN_FLAKY_RUN_SERIES) {
|
|
325
|
+
fail("flakyRunSeries", `must be an integer of at least ${MIN_FLAKY_RUN_SERIES}`);
|
|
326
|
+
}
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function asCount(value: unknown, path: string, minimum: number): number {
|
|
331
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < minimum) {
|
|
332
|
+
fail(path, `must be an integer of at least ${minimum}`);
|
|
333
|
+
}
|
|
334
|
+
return value;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function parseDurationBudgets(value: unknown): Record<string, number> {
|
|
338
|
+
return Object.fromEntries(
|
|
339
|
+
Object.entries(asRecord(value, "quality.durationBudgetMs")).map(([project, budget]) => {
|
|
340
|
+
if (typeof budget !== "number" || !Number.isFinite(budget) || budget <= 0) {
|
|
341
|
+
return fail(`quality.durationBudgetMs["${project}"]`, "must be a number above 0");
|
|
342
|
+
}
|
|
343
|
+
return [project, budget];
|
|
344
|
+
}),
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function parseQuality(value: unknown): ProjectFacts["quality"] {
|
|
349
|
+
const quality = asRecord(value, "quality");
|
|
350
|
+
const count = (key: string, minimum: number): number =>
|
|
351
|
+
asCount(present(quality, key, `quality.${key}`), `quality.${key}`, minimum);
|
|
352
|
+
const ratio = present(quality, "slowdownRatio", "quality.slowdownRatio");
|
|
353
|
+
if (typeof ratio !== "number" || !Number.isFinite(ratio) || ratio < MIN_SLOWDOWN_RATIO) {
|
|
354
|
+
fail("quality.slowdownRatio", `must be a number of at least ${MIN_SLOWDOWN_RATIO}`);
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
maxSteps: count("maxSteps", 0),
|
|
358
|
+
maxLines: count("maxLines", 1),
|
|
359
|
+
maxExpects: count("maxExpects", 0),
|
|
360
|
+
maxNesting: count("maxNesting", 0),
|
|
361
|
+
maxConditionals: count("maxConditionals", 0),
|
|
362
|
+
stableSeries: count("stableSeries", MIN_STABLE_SERIES),
|
|
363
|
+
durationBudgetMs: parseDurationBudgets(present(quality, "durationBudgetMs", "quality.durationBudgetMs")),
|
|
364
|
+
slowdownRatio: ratio,
|
|
365
|
+
slowdownMinMs: count("slowdownMinMs", 0),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function parseAutonomy(value: unknown): ProjectFacts["autonomy"] {
|
|
370
|
+
const autonomy = asRecord(value, "autonomy");
|
|
371
|
+
present(autonomy, DEFAULT_AUTONOMY_KEY, `autonomy["${DEFAULT_AUTONOMY_KEY}"]`);
|
|
372
|
+
return Object.fromEntries(
|
|
373
|
+
Object.entries(autonomy).map(([key, mode]) => {
|
|
374
|
+
if (mode !== "apply" && mode !== "propose") {
|
|
375
|
+
return fail(`autonomy["${key}"]`, 'must be "apply" or "propose"');
|
|
376
|
+
}
|
|
377
|
+
return [key, mode];
|
|
378
|
+
}),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function isForbiddenHealerSegment(segment: string): boolean {
|
|
383
|
+
const name = segment.toLowerCase();
|
|
384
|
+
return (
|
|
385
|
+
name === "." ||
|
|
386
|
+
name === ".." ||
|
|
387
|
+
name.startsWith("-") ||
|
|
388
|
+
name.startsWith(".git") ||
|
|
389
|
+
name.startsWith(".qa") ||
|
|
390
|
+
FORBIDDEN_HEALER_SEGMENTS.includes(name) ||
|
|
391
|
+
SHORT_NAME_SEGMENT.test(name)
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function parseHealerPaths(value: unknown): string[] {
|
|
396
|
+
return asList(value, "healerPaths").map((item, index) => {
|
|
397
|
+
const path = `healerPaths[${index}]`;
|
|
398
|
+
const text = asString(item, path);
|
|
399
|
+
if (!HEALER_PATH.test(text) || text.split("/").filter(Boolean).some(isForbiddenHealerSegment)) {
|
|
400
|
+
fail(path, "must be a plain directory inside the repository, not its root, git, qa, tooling or a short name");
|
|
401
|
+
}
|
|
402
|
+
return text;
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function parseSuiteDir(value: unknown): string {
|
|
407
|
+
if (value === undefined || value === ROOT_SUITE_DIR) {
|
|
408
|
+
return ROOT_SUITE_DIR;
|
|
409
|
+
}
|
|
410
|
+
const text = asString(value, "suiteDir");
|
|
411
|
+
if (!HEALER_PATH.test(text) || text.split("/").filter(Boolean).some(isForbiddenHealerSegment)) {
|
|
412
|
+
fail("suiteDir", 'must be "." or a plain directory inside the repository, not git, qa, tooling or a short name');
|
|
413
|
+
}
|
|
414
|
+
return text.replace(TRAILING_SLASHES, "");
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** The arguments that point Playwright at the suite: none for a suite at the repository root, else `--config`. */
|
|
418
|
+
export function playwrightConfigArgs(suiteDir: string): string[] {
|
|
419
|
+
return suiteDir === ROOT_SUITE_DIR ? [] : [`--config=${suiteDir}`];
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** The suite's `.env` file, relative to the repository root: `<suiteDir>/.env`, or `.env` for a suite at the root. */
|
|
423
|
+
export function suiteEnvPath(suiteDir: string): string {
|
|
424
|
+
return suiteDir === ROOT_SUITE_DIR ? ENV_FILE : `${suiteDir}/${ENV_FILE}`;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Validates the parsed contents of a project facts file.
|
|
429
|
+
*
|
|
430
|
+
* @throws Error `"project.json: <path> <problem>"` naming the first missing or invalid field.
|
|
431
|
+
*/
|
|
432
|
+
export function parseProjectFacts(json: unknown): ProjectFacts {
|
|
433
|
+
const root = asRecord(json, "file");
|
|
434
|
+
const roles = asStringMap(present(root, "roles", "roles"), "roles");
|
|
435
|
+
const roleFor = parseRoleFor(present(root, "roleFor", "roleFor"), roles);
|
|
436
|
+
const permissions = root["rolePermissions"];
|
|
437
|
+
const passwordFor = root["passwordFor"];
|
|
438
|
+
return {
|
|
439
|
+
suiteDir: parseSuiteDir(root["suiteDir"]),
|
|
440
|
+
tracker: parseTracker(present(root, "tracker", "tracker")),
|
|
441
|
+
docSources: parseDocSources(present(root, "docSources", "docSources")),
|
|
442
|
+
commands: parseCommands(present(root, "commands", "commands")),
|
|
443
|
+
critical: asStringList(present(root, "critical", "critical"), "critical"),
|
|
444
|
+
knowledgeDir: asString(present(root, "knowledgeDir", "knowledgeDir"), "knowledgeDir"),
|
|
445
|
+
roles,
|
|
446
|
+
roleFor,
|
|
447
|
+
...(permissions === undefined ? {} : { rolePermissions: parseRolePermissions(permissions, roles) }),
|
|
448
|
+
...(passwordFor === undefined ? {} : { passwordFor: parsePasswordFor(passwordFor, roles) }),
|
|
449
|
+
coverageWeights: parseCoverageWeights(present(root, "coverageWeights", "coverageWeights")),
|
|
450
|
+
flakyRunSeries: parseFlakyRunSeries(present(root, "flakyRunSeries", "flakyRunSeries")),
|
|
451
|
+
quality: parseQuality(present(root, "quality", "quality")),
|
|
452
|
+
autonomy: parseAutonomy(present(root, "autonomy", "autonomy")),
|
|
453
|
+
healerPaths: parseHealerPaths(present(root, "healerPaths", "healerPaths")),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Reads and validates the project facts of the repository the agents work in. There is no fallback: a
|
|
459
|
+
* missing or broken file stops the agents instead of letting them guess.
|
|
460
|
+
*
|
|
461
|
+
* @throws Error `"project.json: <path> cannot be read"` or the first validation error.
|
|
462
|
+
*/
|
|
463
|
+
export function readProjectFacts(path = PROJECT_FACTS_PATH): ProjectFacts {
|
|
464
|
+
let text: string;
|
|
465
|
+
try {
|
|
466
|
+
text = readFileSync(path, "utf8");
|
|
467
|
+
} catch {
|
|
468
|
+
return fail(path, "cannot be read");
|
|
469
|
+
}
|
|
470
|
+
let json: unknown;
|
|
471
|
+
try {
|
|
472
|
+
json = JSON.parse(text);
|
|
473
|
+
} catch {
|
|
474
|
+
return fail(path, "is not valid JSON");
|
|
475
|
+
}
|
|
476
|
+
return parseProjectFacts(json);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** {@link readProjectFacts} of the repository at `projectDir`. */
|
|
480
|
+
export function readProjectFactsIn(projectDir: string): ProjectFacts {
|
|
481
|
+
return readProjectFacts(join(projectDir, PROJECT_FACTS_PATH));
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (basename(process.argv[1] ?? "") === CLI_FILE_NAME) {
|
|
485
|
+
try {
|
|
486
|
+
process.stdout.write(`${JSON.stringify(readProjectFacts(), null, 2)}\n`);
|
|
487
|
+
} catch (error) {
|
|
488
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
489
|
+
process.exitCode = 1;
|
|
490
|
+
}
|
|
491
|
+
}
|