@maniumek/suwgate 0.3.0 → 0.4.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.
Files changed (47) hide show
  1. package/README.md +92 -20
  2. package/dist/cli.js +38 -3
  3. package/dist/dev/db.d.ts +1 -1
  4. package/dist/dev/db.js +25 -0
  5. package/dist/dev/logs.js +9 -1
  6. package/dist/dev/settings.d.ts +2 -0
  7. package/dist/dev/settings.js +5 -2
  8. package/dist/eslint/index.js +4 -1
  9. package/dist/gate/check.d.ts +10 -0
  10. package/dist/gate/check.js +91 -19
  11. package/dist/gate/config.d.ts +12 -0
  12. package/dist/gate/config.js +87 -2
  13. package/dist/gate/contract.d.ts +6 -0
  14. package/dist/gate/guardsStep.d.ts +3 -1
  15. package/dist/gate/guardsStep.js +14 -3
  16. package/dist/gate/plan.d.ts +20 -1
  17. package/dist/gate/plan.js +89 -22
  18. package/dist/gate/report.d.ts +1 -0
  19. package/dist/gate/report.js +12 -3
  20. package/dist/gate/repository.d.ts +1 -0
  21. package/dist/gate/repository.js +8 -0
  22. package/dist/gate/runner.js +18 -3
  23. package/dist/guards/comments/hash.js +22 -1
  24. package/dist/guards/dotnet/appsettingsBound.js +29 -2
  25. package/dist/guards/repository/imagePins.js +1 -1
  26. package/dist/guards/repository/justModules.js +28 -10
  27. package/dist/guards/repository/noRawColors.js +1 -1
  28. package/dist/guards/repository/scriptsCalled.js +38 -11
  29. package/dist/profiles/contract.js +81 -38
  30. package/dist/profiles/criteriaRan.d.ts +1 -0
  31. package/dist/profiles/criteriaRan.js +44 -1
  32. package/dist/profiles/database.js +11 -4
  33. package/dist/profiles/dotnet.d.ts +1 -0
  34. package/dist/profiles/dotnet.js +28 -5
  35. package/dist/profiles/dotnetGuards.js +17 -1
  36. package/dist/profiles/library.js +4 -1
  37. package/dist/profiles/node.js +1 -0
  38. package/dist/profiles/presets/knip.d.ts +1 -0
  39. package/dist/profiles/presets/knip.js +4 -2
  40. package/dist/profiles/presets/playwright.d.ts +3 -1
  41. package/dist/profiles/presets/playwright.js +7 -1
  42. package/dist/profiles/shell.d.ts +3 -1
  43. package/dist/profiles/shell.js +22 -7
  44. package/dist/profiles/verdict.js +6 -2
  45. package/dist/profiles/web.js +24 -5
  46. package/package.json +1 -1
  47. package/schema/suwgate.schema.json +62 -3
@@ -1,4 +1,10 @@
1
1
  const ci = () => Boolean(process.env["CI"]);
