@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
|
@@ -31,3 +31,41 @@ export function isRecord(value) {
|
|
|
31
31
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
32
|
}
|
|
33
33
|
export const stringList = { type: "array", uniqueItems: true, items: { type: "string", minLength: 1 } };
|
|
34
|
+
function withoutComments(text) {
|
|
35
|
+
let kept = "";
|
|
36
|
+
let index = 0;
|
|
37
|
+
let inString = false;
|
|
38
|
+
while (index < text.length) {
|
|
39
|
+
const character = text.charAt(index);
|
|
40
|
+
const next = text.charAt(index + 1);
|
|
41
|
+
if (inString) {
|
|
42
|
+
kept += character;
|
|
43
|
+
if (character === "\\") {
|
|
44
|
+
kept += next;
|
|
45
|
+
index += 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (character === '"')
|
|
49
|
+
inString = false;
|
|
50
|
+
index++;
|
|
51
|
+
}
|
|
52
|
+
else if (character === "/" && next === "/") {
|
|
53
|
+
while (index < text.length && text.charAt(index) !== "\n")
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
else if (character === "/" && next === "*") {
|
|
57
|
+
const end = text.indexOf("*/", index + 2);
|
|
58
|
+
index = end === -1 ? text.length : end + 2;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (character === '"')
|
|
62
|
+
inString = true;
|
|
63
|
+
kept += character;
|
|
64
|
+
index++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return kept;
|
|
68
|
+
}
|
|
69
|
+
export function parseJsonc(text) {
|
|
70
|
+
return parseJson(withoutComments(text).replace(/,(\s*[}\]])/g, "$1"));
|
|
71
|
+
}
|
|
@@ -21,7 +21,7 @@ function settingsFindings(text) {
|
|
|
21
21
|
.filter(isStyleKey)
|
|
22
22
|
.map((key) => ({
|
|
23
23
|
target: SETTINGS,
|
|
24
|
-
message: `${key} is a style rule only VS Code reads: move it to .editorconfig
|
|
24
|
+
message: `${key} is a style rule only VS Code reads: move it to .editorconfig (C# width: max_line_length) or the Prettier config so every editor and the gate use it`,
|
|
25
25
|
}));
|
|
26
26
|
}
|
|
27
27
|
function extensionFindings(text) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Step, StepContext } from "../gate/contract.ts";
|
|
2
|
+
export declare const API_TYPES = "src/api/openapi.d.ts";
|
|
2
3
|
export declare const API_CONTRACT = "api-contract";
|
|
3
4
|
export declare function apiContract(context: StepContext): string | null;
|
|
4
5
|
export declare function contractPins(context: StepContext): string | null;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { DOTNET_TEST } from "./dotnet.js";
|
|
3
|
+
import { DOTNET_TEST, NO_IDLE_BUILD_PROCESSES } from "./dotnet.js";
|
|
4
4
|
import { PNPM_INSTALL } from "./node.js";
|
|
5
5
|
import { has, quoted, read, script, tracked } from "./shell.js";
|
|
6
6
|
const CONTRACT = "contract/openapi.json";
|
|
7
7
|
const CONTRACT_VERSION = "contract/package.json";
|
|
8
|
-
const
|
|
8
|
+
export const API_TYPES = "src/api/openapi.d.ts";
|
|
9
9
|
export const API_CONTRACT = "api-contract";
|
|
10
10
|
const GENERATOR = "Microsoft.Extensions.ApiDescription.Server";
|
|
11
11
|
const TAGGED = ["*.cs", "*.test.ts", "*.test.tsx", "*.e2e.ts"];
|
|
@@ -19,7 +19,7 @@ function webApp(context) {
|
|
|
19
19
|
if (!context.profiles.includes("web"))
|
|
20
20
|
return null;
|
|
21
21
|
const directory = path.join(context.root, context.directories.web ?? "");
|
|
22
|
-
return existsSync(path.join(directory,
|
|
22
|
+
return existsSync(path.join(directory, API_TYPES)) ? directory : null;
|
|
23
23
|
}
|
|
24
24
|
export function apiContract(context) {
|
|
25
25
|
if (!has(context, CONTRACT))
|
|
@@ -33,8 +33,9 @@ export function apiContract(context) {
|
|
|
33
33
|
const name = path.basename(server, ".csproj");
|
|
34
34
|
const document = `"$work"/${quoted(`${name}.json`)}`;
|
|
35
35
|
const web = webApp(context);
|
|
36
|
-
const types = web === null ? "" : path.join(web,
|
|
36
|
+
const types = web === null ? "" : path.join(web, API_TYPES);
|
|
37
37
|
return script([
|
|
38
|
+
NO_IDLE_BUILD_PROCESSES,
|
|
38
39
|
'work="$(mktemp -d)"',
|
|
39
40
|
"trap 'rm -rf \"$work\"' EXIT",
|
|
40
41
|
`rm -f ${quoted(path.join(path.dirname(server), "obj", `${name}.OpenApiFiles.cache`))}`,
|
|
@@ -99,7 +100,7 @@ export function contractPins(context) {
|
|
|
99
100
|
export const contractSteps = [
|
|
100
101
|
{
|
|
101
102
|
id: API_CONTRACT,
|
|
102
|
-
title: `the API contract and the web app's types up to date with the server (${CONTRACT}, ${
|
|
103
|
+
title: `the API contract and the web app's types up to date with the server (${CONTRACT}, ${API_TYPES}, openapi-typescript)`,
|
|
103
104
|
profile: "dotnet",
|
|
104
105
|
needs: ["dotnet"],
|
|
105
106
|
after: [DOTNET_TEST, PNPM_INSTALL],
|
|
@@ -5,7 +5,7 @@ import { homedir } from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { CONSUMER, VISUAL_CONFIG } from "./library.js";
|
|
7
7
|
import { onPath, quoted, read, script, tracked } from "./shell.js";
|
|
8
|
-
const CRITERIA_FILE = "criteria.json";
|
|
8
|
+
export const CRITERIA_FILE = "criteria.json";
|
|
9
9
|
const VDOC = {
|
|
10
10
|
repository: "Manomenu/suwalski-agent-plugin",
|
|
11
11
|
commit: "02a5f3d98c5caa9f69af3fa0508efa566a6d78f2",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Step, StepContext } from "../gate/contract.ts";
|
|
2
|
+
import { type ReportFormat } from "./reports.ts";
|
|
3
|
+
interface TestSource {
|
|
4
|
+
step: string;
|
|
5
|
+
format: ReportFormat;
|
|
6
|
+
report: string;
|
|
7
|
+
patterns: string[];
|
|
8
|
+
skipped?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CriteriaRanInput {
|
|
11
|
+
root: string;
|
|
12
|
+
run: string;
|
|
13
|
+
specs: string[];
|
|
14
|
+
sources: TestSource[];
|
|
15
|
+
}
|
|
16
|
+
export declare function criterionIds(spec: string): string[];
|
|
17
|
+
export declare function names(text: string, id: string, format: ReportFormat): boolean;
|
|
18
|
+
export declare function criteriaRan(input: CriteriaRanInput): string[];
|
|
19
|
+
export declare function criteriaRanInput(context: StepContext): Omit<CriteriaRanInput, "run"> | null;
|
|
20
|
+
export declare const criteriaRanStep: Step;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { CRITERIA_FILE, criteriaConfig } from "./criteria.js";
|
|
5
|
+
import { readRun } from "./reports.js";
|
|
6
|
+
import { quoted, read, tracked, verdictCommand } from "./shell.js";
|
|
7
|
+
const REPORTED = {
|
|
8
|
+
"test (xunit)": { step: "dotnet-test", format: "xunit" },
|
|
9
|
+
"web test (vitest)": { step: "unit-tests", format: "vitest" },
|
|
10
|
+
"unit test (vitest)": { step: "unit-tests", format: "vitest" },
|
|
11
|
+
"story test (vitest, Chromium)": { step: "stories", format: "vitest" },
|
|
12
|
+
"e2e test (playwright)": { step: "e2e", format: "playwright" },
|
|
13
|
+
"visual test (playwright)": { step: "visual", format: "playwright" },
|
|
14
|
+
"consumer test (playwright)": { step: "consumer-app", format: "playwright" },
|
|
15
|
+
};
|
|
16
|
+
const REPORT_FILE = { vitest: "vitest.json", playwright: "playwright.json", xunit: "results" };
|
|
17
|
+
const ACCEPTANCE = /data-role="acceptance"[\s\S]*?(?=data-role="|$)/g;
|
|
18
|
+
const CODE = /<code>([A-Za-z][\w.]*(?:-[\w.]+)*-\d+)<\/code>/g;
|
|
19
|
+
export function criterionIds(spec) {
|
|
20
|
+
return [...new Set([...spec.matchAll(ACCEPTANCE)].flatMap((section) => [...section[0].matchAll(CODE)].map((code) => code[1] ?? "")))];
|
|
21
|
+
}
|
|
22
|
+
export function names(text, id, format) {
|
|
23
|
+
if (format === "xunit")
|
|
24
|
+
return new RegExp(`Trait\\(\\s*"criterion"\\s*,\\s*"${id.replace(/[.]/g, "\\.")}"\\s*\\)`).test(text);
|
|
25
|
+
return ['"', "'", "`"].some((quote) => text.includes(`${quote}${id}:`));
|
|
26
|
+
}
|
|
27
|
+
function proven(passed, id) {
|
|
28
|
+
return passed.some((title) => title.startsWith(`${id}:`) || title.includes(` ${id}:`));
|
|
29
|
+
}
|
|
30
|
+
function listed(root, patterns) {
|
|
31
|
+
if (patterns.length === 0)
|
|
32
|
+
return [];
|
|
33
|
+
try {
|
|
34
|
+
return execFileSync("git", ["ls-files", "--cached", "--others", "--exclude-standard", "-z", "--", ...patterns.map((p) => `:(glob)${p}`)], {
|
|
35
|
+
cwd: root,
|
|
36
|
+
encoding: "utf8",
|
|
37
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
38
|
+
})
|
|
39
|
+
.split("\0")
|
|
40
|
+
.filter((file) => file !== "");
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function criteriaRan(input) {
|
|
47
|
+
const ids = [...new Set(input.specs.flatMap((spec) => criterionIds(readFileSync(path.join(input.root, spec), "utf8"))))];
|
|
48
|
+
const runs = new Map(input.sources.map((source) => [
|
|
49
|
+
source.step,
|
|
50
|
+
source.skipped === undefined ? readRun(source.format, path.join(input.run, source.report)) : null,
|
|
51
|
+
]));
|
|
52
|
+
const texts = input.sources.map((source) => ({
|
|
53
|
+
source,
|
|
54
|
+
files: listed(input.root, source.patterns).map((file) => ({ file, text: readFileSync(path.join(input.root, file), "utf8") })),
|
|
55
|
+
}));
|
|
56
|
+
return ids.flatMap((id) => {
|
|
57
|
+
const naming = texts.flatMap(({ source, files }) => files.filter((file) => names(file.text, id, source.format)).map((file) => ({ source, file: file.file })));
|
|
58
|
+
const checked = naming.filter((entry) => entry.source.skipped === undefined);
|
|
59
|
+
if (checked.length === 0)
|
|
60
|
+
return [];
|
|
61
|
+
if (checked.some((entry) => proven(runs.get(entry.source.step)?.passed ?? [], id)))
|
|
62
|
+
return [];
|
|
63
|
+
const unreported = [...new Set(checked.filter((entry) => runs.get(entry.source.step) === null).map((entry) => entry.source.step))];
|
|
64
|
+
const why = unreported.length > 0 ? `${unreported.join(", ")} wrote no report` : "skipped, filtered out, or failed";
|
|
65
|
+
return [
|
|
66
|
+
`${id}: named by ${checked.map((entry) => `${entry.file} (${entry.source.step})`).join(", ")}, but no test naming it ran and passed in this gate run (${why}): make that test run and pass, or skip its step in suwgate.yml (steps.skip) with a reason`,
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function specsFolder(context) {
|
|
71
|
+
const text = read({ ...context, cwd: context.root }, CRITERIA_FILE);
|
|
72
|
+
try {
|
|
73
|
+
const parsed = text === null ? {} : JSON.parse(text);
|
|
74
|
+
return typeof parsed.specs === "string" ? parsed.specs : "docs/visual/spec";
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return "docs/visual/spec";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export function criteriaRanInput(context) {
|
|
81
|
+
const root = { ...context, cwd: context.root };
|
|
82
|
+
const specs = tracked(root, [`${specsFolder(context)}/*.html`]);
|
|
83
|
+
if (specs.length === 0)
|
|
84
|
+
return null;
|
|
85
|
+
const sources = criteriaConfig(context, {}).kinds.flatMap((kind) => {
|
|
86
|
+
const reported = REPORTED[kind.kind];
|
|
87
|
+
if (reported === undefined)
|
|
88
|
+
return [];
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
...reported,
|
|
92
|
+
report: path.posix.join(reported.step, REPORT_FILE[reported.format]),
|
|
93
|
+
patterns: kind.paths,
|
|
94
|
+
...(context.skippedSteps.includes(reported.step) ? { skipped: "skipped in suwgate.yml" } : {}),
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
});
|
|
98
|
+
return { root: context.root, specs, sources };
|
|
99
|
+
}
|
|
100
|
+
export const criteriaRanStep = {
|
|
101
|
+
id: "criteria-ran",
|
|
102
|
+
title: "every acceptance criterion a test names ran and passed in this gate run (the test tools' reports)",
|
|
103
|
+
after: ["unit-tests", "stories", "e2e", "visual", "consumer-app", "dotnet-test"],
|
|
104
|
+
run: (context) => {
|
|
105
|
+
const input = criteriaRanInput(context);
|
|
106
|
+
return input === null ? null : verdictCommand(`criteria "\${SUWGATE_RUN:-/no-run-folder}" ${quoted(JSON.stringify(input))}`);
|
|
107
|
+
},
|
|
108
|
+
limitSeconds: 60,
|
|
109
|
+
};
|
|
@@ -2,7 +2,7 @@ import { has, script } from "./shell.js";
|
|
|
2
2
|
export const DATABASE_UP = "database-up";
|
|
3
3
|
const COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
4
4
|
const UP = script([
|
|
5
|
-
'if [ -n "${CI:-}" ]; then echo "CI: the workflow
|
|
5
|
+
'if [ -n "${CI:-}" ]; then echo "CI: the workflow starts the database (database: true of the reusable gate workflow)"; exit 0; fi',
|
|
6
6
|
"docker compose --profile db up -d --wait db >/dev/null 2>&1 || {",
|
|
7
7
|
' echo "postgres did not start — see: docker compose --profile db logs db" >&2',
|
|
8
8
|
" exit 1",
|
|
@@ -14,7 +14,7 @@ export function composeFile(context) {
|
|
|
14
14
|
export const databaseSteps = [
|
|
15
15
|
{
|
|
16
16
|
id: DATABASE_UP,
|
|
17
|
-
title: "the local database for the tests (docker compose --profile db up --wait db; CI
|
|
17
|
+
title: "the local database for the tests (docker compose --profile db up --wait db; in CI the workflow starts it)",
|
|
18
18
|
profile: "database",
|
|
19
19
|
needs: ["docker"],
|
|
20
20
|
run: (context) => (composeFile(context) ? UP : null),
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Step, StepContext } from "../gate/contract.ts";
|
|
2
|
+
export declare const NO_IDLE_BUILD_PROCESSES = "export MSBUILDDISABLENODEREUSE=1 DOTNET_CLI_USE_MSBUILD_SERVER=0";
|
|
2
3
|
export declare const DOTNET_BUILD = "dotnet-build";
|
|
3
4
|
export declare const DOTNET_TEST = "dotnet-test";
|
|
5
|
+
export declare function inCheckoutEnv(context: StepContext, command: string): string;
|
|
4
6
|
export declare function guardTests(context: StepContext): string | null;
|
|
7
|
+
export declare function witnessed(context: StepContext, tests: string): string;
|
|
5
8
|
export declare const dotnetSteps: readonly Step[];
|
package/dist/profiles/dotnet.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { DATABASE_UP } from "./database.js";
|
|
2
|
-
import {
|
|
2
|
+
import { requiredGuards } from "./dotnetGuards.js";
|
|
3
|
+
import { CHECKOUT_ENV, changedIn, hasDevSection, quoted, read, runDirectory, tracked, verdictCommand, withChanged } from "./shell.js";
|
|
3
4
|
const DOTNET_INPUT = /\.(cs|csproj|props|targets|slnx|sln|rsp)$|(^|\/)(\.editorconfig|BannedSymbols\.txt|global\.json|packages\.lock\.json|nuget\.config)$/;
|
|
4
|
-
const GUARD_PACKAGE = /<(PackageReference|ProjectReference)\b[^>]*Include="[^"]*Suwgate\.(Architecture|Database)\b/;
|
|
5
|
+
const GUARD_PACKAGE = /<(PackageReference|ProjectReference)\b[^>]*(?:Include|Update)="[^"]*Suwgate\.(Architecture|Database)\b/;
|
|
5
6
|
const TEST_PROJECT = /<PackageReference\b[^>]*Include="xunit\.v3"|<IsTestProject>true<\/IsTestProject>/;
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
export const NO_IDLE_BUILD_PROCESSES = "export MSBUILDDISABLENODEREUSE=1 DOTNET_CLI_USE_MSBUILD_SERVER=0";
|
|
8
|
+
const BUILD = `${NO_IDLE_BUILD_PROCESSES} && dotnet build --nologo -v quiet`;
|
|
9
|
+
const TEST_OPTIONS = '--no-build --no-progress --zero-tests-policy strict --report-xunit-xml --results-directory "$run/results"';
|
|
10
|
+
const FORMAT = `${NO_IDLE_BUILD_PROCESSES} && dotnet tool restore >/dev/null`;
|
|
8
11
|
export const DOTNET_BUILD = "dotnet-build";
|
|
9
12
|
export const DOTNET_TEST = "dotnet-test";
|
|
10
13
|
function dotnetChanged(context) {
|
|
11
14
|
return changedIn(context, DOTNET_INPUT).length > 0;
|
|
12
15
|
}
|
|
16
|
+
export function inCheckoutEnv(context, command) {
|
|
17
|
+
if (!hasDevSection(context))
|
|
18
|
+
return `${NO_IDLE_BUILD_PROCESSES} && ${command}`;
|
|
19
|
+
return [...CHECKOUT_ENV, command].join(" && ");
|
|
20
|
+
}
|
|
13
21
|
export function guardTests(context) {
|
|
14
22
|
if (!dotnetChanged(context))
|
|
15
23
|
return null;
|
|
@@ -19,7 +27,16 @@ export function guardTests(context) {
|
|
|
19
27
|
});
|
|
20
28
|
if (projects.length === 0)
|
|
21
29
|
return null;
|
|
22
|
-
return projects.map((project) => `dotnet test --project ${quoted(project)}
|
|
30
|
+
return projects.map((project) => `dotnet test --project ${quoted(project)} ${TEST_OPTIONS}`).join(" && ");
|
|
31
|
+
}
|
|
32
|
+
export function witnessed(context, tests) {
|
|
33
|
+
return [
|
|
34
|
+
runDirectory(DOTNET_TEST),
|
|
35
|
+
'export SUWGATE_EVIDENCE="$run/evidence"',
|
|
36
|
+
tests,
|
|
37
|
+
verdictCommand(`tests xunit "$run/results" ${quoted("dotnet test")}`),
|
|
38
|
+
verdictCommand(`guards "$run/evidence" ${requiredGuards(context).map(quoted).join(" ")}`),
|
|
39
|
+
].join(" && ");
|
|
23
40
|
}
|
|
24
41
|
export const dotnetSteps = [
|
|
25
42
|
{
|
|
@@ -36,21 +53,24 @@ export const dotnetSteps = [
|
|
|
36
53
|
title: "format C# (csharpier check)",
|
|
37
54
|
profile: "dotnet",
|
|
38
55
|
needs: ["dotnet"],
|
|
39
|
-
run:
|
|
56
|
+
run: `${FORMAT} && dotnet csharpier check .`,
|
|
40
57
|
quick: (context) => {
|
|
41
58
|
const command = withChanged(context, /\.cs$/, "dotnet csharpier check");
|
|
42
|
-
return command === null ? null :
|
|
59
|
+
return command === null ? null : `${FORMAT} && ${command}`;
|
|
43
60
|
},
|
|
44
61
|
limitSeconds: 120,
|
|
45
62
|
},
|
|
46
63
|
{
|
|
47
64
|
id: DOTNET_TEST,
|
|
48
|
-
title: "tests (dotnet test, xUnit v3; --quick: the projects that test with Suwgate.Architecture or Suwgate.Database)",
|
|
65
|
+
title: "tests (dotnet test, xUnit v3, with the checkout's databases when suwgate.yml has dev; fails on 0 tests run and unless every .NET guard of the profiles ran; --quick: the projects that test with Suwgate.Architecture or Suwgate.Database)",
|
|
49
66
|
profile: "dotnet",
|
|
50
67
|
needs: ["dotnet"],
|
|
51
68
|
after: [DOTNET_BUILD, DATABASE_UP],
|
|
52
|
-
run:
|
|
53
|
-
quick:
|
|
69
|
+
run: (context) => inCheckoutEnv(context, witnessed(context, `dotnet test ${TEST_OPTIONS}`)),
|
|
70
|
+
quick: (context) => {
|
|
71
|
+
const command = guardTests(context);
|
|
72
|
+
return command === null ? null : inCheckoutEnv(context, witnessed(context, command));
|
|
73
|
+
},
|
|
54
74
|
limitSeconds: 600,
|
|
55
75
|
},
|
|
56
76
|
];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const ARCHITECTURE = [
|
|
2
|
+
"layers",
|
|
3
|
+
"endpoints",
|
|
4
|
+
"project-references",
|
|
5
|
+
"every-project-guarded",
|
|
6
|
+
"interfaces-have-two-implementations",
|
|
7
|
+
"nothing-obsolete",
|
|
8
|
+
"no-unused-types",
|
|
9
|
+
"forbidden-type-names",
|
|
10
|
+
"unique-type-names",
|
|
11
|
+
"one-type-per-file",
|
|
12
|
+
"no-escape-hatches",
|
|
13
|
+
"no-fixture-in-field",
|
|
14
|
+
"build-settings",
|
|
15
|
+
];
|
|
16
|
+
export const dotnetGuards = [
|
|
17
|
+
...ARCHITECTURE.map((name) => ({ id: `architecture/${name}`, profile: "dotnet" })),
|
|
18
|
+
{
|
|
19
|
+
id: "database/migration-script-names",
|
|
20
|
+
profile: "database",
|
|
21
|
+
settingsSchema: {
|
|
22
|
+
type: "object",
|
|
23
|
+
additionalProperties: false,
|
|
24
|
+
properties: {
|
|
25
|
+
directory: {
|
|
26
|
+
type: "string",
|
|
27
|
+
pattern: "^[^/\\\\][^\\\\]*$",
|
|
28
|
+
description: "The folder of the NNNN_what_it_does.sql scripts, when it is not the one Migrations/up folder.",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
export function requiredGuards(context) {
|
|
35
|
+
return dotnetGuards
|
|
36
|
+
.filter((guard) => context.profiles.includes(guard.profile) && !context.skippedGuards.includes(guard.id))
|
|
37
|
+
.map((guard) => guard.id);
|
|
38
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { criteriaStep } from "./criteria.js";
|
|
2
|
+
import { criteriaRanStep } from "./criteriaRan.js";
|
|
2
3
|
import { composeFile } from "./database.js";
|
|
3
4
|
import { withChanged } from "./shell.js";
|
|
4
5
|
const SHELL_SCRIPT = /\.sh$|^\.githooks\/[^/]+$/;
|
|
@@ -11,6 +12,7 @@ export const everyRepositorySteps = [
|
|
|
11
12
|
limitSeconds: 120,
|
|
12
13
|
},
|
|
13
14
|
criteriaStep,
|
|
15
|
+
criteriaRanStep,
|
|
14
16
|
{
|
|
15
17
|
id: "shellcheck",
|
|
16
18
|
title: "shell scripts (shellcheck)",
|
package/dist/profiles/index.d.ts
CHANGED
package/dist/profiles/index.js
CHANGED
|
@@ -6,6 +6,8 @@ import { everyRepositorySteps } from "./everyRepository.js";
|
|
|
6
6
|
import { librarySteps } from "./library.js";
|
|
7
7
|
import { nodeSteps } from "./node.js";
|
|
8
8
|
import { webSteps } from "./web.js";
|
|
9
|
+
export { dotnetGuards } from "./dotnetGuards.js";
|
|
10
|
+
export { verdict } from "./verdict.js";
|
|
9
11
|
const BY_PROFILE = {
|
|
10
12
|
web: [...nodeSteps("web"), ...webSteps, ...contractSteps],
|
|
11
13
|
library: [...nodeSteps("library"), ...librarySteps],
|
package/dist/profiles/library.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PNPM_INSTALL } from "./node.js";
|
|
2
|
-
import { has, quoted, read, script } from "./shell.js";
|
|
2
|
+
import { countedPlaywright, countedVitest, has, quoted, read, runDirectory, script, verdictCommand } from "./shell.js";
|
|
3
3
|
const CHANGESET = script([
|
|
4
4
|
'base=""',
|
|
5
5
|
"if git rev-parse --verify -q origin/master >/dev/null; then base=origin/master; elif git rev-parse --verify -q master >/dev/null; then base=master; fi",
|
|
@@ -24,11 +24,11 @@ function consumerAppCommand(build) {
|
|
|
24
24
|
`cp -r ${CONSUMER}/app "$work/app"`,
|
|
25
25
|
`(cd "$work/app" && pnpm add "$tarball" --silent && ${build})`,
|
|
26
26
|
`port="$(node -e 'const server = require("node:net").createServer().listen(0, "127.0.0.1", () => { console.log(server.address().port); server.close(); });')"`,
|
|
27
|
-
`CONSUMER_APP="$work/app" CONSUMER_PORT="$port" pnpm exec playwright test -c ${CONSUMER}/playwright.config.ts
|
|
27
|
+
countedPlaywright("consumer-app", `CONSUMER_APP="$work/app" CONSUMER_PORT="$port" pnpm exec playwright test -c ${CONSUMER}/playwright.config.ts`).join(" && "),
|
|
28
28
|
]);
|
|
29
29
|
}
|
|
30
30
|
function stories(context) {
|
|
31
|
-
return has(context, STORYBOOK) ? "pnpm exec vitest run --project stories" : null;
|
|
31
|
+
return has(context, STORYBOOK) ? countedVitest("stories", "pnpm exec vitest run --project stories") : null;
|
|
32
32
|
}
|
|
33
33
|
function playwrightVersion(context) {
|
|
34
34
|
const manifest = read(context, "node_modules/@playwright/test/package.json");
|
|
@@ -44,10 +44,12 @@ export function visual(context) {
|
|
|
44
44
|
if (version === null) {
|
|
45
45
|
return `echo "${VISUAL_CONFIG} runs in the Playwright image of the installed @playwright/test, which is not installed: pnpm add -D @playwright/test" >&2; exit 1`;
|
|
46
46
|
}
|
|
47
|
-
return
|
|
47
|
+
return [
|
|
48
48
|
"pnpm exec storybook build --quiet -o storybook-static >/dev/null",
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
runDirectory("visual"),
|
|
50
|
+
`docker run --rm --init --ipc=host --security-opt label=disable -v "$PWD:/work" -v "$run:/suwgate-run" -w /work -e CI -e PLAYWRIGHT_JSON_OUTPUT_FILE=/suwgate-run/playwright.json mcr.microsoft.com/playwright:v${version}-noble node_modules/.bin/playwright test -c ${VISUAL_CONFIG} --reporter=line,json`,
|
|
51
|
+
verdictCommand(`tests playwright "$run/playwright.json" ${quoted("playwright (visual)")}`),
|
|
52
|
+
].join(" && ");
|
|
51
53
|
}
|
|
52
54
|
const NOT_A_MODULE = /\.(css|json)$/;
|
|
53
55
|
function targets(entry) {
|
|
@@ -77,7 +79,7 @@ const after = [PNPM_INSTALL];
|
|
|
77
79
|
export const librarySteps = [
|
|
78
80
|
{
|
|
79
81
|
id: "stories",
|
|
80
|
-
title: "stories as tests with axe (vitest project stories, Chromium)",
|
|
82
|
+
title: "stories as tests with axe (vitest project stories, Chromium; 0 tests run fails)",
|
|
81
83
|
profile: "library",
|
|
82
84
|
needs: ["pnpm"],
|
|
83
85
|
after,
|
package/dist/profiles/node.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { changedIn, filesIn, has, read, withChanged } from "./shell.js";
|
|
1
|
+
import { changedIn, countedVitest, filesIn, has, quoted, read, tracked, verdictCommand, withChanged } from "./shell.js";
|
|
2
2
|
const CODE = /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
|
|
3
3
|
const TSCONFIG = /^tsconfig(\..+)?\.json$/;
|
|
4
4
|
const VITEST_CONFIG = /^vitest\.config\.(ts|mts|js|mjs)$/;
|
|
5
5
|
const UNIT_PROJECT = /\bname:\s*["'`]unit["'`]|\bunitTests\(/;
|
|
6
|
+
const NOT_A_SOURCE = /\.(test|stories|e2e|visual|spec)\.[cm]?[jt]sx?$|\.d\.ts$/;
|
|
7
|
+
const ENFORCED_RULES = ["suwgate/no-comments", "boundaries/dependencies"];
|
|
6
8
|
export const PNPM_INSTALL = "pnpm-install";
|
|
7
9
|
function install(context) {
|
|
8
10
|
return has(context, "node_modules") ? null : "pnpm install --frozen-lockfile --silent";
|
|
@@ -10,11 +12,22 @@ function install(context) {
|
|
|
10
12
|
export function typecheck(context) {
|
|
11
13
|
const configs = filesIn(context, TSCONFIG).filter((file) => file !== "tsconfig.build.json");
|
|
12
14
|
const ordered = [...configs.filter((file) => file === "tsconfig.json"), ...configs.filter((file) => file !== "tsconfig.json")];
|
|
13
|
-
return (ordered.length === 0 ? ["tsconfig.json"] : ordered)
|
|
15
|
+
return (ordered.length === 0 ? ["tsconfig.json"] : ordered)
|
|
16
|
+
.map((file) => `pnpm exec tsc --noEmit -p ${file} && pnpm exec tsc --showConfig -p ${file} | ${verdictCommand(`tsconfig ${quoted(file)}`)}`)
|
|
17
|
+
.join(" && ");
|
|
18
|
+
}
|
|
19
|
+
function lint(context) {
|
|
20
|
+
const source = tracked(context, ["src/*.ts", "src/*.tsx"]).find((file) => !NOT_A_SOURCE.test(file));
|
|
21
|
+
const rules = source === undefined
|
|
22
|
+
? []
|
|
23
|
+
: [
|
|
24
|
+
`pnpm exec eslint --print-config ${quoted(source)} | ${verdictCommand(`eslint ${quoted(source)} ${ENFORCED_RULES.join(" ")}`)}`,
|
|
25
|
+
];
|
|
26
|
+
return [...rules, "pnpm exec eslint . --max-warnings 0"].join(" && ");
|
|
14
27
|
}
|
|
15
28
|
export function unitTests(context) {
|
|
16
29
|
const named = filesIn(context, VITEST_CONFIG).some((file) => UNIT_PROJECT.test(read(context, file) ?? ""));
|
|
17
|
-
return named ? "pnpm exec vitest run --project unit" : "pnpm exec vitest run";
|
|
30
|
+
return countedVitest("unit-tests", named ? "pnpm exec vitest run --project unit" : "pnpm exec vitest run");
|
|
18
31
|
}
|
|
19
32
|
export function nodeSteps(profile) {
|
|
20
33
|
const after = [PNPM_INSTALL];
|
|
@@ -30,7 +43,7 @@ export function nodeSteps(profile) {
|
|
|
30
43
|
},
|
|
31
44
|
{
|
|
32
45
|
id: "typecheck",
|
|
33
|
-
title: "typecheck (tsc, every tsconfig*.json but the build one)",
|
|
46
|
+
title: "typecheck (tsc, every tsconfig*.json but the build one; tsc --showConfig keeps the strict options of the preset on)",
|
|
34
47
|
profile,
|
|
35
48
|
needs: ["pnpm"],
|
|
36
49
|
after,
|
|
@@ -40,17 +53,17 @@ export function nodeSteps(profile) {
|
|
|
40
53
|
},
|
|
41
54
|
{
|
|
42
55
|
id: "lint",
|
|
43
|
-
title: "lint (eslint)",
|
|
56
|
+
title: "lint (eslint; eslint --print-config of a source file keeps no-comments and boundaries at error)",
|
|
44
57
|
profile,
|
|
45
58
|
needs: ["pnpm"],
|
|
46
59
|
after,
|
|
47
|
-
run:
|
|
60
|
+
run: lint,
|
|
48
61
|
quick: (context) => withChanged(context, CODE, "pnpm exec eslint --no-warn-ignored --max-warnings 0"),
|
|
49
62
|
limitSeconds: 300,
|
|
50
63
|
},
|
|
51
64
|
{
|
|
52
65
|
id: "unit-tests",
|
|
53
|
-
title: "unit tests (vitest, the project unit when the config has several)",
|
|
66
|
+
title: "unit tests (vitest, the project unit when the config has several; 0 tests run fails)",
|
|
54
67
|
profile,
|
|
55
68
|
needs: ["pnpm"],
|
|
56
69
|
after,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type ReportFormat = "vitest" | "playwright" | "xunit";
|
|
2
|
+
export interface TestRun {
|
|
3
|
+
executed: number;
|
|
4
|
+
passed: string[];
|
|
5
|
+
}
|
|
6
|
+
interface VitestAssertion {
|
|
7
|
+
fullName?: string;
|
|
8
|
+
status?: string;
|
|
9
|
+
}
|
|
10
|
+
interface VitestReport {
|
|
11
|
+
testResults?: {
|
|
12
|
+
assertionResults?: VitestAssertion[];
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
interface PlaywrightSpec {
|
|
16
|
+
title?: string;
|
|
17
|
+
tests?: {
|
|
18
|
+
status?: string;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
interface PlaywrightSuite {
|
|
22
|
+
title?: string;
|
|
23
|
+
file?: string;
|
|
24
|
+
specs?: PlaywrightSpec[];
|
|
25
|
+
suites?: PlaywrightSuite[];
|
|
26
|
+
}
|
|
27
|
+
interface PlaywrightReport {
|
|
28
|
+
suites?: PlaywrightSuite[];
|
|
29
|
+
}
|
|
30
|
+
export declare function vitestRun(report: VitestReport): TestRun;
|
|
31
|
+
export declare function playwrightRun(report: PlaywrightReport): TestRun;
|
|
32
|
+
export declare function xunitRun(xml: string): TestRun;
|
|
33
|
+
export declare function files(location: string, extension: string): string[];
|
|
34
|
+
export declare function readRun(format: ReportFormat, location: string): TestRun | null;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const XUNIT_TEST = /<test\b([^>]*?)(?:\/>|>([\s\S]*?)<\/test>)/g;
|
|
4
|
+
const CRITERION_TRAIT = /<trait\s+name="criterion"\s+value="([^"]*)"/g;
|
|
5
|
+
export function vitestRun(report) {
|
|
6
|
+
const assertions = (report.testResults ?? []).flatMap((file) => file.assertionResults ?? []);
|
|
7
|
+
return {
|
|
8
|
+
executed: assertions.filter((assertion) => assertion.status === "passed" || assertion.status === "failed").length,
|
|
9
|
+
passed: assertions.filter((assertion) => assertion.status === "passed").map((assertion) => assertion.fullName ?? ""),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function specsOf(suite, titles) {
|
|
13
|
+
const own = suite.file === undefined || suite.title !== suite.file ? [...titles, suite.title ?? ""] : titles;
|
|
14
|
+
return [
|
|
15
|
+
...(suite.specs ?? []).map((spec) => ({
|
|
16
|
+
title: [...own, spec.title ?? ""].filter((title) => title !== "").join(" "),
|
|
17
|
+
statuses: (spec.tests ?? []).map((test) => test.status ?? ""),
|
|
18
|
+
})),
|
|
19
|
+
...(suite.suites ?? []).flatMap((inner) => specsOf(inner, own)),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
export function playwrightRun(report) {
|
|
23
|
+
const specs = (report.suites ?? []).flatMap((suite) => specsOf(suite, []));
|
|
24
|
+
return {
|
|
25
|
+
executed: specs.filter((spec) => spec.statuses.some((status) => status !== "skipped")).length,
|
|
26
|
+
passed: specs
|
|
27
|
+
.filter((spec) => spec.statuses.length > 0 && spec.statuses.every((status) => status === "expected" || status === "flaky"))
|
|
28
|
+
.map((spec) => spec.title),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function xunitRun(xml) {
|
|
32
|
+
const tests = [...xml.matchAll(XUNIT_TEST)].map((match) => ({
|
|
33
|
+
result: /\bresult="([^"]*)"/.exec(match[1] ?? "")?.[1] ?? "",
|
|
34
|
+
criteria: [...(match[2] ?? "").matchAll(CRITERION_TRAIT)].map((trait) => trait[1] ?? ""),
|
|
35
|
+
}));
|
|
36
|
+
return {
|
|
37
|
+
executed: tests.filter((test) => test.result === "Pass" || test.result === "Fail").length,
|
|
38
|
+
passed: tests.filter((test) => test.result === "Pass").flatMap((test) => test.criteria.map((id) => `${id}:`)),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function files(location, extension) {
|
|
42
|
+
if (!existsSync(location))
|
|
43
|
+
return [];
|
|
44
|
+
return readdirSync(location)
|
|
45
|
+
.filter((file) => file.endsWith(extension))
|
|
46
|
+
.map((file) => path.join(location, file));
|
|
47
|
+
}
|
|
48
|
+
export function readRun(format, location) {
|
|
49
|
+
if (format === "xunit") {
|
|
50
|
+
const reports = files(location, ".xml");
|
|
51
|
+
if (reports.length === 0)
|
|
52
|
+
return null;
|
|
53
|
+
const runs = reports.map((report) => xunitRun(readFileSync(report, "utf8")));
|
|
54
|
+
return { executed: runs.reduce((sum, run) => sum + run.executed, 0), passed: runs.flatMap((run) => run.passed) };
|
|
55
|
+
}
|
|
56
|
+
if (!existsSync(location))
|
|
57
|
+
return null;
|
|
58
|
+
const report = JSON.parse(readFileSync(location, "utf8"));
|
|
59
|
+
return format === "vitest" ? vitestRun(report) : playwrightRun(report);
|
|
60
|
+
}
|