-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
270 lines (224 loc) · 10.2 KB
/
Makefile
File metadata and controls
270 lines (224 loc) · 10.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
.PHONY: build dev-ready build-rust build-python build-python-full build-dashboard sync check test test-quick test-rust test-python test-workers test-ml test-affected test-bg test-bg-status test-bg-smoke test-concurrency-smoke test-smart test-smart-list probe-stanza probe-mwt probe-decision lint lint-rust lint-python lint-affected lint-hygiene fmt clean ci-local ci-full install-hooks generate-ipc-types check-ipc-drift check-affected
# ---------------------------------------------------------------------------
# Profile selection — interactive runs use the `interactive` nextest profile
# (fail-fast enabled); CI runs use `default` (full failure reports).
# ---------------------------------------------------------------------------
NEXTEST_PROFILE := $(if $(CI),default,interactive)
# ---------------------------------------------------------------------------
# FAST DEV LOOP (< 10 seconds incremental)
# ---------------------------------------------------------------------------
# Default: check compilation only. This is what you run after every edit.
check:
cargo check -p batchalign-cli -q
# Quick test: library tests only. No Python, no ML, no OOM risk. ~3 seconds.
test: test-quick
test-quick:
cargo test --workspace --lib -q
# Houjun-path dev build: fast extension rebuild + Rust CLI (debug), no dashboard.
dev-ready: build-python build-rust
# ---------------------------------------------------------------------------
# BUILD TARGETS
# ---------------------------------------------------------------------------
# Full dev build: dashboard (embedded in binary) + PyO3 + Rust CLI (debug).
build: build-dashboard build-python build-rust
# Rust CLI binary (debug for fast incremental builds).
build-rust:
cargo build -p batchalign-cli
# Rust CLI binary (release, for large-scale work).
build-release:
cargo build --release -p batchalign-cli
# Fast local-dev rebuild: extension-only PyO3.
build-python:
uv run maturin develop -m pyo3/Cargo.toml -F pyo3/extension-module
# Full packaged rebuild: extension + CLI binary copied into package.
build-python-full: build-rust
cp target/debug/batchalign3 batchalign/_bin/batchalign3
uv run maturin develop -m pyo3/Cargo.toml -F pyo3/extension-module
# Build React dashboard and deploy to ~/.batchalign3/dashboard/.
build-dashboard:
bash scripts/build_react_dashboard.sh
# Install/update Python deps + rebuild batchalign_core from scratch.
sync:
uv sync --group dev
# ---------------------------------------------------------------------------
# EXTENDED TEST TARGETS (opt-in, not part of the default dev loop)
# ---------------------------------------------------------------------------
# Full safe Rust tests — library + safe integration tests. ~5 seconds.
test-rust:
cargo test --workspace --lib -q
cargo test -p batchalign-app --test json_compat --test workflow_helpers -q
# Python tests (pytest). Slow — run before pushing, not every edit.
test-python:
uv run pytest --ignore=_private
# Worker tests — spawns Python test-echo workers (no ML models).
# Memory guard protects against OOM. Still, run only when needed.
test-workers:
cargo test -p batchalign-app --test worker_integration -- --test-threads=1
cargo test -p batchalign-app --test worker_protocol_matrix -- --test-threads=1
cargo test -p batchalign-app --test gpu_concurrent_dispatch -- --test-threads=1
cargo test -p batchalign-app --test integration -- --test-threads=1
# ML golden tests — loads real ML models (2-15 GB each).
# ONLY run on net (256 GB). See docs/memory-safety.md.
test-ml:
@echo "WARNING: ML tests load Whisper/Stanza models (2-15 GB each)."
@echo "Only run on machines with 256+ GB RAM (e.g., net)."
@echo "Press Ctrl-C to abort, or wait 3 seconds to continue..."
@sleep 3
cargo test -p batchalign-app --test ml_golden -- --test-threads=1
test-affected:
cargo xtask affected-rust test
# ---------------------------------------------------------------------------
# BACKGROUND TEST RUNNER (reduces time spent *waiting* for tests)
# ---------------------------------------------------------------------------
#
# Wrap any make target in scripts/test-bg.sh to run it detached, with
# structured logs under ~/.batchalign3/bg-test/<slug>/ and a macOS
# desktop notification on completion. The caller returns immediately;
# failures always notify, successes are announced unless --quiet.
#
# Examples:
# make test-bg CMD="make test-rust" # run test-rust in background
# make test-bg CMD="uv run pytest -m mwt_probe" # pytest subset in background
# make test-bg-status # list running + recent runs
#
# See scripts/test-bg.sh for flags and log layout.
CMD ?=
test-bg:
@if [ -z "$(CMD)" ]; then \
echo 'usage: make test-bg CMD="<command to run in background>"'; \
exit 2; \
fi
@bash scripts/test-bg.sh -- $(CMD)
test-bg-status:
@bash scripts/test-bg-status.sh
test-bg-smoke:
@bash scripts/tests/test_test_bg.sh
# ---------------------------------------------------------------------------
# RAM-sensing concurrency dispatcher (Phase A4 of the test-cost revamp)
# ---------------------------------------------------------------------------
#
# scripts/choose-test-concurrency.sh returns a safe parallel-jobs count
# based on the current host's RAM and the profile's peak per-job RSS
# (default/python=1GB, stress=4GB, gpu=6GB, ml=12GB). Used for ad-hoc
# invocations — e.g. `cargo nextest run --profile interactive
# --test-threads=$$(bash scripts/choose-test-concurrency.sh default)`
#
# The hard 128 GB OOM guard for golden+xdist in
# batchalign/tests/conftest.py is correctness and stays above this
# tuning layer.
test-concurrency-smoke:
@bash scripts/tests/test_choose_test_concurrency.sh
# ---------------------------------------------------------------------------
# CHANGE-AWARE PYTHON TEST SELECTION (Phase C of the test-cost revamp)
# ---------------------------------------------------------------------------
#
# scripts/test-affected.py walks batchalign/tests/ for `# affects:` header
# comments, matches their gitignore-style globs against the current git
# diff, and emits the relevant test files plus every test file without
# declarations (the "runs always" set — backward compatible).
#
# Examples:
# make test-smart # diff=HEAD~1..HEAD, run tests
# make test-smart BASE=origin/main # diff this branch vs main
# make test-smart-list # list affected files only
#
# Rust test annotation is a separate follow-up (xtask integration).
BASE ?=
test-smart-list:
@uv run python scripts/test-affected.py $(if $(BASE),--base $(BASE))
test-smart:
@files="$$(uv run python scripts/test-affected.py $(if $(BASE),--base $(BASE)))"; \
if [ -z "$$files" ]; then echo "no tests selected"; exit 0; fi; \
uv run pytest $$files
# ---------------------------------------------------------------------------
# DRIFT-SENTINEL PROBES (Phase G of the test-cost revamp)
# ---------------------------------------------------------------------------
#
# mwt_probe / decision_probe tests are monitors, not tests. Running them
# via these targets produces a dated markdown report at
# docs/investigations/drift-<date>-stanza.md instead of returning a
# non-zero exit code on probe failure. Never run as part of CI's main
# gate — wire into a nightly workflow (Phase G.3, deferred).
probe-stanza:
@bash scripts/run-drift-probes.sh
probe-mwt:
@bash scripts/run-drift-probes.sh --mwt-only
probe-decision:
@bash scripts/run-drift-probes.sh --decision-only
# ---------------------------------------------------------------------------
# LINT — hygiene, not correctness
# ---------------------------------------------------------------------------
#
# Since 2026-04-20, fmt and clippy are NOT enforced on pre-push. They cause
# churn without catching semantic bugs. Run these manually before releases
# or during periodic hygiene sweeps. The pre-push hook only runs the compile,
# API-drift, and mypy gates. See `scripts/pre-push.sh` for rationale.
# Reformat all Rust sources in place. Fast. Safe. Run before a release.
fmt:
cargo fmt --all
# Hygiene sweep: fmt + clippy + mypy. Fixes nothing; reports drift.
# Run before releases.
lint-hygiene:
@echo "==> fmt check"
cargo fmt --all -- --check
@echo "==> clippy"
cargo clippy --workspace --all-targets -- -D warnings
@echo "==> mypy"
uv run mypy
@echo "✓ hygiene passed"
# Rust only — faster than full lint.
lint-rust:
cargo clippy -p batchalign-types -p batchalign-app -p batchalign-cli --lib -- -D warnings
# Full lint (Rust + Python types). Slow. Alias for `lint-hygiene` minus fmt.
lint:
cargo clippy --workspace --all-targets -- -D warnings
uv run mypy
# Python types only.
lint-python:
uv run mypy
lint-affected:
cargo xtask affected-rust clippy
check-affected:
cargo xtask affected-rust check
# Regenerate Python Pydantic models from Rust IPC types via JSON Schema.
# Run after changing any Rust struct/enum with JsonSchema that crosses the Python boundary.
generate-ipc-types:
bash scripts/generate_ipc_types.sh
# Check that Rust IPC schemas are up to date. Exits non-zero on drift.
check-ipc-drift:
bash scripts/check_ipc_type_drift.sh
# Fast local CI: fmt + affected compile checks + structural lints.
ci-local:
@echo "==> fmt check"
cargo fmt --all -- --check
@echo "==> affected compile check"
cargo xtask affected-rust check
@echo "==> wide struct audit"
cargo xtask lint-wide-structs
@echo "==> ci hygiene"
cargo xtask lint-ci-hygiene
@echo "==> dashboard API drift"
bash scripts/check_dashboard_api_drift.sh
@echo "✓ ci-local passed"
# Full local CI: mirrors the strict CI-style gate and keeps heavy checks explicit.
ci-full:
@echo "==> fmt check"
cargo fmt --all -- --check
@echo "==> clippy"
cargo clippy --workspace --all-targets -- -D warnings
@echo "==> compile check"
cargo check --workspace
@echo "==> mypy (strict)"
uv run mypy
@echo "==> IPC schema drift"
bash scripts/check_ipc_type_drift.sh
@echo "==> dashboard API drift"
bash scripts/check_dashboard_api_drift.sh
@echo "✓ ci-full passed"
# Install the pre-push git hook.
install-hooks:
ln -sf ../../scripts/pre-push.sh .git/hooks/pre-push
@echo "✓ pre-push hook installed"
# Remove the release binary from the default Cargo target dir.
clean:
rm -f target/release/batchalign3