Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
377 lines (330 loc) · 16.1 KB
/
Copy pathMakefile
File metadata and controls
377 lines (330 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
.PHONY: lint lint-docs vuln typecheck fmt fmt-check build test test-frontend test-e2e test-inventory test-stack test-multinode test-stack-race e2e-up e2e-down check bench bench-baseline bench-diff sbom sbom-check sbom-verify hooks cover spec spec-extract spec-extract-check spec-genmcp spec-report spec-report-full spec-transcript spec-mutants spec-mutants-generate
# Where test-stack puts its instrumented binary and the profiles it writes.
# Both are gitignored, and neither replaces ./cetacean.
E2E_BINARY := cetacean.cover
E2E_RACE_BIN := cetacean.race
E2E_COVERDIR := coverdata
SPEC_VET := spec-vet
# The multi-node lane skips unless its variable is set, which only this sets:
# run inside the main suite, its worker would outlive the lanes after it.
MULTINODE_TEST := CETACEAN_E2E_MULTINODE=1 go test -tags e2e -count=1 -timeout 10m \
-run '^TestMultiNode$$' ./test/e2e/
# Where a run writes what it exercised. Gitignored.
SPEC_CLAIMS := .spec-claims
PKG ?= ./internal/oauth
## Lint all code and the published docs
lint: lint-docs
golangci-lint run ./...
go run ./scripts/comment-cap
actionlint
zizmor --config .github/zizmor.yml .github/workflows/
pnpm --filter frontend exec oxlint
pnpm --filter frontend exec knip
pnpm --filter website exec oxlint
## Lint the prose of the published docs
# The pages the website publishes, the changelog, and the two a contributor reads
# first. The design specs and the test protocol are working notes.
DOCS := $(filter-out docs/test_%,$(wildcard docs/*.md docs/*.mdx)) README.md CONTRIBUTING.md CHANGELOG.md
VALE_FLAGS ?=
lint-docs: .vale/styles/.synced
vale $(VALE_FLAGS) $(DOCS)
# The style packages BasedOnStyles names, by URL and SHA-256. Fetched here rather
# than by `vale sync`, which checks nothing it downloads.
VALE_PACKAGES := \
https://github.com/errata-ai/Google/releases/download/v0.7.0/Google.zip=dddb3dca035a067fe9ab13a1d8d8f89cb63e8b83ab4cf1934a935d60cd91d697 \
https://github.com/errata-ai/proselint/releases/download/v0.3.4/proselint.zip=48b1fb481ba44f6505d44346b283f6cdc74efd234f913bbdb09bf34420fab81c
.vale/styles/.synced: Makefile
@set -e; for package in $(VALE_PACKAGES); do \
url=$${package%=*}; zip=$$(mktemp); \
curl -fsSL -o "$$zip" "$$url"; \
echo "$${package##*=} $$zip" | sha256sum -c - >/dev/null || { echo "checksum mismatch: $$url" >&2; rm -f "$$zip"; exit 1; }; \
unzip -qo "$$zip" -d .vale/styles; rm -f "$$zip"; \
done
touch $@
## Fail on a reachable vulnerability that VULN_IGNORE does not list
# Both are in github.com/docker/docker and have no fixed version. Drop an ID
# once govulncheck names a release that fixes it.
VULN_IGNORE := GO-2026-4887 GO-2026-4883
vuln:
@out=$$(go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 -format json ./...) && \
found=$$(printf '%s' "$$out" | jq -r --arg ignore "$(VULN_IGNORE)" \
'select(.finding.trace[0].function? != null) | .finding.osv | select(IN($$ignore | split(" ")[]) | not)' | sort -u) && \
if [ -n "$$found" ]; then echo "reachable vulnerabilities:"; echo "$$found"; exit 1; fi
## Type-check the frontend and the website
# The website's error reference is generated from Go source, and `astro check`
# type-checks the module that imports it, so the generated file has to exist
# before the check runs.
typecheck:
pnpm --filter frontend check
pnpm --filter website sync-assets && pnpm --filter website check
## Format all code in place
fmt:
golangci-lint fmt ./...
pnpm --filter frontend exec oxfmt --write .
pnpm --filter website exec oxfmt --write .
## Check formatting without modifying files
fmt-check:
golangci-lint fmt --diff ./... 2>&1 | diff /dev/null -
pnpm --filter frontend exec oxfmt --check .
pnpm --filter website exec oxfmt --check .
## Build everything
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
# A clean tree is stamped with its commit's time, so rebuilding a commit is
# reproducible; a dirty one (as VERSION's -dirty counts it) with the clock's.
DATE ?= $(shell if [ -z "$$(git status --porcelain --untracked-files=no 2>/dev/null)" ] \
&& d=$$(TZ=UTC0 git log -1 --date=format-local:%Y-%m-%dT%H:%M:%SZ --format=%cd 2>/dev/null) \
&& [ -n "$$d" ]; then echo "$$d"; else date -u +%Y-%m-%dT%H:%M:%SZ; fi)
LDFLAGS := -X github.com/radiergummi/cetacean/internal/version.Version=$(VERSION) \
-X github.com/radiergummi/cetacean/internal/version.Commit=$(COMMIT) \
-X github.com/radiergummi/cetacean/internal/version.Date=$(DATE)
build: node_modules
pnpm --filter frontend build
pnpm --filter frontend build:widgets
go build -trimpath -ldflags "$(LDFLAGS)" -o cetacean .
## Install the workspace the build embeds. Not phony: the stamp is the
## directory itself, so a second `make build` skips the install.
node_modules: pnpm-lock.yaml
pnpm install --frozen-lockfile
@touch $@
## Run all tests
test:
go test ./...
## Run the frontend unit tests (vitest), as CI's test-frontend job does
test-frontend:
pnpm --filter frontend test --run
## Run the e2e suite's inventory gates, which read the router and need no Docker
#
# -short makes harness.Up skip, so a gate that needs the environment skips
# here and runs in test-stack.
test-inventory:
go test -tags e2e -short -count=1 -run '^TestEvery' ./test/e2e/
## Run end-to-end tests
test-e2e:
pnpm --filter frontend exec playwright test
## Run the end-to-end stack suite (local only; needs Docker)
## -p 1 serialises packages: each reserves the same lane ports, so parallel
## packages would fight over them. The multi-node lane runs last, once the rest
## pass, since a joined worker can take the tasks the other lanes assert over.
## The environment is torn down on success and left running on failure.
test-stack: build
go build -cover -coverpkg=./... -ldflags "$(LDFLAGS)" -o $(E2E_BINARY) .
rm -rf $(E2E_COVERDIR) && mkdir -p $(E2E_COVERDIR)
@GOCOVERDIR=$(PWD)/$(E2E_COVERDIR) CETACEAN_E2E_BINARY=$(PWD)/$(E2E_BINARY) \
go test -tags e2e -p 1 -count=1 -timeout 30m ./test/e2e/... && \
GOCOVERDIR=$(PWD)/$(E2E_COVERDIR) CETACEAN_E2E_BINARY=$(PWD)/$(E2E_BINARY) \
$(MULTINODE_TEST); \
status=$$?; \
if [ $$status -eq 0 ]; then \
$(MAKE) e2e-down; \
else \
echo "e2e environment left running for inspection; tear down with: make e2e-down"; \
fi; \
echo ""; \
echo "── what the e2e suite reached ────────────────────────────"; \
go tool covdata percent -i=$(E2E_COVERDIR) \
| sed 's|github.com/radiergummi/cetacean|@.|g' | tr '@' '\n' \
| grep 'coverage:' | sed 's/[[:space:]]*coverage: / /' | sort \
| awk '{ printf " %-28s %s\n", $$1, $$2 }'; \
go tool covdata func -i=$(E2E_COVERDIR) \
| awk 'END { printf " %-28s %s\n\n", "TOTAL", $$NF }'; \
exit $$status
## Run only the multi-node lane, which joins a second engine as a worker
## The environment is left up either way; tear it down with `make e2e-down`.
test-multinode: build
$(MULTINODE_TEST)
## Run the end-to-end stack suite against a race-instrumented binary
## CI's `go test -race ./...` covers the packages in isolation; nothing until
## now ran the real server's concurrency -- the watcher goroutines, the cache
## mutex, the SSE fan-out, the MCP notification manager and the ACL hot reload
## -- against real Docker events. halt_on_error=1 makes the first race kill
## the SUT, which sut.assertExitedCleanly then reports against the case that
## provoked it; without it the detector logs and the run carries on.
## No coverage here: -cover and -race together make an already slow suite
## slower for a number `make test-stack` already reports.
test-stack-race: build
go build -race -ldflags "$(LDFLAGS)" -o $(E2E_RACE_BIN) .
@GORACE=halt_on_error=1 CETACEAN_E2E_BINARY=$(PWD)/$(E2E_RACE_BIN) \
go test -tags e2e -p 1 -count=1 -timeout 60m ./test/e2e/... && \
GORACE=halt_on_error=1 CETACEAN_E2E_BINARY=$(PWD)/$(E2E_RACE_BIN) \
$(MULTINODE_TEST); \
status=$$?; \
if [ $$status -eq 0 ]; then \
$(MAKE) e2e-down; \
else \
echo "e2e environment left running for inspection; tear down with: make e2e-down"; \
fi; \
exit $$status
## Bring the end-to-end environment up with fixtures, and run cetacean against it
# CETACEAN_CONFIG=/dev/null blocks the config-file autodiscovery a plain
# `./cetacean` invocation would otherwise do (./cetacean.toml in the repo
# root, then the user's own ~/.cetacean.toml) -- a developer's own local
# config silently changing this environment is exactly what the harness
# exists to rule out. CETACEAN_OPERATIONS_LEVEL=3 is set because
# frontend/e2e's specs assert write affordances (Remove buttons, editors) are
# present unconditionally, not gated on CETACEAN_E2E_WRITE -- at the default
# level 0 those assertions fail not because anything is broken, but because
# the Allow-header-gated buttons the specs look for are correctly absent.
e2e-up: build
go run -tags e2e ./test/e2e/cmd/e2eenv
env -i \
PATH="$$PATH" \
HOME="$$HOME" \
CETACEAN_CONFIG=/dev/null \
CETACEAN_AUTH_MODE=none \
CETACEAN_OPERATIONS_LEVEL=3 \
CETACEAN_LISTEN_ADDR=:19001 \
CETACEAN_DOCKER_HOST=tcp://127.0.0.1:12375 \
CETACEAN_PROMETHEUS_URL=http://127.0.0.1:19090 \
CETACEAN_SNAPSHOT=false \
./cetacean & echo $$! > test/e2e/.sut.pid
@# Wait for the first full sync, not just for the port to open. Backgrounding
@# the binary and printing straight away hands the browser suite a server
@# whose cache is still filling, and its first spec fails on a cluster that
@# is not there yet.
@for i in $$(seq 1 60); do \
if curl -fsS -m 2 http://localhost:19001/-/ready >/dev/null 2>&1; then break; fi; \
if [ $$i -eq 60 ]; then echo "cetacean did not become ready on :19001" >&2; exit 1; fi; \
sleep 1; \
done
@# Relabel the fixtures now that the SUT is watching. Its history ring
@# buffer is fed by watcher events, and the initial full sync records
@# none, so without this every Recent Activity section is empty and the
@# specs that assert one skip.
go run -tags e2e ./test/e2e/cmd/e2eenv -history
@echo "Cetacean running at http://localhost:19001"
@echo "Run the browser suite with:"
@echo " CETACEAN_E2E_URL=http://localhost:19001 make test-e2e"
## Tear the end-to-end environment down, including volumes
# Tolerates a stale pidfile (process already exited) or none at all (e.g.
# torn down after test-stack, which never wrote one) — the pidfile is always
# removed once a kill has been attempted, so a dead PID cannot wedge teardown.
e2e-down:
-@if [ -f test/e2e/.sut.pid ]; then \
kill $$(cat test/e2e/.sut.pid) 2>/dev/null || true; \
rm -f test/e2e/.sut.pid; \
fi
docker compose -f test/e2e/compose.e2e.yaml --profile multinode down -v
-docker run --rm -v $(PWD)/test/e2e/certs:/certs alpine sh -c 'rm -rf /certs/..?* /certs/.[!.]* /certs/*' 2>/dev/null
-rm -rf test/e2e/certs
## Measure the repository coverage baseline: what `go test ./...` reaches.
cover:
go test -coverprofile=cover.out -covermode=atomic ./...
go tool cover -func=cover.out | tail -1
@echo "HTML report: go tool cover -html=cover.out"
## Check the requirement registry against the test suite
#
# spec-vet holds callers to what the static scan can read, so the two run
# together: a claim it refuses is one the scan silently does not see.
spec:
go run ./scripts/spec-gate static
go run ./scripts/spec-gate sweep
@go build -o $(SPEC_VET) ./scripts/spec-vet
go vet -vettool=$(CURDIR)/$(SPEC_VET) ./...
go vet -tags e2e -vettool=$(CURDIR)/$(SPEC_VET) ./test/e2e/...
## Prove each requirement's tests refuse its mutants
#
# Minutes rather than seconds, so it has its own CI job and is not in `check`.
spec-mutants:
go run ./scripts/spec-gate mutants
## Report the operator swaps one package's tests do not notice
#
# Discovery, not a gate: an equivalent mutant survives honestly and no
# threshold tells it from a hole. A survivor worth keeping becomes a registry
# mutant, attached to the requirement it breaks.
spec-mutants-generate:
go run ./scripts/spec-gate mutants --generate $(PKG)
# Clears the claims directory first: a stale <pid>.claims from an earlier run
# would satisfy a requirement this run never reached.
define SPEC_UNIT_CLAIMS
rm -rf $(SPEC_CLAIMS) && mkdir -p $(SPEC_CLAIMS)
CETACEAN_SPEC_CLAIMS=$(CURDIR)/$(SPEC_CLAIMS) go test -count=1 ./...
endef
## Report what the unit suite exercised
spec-report:
$(SPEC_UNIT_CLAIMS)
go run ./scripts/spec-gate report --claims $(SPEC_CLAIMS) --suites unit
## Print each requirement beside what a test watched the server do
#
# The transcript goes to stdout and the summary to stderr, so redirecting the
# first leaves the gate's own output readable.
spec-transcript:
$(SPEC_UNIT_CLAIMS)
go run ./scripts/spec-gate report --claims $(SPEC_CLAIMS) --suites unit --transcript
## Report what the unit and e2e suites exercised together
spec-report-full: build
$(SPEC_UNIT_CLAIMS)
CETACEAN_SPEC_CLAIMS=$(CURDIR)/$(SPEC_CLAIMS) \
go test -tags e2e -p 1 -count=1 -timeout 30m ./test/e2e/...
go run ./scripts/spec-gate report --claims $(SPEC_CLAIMS) --suites unit,e2e
## Report the normative statements no registry entry accounts for
#
# Needs network: it fetches each document's own text at the revision the
# registry pins. Not part of `check` — the sentence splitter is approximate, so
# the output is a list to reconcile. --check holds each document to
# scripts/spec-extract/baseline.yaml.
spec-extract:
go run ./scripts/spec-extract -v
spec-extract-check:
go run ./scripts/spec-extract --check
## Regenerate the MCP registry families from upstream
#
# Needs network: it fetches the conformance suite's requirement files and the
# published revision's pages at the commits scripts/spec-genmcp pins, and reads
# the site's own anchors back. Not part of `check`.
spec-genmcp:
go run ./scripts/spec-genmcp
git diff --exit-code internal/spec/registry/mcp/
## Run all checks (lint + type check + format check + Go, e2e-inventory and frontend tests + spec)
#
# vuln is not here: govulncheck fetches its database on every run, so it
# needs the network, and CI runs it on its own.
check: lint typecheck fmt-check test test-inventory test-frontend spec
## Run the Go benchmark suite, writing results to bench.txt
#
# The default is a fixed iteration count rather than a duration: allocs/op and
# B/op are what these are read for, those are counted rather than timed, and a
# fixed count keeps a run to a predictable couple of minutes. Override for
# timing work, where a duration and more samples are worth the wait:
#
# make bench BENCHTIME=1s BENCHCOUNT=10
# make bench BENCH='BenchmarkHandleSearch|BenchmarkStackMatcher'
#
# -race is deliberately absent: it perturbs allocation accounting.
BENCH ?= .
BENCHTIME ?= 200x
BENCHCOUNT ?= 6
BENCHPKGS ?= ./internal/...
BENCHOUT ?= bench.txt
bench:
go test -run '^$$' -bench '$(BENCH)' -benchmem \
-benchtime=$(BENCHTIME) -count=$(BENCHCOUNT) $(BENCHPKGS) \
| tee $(BENCHOUT)
## Record the current results as the baseline to compare against
bench-baseline: bench
@cp $(BENCHOUT) bench-baseline.txt
@echo "baseline recorded in bench-baseline.txt"
## Compare bench.txt against the recorded baseline
#
# Run `make bench-baseline` before changing anything, then `make bench` after,
# then this. benchstat reports allocs/op with no noise, so any movement there is
# real; sec/op needs a quiet machine before it means much.
bench-diff:
@test -f bench-baseline.txt || { echo "no baseline: run 'make bench-baseline' first" >&2; exit 1; }
go run golang.org/x/perf/cmd/benchstat@v0.0.0-20260929162123-406019bb8b68 bench-baseline.txt $(BENCHOUT)
## Generate the CycloneDX SBOM (Go + frontend npm) embedded into the binary
SBOM_ARTIFACTS := $(shell grep -v '^\#' scripts/sbom-artifacts.txt)
sbom:
./scripts/build-sbom.sh
## Verify the committed SBOM is up to date (CI gate)
sbom-check: sbom sbom-verify
## Compare the committed SBOM artifacts against the working tree, without
## regenerating them. Split out of sbom-check so CI can regenerate once and then
## verify, rather than paying for the build twice.
sbom-verify:
@git diff --exit-code -- $(SBOM_ARTIFACTS) \
|| { echo "ERROR: SBOM artifacts are stale. Run 'make sbom' and commit." >&2; exit 1; }
## Install the repository git hooks (opt-in)
hooks:
git config core.hooksPath .githooks
@echo "git hooks installed (core.hooksPath=.githooks)"