2
+ const GATE_REPORT = "PLAYWRIGHT_JSON_OUTPUT_FILE";
3
+ function withGateReport(reporter) {
4
+ const listed = typeof reporter === "string" ? reporter.split(",").map((name) => [name.trim()]) : [...reporter];
5
+ const wanted = (process.env[GATE_REPORT] ?? "") !== "" && !listed.some(([name]) => name === "json");
6
+ return wanted ? [...listed, ["json"]] : listed;
7
+ }
2
8
  export function e2eTests(config) {
3
9
  return {
4
10
  testDir: "../src",
@@ -6,10 +12,10 @@ export function e2eTests(config) {
6
12
  workers: 1,
7
13
  retries: ci() ? 1 : 0,
8
14
  failOnFlakyTests: ci(),
9
- reporter: "list",
10
15
  timeout: 60_000,
11
16
  projects: [{ name: "chromium", use: { browserName: "chromium", viewport: { width: 1440, height: 900 } } }],
12
17
  ...config,
18
+ reporter: withGateReport(config.reporter ?? "list"),
13
19
  use: { locale: "en-US", trace: "retain-on-failure", screenshot: "only-on-failure", ...config.use },
14
20
  };
15
21
  }
@@ -10,8 +10,10 @@ export declare function script(lines: readonly string[]): string;
10
10
  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
+ export declare function databaseUpCommand(context: StepContext): string | null;
14
+ export declare function settingsOf<Settings>(context: StepContext, step: string): Partial<Settings>;
13
15
  export declare const CHECKOUT_ENV: string[];
14
16
  export declare function runDirectory(step: string): string;
15
17
  export declare function verdictCommand(args: string): string;
16
18
  export declare function countedVitest(step: string, command: string): string;
17
- export declare function countedPlaywright(step: string, command: string): string[];
19
+ export declare function countedPlaywright(step: string, command: string, reporters?: string | null): string[];
@@ -67,15 +67,30 @@ export function onPath(tool) {
67
67
  export function suwgate(args) {
68
68
  return `${quoted(process.execPath)} ${quoted(CLI)} ${args}`;
69
69
  }
70
- export function hasDevSection(context) {
70
+ const MAX_ALIASES = 10_000;
71
+ function devSection(context) {
71
72
  try {
72
- const parsed = parseYaml(readFileSync(path.join(context.root, "suwgate.yml"), "utf8"));
73
- return typeof parsed === "object" && parsed !== null && "dev" in parsed;
73
+ const parsed = parseYaml(readFileSync(path.join(context.root, "suwgate.yml"), "utf8"), { maxAliasCount: MAX_ALIASES });
74
+ if (typeof parsed !== "object" || parsed === null || !("dev" in parsed))
75
+ return null;
76
+ const dev = parsed.dev;
77
+ return typeof dev === "object" && dev !== null ? dev : {};
74
78
  }
75
79
  catch {
76
- return false;
80
+ return null;
77
81
  }
78
82
  }
83
+ export function hasDevSection(context) {
84
+ return devSection(context) !== null;
85
+ }
86
+ export function databaseUpCommand(context) {
87
+ const database = devSection(context)?.["database"];
88
+ const up = typeof database === "object" && database !== null ? database["up"] : undefined;
89
+ return typeof up === "string" ? up : null;
90
+ }
91
+ export function settingsOf(context, step) {
92
+ return context.settings[step] ?? {};
93
+ }
79
94
  export const CHECKOUT_ENV = [`variables="$(${suwgate("dev checkout-env")})"`, 'eval "$variables"'];
80
95
  export function runDirectory(step) {
81
96
  return `run="\${SUWGATE_RUN:-$(mktemp -d)}/${step}" && mkdir -p "$run"`;
@@ -86,14 +101,14 @@ export function verdictCommand(args) {
86
101
  export function countedVitest(step, command) {
87
102
  return [
88
103
  runDirectory(step),
89
- `${command} --reporter=default --reporter=json --outputFile.json="$run/vitest.json"`,
104
+ `${command} --reporter=default --reporter=json --outputFile.json="$run/vitest.json" "$@"`,
90
105
  verdictCommand(`tests vitest "$run/vitest.json" ${quoted(`vitest (${step})`)}`),
91
106
  ].join(" && ");
92
107
  }
93
- export function countedPlaywright(step, command) {
108
+ export function countedPlaywright(step, command, reporters = "list,json") {
94
109
  return [
95
110
  runDirectory(step),
96
- `PLAYWRIGHT_JSON_OUTPUT_FILE="$run/playwright.json" ${command} --reporter=list,json`,
111
+ `PLAYWRIGHT_JSON_OUTPUT_FILE="$run/playwright.json" ${command}${reporters === null ? "" : ` --reporter=${reporters}`} "$@"`,
97
112
  verdictCommand(`tests playwright "$run/playwright.json" ${quoted(`playwright (${step})`)}`),
98
113
  ];
99
114
  }
@@ -14,8 +14,12 @@ const STRICT_FAMILY = [
14
14
  ];
15
15
  export function testsVerdict(format, location, tool) {
16
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`;
17
+ if (run === null) {
18
+ const hint = format === "playwright"
19
+ ? "; Playwright writes it when its reporters include json, which e2eTests() of @maniumek/suwgate/playwright adds: keep the config's reporter inside e2eTests(), and pass no --reporter after --"
20
+ : "";
21
+ return `${tool} wrote no report, so suwgate cannot tell that any test ran: run it again and look at its output above${hint}`;
22
+ }
19
23
  if (run.executed > 0)
20
24
  return null;
21
25
  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`;
@@ -2,14 +2,29 @@ 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, countedPlaywright, has, hasDevSection, quoted, script, suwgate } from "./shell.js";
5
+ import { CHECKOUT_ENV, countedPlaywright, has, hasDevSection, quoted, script, settingsOf, suwgate } from "./shell.js";
6
+ const E2E = "e2e";
6
7
  const E2E_CONFIG = "e2e/playwright.config.ts";
7
8
  const PLAYWRIGHT = `pnpm exec playwright test -c ${E2E_CONFIG}`;
9
+ const E2E_SETTINGS = {
10
+ type: "object",
11
+ additionalProperties: false,
12
+ properties: {
13
+ before: {
14
+ description: "Commands run in the repository root after the database is fresh and before Playwright, in order (e.g. rm -rf .artifacts/e2e/versions); a failing one stops the step.",
15
+ type: "array",
16
+ minItems: 1,
17
+ items: { type: "string", minLength: 1 },
18
+ },
19
+ },
20
+ };
8
21
  function e2e(context) {
9
22
  if (!has(context, E2E_CONFIG))
10
23
  return null;
24
+ const before = (settingsOf(context, E2E).before ?? []).map((command) => `(cd ${quoted(context.root)} && ${command})`);
25
+ const playwright = countedPlaywright(E2E, PLAYWRIGHT, null);
11
26
  if (!hasDevSection(context))
12
- return script(["set -euo pipefail", ...countedPlaywright("e2e", PLAYWRIGHT)]);
27
+ return script(["set -euo pipefail", ...before, ...playwright]);
13
28
  return script([
14
29
  "set -euo pipefail",
15
30
  ...CHECKOUT_ENV,
@@ -17,17 +32,21 @@ function e2e(context) {
17
32
  `${suwgate("dev db up")} >/dev/null`,
18
33
  `${suwgate("dev db psql")} -q -d postgres -c "DROP DATABASE IF EXISTS $E2E_DATABASE WITH (FORCE)" -c "CREATE DATABASE $E2E_DATABASE"`,
19
34
  `mkdir -p ${quoted(`${context.root}/.artifacts/logs`)}`,
20
- ...countedPlaywright("e2e", PLAYWRIGHT),
35
+ ...before,
36
+ ...playwright,
21
37
  ]);
22
38
  }
23
39
  export const webSteps = [
24
40
  {
25
- id: "e2e",
41
+ id: E2E,
26
42
  title: `browser tests against the real server and a fresh database of this checkout (playwright, ${E2E_CONFIG}; 0 tests run fails)`,
27
43
  profile: "web",
28
44
  needs: ["pnpm"],
29
- after: [PNPM_INSTALL, DOTNET_BUILD, DATABASE_UP, DOTNET_TEST, API_CONTRACT],
45
+ after: [PNPM_INSTALL, DOTNET_BUILD, DATABASE_UP],
46
+ orderAfter: [DOTNET_TEST, API_CONTRACT],
30
47
  run: e2e,
48
+ args: "playwright test",
49
+ settingsSchema: E2E_SETTINGS,
31
50
  limitSeconds: 600,
32
51
  },
33
52
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maniumek/suwgate",
3
- "version": "0.3.0",
3
+ "version": "0.4.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",
@@ -35,6 +35,11 @@
35
35
  }
36
36
  }
37
37
  },
38
+ "env": { "$ref": "#/$defs/env", "description": "Variables set for every step (a step's own env in steps.configure wins)." },
39
+ "unset": {
40
+ "$ref": "#/$defs/unset",
41
+ "description": "Variables no step sees, removed before the steps run, e.g. [Models__*, LLM_MODEL_*] so no step reaches a real model."
42
+ },
38
43
  "steps": {
39
44
  "type": "object",
40
45
  "additionalProperties": false,
@@ -73,6 +78,29 @@
73
78
  "reason": { "$ref": "#/$defs/reason" }
74
79
  }
75
80
  }
81
+ },
82
+ "configure": {
83
+ "description": "Knobs of the profiles' own steps, by step id: their ceiling, more steps to wait for, their environment, and the step's own settings, which the step's schema checks. Replacing a step's command is a skip with its reason plus an added step.",
84
+ "type": "object",
85
+ "propertyNames": { "$ref": "#/$defs/id" },
86
+ "additionalProperties": {
87
+ "type": "object",
88
+ "additionalProperties": false,
89
+ "properties": {
90
+ "limitSeconds": { "type": "integer", "minimum": 1, "description": "The step is killed above this." },
91
+ "after": {
92
+ "type": "array",
93
+ "uniqueItems": true,
94
+ "items": { "$ref": "#/$defs/id" },
95
+ "description": "More steps that must finish first, on top of the step's own."
96
+ },
97
+ "env": { "$ref": "#/$defs/env" },
98
+ "unset": { "$ref": "#/$defs/unset" },
99
+ "settings": {
100
+ "description": "The step's own settings, checked by the step's settingsSchema (README: the settings of the steps)."
101
+ }
102
+ }
103
+ }
76
104
  }
77
105
  }
78
106
  },
@@ -105,7 +133,16 @@
105
133
  "properties": {
106
134
  "guard": { "type": "string", "pattern": "^([a-z]+/)?[a-z][a-z0-9-]*$" },
107
135
  "target": { "type": "string", "minLength": 1 },
108
- "reason": { "$ref": "#/$defs/reason" }
136
+ "reason": { "$ref": "#/$defs/reason" },
137
+ "message": {
138
+ "type": "string",
139
+ "minLength": 1,
140
+ "description": "Narrows the exception to the target's findings whose message contains this text; without it, every finding of the target is excepted. Repository guards only."
141
+ },
142
+ "once": {
143
+ "type": "boolean",
144
+ "description": "A one-time exception: it holds only while master's suwgate.yml does not have it yet (on the branch that adds it). After the merge it excepts nothing and is never stale; the report asks to delete it. Repository guards only."
145
+ }
109
146
  }
110
147
  }
