@maniumek/suwgate 0.16.0 → 0.18.0
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/AGENTS.shared.md +13 -2
- package/README.md +98 -9
- package/dist/cli.js +217 -13
- package/dist/gate/breakdown.d.ts +40 -0
- package/dist/gate/breakdown.js +111 -0
- package/dist/gate/check.d.ts +4 -0
- package/dist/gate/check.js +38 -1
- package/dist/gate/ciHistory.d.ts +21 -0
- package/dist/gate/ciHistory.js +195 -0
- package/dist/gate/config.d.ts +5 -1
- package/dist/gate/config.js +56 -2
- package/dist/gate/context.d.ts +15 -0
- package/dist/gate/context.js +98 -0
- package/dist/gate/contract.d.ts +7 -0
- package/dist/gate/contract.js +1 -0
- package/dist/gate/dashboard.d.ts +112 -0
- package/dist/gate/dashboard.js +148 -0
- package/dist/gate/dashboardFile.d.ts +33 -0
- package/dist/gate/dashboardFile.js +185 -0
- package/dist/gate/dashboardJson.d.ts +2 -0
- package/dist/gate/dashboardJson.js +26 -0
- package/dist/gate/dashboardPage.d.ts +3 -0
- package/dist/gate/dashboardPage.js +307 -0
- package/dist/gate/dashboardServer.d.ts +11 -0
- package/dist/gate/dashboardServer.js +70 -0
- package/dist/gate/dashboardTesting.d.ts +12 -0
- package/dist/gate/dashboardTesting.js +99 -0
- package/dist/gate/guardsStep.d.ts +6 -0
- package/dist/gate/guardsStep.js +8 -1
- package/dist/gate/history.d.ts +31 -0
- package/dist/gate/history.js +105 -0
- package/dist/gate/plan.d.ts +3 -1
- package/dist/gate/plan.js +6 -3
- package/dist/gate/repository.d.ts +1 -0
- package/dist/gate/repository.js +1 -1
- package/dist/gate/runner.d.ts +3 -0
- package/dist/gate/runner.js +4 -1
- package/dist/gate/stats.d.ts +27 -0
- package/dist/gate/stats.js +84 -0
- package/dist/guards/comments/eslint.js +1 -0
- package/dist/guards/comments/scan.js +1 -0
- package/dist/guards/comments/switches.js +1 -0
- package/dist/guards/database/connectionHost.js +1 -0
- package/dist/guards/dotnet/appsettingsBound.js +1 -0
- package/dist/guards/dotnet/bannedNugetPackages.js +1 -0
- package/dist/guards/dotnet/openApiVersions.js +1 -0
- package/dist/guards/dotnet/suwbackkitWiring.js +1 -0
- package/dist/guards/dotnet/unusedNugetVersions.js +1 -0
- package/dist/guards/repository/bannedNpmPackages.js +1 -0
- package/dist/guards/repository/composePorts.js +1 -0
- package/dist/guards/repository/dependencyDirection.js +1 -0
- package/dist/guards/repository/forbiddenNames.js +1 -0
- package/dist/guards/repository/humanDocs.js +1 -0
- package/dist/guards/repository/imagePins.js +1 -0
- package/dist/guards/repository/justModules.js +1 -0
- package/dist/guards/repository/noRawColors.js +1 -0
- package/dist/guards/repository/repositoryLayout.js +1 -0
- package/dist/guards/repository/scriptsCalled.js +1 -0
- package/dist/guards/repository/scriptsHelp.js +1 -0
- package/dist/guards/repository/suwfrontkitWiring.js +1 -0
- package/dist/guards/repository/vsCodeSettings.js +1 -0
- package/dist/profiles/holdout.d.ts +2 -0
- package/dist/profiles/holdout.js +38 -0
- package/dist/profiles/index.d.ts +1 -0
- package/dist/profiles/index.js +1 -0
- package/dist/profiles/reports.d.ts +6 -0
- package/dist/profiles/reports.js +14 -0
- package/dist/profiles/verdict.js +41 -2
- package/dist/session/doctor.d.ts +26 -0
- package/dist/session/doctor.js +265 -0
- package/dist/session/gardenRecord.d.ts +12 -0
- package/dist/session/gardenRecord.js +58 -0
- package/dist/session/guardPr.js +2 -2
- package/dist/session/prePush.js +1 -1
- package/dist/session/suwagentInfo.d.ts +28 -0
- package/dist/session/suwagentInfo.js +103 -0
- package/package.json +1 -1
- package/schema/suwgate.schema.json +26 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { appendFileSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
export const HISTORY_FILE = "suwgate-runs.jsonl";
|
|
5
|
+
const MAX_HISTORY_BYTES = 5 * 1024 * 1024;
|
|
6
|
+
function git(root, args) {
|
|
7
|
+
try {
|
|
8
|
+
return execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function inCommonDir(root, file) {
|
|
15
|
+
const common = git(root, ["rev-parse", "--git-common-dir"]);
|
|
16
|
+
return common === "" ? null : path.join(path.resolve(root, common), file);
|
|
17
|
+
}
|
|
18
|
+
export function historyFile(root) {
|
|
19
|
+
return inCommonDir(root, HISTORY_FILE);
|
|
20
|
+
}
|
|
21
|
+
export function branchOf(root) {
|
|
22
|
+
return git(root, ["symbolic-ref", "-q", "--short", "HEAD"]) || "HEAD";
|
|
23
|
+
}
|
|
24
|
+
function dropOldestHalf(file) {
|
|
25
|
+
const lines = readFileSync(file, "utf8")
|
|
26
|
+
.split("\n")
|
|
27
|
+
.filter((line) => line !== "");
|
|
28
|
+
writeFileSync(file, lines
|
|
29
|
+
.slice(Math.ceil(lines.length / 2))
|
|
30
|
+
.map((line) => `${line}\n`)
|
|
31
|
+
.join(""));
|
|
32
|
+
}
|
|
33
|
+
export function recordRun(root, record, maxBytes = MAX_HISTORY_BYTES) {
|
|
34
|
+
try {
|
|
35
|
+
const file = historyFile(root);
|
|
36
|
+
if (file === null)
|
|
37
|
+
return;
|
|
38
|
+
try {
|
|
39
|
+
if (statSync(file).size > maxBytes)
|
|
40
|
+
dropOldestHalf(file);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code !== "ENOENT")
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
appendFileSync(file, `${JSON.stringify(record)}\n`);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export function readRuns(root) {
|
|
53
|
+
const file = historyFile(root);
|
|
54
|
+
if (file === null)
|
|
55
|
+
return [];
|
|
56
|
+
let text;
|
|
57
|
+
try {
|
|
58
|
+
text = readFileSync(file, "utf8");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return parseRuns(text);
|
|
64
|
+
}
|
|
65
|
+
const MODES = ["quick", "full", "ship", "step"];
|
|
66
|
+
const STEP_VERDICTS = ["pass", "fail", "skip"];
|
|
67
|
+
function counts(value) {
|
|
68
|
+
return typeof value === "object" && value !== null && Object.values(value).every((count) => typeof count === "number");
|
|
69
|
+
}
|
|
70
|
+
function isStep(value) {
|
|
71
|
+
const step = value;
|
|
72
|
+
return (typeof step?.id === "string" &&
|
|
73
|
+
typeof step.verdict === "string" &&
|
|
74
|
+
STEP_VERDICTS.includes(step.verdict) &&
|
|
75
|
+
typeof step.seconds === "number");
|
|
76
|
+
}
|
|
77
|
+
function isRun(value) {
|
|
78
|
+
if (typeof value !== "object" || value === null)
|
|
79
|
+
return false;
|
|
80
|
+
const run = value;
|
|
81
|
+
return (typeof run.at === "string" &&
|
|
82
|
+
!Number.isNaN(Date.parse(run.at)) &&
|
|
83
|
+
typeof run.mode === "string" &&
|
|
84
|
+
MODES.includes(run.mode) &&
|
|
85
|
+
typeof run.branch === "string" &&
|
|
86
|
+
(run.verdict === "green" || run.verdict === "red") &&
|
|
87
|
+
typeof run.seconds === "number" &&
|
|
88
|
+
Array.isArray(run.steps) &&
|
|
89
|
+
run.steps.every(isStep) &&
|
|
90
|
+
Array.isArray(run.ran) &&
|
|
91
|
+
run.ran.every((id) => typeof id === "string") &&
|
|
92
|
+
counts(run.guards) &&
|
|
93
|
+
counts(run.excepted));
|
|
94
|
+
}
|
|
95
|
+
export function parseRuns(text) {
|
|
96
|
+
return text.split("\n").flatMap((line) => {
|
|
97
|
+
try {
|
|
98
|
+
const parsed = JSON.parse(line);
|
|
99
|
+
return isRun(parsed) ? [parsed] : [];
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
package/dist/gate/plan.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Catalog, type Config, type Environment } from "./config.ts";
|
|
2
2
|
import type { GuardException, Step } from "./contract.ts";
|
|
3
|
+
import { type GuardTally } from "./guardsStep.ts";
|
|
3
4
|
export declare const GUARDS_STEP = "guards";
|
|
4
5
|
export interface Outcome {
|
|
5
6
|
passed: boolean;
|
|
6
7
|
log: string;
|
|
8
|
+
guards?: GuardTally;
|
|
7
9
|
}
|
|
8
10
|
export interface PlannedStep {
|
|
9
11
|
id: string;
|
package/dist/gate/plan.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { accessSync, constants } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { takesGuard } from "./config.js";
|
|
3
4
|
import { runGuards } from "./guardsStep.js";
|
|
4
5
|
const DEFAULT_LIMIT_SECONDS = 300;
|
|
5
6
|
export const GUARDS_STEP = "guards";
|
|
@@ -25,7 +26,8 @@ function addedSteps(config) {
|
|
|
25
26
|
}));
|
|
26
27
|
}
|
|
27
28
|
export function allSteps(config, catalog) {
|
|
28
|
-
|
|
29
|
+
const holdout = config.holdout === undefined ? [] : [catalog.holdoutStep?.(config.holdout)].filter((found) => found !== undefined);
|
|
30
|
+
return [...catalog.stepsFor(config.profiles), ...holdout, ...addedSteps(config)];
|
|
29
31
|
}
|
|
30
32
|
function chosenRun(step, quick) {
|
|
31
33
|
if (!quick)
|
|
@@ -36,7 +38,8 @@ function chosenRun(step, quick) {
|
|
|
36
38
|
}
|
|
37
39
|
function activeGuards(input) {
|
|
38
40
|
const skipped = input.config.skippedGuards.map((entry) => entry.guard);
|
|
39
|
-
return input.catalog.guards.filter((guard) => (
|
|
41
|
+
return input.catalog.guards.filter((guard) => takesGuard(input.config, guard) &&
|
|
42
|
+
(guard.profiles === "every" || guard.profiles.some((profile) => input.config.profiles.includes(profile))) &&
|
|
40
43
|
(!input.quick || guard.quick !== false) &&
|
|
41
44
|
!skipped.includes(guard.id));
|
|
42
45
|
}
|
|
@@ -61,7 +64,7 @@ function guardsStep(input) {
|
|
|
61
64
|
config: input.config,
|
|
62
65
|
merged: input.merged ?? [],
|
|
63
66
|
});
|
|
64
|
-
return { passed: summary.passed, log: summary.log };
|
|
67
|
+
return { passed: summary.passed, log: summary.log, guards: summary.tally };
|
|
65
68
|
},
|
|
66
69
|
};
|
|
67
70
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function git(root: string, args: readonly string[]): string | null;
|
|
1
2
|
export declare function repositoryRoot(cwd: string): string | null;
|
|
2
3
|
export declare function repositoryFiles(root: string): string[];
|
|
3
4
|
export declare function changedFiles(root: string): string[];
|
package/dist/gate/repository.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
function git(root, args) {
|
|
4
|
+
export function git(root, args) {
|
|
5
5
|
try {
|
|
6
6
|
return execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
7
7
|
}
|
package/dist/gate/runner.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GuardTally } from "./guardsStep.ts";
|
|
1
2
|
import type { PlannedStep } from "./plan.ts";
|
|
2
3
|
type Status = "pass" | "fail" | "skip";
|
|
3
4
|
export interface StepResult {
|
|
@@ -5,6 +6,8 @@ export interface StepResult {
|
|
|
5
6
|
status: Status;
|
|
6
7
|
seconds: number;
|
|
7
8
|
log: string;
|
|
9
|
+
elapsed?: number;
|
|
10
|
+
guards?: GuardTally;
|
|
8
11
|
}
|
|
9
12
|
export declare function runSteps(steps: readonly PlannedStep[], env: NodeJS.ProcessEnv, stepLimit: number | null): Promise<StepResult[]>;
|
|
10
13
|
export {};
|
package/dist/gate/runner.js
CHANGED
|
@@ -76,11 +76,14 @@ export async function runSteps(steps, env, stepLimit) {
|
|
|
76
76
|
const outcome = step.command !== undefined
|
|
77
77
|
? await runCommand(step.command, limit, stepEnv(env, step.environment))
|
|
78
78
|
: await (step.inline ?? (() => Promise.resolve({ passed: true, log: "" })))();
|
|
79
|
+
const elapsed = (performance.now() - began) / 1000;
|
|
79
80
|
return {
|
|
80
81
|
step,
|
|
81
82
|
status: outcome.passed ? "pass" : "fail",
|
|
82
|
-
seconds: Math.round(
|
|
83
|
+
seconds: Math.round(elapsed),
|
|
84
|
+
elapsed,
|
|
83
85
|
log: outcome.log,
|
|
86
|
+
...(outcome.guards === undefined ? {} : { guards: outcome.guards }),
|
|
84
87
|
};
|
|
85
88
|
})();
|
|
86
89
|
running.set(step.id, result);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RunRecord } from "./history.ts";
|
|
2
|
+
export interface Stats {
|
|
3
|
+
days: number;
|
|
4
|
+
runs: number;
|
|
5
|
+
modes: Record<string, {
|
|
6
|
+
runs: number;
|
|
7
|
+
red: number;
|
|
8
|
+
}>;
|
|
9
|
+
quick: {
|
|
10
|
+
runs: number;
|
|
11
|
+
medianSeconds: number;
|
|
12
|
+
slowestSeconds: number;
|
|
13
|
+
overBudget: number;
|
|
14
|
+
} | null;
|
|
15
|
+
slowestSteps: {
|
|
16
|
+
id: string;
|
|
17
|
+
medianSeconds: number;
|
|
18
|
+
}[];
|
|
19
|
+
guards: {
|
|
20
|
+
id: string;
|
|
21
|
+
findings: number;
|
|
22
|
+
excepted: number;
|
|
23
|
+
}[];
|
|
24
|
+
quiet: string[];
|
|
25
|
+
}
|
|
26
|
+
export declare function summarize(history: readonly RunRecord[], days: number, now: Date): Stats;
|
|
27
|
+
export declare function formatStats(stats: Stats): string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const SLOWEST_STEPS = 5;
|
|
2
|
+
const MODES = ["quick", "full", "ship", "step"];
|
|
3
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
4
|
+
function median(values) {
|
|
5
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
6
|
+
const middle = Math.floor(sorted.length / 2);
|
|
7
|
+
const value = sorted.length % 2 === 1 ? (sorted[middle] ?? 0) : ((sorted[middle - 1] ?? 0) + (sorted[middle] ?? 0)) / 2;
|
|
8
|
+
return Math.round(value * 10) / 10;
|
|
9
|
+
}
|
|
10
|
+
function sumInto(total, counts) {
|
|
11
|
+
for (const [id, count] of Object.entries(counts))
|
|
12
|
+
total.set(id, (total.get(id) ?? 0) + count);
|
|
13
|
+
}
|
|
14
|
+
export function summarize(history, days, now) {
|
|
15
|
+
const since = now.getTime() - days * DAY_MS;
|
|
16
|
+
const runs = history.filter((run) => Date.parse(run.at) >= since);
|
|
17
|
+
const modes = Object.fromEntries(MODES.flatMap((mode) => {
|
|
18
|
+
const own = runs.filter((run) => run.mode === mode);
|
|
19
|
+
return own.length === 0 ? [] : [[mode, { runs: own.length, red: own.filter((run) => run.verdict === "red").length }]];
|
|
20
|
+
}));
|
|
21
|
+
const quickRuns = runs.filter((run) => run.mode === "quick");
|
|
22
|
+
const stepSeconds = new Map();
|
|
23
|
+
for (const step of runs.flatMap((run) => run.steps).filter((step) => step.verdict !== "skip")) {
|
|
24
|
+
stepSeconds.set(step.id, [...(stepSeconds.get(step.id) ?? []), step.seconds]);
|
|
25
|
+
}
|
|
26
|
+
const findings = new Map();
|
|
27
|
+
const excepted = new Map();
|
|
28
|
+
for (const run of runs) {
|
|
29
|
+
sumInto(findings, run.guards);
|
|
30
|
+
sumInto(excepted, run.excepted);
|
|
31
|
+
}
|
|
32
|
+
const ran = new Set(runs.flatMap((run) => run.ran));
|
|
33
|
+
return {
|
|
34
|
+
days,
|
|
35
|
+
runs: runs.length,
|
|
36
|
+
modes,
|
|
37
|
+
quick: quickRuns.length === 0
|
|
38
|
+
? null
|
|
39
|
+
: {
|
|
40
|
+
runs: quickRuns.length,
|
|
41
|
+
medianSeconds: median(quickRuns.map((run) => run.seconds)),
|
|
42
|
+
slowestSeconds: Math.max(...quickRuns.map((run) => run.seconds)),
|
|
43
|
+
overBudget: quickRuns.filter((run) => run.overBudget).length,
|
|
44
|
+
},
|
|
45
|
+
slowestSteps: [...stepSeconds]
|
|
46
|
+
.map(([id, seconds]) => ({ id, medianSeconds: median(seconds) }))
|
|
47
|
+
.sort((a, b) => b.medianSeconds - a.medianSeconds || a.id.localeCompare(b.id))
|
|
48
|
+
.slice(0, SLOWEST_STEPS),
|
|
49
|
+
guards: [...new Set([...findings.keys(), ...excepted.keys()])]
|
|
50
|
+
.map((id) => ({ id, findings: findings.get(id) ?? 0, excepted: excepted.get(id) ?? 0 }))
|
|
51
|
+
.sort((a, b) => b.findings - a.findings || b.excepted - a.excepted || a.id.localeCompare(b.id)),
|
|
52
|
+
quiet: [...ran].filter((id) => !findings.has(id) && !excepted.has(id)).sort(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function percent(part, whole) {
|
|
56
|
+
return `${Math.round((part / whole) * 100)}%`;
|
|
57
|
+
}
|
|
58
|
+
export function formatStats(stats) {
|
|
59
|
+
if (stats.runs === 0) {
|
|
60
|
+
return `suwgate stats: no gate run recorded in the last ${stats.days} days: run suwgate check --quick, or widen the period with --days <n>`;
|
|
61
|
+
}
|
|
62
|
+
const lines = [`The gate in the last ${stats.days} days: ${stats.runs} run${stats.runs === 1 ? "" : "s"}`, ""];
|
|
63
|
+
for (const [mode, own] of Object.entries(stats.modes)) {
|
|
64
|
+
lines.push(` ${mode.padEnd(6)} ${String(own.runs).padStart(4)} run${own.runs === 1 ? " " : "s"}, ${own.red} red (${percent(own.red, own.runs)})`);
|
|
65
|
+
}
|
|
66
|
+
if (stats.quick !== null) {
|
|
67
|
+
lines.push("", `Quick gate: median ${stats.quick.medianSeconds}s, slowest ${stats.quick.slowestSeconds}s, ${stats.quick.overBudget} over budget`);
|
|
68
|
+
}
|
|
69
|
+
if (stats.slowestSteps.length > 0) {
|
|
70
|
+
lines.push("", "Slowest steps (median seconds):");
|
|
71
|
+
for (const step of stats.slowestSteps)
|
|
72
|
+
lines.push(` ${String(step.medianSeconds).padStart(6)}s ${step.id}`);
|
|
73
|
+
}
|
|
74
|
+
if (stats.guards.length > 0) {
|
|
75
|
+
lines.push("", "Guards by findings (failed, excepted):");
|
|
76
|
+
for (const guard of stats.guards)
|
|
77
|
+
lines.push(` ${String(guard.findings).padStart(5)} ${String(guard.excepted).padStart(5)} ${guard.id}`);
|
|
78
|
+
}
|
|
79
|
+
if (stats.quiet.length > 0) {
|
|
80
|
+
lines.push("", `Guards with no finding in ${stats.days} days:`, ...stats.quiet.map((id) => ` ${id}`));
|
|
81
|
+
lines.push("Candidates for review: a quiet guard may still be worth keeping when it guards something rare.");
|
|
82
|
+
}
|
|
83
|
+
return lines.join("\n");
|
|
84
|
+
}
|
|
@@ -79,5 +79,6 @@ export const commentsEslint = {
|
|
|
79
79
|
id: "comments-eslint",
|
|
80
80
|
description: `ESLint lints every TypeScript and JavaScript file but the web app's generated API types and refuses its comments with ${RULE} as an error`,
|
|
81
81
|
profiles: LINTED_PROFILES,
|
|
82
|
+
set: "stack",
|
|
82
83
|
check: async (context) => (await Promise.all(lintedDirectories(context).map((directory) => findingsIn(context, directory)))).flat(),
|
|
83
84
|
};
|
|
@@ -77,6 +77,7 @@ export function commentGuard(guard) {
|
|
|
77
77
|
id: guard.id,
|
|
78
78
|
description: guard.description,
|
|
79
79
|
profiles: guard.profiles,
|
|
80
|
+
set: "stack",
|
|
80
81
|
check: (context) => context.files
|
|
81
82
|
.filter((file) => isScanned(file) && guard.scans(file))
|
|
82
83
|
.flatMap((file) => guard.commentsIn(file, context.read(file)).map((comment) => commentFinding(file, comment))),
|
|
@@ -26,5 +26,6 @@ export const noInPlaceSwitches = {
|
|
|
26
26
|
id: "no-in-place-switches",
|
|
27
27
|
description: "No source file switches the type checker, a lint rule or an analyzer off in place (@ts-ignore, @ts-nocheck, eslint-disable, an eslint config comment, #pragma warning disable)",
|
|
28
28
|
profiles: ["web", "library", "dotnet"],
|
|
29
|
+
set: "stack",
|
|
29
30
|
check: (context) => context.files.filter(isScanned).flatMap((file) => switchesIn(file, context.read(file))),
|
|
30
31
|
};
|
|
@@ -9,6 +9,7 @@ export const connectionHost = {
|
|
|
9
9
|
id: "connection-host",
|
|
10
10
|
description: "No connection string names the host by its name instead of its address (write Host=127.0.0.1)",
|
|
11
11
|
profiles: ["database"],
|
|
12
|
+
set: "stack",
|
|
12
13
|
check(context) {
|
|
13
14
|
const findings = [];
|
|
14
15
|
for (const file of context.files.filter(scanned)) {
|
|
@@ -46,6 +46,7 @@ export const appsettingsBound = {
|
|
|
46
46
|
id: "appsettings-bound",
|
|
47
47
|
description: "Every section of appsettings*.json is read by the code (an options class bound to it, by a string or a const string), so no setting is dead",
|
|
48
48
|
profiles: ["dotnet"],
|
|
49
|
+
set: "stack",
|
|
49
50
|
check(context) {
|
|
50
51
|
const read = sectionsRead(dotnetFiles(context, CSHARP).map((file) => context.read(file)));
|
|
51
52
|
const problems = [];
|
|
@@ -21,6 +21,7 @@ export const bannedNugetPackages = {
|
|
|
21
21
|
id: "banned-nuget-packages",
|
|
22
22
|
description: "No project references or versions a NuGet package that hides calls from grep, mocks the real thing or duplicates the platform",
|
|
23
23
|
profiles: ["dotnet"],
|
|
24
|
+
set: "stack",
|
|
24
25
|
settingsSchema: {
|
|
25
26
|
type: "object",
|
|
26
27
|
additionalProperties: false,
|
|
@@ -14,6 +14,7 @@ export const openApiVersions = {
|
|
|
14
14
|
id: "openapi-versions",
|
|
15
15
|
description: `${TOOL}, which writes the OpenAPI contract at build, is pinned in Directory.Packages.props to the same version as ${LIBRARY}, whose OpenAPI library it loads`,
|
|
16
16
|
profiles: ["dotnet"],
|
|
17
|
+
set: "stack",
|
|
17
18
|
check(context) {
|
|
18
19
|
const file = centralPackagesFile(context);
|
|
19
20
|
if (!context.files.includes(file))
|
|
@@ -22,6 +22,7 @@ export const suwbackkitWiring = {
|
|
|
22
22
|
id: "suwbackkit-wiring",
|
|
23
23
|
description: "A web server that references Suwbackkit.Server calls AddServerDefaults and MapServerDefaults, so the kit is wired, not only installed",
|
|
24
24
|
profiles: ["dotnet"],
|
|
25
|
+
set: "stack",
|
|
25
26
|
check: (context) => dotnetFiles(context, PROJECT)
|
|
26
27
|
.filter((project) => {
|
|
27
28
|
const text = context.read(project);
|
|
@@ -3,6 +3,7 @@ export const unusedNugetVersions = {
|
|
|
3
3
|
id: "unused-nuget-versions",
|
|
4
4
|
description: "Every package version of Directory.Packages.props is referenced by a project",
|
|
5
5
|
profiles: ["dotnet"],
|
|
6
|
+
set: "stack",
|
|
6
7
|
check(context) {
|
|
7
8
|
const central = centralPackagesFile(context);
|
|
8
9
|
if (!context.files.includes(central)) {
|
|
@@ -21,6 +21,7 @@ export const bannedNpmPackages = {
|
|
|
21
21
|
id: "banned-npm-packages",
|
|
22
22
|
description: "No package.json depends on a banned package (component kits, CSS-in-JS, lodash, moment, jQuery, classnames, and what settings add)",
|
|
23
23
|
profiles: ["web", "library"],
|
|
24
|
+
set: "stack",
|
|
24
25
|
settingsSchema: {
|
|
25
26
|
type: "object",
|
|
26
27
|
additionalProperties: false,
|
|
@@ -43,6 +43,7 @@ export const composePorts = {
|
|
|
43
43
|
id: "compose-ports",
|
|
44
44
|
description: "Every compose file publishes its ports on the loopback (127.0.0.1) only, never on every network interface",
|
|
45
45
|
profiles: "every",
|
|
46
|
+
set: "stack",
|
|
46
47
|
check(context) {
|
|
47
48
|
return context.files
|
|
48
49
|
.filter((file) => COMPOSE_FILE.test(baseName(file)))
|
|
@@ -68,6 +68,7 @@ export const dependencyDirection = {
|
|
|
68
68
|
id: "dependency-direction",
|
|
69
69
|
description: "Dependencies point one way: a library never depends at runtime on an application (named in settings, or taken from a local path), and no repository depends on a package its settings forbid",
|
|
70
70
|
profiles: "every",
|
|
71
|
+
set: "stack",
|
|
71
72
|
settingsSchema: {
|
|
72
73
|
type: "object",
|
|
73
74
|
additionalProperties: false,
|
|
@@ -48,6 +48,7 @@ export const forbiddenNames = {
|
|
|
48
48
|
id: "forbidden-names",
|
|
49
49
|
description: "No folder, project or file is named by a vague word (utils, helpers, common), and no folder or project by the kind of thing it holds (services, components), instead of what it is",
|
|
50
50
|
profiles: "every",
|
|
51
|
+
set: "stack",
|
|
51
52
|
settingsSchema: { type: "object", additionalProperties: false, properties: { words: stringList, ignore: stringList } },
|
|
52
53
|
check(context) {
|
|
53
54
|
const settings = (context.settings ?? {});
|
|
@@ -77,6 +77,7 @@ export const humanDocs = {
|
|
|
77
77
|
id: "human-docs",
|
|
78
78
|
description: "The docs for people (README.md, docs/development.md and the README of a profile's directory) never tell a person to run a script meant for agents (scripts/.internal/, <name>.Gate/scripts/): people run just recipes",
|
|
79
79
|
profiles: "every",
|
|
80
|
+
set: "stack",
|
|
80
81
|
check(context) {
|
|
81
82
|
const agentNames = new Set(context.files.filter((file) => AGENT_SCRIPT.test(file)).map(baseName));
|
|
82
83
|
return documentsOf(context).flatMap((document) => commandsOf(context.read(document)).flatMap(({ line, text }) => {
|
|
@@ -41,6 +41,7 @@ export const imagePins = {
|
|
|
41
41
|
id: "image-pins",
|
|
42
42
|
description: "Every container image (Dockerfile FROM, image: in YAML, IMAGE= in a script) is pinned to a version, never latest, and the Playwright image matches the installed @playwright/test",
|
|
43
43
|
profiles: "every",
|
|
44
|
+
set: "stack",
|
|
44
45
|
check(context) {
|
|
45
46
|
const found = context.files.flatMap((file) => isDockerfile(baseName(file)) || /\.(ya?ml|sh)$/.test(file) ? references(file, context.read(file)) : []);
|
|
46
47
|
const unpinned = found
|
|
@@ -17,6 +17,7 @@ export const justModules = {
|
|
|
17
17
|
id: "just-modules",
|
|
18
18
|
description: "Every just module is <name>.just beside the justfile, <folder>/mod.just, or the file a mod line names by its path (mod <name> '<path>'), and the justfile names each one",
|
|
19
19
|
profiles: "every",
|
|
20
|
+
set: "stack",
|
|
20
21
|
check(context) {
|
|
21
22
|
const modules = context.files.filter((file) => file.endsWith(".just"));
|
|
22
23
|
const mods = context.files.includes("justfile")
|
|
@@ -6,6 +6,7 @@ export const noRawColors = {
|
|
|
6
6
|
id: "no-raw-colors",
|
|
7
7
|
description: "Components use the theme's tokens, never a colour value of their own; it reads the src/ folder of a web app, and the folders settings name, but not the tests",
|
|
8
8
|
profiles: ["web", "library"],
|
|
9
|
+
set: "stack",
|
|
9
10
|
settingsSchema: {
|
|
10
11
|
type: "object",
|
|
11
12
|
additionalProperties: false,
|
|
@@ -83,6 +83,7 @@ export const repositoryLayout = {
|
|
|
83
83
|
id: "repository-layout",
|
|
84
84
|
description: "Every top-level folder has a short line in the map (the section ## The map) of docs/architecture.md, no two files differ only in letter case, and every shell script is executable in git",
|
|
85
85
|
profiles: "every",
|
|
86
|
+
set: "stack",
|
|
86
87
|
check(context) {
|
|
87
88
|
return [
|
|
88
89
|
...(context.files.includes(MAP) ? mapFindings(context) : []),
|
|
@@ -53,6 +53,7 @@ export const scriptsCalled = {
|
|
|
53
53
|
id: "scripts-called",
|
|
54
54
|
description: "Every script (*.sh, and the files of a scripts/ folder) is called by a recipe, another script, a hook (also a Claude Code plugin's hooks/hooks.json), the workflow or a command of suwgate.yml (steps.add run, steps.configure, env, dev)",
|
|
55
55
|
profiles: "every",
|
|
56
|
+
set: "stack",
|
|
56
57
|
check(context) {
|
|
57
58
|
const callers = callersOf(context);
|
|
58
59
|
return context.files
|
|
@@ -28,6 +28,7 @@ export const scriptsHelp = {
|
|
|
28
28
|
id: "scripts-help",
|
|
29
29
|
description: "Every shell script but the hooks answers --help with a usage text, so an agent asks it instead of reading it",
|
|
30
30
|
profiles: "every",
|
|
31
|
+
set: "stack",
|
|
31
32
|
quick: false,
|
|
32
33
|
check(context) {
|
|
33
34
|
return context.files
|
|
@@ -38,6 +38,7 @@ export const suwfrontkitWiring = {
|
|
|
38
38
|
id: "suwfrontkit-wiring",
|
|
39
39
|
description: `A web app (an index.html with a module script) that depends on ${KIT} loads ${THEME} from its main module or a stylesheet that module imports`,
|
|
40
40
|
profiles: PROFILES,
|
|
41
|
+
set: "stack",
|
|
41
42
|
check(context) {
|
|
42
43
|
const directories = [
|
|
43
44
|
...new Set(PROFILES.filter((profile) => context.profiles.includes(profile)).map((profile) => context.directories[profile] ?? "")),
|
|
@@ -40,6 +40,7 @@ export const vsCodeSettings = {
|
|
|
40
40
|
id: "vscode-settings",
|
|
41
41
|
description: "The VS Code settings hold glue and no style rules, and every recommended extension id is well formed and listed once",
|
|
42
42
|
profiles: "every",
|
|
43
|
+
set: "stack",
|
|
43
44
|
check(context) {
|
|
44
45
|
return [
|
|
45
46
|
...(context.files.includes(SETTINGS) ? settingsFindings(context.read(SETTINGS)) : []),
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { HOLDOUT_STEP } from "../gate/contract.js";
|
|
3
|
+
import { quoted, runDirectory, script, verdictCommand } from "./shell.js";
|
|
4
|
+
const HOLDOUT_LIMIT_SECONDS = 600;
|
|
5
|
+
function holdoutDirectory() {
|
|
6
|
+
const directory = process.env["SUWGATE_HOLDOUT"];
|
|
7
|
+
if (directory === undefined || directory === "")
|
|
8
|
+
return null;
|
|
9
|
+
try {
|
|
10
|
+
return statSync(directory).isDirectory() ? directory : null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function holdoutCommand(holdout) {
|
|
17
|
+
return script([
|
|
18
|
+
runDirectory(HOLDOUT_STEP),
|
|
19
|
+
`trap 'rm -f "$run/output.log"' EXIT`,
|
|
20
|
+
'rm -f "$run/report.xml"',
|
|
21
|
+
"status=0",
|
|
22
|
+
`SUWGATE_HOLDOUT_REPORT="$run/report.xml" bash -c ${quoted(holdout.run)} >"$run/output.log" 2>&1 || status=$?`,
|
|
23
|
+
verdictCommand('holdout "$run/report.xml" "$status"'),
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
export function holdoutStep(holdout) {
|
|
27
|
+
return {
|
|
28
|
+
id: HOLDOUT_STEP,
|
|
29
|
+
title: "holdout scenarios, kept outside the repository and run in CI only (a failure shows only the names of the failed scenarios)",
|
|
30
|
+
after: holdout.after ?? [],
|
|
31
|
+
limitSeconds: holdout.limitSeconds ?? HOLDOUT_LIMIT_SECONDS,
|
|
32
|
+
run: () => holdoutDirectory() === null
|
|
33
|
+
? {
|
|
34
|
+
skip: "SUWGATE_HOLDOUT names no directory: CI provides the holdout scenarios, so pass holdout-repository to the gate workflow (docs/ci.md); to run them here, check them out and set SUWGATE_HOLDOUT to that directory",
|
|
35
|
+
}
|
|
36
|
+
: holdoutCommand(holdout),
|
|
37
|
+
};
|
|
38
|
+
}
|
package/dist/profiles/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Profile, type Step } from "../gate/contract.ts";
|
|
2
2
|
export { discoverApiIn } from "./contract.ts";
|
|
3
3
|
export { dotnetGuards } from "./dotnetGuards.ts";
|
|
4
|
+
export { holdoutStep } from "./holdout.ts";
|
|
4
5
|
export { verdict } from "./verdict.ts";
|
|
5
6
|
export declare function stepsFor(profiles: readonly Profile[]): Step[];
|
package/dist/profiles/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { nodeSteps } from "./node.js";
|
|
|
8
8
|
import { webSteps } from "./web.js";
|
|
9
9
|
export { discoverApiIn } from "./contract.js";
|
|
10
10
|
export { dotnetGuards } from "./dotnetGuards.js";
|
|
11
|
+
export { holdoutStep } from "./holdout.js";
|
|
11
12
|
export { verdict } from "./verdict.js";
|
|
12
13
|
const BY_PROFILE = {
|
|
13
14
|
web: [...nodeSteps("web"), ...webSteps, ...contractSteps],
|
|
@@ -40,6 +40,12 @@ interface PlaywrightReport {
|
|
|
40
40
|
export declare function vitestRun(report: VitestReport): TestRun;
|
|
41
41
|
export declare function playwrightRun(report: PlaywrightReport): TestRun;
|
|
42
42
|
export declare function xunitRun(xml: string): TestRun;
|
|
43
|
+
export interface JunitCase {
|
|
44
|
+
name: string;
|
|
45
|
+
skipped: boolean;
|
|
46
|
+
failed: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare function junitCases(xml: string): JunitCase[] | null;
|
|
43
49
|
export declare function vitestTimes(report: VitestReport): TestTime[];
|
|
44
50
|
export declare function playwrightTimes(report: PlaywrightReport): TestTime[];
|
|
45
51
|
export declare function xunitTimes(xml: string): TestTime[];
|
package/dist/profiles/reports.js
CHANGED
|
@@ -48,6 +48,7 @@ export function xunitRun(xml) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
const MILLISECONDS = 1000;
|
|
51
|
+
const JUNIT_CASE = /<testcase\b([^>]*?)(?:\/>|>([\s\S]*?)<\/testcase>)/g;
|
|
51
52
|
const ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
|
|
52
53
|
function unescaped(value) {
|
|
53
54
|
return value.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|(\w+));/g, (entity, decimal, hex, named) => {
|
|
@@ -58,6 +59,19 @@ function unescaped(value) {
|
|
|
58
59
|
return ENTITIES[named ?? ""] ?? entity;
|
|
59
60
|
});
|
|
60
61
|
}
|
|
62
|
+
export function junitCases(xml) {
|
|
63
|
+
if (!/<testsuites?\b/.test(xml))
|
|
64
|
+
return null;
|
|
65
|
+
return Array.from(xml.matchAll(JUNIT_CASE), (tag) => {
|
|
66
|
+
const body = tag[2] ?? "";
|
|
67
|
+
const name = /\bname="([^"]*)"/.exec(tag[1] ?? "")?.[1];
|
|
68
|
+
return {
|
|
69
|
+
name: name === undefined ? "(unnamed scenario)" : unescaped(name),
|
|
70
|
+
skipped: /<skipped\b/.test(body),
|
|
71
|
+
failed: /<(failure|error)\b/.test(body),
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
61
75
|
export function vitestTimes(report) {
|
|
62
76
|
return (report.testResults ?? [])
|
|
63
77
|
.flatMap((file) => file.assertionResults ?? [])
|