@maniumek/suwgate 0.2.0 → 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 +43 -7
- package/dist/cli.js +11 -2
- package/dist/gate/check.js +5 -1
- package/dist/gate/config.d.ts +7 -1
- package/dist/gate/config.js +32 -2
- package/dist/gate/contract.d.ts +7 -0
- package/dist/gate/plan.js +7 -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/index.js +2 -0
- package/dist/guards/repository/suwfrontkitWiring.d.ts +2 -0
- package/dist/guards/repository/suwfrontkitWiring.js +52 -0
- 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/dotnet.d.ts +1 -0
- package/dist/profiles/dotnet.js +16 -6
- 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 +4 -0
- package/dist/profiles/shell.js +20 -0
- package/dist/profiles/verdict.d.ts +9 -0
- package/dist/profiles/verdict.js +120 -0
- package/dist/profiles/web.js +4 -4
- package/package.json +2 -2
- package/schema/suwgate.schema.json +20 -1
package/README.md
CHANGED
|
@@ -38,6 +38,9 @@ exceptions:
|
|
|
38
38
|
across the board overrides it with `SUWGATE_QUICK_LIMIT=<seconds>`.
|
|
39
39
|
- `exceptions` let one target through one guard, always with a `reason`; `suwgate check` counts them in its report, and an
|
|
40
40
|
exception that no longer matches anything fails the gate until it is deleted.
|
|
41
|
+
- `guards.skip` turns one whole guard off, always with a `reason`: a repository guard, or a .NET guard (`architecture/*`,
|
|
42
|
+
`database/*`), which `SuwgateGuards.VerifyAll` then does not run and the `dotnet-test` step does not ask evidence for. A
|
|
43
|
+
library, for example: `guards: { skip: [{ guard: architecture/endpoints, reason: a library has no server }] }`.
|
|
41
44
|
- The schema is in the package, `schema/suwgate.schema.json`. VS Code checks the file as you type with
|
|
42
45
|
`"yaml.schemas": { "./node_modules/@maniumek/suwgate/schema/suwgate.schema.json": "suwgate.yml" }` in `.vscode/settings.json`.
|
|
43
46
|
- `settings` configure a guard by its id, for example `dependency-direction: { applications: [Myapp.*] }`,
|
|
@@ -89,10 +92,10 @@ Each step looks where its profile lives (`directories`) and passes with nothing
|
|
|
89
92
|
|
|
90
93
|
| Profile | Steps |
|
|
91
94
|
| :--------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
|
-
| `web`, `library` | `pnpm-install` (only without `node_modules`), `typecheck` (every `tsconfig*.json` but `tsconfig.build.json`), `lint
|
|
95
|
+
| `web`, `library` | `pnpm-install` (only without `node_modules`), `typecheck` (every `tsconfig*.json` but `tsconfig.build.json`, with `tsc --showConfig`), `lint` (with `eslint --print-config`), `unit-tests` (the Vitest project `unit` when the config names one; 0 tests fail), `format`, `knip` |
|
|
93
96
|
| `web` | `e2e`: `playwright test -c e2e/playwright.config.ts`, after the build, the database and the .NET tests; with a `dev` section, first the checkout's variables (`suwgate dev checkout-env`) and a fresh, empty `E2E_DATABASE` (`dev db up`, then drop and create it); Playwright's `webServer` starts and stops the server and the web app |
|
|
94
97
|
| `library` | `stories` (with `.storybook/`), `publint`, `attw`, `consumer-app` (packs the library into a copy of `gate/consumer/app`, builds it, runs `gate/consumer/playwright.config.ts`), `visual` (`visual/playwright.config.ts` in the Playwright image of the installed `@playwright/test`), `changeset` |
|
|
95
|
-
| `dotnet` | `dotnet-build`, `dotnet-format`, `dotnet-test` (with a `dev` section, under the checkout's variables, so two worktrees never share a test database; `--quick`: only the test projects that use `Suwgate.Architecture` or `Suwgate.Database`); every .NET step leaves no idle MSBuild worker or build server behind
|
|
98
|
+
| `dotnet` | `dotnet-build`, `dotnet-format`, `dotnet-test` (fails on 0 tests and unless every .NET guard of the profiles ran; with a `dev` section, under the checkout's variables, so two worktrees never share a test database; `--quick`: only the test projects that use `Suwgate.Architecture` or `Suwgate.Database`); every .NET step leaves no idle MSBuild worker or build server behind |
|
|
96
99
|
| `dotnet`, `web` | with `contract/openapi.json`: `api-contract` (the contract and `src/api/openapi.d.ts` of the web app regenerated from the server's project, the one that references `Microsoft.Extensions.ApiDescription.Server`), `api-version` (oasdiff against master; a break needs a new major version in `contract/package.json`), `contract-pins` (every test tagged `contract <name>@<version>` names a version) |
|
|
97
100
|
| `database` | `database-up`: `docker compose --profile db up -d --wait db`, not in CI |
|
|
98
101
|
| every repository | `compose` (with a compose file), `criteria`, `shellcheck`, `gitleaks` |
|
|
@@ -154,15 +157,48 @@ The configs of the tools the steps run extend suwgate's, so an application keeps
|
|
|
154
157
|
|
|
155
158
|
### The .NET guards
|
|
156
159
|
|
|
157
|
-
|
|
160
|
+
One xUnit test in the gate's test project runs every guard of the `dotnet` and `database` profiles:
|
|
158
161
|
|
|
159
162
|
```csharp
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
public sealed class GuardTests
|
|
164
|
+
{
|
|
165
|
+
[Fact]
|
|
166
|
+
public void Every_guard_of_suwgate_passes() =>
|
|
167
|
+
SuwgateGuards.VerifyAll(
|
|
168
|
+
new GuardInputs { Production = [typeof(ServerApp).Assembly], Tests = [typeof(GuardTests).Assembly], Server = typeof(ServerApp) },
|
|
169
|
+
new DatabaseProfile()
|
|
170
|
+
);
|
|
171
|
+
}
|
|
163
172
|
```
|
|
164
173
|
|
|
165
|
-
`
|
|
174
|
+
`VerifyAll` reads the nearest `suwgate.yml` above the test's output folder (profiles, `guards.skip`, exceptions, settings), finds
|
|
175
|
+
the solution, `layers.json`, the sources and the migrations itself, and takes from the test only what it cannot find
|
|
176
|
+
([dotnet/Suwgate.Architecture/README.md](dotnet/Suwgate.Architecture/README.md) lists the inputs).
|
|
177
|
+
|
|
178
|
+
### What the gate proves ran
|
|
179
|
+
|
|
180
|
+
A check counts only when the tool shows it ran, not because a file or a line of text is there:
|
|
181
|
+
|
|
182
|
+
- The .NET guards: `dotnet-test` points `SUWGATE_EVIDENCE` at a fresh folder of this gate run, and every guard that runs (through
|
|
183
|
+
`VerifyAll` or `Guards.Verify`) writes its id and outcome there. The step fails unless every guard of the profiles that
|
|
184
|
+
`guards.skip` does not name is in it, so a deleted guard test, a `[Fact(Skip = …)]` or a filtered-out one fails the gate.
|
|
185
|
+
- Zero tests fail: `unit-tests`, `stories` (Vitest, its JSON report), `e2e` (Playwright, its JSON report) and `dotnet-test`
|
|
186
|
+
(`--zero-tests-policy strict` of Microsoft.Testing.Platform, and xUnit's XML report) fail when the tool ran no test, also when
|
|
187
|
+
every test was skipped. A repository with truly no tests for a profile skips the step in `suwgate.yml` with a reason.
|
|
188
|
+
- `typecheck` reads `tsc --showConfig` of every tsconfig it checks: the strict options of the suwgate preset must be in effect, so
|
|
189
|
+
an override that turns one off fails, naming the option.
|
|
190
|
+
- `lint` reads `eslint --print-config` of a source file of `src/`: `suwgate/no-comments` and `boundaries/dependencies` must be
|
|
191
|
+
errors there.
|
|
192
|
+
- `criteria-ran`, after the test steps: every acceptance criterion of a living spec (`docs/visual/spec/`) that a test names
|
|
193
|
+
(`[Trait("criterion", "<id>")]`, a title or story name `"<id>: …"`) must have a test naming it that ran and passed in this run,
|
|
194
|
+
by the reports of xUnit, Vitest and Playwright. A criterion named only by tests of a step `steps.skip` names is not checked.
|
|
195
|
+
- The kits are wired, not only installed: `suwbackkit-wiring` (dotnet) asks a web server that references `Suwbackkit.Server` to
|
|
196
|
+
call `AddServerDefaults` and `MapServerDefaults`; `suwfrontkit-wiring` (web, library) asks an app whose `package.json` depends
|
|
197
|
+
on `@maniumek/suwfrontkit` to load `@maniumek/suwfrontkit/theme.css` from the main module of its `index.html`, or from a
|
|
198
|
+
stylesheet that module imports. Both read the sources: the evidence (a run hitting `/health`, a built stylesheet with the
|
|
199
|
+
kit's tokens) needs a running server or a production build, which the gate does not have in every repository.
|
|
200
|
+
- The reports live in a temporary folder of the run (`SUWGATE_RUN`), deleted when `suwgate check` ends. `dotnet-test` asks xUnit
|
|
201
|
+
for its XML report (`--report-xunit-xml`), so every .NET test project tests with xUnit v3.
|
|
166
202
|
|
|
167
203
|
`suwgate dev db|logs|smoke|server|tmux|checkout-env` runs the local stack of the template (database, logs, smoke test, server, tmux
|
|
168
204
|
session, worktree databases) from a `dev` section of `suwgate.yml`: [docs/dev.md](docs/dev.md).
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { loadConfig } from "./gate/config.js";
|
|
|
7
7
|
import { PROFILES } from "./gate/contract.js";
|
|
8
8
|
import { repositoryRoot } from "./gate/repository.js";
|
|
9
9
|
import { guards } from "./guards/index.js";
|
|
10
|
-
import { stepsFor } from "./profiles/index.js";
|
|
10
|
+
import { dotnetGuards, stepsFor, verdict } from "./profiles/index.js";
|
|
11
11
|
import { guardEdit } from "./session/guardEdit.js";
|
|
12
12
|
import { preCommit, runTool } from "./session/preCommit.js";
|
|
13
13
|
import { stop } from "./session/stop.js";
|
|
@@ -23,9 +23,12 @@ const USAGE = `usage: suwgate check [--quick] [--verbose] | suwgate hook <guard-
|
|
|
23
23
|
suwgate hook pre-commit git pre-commit hook: gitleaks on the staged changes, then the quick gate
|
|
24
24
|
suwgate dev <db|logs|smoke|server|tmux|checkout-env>
|
|
25
25
|
the local stack of the repository (the dev section of suwgate.yml); suwgate dev --help
|
|
26
|
+
suwgate verdict <tests|guards|tsconfig|eslint> ...
|
|
27
|
+
what the steps call after their tool: did tests run, did the .NET guards run (evidence),
|
|
28
|
+
are the strict compiler options and the eslint rules in effect
|
|
26
29
|
Every step has a ceiling (SUWGATE_STEP_LIMIT seconds overrides them all). A step whose tool is missing is SKIP,
|
|
27
30
|
and a SKIP fails the gate when CI is set. Exit code: 0 green, 1 red, 2 a usage or suwgate.yml problem.`;
|
|
28
|
-
const catalog = { guards, stepsFor };
|
|
31
|
+
const catalog = { guards, dotnetGuards, stepsFor };
|
|
29
32
|
function version() {
|
|
30
33
|
const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
31
34
|
return manifest.version;
|
|
@@ -48,6 +51,12 @@ function readInput() {
|
|
|
48
51
|
async function main(argv) {
|
|
49
52
|
if (argv[0] === "dev")
|
|
50
53
|
return dev(argv.slice(1));
|
|
54
|
+
if (argv[0] === "verdict") {
|
|
55
|
+
const result = verdict(argv.slice(1));
|
|
56
|
+
if (result.text !== "")
|
|
57
|
+
console.error(result.text);
|
|
58
|
+
return result.exitCode;
|
|
59
|
+
}
|
|
51
60
|
const { values, positionals } = parseArgs({
|
|
52
61
|
args: [...argv],
|
|
53
62
|
allowPositionals: true,
|
package/dist/gate/check.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
1
4
|
import { loadConfig } from "./config.js";
|
|
2
5
|
import { plan } from "./plan.js";
|
|
3
6
|
import { report } from "./report.js";
|
|
@@ -34,7 +37,8 @@ export async function check(options) {
|
|
|
34
37
|
changed: () => (changed ??= changedFiles(root)),
|
|
35
38
|
});
|
|
36
39
|
const began = performance.now();
|
|
37
|
-
const
|
|
40
|
+
const run = mkdtempSync(path.join(tmpdir(), "suwgate-run-"));
|
|
41
|
+
const results = await runSteps(steps, { ...options.env, SUWGATE_ROOT: root, SUWGATE_QUICK: options.quick ? "1" : "", SUWGATE_RUN: run }, typeof stepLimit === "number" ? stepLimit : null).finally(() => rmSync(run, { recursive: true, force: true }));
|
|
38
42
|
const totalSeconds = Math.round((performance.now() - began) / 1000);
|
|
39
43
|
const { text, passed } = report({
|
|
40
44
|
results,
|
package/dist/gate/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Guard, type GuardException, type Profile, type Step } from "./contract.ts";
|
|
1
|
+
import { type DotnetGuard, type Guard, type GuardException, type Profile, type Step } from "./contract.ts";
|
|
2
2
|
export declare const CONFIG_FILE = "suwgate.yml";
|
|
3
3
|
interface AddedStep {
|
|
4
4
|
name: string;
|
|
@@ -12,17 +12,23 @@ interface SkippedStep {
|
|
|
12
12
|
step: string;
|
|
13
13
|
reason: string;
|
|
14
14
|
}
|
|
15
|
+
interface SkippedGuard {
|
|
16
|
+
guard: string;
|
|
17
|
+
reason: string;
|
|
18
|
+
}
|
|
15
19
|
export interface Config {
|
|
16
20
|
profiles: Profile[];
|
|
17
21
|
directories: Partial<Record<Profile, string>>;
|
|
18
22
|
add: AddedStep[];
|
|
19
23
|
skip: SkippedStep[];
|
|
24
|
+
skippedGuards: SkippedGuard[];
|
|
20
25
|
exceptions: GuardException[];
|
|
21
26
|
settings: Record<string, unknown>;
|
|
22
27
|
quickLimitSeconds?: number;
|
|
23
28
|
}
|
|
24
29
|
export interface Catalog {
|
|
25
30
|
guards: readonly Guard[];
|
|
31
|
+
dotnetGuards: readonly DotnetGuard[];
|
|
26
32
|
stepsFor(profiles: readonly Profile[]): readonly Step[];
|
|
27
33
|
}
|
|
28
34
|
export type Loaded = {
|
package/dist/gate/config.js
CHANGED
|
@@ -35,7 +35,8 @@ function describe(error) {
|
|
|
35
35
|
switch (error.keyword) {
|
|
36
36
|
case "required": {
|
|
37
37
|
const missing = String(params["missingProperty"]);
|
|
38
|
-
const
|
|
38
|
+
const what = parts[0] === "exceptions" ? "exception" : parts[0] === "guards" ? "skipped guard" : "skipped step";
|
|
39
|
+
const fix = missing === "reason" ? `: every ${what} says why (reason: <why>)` : "";
|
|
39
40
|
return `${where} has no "${missing}"${fix}`;
|
|
40
41
|
}
|
|
41
42
|
case "additionalProperties":
|
|
@@ -104,9 +105,36 @@ function checkSteps(raw, catalog, problem) {
|
|
|
104
105
|
}
|
|
105
106
|
});
|
|
106
107
|
}
|
|
108
|
+
function profilesOf(id, catalog) {
|
|
109
|
+
const dotnet = catalog.dotnetGuards.find((guard) => guard.id === id);
|
|
110
|
+
if (dotnet !== undefined)
|
|
111
|
+
return [dotnet.profile];
|
|
112
|
+
return catalog.guards.find((guard) => guard.id === id)?.profiles ?? null;
|
|
113
|
+
}
|
|
114
|
+
function checkSkippedGuards(raw, catalog, problem) {
|
|
115
|
+
const skipped = (raw.guards?.skip ?? []).map((entry) => entry.guard);
|
|
116
|
+
(raw.guards?.skip ?? []).forEach((entry, index) => {
|
|
117
|
+
const where = ["guards", "skip", index, "guard"];
|
|
118
|
+
const profiles = profilesOf(entry.guard, catalog);
|
|
119
|
+
if (profiles === null) {
|
|
120
|
+
const known = [...catalog.guards.map((guard) => guard.id), ...catalog.dotnetGuards.map((guard) => guard.id)];
|
|
121
|
+
problem(where, `no guard "${entry.guard}": the guards are ${known.join(", ")}`);
|
|
122
|
+
}
|
|
123
|
+
else if (profiles !== "every" && !profiles.some((profile) => raw.profiles.includes(profile))) {
|
|
124
|
+
problem(where, `"${entry.guard}" runs only for ${profiles.join(", ")}, which this repository does not have: delete the entry`);
|
|
125
|
+
}
|
|
126
|
+
if (skipped.indexOf(entry.guard) !== index)
|
|
127
|
+
problem(where, `"${entry.guard}" is skipped twice: keep one entry`);
|
|
128
|
+
});
|
|
129
|
+
(raw.exceptions ?? []).forEach((exception, index) => {
|
|
130
|
+
if (skipped.includes(exception.guard)) {
|
|
131
|
+
problem(["exceptions", index], `"${exception.guard}" is skipped in guards.skip, so this exception is never checked: delete it, or the skip`);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
107
135
|
function checkSettings(raw, catalog, problem) {
|
|
108
136
|
for (const [id, value] of Object.entries(raw.settings ?? {})) {
|
|
109
|
-
const guard = catalog.guards.find((candidate) => candidate.id === id);
|
|
137
|
+
const guard = catalog.guards.find((candidate) => candidate.id === id) ?? catalog.dotnetGuards.find((candidate) => candidate.id === id);
|
|
110
138
|
if (guard?.settingsSchema === undefined) {
|
|
111
139
|
problem(["settings", id], guard === undefined ? `no guard "${id}"` : `the guard "${id}" takes no settings`);
|
|
112
140
|
continue;
|
|
@@ -147,6 +175,7 @@ export function parseConfig(text, catalog) {
|
|
|
147
175
|
checkDirectories(data, problem);
|
|
148
176
|
checkExceptions(data, catalog, problem);
|
|
149
177
|
checkSteps(data, catalog, problem);
|
|
178
|
+
checkSkippedGuards(data, catalog, problem);
|
|
150
179
|
checkSettings(data, catalog, problem);
|
|
151
180
|
if (problems.length > 0)
|
|
152
181
|
return { problems };
|
|
@@ -156,6 +185,7 @@ export function parseConfig(text, catalog) {
|
|
|
156
185
|
directories: data.directories ?? {},
|
|
157
186
|
add: data.steps?.add ?? [],
|
|
158
187
|
skip: data.steps?.skip ?? [],
|
|
188
|
+
skippedGuards: data.guards?.skip ?? [],
|
|
159
189
|
exceptions: data.exceptions ?? [],
|
|
160
190
|
settings: data.settings ?? {},
|
|
161
191
|
...(data.quick?.limitSeconds === undefined ? {} : { quickLimitSeconds: data.quick.limitSeconds }),
|
package/dist/gate/contract.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export interface GuardContext {
|
|
|
19
19
|
settings: unknown;
|
|
20
20
|
read(file: string): string;
|
|
21
21
|
}
|
|
22
|
+
export interface DotnetGuard {
|
|
23
|
+
id: string;
|
|
24
|
+
profile: Profile;
|
|
25
|
+
settingsSchema?: object;
|
|
26
|
+
}
|
|
22
27
|
export interface Guard {
|
|
23
28
|
id: string;
|
|
24
29
|
description: string;
|
|
@@ -33,6 +38,8 @@ export interface StepContext {
|
|
|
33
38
|
quick: boolean;
|
|
34
39
|
profiles: readonly Profile[];
|
|
35
40
|
directories: Readonly<Partial<Record<Profile, string>>>;
|
|
41
|
+
skippedSteps: readonly string[];
|
|
42
|
+
skippedGuards: readonly string[];
|
|
36
43
|
changed(): readonly string[];
|
|
37
44
|
}
|
|
38
45
|
export interface Skip {
|
package/dist/gate/plan.js
CHANGED
|
@@ -32,11 +32,14 @@ function chosenRun(step, quick) {
|
|
|
32
32
|
return step.quick;
|
|
33
33
|
}
|
|
34
34
|
function guardsStep(input) {
|
|
35
|
+
const skipped = input.config.skippedGuards.map((entry) => entry.guard);
|
|
35
36
|
const active = input.catalog.guards.filter((guard) => (guard.profiles === "every" || guard.profiles.some((profile) => input.config.profiles.includes(profile))) &&
|
|
36
|
-
(!input.quick || guard.quick !== false)
|
|
37
|
+
(!input.quick || guard.quick !== false) &&
|
|
38
|
+
!skipped.includes(guard.id));
|
|
39
|
+
const skippedHere = input.catalog.guards.filter((guard) => skipped.includes(guard.id)).length;
|
|
37
40
|
return {
|
|
38
41
|
id: GUARDS_STEP,
|
|
39
|
-
title: `repository guards (${active.length})`,
|
|
42
|
+
title: `repository guards (${active.length}${skippedHere === 0 ? "" : `, ${skippedHere} skipped in suwgate.yml`})`,
|
|
40
43
|
after: [],
|
|
41
44
|
limitSeconds: DEFAULT_LIMIT_SECONDS,
|
|
42
45
|
inline: async () => {
|
|
@@ -65,6 +68,8 @@ export function plan(input) {
|
|
|
65
68
|
quick: input.quick,
|
|
66
69
|
profiles: input.config.profiles,
|
|
67
70
|
directories: input.config.directories,
|
|
71
|
+
skippedSteps: input.config.skip.map((skipped) => skipped.step),
|
|
72
|
+
skippedGuards: input.config.skippedGuards.map((skipped) => skipped.guard),
|
|
68
73
|
changed: input.changed,
|
|
69
74
|
};
|
|
70
75
|
const line = typeof run === "string" ? run : run(context);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { appsettingsBound } from "./appsettingsBound.js";
|
|
2
2
|
import { bannedNugetPackages } from "./bannedNugetPackages.js";
|
|
3
|
+
import { suwbackkitWiring } from "./suwbackkitWiring.js";
|
|
3
4
|
import { unusedNugetVersions } from "./unusedNugetVersions.js";
|
|
4
|
-
export const dotnetGuards = [bannedNugetPackages, unusedNugetVersions, appsettingsBound];
|
|
5
|
+
export const dotnetGuards = [bannedNugetPackages, unusedNugetVersions, appsettingsBound, suwbackkitWiring];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { dotnetFiles } from "./msbuild.js";
|
|
3
|
+
const PROJECT = /\.csproj$/;
|
|
4
|
+
const CSHARP = /\.cs$/;
|
|
5
|
+
const WEB_SDK = /<Project\b[^>]*\bSdk\s*=\s*"Microsoft\.NET\.Sdk\.Web"/;
|
|
6
|
+
const KIT_REFERENCE = /<(?:PackageReference\b[^>]*\bInclude\s*=\s*"Suwbackkit\.Server"|ProjectReference\b[^>]*\bInclude\s*=\s*"[^"]*Suwbackkit\.Server\.csproj")/;
|
|
7
|
+
const CALLS = [
|
|
8
|
+
{ method: "AddServerDefaults", pattern: /\.AddServerDefaults\s*(?:<[^>]*>)?\s*\(/, on: "the builder (builder.AddServerDefaults())" },
|
|
9
|
+
{ method: "MapServerDefaults", pattern: /\.MapServerDefaults\s*\(/, on: "the app (app.MapServerDefaults())" },
|
|
10
|
+
];
|
|
11
|
+
function findingsOf(context, project) {
|
|
12
|
+
const folder = path.posix.dirname(project);
|
|
13
|
+
const sources = dotnetFiles(context, CSHARP)
|
|
14
|
+
.filter((file) => folder === "." || file.startsWith(`${folder}/`))
|
|
15
|
+
.map((file) => context.read(file));
|
|
16
|
+
return CALLS.filter((call) => !sources.some((text) => call.pattern.test(text))).map((call) => ({
|
|
17
|
+
target: project,
|
|
18
|
+
message: `the server references Suwbackkit.Server but never calls ${call.method}: call it on ${call.on} where the server is built, so it gets the kit's logging, problem details, OpenAPI and the /health and /alive checks`,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
export const suwbackkitWiring = {
|
|
22
|
+
id: "suwbackkit-wiring",
|
|
23
|
+
description: "A web server that references Suwbackkit.Server calls AddServerDefaults and MapServerDefaults, so the kit is wired, not only installed",
|
|
24
|
+
profiles: ["dotnet"],
|
|
25
|
+
check: (context) => dotnetFiles(context, PROJECT)
|
|
26
|
+
.filter((project) => {
|
|
27
|
+
const text = context.read(project);
|
|
28
|
+
return WEB_SDK.test(text) && KIT_REFERENCE.test(text);
|
|
29
|
+
})
|
|
30
|
+
.flatMap((project) => findingsOf(context, project)),
|
|
31
|
+
};
|
|
@@ -13,6 +13,7 @@ import { repositoryLayout } from "./repositoryLayout.js";
|
|
|
13
13
|
import { requiredFiles } from "./requiredFiles.js";
|
|
14
14
|
import { scriptsCalled } from "./scriptsCalled.js";
|
|
15
15
|
import { scriptsHelp } from "./scriptsHelp.js";
|
|
16
|
+
import { suwfrontkitWiring } from "./suwfrontkitWiring.js";
|
|
16
17
|
import { vsCodeSettings } from "./vsCodeSettings.js";
|
|
17
18
|
export const repositoryGuards = [
|
|
18
19
|
requiredFiles,
|
|
@@ -31,4 +32,5 @@ export const repositoryGuards = [
|
|
|
31
32
|
noRawColors,
|
|
32
33
|
dependencyDirection,
|
|
33
34
|
hooks,
|
|
35
|
+
suwfrontkitWiring,
|
|
34
36
|
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { npmDependencies } from "./packageManifests.js";
|
|
3
|
+
const KIT = "@maniumek/suwfrontkit";
|
|
4
|
+
const THEME = `${KIT}/theme.css`;
|
|
5
|
+
const PROFILES = ["web", "library"];
|
|
6
|
+
const MAIN_SCRIPT = /<script\b[^>]*\btype\s*=\s*["']module["'][^>]*\bsrc\s*=\s*["']\/?([^"']+)["']/;
|
|
7
|
+
const CSS_IMPORT = /\bimport\s+["'](\.{1,2}\/[^"']+\.css)["']/g;
|
|
8
|
+
function importsTheme(text) {
|
|
9
|
+
const escaped = THEME.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
10
|
+
return new RegExp(`(?:\\bimport\\s+|@import\\s+(?:url\\()?)["']${escaped}["']`).test(text);
|
|
11
|
+
}
|
|
12
|
+
function present(context, file) {
|
|
13
|
+
return context.files.includes(file);
|
|
14
|
+
}
|
|
15
|
+
function findingsIn(context, directory) {
|
|
16
|
+
const joined = (file) => (directory === "" ? file : path.posix.join(directory, file));
|
|
17
|
+
const html = joined("index.html");
|
|
18
|
+
if (!present(context, html))
|
|
19
|
+
return [];
|
|
20
|
+
const main = MAIN_SCRIPT.exec(context.read(html))?.[1];
|
|
21
|
+
if (main === undefined)
|
|
22
|
+
return [];
|
|
23
|
+
const module = joined(main);
|
|
24
|
+
if (!present(context, module))
|
|
25
|
+
return [];
|
|
26
|
+
const text = context.read(module);
|
|
27
|
+
const stylesheets = [...text.matchAll(CSS_IMPORT)].map((match) => path.posix.join(path.posix.dirname(module), match[1] ?? ""));
|
|
28
|
+
if (importsTheme(text) || stylesheets.some((sheet) => present(context, sheet) && importsTheme(context.read(sheet))))
|
|
29
|
+
return [];
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
target: module,
|
|
33
|
+
message: `the app depends on ${KIT} but neither its main module nor a stylesheet it imports loads the kit's theme: add @import "${THEME}"; at the top of the entry stylesheet (or import "${THEME}" in ${path.posix.basename(module)}), so the kit's components get their tokens`,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
export const suwfrontkitWiring = {
|
|
38
|
+
id: "suwfrontkit-wiring",
|
|
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
|
+
profiles: PROFILES,
|
|
41
|
+
check(context) {
|
|
42
|
+
const directories = [
|
|
43
|
+
...new Set(PROFILES.filter((profile) => context.profiles.includes(profile)).map((profile) => context.directories[profile] ?? "")),
|
|
44
|
+
];
|
|
45
|
+
const manifests = new Set(npmDependencies(context)
|
|
46
|
+
.filter((dependency) => dependency.name === KIT)
|
|
47
|
+
.map((dependency) => dependency.manifest));
|
|
48
|
+
return directories
|
|
49
|
+
.filter((directory) => manifests.has(directory === "" ? "package.json" : `${directory}/package.json`))
|
|
50
|
+
.flatMap((directory) => findingsIn(context, directory));
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -4,4 +4,5 @@ export declare const DOTNET_BUILD = "dotnet-build";
|
|
|
4
4
|
export declare const DOTNET_TEST = "dotnet-test";
|
|
5
5
|
export declare function inCheckoutEnv(context: StepContext, command: string): string;
|
|
6
6
|
export declare function guardTests(context: StepContext): string | null;
|
|
7
|
+
export declare function witnessed(context: StepContext, tests: string): string;
|
|
7
8
|
export declare const dotnetSteps: readonly Step[];
|
package/dist/profiles/dotnet.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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
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
7
|
export const NO_IDLE_BUILD_PROCESSES = "export MSBUILDDISABLENODEREUSE=1 DOTNET_CLI_USE_MSBUILD_SERVER=0";
|
|
7
8
|
const BUILD = `${NO_IDLE_BUILD_PROCESSES} && dotnet build --nologo -v quiet`;
|
|
8
|
-
const
|
|
9
|
+
const TEST_OPTIONS = '--no-build --no-progress --zero-tests-policy strict --report-xunit-xml --results-directory "$run/results"';
|
|
9
10
|
const FORMAT = `${NO_IDLE_BUILD_PROCESSES} && dotnet tool restore >/dev/null`;
|
|
10
11
|
export const DOTNET_BUILD = "dotnet-build";
|
|
11
12
|
export const DOTNET_TEST = "dotnet-test";
|
|
@@ -26,7 +27,16 @@ export function guardTests(context) {
|
|
|
26
27
|
});
|
|
27
28
|
if (projects.length === 0)
|
|
28
29
|
return null;
|
|
29
|
-
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(" && ");
|
|
30
40
|
}
|
|
31
41
|
export const dotnetSteps = [
|
|
32
42
|
{
|
|
@@ -52,14 +62,14 @@ export const dotnetSteps = [
|
|
|
52
62
|
},
|
|
53
63
|
{
|
|
54
64
|
id: DOTNET_TEST,
|
|
55
|
-
title: "tests (dotnet test, xUnit v3, with the checkout's databases when suwgate.yml has dev; --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)",
|
|
56
66
|
profile: "dotnet",
|
|
57
67
|
needs: ["dotnet"],
|
|
58
68
|
after: [DOTNET_BUILD, DATABASE_UP],
|
|
59
|
-
run: (context) => inCheckoutEnv(context,
|
|
69
|
+
run: (context) => inCheckoutEnv(context, witnessed(context, `dotnet test ${TEST_OPTIONS}`)),
|
|
60
70
|
quick: (context) => {
|
|
61
71
|
const command = guardTests(context);
|
|
62
|
-
return command === null ? null : inCheckoutEnv(context, command);
|
|
72
|
+
return command === null ? null : inCheckoutEnv(context, witnessed(context, command));
|
|
63
73
|
},
|
|
64
74
|
limitSeconds: 600,
|
|
65
75
|
},
|
|
@@ -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
|
+
}
|
package/dist/profiles/shell.d.ts
CHANGED
|
@@ -11,3 +11,7 @@ export declare function onPath(tool: string): boolean;
|
|
|
11
11
|
export declare function suwgate(args: string): string;
|
|
12
12
|
export declare function hasDevSection(context: StepContext): boolean;
|
|
13
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
|
@@ -77,3 +77,23 @@ export function hasDevSection(context) {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
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,14 +2,14 @@ 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 { CHECKOUT_ENV, has, hasDevSection, quoted, script, suwgate } 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
7
|
const PLAYWRIGHT = `pnpm exec playwright test -c ${E2E_CONFIG}`;
|
|
8
8
|
function e2e(context) {
|
|
9
9
|
if (!has(context, E2E_CONFIG))
|
|
10
10
|
return null;
|
|
11
11
|
if (!hasDevSection(context))
|
|
12
|
-
return PLAYWRIGHT;
|
|
12
|
+
return script(["set -euo pipefail", ...countedPlaywright("e2e", PLAYWRIGHT)]);
|
|
13
13
|
return script([
|
|
14
14
|
"set -euo pipefail",
|
|
15
15
|
...CHECKOUT_ENV,
|
|
@@ -17,13 +17,13 @@ function e2e(context) {
|
|
|
17
17
|
`${suwgate("dev db up")} >/dev/null`,
|
|
18
18
|
`${suwgate("dev db psql")} -q -d postgres -c "DROP DATABASE IF EXISTS $E2E_DATABASE WITH (FORCE)" -c "CREATE DATABASE $E2E_DATABASE"`,
|
|
19
19
|
`mkdir -p ${quoted(`${context.root}/.artifacts/logs`)}`,
|
|
20
|
-
PLAYWRIGHT,
|
|
20
|
+
...countedPlaywright("e2e", PLAYWRIGHT),
|
|
21
21
|
]);
|
|
22
22
|
}
|
|
23
23
|
export const webSteps = [
|
|
24
24
|
{
|
|
25
25
|
id: "e2e",
|
|
26
|
-
title: `browser tests against the real server and a fresh database of this checkout (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)`,
|
|
27
27
|
profile: "web",
|
|
28
28
|
needs: ["pnpm"],
|
|
29
29
|
after: [PNPM_INSTALL, DOTNET_BUILD, DATABASE_UP, DOTNET_TEST, API_CONTRACT],
|
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
|
}
|
|
@@ -76,6 +76,25 @@
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
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
|
+
},
|
|
79
98
|
"exceptions": {
|
|
80
99
|
"description": "Exceptions from the guards: one target of one guard, each with its reason. suwgate check counts them.",
|
|
81
100
|
"type": "array",
|
|
@@ -196,7 +215,7 @@
|
|
|
196
215
|
"settings": {
|
|
197
216
|
"description": "Settings of a guard, by its id; the guard's own schema checks them.",
|
|
198
217
|
"type": "object",
|
|
199
|
-
"propertyNames": { "pattern": "^[a-z][a-z0-9-]*$" }
|
|
218
|
+
"propertyNames": { "pattern": "^([a-z]+/)?[a-z][a-z0-9-]*$" }
|
|
200
219
|
}
|
|
201
220
|
},
|
|
202
221
|
"$defs": {
|