111
148
  },
@@ -158,7 +195,7 @@
158
195
  }
159
196
  },
160
197
  "database": {
161
- "description": "Defaults to the app name for all three.",
198
+ "description": "The app's database: user, password and name default to the app name; up and psql replace the compose service with the repository's own commands.",
162
199
  "type": "object",
163
200
  "additionalProperties": false,
164
201
  "properties": {
@@ -168,7 +205,17 @@
168
205
  "minLength": 1,
169
206
  "description": "A development password: the database is published on the loopback only."
170
207
  },
171
- "name": { "type": "string", "minLength": 1 }
208
+ "name": { "type": "string", "minLength": 1 },
209
+ "up": {
210
+ "type": "string",
211
+ "minLength": 1,
212
+ "description": "A bash command, run in the repository root, that starts the database (or leaves it running) and returns once it answers, e.g. scripts/.internal/db.sh up. suwgate dev db up, the database-up step and the e2e step run it instead of docker compose."
213
+ },
214
+ "psql": {
215
+ "type": "string",
216
+ "minLength": 1,
217
+ "description": "A bash command that runs psql in the database as its owner and takes psql's arguments after it, e.g. scripts/.internal/db.sh psql. suwgate dev db psql and the e2e step use it instead of docker compose exec."
218
+ }
172
219
  }
173
220
  },
174
221
  "server": {
@@ -221,6 +268,18 @@
221
268
  "$defs": {
222
269
  "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
223
270
  "reason": { "type": "string", "pattern": "\\S", "description": "Why: a sentence a reviewer can judge." },
271
+ "env": {
272
+ "description": "Variables set for the commands, by name; quote a value YAML would read as a number or a boolean (\"1\").",
273
+ "type": "object",
274
+ "propertyNames": { "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" },
275
+ "additionalProperties": { "type": "string" }
276
+ },
277
+ "unset": {
278
+ "description": "Variables removed from the environment, by name; * and ? match any characters (Models__* clears every Models__ setting), without regard to case, as .NET reads configuration.",
279
+ "type": "array",
280
+ "uniqueItems": true,
281
+ "items": { "type": "string", "pattern": "^[A-Za-z0-9_*?]+$" }
282
+ },
224
283
  "port": { "type": "integer", "minimum": 1, "maximum": 65535 },
225
284
  "relativePath": { "type": "string", "pattern": "^[^/\\\\][^\\\\]*$" }
226
285
  }