@maniumek/suwgate 0.0.0-stage → 0.1.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 (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +149 -2
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +97 -0
  5. package/dist/dev/checkoutEnv.d.ts +20 -0
  6. package/dist/dev/checkoutEnv.js +101 -0
  7. package/dist/dev/db.d.ts +25 -0
  8. package/dist/dev/db.js +103 -0
  9. package/dist/dev/index.d.ts +16 -0
  10. package/dist/dev/index.js +108 -0
  11. package/dist/dev/logs.d.ts +15 -0
  12. package/dist/dev/logs.js +127 -0
  13. package/dist/dev/process.d.ts +24 -0
  14. package/dist/dev/process.js +34 -0
  15. package/dist/dev/server.d.ts +8 -0
  16. package/dist/dev/server.js +61 -0
  17. package/dist/dev/settings.d.ts +46 -0
  18. package/dist/dev/settings.js +160 -0
  19. package/dist/dev/smoke.d.ts +15 -0
  20. package/dist/dev/smoke.js +50 -0
  21. package/dist/dev/testing.d.ts +19 -0
  22. package/dist/dev/testing.js +18 -0
  23. package/dist/dev/tmux.d.ts +24 -0
  24. package/dist/dev/tmux.js +121 -0
  25. package/dist/eslint/index.d.ts +17 -0
  26. package/dist/eslint/index.js +91 -0
  27. package/dist/eslint/noComments.d.ts +2 -0
  28. package/dist/eslint/noComments.js +27 -0
  29. package/dist/gate/check.d.ts +13 -0
  30. package/dist/gate/check.js +49 -0
  31. package/dist/gate/config.d.ts +34 -0
  32. package/dist/gate/config.js +170 -0
  33. package/dist/gate/contract.d.ts +51 -0
  34. package/dist/gate/contract.js +1 -0
  35. package/dist/gate/guardsStep.d.ts +14 -0
  36. package/dist/gate/guardsStep.js +53 -0
  37. package/dist/gate/plan.d.ts +29 -0
  38. package/dist/gate/plan.js +86 -0
  39. package/dist/gate/report.d.ts +15 -0
  40. package/dist/gate/report.js +65 -0
  41. package/dist/gate/repository.d.ts +3 -0
  42. package/dist/gate/repository.js +37 -0
  43. package/dist/gate/runner.d.ts +10 -0
  44. package/dist/gate/runner.js +75 -0
  45. package/dist/guards/comments/csharp.d.ts +3 -0
  46. package/dist/guards/comments/csharp.js +163 -0
  47. package/dist/guards/comments/css.d.ts +3 -0
  48. package/dist/guards/comments/css.js +11 -0
  49. package/dist/guards/comments/eslint.d.ts +2 -0
  50. package/dist/guards/comments/eslint.js +81 -0
  51. package/dist/guards/comments/hash.d.ts +3 -0
  52. package/dist/guards/comments/hash.js +72 -0
  53. package/dist/guards/comments/index.d.ts +2 -0
  54. package/dist/guards/comments/index.js +18 -0
  55. package/dist/guards/comments/json.d.ts +3 -0
  56. package/dist/guards/comments/json.js +13 -0
  57. package/dist/guards/comments/markup.d.ts +3 -0
  58. package/dist/guards/comments/markup.js +14 -0
  59. package/dist/guards/comments/scan.d.ts +19 -0
  60. package/dist/guards/comments/scan.js +84 -0
  61. package/dist/guards/comments/sql.d.ts +3 -0
  62. package/dist/guards/comments/sql.js +11 -0
  63. package/dist/guards/comments/switches.d.ts +3 -0
  64. package/dist/guards/comments/switches.js +30 -0
  65. package/dist/guards/criteria/criteriaKinds.d.ts +2 -0
  66. package/dist/guards/criteria/criteriaKinds.js +45 -0
  67. package/dist/guards/criteria/index.d.ts +2 -0
  68. package/dist/guards/criteria/index.js +2 -0
  69. package/dist/guards/database/connectionHost.d.ts +2 -0
  70. package/dist/guards/database/connectionHost.js +30 -0
  71. package/dist/guards/database/index.d.ts +2 -0
  72. package/dist/guards/database/index.js +3 -0
  73. package/dist/guards/database/migrationsUnchanged.d.ts +2 -0
  74. package/dist/guards/database/migrationsUnchanged.js +56 -0
  75. package/dist/guards/dotnet/appsettingsBound.d.ts +2 -0
  76. package/dist/guards/dotnet/appsettingsBound.js +43 -0
  77. package/dist/guards/dotnet/bannedNugetPackages.d.ts +2 -0
  78. package/dist/guards/dotnet/bannedNugetPackages.js +51 -0
  79. package/dist/guards/dotnet/index.d.ts +2 -0
  80. package/dist/guards/dotnet/index.js +4 -0
  81. package/dist/guards/dotnet/msbuild.d.ts +5 -0
  82. package/dist/guards/dotnet/msbuild.js +17 -0
  83. package/dist/guards/dotnet/testContext.d.ts +2 -0
  84. package/dist/guards/dotnet/testContext.js +12 -0
  85. package/dist/guards/dotnet/unusedNugetVersions.d.ts +2 -0
  86. package/dist/guards/dotnet/unusedNugetVersions.js +21 -0
  87. package/dist/guards/index.d.ts +2 -0
  88. package/dist/guards/index.js +6 -0
  89. package/dist/guards/repository/agentsFile.d.ts +3 -0
  90. package/dist/guards/repository/agentsFile.js +56 -0
  91. package/dist/guards/repository/bannedNpmPackages.d.ts +2 -0
  92. package/dist/guards/repository/bannedNpmPackages.js +43 -0
  93. package/dist/guards/repository/composePorts.d.ts +6 -0
  94. package/dist/guards/repository/composePorts.js +57 -0
  95. package/dist/guards/repository/dependencyDirection.d.ts +2 -0
  96. package/dist/guards/repository/dependencyDirection.js +87 -0
  97. package/dist/guards/repository/docsPaths.d.ts +2 -0
  98. package/dist/guards/repository/docsPaths.js +54 -0
  99. package/dist/guards/repository/forbiddenNames.d.ts +4 -0
  100. package/dist/guards/repository/forbiddenNames.js +69 -0
  101. package/dist/guards/repository/hooks.d.ts +3 -0
  102. package/dist/guards/repository/hooks.js +86 -0
  103. package/dist/guards/repository/imagePins.d.ts +3 -0
  104. package/dist/guards/repository/imagePins.js +68 -0
  105. package/dist/guards/repository/index.d.ts +2 -0
  106. package/dist/guards/repository/index.js +32 -0
  107. package/dist/guards/repository/justModules.d.ts +2 -0
  108. package/dist/guards/repository/justModules.js +36 -0
  109. package/dist/guards/repository/noRawColors.d.ts +2 -0
  110. package/dist/guards/repository/noRawColors.js +29 -0
  111. package/dist/guards/repository/packageManifests.d.ts +13 -0
  112. package/dist/guards/repository/packageManifests.js +26 -0
  113. package/dist/guards/repository/repositoryLayout.d.ts +3 -0
  114. package/dist/guards/repository/repositoryLayout.js +75 -0
  115. package/dist/guards/repository/requiredFiles.d.ts +6 -0
  116. package/dist/guards/repository/requiredFiles.js +78 -0
  117. package/dist/guards/repository/scriptsCalled.d.ts +3 -0
  118. package/dist/guards/repository/scriptsCalled.js +39 -0
  119. package/dist/guards/repository/scriptsHelp.d.ts +2 -0
  120. package/dist/guards/repository/scriptsHelp.js +37 -0
  121. package/dist/guards/repository/testRepository.d.ts +4 -0
  122. package/dist/guards/repository/testRepository.js +39 -0
  123. package/dist/guards/repository/text.d.ts +20 -0
  124. package/dist/guards/repository/text.js +33 -0
  125. package/dist/guards/repository/vsCodeSettings.d.ts +3 -0
  126. package/dist/guards/repository/vsCodeSettings.js +49 -0
  127. package/dist/profiles/contract.d.ts +5 -0
  128. package/dist/profiles/contract.js +124 -0
  129. package/dist/profiles/criteria.d.ts +25 -0
  130. package/dist/profiles/criteria.js +162 -0
  131. package/dist/profiles/database.d.ts +4 -0
  132. package/dist/profiles/database.js +23 -0
  133. package/dist/profiles/dotnet.d.ts +5 -0
  134. package/dist/profiles/dotnet.js +56 -0
  135. package/dist/profiles/everyRepository.d.ts +2 -0
  136. package/dist/profiles/everyRepository.js +32 -0
  137. package/dist/profiles/index.d.ts +2 -0
  138. package/dist/profiles/index.js +21 -0
  139. package/dist/profiles/library.d.ts +7 -0
  140. package/dist/profiles/library.js +132 -0
  141. package/dist/profiles/node.d.ts +5 -0
  142. package/dist/profiles/node.js +79 -0
  143. package/dist/profiles/presets/knip.d.ts +11 -0
  144. package/dist/profiles/presets/knip.js +29 -0
  145. package/dist/profiles/presets/playwright.d.ts +68 -0
  146. package/dist/profiles/presets/playwright.js +37 -0
  147. package/dist/profiles/presets/prettier.d.ts +12 -0
  148. package/dist/profiles/presets/prettier.js +7 -0
  149. package/dist/profiles/presets/tsconfig/browser.json +11 -0
  150. package/dist/profiles/presets/tsconfig/node.json +8 -0
  151. package/dist/profiles/presets/tsconfig/strict.json +17 -0
  152. package/dist/profiles/presets/vitest.d.ts +36 -0
  153. package/dist/profiles/presets/vitest.js +16 -0
  154. package/dist/profiles/shell.d.ts +10 -0
  155. package/dist/profiles/shell.js +62 -0
  156. package/dist/profiles/web.d.ts +2 -0
  157. package/dist/profiles/web.js +17 -0
  158. package/dist/session/guardEdit.d.ts +19 -0
  159. package/dist/session/guardEdit.js +96 -0
  160. package/dist/session/preCommit.d.ts +16 -0
  161. package/dist/session/preCommit.js +33 -0
  162. package/dist/session/stop.d.ts +8 -0
  163. package/dist/session/stop.js +39 -0
  164. package/package.json +97 -3
  165. package/schema/suwgate.schema.json +196 -0
@@ -0,0 +1,124 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { DOTNET_TEST } from "./dotnet.js";
4
+ import { PNPM_INSTALL } from "./node.js";
5
+ import { has, quoted, read, script, tracked } from "./shell.js";
6
+ const CONTRACT = "contract/openapi.json";
7
+ const CONTRACT_VERSION = "contract/package.json";
8
+ const TYPES = "src/api/openapi.d.ts";
9
+ export const API_CONTRACT = "api-contract";
10
+ const GENERATOR = "Microsoft.Extensions.ApiDescription.Server";
11
+ const TAGGED = ["*.cs", "*.test.ts", "*.test.tsx", "*.e2e.ts"];
12
+ const TRAIT_TAG = /"contract"\s*,\s*"([^"@]+@[^"]+)"/;
13
+ const TITLE_TAG = /["'`]contract ([^ :@"'`]+@[^ :"'`]+)/;
14
+ const PINNED_VERSION = /^[^@]+@v?\d+(\.\d+){0,2}$/;
15
+ function fail(message) {
16
+ return `echo ${quoted(message)} >&2; exit 1`;
17
+ }
18
+ function webApp(context) {
19
+ if (!context.profiles.includes("web"))
20
+ return null;
21
+ const directory = path.join(context.root, context.directories.web ?? "");
22
+ return existsSync(path.join(directory, TYPES)) ? directory : null;
23
+ }
24
+ export function apiContract(context) {
25
+ if (!has(context, CONTRACT))
26
+ return null;
27
+ const servers = tracked(context, ["*.csproj"]).filter((project) => (read(context, project) ?? "").includes(GENERATOR));
28
+ const [server, ...others] = servers;
29
+ if (server === undefined)
30
+ return fail(`${CONTRACT} is there, but no project writes it: reference ${GENERATOR} in the server's project`);
31
+ if (others.length > 0)
32
+ return fail(`${CONTRACT} has more than one project that could write it (${servers.join(", ")}): keep ${GENERATOR} in the server's project only`);
33
+ const name = path.basename(server, ".csproj");
34
+ const document = `"$work"/${quoted(`${name}.json`)}`;
35
+ const web = webApp(context);
36
+ const types = web === null ? "" : path.join(web, TYPES);
37
+ return script([
38
+ 'work="$(mktemp -d)"',
39
+ "trap 'rm -rf \"$work\"' EXIT",
40
+ `rm -f ${quoted(path.join(path.dirname(server), "obj", `${name}.OpenApiFiles.cache`))}`,
41
+ `dotnet build ${quoted(server)} --nologo -v quiet -p:OpenApiGenerateDocumentsOnBuild=true -p:OpenApiDocumentsDirectory="$work" >"$work/build.log" || { cat "$work/build.log" >&2; exit 1; }`,
42
+ "stale=()",
43
+ `diff -q ${document} ${CONTRACT} >/dev/null 2>&1 || stale+=(${quoted(path.relative(context.root, path.join(context.cwd, CONTRACT)))})`,
44
+ ...(web === null
45
+ ? []
46
+ : [
47
+ `digest="$(sha256sum ${document} | cut -d' ' -f1)"`,
48
+ `(cd ${quoted(web)} && pnpm exec openapi-typescript ${document} --output "$work/schema.d.ts" >/dev/null)`,
49
+ `if ! head -n 1 ${quoted(types)} | grep -q "sha256 $digest" || ! tail -n +2 ${quoted(types)} | diff -q - "$work/schema.d.ts" >/dev/null; then stale+=(${quoted(path.relative(context.root, types))}); fi`,
50
+ ]),
51
+ 'if [ ${#stale[@]} -gt 0 ]; then echo "${stale[*]} out of date with the server\'s API — regenerate them (just api-types)" >&2; exit 1; fi',
52
+ `echo "API contract${web === null ? "" : " and types"} up to date"`,
53
+ ]);
54
+ }
55
+ const API_VERSION = script([
56
+ 'if ! git rev-parse --verify -q master >/dev/null && ! git rev-parse --verify -q origin/master >/dev/null; then echo "no master yet: nothing to compare the contract with"; exit 0; fi',
57
+ "if git show-ref --verify --quiet refs/heads/master; then base=master; else base=origin/master; fi",
58
+ 'work="$(mktemp -d)"',
59
+ "trap 'rm -rf \"$work\"' EXIT",
60
+ `if ! git show "$base:./${CONTRACT}" >"$work/base.json" 2>/dev/null; then echo "no ${CONTRACT} on $base yet; nothing to compare against."; exit 0; fi`,
61
+ `if git diff --quiet --no-index "$work/base.json" ${CONTRACT} 2>/dev/null; then echo "API contract unchanged since $base"; exit 0; fi`,
62
+ `if ! oasdiff breaking "$work/base.json" ${CONTRACT} >"$work/load.log" 2>&1; then cat "$work/load.log" >&2; echo "oasdiff could not compare the documents (see above); is ${CONTRACT} valid JSON? Regenerate it (just api-types)" >&2; exit 1; fi`,
63
+ `version_of() { node -e 'let text = ""; process.stdin.on("data", (chunk) => (text += chunk)).on("end", () => console.log(JSON.parse(text).version));'; }`,
64
+ `now="$(version_of <${CONTRACT_VERSION})"`,
65
+ `was="$(git show "$base:./${CONTRACT_VERSION}" 2>/dev/null | version_of 2>/dev/null || true)"`,
66
+ `version_is_higher() { [ "$1" != "$2" ] && [ "$(printf '%s\\n%s\\n' "$1" "$2" | sort -V | tail -n 1)" = "$1" ]; }`,
67
+ `if oasdiff breaking "$work/base.json" ${CONTRACT} --fail-on ERR; then`,
68
+ ' if [ -n "$was" ] && ! version_is_higher "$now" "$was"; then',
69
+ ` echo "the API contract changed since $base, but ${CONTRACT_VERSION} still says $now. Raise its minor version (a compatible change), so a consumer can pin the new one." >&2`,
70
+ " exit 1",
71
+ " fi",
72
+ ' echo "API contract changed since $base, compatibly (nothing breaks a consumer), as version $now"',
73
+ "else",
74
+ ' if [ -n "$was" ] && [ "${now%%.*}" -gt "${was%%.*}" ]; then',
75
+ ' echo "API contract breaks consumers since $base (see above), as the new major version $now: every consumer moves to it on purpose."',
76
+ " exit 0",
77
+ " fi",
78
+ ` echo "the API contract breaks consumers (see above). Keep the old shape and add the new one beside it, or, agreed with every consumer, raise the major version in ${CONTRACT_VERSION}." >&2`,
79
+ " exit 1",
80
+ "fi",
81
+ ]);
82
+ function pins(context) {
83
+ return tracked({ ...context, cwd: context.root }, TAGGED).flatMap((file) => (read({ ...context, cwd: context.root }, file) ?? "").split("\n").flatMap((line, index) => {
84
+ const tag = TRAIT_TAG.exec(line)?.[1] ?? TITLE_TAG.exec(line)?.[1];
85
+ return tag === undefined ? [] : [{ tag, where: `${file}:${index + 1}` }];
86
+ }));
87
+ }
88
+ export function contractPins(context) {
89
+ const found = pins(context);
90
+ if (found.length === 0)
91
+ return null;
92
+ const malformed = found.filter((pin) => !PINNED_VERSION.test(pin.tag));
93
+ const lines = [
94
+ ...found.map((pin) => `${pin.tag.padEnd(24)} ${pin.where}`),
95
+ ...malformed.map((pin) => `${pin.where}: the contract tag ${pin.tag} pins no version: write <contract>@v<major> or <contract>@<major>.<minor>.<patch>, the version the test adapts to`),
96
+ ];
97
+ return `printf '%s\\n' ${lines.map(quoted).join(" ")}${malformed.length === 0 ? "" : "; exit 1"}`;
98
+ }
99
+ export const contractSteps = [
100
+ {
101
+ id: API_CONTRACT,
102
+ title: `the API contract and the web app's types up to date with the server (${CONTRACT}, ${TYPES}, openapi-typescript)`,
103
+ profile: "dotnet",
104
+ needs: ["dotnet"],
105
+ after: [DOTNET_TEST, PNPM_INSTALL],
106
+ run: apiContract,
107
+ limitSeconds: 300,
108
+ },
109
+ {
110
+ id: "api-version",
111
+ title: `the API contract's version right for what changed since master (${CONTRACT_VERSION}, oasdiff breaking)`,
112
+ profile: "dotnet",
113
+ needs: ["oasdiff", "node"],
114
+ after: [API_CONTRACT],
115
+ run: (context) => (has(context, CONTRACT) ? API_VERSION : null),
116
+ limitSeconds: 60,
117
+ },
118
+ {
119
+ id: "contract-pins",
120
+ title: "the tests that pin another repository's contract name a version (contract <name>@<version>)",
121
+ run: contractPins,
122
+ limitSeconds: 60,
123
+ },
124
+ ];
@@ -0,0 +1,25 @@
1
+ import type { Skip, Step, StepContext } from "../gate/contract.ts";
2
+ interface Kind {
3
+ kind: string;
4
+ paths: string[];
5
+ how: string;
6
+ }
7
+ interface Extras {
8
+ specs?: string;
9
+ prose?: string[];
10
+ kinds?: Kind[];
11
+ }
12
+ export interface CriteriaConfig {
13
+ specs: string;
14
+ prose: string[];
15
+ kinds: Kind[];
16
+ }
17
+ export interface ToolPin {
18
+ repository: string;
19
+ commit: string;
20
+ sha256: string;
21
+ }
22
+ export declare function criteriaConfig(context: StepContext, extras: Extras): CriteriaConfig;
23
+ export declare function criteria(pin: ToolPin): (context: StepContext) => string | Skip;
24
+ export declare const criteriaStep: Step;
25
+ export {};
@@ -0,0 +1,162 @@
1
+ import { createHash } from "node:crypto";
2
+ import { execFileSync } from "node:child_process";
3
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync } from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import path from "node:path";
6
+ import { CONSUMER, VISUAL_CONFIG } from "./library.js";
7
+ import { onPath, quoted, read, script, tracked } from "./shell.js";
8
+ const CRITERIA_FILE = "criteria.json";
9
+ const VDOC = {
10
+ repository: "Manomenu/suwalski-agent-plugin",
11
+ commit: "02a5f3d98c5caa9f69af3fa0508efa566a6d78f2",
12
+ sha256: "d83e3a4e7c7f31bbe28d7eacc8eb5dbab8ba4298601839e827638ce716a91088",
13
+ };
14
+ const XUNIT = /<PackageReference\s+Include="xunit/i;
15
+ const TITLE = 'the id in the title: it("<id>: …")';
16
+ function prefix(context, profile) {
17
+ const directory = context.directories[profile];
18
+ return directory === undefined ? "" : `${directory}/`;
19
+ }
20
+ function scripts(directory) {
21
+ return [
22
+ { kind: "lint (eslint)", paths: [`${directory}eslint.config.js`], how: "// <id> on the line above the rule" },
23
+ { kind: "type check (tsc)", paths: [`${directory}tsconfig*.json`], how: "// <id> on the line above the option" },
24
+ ];
25
+ }
26
+ function dotnetKinds(context) {
27
+ const directory = prefix(context, "dotnet");
28
+ const root = { ...context, cwd: context.root };
29
+ const testProjects = tracked(root, ["*.csproj"])
30
+ .filter((project) => XUNIT.test(read(root, project) ?? ""))
31
+ .map((project) => path.posix.dirname(project));
32
+ return [
33
+ ...(testProjects.length === 0
34
+ ? []
35
+ : [
36
+ {
37
+ kind: "test (xunit)",
38
+ paths: testProjects.map((folder) => `${folder}/**/*.cs`),
39
+ how: '[Trait("criterion", "<id>")] on the test',
40
+ },
41
+ ]),
42
+ {
43
+ kind: "lint (.NET analyzer)",
44
+ paths: [...new Set([".editorconfig", `${directory}.editorconfig`])],
45
+ how: "# <id> on its own line above the rule",
46
+ },
47
+ { kind: "banned API", paths: [`${directory}BannedSymbols.txt`], how: "the id in the message: P:…;<id> use …" },
48
+ { kind: "build rule", paths: [`${directory}Directory.Build.props`], how: "<!-- <id> --> above the property" },
49
+ ];
50
+ }
51
+ function webKinds(context) {
52
+ const directory = prefix(context, "web");
53
+ return [
54
+ { kind: "e2e test (playwright)", paths: [`${directory}src/**/*.e2e.ts`], how: 'the id in the title: test("<id>: …")' },
55
+ { kind: "web test (vitest)", paths: [`${directory}src/**/*.test.ts`, `${directory}src/**/*.test.tsx`], how: TITLE },
56
+ ...scripts(directory),
57
+ ];
58
+ }
59
+ function libraryKinds(context) {
60
+ const directory = prefix(context, "library");
61
+ return [
62
+ { kind: "unit test (vitest)", paths: [`${directory}src/**/*.test.ts`, `${directory}src/**/*.test.tsx`], how: TITLE },
63
+ {
64
+ kind: "story test (vitest, Chromium)",
65
+ paths: [`${directory}src/**/*.stories.tsx`],
66
+ how: 'the id in the story\'s name: name: "<id>: …"',
67
+ },
68
+ {
69
+ kind: "visual test (playwright)",
70
+ paths: [`${directory}${path.posix.dirname(VISUAL_CONFIG)}/*.visual.ts`],
71
+ how: 'the id in the title: test("<id>: …")',
72
+ },
73
+ { kind: "consumer test (playwright)", paths: [`${directory}${CONSUMER}/*.spec.ts`], how: 'the id in the title: test("<id>: …")' },
74
+ ...scripts(directory),
75
+ ];
76
+ }
77
+ const KINDS_BY_PROFILE = {
78
+ web: webKinds,
79
+ library: libraryKinds,
80
+ dotnet: dotnetKinds,
81
+ database: () => [],
82
+ };
83
+ function merged(kinds) {
84
+ const byName = new Map();
85
+ for (const kind of kinds) {
86
+ const known = byName.get(kind.kind);
87
+ byName.set(kind.kind, known === undefined ? { ...kind } : { ...known, paths: [...new Set([...known.paths, ...kind.paths])] });
88
+ }
89
+ return [...byName.values()];
90
+ }
91
+ function defaultKinds(context) {
92
+ return merged(context.profiles.flatMap((profile) => KINDS_BY_PROFILE[profile](context)));
93
+ }
94
+ export function criteriaConfig(context, extras) {
95
+ return {
96
+ specs: extras.specs ?? "docs/visual/spec",
97
+ prose: extras.prose ?? ["docs/**", "**/*.md"],
98
+ kinds: merged([...(extras.kinds ?? []), ...defaultKinds(context)]),
99
+ };
100
+ }
101
+ function fail(message) {
102
+ return `echo ${quoted(message)} >&2; exit 1`;
103
+ }
104
+ function download(pin, tool) {
105
+ const url = `https://raw.githubusercontent.com/${pin.repository}/${pin.commit}/plugins/suwagent/scripts/vdoc.py`;
106
+ const part = `${tool}.part`;
107
+ try {
108
+ mkdirSync(path.dirname(tool), { recursive: true });
109
+ execFileSync("curl", ["-sSfL", "--max-time", "30", "-o", part, url], { stdio: "ignore" });
110
+ renameSync(part, tool);
111
+ return null;
112
+ }
113
+ catch {
114
+ rmSync(part, { force: true });
115
+ return { skip: `the pinned vdoc.py cannot be downloaded from ${url} (no network?)` };
116
+ }
117
+ }
118
+ function cacheFolder() {
119
+ const configured = process.env["XDG_CACHE_HOME"];
120
+ return configured === undefined || configured === "" ? path.join(homedir(), ".cache") : configured;
121
+ }
122
+ export function criteria(pin) {
123
+ return (context) => {
124
+ if (!onPath("python3"))
125
+ return { skip: "python3 not installed" };
126
+ const tool = path.join(cacheFolder(), "suwagent", `vdoc-${pin.commit}.py`);
127
+ if (!existsSync(tool)) {
128
+ if (!onPath("curl"))
129
+ return { skip: "curl not installed: it downloads the pinned vdoc.py" };
130
+ const failed = download(pin, tool);
131
+ if (failed !== null)
132
+ return failed;
133
+ }
134
+ if (createHash("sha256").update(readFileSync(tool)).digest("hex") !== pin.sha256) {
135
+ return fail(`${tool} does not match the SHA-256 suwgate pins: delete it and run again; if it still differs, the pin in suwgate is wrong`);
136
+ }
137
+ let extras = {};
138
+ const text = read({ ...context, cwd: context.root }, CRITERIA_FILE);
139
+ if (text !== null) {
140
+ try {
141
+ extras = JSON.parse(text);
142
+ }
143
+ catch (error) {
144
+ return fail(`${CRITERIA_FILE} is not valid JSON (${error instanceof Error ? error.message : String(error)}): fix it`);
145
+ }
146
+ }
147
+ const config = path.join(cacheFolder(), "suwgate", `criteria-${createHash("sha256").update(context.root).digest("hex").slice(0, 16)}.json`);
148
+ return script([
149
+ `mkdir -p ${quoted(path.dirname(config))}`,
150
+ `cat >${quoted(config)} <<'SUWGATE_CRITERIA'`,
151
+ JSON.stringify(criteriaConfig(context, extras), null, 2),
152
+ "SUWGATE_CRITERIA",
153
+ `python3 ${quoted(tool)} criteria --root ${quoted(context.root)} --config ${quoted(config)}`,
154
+ ]);
155
+ };
156
+ }
157
+ export const criteriaStep = {
158
+ id: "criteria",
159
+ title: "acceptance criteria guarded (vdoc.py criteria, the kinds of the profiles and criteria.json)",
160
+ run: criteria(VDOC),
161
+ limitSeconds: 60,
162
+ };
@@ -0,0 +1,4 @@
1
+ import type { Step, StepContext } from "../gate/contract.ts";
2
+ export declare const DATABASE_UP = "database-up";
3
+ export declare function composeFile(context: StepContext): boolean;
4
+ export declare const databaseSteps: readonly Step[];
@@ -0,0 +1,23 @@
1
+ import { has, script } from "./shell.js";
2
+ export const DATABASE_UP = "database-up";
3
+ const COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
4
+ const UP = script([
5
+ 'if [ -n "${CI:-}" ]; then echo "CI: the workflow provides the database as a service"; exit 0; fi',
6
+ "docker compose --profile db up -d --wait db >/dev/null 2>&1 || {",
7
+ ' echo "postgres did not start — see: docker compose --profile db logs db" >&2',
8
+ " exit 1",
9
+ "}",
10
+ ]);
11
+ export function composeFile(context) {
12
+ return COMPOSE_FILES.some((file) => has(context, file));
13
+ }
14
+ export const databaseSteps = [
15
+ {
16
+ id: DATABASE_UP,
17
+ title: "the local database for the tests (docker compose --profile db up --wait db; CI provides its own)",
18
+ profile: "database",
19
+ needs: ["docker"],
20
+ run: (context) => (composeFile(context) ? UP : null),
21
+ limitSeconds: 120,
22
+ },
23
+ ];
@@ -0,0 +1,5 @@
1
+ import type { Step, StepContext } from "../gate/contract.ts";
2
+ export declare const DOTNET_BUILD = "dotnet-build";
3
+ export declare const DOTNET_TEST = "dotnet-test";
4
+ export declare function guardTests(context: StepContext): string | null;
5
+ export declare const dotnetSteps: readonly Step[];
@@ -0,0 +1,56 @@
1
+ import { DATABASE_UP } from "./database.js";
2
+ import { changedIn, quoted, read, tracked, withChanged } from "./shell.js";
3
+ 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 TEST_PROJECT = /<PackageReference\b[^>]*Include="xunit\.v3"|<IsTestProject>true<\/IsTestProject>/;
6
+ const BUILD = "dotnet build --nologo -v quiet";
7
+ const TEST = "dotnet test --no-build --no-progress";
8
+ export const DOTNET_BUILD = "dotnet-build";
9
+ export const DOTNET_TEST = "dotnet-test";
10
+ function dotnetChanged(context) {
11
+ return changedIn(context, DOTNET_INPUT).length > 0;
12
+ }
13
+ export function guardTests(context) {
14
+ if (!dotnetChanged(context))
15
+ return null;
16
+ const projects = tracked(context, ["*.csproj"]).filter((project) => {
17
+ const text = read(context, project) ?? "";
18
+ return GUARD_PACKAGE.test(text) && TEST_PROJECT.test(text);
19
+ });
20
+ if (projects.length === 0)
21
+ return null;
22
+ return projects.map((project) => `dotnet test --project ${quoted(project)} --no-build --no-progress`).join(" && ");
23
+ }
24
+ export const dotnetSteps = [
25
+ {
26
+ id: DOTNET_BUILD,
27
+ title: "build (compiler, analyzers, banned APIs, NuGet audit)",
28
+ profile: "dotnet",
29
+ needs: ["dotnet"],
30
+ run: BUILD,
31
+ quick: (context) => (dotnetChanged(context) ? BUILD : null),
32
+ limitSeconds: 300,
33
+ },
34
+ {
35
+ id: "dotnet-format",
36
+ title: "format C# (csharpier check)",
37
+ profile: "dotnet",
38
+ needs: ["dotnet"],
39
+ run: "dotnet tool restore >/dev/null && dotnet csharpier check .",
40
+ quick: (context) => {
41
+ const command = withChanged(context, /\.cs$/, "dotnet csharpier check");
42
+ return command === null ? null : `dotnet tool restore >/dev/null && ${command}`;
43
+ },
44
+ limitSeconds: 120,
45
+ },
46
+ {
47
+ id: DOTNET_TEST,
48
+ title: "tests (dotnet test, xUnit v3; --quick: the projects that test with Suwgate.Architecture or Suwgate.Database)",
49
+ profile: "dotnet",
50
+ needs: ["dotnet"],
51
+ after: [DOTNET_BUILD, DATABASE_UP],
52
+ run: TEST,
53
+ quick: guardTests,
54
+ limitSeconds: 600,
55
+ },
56
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Step } from "../gate/contract.ts";
2
+ export declare const everyRepositorySteps: readonly Step[];
@@ -0,0 +1,32 @@
1
+ import { criteriaStep } from "./criteria.js";
2
+ import { composeFile } from "./database.js";
3
+ import { withChanged } from "./shell.js";
4
+ const SHELL_SCRIPT = /\.sh$|^\.githooks\/[^/]+$/;
5
+ export const everyRepositorySteps = [
6
+ {
7
+ id: "compose",
8
+ title: "the compose stack resolves, with and without the db profile (docker compose config)",
9
+ needs: ["docker"],
10
+ run: (context) => (composeFile(context) ? "docker compose config --quiet && docker compose --profile db config --quiet" : null),
11
+ limitSeconds: 120,
12
+ },
13
+ criteriaStep,
14
+ {
15
+ id: "shellcheck",
16
+ title: "shell scripts (shellcheck)",
17
+ needs: ["shellcheck"],
18
+ run: "git ls-files --cached --others --exclude-standard -z -- '*.sh' '.githooks/*' | xargs -0 -r shellcheck -S warning",
19
+ quick: (context) => withChanged(context, SHELL_SCRIPT, "shellcheck -S warning"),
20
+ limitSeconds: 120,
21
+ },
22
+ {
23
+ id: "gitleaks",
24
+ title: "secrets in git and in the working tree (gitleaks)",
25
+ needs: ["gitleaks"],
26
+ run: [
27
+ "if git rev-parse --verify -q HEAD >/dev/null; then gitleaks git . --no-banner --redact --log-level warn; fi",
28
+ "gitleaks dir . --no-banner --redact --log-level warn --max-target-megabytes 1",
29
+ ].join(" && "),
30
+ limitSeconds: 300,
31
+ },
32
+ ];
@@ -0,0 +1,2 @@
1
+ import { type Profile, type Step } from "../gate/contract.ts";
2
+ export declare function stepsFor(profiles: readonly Profile[]): Step[];
@@ -0,0 +1,21 @@
1
+ import { PROFILES } from "../gate/contract.js";
2
+ import { contractSteps } from "./contract.js";
3
+ import { databaseSteps } from "./database.js";
4
+ import { dotnetSteps } from "./dotnet.js";
5
+ import { everyRepositorySteps } from "./everyRepository.js";
6
+ import { librarySteps } from "./library.js";
7
+ import { nodeSteps } from "./node.js";
8
+ import { webSteps } from "./web.js";
9
+ const BY_PROFILE = {
10
+ web: [...nodeSteps("web"), ...webSteps, ...contractSteps],
11
+ library: [...nodeSteps("library"), ...librarySteps],
12
+ dotnet: [...dotnetSteps, ...contractSteps],
13
+ database: databaseSteps,
14
+ };
15
+ export function stepsFor(profiles) {
16
+ const steps = [
17
+ ...PROFILES.filter((profile) => profiles.includes(profile)).flatMap((profile) => BY_PROFILE[profile]),
18
+ ...everyRepositorySteps,
19
+ ];
20
+ return steps.filter((step, index) => steps.findIndex((other) => other.id === step.id) === index);
21
+ }
@@ -0,0 +1,7 @@
1
+ import type { Step, StepContext } from "../gate/contract.ts";
2
+ export declare const VISUAL_CONFIG = "visual/playwright.config.ts";
3
+ export declare const CONSUMER = "gate/consumer";
4
+ export declare function visual(context: StepContext): string | null;
5
+ export declare function attw(context: StepContext): string;
6
+ export declare function consumerApp(context: StepContext): string | null;
7
+ export declare const librarySteps: readonly Step[];
@@ -0,0 +1,132 @@
1
+ import { PNPM_INSTALL } from "./node.js";
2
+ import { has, quoted, read, script } from "./shell.js";
3
+ const CHANGESET = script([
4
+ 'base=""',
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",
6
+ 'if [ -z "$base" ] || [ "$(git rev-parse HEAD 2>/dev/null)" = "$(git rev-parse "$base")" ]; then echo "on $base itself or no master yet: nothing to compare with"; exit 0; fi',
7
+ 'pnpm exec changeset status --since "$base"',
8
+ ]);
9
+ const PUBLINT = script([
10
+ 'work="$(mktemp -d)"',
11
+ "trap 'rm -rf \"$work\"' EXIT",
12
+ 'pnpm pack --pack-destination "$work" >/dev/null',
13
+ 'pnpm exec publint "$work"/*.tgz --strict',
14
+ ]);
15
+ const STORYBOOK = ".storybook";
16
+ export const VISUAL_CONFIG = "visual/playwright.config.ts";
17
+ export const CONSUMER = "gate/consumer";
18
+ function consumerAppCommand(build) {
19
+ return script([
20
+ 'work="$(mktemp -d)"',
21
+ "trap 'rm -rf \"$work\"' EXIT",
22
+ 'pnpm pack --pack-destination "$work" >/dev/null',
23
+ 'tarball="$(ls "$work"/*.tgz)"',
24
+ `cp -r ${CONSUMER}/app "$work/app"`,
25
+ `(cd "$work/app" && pnpm add "$tarball" --silent && ${build})`,
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`,
28
+ ]);
29
+ }
30
+ function stories(context) {
31
+ return has(context, STORYBOOK) ? "pnpm exec vitest run --project stories" : null;
32
+ }
33
+ function playwrightVersion(context) {
34
+ const manifest = read(context, "node_modules/@playwright/test/package.json");
35
+ if (manifest === null)
36
+ return null;
37
+ const { version } = JSON.parse(manifest);
38
+ return typeof version === "string" ? version : null;
39
+ }
40
+ export function visual(context) {
41
+ if (!has(context, STORYBOOK) || !has(context, VISUAL_CONFIG))
42
+ return null;
43
+ const version = playwrightVersion(context);
44
+ if (version === null) {
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
+ }
47
+ return script([
48
+ "pnpm exec storybook build --quiet -o storybook-static >/dev/null",
49
+ `docker run --rm --init --ipc=host --security-opt label=disable -v "$PWD:/work" -w /work -e CI mcr.microsoft.com/playwright:v${version}-noble node_modules/.bin/playwright test -c ${VISUAL_CONFIG}`,
50
+ ]);
51
+ }
52
+ const NOT_A_MODULE = /\.(css|json)$/;
53
+ function targets(entry) {
54
+ if (typeof entry === "string")
55
+ return [entry];
56
+ if (entry === null || typeof entry !== "object")
57
+ return [];
58
+ return Object.values(entry).flatMap(targets);
59
+ }
60
+ export function attw(context) {
61
+ const manifest = JSON.parse(read(context, "package.json") ?? "{}");
62
+ const exportsField = manifest.exports;
63
+ const entries = exportsField !== null && typeof exportsField === "object" && !Array.isArray(exportsField) ? exportsField : {};
64
+ const excluded = Object.entries(entries)
65
+ .filter(([key, entry]) => key.startsWith(".") && targets(entry).length > 0 && targets(entry).every((target) => NOT_A_MODULE.test(target)))
66
+ .map(([key]) => quoted(key));
67
+ return `pnpm exec attw --pack . --profile esm-only${excluded.length === 0 ? "" : ` --exclude-entrypoints ${excluded.join(" ")}`}`;
68
+ }
69
+ export function consumerApp(context) {
70
+ const manifest = read(context, `${CONSUMER}/app/package.json`);
71
+ if (manifest === null || !has(context, `${CONSUMER}/playwright.config.ts`))
72
+ return null;
73
+ const { scripts } = JSON.parse(manifest);
74
+ return consumerAppCommand(scripts?.["build"] === undefined ? "pnpm exec vite build --logLevel warn" : "pnpm run build");
75
+ }
76
+ const after = [PNPM_INSTALL];
77
+ export const librarySteps = [
78
+ {
79
+ id: "stories",
80
+ title: "stories as tests with axe (vitest project stories, Chromium)",
81
+ profile: "library",
82
+ needs: ["pnpm"],
83
+ after,
84
+ run: stories,
85
+ limitSeconds: 600,
86
+ },
87
+ {
88
+ id: "publint",
89
+ title: "the package as npm publishes it (pnpm pack, publint --strict)",
90
+ profile: "library",
91
+ needs: ["pnpm"],
92
+ after,
93
+ run: PUBLINT,
94
+ limitSeconds: 300,
95
+ },
96
+ {
97
+ id: "attw",
98
+ title: "the package's types resolve for ESM consumers (attw --pack, CSS and JSON entry points left out)",
99
+ profile: "library",
100
+ needs: ["pnpm"],
101
+ after: ["publint"],
102
+ run: attw,
103
+ limitSeconds: 300,
104
+ },
105
+ {
106
+ id: "consumer-app",
107
+ title: `the package as an app installs it (pnpm pack, ${CONSUMER}/app builds with the tarball, playwright)`,
108
+ profile: "library",
109
+ needs: ["pnpm", "node"],
110
+ after: ["attw"],
111
+ run: consumerApp,
112
+ limitSeconds: 900,
113
+ },
114
+ {
115
+ id: "visual",
116
+ title: "visual regression of every story (storybook build, playwright in the image of the installed version)",
117
+ profile: "library",
118
+ needs: ["pnpm", "docker"],
119
+ after,
120
+ run: visual,
121
+ limitSeconds: 900,
122
+ },
123
+ {
124
+ id: "changeset",
125
+ title: "a changeset for a change of the package since master (changeset status)",
126
+ profile: "library",
127
+ needs: ["pnpm"],
128
+ after,
129
+ run: CHANGESET,
130
+ limitSeconds: 120,
131
+ },
132
+ ];
@@ -0,0 +1,5 @@
1
+ import type { Profile, Step, StepContext } from "../gate/contract.ts";
2
+ export declare const PNPM_INSTALL = "pnpm-install";
3
+ export declare function typecheck(context: StepContext): string;
4
+ export declare function unitTests(context: StepContext): string;
5
+ export declare function nodeSteps(profile: Profile): Step[];