Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
258 lines (207 loc) · 12.4 KB
/
Copy pathMakefile
File metadata and controls
258 lines (207 loc) · 12.4 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
.PHONY: help lint type test test-py test-e2e check check-oo update-oo check-coupling update-coupling check-suppressions update-suppressions check-dev-commands gen-dev-commands check-comments check-docstrings build-api-docs format build install uat clean depot assert report spec-reports metrics coverage coverage-ci
.PHONY: hooks test-changed test-push test-subprocess test-nightly test-quarantine test-quarantine-run
FUZZ ?= fuzz
PROBCLI ?= $(HOME)/Applications/ProB/probcli
SETSIZE ?= 1
# MAX_OPS and TIMEOUT are ONE setting, and lowering either costs time rather
# than saving it. TIMEOUT is probcli's per-computation TIME_OUT, not a wall
# clock: below it, operations are abandoned rather than solved, and abandoning
# them is far more expensive than solving them. Measured on claude-code.tex
# (329357 states), each run to completion or the stated limit:
#
# MAX_OPS=200 TIMEOUT=300000 3m43s INCOMPLETE (model_check_incomplete)
# MAX_OPS=400 TIMEOUT=300000 5m56s complete
# MAX_OPS=1000 TIMEOUT=300000 >10m did not finish
# MAX_OPS=1000 TIMEOUT=1800000 2m16s complete <- this pair
#
# An incomplete run now fails the gate: "no counter-example" is a claim over
# ALL reachable states, and a truncated run cannot establish it. So 200 is not
# an option, and the fastest complete pair is the one configured here.
#
# Raising TIMEOUT does NOT extend how long a run may take overall. The wrapper
# caps the probcli process separately at _PROCESS_TIMEOUT_S (prob.py), which is
# deliberately not derived from this value: TIMEOUT buys a large specification
# the budget to solve its operations rather than abandon them, while the
# process cap exists to notice a hung probcli. Tying them would mean every
# raise of the solve budget also lengthened how long a hang is waited on.
MAX_OPS ?= 1000
TIMEOUT ?= 1800000
# Specs ending in -bad.tex are intentional anti-pattern demonstrations
# excluded from quality gates. Only use this suffix for specs designed
# to demonstrate probcli animation failures.
SPECS := $(filter-out %-bad.tex,$(wildcard examples/*.tex))
SPEC_NAMES := $(notdir $(basename $(SPECS)))
# ── Required targets (makefile.md) ──────────────────────────
help: ## Show available targets
@grep -E '^[a-zA-Z_%-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
# The shellcheck line is byte-identical to lint.yml's, so a shell fault fails
# here rather than on the PR. plugin/hooks/*.sh is in scope: it ships to users.
lint: check-comments check-docstrings ## Lint markdown, Python, comments, docstrings, and shell
npx markdownlint-cli2 "**/*.md" "#node_modules"
uv run ruff check .
uv run ruff format --check .
shellcheck -x scripts/*.sh install.sh plugin/hooks/*.sh .githooks/pre-commit .githooks/pre-push
check-comments: ## Reject commented-out code and tracker references in Python prose
uv run ruff check --select ERA001 .
uv run python tools/check_python_docs.py comments src tests tools
check-docstrings: ## Check public Python docstrings and documented argument names
uv run ruff check --select D,D401 --ignore D105,D107,D417 src/
uv run python tools/check_python_docs.py docstrings src/
build-api-docs: ## Build and verify the generated Python API reference
uv run --group docs mkdocs build --strict
uv run python tools/check_python_docs.py api .tmp/api-site/objects.inv
type: type-py $(addprefix type-z-,$(SPEC_NAMES)) ## Type-check Python and Z specs
type-py:
uv run mypy src/ tests/ tools/
uv run pyright src/ tests/ tools/
type-z-%: examples/%.tex
@echo "fuzz $<"
@$(FUZZ) -t $< > /dev/null 2>&1 && echo " ✓ $*" || (echo " ✗ $*"; $(FUZZ) -t $<; false)
test: test-py $(addprefix test-z-,$(SPEC_NAMES)) ## Run Python tests and model-check Z specs
test-py:
uv run pytest tests/ -v
hooks: ## Install the local test hooks without overwriting other hooks
@if path=$$(git config --get core.hooksPath); then \
echo "core.hooksPath already set to $$path; chain .githooks manually" >&2; exit 1; \
fi; \
dir=$$(git rev-parse --git-path hooks) && mkdir -p "$$dir" || exit; \
for hook in pre-commit pre-push; do \
if { [ -e "$$dir/$$hook" ] || [ -L "$$dir/$$hook" ]; } && \
! cmp -s ".githooks/$$hook" "$$dir/$$hook"; then \
echo "$$dir/$$hook already exists; chain .githooks/$$hook manually" >&2; exit 1; \
fi; \
done; \
for hook in pre-commit pre-push; do \
[ -x "$$dir/$$hook" ] || install -m 755 ".githooks/$$hook" "$$dir/$$hook" || exit; \
done
test-changed: ## Run default tests affected by staged changes
TMPDIR=/tmp uv run python tools/test_changed.py
test-push: export TMPDIR = /tmp
test-push: test-py ## Run the local push gate (default suite and its local process tests)
test-subprocess: ## Run local installer and command-tool process contracts
uv run pytest tests/test_install_probcli_pin.py tests/test_gen_dev_commands.py
test-e2e: ## Tier 5 — drive the INSTALLED binary and MCP server (run make install first)
Z_SPEC_TEST_EXECUTABLE="$$(uv tool dir --bin)/z-spec" uv run pytest tests/e2e -v -m 'e2e and not quarantine'
test-nightly: test-e2e ## Run the installed wheel and a larger-scope ProB model check
$(MAKE) test-z-animation-hints-good SETSIZE=2
test-quarantine: ## List quarantines; an empty selection is expected
@uv run pytest --collect-only -v -m quarantine || [ "$$?" = 5 ]
test-quarantine-run: ## Run only quarantined tests (install the wheel if needed)
Z_SPEC_TEST_EXECUTABLE="$$(uv tool dir --bin)/z-spec" uv run pytest -m quarantine
test-z-%: examples/%.tex
@echo "probcli $< (setsize=$(SETSIZE))"
@PROBCLI=$(PROBCLI) uv run python tools/model_check_spec.py $< \
--setsize $(SETSIZE) --max-ops $(MAX_OPS) --timeout $(TIMEOUT)
@echo ""
check: lint type test check-oo check-coupling check-suppressions check-dev-commands design-gate ## Run all quality gates
# ── Dev/prod plugin namespace ───────────────────────────────
gen-dev-commands: ## Regenerate plugin/commands/*-dev.md twins from prod sources
uv run python tools/gen_dev_commands.py plugin/commands
check-dev-commands: ## Fail if any -dev twin is missing or out of sync
uv run python tools/gen_dev_commands.py plugin/commands --check
# ── OO gate suite (ratchet against committed baselines) ─────
# Base-comparison flags injected by CI (e.g. --base-ref <merge-base>). Empty
# locally, where the tools default the base to `git merge-base origin/main HEAD`.
OO_BASE ?=
COUPLING_BASE ?=
SUPPRESSION_BASE ?=
DESIGN_BASE ?= origin/main
.PHONY: design-gate
design-gate: ## Gate design changes against DESIGN_BASE
@set -e; \
if ! git rev-parse --verify --quiet "$(DESIGN_BASE)^{commit}" >/dev/null 2>&1; then \
echo "FATAL: design-gate base ref '$(DESIGN_BASE)' does not resolve to a commit" >&2; \
echo " fetch the base branch or set DESIGN_BASE to a resolvable commit" >&2; \
exit 2; \
fi; \
report=$$(mktemp); trap 'rm -f "$$report"' EXIT HUP INT TERM; \
status=0; \
uv run oo-ratchet design src/punt_zspec --shadow-check "$(DESIGN_BASE)" --json > "$$report" || status=$$?; \
cat "$$report"; \
if [ "$$status" -ne 0 ]; then exit "$$status"; fi; \
python3 -c 'import json, sys; verdict = json.load(sys.stdin)["verdict"]; sys.exit(0 if verdict in ("neutral", "good-deed", "good-deed: trade") else "Design gate rejected verdict: " + str(verdict))' < "$$report"
check-oo: ## OO ratchet — must improve over baseline, never regress
uv run oo-ratchet oo src/punt_zspec/ --check $(OO_BASE)
update-oo: ## Update OO baseline (stage .oo-baseline.json and .oo-audit.jsonl)
uv run oo-ratchet oo src/punt_zspec/ --update $(OO_BASE)
check-coupling: ## Coupling ratchet — merge-base scoped, must not regress
uv run oo-ratchet coupling src/punt_zspec/ --check $(COUPLING_BASE)
update-coupling: ## Update coupling baseline (stage baseline and audit jsonl)
uv run oo-ratchet coupling src/punt_zspec/ --update $(COUPLING_BASE)
check-suppressions: ## Suppression ratchet — base-commit scoped, count must not rise
uv run oo-ratchet suppressions src/punt_zspec/ --check $(SUPPRESSION_BASE)
update-suppressions: ## Update suppression baseline
uv run oo-ratchet suppressions src/punt_zspec/ --update
format: ## Auto-format code
uv run ruff format .
uv run ruff check --fix .
build: ## Build wheel and sdist
rm -rf dist/
uv build
uvx twine check dist/*
install: build ## Build the wheel and install the z-spec CLI locally
uv tool install --force dist/*.whl
@echo ""
@echo " CLI installed: $$(z-spec --version 2>/dev/null || echo '(z-spec not on PATH)')"
@echo ""
@echo " The RUNNING MCP server still holds the OLD code. A reinstall does"
@echo " not restart it. Reconnect the z-spec MCP server before exercising"
@echo " any MCP tool, lux menu entry, or slash command."
uat: install ## Build, install, then run the acceptance flight by hand
@echo ""
@echo " Acceptance flight: docs/testing/manual-tests.md"
@echo ""
@echo " Hard rule: write the expected outcome BEFORE each step, then run it"
@echo " and compare. Every difference is a bug. UAT passes before the PR"
@echo " opens, not after."
metrics: ## ABC complexity metrics on src/
uv run python tools/run_metrics.py
coverage: ## Run tests with coverage report (terminal + HTML)
uv run pytest tests/ --cov --cov-report=term-missing --cov-report=html
coverage-ci: ## Run the default suite with line and branch coverage (XML)
uv run pytest tests/ --cov --cov-report=term --cov-report=xml
DEPOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))../.depot
depot: build ## Build and copy wheel to local depot
@mkdir -p $(DEPOT)
@cp dist/*.whl $(DEPOT)/
@echo "depot: $$(ls dist/*.whl | xargs -n1 basename) -> $(DEPOT)/"
# ── Optional targets ────────────────────────────────────────
assert: $(addprefix assert-,$(SPEC_NAMES)) ## CBC assertion check all specs
assert-%: examples/%.tex
@echo "cbc_assertions $<"
@mkdir -p .tmp
@$(PROBCLI) $< -cbc_assertions \
> .tmp/probcli-assert-$*.out 2>&1; \
rc=$$?; \
grep -E "counter|ASSERTION" .tmp/probcli-assert-$*.out | head -3; \
echo ""; \
exit $$rc
report: ## Full diagnostics — every gate and metric, no fail-fast
@echo "── OO score ─────────────────────────────────────────────"
-uv run oo-ratchet oo src/punt_zspec/ --threshold
@echo "── Coupling ─────────────────────────────────────────────"
-uv run oo-ratchet coupling src/punt_zspec/ --threshold
@echo "── Suppressions ─────────────────────────────────────────"
-uv run oo-ratchet suppressions src/punt_zspec/ --threshold
@echo "── Types (mypy) ─────────────────────────────────────────"
-uv run mypy src/ tests/
@echo "── Types (pyright) ──────────────────────────────────────"
-uv run pyright src/ tests/
@echo "── Formatting ───────────────────────────────────────────"
-uv run ruff format --check src/ tests/
@echo "── Lint ─────────────────────────────────────────────────"
-uv run ruff check .
@echo "── Tests ────────────────────────────────────────────────"
-uv run pytest
@echo "── Z specs (fuzz) ───────────────────────────────────────"
-$(MAKE) --keep-going $(addprefix type-z-,$(SPEC_NAMES))
@echo "Report complete."
spec-reports: $(addprefix report-,$(SPEC_NAMES)) ## Generate probcli reports for all specs
report-%: examples/%.tex
@echo "report $<"
@uv run z-spec test $< --setsize $(SETSIZE) --max-ops $(MAX_OPS) --timeout $(TIMEOUT) > /dev/null 2>&1 \
&& echo " ✓ $* (report saved)" || (echo " ✗ $*"; false)
clean: ## Remove generated files
@rm -f examples/*.fuzz examples/*.aux examples/*.log examples/*.out examples/*.toc examples/*.pdf
@rm -f examples/*.report.json
@rm -f ./*.aux ./*.log ./*.out ./*.toc