@maniumek/suwgate 0.9.0 → 0.11.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 +184 -284
- package/dist/cli.js +3 -2
- package/dist/dev/index.d.ts +2 -1
- package/dist/dev/index.js +17 -1
- package/dist/dev/process.js +2 -5
- package/dist/dev/settings.d.ts +9 -0
- package/dist/dev/settings.js +40 -3
- package/dist/dev/sibling.d.ts +34 -0
- package/dist/dev/sibling.js +275 -0
- package/dist/guards/dotnet/index.js +8 -1
- package/dist/guards/dotnet/openApiVersions.d.ts +3 -0
- package/dist/guards/dotnet/openApiVersions.js +38 -0
- package/package.json +1 -1
- package/schema/suwgate.schema.json +39 -1
package/README.md
CHANGED
|
@@ -1,169 +1,207 @@
|
|
|
1
|
-
|
|
1
|
+
<picture>
|
|
2
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/hero-dark.png">
|
|
3
|
+
<img alt="suwgate, npm CLI and NuGet guards. One quality gate for every repository: one command runs the steps of its profiles and its guards, configured in one suwgate.yml. Tags: suwgate check, agent hooks, suwgate dev, CI workflows, Renovate preset. Terminal: suwgate check --quick prints PASS, all 8 steps in 4s (14 exceptions in suwgate.yml); suwgate step dotnet-test prints PASS, all 2 steps in 55s. Numbers: 4 profiles (web, library, dotnet, database), 25 steps the profiles bring, 36 repository guards, 14 .NET guards in xUnit, 3 hooks for agents and git, 3 reusable CI workflows." src="docs/visual/board/img/readme/hero-light.png" width="100%">
|
|
4
|
+
</picture>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
suwgate is the one quality gate of a stack of repositories that agents and one developer work on: the CLI
|
|
7
|
+
[`@maniumek/suwgate`](https://www.npmjs.com/package/@maniumek/suwgate) on npm, and the .NET guards `Suwgate.Architecture` and
|
|
8
|
+
`Suwgate.Database` on NuGet. A repository says what it is in `suwgate.yml`; suwgate brings the steps, the guards, the hooks, the
|
|
9
|
+
tool presets, the local dev commands, the CI workflows and the Renovate preset.
|
|
4
10
|
|
|
5
|
-
##
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Node 24 or later, pnpm, and a git repository:
|
|
6
14
|
|
|
7
15
|
```sh
|
|
8
|
-
pnpm add -D @maniumek/suwgate
|
|
9
|
-
pnpm exec suwgate check # the whole gate, the same CI runs
|
|
10
|
-
pnpm exec suwgate check --quick # the guards, and the quick steps for what changed since master
|
|
11
|
-
pnpm exec suwgate step # the steps of this repository, with their titles
|
|
12
|
-
pnpm exec suwgate step e2e -- --headed -g notes # one step and what it needs; after --, arguments for its tool
|
|
16
|
+
pnpm add -D --save-exact @maniumek/suwgate
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
pnpm installs a version only once it is a day old (`minimumReleaseAge`). To take a new suwgate the day it is published, exclude
|
|
16
|
-
|
|
17
|
-
(`@maniumek/suwgate@0.5.0`) has to be edited on every version bump, the name does not.
|
|
19
|
+
pnpm installs a version only once it is a day old (`minimumReleaseAge`). To take a new suwgate the day it is published, exclude the
|
|
20
|
+
package by name in `pnpm-workspace.yaml`: `minimumReleaseAgeExclude: ["@maniumek/suwgate"]`.
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
## Quick start
|
|
20
23
|
|
|
21
|
-
```
|
|
22
|
-
profiles: [web, dotnet, database
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
steps:
|
|
26
|
-
add:
|
|
27
|
-
- name: api-diff
|
|
28
|
-
run: scripts/.internal/api-diff.sh
|
|
29
|
-
after: [dotnet-build]
|
|
30
|
-
skip:
|
|
31
|
-
- step: knip
|
|
32
|
-
reason: the generated API client exports more than the app uses, and knip cannot tell
|
|
33
|
-
exceptions:
|
|
34
|
-
- guard: architecture/interfaces-have-two-implementations
|
|
35
|
-
target: Myapp.Server.Payments.IPaymentGateway
|
|
36
|
-
reason: the payment SDK takes an implementation of this interface; the second one is the SDK's test double
|
|
24
|
+
```sh
|
|
25
|
+
printf 'profiles: [web]\n' > suwgate.yml # or library, dotnet, database, several at once
|
|
26
|
+
pnpm exec suwgate agents-shared # writes AGENTS.shared.md, the rules every repository shares
|
|
27
|
+
pnpm exec suwgate check # the whole gate; every finding says how to fix it
|
|
37
28
|
```
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- `quick.limitSeconds` is the budget of `suwgate check --quick` (default 20): the quick gate fails above it. A machine that is slow
|
|
47
|
-
across the board overrides it with `SUWGATE_QUICK_LIMIT=<seconds>`.
|
|
48
|
-
- `exceptions` let one target through one guard, always with a `reason`; `suwgate check` counts them in its report, and an
|
|
49
|
-
exception that no longer matches anything fails the gate until it is deleted. Two optional fields, for the repository guards
|
|
50
|
-
and the .NET guards alike:
|
|
51
|
-
- `message` narrows it to the target's findings whose message contains that text, so a second finding in the same file still
|
|
52
|
-
fails: `{ guard: no-raw-colors, target: Myapp.Web/src/mail.tsx, message: "#1e66f5", reason: … }`.
|
|
53
|
-
- `once: true` makes it a one-time exception, for a finding that goes away once the change is on master, such as an
|
|
54
|
-
owner-approved edit of an applied migration (`migrations-unchanged`). It holds only while master's `suwgate.yml` does not
|
|
55
|
-
have it, that is on the branch that adds it. After the merge it excepts nothing (a later edit of the same script fails
|
|
56
|
-
again) and is never stale, so the first run on master stays green; the report asks to delete it with the next change.
|
|
57
|
-
- A reason shared by many exceptions can be a YAML anchor (`reason: &sdk the SDK implements it`, then `reason: *sdk`), up to
|
|
58
|
-
10 000 aliases.
|
|
59
|
-
- `guards.skip` turns one whole guard off, always with a `reason`: a repository guard, or a .NET guard (`architecture/*`,
|
|
60
|
-
`database/*`), which `SuwgateGuards.VerifyAll` then does not run and the `dotnet-test` step does not ask evidence for. A
|
|
61
|
-
library, for example: `guards: { skip: [{ guard: architecture/endpoints, reason: a library has no server }] }`.
|
|
62
|
-
- The schema is in the package, `schema/suwgate.schema.json`. VS Code checks the file as you type with
|
|
63
|
-
`"yaml.schemas": { "./node_modules/@maniumek/suwgate/schema/suwgate.schema.json": "suwgate.yml" }` in `.vscode/settings.json`.
|
|
64
|
-
- `settings` configure a guard by its id, for example `dependency-direction: { applications: [Myapp.*] }`,
|
|
65
|
-
`agents-file: { acronyms: [NUGET] }` or `docs-paths: { ignore: [Myapp.Web/node_modules/], skip: [docs/notes/**] }` (`ignore`: names the
|
|
66
|
-
docs may mention that are not paths here; `skip`: documents, by glob, that docs-paths does not read at all); the schema of each
|
|
67
|
-
guard's settings is in its source, and `suwgate check` validates them.
|
|
68
|
-
|
|
69
|
-
## Hooks
|
|
70
|
-
|
|
71
|
-
Three lines wire the hooks; `.claude/settings.json`:
|
|
72
|
-
|
|
73
|
-
```json
|
|
74
|
-
{
|
|
75
|
-
"hooks": {
|
|
76
|
-
"Stop": [
|
|
77
|
-
{ "hooks": [{ "type": "command", "command": "\"${CLAUDE_PROJECT_DIR}/node_modules/.bin/suwgate\" hook stop", "timeout": 600 }] }
|
|
78
|
-
],
|
|
79
|
-
"PreToolUse": [
|
|
80
|
-
{
|
|
81
|
-
"matcher": "Edit|Write|MultiEdit|NotebookEdit",
|
|
82
|
-
"hooks": [{ "type": "command", "command": "\"${CLAUDE_PROJECT_DIR}/node_modules/.bin/suwgate\" hook guard-edit" }]
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
}
|
|
30
|
+
The first run lists what the repository still lacks (the hooks, the tool configs, the line in `AGENTS.md` that reads the shared
|
|
31
|
+
rules), each finding with its fix. Then, while working:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
pnpm exec suwgate check --quick # the guards, and the quick steps for what changed since master (20 s budget)
|
|
35
|
+
pnpm exec suwgate step # the steps of this repository
|
|
36
|
+
pnpm exec suwgate step unit-tests -- -t "saves a note" # one step and what it needs; after --, its tool's arguments
|
|
87
37
|
```
|
|
88
38
|
|
|
89
|
-
|
|
39
|
+
Wiring the hooks (`.claude/settings.json`, `.githooks/pre-commit`) and every other detail: [docs/usage.md](docs/usage.md).
|
|
40
|
+
|
|
41
|
+
## Why
|
|
42
|
+
|
|
43
|
+
<picture>
|
|
44
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/why-dark.png">
|
|
45
|
+
<img alt="Why one gate. Each repository on its own: its own check script, ci.yml, hooks and lint configs, copied and drifting apart; an agent says done with the tests red; an agent loosens a lint rule or edits a lockfile to get through; eslint-disable, #pragma and skipped tests hide exceptions in the code; a test file deleted or filtered out passes in silence; CI runs the gate again on a merge commit it already tested; dependency pull requests every day, merged by hand. With suwgate: one package, the repository keeps suwgate.yml and its own code; the Stop hook runs the quick gate after every turn and red blocks the end of the turn; guard-edit refuses an agent's edit of the gate and of generated files; every exception is in suwgate.yml with a reason and a stale one fails; 0 tests run fails, and every .NET guard must leave evidence it ran; a tree stamp skips a tree that already passed; one Renovate run a week, two pull requests, merged when green." src="docs/visual/board/img/readme/why-light.png" width="100%">
|
|
46
|
+
</picture>
|
|
47
|
+
|
|
48
|
+
## How a change goes through it
|
|
49
|
+
|
|
50
|
+
<picture>
|
|
51
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/flow-dark.png">
|
|
52
|
+
<img alt="How a change goes through it. On your machine: an agent edits, and guard-edit runs before every edit (gate files refused; lockfiles, API types and migrations refused); the turn ends, and stop runs the quick gate within 20 seconds (guards and changed files, skipped when nothing changed); git commit runs pre-commit (gitleaks, then the quick gate; staged secrets refused); before done, suwgate check runs the full gate (every step, in parallel, browser tests included). In CI, gate.yml: proof asks whether the tree already passed, in a few seconds (a green ci/tree stamp of the same tree skips the gate); gate runs suwgate check --verbose (a SKIP fails in CI); stack runs the smoke test when smoke is true (its own compose project, free ports); stamp writes ci/tree after green (the merge push is proven); release with release-npm or release-nuget (the publish job stays in the caller). Every step has a ceiling; a missing tool is SKIP, and SKIP fails in CI; exit 0 green, 1 red, 2 usage or suwgate.yml problem." src="docs/visual/board/img/readme/flow-light.png" width="100%">
|
|
53
|
+
</picture>
|
|
54
|
+
|
|
55
|
+
The quick gate is what an agent meets after every turn, so it has a time budget; the full gate is what CI runs. A step that cannot
|
|
56
|
+
run here (its tool is missing) is reported as not verified, never as passed.
|
|
57
|
+
|
|
58
|
+
## The gate
|
|
59
|
+
|
|
60
|
+
<picture>
|
|
61
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/gate-dark.png">
|
|
62
|
+
<img alt="The gate: profiles and their steps. web, a web app: pnpm-install, typecheck, lint, unit-tests, format, knip, e2e (Playwright, fresh database). library, an npm package: the Node steps, stories, publint, attw, consumer-app, visual, changeset (packed as npm ships it). dotnet, a .NET solution: dotnet-build, dotnet-format, dotnet-test, which runs the .NET guards (xUnit v3, CSharpier). database, PostgreSQL: database-up, the database guards, migrations stay unchanged (compose or your script). web and dotnet together: api-contract, api-version (oasdiff), contract-pins. Every repository: guards, compose, criteria, criteria-ran, shellcheck, gitleaks. Proof, not presence: 0 tests fail (Vitest, Playwright and xUnit reports, a run with no test is red); .NET evidence (every .NET guard of the profiles writes that it ran, or dotnet-test fails); configs in effect (tsc --showConfig and eslint --print-config keep the strict options on); criteria-ran (each acceptance criterion a test names ran and passed in this run). --quick: the guards and the quick steps, only for what changed since master, budget 20 s (quick.limitSeconds, SUWGATE_QUICK_LIMIT)." src="docs/visual/board/img/readme/gate-light.png" width="100%">
|
|
63
|
+
</picture>
|
|
64
|
+
|
|
65
|
+
Independent steps run in parallel, and each looks only where its profile lives. The steps of each profile, the criteria kinds and
|
|
66
|
+
what each step proves: [docs/usage.md](docs/usage.md#the-steps-of-the-profiles).
|
|
67
|
+
|
|
68
|
+
## The guards
|
|
69
|
+
|
|
70
|
+
<picture>
|
|
71
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/guards-dark.png">
|
|
72
|
+
<img alt="The guards. Repository guards, 36, in-process, the step guards. Agents: agents-shared, agents-file, hooks, human-docs, docs-paths. Layout and names: repository-layout, forbidden-names, required-files, just-modules. Configs: config-contents, vscode-settings, image-pins, compose-ports. Scripts: scripts-called, scripts-help (answers --help). Dependencies: banned-npm-packages, banned-nuget-packages, unused-nuget-versions, dependency-direction. No comments: comments-hash, comments-css, comments-json, comments-markup, comments-sql, comments-csharp, comments-eslint, no-in-place-switches. Tests: test-timing, tests drive a fake clock, never real time. Kits wired: suwfrontkit-wiring, suwbackkit-wiring, openapi-versions, no-raw-colors, appsettings-bound. Database: connection-host, migrations-unchanged. Criteria: criteria-kinds, a repository's own kinds of guardrail are explained. .NET guards, NuGet, one xUnit test calls SuwgateGuards.VerifyAll. Suwgate.Architecture: architecture/ layers, endpoints, project-references, every-project-guarded, interfaces-have-two-implementations, nothing-obsolete, no-unused-types, forbidden-type-names, unique-type-names, one-type-per-file, no-escape-hatches, no-fixture-in-field, build-settings; and the build defaults: warnings as errors, analyzers, banned APIs. Suwgate.Database: database/ migration-script-names, NNNN_snake_case.sql, each number once. suwgate.yml: exceptions let one target through one guard, with a reason; a stale one fails; once: true for one branch; guards.skip and steps.skip, with a reason." src="docs/visual/board/img/readme/guards-light.png" width="100%">
|
|
73
|
+
</picture>
|
|
74
|
+
|
|
75
|
+
A guard reports every finding with its fix and never decides an exception itself: `suwgate.yml` holds the exceptions, each with
|
|
76
|
+
its reason. The .NET guards and build defaults: [Suwgate.Architecture](dotnet/Suwgate.Architecture/README.md).
|
|
77
|
+
|
|
78
|
+
## For agents
|
|
79
|
+
|
|
80
|
+
<picture>
|
|
81
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/agents-dark.png">
|
|
82
|
+
<img alt="For agents. hook guard-edit, Claude Code PreToolUse: refuses an edit of the gate (suwgate.yml, hooks, workflows, lint and type configs) and of generated files; ALLOW_GATE_EDIT=1 lifts the gate part. hook stop, Claude Code Stop: runs the quick gate after every turn, unless nothing changed since it last passed; red, the agent keeps working. hook pre-commit, git: gitleaks on the staged changes, then the quick gate; .githooks/pre-commit. AGENTS.shared.md: the rules every repository shares (test last, git, specs, names, secrets, no comments); suwgate agents-shared writes the copy; the agents-shared guard fails until it is current and AGENTS.md reads it first. Acceptance criteria as guardrails: every criterion id of a spec in docs/visual/spec/ is named by a test, a lint rule or a build rule (criteria), and the tests that name it ran and passed (criteria-ran)." src="docs/visual/board/img/readme/agents-light.png" width="100%">
|
|
83
|
+
</picture>
|
|
84
|
+
|
|
85
|
+
## suwgate dev
|
|
86
|
+
|
|
87
|
+
<picture>
|
|
88
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/dev-dark.png">
|
|
89
|
+
<img alt="suwgate dev: the local stack. db (up, down, reset, psql, logs, status): the PostgreSQL of the compose file, or your own script. server (dotnet watch): restarted when it exits, output teed to a JSON log. tmux (start [--restart], stop): shell, server and web app in one session. logs (why did it fail?): the last warnings and errors; --trace one request. smoke (read-only requests): --ci builds and starts its own stack on free ports. checkout-env (eval in a worktree): own test databases and e2e ports per linked worktree. sibling (image, up, rebuild, down, status), new: a sibling repository's images, rebuilt when its checkout moved on. dev: in suwgate.yml: only name is required; portOffset keeps repositories on one machine apart." src="docs/visual/board/img/readme/dev-light.png" width="100%">
|
|
90
|
+
</picture>
|
|
90
91
|
|
|
91
92
|
```sh
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
suwgate dev tmux start # the whole local stack in one tmux session
|
|
94
|
+
eval "$(suwgate dev checkout-env)" # in a linked worktree: its own test databases and e2e ports
|
|
95
|
+
suwgate dev sibling suwagcms up # a sibling's images, rebuilt if its checkout moved on, then started
|
|
94
96
|
```
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
- `hook guard-edit` refuses an agent's edit of the gate (`suwgate.yml`, the criteria file, the hooks, the workflows, `.editorconfig`,
|
|
98
|
-
and the lint, type and build configs of the repository's profiles, the layers file of a .NET server among them) until the owner starts a session
|
|
99
|
-
with `ALLOW_GATE_EDIT=1`. It always refuses generated files (lockfiles, the API contract and types) with the command that
|
|
100
|
-
regenerates them and an existing migration script, and refuses a recorded characterization test that git tracks. It guards only
|
|
101
|
-
files of its own project (`CLAUDE_PROJECT_DIR`, else the checkout it runs in), so a session never blocks another repository.
|
|
102
|
-
`settings.hooks` adds the repository's own: `protected` (globs), `generated` (`path` and `command`), `recordings`, `migrations`.
|
|
103
|
-
- `hook pre-commit` runs gitleaks on the staged changes, then the quick gate, and refuses the commit if either fails
|
|
104
|
-
([docs/adr/0001-suwgate-hook-pre-commit.md](docs/adr/0001-suwgate-hook-pre-commit.md)).
|
|
105
|
-
- The `hooks` guard checks that these lines are there.
|
|
98
|
+
Every subcommand answers `--help`. The `dev` section and what each command does: [docs/dev.md](docs/dev.md).
|
|
106
99
|
|
|
107
|
-
##
|
|
100
|
+
## CI, releases and dependencies
|
|
108
101
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
102
|
+
<picture>
|
|
103
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/ci-dark.png">
|
|
104
|
+
<img alt="CI, releases and dependencies. Reusable workflows, pinned by commit: gate.yml (proof, gate, smoke, stamp; tools installed with checksums; consumer: a kit tested in a real app); release-npm.yml (changesets: the Version Packages pull request, then build and pack; npm trusted publishing); release-nuget.yml (full history, dotnet pack in Release, the artifact nupkg; NuGet trusted publishing). Self-hosted fallback: private repositories move to local runners when the month's Actions minutes run out: CI_RUNNER=suw-local, set and cleared by a timer. Renovate for every repository: once a week (new pull requests on Monday before 6:00 Warsaw time); two pull requests (minor and patch in one, majors in the other); merged on green (Renovate merges once the checks pass, a red one stays open); holds follow peers (TypeScript held to what typescript-eslint accepts, moved by pull request)." src="docs/visual/board/img/readme/ci-light.png" width="100%">
|
|
105
|
+
</picture>
|
|
113
106
|
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
A repository's whole `ci.yml` can be one job:
|
|
108
|
+
|
|
109
|
+
```yaml
|
|
110
|
+
jobs:
|
|
111
|
+
gate:
|
|
112
|
+
permissions:
|
|
113
|
+
contents: read
|
|
114
|
+
statuses: write
|
|
115
|
+
pull-requests: read
|
|
116
|
+
uses: Manomenu/suwgate/.github/workflows/gate.yml@<full commit sha>
|
|
117
|
+
with:
|
|
118
|
+
browser: chromium
|
|
116
119
|
```
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
The inputs, the tree stamp, the consumer test, trusted publishing and the Renovate preset: [docs/ci.md](docs/ci.md); the
|
|
122
|
+
self-hosted runners: [ci/self-hosted](ci/self-hosted/README.md).
|
|
123
|
+
|
|
124
|
+
## Which command, when
|
|
125
|
+
|
|
126
|
+
<picture>
|
|
127
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/choose-dark.png">
|
|
128
|
+
<img alt="Which command, when. While an agent works, after every turn: suwgate check --quick (the Stop hook). Before calling a change done: suwgate check (the full gate). Which steps does this repository have: suwgate step (lists them). One step, with what it needs, and its tool's flags: suwgate step e2e -- --headed. Run the whole local stack: suwgate dev tmux start. The server failed, why: suwgate dev logs. A linked worktree needs its own databases and ports: suwgate dev checkout-env, with eval. A sibling repository's images are behind its checkout: suwgate dev sibling name up. suwgate was upgraded and agents-shared is red: suwgate agents-shared (writes the copy)." src="docs/visual/board/img/readme/choose-light.png" width="100%">
|
|
129
|
+
</picture>
|
|
120
130
|
|
|
121
|
-
|
|
131
|
+
<details>
|
|
132
|
+
<summary>suwgate --help</summary>
|
|
122
133
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
```text
|
|
135
|
+
usage: suwgate check [--quick] [--verbose] | suwgate step [<id> [--only] [--verbose] [-- <args>]] | suwgate hook <guard-edit|stop|pre-commit> | suwgate dev <command> | suwgate agents-shared | suwgate --help | --version
|
|
136
|
+
suwgate check every step of the repository's profiles (suwgate.yml) and the repository guards
|
|
137
|
+
suwgate check --quick the guards, and the quick steps only for what changed since master; has a time budget
|
|
138
|
+
(SUWGATE_QUICK_LIMIT seconds, default 20) because the Stop hook runs it after every turn
|
|
139
|
+
--verbose list every step with its time, also when all pass, and the whole output of a failed step
|
|
140
|
+
suwgate step the steps of this repository, with their titles and the tool that takes -- arguments
|
|
141
|
+
suwgate step <id> one step and the steps it needs (after, transitively), with the same report; not a gate
|
|
142
|
+
pass: the Stop hook does not count it. --only: that step alone. After --, arguments for the
|
|
143
|
+
step's tool: suwgate step e2e -- --headed -g notes (Playwright), suwgate step unit-tests --
|
|
144
|
+
-t "name" (Vitest), suwgate step dotnet-test -- --filter-method "*Notes*" (xUnit v3)
|
|
145
|
+
suwgate hook guard-edit Claude Code PreToolUse hook: refuses an agent's edit of the gate and of generated files
|
|
146
|
+
(ALLOW_GATE_EDIT=1 lifts the gate part for one session); only files of its own project
|
|
147
|
+
(CLAUDE_PROJECT_DIR, else the git checkout it runs in), with the lists of its profiles
|
|
148
|
+
suwgate hook stop Claude Code Stop hook: runs the quick gate unless nothing changed since it last passed
|
|
149
|
+
suwgate hook pre-commit git pre-commit hook: gitleaks on the staged changes, then the quick gate
|
|
150
|
+
suwgate dev <db|logs|smoke|server|tmux|sibling|checkout-env>
|
|
151
|
+
the local stack of the repository (the dev section of suwgate.yml), and the images of the
|
|
152
|
+
sibling repositories it runs, rebuilt from their checkouts when stale; suwgate dev --help
|
|
153
|
+
suwgate agents-shared writes AGENTS.shared.md, the rules every repository shares, as this suwgate ships it, into the
|
|
154
|
+
repository root (the agents-shared guard fails until the copy is current)
|
|
155
|
+
suwgate verdict <tests|guards|tsconfig|eslint> ...
|
|
156
|
+
what the steps call after their tool: did tests run, did the .NET guards run (evidence),
|
|
157
|
+
are the strict compiler options and the eslint rules in effect
|
|
158
|
+
Every step has a ceiling (SUWGATE_STEP_LIMIT seconds overrides them all). A step whose tool is missing is SKIP,
|
|
159
|
+
and a SKIP fails the gate when CI is set. Exit code: 0 green, 1 red, 2 a usage or suwgate.yml problem.
|
|
160
|
+
```
|
|
126
161
|
|
|
127
|
-
|
|
128
|
-
(Playwright), `suwgate step unit-tests -- -t "saves a note"` (Vitest), `suwgate step dotnet-test -- --filter-class "*Notes*"`
|
|
129
|
-
(xUnit v3 on Microsoft.Testing.Platform: `--filter-class`, `--filter-method`, `--filter-namespace`, `--filter-trait name=value`
|
|
130
|
-
and their `--filter-not-*`). The steps that take them: `unit-tests`, `stories`, `e2e`, `visual`, `consumer-app`, `dotnet-test`;
|
|
131
|
-
any other step refuses `--` and names these.
|
|
132
|
-
- A step named on the command line runs even when `steps.skip` leaves it out of the gate, so a repository that keeps `e2e`
|
|
133
|
-
out of `suwgate check` still runs it with `suwgate step e2e`; the steps it needs keep their skips.
|
|
134
|
-
- A step waits for some steps only for the order of the full gate (`e2e` for `dotnet-test` and `api-contract`, which rebuild the
|
|
135
|
-
server): `suwgate step e2e` does not run them.
|
|
136
|
-
- It is not a gate pass: the Stop hook does not count it, and the next turn still runs the quick gate.
|
|
137
|
-
- The evidence still applies where it makes sense for one step: a test step that ran 0 tests fails (a filter that matches
|
|
138
|
-
nothing is a mistake). With arguments, `dotnet-test` counts the tests of the whole run, not of each test project
|
|
139
|
-
(`--ignore-exit-code 8` for each test project, then xUnit's reports of all of them), so `--filter-class "*Notes*"` passes in a
|
|
140
|
-
repository with more than one test project and fails only when no test anywhere matched; `dotnet-test` asks the .NET guards' evidence only when it gets no arguments, because a filtered run
|
|
141
|
-
leaves guards out on purpose; `criteria-ran` reads the reports of the same run, so `suwgate step criteria-ran` runs every
|
|
142
|
-
test step first, and with `--only` it has no reports and fails.
|
|
162
|
+
</details>
|
|
143
163
|
|
|
144
|
-
|
|
164
|
+
## Configuration
|
|
145
165
|
|
|
146
|
-
|
|
166
|
+
<picture>
|
|
167
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/visual/board/img/readme/settings-dark.png">
|
|
168
|
+
<img alt="What suwgate.yml configures. profiles: what the repository is, the steps and guards follow (web, library, dotnet, database). directories: where each profile's project lives (web: Myapp.Web). steps.add, skip, configure: more steps; one left out with a reason; a step's ceiling, after, env, settings. quick.limitSeconds: the budget of the quick gate (20). exceptions: guard, target, reason; optional message and once; a stale one fails. guards.skip: a whole guard off, with a reason. settings.guard: a guard's own knobs, validated by its schema (docs-paths: ignore). env and unset: variables of every step; unset: [Models__*]. dev: name, portOffset, ports, compose, database, siblings (name: myapp). schema: checked as you type in VS Code, exit 2 when invalid, always on. Tool presets your configs extend: ESLint app() and strict(); Prettier, the shared options; knip(); Vitest unitTests() and storyTests(); Playwright e2eTests() and visualTests(); tsconfig strict, browser, node." src="docs/visual/board/img/readme/settings-light.png" width="100%">
|
|
169
|
+
</picture>
|
|
147
170
|
|
|
148
171
|
```yaml
|
|
172
|
+
profiles: [web, dotnet, database]
|
|
173
|
+
directories:
|
|
174
|
+
web: Myapp.Web
|
|
149
175
|
steps:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
before: ["rm -rf .artifacts/e2e/versions"]
|
|
176
|
+
skip:
|
|
177
|
+
- step: knip
|
|
178
|
+
reason: the generated API client exports more than the app uses, and knip cannot tell
|
|
179
|
+
exceptions:
|
|
180
|
+
- guard: architecture/interfaces-have-two-implementations
|
|
181
|
+
target: Myapp.Server.Payments.IPaymentGateway
|
|
182
|
+
reason: the payment SDK takes an implementation of this interface; the second one is the SDK's test double
|
|
158
183
|
```
|
|
159
184
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
185
|
+
| Key | What it does |
|
|
186
|
+
| :----------------------- | :------------------------------------------------------------------------------------------------- |
|
|
187
|
+
| `profiles` | `web`, `library`, `dotnet`, `database`: the steps and guards the repository gets |
|
|
188
|
+
| `directories` | where a profile's project lives when it is not the root |
|
|
189
|
+
| `steps.add` | more steps: `name`, `run`, optionally `title`, `quick`, `after`, `limitSeconds` |
|
|
190
|
+
| `steps.skip` | a step of the profiles left out, with its `reason` |
|
|
191
|
+
| `steps.configure.<step>` | a profile's step: `limitSeconds`, more `after`, `env`, `unset`, `settings` (below) |
|
|
192
|
+
| `env`, `unset` | variables set for every step, and variables no step sees (`*` and `?` match) |
|
|
193
|
+
| `quick.limitSeconds` | the budget of `suwgate check --quick` (default 20; `SUWGATE_QUICK_LIMIT` on a machine) |
|
|
194
|
+
| `exceptions` | `guard`, `target`, `reason`, optionally `message` and `once: true`; one that matches nothing fails |
|
|
195
|
+
| `guards.skip` | a whole guard off, repository or .NET, with its `reason` |
|
|
196
|
+
| `settings.<guard>` | a guard's own settings, checked by its schema |
|
|
197
|
+
| `dev` | the local stack of `suwgate dev` ([docs/dev.md](docs/dev.md)) |
|
|
198
|
+
|
|
199
|
+
The schema ships in the package (`schema/suwgate.schema.json`); VS Code checks the file as you type with `yaml.schemas` in
|
|
200
|
+
`.vscode/settings.json`. The tool presets (`@maniumek/suwgate/eslint`, `/prettier`, `/knip`, `/vitest`, `/playwright`,
|
|
201
|
+
`/tsconfig/strict`, `/tsconfig/browser`, `/tsconfig/node`): [docs/usage.md](docs/usage.md#the-tool-presets).
|
|
202
|
+
|
|
203
|
+
<details>
|
|
204
|
+
<summary>The settings of the steps</summary>
|
|
167
205
|
|
|
168
206
|
| Step | Setting | What it does |
|
|
169
207
|
| :------------- | :------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -172,160 +210,22 @@ The settings of the steps:
|
|
|
172
210
|
| `api-contract` | `contract: Myapp.Server/openapi.json` | where the contract is, relative to the dotnet directory (default `contract/openapi.json`); `api-version` compares the same file and reads its version from the `package.json` beside it |
|
|
173
211
|
| `api-version` | `breaking: never` | every breaking change fails; the default, `major`, lets one through with a new major version |
|
|
174
212
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
### The steps of the profiles
|
|
180
|
-
|
|
181
|
-
Each step looks where its profile lives (`directories`) and passes with nothing to check when the repository has nothing for it.
|
|
182
|
-
|
|
183
|
-
| Profile | Steps |
|
|
184
|
-
| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
185
|
-
| `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` |
|
|
186
|
-
| `web` | `e2e`: `playwright test -c e2e/playwright.config.ts`, after the build and the database (and, in the full gate, the .NET tests and the contract); 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), then `settings.before`; Playwright's `webServer` starts and stops the server and the web app |
|
|
187
|
-
| `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`; a real consumer's whole gate against the packed package runs in CI, [docs/ci.md](docs/ci.md)), `visual` (`visual/playwright.config.ts` in the Playwright image of the installed `@playwright/test`), `changeset` |
|
|
188
|
-
| `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 |
|
|
189
|
-
| `dotnet`, `web` | with `contract/openapi.json` (or `settings.contract`): `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 the `package.json` beside the contract, or fails with `breaking: never`), `contract-pins` (every test tagged `contract <name>@<version>` names a version) |
|
|
190
|
-
| `database` | `database-up`: `docker compose --profile db up -d --wait db`, or `dev.database.up`; not in CI, where the workflow starts it |
|
|
191
|
-
| every repository | `compose` (with a compose file), `criteria`, `shellcheck`, `gitleaks` |
|
|
192
|
-
|
|
193
|
-
`criteria` runs `vdoc.py criteria` of the suwagent plugin, pinned by commit and SHA-256: every acceptance criterion of the specs in
|
|
194
|
-
`docs/visual/spec/` is named by a guardrail. The kinds of guardrail come with the profiles; `criteria.json` in the repository root
|
|
195
|
-
adds the repository's own (`{ "kinds": [{ "kind", "paths", "how" }] }`, optionally `specs` and `prose`), and the guard
|
|
196
|
-
`criteria-kinds` asks for a row of each in a table of `README.md` or `docs/development.md`. The default kinds:
|
|
197
|
-
|
|
198
|
-
| Kind | Profile | Where (in the profile's directory) | How the id is written |
|
|
199
|
-
| :------------------------------ | :--------------- | :---------------------------------- | :----------------------------------------- |
|
|
200
|
-
| `test (xunit)` | `dotnet` | every project that references xunit | `[Trait("criterion", "<id>")]` on the test |
|
|
201
|
-
| `lint (.NET analyzer)` | `dotnet` | `.editorconfig` | `# <id>` on its own line above the rule |
|
|
202
|
-
| `banned API` | `dotnet` | `BannedSymbols.txt` | in the message: `P:…;<id> use …` |
|
|
203
|
-
| `build rule` | `dotnet` | `Directory.Build.props` | `<!-- <id> -->` above the property |
|
|
204
|
-
| `e2e test (playwright)` | `web` | `src/**/*.e2e.ts` | in the title: `test("<id>: …")` |
|
|
205
|
-
| `web test (vitest)` | `web` | `src/**/*.test.ts(x)` | in the title: `it("<id>: …")` |
|
|
206
|
-
| `unit test (vitest)` | `library` | `src/**/*.test.ts(x)` | in the title: `it("<id>: …")` |
|
|
207
|
-
| `story test (vitest, Chromium)` | `library` | `src/**/*.stories.tsx` | in the story's name: `name: "<id>: …"` |
|
|
208
|
-
| `visual test (playwright)` | `library` | `visual/*.visual.ts` | in the title: `test("<id>: …")` |
|
|
209
|
-
| `consumer test (playwright)` | `library` | `gate/consumer/*.spec.ts` | in the title: `test("<id>: …")` |
|
|
210
|
-
| `lint (eslint)` | `web`, `library` | `eslint.config.js` | `// <id>` on the line above the rule |
|
|
211
|
-
| `type check (tsc)` | `web`, `library` | `tsconfig*.json` | `// <id>` on the line above the option |
|
|
212
|
-
|
|
213
|
-
### The tool presets
|
|
214
|
-
|
|
215
|
-
The configs of the tools the steps run extend suwgate's, so an application keeps only its own paths:
|
|
216
|
-
|
|
217
|
-
| Tool | The application's file |
|
|
218
|
-
| :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
219
|
-
| Prettier | `.prettierrc.json`: `"@maniumek/suwgate/prettier"` (with a plugin: spread it in `prettier.config.js`) |
|
|
220
|
-
| TypeScript | `{ "extends": "@maniumek/suwgate/tsconfig/browser", "include": ["src"] }`; `tsconfig/node` for the configs, scripts and tests run by Node; `tsconfig/strict` for the options alone |
|
|
221
|
-
| knip | `knip.config.ts`: `export { default } from "@maniumek/suwgate/knip"`, or `knip({ entry: [...] })`; it ignores the tools the steps run (Prettier among them) and the issues of the generated API types, and reads the steps' Playwright configs |
|
|
222
|
-
| Vitest | `unitTests({ environment: "jsdom" })` and `storyTests({ plugin, provider })` from `@maniumek/suwgate/vitest`: the projects `unit` and `stories` the steps run |
|
|
223
|
-
| Playwright | `defineConfig(e2eTests({ use: { baseURL }, webServer, reporter }))` or `defineConfig(visualTests())` from `@maniumek/suwgate/playwright`; `e2eTests` keeps the app's `reporter` (an HTML report in CI) and adds the JSON report the `e2e` step reads |
|
|
224
|
-
| ESLint | `app({ root, features, shared, sharedImports, storage })` from `@maniumek/suwgate/eslint`: a feature imports itself and the shared folders, a shared folder only itself and what `sharedImports` allows it (`[["design", "api"]]`: design may import api); the import resolver reads the first of `projects`, the one of `src/` (or a root tsconfig with references) |
|
|
225
|
-
|
|
226
|
-
### What the config files must say
|
|
227
|
-
|
|
228
|
-
`required-files` asks for the files; `config-contents` checks that they say what the gate relies on, each where its profile lives
|
|
229
|
-
(`directories`), and only when the profile is on and the file is there:
|
|
230
|
-
|
|
231
|
-
| File | Profile | Must contain |
|
|
232
|
-
| :---------------------------------------------------------------------------- | :--------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
233
|
-
| `global.json` | `dotnet` | an exact `sdk.version` (`10.0.100`), a `sdk.rollForward` other than `major` and `latestMajor`, `test.runner` `Microsoft.Testing.Platform` |
|
|
234
|
-
| `.editorconfig` (the root's, then the dotnet directory's) | `dotnet` | `max_line_length = 140` for `*.cs`, `*.csproj`, `*.props` and `*.targets`: CSharpier's width; a `.csharpierrc*` anywhere must go, it would win over it |
|
|
235
|
-
| `Directory.Packages.props` | `dotnet` | `<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>` |
|
|
236
|
-
| `tsconfig*.json` (not `tsconfig.build.json`, which the typecheck step skips) | `web`, `library` | `extends` `@maniumek/suwgate/tsconfig/...`, directly or through another tsconfig of the repository |
|
|
237
|
-
| `eslint.config.js`, `knip.config.ts`, the Vitest config | `web`, `library` | an import of `@maniumek/suwgate/eslint`, `/knip`, `/vitest` |
|
|
238
|
-
| `.prettierrc.json` or `prettier.config.js` | `web`, `library` | exactly `"@maniumek/suwgate/prettier"`, or an import of it |
|
|
239
|
-
| `e2e/playwright.config.ts`, `visual/playwright.config.ts` | `web`, `library` | an import of `@maniumek/suwgate/playwright` |
|
|
240
|
-
| `package.json` that installs suwgate (the root or a web or library directory) | every | `@maniumek/suwgate` at an exact version: no `^`, `~`, range or tag |
|
|
241
|
-
| `pnpm-workspace.yaml` (web, library, and where suwgate is installed) | every | no `minimumReleaseAge` of 0 (pnpm waits 1440 minutes by default); `minimumReleaseAgeExclude` is fine |
|
|
242
|
-
| `.vscode/settings.json` | every | `yaml.schemas` mapping `./node_modules/@maniumek/suwgate/schema/suwgate.schema.json` (or under a profile's directory) to `suwgate.yml` |
|
|
243
|
-
| `.github/workflows/*.yml` | every | a job with `uses: Manomenu/suwgate/.github/workflows/gate.yml@<full 40-character commit sha>` |
|
|
244
|
-
|
|
245
|
-
`required-files` also asks the `dotnet` profile for exactly one `*.slnx` in its directory, and for `Directory.Build.rsp`
|
|
246
|
-
(`-nodeReuse:false`, so no idle MSBuild worker stays behind).
|
|
247
|
-
|
|
248
|
-
### The .NET guards
|
|
249
|
-
|
|
250
|
-
One xUnit test in the gate's test project runs every guard of the `dotnet` and `database` profiles:
|
|
251
|
-
|
|
252
|
-
```csharp
|
|
253
|
-
public sealed class GuardTests
|
|
254
|
-
{
|
|
255
|
-
[Fact]
|
|
256
|
-
public void Every_guard_of_suwgate_passes() =>
|
|
257
|
-
SuwgateGuards.VerifyAll(
|
|
258
|
-
new GuardInputs { Production = [typeof(ServerApp).Assembly], Tests = [typeof(GuardTests).Assembly], Server = typeof(ServerApp) },
|
|
259
|
-
new DatabaseProfile()
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
```
|
|
213
|
+
</details>
|
|
214
|
+
|
|
215
|
+
## Documentation
|
|
263
216
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
### The tests and the docs for people
|
|
269
|
-
|
|
270
|
-
- `test-timing` (`dotnet`, `web`, `library`): no test measures, sleeps on, waits for or limits real time, because a test that
|
|
271
|
-
waits on the clock flakes on a slow machine and a speed promise, in milliseconds or in steps counted instead of them, does not
|
|
272
|
-
belong on the gate. It reads the `.cs` files of the `*.Tests` and `*.Testing` projects (`Stopwatch`, `GetTimestamp`,
|
|
273
|
-
`GetElapsedTime`, `TickCount`, `DateTime.Now`, `UtcNow` and `Today`, `TimeProvider.System`, `Thread.Sleep`, `Task.Delay`, `Timeout =` in an attribute,
|
|
274
|
-
a `TimeSpan.From…` or `new TimeSpan(…)` handed to a constructor that gets no `TimeProvider`),
|
|
275
|
-
and the `*.test`, `*.spec`, `*.e2e`, `*.visual`
|
|
276
|
-
and `*.stories` files and the helpers of an `e2e/` folder (`performance.now`, `Date.now()` in a subtraction, `setTimeout`,
|
|
277
|
-
`sleep(<n>)`, `waitForTimeout`, `interruptAfterTimeLimit`, and `timeout: <n>` in a Vitest file, such as the options of `it`, `test`
|
|
278
|
-
or `describe`). It lets through a call that is
|
|
279
|
-
handed a `TimeProvider` (a `FakeTimeProvider` in the tests; `TimeProvider.System` is the real clock and fails), `Task.Delay` inside a `while`, `for`, `foreach` or `do` loop (a poll)
|
|
280
|
-
or with `Timeout.Infinite`, the timers and the clock of a file that calls `vi.useFakeTimers()`, Playwright's auto-waiting
|
|
281
|
-
`expect` with its own `timeout`, a ceiling against a hang (`CancelAfter`, `new CancellationTokenSource(<delay>)`,
|
|
282
|
-
`WaitAsync(<TimeSpan>)`, an `HttpClient`'s `Timeout`, and the `timeout` option of a Vitest wait for an event: `vi.waitFor`, `vi.waitUntil`, `expect.poll`,
|
|
283
|
-
Testing Library's `waitFor`, `findBy*` and `findAllBy*`; the test waits for the event and fails fast, with its name, if it never
|
|
284
|
-
comes: a ceiling, not a speed promise), and the tools' configs
|
|
285
|
-
(`playwright.config.ts`), whose ceilings stop a hang.
|
|
286
|
-
- `human-docs` (every profile): `README.md`, `docs/development.md` and the README of a profile's directory never tell a person to
|
|
287
|
-
run a script meant for agents, one in `scripts/.internal/` or `<name>.Gate/scripts/`; people run `just` recipes. A command is a
|
|
288
|
-
line of a shell code block or an inline code span with a space in it, and a span in parentheses or right after "runs", "calls",
|
|
289
|
-
"starts", "through" or "via" explains what runs the script, so it passes. The message names the recipe that calls the script, or
|
|
290
|
-
asks for one.
|
|
291
|
-
|
|
292
|
-
### What the gate proves ran
|
|
293
|
-
|
|
294
|
-
A check counts only when the tool shows it ran, not because a file or a line of text is there:
|
|
295
|
-
|
|
296
|
-
- The .NET guards: `dotnet-test` points `SUWGATE_EVIDENCE` at a fresh folder of this gate run, and every guard that runs (through
|
|
297
|
-
`VerifyAll` or `Guards.Verify`) writes its id and outcome there. The step fails unless every guard of the profiles that
|
|
298
|
-
`guards.skip` does not name is in it, so a deleted guard test, a `[Fact(Skip = …)]` or a filtered-out one fails the gate.
|
|
299
|
-
- Zero tests fail: `unit-tests`, `stories` (Vitest, its JSON report), `e2e` (Playwright, its JSON report) and `dotnet-test`
|
|
300
|
-
(`--zero-tests-policy strict` of Microsoft.Testing.Platform for each test project, and xUnit's XML reports for the whole run)
|
|
301
|
-
fail when the tool ran no test, also when every test was skipped. A repository with truly no tests for a profile skips the step in `suwgate.yml` with a reason.
|
|
302
|
-
- `typecheck` reads `tsc --showConfig` of every tsconfig it checks: the strict options of the suwgate preset must be in effect, so
|
|
303
|
-
an override that turns one off fails, naming the option.
|
|
304
|
-
- `lint` reads `eslint --print-config` of a source file of `src/`: `suwgate/no-comments` and `boundaries/dependencies` must be
|
|
305
|
-
errors there.
|
|
306
|
-
- `criteria-ran`, after the test steps: every acceptance criterion of a living spec (`docs/visual/spec/`) that a test names
|
|
307
|
-
(`[Trait("criterion", "<id>")]`, a title or story name `"<id>: …"`) must have a test naming it that ran and passed in this run,
|
|
308
|
-
by the reports of xUnit, Vitest and Playwright. A criterion named only by tests of a step `steps.skip` names is not checked; one
|
|
309
|
-
named only by tests that `excludeTraits` of `dotnet-test` keeps out of the gate fails with the fix: a gate test with a stand-in.
|
|
310
|
-
- The kits are wired, not only installed: `suwbackkit-wiring` (dotnet) asks a web server that references `Suwbackkit.Server` to
|
|
311
|
-
call `AddServerDefaults` and `MapServerDefaults`; `suwfrontkit-wiring` (web, library) asks an app whose `package.json` depends
|
|
312
|
-
on `@maniumek/suwfrontkit` to load `@maniumek/suwfrontkit/theme.css` from the main module of its `index.html`, or from a
|
|
313
|
-
stylesheet that module imports. Both read the sources: the evidence (a run hitting `/health`, a built stylesheet with the
|
|
314
|
-
kit's tokens) needs a running server or a production build, which the gate does not have in every repository.
|
|
315
|
-
- The reports live in a temporary folder of the run (`SUWGATE_RUN`), deleted when `suwgate check` ends. `dotnet-test` asks xUnit
|
|
316
|
-
for its XML report (`--report-xunit-xml`), so every .NET test project tests with xUnit v3. Each test project writes its own
|
|
317
|
-
report, `<project>.<target framework>.xunit.xml` (`--report-xunit-xml-filename` through `TestingPlatformCommandLineArguments`,
|
|
318
|
-
from a targets file the step passes as `-p:CustomAfterMicrosoftCommonTargets`): xUnit's own name is the moment the project
|
|
319
|
-
started, which two projects that start together share, and one report would overwrite the other.
|
|
320
|
-
|
|
321
|
-
`suwgate dev db|logs|smoke|server|tmux|checkout-env` runs the local stack of the template (database, logs, smoke test, server, tmux
|
|
322
|
-
session, worktree databases) from a `dev` section of `suwgate.yml`: [docs/dev.md](docs/dev.md).
|
|
217
|
+
- [docs/usage.md](docs/usage.md): the gate, `suwgate.yml`, the steps and guards, the hooks, the shared rules, the presets, the .NET guards
|
|
218
|
+
- [docs/dev.md](docs/dev.md): `suwgate dev` and the `dev` section
|
|
219
|
+
- [docs/ci.md](docs/ci.md): the reusable workflows, the tree stamp, releases and Renovate
|
|
220
|
+
- [CHANGELOG.md](CHANGELOG.md): what each version changed, and what a repository must change with it
|
|
323
221
|
|
|
324
222
|
## Work on suwgate
|
|
325
223
|
|
|
326
224
|
[AGENTS.md](AGENTS.md) holds the rules, [docs/development.md](docs/development.md) the setup, [docs/architecture.md](docs/architecture.md)
|
|
327
|
-
the contract of a guard and a step, and [docs/inventory.md](docs/inventory.md) what is still to be moved here from the template and
|
|
225
|
+
the contract of a guard and a step, and [docs/inventory.md](docs/inventory.md) what is still to be moved here from the template and
|
|
226
|
+
the kits. The pictures of this README are panels of `docs/visual/board/readme.html`: edit the board, then redraw them with
|
|
227
|
+
`vdoc.py render docs/visual/board/readme.html` of the suwagent plugin.
|
|
328
228
|
|
|
329
|
-
##
|
|
229
|
+
## License
|
|
330
230
|
|
|
331
231
|
MIT, see [LICENSE](LICENSE).
|
package/dist/cli.js
CHANGED
|
@@ -26,8 +26,9 @@ const USAGE = `usage: suwgate check [--quick] [--verbose] | suwgate step [<id> [
|
|
|
26
26
|
(CLAUDE_PROJECT_DIR, else the git checkout it runs in), with the lists of its profiles
|
|
27
27
|
suwgate hook stop Claude Code Stop hook: runs the quick gate unless nothing changed since it last passed
|
|
28
28
|
suwgate hook pre-commit git pre-commit hook: gitleaks on the staged changes, then the quick gate
|
|
29
|
-
suwgate dev <db|logs|smoke|server|tmux|checkout-env>
|
|
30
|
-
the local stack of the repository (the dev section of suwgate.yml)
|
|
29
|
+
suwgate dev <db|logs|smoke|server|tmux|sibling|checkout-env>
|
|
30
|
+
the local stack of the repository (the dev section of suwgate.yml), and the images of the
|
|
31
|
+
sibling repositories it runs, rebuilt from their checkouts when stale; suwgate dev --help
|
|
31
32
|
suwgate agents-shared writes AGENTS.shared.md, the rules every repository shares, as this suwgate ships it, into the
|
|
32
33
|
repository root (the agents-shared guard fails until the copy is current)
|
|
33
34
|
suwgate verdict <tests|guards|tsconfig|eslint> ...
|
package/dist/dev/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type Exec, type Io } from "./process.ts";
|
|
2
2
|
import { type DevSettings } from "./settings.ts";
|
|
3
3
|
import { type Fetch, type SmokeCiEnvironment } from "./smoke.ts";
|
|
4
|
-
export declare const DEV_USAGE = "usage: suwgate dev <db|logs|smoke|server|tmux|checkout-env> [arguments] (every one takes --help)\nThe dev scripts of the template as commands, configured by the dev section of suwgate.yml:\n db the local PostgreSQL of the compose file: up | down | reset | psql | logs | status\n logs why did it fail? the last warnings and errors of the server's JSON log\n smoke read-only requests against a running stack; --ci builds and starts its own stack first\n server the server under dotnet watch, restarted when it exits\n tmux the whole local stack in one tmux session: start [--restart] | stop\n checkout-env eval \"$(suwgate dev checkout-env)\": own test databases and e2e ports for a linked worktree";
|
|
4
|
+
export declare const DEV_USAGE = "usage: suwgate dev <db|logs|smoke|server|tmux|sibling|checkout-env> [arguments] (every one takes --help)\nThe dev scripts of the template as commands, configured by the dev section of suwgate.yml:\n db the local PostgreSQL of the compose file: up | down | reset | psql | logs | status\n logs why did it fail? the last warnings and errors of the server's JSON log\n smoke read-only requests against a running stack; --ci builds and starts its own stack first\n server the server under dotnet watch, restarted when it exits\n tmux the whole local stack in one tmux session: start [--restart] | stop\n sibling the images of a sibling repository, rebuilt from its checkout when stale: <name> image | up | rebuild | down | status\n checkout-env eval \"$(suwgate dev checkout-env)\": own test databases and e2e ports for a linked worktree";
|
|
5
5
|
export interface DevEnvironment {
|
|
6
6
|
cwd: string;
|
|
7
7
|
env: Readonly<Record<string, string | undefined>>;
|
|
8
8
|
io: Io;
|
|
9
9
|
exec: Exec;
|
|
10
10
|
fetch: Fetch;
|
|
11
|
+
pause: (milliseconds: number) => Promise<void>;
|
|
11
12
|
self: string;
|
|
12
13
|
interactive: boolean;
|
|
13
14
|
ask: (question: string) => Promise<string>;
|
package/dist/dev/index.js
CHANGED
|
@@ -2,21 +2,24 @@ import { execFileSync } from "node:child_process";
|
|
|
2
2
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { setTimeout as pause } from "node:timers/promises";
|
|
5
6
|
import { askOnTerminal, DB_USAGE, parseDb, runDb } from "./db.js";
|
|
6
7
|
import { CHECKOUT_ENV_USAGE, runCheckoutEnv } from "./checkoutEnv.js";
|
|
7
8
|
import { LOGS_USAGE, parseLogs, runLogs } from "./logs.js";
|
|
8
9
|
import { exec, Failure, UsageError } from "./process.js";
|
|
9
10
|
import { runServer, SERVER_USAGE } from "./server.js";
|
|
10
11
|
import { loadSettings } from "./settings.js";
|
|
12
|
+
import { parseSibling, runSibling, SIBLING_USAGE } from "./sibling.js";
|
|
11
13
|
import { parseSmoke, realFetch, runSmoke, runSmokeCi, SMOKE_USAGE } from "./smoke.js";
|
|
12
14
|
import { parseTmux, runTmux, TMUX_USAGE } from "./tmux.js";
|
|
13
|
-
export const DEV_USAGE = `usage: suwgate dev <db|logs|smoke|server|tmux|checkout-env> [arguments] (every one takes --help)
|
|
15
|
+
export const DEV_USAGE = `usage: suwgate dev <db|logs|smoke|server|tmux|sibling|checkout-env> [arguments] (every one takes --help)
|
|
14
16
|
The dev scripts of the template as commands, configured by the dev section of suwgate.yml:
|
|
15
17
|
db the local PostgreSQL of the compose file: up | down | reset | psql | logs | status
|
|
16
18
|
logs why did it fail? the last warnings and errors of the server's JSON log
|
|
17
19
|
smoke read-only requests against a running stack; --ci builds and starts its own stack first
|
|
18
20
|
server the server under dotnet watch, restarted when it exits
|
|
19
21
|
tmux the whole local stack in one tmux session: start [--restart] | stop
|
|
22
|
+
sibling the images of a sibling repository, rebuilt from its checkout when stale: <name> image | up | rebuild | down | status
|
|
20
23
|
checkout-env eval "$(suwgate dev checkout-env)": own test databases and e2e ports for a linked worktree`;
|
|
21
24
|
const USAGES = {
|
|
22
25
|
db: DB_USAGE,
|
|
@@ -24,6 +27,7 @@ const USAGES = {
|
|
|
24
27
|
smoke: SMOKE_USAGE,
|
|
25
28
|
server: SERVER_USAGE,
|
|
26
29
|
tmux: TMUX_USAGE,
|
|
30
|
+
sibling: SIBLING_USAGE,
|
|
27
31
|
"checkout-env": CHECKOUT_ENV_USAGE,
|
|
28
32
|
};
|
|
29
33
|
function repositoryRootOf(cwd) {
|
|
@@ -64,6 +68,9 @@ function realEnvironment() {
|
|
|
64
68
|
io: { out: (text) => console.log(text), err: (text) => console.error(text) },
|
|
65
69
|
exec,
|
|
66
70
|
fetch: realFetch,
|
|
71
|
+
pause: async (milliseconds) => {
|
|
72
|
+
await pause(milliseconds);
|
|
73
|
+
},
|
|
67
74
|
self: `${JSON.stringify(process.execPath)} ${JSON.stringify(process.argv[1] ?? "suwgate")}`,
|
|
68
75
|
interactive: process.stdin.isTTY,
|
|
69
76
|
ask: askOnTerminal,
|
|
@@ -112,6 +119,15 @@ async function dispatch(command, args, environment) {
|
|
|
112
119
|
env: environment.env,
|
|
113
120
|
self: environment.self,
|
|
114
121
|
});
|
|
122
|
+
case "sibling": {
|
|
123
|
+
const parsed = parseSibling(args);
|
|
124
|
+
if (parsed.kind === "help") {
|
|
125
|
+
io.out(parsed.text);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
const { exec, fetch } = environment;
|
|
129
|
+
return runSibling(parsed, { settings: settings(), exec, fetch, io, pause: environment.pause });
|
|
130
|
+
}
|
|
115
131
|
default:
|
|
116
132
|
return runCheckoutEnv(args, settings(), environment.env, io);
|
|
117
133
|
}
|
package/dist/dev/process.js
CHANGED
|
@@ -13,11 +13,8 @@ export function quoted(argument) {
|
|
|
13
13
|
}
|
|
14
14
|
export const exec = (argv, options = {}) => new Promise((resolve) => {
|
|
15
15
|
const [program = "", ...args] = argv;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
: options.quiet === true
|
|
19
|
-
? ["inherit", "ignore", "ignore"]
|
|
20
|
-
: "inherit";
|
|
16
|
+
const quiet = options.quiet === true ? "ignore" : "inherit";
|
|
17
|
+
const stdio = options.capture === true ? ["inherit", "pipe", quiet] : options.quiet === true ? ["inherit", "ignore", "ignore"] : "inherit";
|
|
21
18
|
const child = spawn(program, args, {
|
|
22
19
|
cwd: options.cwd ?? process.cwd(),
|
|
23
20
|
env: { ...process.env, ...options.env },
|
package/dist/dev/settings.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ export interface SmokeCheck {
|
|
|
3
3
|
expect: string;
|
|
4
4
|
hint: string;
|
|
5
5
|
}
|
|
6
|
+
export interface SiblingSettings {
|
|
7
|
+
name: string;
|
|
8
|
+
checkout: string;
|
|
9
|
+
build: string;
|
|
10
|
+
images: string[];
|
|
11
|
+
compose: string | null;
|
|
12
|
+
health: string | null;
|
|
13
|
+
}
|
|
6
14
|
export interface DevSettings {
|
|
7
15
|
root: string;
|
|
8
16
|
name: string;
|
|
@@ -33,6 +41,7 @@ export interface DevSettings {
|
|
|
33
41
|
webDirectory: string | null;
|
|
34
42
|
logFile: string;
|
|
35
43
|
smokeChecks: SmokeCheck[];
|
|
44
|
+
siblings: SiblingSettings[];
|
|
36
45
|
}
|
|
37
46
|
export declare const BASE_PORTS: {
|
|
38
47
|
readonly server: 6300;
|
package/dist/dev/settings.js
CHANGED
|
@@ -13,22 +13,27 @@ export const DEFAULT_SMOKE_CHECKS = [
|
|
|
13
13
|
];
|
|
14
14
|
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
15
15
|
const MAX_ALIASES = 10_000;
|
|
16
|
-
const ROOT_KEYS = ["name", "portOffset", "ports", "compose", "database", "server", "smoke"];
|
|
16
|
+
const ROOT_KEYS = ["name", "portOffset", "ports", "compose", "database", "server", "smoke", "siblings"];
|
|
17
17
|
const PORT_KEYS = Object.keys(BASE_PORTS);
|
|
18
18
|
const COMPOSE_KEYS = ["file", "profile", "databaseService", "serverService", "extraServices"];
|
|
19
19
|
const DATABASE_KEYS = ["user", "password", "name", "up", "psql"];
|
|
20
20
|
const SERVER_KEYS = ["project", "logFile"];
|
|
21
21
|
const SMOKE_KEYS = ["checks"];
|
|
22
22
|
const CHECK_KEYS = ["path", "expect", "hint"];
|
|
23
|
+
const SIBLING_KEYS = ["checkout", "build", "images", "compose", "health"];
|
|
24
|
+
const HEALTH_URL = /^https?:\/\/[^/]/;
|
|
23
25
|
const PORT_RANGE = { min: 1, max: 65535 };
|
|
24
|
-
function
|
|
26
|
+
function mapping(value, where, problems) {
|
|
25
27
|
if (value === undefined)
|
|
26
28
|
return {};
|
|
27
29
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
28
30
|
problems.push(`${where} must be a mapping`);
|
|
29
31
|
return {};
|
|
30
32
|
}
|
|
31
|
-
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function section(value, where, keys, problems) {
|
|
36
|
+
const record = mapping(value, where, problems);
|
|
32
37
|
for (const key of Object.keys(record)) {
|
|
33
38
|
if (!keys.includes(key))
|
|
34
39
|
problems.push(`${where}.${key} is not a setting of suwgate dev: the settings are ${keys.join(", ")}`);
|
|
@@ -87,6 +92,37 @@ function smokeChecks(raw, problems) {
|
|
|
87
92
|
return { path: checkPath, expect, hint: text(record, "hint", where, "", problems) };
|
|
88
93
|
});
|
|
89
94
|
}
|
|
95
|
+
function optionalText(record, key, where, problems) {
|
|
96
|
+
return record[key] === undefined ? null : text(record, key, where, "", problems);
|
|
97
|
+
}
|
|
98
|
+
function sibling(name, raw, root, problems) {
|
|
99
|
+
const where = `dev.siblings.${name}`;
|
|
100
|
+
if (!NAME.test(name))
|
|
101
|
+
problems.push(`dev.siblings: the name "${name}" must be lower-case letters, digits and dashes, starting with a letter`);
|
|
102
|
+
const record = section(raw ?? {}, where, SIBLING_KEYS, problems);
|
|
103
|
+
const images = list(record, "images", where, problems);
|
|
104
|
+
if (record["images"] === undefined) {
|
|
105
|
+
problems.push(`${where}.images is missing: the images the sibling's build makes, e.g. [${name}-server:local]`);
|
|
106
|
+
}
|
|
107
|
+
else if (Array.isArray(record["images"]) && images.length === 0) {
|
|
108
|
+
problems.push(`${where}.images must name at least one image the sibling's build makes`);
|
|
109
|
+
}
|
|
110
|
+
const health = optionalText(record, "health", where, problems);
|
|
111
|
+
if (health !== null && !HEALTH_URL.test(health))
|
|
112
|
+
problems.push(`${where}.health must be an http:// or https:// address: ${health}`);
|
|
113
|
+
return {
|
|
114
|
+
name,
|
|
115
|
+
checkout: path.resolve(root, text(record, "checkout", where, `../${name}`, problems)),
|
|
116
|
+
build: text(record, "build", where, "docker compose build", problems),
|
|
117
|
+
images,
|
|
118
|
+
compose: optionalText(record, "compose", where, problems),
|
|
119
|
+
health,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function siblings(raw, root, problems) {
|
|
123
|
+
const record = mapping(raw, "dev.siblings", problems);
|
|
124
|
+
return Object.entries(record).map(([name, value]) => sibling(name, value, root, problems));
|
|
125
|
+
}
|
|
90
126
|
export function resolveSettings(raw, directories, root) {
|
|
91
127
|
if (raw === undefined) {
|
|
92
128
|
throw new Failure("suwgate.yml has no dev section: add `dev:` with at least `name: <short lower-case name of the app>` (see docs/dev.md)", 2);
|
|
@@ -133,6 +169,7 @@ export function resolveSettings(raw, directories, root) {
|
|
|
133
169
|
webDirectory: stringOrNull(directories["web"]),
|
|
134
170
|
logFile: text(serverRaw, "logFile", "dev.server", ".artifacts/logs/server.jsonl", problems),
|
|
135
171
|
smokeChecks: smokeChecks(top["smoke"], problems),
|
|
172
|
+
siblings: siblings(top["siblings"], root, problems),
|
|
136
173
|
};
|
|
137
174
|
if (problems.length > 0) {
|
|
138
175
|
throw new Failure(`suwgate.yml: ${problems.join("\n suwgate.yml: ")}`, 2);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Exec, type Io } from "./process.ts";
|
|
2
|
+
import type { DevSettings } from "./settings.ts";
|
|
3
|
+
import type { Fetch } from "./smoke.ts";
|
|
4
|
+
export declare const SIBLING_USAGE = "usage: suwgate dev sibling [<name> image | up | rebuild | down | status] (every command takes --help)\nThe Docker images of a sibling repository checked out next to this one (dev.siblings.<name> of suwgate.yml), rebuilt from\nits checkout whenever they are not what it holds now: an image is missing, it was built from another commit, it was rebuilt\nor pulled since suwgate built it, or the checkout has uncommitted changes. With no name: every sibling, its checkout and\nwhether its images are current.\n image make the images current, without starting anything\n up image, then start them with dev.siblings.<name>.compose and wait until dev.siblings.<name>.health answers\n rebuild build the images whatever their state, and recreate the stack when it runs\n down stop the stack; its data stays\n status does health answer, what compose runs, are the images current";
|
|
5
|
+
declare const ACTION_USAGES: {
|
|
6
|
+
readonly image: "usage: suwgate dev sibling <name> image\nMakes the images of dev.siblings.<name>.images current without starting anything: runs dev.siblings.<name>.build in the\nsibling's checkout when an image is missing, the images were built from another commit than the checkout's HEAD, an image is\nnot the one suwgate built (rebuilt or pulled since), or the checkout has uncommitted changes, untracked files included. Prints\none line: why it rebuilds, or that the images are current. Without a checkout, images that exist run as they are.";
|
|
7
|
+
readonly up: "usage: suwgate dev sibling <name> up\nimage, then docker compose -f <dev.siblings.<name>.compose> up -d, which recreates a container whose image changed, then waits\nup to 2 minutes until dev.siblings.<name>.health answers 2xx. Prints <name>: <the address of health, or up>. Needs compose.";
|
|
8
|
+
readonly rebuild: "usage: suwgate dev sibling <name> rebuild\nRuns dev.siblings.<name>.build in the sibling's checkout whatever the state of the images, records it, and recreates the stack\nof dev.siblings.<name>.compose when it runs.";
|
|
9
|
+
readonly down: "usage: suwgate dev sibling <name> down\ndocker compose -f <dev.siblings.<name>.compose> down: stops the stack and removes its containers; its volumes and data stay.";
|
|
10
|
+
readonly status: "usage: suwgate dev sibling <name> status\nWhether dev.siblings.<name>.health answers, docker compose ps of dev.siblings.<name>.compose, and whether the images are\ncurrent, by the rule of image, without building anything.";
|
|
11
|
+
};
|
|
12
|
+
type SiblingAction = keyof typeof ACTION_USAGES;
|
|
13
|
+
export type SiblingCommand = {
|
|
14
|
+
kind: "list";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "help";
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "run";
|
|
20
|
+
name: string;
|
|
21
|
+
action: SiblingAction;
|
|
22
|
+
};
|
|
23
|
+
export interface SiblingEnvironment {
|
|
24
|
+
settings: DevSettings;
|
|
25
|
+
exec: Exec;
|
|
26
|
+
fetch: Fetch;
|
|
27
|
+
io: Io;
|
|
28
|
+
pause: (milliseconds: number) => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare function parseSibling(args: readonly string[]): SiblingCommand;
|
|
31
|
+
export declare function runSibling(command: Exclude<SiblingCommand, {
|
|
32
|
+
kind: "help";
|
|
33
|
+
}>, environment: SiblingEnvironment): Promise<number>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Failure, UsageError } from "./process.js";
|
|
4
|
+
export const SIBLING_USAGE = `usage: suwgate dev sibling [<name> image | up | rebuild | down | status] (every command takes --help)
|
|
5
|
+
The Docker images of a sibling repository checked out next to this one (dev.siblings.<name> of suwgate.yml), rebuilt from
|
|
6
|
+
its checkout whenever they are not what it holds now: an image is missing, it was built from another commit, it was rebuilt
|
|
7
|
+
or pulled since suwgate built it, or the checkout has uncommitted changes. With no name: every sibling, its checkout and
|
|
8
|
+
whether its images are current.
|
|
9
|
+
image make the images current, without starting anything
|
|
10
|
+
up image, then start them with dev.siblings.<name>.compose and wait until dev.siblings.<name>.health answers
|
|
11
|
+
rebuild build the images whatever their state, and recreate the stack when it runs
|
|
12
|
+
down stop the stack; its data stays
|
|
13
|
+
status does health answer, what compose runs, are the images current`;
|
|
14
|
+
const ACTION_USAGES = {
|
|
15
|
+
image: `usage: suwgate dev sibling <name> image
|
|
16
|
+
Makes the images of dev.siblings.<name>.images current without starting anything: runs dev.siblings.<name>.build in the
|
|
17
|
+
sibling's checkout when an image is missing, the images were built from another commit than the checkout's HEAD, an image is
|
|
18
|
+
not the one suwgate built (rebuilt or pulled since), or the checkout has uncommitted changes, untracked files included. Prints
|
|
19
|
+
one line: why it rebuilds, or that the images are current. Without a checkout, images that exist run as they are.`,
|
|
20
|
+
up: `usage: suwgate dev sibling <name> up
|
|
21
|
+
image, then docker compose -f <dev.siblings.<name>.compose> up -d, which recreates a container whose image changed, then waits
|
|
22
|
+
up to 2 minutes until dev.siblings.<name>.health answers 2xx. Prints <name>: <the address of health, or up>. Needs compose.`,
|
|
23
|
+
rebuild: `usage: suwgate dev sibling <name> rebuild
|
|
24
|
+
Runs dev.siblings.<name>.build in the sibling's checkout whatever the state of the images, records it, and recreates the stack
|
|
25
|
+
of dev.siblings.<name>.compose when it runs.`,
|
|
26
|
+
down: `usage: suwgate dev sibling <name> down
|
|
27
|
+
docker compose -f <dev.siblings.<name>.compose> down: stops the stack and removes its containers; its volumes and data stay.`,
|
|
28
|
+
status: `usage: suwgate dev sibling <name> status
|
|
29
|
+
Whether dev.siblings.<name>.health answers, docker compose ps of dev.siblings.<name>.compose, and whether the images are
|
|
30
|
+
current, by the rule of image, without building anything.`,
|
|
31
|
+
};
|
|
32
|
+
const STATE_FOLDER = ".artifacts/dev/siblings";
|
|
33
|
+
const SHORT_REVISION = 9;
|
|
34
|
+
const HEALTH_ATTEMPTS = 60;
|
|
35
|
+
const HEALTH_PAUSE_MS = 2000;
|
|
36
|
+
const SUCCESS = { min: 200, max: 299 };
|
|
37
|
+
function isAction(word) {
|
|
38
|
+
return Object.hasOwn(ACTION_USAGES, word);
|
|
39
|
+
}
|
|
40
|
+
export function parseSibling(args) {
|
|
41
|
+
const [name, action, ...rest] = args;
|
|
42
|
+
if (name === undefined)
|
|
43
|
+
return { kind: "list" };
|
|
44
|
+
if (name.startsWith("-") || action === undefined)
|
|
45
|
+
throw new UsageError(SIBLING_USAGE);
|
|
46
|
+
if (action === "--help" && rest.length === 0)
|
|
47
|
+
return { kind: "help", text: SIBLING_USAGE };
|
|
48
|
+
if (!isAction(action))
|
|
49
|
+
throw new UsageError(SIBLING_USAGE);
|
|
50
|
+
if (rest.length === 0)
|
|
51
|
+
return { kind: "run", name, action };
|
|
52
|
+
if (rest.length === 1 && rest[0] === "--help")
|
|
53
|
+
return { kind: "help", text: ACTION_USAGES[action] };
|
|
54
|
+
throw new UsageError(`suwgate dev sibling <name> ${action} takes no arguments\n${ACTION_USAGES[action]}`);
|
|
55
|
+
}
|
|
56
|
+
function short(revision) {
|
|
57
|
+
return revision.slice(0, SHORT_REVISION);
|
|
58
|
+
}
|
|
59
|
+
function stateFile(settings, sibling) {
|
|
60
|
+
return path.join(settings.root, STATE_FOLDER, `${sibling.name}.json`);
|
|
61
|
+
}
|
|
62
|
+
function readState(file) {
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
71
|
+
return null;
|
|
72
|
+
const { revision, images } = parsed;
|
|
73
|
+
if (typeof revision !== "string" || typeof images !== "object" || images === null)
|
|
74
|
+
return null;
|
|
75
|
+
return { revision, images: images };
|
|
76
|
+
}
|
|
77
|
+
async function captured(exec, argv) {
|
|
78
|
+
const { status, stdout } = await exec(argv, { capture: true, quiet: true });
|
|
79
|
+
return status === 0 ? stdout.trim() : null;
|
|
80
|
+
}
|
|
81
|
+
async function imageIds(sibling, exec) {
|
|
82
|
+
const ids = new Map();
|
|
83
|
+
for (const image of sibling.images) {
|
|
84
|
+
const id = await captured(exec, ["docker", "image", "inspect", "-f", "{{.Id}}", image]);
|
|
85
|
+
if (id !== null && id !== "")
|
|
86
|
+
ids.set(image, id);
|
|
87
|
+
}
|
|
88
|
+
return ids;
|
|
89
|
+
}
|
|
90
|
+
function revisionOf(sibling, exec) {
|
|
91
|
+
return captured(exec, ["git", "-C", sibling.checkout, "rev-parse", "HEAD"]);
|
|
92
|
+
}
|
|
93
|
+
async function lookAt(sibling, environment) {
|
|
94
|
+
const { exec, settings } = environment;
|
|
95
|
+
const revision = await revisionOf(sibling, exec);
|
|
96
|
+
const ids = await imageIds(sibling, exec);
|
|
97
|
+
const changes = revision === null ? null : await captured(exec, ["git", "-C", sibling.checkout, "status", "--porcelain"]);
|
|
98
|
+
return { revision, ids, dirty: (changes ?? "") !== "", state: readState(stateFile(settings, sibling)) };
|
|
99
|
+
}
|
|
100
|
+
function missingImage(sibling, ids) {
|
|
101
|
+
return sibling.images.find((image) => !ids.has(image));
|
|
102
|
+
}
|
|
103
|
+
function staleReason(sibling, revision, look) {
|
|
104
|
+
const missing = missingImage(sibling, look.ids);
|
|
105
|
+
if (missing !== undefined)
|
|
106
|
+
return `the image ${missing} is missing`;
|
|
107
|
+
if (look.state === null)
|
|
108
|
+
return "suwgate has no record of the commit they were built from";
|
|
109
|
+
if (look.state.revision !== revision)
|
|
110
|
+
return `the images are from ${short(look.state.revision)}, the checkout is at ${short(revision)}`;
|
|
111
|
+
const { images } = look.state;
|
|
112
|
+
const changed = sibling.images.find((image) => images[image] !== look.ids.get(image));
|
|
113
|
+
if (changed !== undefined)
|
|
114
|
+
return `the image ${changed} is not the one suwgate built (rebuilt or pulled since)`;
|
|
115
|
+
if (look.dirty)
|
|
116
|
+
return `the checkout at ${short(revision)} has uncommitted changes`;
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function noCheckout(sibling) {
|
|
120
|
+
return `there is no git checkout of ${sibling.name} at ${sibling.checkout}`;
|
|
121
|
+
}
|
|
122
|
+
function checkoutFix(sibling) {
|
|
123
|
+
return `clone it there, or set dev.siblings.${sibling.name}.checkout in suwgate.yml`;
|
|
124
|
+
}
|
|
125
|
+
function describe(sibling, look) {
|
|
126
|
+
if (look.revision === null) {
|
|
127
|
+
const missing = missingImage(sibling, look.ids);
|
|
128
|
+
if (missing !== undefined)
|
|
129
|
+
return `the image ${missing} is missing and ${noCheckout(sibling)} to build it from: ${checkoutFix(sibling)}`;
|
|
130
|
+
return `${noCheckout(sibling)}, so its images run as they are: ${checkoutFix(sibling)}`;
|
|
131
|
+
}
|
|
132
|
+
const reason = staleReason(sibling, look.revision, look);
|
|
133
|
+
if (reason === null)
|
|
134
|
+
return `the images are current (${short(look.revision)})`;
|
|
135
|
+
return `the images are not current, ${reason}: suwgate dev sibling ${sibling.name} image rebuilds them`;
|
|
136
|
+
}
|
|
137
|
+
async function build(sibling, revision, environment) {
|
|
138
|
+
const { exec, settings } = environment;
|
|
139
|
+
const { status } = await exec(["bash", "-c", sibling.build], { cwd: sibling.checkout });
|
|
140
|
+
if (status !== 0) {
|
|
141
|
+
throw new Failure(`${sibling.name}: the build failed (exit ${status}): ${sibling.build} in ${sibling.checkout}; fix it there and run suwgate dev sibling ${sibling.name} image again`);
|
|
142
|
+
}
|
|
143
|
+
const ids = await imageIds(sibling, exec);
|
|
144
|
+
const missing = missingImage(sibling, ids);
|
|
145
|
+
if (missing !== undefined) {
|
|
146
|
+
throw new Failure(`${sibling.name}: the build passed but made no image ${missing}: make the build tag it so, or list the images it makes in dev.siblings.${sibling.name}.images`);
|
|
147
|
+
}
|
|
148
|
+
const file = stateFile(settings, sibling);
|
|
149
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
150
|
+
writeFileSync(file, `${JSON.stringify({ revision, images: Object.fromEntries(ids) }, null, 4)}\n`);
|
|
151
|
+
}
|
|
152
|
+
async function makeCurrent(sibling, environment) {
|
|
153
|
+
const look = await lookAt(sibling, environment);
|
|
154
|
+
const { io } = environment;
|
|
155
|
+
if (look.revision === null) {
|
|
156
|
+
if (missingImage(sibling, look.ids) !== undefined)
|
|
157
|
+
throw new Failure(`${sibling.name}: ${describe(sibling, look)}`);
|
|
158
|
+
io.out(`${sibling.name}: ${describe(sibling, look)}`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const reason = staleReason(sibling, look.revision, look);
|
|
162
|
+
if (reason === null) {
|
|
163
|
+
io.out(`${sibling.name}: ${describe(sibling, look)}`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
io.out(`${sibling.name}: rebuilding, ${reason}`);
|
|
167
|
+
await build(sibling, look.revision, environment);
|
|
168
|
+
}
|
|
169
|
+
function composeOf(settings, sibling, action) {
|
|
170
|
+
if (sibling.compose === null) {
|
|
171
|
+
throw new Failure(`suwgate dev sibling ${sibling.name} ${action} needs dev.siblings.${sibling.name}.compose in suwgate.yml, the compose file of this repository that runs its images; suwgate dev sibling ${sibling.name} image makes the images current without one`, 2);
|
|
172
|
+
}
|
|
173
|
+
return ["docker", "compose", "-f", `${settings.root}/${sibling.compose}`];
|
|
174
|
+
}
|
|
175
|
+
async function answers(url, fetcher) {
|
|
176
|
+
try {
|
|
177
|
+
const { status } = await fetcher(url);
|
|
178
|
+
return status >= SUCCESS.min && status <= SUCCESS.max;
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async function waitForHealth(sibling, health, compose, environment) {
|
|
185
|
+
for (let attempt = 1; attempt <= HEALTH_ATTEMPTS; attempt += 1) {
|
|
186
|
+
if (await answers(health, environment.fetch))
|
|
187
|
+
return;
|
|
188
|
+
if (attempt < HEALTH_ATTEMPTS)
|
|
189
|
+
await environment.pause(HEALTH_PAUSE_MS);
|
|
190
|
+
}
|
|
191
|
+
throw new Failure(`${sibling.name} did not answer at ${health} within 2 minutes: see ${compose.join(" ")} logs`);
|
|
192
|
+
}
|
|
193
|
+
async function start(sibling, compose, environment) {
|
|
194
|
+
const { status } = await environment.exec([...compose, "up", "-d"]);
|
|
195
|
+
if (status !== 0)
|
|
196
|
+
throw new Failure(`${sibling.name}: ${compose.join(" ")} up -d failed (exit ${status}): see ${compose.join(" ")} logs`);
|
|
197
|
+
if (sibling.health === null) {
|
|
198
|
+
environment.io.out(`${sibling.name}: up`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
await waitForHealth(sibling, sibling.health, compose, environment);
|
|
202
|
+
environment.io.out(`${sibling.name}: ${new URL(sibling.health).origin}`);
|
|
203
|
+
}
|
|
204
|
+
async function rebuild(sibling, environment) {
|
|
205
|
+
const { exec, settings, io } = environment;
|
|
206
|
+
const revision = await revisionOf(sibling, exec);
|
|
207
|
+
if (revision === null)
|
|
208
|
+
throw new Failure(`${sibling.name}: ${noCheckout(sibling)} to build from: ${checkoutFix(sibling)}`);
|
|
209
|
+
io.out(`${sibling.name}: rebuilding from ${short(revision)}`);
|
|
210
|
+
await build(sibling, revision, environment);
|
|
211
|
+
if (sibling.compose === null)
|
|
212
|
+
return;
|
|
213
|
+
const compose = composeOf(settings, sibling, "rebuild");
|
|
214
|
+
const running = await captured(exec, [...compose, "ps", "-q"]);
|
|
215
|
+
if (running !== null && running !== "")
|
|
216
|
+
await start(sibling, compose, environment);
|
|
217
|
+
}
|
|
218
|
+
async function status(sibling, environment) {
|
|
219
|
+
const { io, settings } = environment;
|
|
220
|
+
if (sibling.health !== null) {
|
|
221
|
+
io.out((await answers(sibling.health, environment.fetch))
|
|
222
|
+
? `${sibling.name}: answers at ${sibling.health}`
|
|
223
|
+
: `${sibling.name}: does not answer at ${sibling.health}: suwgate dev sibling ${sibling.name} up starts it`);
|
|
224
|
+
}
|
|
225
|
+
if (sibling.compose !== null)
|
|
226
|
+
await environment.exec([...composeOf(settings, sibling, "status"), "ps"]);
|
|
227
|
+
io.out(`${sibling.name}: ${describe(sibling, await lookAt(sibling, environment))}`);
|
|
228
|
+
}
|
|
229
|
+
async function list(environment) {
|
|
230
|
+
const { siblings } = environment.settings;
|
|
231
|
+
if (siblings.length === 0) {
|
|
232
|
+
environment.io.out("no siblings in suwgate.yml: add dev.siblings.<name> with the images its build makes (see docs/dev.md of suwgate)");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
for (const sibling of siblings) {
|
|
236
|
+
environment.io.out(`${sibling.name} (${sibling.checkout}): ${describe(sibling, await lookAt(sibling, environment))}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function siblingNamed(settings, name) {
|
|
240
|
+
const found = settings.siblings.find((sibling) => sibling.name === name);
|
|
241
|
+
if (found !== undefined)
|
|
242
|
+
return found;
|
|
243
|
+
const known = settings.siblings.map((sibling) => sibling.name);
|
|
244
|
+
const named = known.length === 0 ? "" : ` (the siblings are ${known.join(", ")})`;
|
|
245
|
+
throw new Failure(`suwgate dev sibling: no sibling "${name}" in suwgate.yml${named}: name one of them, or add dev.siblings.${name} with the images its build makes`, 2);
|
|
246
|
+
}
|
|
247
|
+
async function run(sibling, action, environment) {
|
|
248
|
+
const { settings, exec } = environment;
|
|
249
|
+
switch (action) {
|
|
250
|
+
case "image":
|
|
251
|
+
await makeCurrent(sibling, environment);
|
|
252
|
+
return 0;
|
|
253
|
+
case "up": {
|
|
254
|
+
const compose = composeOf(settings, sibling, action);
|
|
255
|
+
await makeCurrent(sibling, environment);
|
|
256
|
+
await start(sibling, compose, environment);
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
case "rebuild":
|
|
260
|
+
await rebuild(sibling, environment);
|
|
261
|
+
return 0;
|
|
262
|
+
case "down":
|
|
263
|
+
return (await exec([...composeOf(settings, sibling, action), "down"])).status;
|
|
264
|
+
case "status":
|
|
265
|
+
await status(sibling, environment);
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export async function runSibling(command, environment) {
|
|
270
|
+
if (command.kind === "list") {
|
|
271
|
+
await list(environment);
|
|
272
|
+
return 0;
|
|
273
|
+
}
|
|
274
|
+
return run(siblingNamed(environment.settings, command.name), command.action, environment);
|
|
275
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { appsettingsBound } from "./appsettingsBound.js";
|
|
2
2
|
import { bannedNugetPackages } from "./bannedNugetPackages.js";
|
|
3
|
+
import { openApiVersions } from "./openApiVersions.js";
|
|
3
4
|
import { suwbackkitWiring } from "./suwbackkitWiring.js";
|
|
4
5
|
import { unusedNugetVersions } from "./unusedNugetVersions.js";
|
|
5
|
-
export const dotnetGuards = [
|
|
6
|
+
export const dotnetGuards = [
|
|
7
|
+
bannedNugetPackages,
|
|
8
|
+
unusedNugetVersions,
|
|
9
|
+
appsettingsBound,
|
|
10
|
+
suwbackkitWiring,
|
|
11
|
+
openApiVersions,
|
|
12
|
+
];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { centralPackagesFile } from "./msbuild.js";
|
|
2
|
+
const TOOL = "Microsoft.Extensions.ApiDescription.Server";
|
|
3
|
+
const LIBRARY = "Microsoft.AspNetCore.OpenApi";
|
|
4
|
+
export function centralVersion(text, name) {
|
|
5
|
+
for (const match of text.matchAll(/<PackageVersion\b[^>]*>/g)) {
|
|
6
|
+
const element = match[0];
|
|
7
|
+
if (!new RegExp(`\\bInclude\\s*=\\s*"${name.replaceAll(".", "\\.")}"`).test(element))
|
|
8
|
+
continue;
|
|
9
|
+
return /\bVersion\s*=\s*"([^"]+)"/.exec(element)?.[1];
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
export const openApiVersions = {
|
|
14
|
+
id: "openapi-versions",
|
|
15
|
+
description: `${TOOL}, which writes the OpenAPI contract at build, is pinned in Directory.Packages.props to the same version as ${LIBRARY}, whose OpenAPI library it loads`,
|
|
16
|
+
profiles: ["dotnet"],
|
|
17
|
+
check(context) {
|
|
18
|
+
const file = centralPackagesFile(context);
|
|
19
|
+
if (!context.files.includes(file))
|
|
20
|
+
return [];
|
|
21
|
+
const text = context.read(file);
|
|
22
|
+
const tool = centralVersion(text, TOOL);
|
|
23
|
+
if (tool === undefined)
|
|
24
|
+
return [];
|
|
25
|
+
const library = centralVersion(text, LIBRARY);
|
|
26
|
+
if (library === tool)
|
|
27
|
+
return [];
|
|
28
|
+
const pin = `<PackageVersion Include="${LIBRARY}" Version="${tool}" />`;
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
target: file,
|
|
32
|
+
message: library === undefined
|
|
33
|
+
? `${TOOL} ${tool} loads the server's ${LIBRARY}, which only comes in through a package (Suwbackkit.Server) and can be another release, so the build of the contract fails with a Microsoft.OpenApi version mismatch: pin it beside the tool, ${pin} (transitive pinning makes it win), so an update moves both`
|
|
34
|
+
: `${TOOL} is ${tool} but ${LIBRARY} is ${library}: the tool loads the server's OpenAPI library and fails on a Microsoft.OpenApi version mismatch, so give both the same version`,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
},
|
|
38
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maniumek/suwgate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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",
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
}
|
|
148
148
|
},
|
|
149
149
|
"dev": {
|
|
150
|
-
"description": "What suwgate dev needs to run the local stack of the repository: db, logs, smoke, server, tmux, checkout-env.",
|
|
150
|
+
"description": "What suwgate dev needs to run the local stack of the repository: db, logs, smoke, server, tmux, sibling, checkout-env.",
|
|
151
151
|
"type": "object",
|
|
152
152
|
"additionalProperties": false,
|
|
153
153
|
"required": ["name"],
|
|
@@ -256,6 +256,44 @@
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
|
+
},
|
|
260
|
+
"siblings": {
|
|
261
|
+
"description": "Sibling repositories checked out next to this one whose Docker images this repository runs, by their kebab-case name; suwgate dev sibling <name> rebuilds the images from the checkout whenever they are not what it holds now.",
|
|
262
|
+
"type": "object",
|
|
263
|
+
"propertyNames": { "$ref": "#/$defs/id" },
|
|
264
|
+
"additionalProperties": {
|
|
265
|
+
"type": "object",
|
|
266
|
+
"additionalProperties": false,
|
|
267
|
+
"required": ["images"],
|
|
268
|
+
"properties": {
|
|
269
|
+
"checkout": {
|
|
270
|
+
"type": "string",
|
|
271
|
+
"minLength": 1,
|
|
272
|
+
"description": "The sibling's git checkout, relative to the repository root (default ../<name>)."
|
|
273
|
+
},
|
|
274
|
+
"build": {
|
|
275
|
+
"type": "string",
|
|
276
|
+
"minLength": 1,
|
|
277
|
+
"description": "A bash command, run in the checkout, that builds the images (default docker compose build)."
|
|
278
|
+
},
|
|
279
|
+
"images": {
|
|
280
|
+
"description": "The images the build makes and this repository runs, e.g. [suwagcms-server:local, suwagcms-web:local].",
|
|
281
|
+
"type": "array",
|
|
282
|
+
"minItems": 1,
|
|
283
|
+
"uniqueItems": true,
|
|
284
|
+
"items": { "type": "string", "minLength": 1 }
|
|
285
|
+
},
|
|
286
|
+
"compose": {
|
|
287
|
+
"$ref": "#/$defs/relativePath",
|
|
288
|
+
"description": "A compose file of this repository that runs the images; up, down and status need it."
|
|
289
|
+
},
|
|
290
|
+
"health": {
|
|
291
|
+
"type": "string",
|
|
292
|
+
"pattern": "^https?://[^/]",
|
|
293
|
+
"description": "An address whose GET answers 2xx once the sibling is up; up waits for it up to 2 minutes."
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
259
297
|
}
|
|
260
298
|
}
|
|
261
299
|
},
|