Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
721 lines (672 loc) · 44.2 KB
/
Copy pathMakefile
File metadata and controls
721 lines (672 loc) · 44.2 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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
BINARY := abcd
BINDIR := bin
TARGETS := darwin/arm64 darwin/amd64 linux/arm64 linux/amd64
# Version stamped into `abcd --version`. Defaults to the in-source "dev" value; the
# release build passes the git tag (VERSION=vX.Y.Z). SemVer, v-prefixed.
VERSION ?=
# -s -w strips the symbol table and DWARF debug info; -X stamps the version.
# -trimpath (in the build recipe) rewrites absolute source paths to module paths
# so no local filesystem path is embedded — a smaller, path-clean binary suitable
# for public distribution.
LDFLAGS := -s -w$(if $(VERSION), -X github.com/intentdriven/abcd/internal/core.Version=$(VERSION),)
# The Go toolchain version go.mod declares, read from the declaration rather
# than spelled here: a second spelling is a second thing to bump, and the one
# that falls behind is the one nothing runs. Drives the format gate and every
# Go step `preflight` makes, below.
GO_TOOLCHAIN_VERSION := $(shell sed -n 's/^go \([0-9][0-9.]*\)$$/\1/p' go.mod)
# Every Go step a target here makes builds under -trimpath. Without it go puts a
# package's directory in its compile key, so each worktree adds its own compiled
# copy of every package to the build cache; with it a second checkout's build of
# ./cmd/abcd added 1.9 MiB rather than 170.5 MiB. It goes through the environment,
# not onto each recipe line, for two reasons: it reaches the go a script or a test
# starts (the evals' build of abcd, the outbound checker), and it leaves every
# command line alone, since the load gate reads waiters and race runs from their
# argv and the tests hold the stages' lines to CI's. A flag in the person's own
# environment stays; one set only with `go env -w` is not read here, as CI has none.
# CI sets the same in its workflow env (TestCIBuildsUnderTrimpath), and its smoke
# and cold-reading jobs run these targets, so preflight judges the form CI runs. No
# code may read its own source path, which -trimpath breaks (sourcepath_test.go).
export GOFLAGS := $(strip $(filter-out -trimpath,$(GOFLAGS)) -trimpath)
.PHONY: build test vet clean preflight preflight-stages precheck load-check lint-reviews lint-issues record-lint issue-drift docs-lint site-render smoke \
evals-cold-reading check-attribution secrets-check vulncheck scaffold-sync scaffold-sync-check asking-sync asking-sync-check command-facts-sync command-facts-sync-check refusal-codes-sync refusal-codes-sync-check fmt fmt-check
# Cross-compile every supported target to bin/abcd-<goos>-<arch>.
# Pass VERSION=vX.Y.Z to stamp the version (release builds); omit for a dev build.
build:
@mkdir -p $(BINDIR)
@for target in $(TARGETS); do \
goos=$${target%/*}; goarch=$${target#*/}; \
out=$(BINDIR)/$(BINARY)-$$goos-$$goarch; \
echo "building $$out"; \
GOOS=$$goos GOARCH=$$goarch go build -trimpath -ldflags "$(LDFLAGS)" -o $$out ./cmd/abcd || exit 1; \
done
test:
go test ./...
# Every eval in evals/: the self-discovering smoke harness (build the binary, walk
# the Cobra tree, run every command's --help + the read-only verbs) and the
# cold-reading evals below. Behind the `smoke` build tag so they stay out of the
# unit-test lane; run explicitly here, under `make preflight`, in CI's smoke job,
# and in the release verify gate.
# The eval lanes' budget (iss-2610241228178135): with no -timeout, go test kills
# the evals package at ten minutes, which a loaded development machine reached
# with no test hung. Each workflow step that runs an eval lane sets its own,
# below its job's timeout-minutes, so a hang there still dumps goroutines
# (internal/core/lint/evallanebudget_test.go holds both).
EVAL_TIMEOUT ?= 20m
ifeq ($(strip $(EVAL_TIMEOUT)),)
override EVAL_TIMEOUT := 20m
endif
smoke:
go test -tags smoke -count=1 -timeout $(EVAL_TIMEOUT) ./evals/...
# The cold-reading evals alone (evals/coldreading_*_test.go): the read-block eval
# that falsifies the assembler's blindfold by planting sentinel warm content in a
# fixture repository state and asserting its absence from what the assembler
# passes.
#
# Both this target and `smoke` are `preflight` prerequisites, so the push gate
# sees what CI sees for the eval lanes rather than trusting a job that cannot
# block a merge (iss-2608311632382737).
#
# It has its own target, and CI its own always-run job, because the diff
# classifier stands the `smoke` job down on a change confined to docs/,
# .abcd/development/, .abcd/work/ and the root prose files — and those are
# precisely the paths these evals read. A record-only change is the diff MOST
# able to introduce warm content into material the assembler includes, so
# standing the eval down there is anti-correlated with the risk, and a stood-down
# job still reports its check context green. Same reasoning `.github/workflows/ci.yml`
# already documents for the ubuntu unit lane, which never stands down because its
# tests read the live tree under the allowlist.
#
# The selection is a BUILD TAG, not a list of test names: every file carrying
# `//go:build smoke || coldreading` runs here and under `make smoke` both, so a
# second cold-reading eval joins the lane by carrying that constraint, with no
# edit to this target or to the workflow.
evals-cold-reading:
go test -tags coldreading -count=1 -timeout $(EVAL_TIMEOUT) ./evals/...
# Format gate, resolved through the toolchain go.mod declares
# (iss-2609081953452204). Not `gofmt` off PATH: gofmt's rules move between
# releases — go 1.27 re-indents a multi-value return whose operands are
# composite literals, which this tree contains at internal/core/ahoy/remote.go —
# so on a machine newer than the declaration a bare `gofmt -l .` names a file
# that CI's pinned gofmt calls correctly formatted. The developer reformats what
# the gate names and pushes a file CI then rejects in the other direction, and
# neither direction is visible in the output, which names a file and never says
# which toolchain judged it.
#
# scripts/pinned-toolchain.sh is the one resolver: `GOTOOLCHAIN=go<version> go
# env GOROOT` fetches and caches the declared toolchain if the machine lacks it,
# then reports where it landed, and the gofmt under that GOROOT is the one CI
# runs. `fmt` applies the same binary, so the remedy and the diagnosis can never
# disagree, and `preflight` exports the same GOTOOLCHAIN to every Go step it
# makes (see below), the load gate's `go run` first on the full rule, and runs
# this gate first among its stages, straight after the load check.
#
# It REFUSES rather than falling back when the toolchain cannot be resolved
# (offline, or the fetch declined). A fallback would print a filename judged by
# the wrong gofmt, which is precisely the false green this target removes — the
# skew is named in the refusal instead
# (.abcd/development/principles/loud-staging.md).
define pinned_gofmt
@set -eu; \
version='$(GO_TOOLCHAIN_VERSION)'; \
goroot="$$(scripts/pinned-toolchain.sh "$$version")" || exit 2; \
case '$(1)' in \
check) \
unformatted="$$("$$goroot/bin/gofmt" -l .)"; \
if [ -n "$$unformatted" ]; then \
echo "gofmt: these files are not formatted (run \`make fmt\`):" >&2; \
echo "$$unformatted" >&2; \
exit 1; \
fi; \
echo "fmt-check: the tree is formatted under go$$version's gofmt"; \
;; \
write) \
"$$goroot/bin/gofmt" -l -w .; \
;; \
esac
endef
# The gate: name every file the declared toolchain's gofmt would rewrite, and
# exit non-zero if there is one. This is CI's `Format (gofmt)` step — the
# workflow invokes this target rather than restating the command, so the
# developer's gate and CI's gate are one thing
# (.abcd/development/principles/one-canonical-primitive.md).
fmt-check:
$(call pinned_gofmt,check)
# The remedy: rewrite them, with the same binary the gate judged them by.
fmt:
$(call pinned_gofmt,write)
vet:
go vet ./...
# Deterministic gate for the .abcd/work/reviews/ charter (RD001-RD004) — a
# stopgap until these codes land in internal/core/lint. Needs full git history
# (RD002 is append-only over committed history): on a shallow checkout the
# script refuses (exit 2) rather than pass vacuously with nothing covered. The
# cases run first, as in lint-issues: a gate nobody has watched fail is an
# enforcement claim with no evidence behind it.
lint-reviews:
@bash scripts/check-reviews-cases.sh
@bash scripts/check-reviews.sh
# AI-attribution gate (AGENTS.md § Attribution), the commit half: the author and
# committer identity and the trailers of every commit on this branch that
# origin/main does not hold, judged as CI's attribution workflow judges them. A
# preflight prerequisite (iss-2608210738363966): a commit CI refuses here was
# otherwise found only after the push, and a pushed commit is repaired only on a
# new branch, because a force push is refused. The pull-request BODY half runs
# only in CI, where the body exists. The cases run first, as in lint-issues. The
# outbound checker is built once from this checkout and handed to the script
# (ABCD_OUTBOUND_BIN), so a branch of many commits pays one build, not one
# `go run` per commit.
check-attribution:
@bash scripts/check-attribution-cases.sh
@tmp=$$(mktemp -d) && trap 'rm -rf "$$tmp"' EXIT && \
go build -o "$$tmp/abcd" ./cmd/abcd && \
ABCD_OUTBOUND_BIN="$$tmp/abcd" bash scripts/check-attribution.sh commits origin/main HEAD
# The two scans CI runs on every pull request (iss-2610261151381604), as
# preflight prerequisites so a finding stops the run before its build and test
# stages: gitleaks over the branch's own commits (origin's default
# branch..HEAD) and govulncheck over the module, each at the version ci.yml pins,
# read from ci.yml. A gitleaks on PATH at another version, or none, is replaced
# by CI's release, sha256-checked against scripts/gitleaks-checksums.txt, and
# the scan refuses when that cannot be fetched or verified
# (iss-2611081341084748). govulncheck is built at CI's version and run as its
# own binary, not through go run, which reports a finding's exit 3 as exit 1
# (iss-2611110905076301). A govulncheck with no network for its database, or
# none to build, is skipped loudly, never passed in silence, and CI's scan still
# runs; one whose build fails its checksum verification refuses. A govulncheck
# finding on a branch that changes neither go.mod nor go.sum, when the fork point's own tree reports
# every vulnerability it names, was not brought in by the branch
# (iss-2610261151481013, iss-2610262259078996), and govulncheck is not a
# required check, so it warns and does not stop the run; any other finding
# stops it, and so does a gitleaks that runs and cannot scan. The comparison is
# by id, so a branch newly reaching an id the fork point reaches is warned of.
secrets-check:
@bash scripts/preflight-scans.sh secrets
vulncheck:
@bash scripts/preflight-scans.sh vulncheck
# Deterministic drift gate for the .abcd/development design record (first slice
# of internal/core/lint). Blocking: any record drift (stale tool names, dropped
# concepts, lifecycle or reference breakage) fails preflight and CI.
#
# `-agent-diff` arms agent_contract's unbumped-edit check — a changed agent
# prompt must bump its prompt_version and add its prompt-version log entry —
# over the branch's own changes, the merge-base range `origin/main...HEAD`. CI's
# step passes the same three-dot range from its base commit. Unarmed, the check
# is a no-op, and a prompt edit passed three green preflights to be refused in
# the merge queue (iss-2609021152026246). Like lint-issues, it needs
# origin/main.
record-lint:
@go run ./cmd/record-lint -agent-diff origin/main...HEAD
# Promote-join drift gate (itd-4 AC3). Blocking: an intent naming a record in
# `related_issues` that does not name it back, a dangling id on either side, a
# shipped intent whose issue never reached resolved/, or a retired
# `promoted_to` / `promoted_from` key fails preflight and CI. `--strict` is what
# turns the verb's warning into exit 1; the receipt lands in the local tier.
issue-drift:
@go run ./cmd/abcd intent audit --issue-drift --strict
# Deterministic issue-resolution gate (iss-2608241347321757). RS001: a
# `Resolves: iss-N` trailer must be accompanied by that record entering a terminal
# folder (resolved/ or wontfix/) in the same change, so resolution lands INSIDE
# the fix and no post-merge step
# exists to forget. RS002/RS003: a resolved_by.commit sha must name a commit
# that is actually reachable — `--commit` is shape-checked only, and the repo
# allows squash and rebase merges, either of which rewrites a cited branch sha
# out of existence. RS005: a `Delivers: itd-N` trailer must be accompanied by
# that intent entering intents/shipped/ in the same change — the intent-store
# twin of RS001 (itd-2609111003026787). The cases run first: a gate nobody has watched fail is an
# enforcement claim with no evidence behind it. Needs full git history, like
# lint-reviews: on a shallow checkout the scripts refuse (exit 2) rather than
# report unfetched commits as ledger violations.
lint-issues:
@bash scripts/check-issue-resolution-cases.sh
@bash scripts/check-issue-resolution.sh ledger HEAD
@bash scripts/check-issue-resolution.sh commits origin/main HEAD
# Deterministic docs-currency gate (itd-60): the same internal/core/lint engine,
# driven over docs/ and the repo root via the transport-agnostic `abcd lint docs`
# verb. Blocking: change-narration in a doc body, a broken relative link, a
# persona the roster does not hold, or a stray root markdown file fails
# preflight and CI. The link check also walks every other committed markdown
# file record-lint does not — the root prose, the agent prompts, the plugin
# command pages and the READMEs — through links_resolve's extra_roots in
# .abcd/docs-lint.json (iss-46).
docs-lint:
@go run ./cmd/abcd lint docs
# Site-render gate (iss-2608241845109280). The site renders the RECORD as well as
# docs/ — 852 records at the 0.6.4 cut — and the renderer supports a fixed
# markdown subset, refusing anything it would otherwise pass through unrendered.
# So a record is a site input, and a malformed one breaks the render. Nothing
# caught that before this target existed: the other lint gates read records but
# never render them, and site-screenshots.yml is path-filtered to the generator
# and docs/, so a records-only pull request changed the rendered page and
# triggered no audit. It reached a release, where `release.yml`'s site job failed
# AFTER the binaries had published.
#
# Builds into a throwaway directory, then runs `lint site` over it before
# discarding it. Build alone answers "does it render"; the publish gates
# (provenance, hero, banned-tokens, snippets, baseline, mobile, figure-labels,
# base-path, link-targets) are what release.yml's post-publish site job runs, so
# a change that renders but trips a check gate would otherwise pass every
# pre-publish gate and fail only AFTER the binaries ship. `lint site` needs no
# mkdocs — it excludes docs/ from its page walk, and link-targets leaves the
# /docs/ targets of an output with no docs tree to a note — so a plain build
# output suffices; the site workflow, which does run mkdocs, judges them. Roughly ten seconds, almost all of it writing files.
#
# Each run takes a directory of its own, so a make precheck and a make preflight
# in one worktree do not remove what the other is writing
# (iss-2611061656036069), and removes it however the run ends.
site-render:
@mkdir -p .abcd/.work.local/scratch
@d=$$(mktemp -d .abcd/.work.local/scratch/site-render-check.XXXXXX) && trap 'rm -rf "$$d"' EXIT && \
go run ./cmd/abcd site build --out "$$d/personal" >/dev/null && \
go run ./cmd/abcd lint site --out "$$d/personal" >/dev/null && \
go run ./cmd/abcd site build --project --base-path /abcd/ --out "$$d/project" >/dev/null && \
go run ./cmd/abcd lint site --project --base-path /abcd/ --out "$$d/project" >/dev/null
@echo "site-render: the record and docs render and pass the site gates, and the record on the project route too"
# Propagate the pinned action refs in the committed release workflows back into
# the scaffold templates they were rendered from (iss-209), and the pins in the
# committed project-site.yml back into the site template, the github-pages
# adapter and the site package's golden renders. Dependabot only ever edits the
# rendered workflow, which breaks the self-scaffold parity test and the project
# site's; this is the one-way fix — re-rendering the template over the workflow
# would revert the bump instead.
#
# Nothing in CI calls either target. The drift is GATED by `go test`
# (TestSelfScaffoldParity, TestAbcdsRecordIsOnTheProjectRouteSetupWrites and
# TestSyncRepoPinsIsCleanToday, all under
# preflight), which is what fails a bump that only landed on the workflow;
# these are the human's read-only look at it and the one-command fix.
scaffold-sync:
@go run ./cmd/scaffold-sync
scaffold-sync-check:
@go run ./cmd/scaffold-sync -check
# Write the asking rules (internal/core/question: asking.go, limits.go) into the
# generated blocks of commands/intent.md (spc-2610030944505997) and of
# agents/question-drafter.md, which also carries the row count. Nothing in CI
# calls either target: the drift is GATED by `go test`
# (TestIntentPageAskingBlockIsGenerated and TestDrafterBlockIsGenerated, under
# preflight); these are the read-only look at it and the one-command fix.
asking-sync:
@go run ./cmd/asking-sync
asking-sync-check:
@go run ./cmd/asking-sync -check
# Write the command facts (cli.CommandFacts, read from the command tree) into
# their derived copies (spc-2610301431075964 step 3): one JSON file per
# top-level verb under docs/reference/cli/commands/, and the ask-the-binary and
# command-facts blocks of every page under commands/. Nothing in CI calls
# either target: the drift is GATED by `go test`
# (TestCommandFactsFilesMatchTheCommittedCopies and
# TestCommandPageBlocksMatchTheCommittedPages in internal/surface/cli, under
# precheck and preflight); these are the read-only look at it and the
# one-command fix.
command-facts-sync:
@go run ./cmd/command-facts-sync
command-facts-sync-check:
@go run ./cmd/command-facts-sync -check
# Write the ledger of refusal codes (internal/core/refusal) into
# .abcd/development/release/refusal-codes.json (spc-2610301431108175 step 1),
# which the release guard reads at the last tag. Nothing in CI calls either
# target: the drift is GATED by `go test` (TestCommittedLedgerMatchesTheRegistry
# in internal/core/refusal); these are the read-only look at it and the
# one-command fix.
refusal-codes-sync:
@go run ./cmd/refusal-codes-sync
refusal-codes-sync-check:
@go run ./cmd/refusal-codes-sync -check
# The run's clock (iss-2611190439574731): named first, as make preflight starts
# and before the records-only classifier below, so the run's time counts from
# here. Either rule's last lines give each stage's time and the whole run's
# checked time beside the reuse counts, with every wait for a turn left out
# (scripts/preflight-receipt.sh, clock and clock_report).
ifneq ($(filter preflight,$(MAKECMDGOALS)),)
PREFLIGHT_CLOCK := $(shell scripts/preflight-receipt.sh clock new)
endif
# A records-only change (iss-2610251555094324) takes a shorter preflight: when
# every path HEAD changes against the merge base with origin's default branch
# lies in .abcd/development/ or .abcd/work/, no test names one of them (by its
# path, its file name or its record id), and the
# tree matches HEAD, scripts/records-only.sh says so and the second preflight
# rule below runs in place of the first. It runs the same gates, build and vet,
# then precheck's test lines in place of the unit and race stages, and says so
# before its tests and in the receipt it mints. Anything else, a failed check included,
# is the full rule. The verdict is read while this Makefile is parsed, as the
# starting state is, and only yes or nothing reaches make: the reason can name a
# changed path, so it is printed by the script itself, never placed in a recipe
# line. The records rule's first step and its mint each run the classifier
# again, so a verdict that no longer holds fails the run rather than skipping
# its tests. `make preflight PREFLIGHT_RECORDS_ONLY=` takes the full rule
# whatever the change. TestPreflightRecordsRuleRunsPrechecksTests holds the
# second rule's gates to every gate the full run runs (preflight-stages's) and
# its test lines to precheck's. The records rule waits at no load gate.
ifneq ($(filter preflight,$(MAKECMDGOALS)),)
PREFLIGHT_RECORDS_ONLY := $(if $(PREFLIGHT_FRESH),,$(shell scripts/records-only.sh >/dev/null 2>&1 && echo yes))
endif
ifneq ($(PREFLIGHT_RECORDS_ONLY),yes)
# Pre-push gate (run before a push, never by it: .githooks/pre-push checks the
# receipt the last step mints, below). It runs precheck's audit tests through
# the narrow gate beside its wait (below), waits at the load gate as one whole
# run, then runs its stages (preflight-stages): the load check first (a
# warning, never a failure: load-check), then the format gate (fmt-check), the
# six lint gates
# (lint-reviews, lint-issues, record-lint, issue-drift,
# docs-lint, and check-attribution over the branch's commits), the two scans
# CI runs on every pull request (secrets-check and vulncheck), the
# site-render gate and both tagged eval lanes (smoke, evals-cold-reading) as
# prerequisites, then build, vet, test,
# and race-enabled internal tests natively — every Go step on the toolchain
# go.mod declares, which is the one CI's check job runs those same four Go
# steps and its format gate on. Host-native `go build` (not the
# cross-compiling build target) because it mirrors CI.
#
# The unit stage runs what the race stage cannot assert, the same two plain
# passes as CI's check job (iss-2610171803053186): the packages outside
# internal/, and by name the tests that assert only without the race detector.
# The race stage runs every other test under internal/, so a plain rerun of them
# was about nine minutes of a preflight for a verdict CI does not hold a change
# to. TestPreflightUnitStageRunsWhatCIPlainPassRuns holds the two passes to CI's.
#
# The eval lanes are prerequisites because the untagged `go test ./...` step
# below cannot reach them: every eval file carries a build tag, so a defect in
# the read-block eval — the only component capable of falsifying the assembler's
# firewall — used to pass every local gate and surface only in CI, if at all
# (iss-2608311632382737). That was not hypothetical: a path-elision defect in
# the amnesia eval's own guard was unsatisfiable wherever the process temp
# directory is the Linux one, so it landed green here and was found by an
# adversarial review rather than by a gate.
#
# Both lanes are named even though `smoke` compiles a superset of
# `evals-cold-reading`'s files: they are separate tag sets, so a cold-reading
# file reaching for a smoke-only helper compiles under one and not the other,
# which is the split CI's two jobs cover. Under a minute each in CI, and
# several on a loaded machine, hence EVAL_TIMEOUT above.
#
# A preflight waits for its turn as one whole run (itd-2610262127138979,
# iss-2610241537197997): `preflight` runs the load gate's command form (`abcd
# implement load --wait -- make preflight-stages`), so a queued preflight does
# no lint, eval, build or vet work and no test work but its narrow audit runs
# (below), and the waiter is the
# parent of the whole run, its turn held until the run ends. Its prerequisites
# ran before the old gate, which stood only before the test stages, so thirty
# queued runs once kept a 10-core machine overloaded while they waited, and a
# gate inside the run waited out its two hours behind a run queued meanwhile.
# The gate stays shut while the load is at the wait limit, another go test
# -race run is live, another make preflight is running, or another waiter is
# queued ahead or running its command, under any account: it reads all of that
# from the process table, which shows every account's processes, never from a
# file another account could write. Once clear it waits 15 to 60 seconds and
# checks again, so two preflights in one quiet minute do not start together; a
# preflight whose own gate is waiting takes that waiter's place in the queue.
# It gives up after twelve hours, failing the preflight and naming what it
# still waited on, and on a CI runner it opens at once. Wrapping `make
# preflight` in the command form as well is harmless: the inner waiter is part
# of the outer one's turn and opens at once. How many preflights may run at
# once is the person's own machine setting, never the checkout's:
# load.preflights in ~/.abcd.noindex/config.json, or ABCD_LOAD_PREFLIGHTS in
# the environment for a trial, one by default and four at most
# (iss-2610161639025702, iss-2610282016250805), read again at every look of the
# wait, so a change reaches the runs already queued. The race stage waits at
# its own gate (`--race-gate`, spelt without --wait so an older abcd never
# reads a preflight there as queued at its first gate). At one, the race gate
# opens at once once the disk check passes. Above one, the first gate admits a
# preflight while fewer than that many others are running (one queued at its
# race gate runs nothing and takes no
# slot), a live race run does not shut it by itself, and a waiter queued ahead
# still does; and the race gate is shut while another go test
# -race run or race waiter ahead is live, the load is at the limit or the race
# gate's own hold is in force. That keeps race stages apart among checkouts
# that have this gate: one at a time within an account, and across accounts
# all but a narrow window (a race waiter gone before its race run shows, or,
# after a pid wrap, two waiters whose start and pid disagree: one running abcd
# v0.15.1, or two of the start order whose whole-second ages read a tie
# differently or the later of which stopped counting the earlier past its
# five-minute cap). An older checkout's
# race stage is ungated, so set more than 1 only once none runs a preflight. Each test
# stage then takes a go test -p derived from the online cores and the load as
# the stage starts, at most the cores divided by the setting
# (cmd/test-parallelism), so one run cannot saturate the machine.
# The unit stage takes the race stage's 40-minute package budget, not go
# test's 10m default: internal/core/implement/loop ran about ten minutes alone
# on a loaded development machine (2026-10-17) and timed out at 10m with no
# test hung, and on 2026-10-25 claim, implement/loop and surface/cli each
# outran 20 minutes on a 10-core Mac at a load of 5 to 7, with no test hung
# (iss-2610250007404944). Each stage doubles that budget when the one-minute
# load passes one runnable per online core as it starts
# (`cmd/test-parallelism -timeout`), since a package on a loaded machine runs
# slower in proportion, and takes no value between, since go test's cache key
# holds the timeout: three packages hit the timeout at a load of 17.8 on ten
# cores, with no test hung (iss-2610241911052191). On a CI runner it stays 40
# minutes unscaled, so make preflight's own budget never moves with CI's steps,
# which declare their own (dcn-2611062201286033).
#
# Beside that wait, precheck's audit tests run first thing
# (iss-2611232155447855): cmd/precheck-audits starts the gate's command form and,
# alongside it, precheck's three test lines (PRECHECK_AUDIT_PACKAGES in full,
# PRECHECK_AUDIT_TESTS in PRECHECK_NAMED_PACKAGES, and the audits it chooses
# everywhere else) as narrow runs of at most three packages, each through `abcd
# implement load --wait --narrow`, which admits them beside a running preflight.
# An audit test a preflight would fail after an hour's queue fails in minutes:
# the first audit run whose tests fail stops the gate's command and every other
# run, each through the process group it leads (interrupted, so go test removes
# its work directory, and killed five seconds on), and the line exits with that run's
# failure, so no receipt is minted. When the command ends first, its verdict
# decides, and the audit runs still going stop, since its unit and race stages
# run every one of their tests. The audits run beside the wait rather than ahead
# of it because a make preflight with no waiter queued beneath it is a running
# preflight to every other run's first gate: run ahead, they would hold every
# other preflight shut for as long as they took. One audit run goes at a time,
# leaving the account's other narrow places to a drive lane's short check. An
# audit run the gate refuses, at the disk floor, an unusable setting or its
# timeout, is no verdict on the tree: it says why, the rest stop, and the whole
# run decides. A run of precheck's first two lines has that line's own flags, so
# a result precheck left in go's test cache can replay; the third line's runs
# each name only their own packages' audits, so they rerun.
preflight:
go run ./cmd/precheck-audits -whole '$(PRECHECK_AUDIT_PACKAGES)' -named '$(PRECHECK_NAMED_PACKAGES)' -run '$(PRECHECK_AUDIT_TESTS)' -- go run ./cmd/abcd implement load --wait --timeout 12h -- $(PREFLIGHT_STAGES_MAKE)
@scripts/preflight-receipt.sh mint "$(PREFLIGHT_BEGAN)"
# Both test stages run through cmd/check-tests (internal/testreuse,
# itd-2611011325421304), which replays what Go's test cache holds for unchanged
# inputs, reruns what is declared or found reading past that cache, and reports
# `reused N of M` for each stage, and the receipt records both counts and how the
# stage ran. A stage's reused lines run from one fixed check directory per repository
# and account, ~/.abcd.noindex/tests/<root-sha>/, whose tree the sync reads back
# against the commit, byte for byte, before the lines run and after, writing only the
# files that differ, with file times derived from file content and -trimpath keeping
# the worktree's path out of the binary. So a fresh worktree replays what another
# worktree's check of the same inputs passed.
#
# A test named on .abcd/work/always-rerun-tests.txt on origin's default branch, or
# that the classifier finds reading what the cache cannot see, reruns on every check,
# in the worktree, and the report names a found one undeclared. The hosted run, whose
# every test step passes -count=1, is the backstop. A race stage reuses race results
# only, since its binary is another build. A working tree that differs from HEAD, and
# a list that is missing, does not read or names what the tree does not hold, run in
# the worktree reusing nothing.
#
# One check at a time holds the lock, for its reused lines and no longer, so under
# load.preflights above one a second run's reused lines wait for the first's while
# each run's rerun lines run side by side. A stage that waited takes its -p and
# -timeout again from -budget, and a race stage goes back through the race gate,
# holding nothing, since the recipe's reading of both is as old as the wait.
#
# `make preflight PREFLIGHT_FRESH=1` reuses nothing, for a person who wants that: it
# takes the full rule whatever the change, a records-only one included, and the
# receipt says `tests cut`. No cut requires it; the hosted release run reuses nothing.
# The results to be reused run under one fixed -timeout, the larger of the two the
# budget below takes, because go test's cache key holds the timeout and a result must
# not stop being reusable when the load crosses the line.
CHECK_TESTS_FLAGS = -cached-timeout 1h20m -budget 40m$(if $(PREFLIGHT_FRESH), -fresh,)
# The flags of CI's "Test (plain-only guards)" step: the -run naming the tests
# that assert only without the race detector, and the packages that hold them.
# Read from the workflow rather than spelled again, so a guard added there
# reaches preflight with no second list (TestEveryLegRunsEveryPlainOnlyGuard
# holds the workflow's list to the test files), the way preflight-scans.sh reads
# its pins. Both of the workflow's copies are held to one list, so the first
# serves. A tree whose workflow stops matching names a package that does not
# exist, so the stage fails there and names why, rather than running go test over
# no packages, which tests the working directory and passes.
PLAIN_ONLY_GUARDS = $(or $(shell sed -n "s/^ *run: go test -count=1 \(-run '^(.*)\$$' .*\)$$/\1/p" .github/workflows/ci.yml 2>/dev/null | sed -n 1p),./ci.yml-carries-no-plain-only-guards-step)
# The make the gate runs the stages with. It is named through this variable so
# the gate's line is an ordinary recipe line: make runs a line that names MAKE
# directly even under -n, -q and -t, and a dry run would then queue at the gate
# for hours. So `make -n preflight` prints the gate's line and runs nothing;
# `make -n preflight-stages` shows the stages. The cost is make's jobserver: a
# `make -j` preflight runs its stages one job at a time.
# The 12h above is internal/core/landing's preflightGateWait, which `abcd land`
# bounds a preflight by (TestGateTimeoutOutlastsTheWholeRunWait).
PREFLIGHT_STAGES_MAKE = $(MAKE) --no-print-directory preflight-stages
# preflight's stages: its gates as prerequisites, then build, vet and the two
# test stages. It is `preflight`'s command, run inside the turn the load gate
# gave the whole run, so it waits at no first gate of its own: a second waiter
# inside a held turn waited out its two hours behind a run queued meanwhile,
# each shut by the other (TestPreflightStagesHaveNoGateOfTheirOwn). Run alone it
# is ungated and mints no receipt; run `make preflight`. The variables exported
# for `preflight` below reach it through the environment. It is the full
# rule's alone: the records-only rule below waits at no gate and runs no stages
# make, and TestPreflightRecordsRuleRunsPrechecksTests holds its gates to these.
preflight-stages: load-check fmt-check lint-reviews lint-issues record-lint issue-drift docs-lint check-attribution secrets-check vulncheck site-render smoke evals-cold-reading
go build ./...
go vet ./...
p=$$(go run ./cmd/test-parallelism) && \
t=$$(go run ./cmd/test-parallelism -timeout 40m) && \
go run ./cmd/check-tests $(CHECK_TESTS_FLAGS) unit go test -p "$$p" -timeout "$$t" ./cmd/... && \
go run ./cmd/check-tests $(CHECK_TESTS_FLAGS) unit go test -p "$$p" -timeout "$$t" $(PLAIN_ONLY_GUARDS)
@scripts/preflight-receipt.sh clock mark race
go run ./cmd/abcd implement load --race-gate --timeout 2h && scripts/preflight-receipt.sh clock since race
p=$$(go run ./cmd/test-parallelism) && \
t=$$(go run ./cmd/test-parallelism -timeout 40m) && \
go run ./cmd/check-tests $(CHECK_TESTS_FLAGS) race go test -race -p "$$p" -timeout "$$t" ./internal/surface/cli ./internal/core/reading ./internal/core/launch ./internal/core/lifeboat ./internal/core/lint ./internal/adapter/scanner ./internal/core/implement/loop ./internal/core/interview ./internal/core/capture ./internal/core/ahoy ./internal/core/site ./internal/...
else
preflight: load-check fmt-check lint-reviews lint-issues record-lint issue-drift docs-lint check-attribution secrets-check vulncheck site-render smoke evals-cold-reading
@scripts/records-only.sh
@echo "preflight: a records-only change, so the unit and race stages are skipped and precheck's tests run in their place; CI's unit lane still runs every test"
go build ./...
go vet ./...
go test -timeout 20m $(PRECHECK_AUDIT_PACKAGES)
go test -timeout 20m -run '$(PRECHECK_AUDIT_TESTS)' $(PRECHECK_NAMED_PACKAGES)
go run ./cmd/precheck-audits $(PRECHECK_AUDIT_PACKAGES) $(PRECHECK_NAMED_PACKAGES)
@scripts/preflight-receipt.sh mint "$(PREFLIGHT_BEGAN)" records-only
endif
# The precheck (iss-2610230016523625): the minutes-long pass a lane runs before
# it queues a preflight, so a test that reads the whole tree fails before the
# queue rather than after it. It runs preflight's gates (all but the load check,
# which reads the machine and only warns), build and vet, the packages whose
# tests audit the record, the generated pages and the agent definitions, in full,
# and the packages whose tests read the committed record tree whole (record ids
# and slugs, the changelog derivation, intents, release pages, decisions, the
# brief's lifeboat table), the audit that every exported core function has a
# caller (internal/reachaudit), the audit that only the resolver spells the home
# folder's name (internal/abcdhome),
# the command and site packages' audit tests, chosen by name: a test in those
# two packages that reads the committed tree carries one of the PRECHECK_AUDIT_TESTS
# words in its name, which is how a new one joins without a list to keep,
# and the audit tests of every other package, chosen by what they do: cmd/precheck-audits
# picks each test that reaches the repository root, so a new one there joins with no
# word and no list (its own comment says what it cannot see). It skips
# the full unit and race stages, needs no load gate, mints no receipt and replaces
# no preflight: a pass says only that what it ran passes.
# TestPrecheckRunsEveryPreflightGateButTheLoadCheck holds its gates to preflight's
# and TestPrecheckRunsTheAuditTests its test lines to what this says. What the
# three lines choose checks itself (iss-2611232155463657):
# cmd/precheck-audits's TestPrecheckRunsEveryAuditNamedTest refuses a test named
# TestNo... or TestEvery... whose reach touches the tree, through a program it
# starts included, that none of the three runs, unless its notAudits says what
# it does instead. make preflight runs the same three lines beside its wait.
PRECHECK_AUDIT_PACKAGES := ./internal/core/lint ./internal/core/launch/scaffold ./internal/core/mdrecord ./internal/core/issueschema ./internal/core/guard ./internal/core/glossary ./internal/core/reading ./internal/core/recordid ./internal/core/changelog ./internal/core/intent ./internal/core/release ./internal/core/releasedigest ./internal/core/decisions ./internal/core/record/match ./internal/core/lifeboat ./internal/reachaudit ./internal/abcdhome ./cmd/precheck-audits
PRECHECK_NAMED_PACKAGES := ./internal/surface/cli ./internal/core/site
PRECHECK_AUDIT_TESTS := Surface|Page|Brief|Parity|Reference|Snapshot|Appendix|Appendices|Paragraph|Vocabulary|Scope|Relay|Chapter|Baseline|Domain|Definitions|Committed|Docs|Identity|InstallBlock|InstallCommand|Sentence|HookEvent|SalvageEntry|FilledInInput|SeparateLogin|StartsASession
precheck: fmt-check lint-reviews lint-issues record-lint issue-drift docs-lint check-attribution secrets-check vulncheck site-render smoke evals-cold-reading
go build ./...
go vet ./...
go test -timeout 20m $(PRECHECK_AUDIT_PACKAGES)
go test -timeout 20m -run '$(PRECHECK_AUDIT_TESTS)' $(PRECHECK_NAMED_PACKAGES)
go run ./cmd/precheck-audits $(PRECHECK_AUDIT_PACKAGES) $(PRECHECK_NAMED_PACKAGES)
precheck: export GOTOOLCHAIN := go$(GO_TOOLCHAIN_VERSION)
# The push receipt (iss-2608290810036869, iss-2608210738378295). The pre-push hook
# never runs this target: git opens a push's connection before it runs the hook,
# and a preflight inside it held that connection open until the transport's idle
# timeout closed it. So the gate runs first, as its own command, and its last step
# mints a receipt the hook checks in milliseconds. A receipt vouches for HEAD only
# when the tree matched HEAD — nothing staged, unstaged or untracked — both when
# the run began and when it ended, which is what makes the gates' reading of the
# working tree a reading of the commit CI will check out.
#
# The starting state is read while this Makefile is PARSED, which is before any
# prerequisite runs; a recipe line or a prerequisite would run after, or in parallel
# with, the gates. It is read only when `preflight` is named on the command line, so
# no other target pays for a git status. It is read before the load gate's wait, so
# a tree changed while the run is queued mints no receipt.
ifneq ($(filter preflight,$(MAKECMDGOALS)),)
PREFLIGHT_BEGAN := $(shell scripts/preflight-receipt.sh state)
endif
# The marker tells a check started inside this preflight (the eval harness's own,
# under `smoke` and `evals-cold-reading`) that the preflight's check already
# warned on the terminal, so one preflight shows one warning. A target-specific
# exported variable reaches the target's prerequisites and recipe, and not a
# prerequisite run on its own; this one and the ones below reach preflight's
# stages through the environment of the make the load gate starts.
preflight: export ABCD_LOAD_CHECKED := preflight
# The run's clock, named above, reaches the gate's command and every stage
# through the environment, and no test (internal/testreuse strips it from every
# go test line it runs). The stages' make, run by the load gate once it opens,
# notes the gate's wait as it reads this Makefile, before its first stage: the
# time from the run's start to then went on the gate's compile, its queue and
# its settling, not on checking. The race gate's wait is marked and noted around
# it in preflight-stages, and each test stage notes its own (cmd/check-tests).
preflight: export ABCD_PREFLIGHT_CLOCK := $(PREFLIGHT_CLOCK)
ifneq ($(filter preflight-stages,$(MAKECMDGOALS)),)
PREFLIGHT_GATE_OPENED := $(shell scripts/preflight-receipt.sh clock opened)
endif
# The three longest packages (internal/core/implement/loop, internal/core/claim
# and internal/surface/cli) run their tests as three processes each in the
# race stage, each process under the stage's package budget: as one process
# implement/loop took 60 minutes alone at a load of about 13 on a 10-core Mac
# (2026-10-25) and was killed at 40 with no test hung, and its tests cannot run
# in parallel, since nearly every one sets HOME through t.Setenv. Each opts in
# from its TestMain through internal/testshard, which shards only a whole-package
# run, so a -run, a profile or -json runs as before, and go test's cache still
# reads every shard's inputs. CI's two race passes set the same shard count
# as preflight. A sharded package counts as one of the stage's -p packages
# and runs three processes, so the stage can run up to six more test processes
# than its -p while all three are running at once; none of the three uses
# t.Parallel, so each process keeps to about one core.
preflight: export ABCD_TEST_SHARDS := 3
# The macOS suite runs internal/core/implement/loop as parts, one on each of its
# last shards, through ABCD_TEST_PART=i/k (cmd/ci-shard), which narrows every
# package that opts in to internal/testshard to that round-robin part of its
# tests. A shell left holding one would make a preflight test a part of each and
# still pass and mint its receipt, so the two targets that stand for a whole run
# export it empty, which testshard reads as the whole package; a bad value would
# also refuse each of those packages, -run or not. It is cleared this way, not
# with a target-specific `unexport`, which GNU make 3.81, the make macOS ships,
# reads as a prerequisite named unexport. A variable exported for preflight
# reaches its stages through the environment of the make the load gate starts.
# TestPreflightAndPrecheckTestEveryPartOfAPackage holds it.
preflight precheck: export ABCD_TEST_PART :=
# Every Go step preflight makes — its own recipe lines and every go run and go
# test its prerequisites make — runs on the toolchain go.mod declares, the one
# CI's setup-go installs, never the go on PATH (iss-2609261850045839). A test
# that asserts standard-library wording passed preflight on a newer local go and
# failed CI (pull request 728). The go on PATH switches to the declared release
# and puts its bin first on PATH for anything it runs, so a `go` a test execs is
# the declared one too. On the full rule the first Go step is the
# `go run ./cmd/precheck-audits` on the preflight line, which starts the load
# gate's own, before any stage, so a machine that lacks the declared release and cannot fetch it
# (offline) sees that go run fail with go's own toolchain download error, before
# anything is waited for or gated. The records-only rule waits at no gate: its
# first Go step is the load check's, whose failure is ignored, so offline its
# `fmt-check` refuses first. Once the release is cached, `fmt-check` runs first
# among the stages, straight after the load check, and its resolver
# (scripts/pinned-toolchain.sh) refuses, naming the skew, whenever the release
# cannot be resolved, before any other gate runs on it.
preflight: export GOTOOLCHAIN := go$(GO_TOOLCHAIN_VERSION)
# The test binaries these targets run skip the flush to stable storage
# (internal/fsutil/flush.go): on macOS every synced write is an F_FULLFSYNC of
# about 8.8 ms, and no test asserts what a flush makes true. The skip needs a
# test binary as well as this opt-in, so a binary built or run here, the lint
# gates' `go run` tools included, still flushes. CI's test steps set the same.
test preflight precheck: export ABCD_TEST_SKIP_FLUSH := 1
# The load check (itd-2609231434459890): reads the machine's load and process
# table once and warns about programs left running and extreme load. It exits 0
# on every status, and the leading `-` ignores even a failure to build it: a
# broken build is the `go build` step's to fail, never the load check's.
load-check:
-go run ./cmd/abcd implement load --site preflight
clean:
rm -rf $(BINDIR)