@maniumek/suwgate 0.1.1 → 0.3.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/README.md +80 -17
- package/dist/cli.js +11 -2
- package/dist/eslint/index.d.ts +1 -0
- package/dist/eslint/index.js +5 -1
- package/dist/gate/check.js +10 -2
- package/dist/gate/config.d.ts +8 -1
- package/dist/gate/config.js +33 -2
- package/dist/gate/contract.d.ts +7 -0
- package/dist/gate/plan.js +7 -2
- package/dist/gate/report.js +1 -1
- package/dist/guards/comments/eslint.d.ts +1 -0
- package/dist/guards/comments/eslint.js +4 -2
- package/dist/guards/dotnet/index.js +2 -1
- package/dist/guards/dotnet/suwbackkitWiring.d.ts +2 -0
- package/dist/guards/dotnet/suwbackkitWiring.js +31 -0
- package/dist/guards/repository/configContents.d.ts +3 -0
- package/dist/guards/repository/configContents.js +330 -0
- package/dist/guards/repository/docsPaths.d.ts +2 -0
- package/dist/guards/repository/docsPaths.js +30 -6
- package/dist/guards/repository/forbiddenNames.js +5 -2
- package/dist/guards/repository/index.js +4 -0
- package/dist/guards/repository/noRawColors.js +3 -2
- package/dist/guards/repository/repositoryLayout.js +20 -2
- package/dist/guards/repository/requiredFiles.js +37 -8
- package/dist/guards/repository/suwfrontkitWiring.d.ts +2 -0
- package/dist/guards/repository/suwfrontkitWiring.js +52 -0
- package/dist/guards/repository/text.d.ts +1 -0
- package/dist/guards/repository/text.js +38 -0
- package/dist/guards/repository/vsCodeSettings.js +1 -1
- package/dist/profiles/contract.d.ts +1 -0
- package/dist/profiles/contract.js +6 -5
- package/dist/profiles/criteria.d.ts +1 -0
- package/dist/profiles/criteria.js +1 -1
- package/dist/profiles/criteriaRan.d.ts +21 -0
- package/dist/profiles/criteriaRan.js +109 -0
- package/dist/profiles/database.js +2 -2
- package/dist/profiles/dotnet.d.ts +3 -0
- package/dist/profiles/dotnet.js +30 -10
- package/dist/profiles/dotnetGuards.d.ts +3 -0
- package/dist/profiles/dotnetGuards.js +38 -0
- package/dist/profiles/everyRepository.js +2 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +2 -0
- package/dist/profiles/library.js +9 -7
- package/dist/profiles/node.js +20 -7
- package/dist/profiles/reports.d.ts +35 -0
- package/dist/profiles/reports.js +60 -0
- package/dist/profiles/shell.d.ts +7 -0
- package/dist/profiles/shell.js +37 -0
- package/dist/profiles/verdict.d.ts +9 -0
- package/dist/profiles/verdict.js +120 -0
- package/dist/profiles/web.js +19 -3
- package/package.json +2 -2
- package/schema/suwgate.schema.json +32 -1
package/dist/profiles/shell.d.ts
CHANGED
|
@@ -8,3 +8,10 @@ export declare function read(context: StepContext, file: string): string | null;
|
|
|
8
8
|
export declare function tracked(context: StepContext, pathspecs: readonly string[]): string[];
|
|
9
9
|
export declare function script(lines: readonly string[]): string;
|
|
10
10
|
export declare function onPath(tool: string): boolean;
|
|
11
|
+
export declare function suwgate(args: string): string;
|
|
12
|
+
export declare function hasDevSection(context: StepContext): boolean;
|
|
13
|
+
export declare const CHECKOUT_ENV: string[];
|
|
14
|
+
export declare function runDirectory(step: string): string;
|
|
15
|
+
export declare function verdictCommand(args: string): string;
|
|
16
|
+
export declare function countedVitest(step: string, command: string): string;
|
|
17
|
+
export declare function countedPlaywright(step: string, command: string): string[];
|
package/dist/profiles/shell.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { accessSync, constants, existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { parse as parseYaml } from "yaml";
|
|
6
|
+
const HERE = fileURLToPath(import.meta.url);
|
|
7
|
+
const CLI = path.join(path.dirname(HERE), "..", `cli${path.extname(HERE)}`);
|
|
4
8
|
export function quoted(argument) {
|
|
5
9
|
return `'${argument.replaceAll("'", `'"'"'`)}'`;
|
|
6
10
|
}
|
|
@@ -60,3 +64,36 @@ export function onPath(tool) {
|
|
|
60
64
|
}
|
|
61
65
|
});
|
|
62
66
|
}
|
|
67
|
+
export function suwgate(args) {
|
|
68
|
+
return `${quoted(process.execPath)} ${quoted(CLI)} ${args}`;
|
|
69
|
+
}
|
|
70
|
+
export function hasDevSection(context) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = parseYaml(readFileSync(path.join(context.root, "suwgate.yml"), "utf8"));
|
|
73
|
+
return typeof parsed === "object" && parsed !== null && "dev" in parsed;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export const CHECKOUT_ENV = [`variables="$(${suwgate("dev checkout-env")})"`, 'eval "$variables"'];
|
|
80
|
+
export function runDirectory(step) {
|
|
81
|
+
return `run="\${SUWGATE_RUN:-$(mktemp -d)}/${step}" && mkdir -p "$run"`;
|
|
82
|
+
}
|
|
83
|
+
export function verdictCommand(args) {
|
|
84
|
+
return suwgate(`verdict ${args}`);
|
|
85
|
+
}
|
|
86
|
+
export function countedVitest(step, command) {
|
|
87
|
+
return [
|
|
88
|
+
runDirectory(step),
|
|
89
|
+
`${command} --reporter=default --reporter=json --outputFile.json="$run/vitest.json"`,
|
|
90
|
+
verdictCommand(`tests vitest "$run/vitest.json" ${quoted(`vitest (${step})`)}`),
|
|
91
|
+
].join(" && ");
|
|
92
|
+
}
|
|
93
|
+
export function countedPlaywright(step, command) {
|
|
94
|
+
return [
|
|
95
|
+
runDirectory(step),
|
|
96
|
+
`PLAYWRIGHT_JSON_OUTPUT_FILE="$run/playwright.json" ${command} --reporter=list,json`,
|
|
97
|
+
verdictCommand(`tests playwright "$run/playwright.json" ${quoted(`playwright (${step})`)}`),
|
|
98
|
+
];
|
|
99
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReportFormat } from "./reports.ts";
|
|
2
|
+
export declare function testsVerdict(format: ReportFormat, location: string, tool: string): string | null;
|
|
3
|
+
export declare function guardsVerdict(directory: string, required: readonly string[]): string | null;
|
|
4
|
+
export declare function tsconfigVerdict(file: string, shown: string, preset: Readonly<Record<string, unknown>>): string | null;
|
|
5
|
+
export declare function eslintVerdict(file: string, printed: string, rules: readonly string[]): string | null;
|
|
6
|
+
export declare function verdict(argv: readonly string[]): {
|
|
7
|
+
exitCode: number;
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { criteriaRan } from "./criteriaRan.js";
|
|
3
|
+
import { files, readRun } from "./reports.js";
|
|
4
|
+
const STRICT_FAMILY = [
|
|
5
|
+
"noImplicitAny",
|
|
6
|
+
"strictNullChecks",
|
|
7
|
+
"strictFunctionTypes",
|
|
8
|
+
"strictBindCallApply",
|
|
9
|
+
"strictPropertyInitialization",
|
|
10
|
+
"strictBuiltinIteratorReturn",
|
|
11
|
+
"noImplicitThis",
|
|
12
|
+
"useUnknownInCatchVariables",
|
|
13
|
+
"alwaysStrict",
|
|
14
|
+
];
|
|
15
|
+
export function testsVerdict(format, location, tool) {
|
|
16
|
+
const run = readRun(format, location);
|
|
17
|
+
if (run === null)
|
|
18
|
+
return `${tool} wrote no report, so suwgate cannot tell that any test ran: run it again and look at its output above`;
|
|
19
|
+
if (run.executed > 0)
|
|
20
|
+
return null;
|
|
21
|
+
return `${tool} ran 0 tests (every test skipped or filtered out, or none found), and a gate that ran nothing proves nothing: add a test that runs, or skip the step in suwgate.yml (steps.skip) with a reason`;
|
|
22
|
+
}
|
|
23
|
+
function missingGuards(evidence, required) {
|
|
24
|
+
const ran = new Set(evidence.split("\n").map((line) => line.split("\t")[0] ?? ""));
|
|
25
|
+
return required.filter((guard) => !ran.has(guard));
|
|
26
|
+
}
|
|
27
|
+
export function guardsVerdict(directory, required) {
|
|
28
|
+
const evidence = files(directory, ".tsv")
|
|
29
|
+
.map((file) => readFileSync(file, "utf8"))
|
|
30
|
+
.join("\n");
|
|
31
|
+
const missing = missingGuards(evidence, required);
|
|
32
|
+
if (missing.length === 0)
|
|
33
|
+
return null;
|
|
34
|
+
return [
|
|
35
|
+
`${missing.length} .NET guard(s) of the repository's profiles did not run in this gate run: ${missing.join(", ")}.`,
|
|
36
|
+
"Call SuwgateGuards.VerifyAll(new GuardInputs { ... }) from one xUnit test in a test project that references Suwgate.Architecture",
|
|
37
|
+
"(the Suwgate.Architecture README shows the test; pass new DatabaseProfile() with the database profile), and do not skip that test;",
|
|
38
|
+
"a guard that does not apply to this repository is skipped in suwgate.yml (guards.skip) with a reason.",
|
|
39
|
+
].join("\n");
|
|
40
|
+
}
|
|
41
|
+
function strictOptions(preset) {
|
|
42
|
+
return Object.keys(preset).filter((option) => /^(strict|no|exact)/.test(option) && option !== "noEmit");
|
|
43
|
+
}
|
|
44
|
+
export function tsconfigVerdict(file, shown, preset) {
|
|
45
|
+
const options = JSON.parse(shown).compilerOptions ?? {};
|
|
46
|
+
const off = [
|
|
47
|
+
...strictOptions(preset).filter((option) => options[option] !== preset[option]),
|
|
48
|
+
...(preset["strict"] === true ? STRICT_FAMILY.filter((option) => options[option] === false) : []),
|
|
49
|
+
];
|
|
50
|
+
if (off.length === 0)
|
|
51
|
+
return null;
|
|
52
|
+
return `${file}: tsc --showConfig shows ${off.map((option) => `${option}: ${JSON.stringify(options[option] ?? "unset")}`).join(", ")}; the strict preset of suwgate needs them on: extend @maniumek/suwgate/tsconfig/strict (or browser, node) and delete the override`;
|
|
53
|
+
}
|
|
54
|
+
export function eslintVerdict(file, printed, rules) {
|
|
55
|
+
const config = JSON.parse(printed);
|
|
56
|
+
const severity = (rule) => {
|
|
57
|
+
const setting = config.rules?.[rule];
|
|
58
|
+
return Array.isArray(setting) ? setting[0] : setting;
|
|
59
|
+
};
|
|
60
|
+
const off = rules.filter((rule) => severity(rule) !== 2 && severity(rule) !== "error");
|
|
61
|
+
if (off.length === 0)
|
|
62
|
+
return null;
|
|
63
|
+
return `${file}: eslint --print-config shows ${off.map((rule) => `${rule} ${JSON.stringify(severity(rule) ?? "off")}`).join(", ")}; it must be an error for every source file: build eslint.config.js on strict() or app() of @maniumek/suwgate/eslint and delete what turns it off`;
|
|
64
|
+
}
|
|
65
|
+
const STRICT_PRESET = new URL("./presets/tsconfig/strict.json", import.meta.url);
|
|
66
|
+
function presetOptions() {
|
|
67
|
+
return JSON.parse(readFileSync(STRICT_PRESET, "utf8")).compilerOptions;
|
|
68
|
+
}
|
|
69
|
+
function stdin() {
|
|
70
|
+
try {
|
|
71
|
+
return readFileSync(0, "utf8");
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function format(value) {
|
|
78
|
+
return value === "vitest" || value === "playwright" || value === "xunit" ? value : null;
|
|
79
|
+
}
|
|
80
|
+
function judged(argv) {
|
|
81
|
+
const [command, first = "", ...rest] = argv;
|
|
82
|
+
switch (command) {
|
|
83
|
+
case "tests": {
|
|
84
|
+
const kind = format(first);
|
|
85
|
+
const [location, tool] = rest;
|
|
86
|
+
return kind === null || location === undefined || tool === undefined ? undefined : testsVerdict(kind, location, tool);
|
|
87
|
+
}
|
|
88
|
+
case "guards":
|
|
89
|
+
return guardsVerdict(first, rest);
|
|
90
|
+
case "tsconfig":
|
|
91
|
+
return tsconfigVerdict(first, stdin(), presetOptions());
|
|
92
|
+
case "eslint":
|
|
93
|
+
return eslintVerdict(first, stdin(), rest);
|
|
94
|
+
case "criteria": {
|
|
95
|
+
const [input] = rest;
|
|
96
|
+
if (input === undefined)
|
|
97
|
+
return undefined;
|
|
98
|
+
const problems = criteriaRan({ ...JSON.parse(input), run: first });
|
|
99
|
+
return problems.length === 0 ? null : problems.join("\n");
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function verdict(argv) {
|
|
106
|
+
let problem;
|
|
107
|
+
try {
|
|
108
|
+
problem = judged(argv);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
problem = `suwgate verdict ${argv.join(" ")}: ${error instanceof Error ? error.message : String(error)}`;
|
|
112
|
+
}
|
|
113
|
+
if (problem === undefined) {
|
|
114
|
+
return {
|
|
115
|
+
exitCode: 2,
|
|
116
|
+
text: "usage: suwgate verdict tests <vitest|playwright|xunit> <report> <tool> | guards <evidence-dir> <guard>... | tsconfig <file> | eslint <file> <rule>... | criteria <run-dir> <input-json>",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return problem === null ? { exitCode: 0, text: "" } : { exitCode: 1, text: problem };
|
|
120
|
+
}
|
package/dist/profiles/web.js
CHANGED
|
@@ -2,16 +2,32 @@ import { API_CONTRACT } from "./contract.js";
|
|
|
2
2
|
import { DATABASE_UP } from "./database.js";
|
|
3
3
|
import { DOTNET_BUILD, DOTNET_TEST } from "./dotnet.js";
|
|
4
4
|
import { PNPM_INSTALL } from "./node.js";
|
|
5
|
-
import { has } from "./shell.js";
|
|
5
|
+
import { CHECKOUT_ENV, countedPlaywright, has, hasDevSection, quoted, script, suwgate } from "./shell.js";
|
|
6
6
|
const E2E_CONFIG = "e2e/playwright.config.ts";
|
|
7
|
+
const PLAYWRIGHT = `pnpm exec playwright test -c ${E2E_CONFIG}`;
|
|
8
|
+
function e2e(context) {
|
|
9
|
+
if (!has(context, E2E_CONFIG))
|
|
10
|
+
return null;
|
|
11
|
+
if (!hasDevSection(context))
|
|
12
|
+
return script(["set -euo pipefail", ...countedPlaywright("e2e", PLAYWRIGHT)]);
|
|
13
|
+
return script([
|
|
14
|
+
"set -euo pipefail",
|
|
15
|
+
...CHECKOUT_ENV,
|
|
16
|
+
'case "$E2E_DATABASE" in *e2e*) ;; *) echo "E2E_DATABASE is \\"$E2E_DATABASE\\": the e2e step drops and recreates it, so its name must contain e2e; never point it at the development database" >&2; exit 2 ;; esac',
|
|
17
|
+
`${suwgate("dev db up")} >/dev/null`,
|
|
18
|
+
`${suwgate("dev db psql")} -q -d postgres -c "DROP DATABASE IF EXISTS $E2E_DATABASE WITH (FORCE)" -c "CREATE DATABASE $E2E_DATABASE"`,
|
|
19
|
+
`mkdir -p ${quoted(`${context.root}/.artifacts/logs`)}`,
|
|
20
|
+
...countedPlaywright("e2e", PLAYWRIGHT),
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
7
23
|
export const webSteps = [
|
|
8
24
|
{
|
|
9
25
|
id: "e2e",
|
|
10
|
-
title: `browser tests against the real server and database (playwright, ${E2E_CONFIG})`,
|
|
26
|
+
title: `browser tests against the real server and a fresh database of this checkout (playwright, ${E2E_CONFIG}; 0 tests run fails)`,
|
|
11
27
|
profile: "web",
|
|
12
28
|
needs: ["pnpm"],
|
|
13
29
|
after: [PNPM_INSTALL, DOTNET_BUILD, DATABASE_UP, DOTNET_TEST, API_CONTRACT],
|
|
14
|
-
run:
|
|
30
|
+
run: e2e,
|
|
15
31
|
limitSeconds: 600,
|
|
16
32
|
},
|
|
17
33
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maniumek/suwgate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "One quality gate for every repository: suwgate check runs the steps of the repository's profiles and its guards, configured in suwgate.yml",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Manomenu",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"provenance": true
|
|
94
94
|
},
|
|
95
95
|
"scripts": {
|
|
96
|
-
"build": "
|
|
96
|
+
"build": "tsc -p tsconfig.build.json && mkdir -p dist/profiles/presets/tsconfig && cp -r src/profiles/presets/tsconfig/. dist/profiles/presets/tsconfig/",
|
|
97
97
|
"changeset": "changeset",
|
|
98
98
|
"release": "pnpm run build && changeset publish"
|
|
99
99
|
}
|
|
@@ -23,6 +23,18 @@
|
|
|
23
23
|
"^": { "$ref": "#/$defs/relativePath" }
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"quick": {
|
|
27
|
+
"description": "The quick gate (suwgate check --quick).",
|
|
28
|
+
"type": "object",
|
|
29
|
+
"additionalProperties": false,
|
|
30
|
+
"properties": {
|
|
31
|
+
"limitSeconds": {
|
|
32
|
+
"type": "integer",
|
|
33
|
+
"minimum": 1,
|
|
34
|
+
"description": "The quick gate fails when it takes longer (default 20). SUWGATE_QUICK_LIMIT on a machine overrides it."
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
26
38
|
"steps": {
|
|
27
39
|
"type": "object",
|
|
28
40
|
"additionalProperties": false,
|
|
@@ -64,6 +76,25 @@
|
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
},
|
|
79
|
+
"guards": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"additionalProperties": false,
|
|
82
|
+
"properties": {
|
|
83
|
+
"skip": {
|
|
84
|
+
"description": "Whole guards that do not apply to this repository, each with its reason: repository guards, and the .NET guards (architecture/*, database/*) that SuwgateGuards.VerifyAll runs and the dotnet-test step asks evidence for.",
|
|
85
|
+
"type": "array",
|
|
86
|
+
"items": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"additionalProperties": false,
|
|
89
|
+
"required": ["guard", "reason"],
|
|
90
|
+
"properties": {
|
|
91
|
+
"guard": { "type": "string", "pattern": "^([a-z]+/)?[a-z][a-z0-9-]*$" },
|
|
92
|
+
"reason": { "$ref": "#/$defs/reason" }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
67
98
|
"exceptions": {
|
|
68
99
|
"description": "Exceptions from the guards: one target of one guard, each with its reason. suwgate check counts them.",
|
|
69
100
|
"type": "array",
|
|
@@ -184,7 +215,7 @@
|
|
|
184
215
|
"settings": {
|
|
185
216
|
"description": "Settings of a guard, by its id; the guard's own schema checks them.",
|
|
186
217
|
"type": "object",
|
|
187
|
-
"propertyNames": { "pattern": "^[a-z][a-z0-9-]*$" }
|
|
218
|
+
"propertyNames": { "pattern": "^([a-z]+/)?[a-z][a-z0-9-]*$" }
|
|
188
219
|
}
|
|
189
220
|
},
|
|
190
221
|
"$defs": {
|