-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathjustfile
More file actions
554 lines (461 loc) · 16.6 KB
/
justfile
File metadata and controls
554 lines (461 loc) · 16.6 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
# Justfile for rustledger
# https://github.com/casey/just
# Default recipe - show help
default:
@just --list
# ============================================================================
# BUILD
# ============================================================================
# Build in debug mode
build:
cargo build --all-targets
# Build in release mode
build-release:
cargo build --release --all-targets
# Build WASM target
build-wasm:
cargo build --target wasm32-unknown-unknown --release -p beancount-wasm
# Build with wasm-pack (for npm)
build-wasm-pack:
wasm-pack build --target web crates/beancount-wasm
# ============================================================================
# TEST
# ============================================================================
# Run all tests
test:
cargo nextest run
# Run tests with standard cargo test
test-cargo:
cargo test --all-targets
# Run tests with coverage
test-cov:
cargo llvm-cov --all-features --lcov --output-path lcov.info
cargo llvm-cov report --html
# Run property tests with more iterations
test-prop iterations="10000":
PROPTEST_CASES={{iterations}} cargo test --features proptest
# Run tests only for crates with uncommitted changes (fast pre-push check)
test-changed:
#!/usr/bin/env bash
set -eo pipefail
changed_crates=$(git diff --name-only HEAD 2>/dev/null | grep '^crates/' | cut -d/ -f2 | sort -u || true)
if [ -z "$changed_crates" ]; then
echo "No crate changes detected."
exit 0
fi
failed=0
for crate in $changed_crates; do
pkg="rustledger-${crate#rustledger-}"
# Normalize: if crate dir is already "rustledger-foo", don't double-prefix
if [[ "$crate" == rustledger-* ]]; then
pkg="$crate"
elif [[ "$crate" == "rustledger" ]]; then
pkg="rustledger"
fi
# Check if the package exists before trying to test it
if ! cargo pkgid -p "$pkg" > /dev/null 2>&1; then
echo " (skipped: $pkg not a cargo package)"
continue
fi
echo "==> Testing $pkg"
if ! cargo test -p "$pkg" --all-features; then
failed=1
fi
done
if [ "$failed" -ne 0 ]; then
echo ""
echo "Some tests failed!"
exit 1
fi
# Run specific test
test-one name:
cargo nextest run {{name}}
# ============================================================================
# LINT & FORMAT
# ============================================================================
# Run clippy
clippy:
cargo clippy --all-targets --all-features -- -D warnings
# Format code
fmt:
treefmt
# Check formatting without changes
fmt-check:
treefmt --fail-on-change
# Run all lints
lint: clippy fmt-check
cargo doc --no-deps --all-features
@echo "✓ All lints passed"
# ============================================================================
# CHECK
# ============================================================================
# Run all checks (like CI)
check:
nix flake check
# Quick check
check-quick:
cargo check --all-targets
# Audit dependencies for security
audit:
cargo audit
# Check dependency licenses
deny:
cargo deny check
# Check for unused dependencies
udeps:
cargo +nightly udeps --all-targets
# ============================================================================
# BENCHMARK
# ============================================================================
# Run benchmarks
bench:
cargo bench
# Run specific benchmark
bench-one name:
cargo bench -- {{name}}
# Compare against baseline
bench-compare baseline="main":
cargo bench -- --baseline {{baseline}}
# ============================================================================
# FUZZ
# ============================================================================
# List fuzz targets
fuzz-list:
cargo +nightly fuzz list
# Run fuzzer (requires nightly)
fuzz target duration="60":
cargo +nightly fuzz run {{target}} -- -max_total_time={{duration}}
# ============================================================================
# TLA+
# ============================================================================
# Download TLA+ tools if not present
tla-setup:
@if [ ! -f tools/tla2tools.jar ]; then \
mkdir -p tools && \
echo "Downloading TLA+ tools..." && \
wget -q https://github.com/tlaplus/tlaplus/releases/download/v1.8.0/tla2tools.jar \
-O tools/tla2tools.jar && \
echo "Downloaded tools/tla2tools.jar"; \
else \
echo "TLA+ tools already present"; \
fi
# Run TLA+ model checker on Inventory spec
tla-inventory: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/Inventory.cfg \
-workers auto \
-deadlock \
spec/tla/Inventory.tla
# Run TLA+ model checker on BookingMethods spec
tla-booking: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/BookingMethods.cfg \
-workers auto \
-deadlock \
spec/tla/BookingMethods.tla
# Run TLA+ model checker on TransactionBalance spec
tla-balance: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/TransactionBalance.cfg \
-workers auto \
-deadlock \
spec/tla/TransactionBalance.tla
# Run TLA+ model checker on AccountLifecycle spec
tla-lifecycle: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/AccountLifecycle.cfg \
-workers auto \
-deadlock \
spec/tla/AccountLifecycle.tla
# Run TLA+ model checker on DirectiveOrdering spec
tla-ordering: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/DirectiveOrdering.cfg \
-workers auto \
-deadlock \
spec/tla/DirectiveOrdering.tla
# Run TLA+ model checker on ValidationErrors spec
tla-validate: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/ValidationErrors.cfg \
-workers auto \
-deadlock \
spec/tla/ValidationErrors.tla
# Run TLA+ model checker on PriceDatabase spec
tla-price: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/PriceDatabase.cfg \
-workers auto \
-deadlock \
spec/tla/PriceDatabase.tla
# Run all TLA+ specs
tla-all: tla-inventory tla-booking tla-balance tla-lifecycle tla-ordering tla-validate tla-price
@echo "All TLA+ specifications verified"
# Run specific TLA+ spec by name
tla-check spec:
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/{{spec}}.cfg \
-workers auto \
-deadlock \
spec/tla/{{spec}}.tla
# ============================================================================
# ADVANCED TLA+ VERIFICATION
# ============================================================================
# Run typed spec with Apalache (better symbolic checking)
tla-typed-inventory: apalache-setup
tools/apalache/bin/apalache-mc check \
--config=spec/tla/InventoryTyped.cfg \
spec/tla/InventoryTyped.tla
# Check inductive invariants (conservation of units)
tla-inductive: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/InductiveInvariants.cfg \
-workers auto \
-deadlock \
spec/tla/InductiveInvariants.tla
# ============================================================================
# TLA+ COVERAGE ANALYSIS
# ============================================================================
# Analyze state space coverage
tla-coverage spec:
@mkdir -p coverage
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/{{spec}}.cfg \
-workers auto \
-dump dot,colorize coverage/{{spec}}_states \
spec/tla/{{spec}}.tla > coverage/{{spec}}_tlc.log 2>&1 || true
python3 scripts/tla_coverage.py \
--tlc-output coverage/{{spec}}_tlc.log \
--spec-name {{spec}} \
--report coverage/{{spec}}_coverage.html
@echo "Coverage report: coverage/{{spec}}_coverage.html"
# ============================================================================
# MODEL-BASED TESTING
# ============================================================================
# Generate MBT tests from TLA+ spec
mbt-generate spec depth="2" max="100":
python3 scripts/model_based_testing.py \
--spec {{spec}} \
--depth {{depth}} \
--max-tests {{max}} \
--output crates/rustledger-core/tests/mbt_{{spec}}_generated.rs
@echo "Generated tests: crates/rustledger-core/tests/mbt_{{spec}}_generated.rs"
# Generate MBT tests for BookingMethods
mbt-booking:
just mbt-generate BookingMethods 3 50
# Generate MBT tests for Inventory
mbt-inventory:
just mbt-generate Inventory 2 30
# ============================================================================
# TLA+ PROOFS (TLAPS)
# ============================================================================
# Check TLAPS proofs for Inventory
tla-prove-inventory:
@echo "Checking InventoryProofs.tla..."
@if command -v tlapm > /dev/null 2>&1; then \
tlapm --threads 4 spec/tla/InventoryProofs.tla; \
else \
echo "TLAPS not installed. Install from: https://tla.msr-inria.inria.fr/tlaps/"; \
echo "Skipping proof verification."; \
fi
# Check TLAPS proofs for BookingMethods
tla-prove-booking:
@echo "Checking BookingMethodsProofs.tla..."
@if command -v tlapm > /dev/null 2>&1; then \
tlapm --threads 4 spec/tla/BookingMethodsProofs.tla; \
else \
echo "TLAPS not installed. Install from: https://tla.msr-inria.inria.fr/tlaps/"; \
echo "Skipping proof verification."; \
fi
# Check TLAPS proofs for ValidationErrors
tla-prove-validate:
@echo "Checking ValidationErrorsProofs.tla..."
@if command -v tlapm > /dev/null 2>&1; then \
tlapm --threads 4 spec/tla/ValidationErrorsProofs.tla; \
else \
echo "TLAPS not installed. Install from: https://tla.msr-inria.inria.fr/tlaps/"; \
echo "Skipping proof verification."; \
fi
# Check all TLAPS proofs
tla-prove-all: tla-prove-inventory tla-prove-booking tla-prove-validate
@echo "All TLAPS proofs checked"
# ============================================================================
# REFINEMENT CHECKING
# ============================================================================
# Check Inventory refinement (Rust → TLA+)
tla-refine-inventory: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/InventoryRefinement.cfg \
-workers auto \
-deadlock \
spec/tla/InventoryRefinement.tla
# Check Booking refinement (Rust → TLA+)
tla-refine-booking: tla-setup
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/BookingRefinement.cfg \
-workers auto \
-deadlock \
spec/tla/BookingRefinement.tla
# Check all refinements
tla-refine-all: tla-refine-inventory tla-refine-booking
@echo "All refinement checks passed"
# ============================================================================
# APALACHE (Symbolic Model Checking)
# ============================================================================
# Setup Apalache (download if not present)
apalache-setup:
@if [ ! -f tools/apalache/bin/apalache-mc ]; then \
mkdir -p tools && \
echo "Downloading Apalache..." && \
curl -sL https://github.com/informalsystems/apalache/releases/download/v0.44.2/apalache-0.44.2.tgz | \
tar -xz -C tools && \
mv tools/apalache-0.44.2 tools/apalache && \
echo "Downloaded tools/apalache"; \
else \
echo "Apalache already present"; \
fi
# Run Apalache on Inventory spec
apalache-inventory: apalache-setup
tools/apalache/bin/apalache-mc check \
--config=spec/tla/Inventory.cfg \
spec/tla/Inventory.tla
# Run Apalache on BookingMethods spec
apalache-booking: apalache-setup
tools/apalache/bin/apalache-mc check \
--config=spec/tla/BookingMethods.cfg \
spec/tla/BookingMethods.tla
# Run Apalache on ValidationErrors spec
apalache-validate: apalache-setup
tools/apalache/bin/apalache-mc check \
--config=spec/tla/ValidationErrors.cfg \
spec/tla/ValidationErrors.tla
# Run Apalache on specific spec
apalache-check spec: apalache-setup
tools/apalache/bin/apalache-mc check \
--config=spec/tla/{{spec}}.cfg \
spec/tla/{{spec}}.tla
# Run Apalache on all specs
apalache-all: apalache-inventory apalache-booking apalache-validate
@echo "All Apalache checks complete"
# ============================================================================
# TLA+ TRACE TO TEST
# ============================================================================
# Run TLC and capture counterexample trace as JSON
tla-trace spec: tla-setup
@mkdir -p traces
java -XX:+UseParallelGC -Xmx4g -jar tools/tla2tools.jar \
-config spec/tla/{{spec}}.cfg \
-workers auto \
-deadlock \
spec/tla/{{spec}}.tla 2>&1 | \
python3 scripts/tla_trace_to_json.py --spec {{spec}} > traces/{{spec}}_trace.json || true
@if [ -s traces/{{spec}}_trace.json ]; then \
echo "Trace saved to traces/{{spec}}_trace.json"; \
else \
echo "No counterexample found (spec passed)"; \
rm -f traces/{{spec}}_trace.json; \
fi
# Generate Rust test from trace JSON
tla-gen-test trace_file:
python3 scripts/trace_to_rust_test.py {{trace_file}}
# Generate Rust tests from all traces
tla-gen-all-tests:
@if ls traces/*.json 1> /dev/null 2>&1; then \
python3 scripts/trace_to_rust_test.py traces/*.json; \
else \
echo "No trace files found in traces/"; \
fi
# ============================================================================
# COMPATIBILITY
# ============================================================================
# Fetch test vectors from upstream
fetch-tests:
./scripts/fetch-test-vectors.sh
# Run compatibility tests against Python beancount
compat:
./tests/compat/run.sh
# ============================================================================
# DOCS
# ============================================================================
# Build documentation
doc:
cargo doc --no-deps --all-features --open
# Build mdbook documentation
doc-book:
mdbook build docs/
# Serve mdbook with live reload
doc-serve:
mdbook serve docs/
# ============================================================================
# DEV
# ============================================================================
# Watch and rebuild on changes
watch:
bacon
# Watch and run tests
watch-test:
bacon test
# Clean build artifacts
clean:
cargo clean
rm -rf result result-*
# Update dependencies
update:
cargo update
nix flake update
# Generate changelog
changelog:
git cliff --unreleased --prepend CHANGELOG.md
# Count lines of code
loc:
tokei --exclude spec/fixtures
# Show dependency tree
deps:
cargo tree
# Show outdated dependencies
outdated:
cargo outdated
# ============================================================================
# RELEASE
# ============================================================================
# Prepare for release
release-prep version:
@echo "Preparing release {{version}}"
cargo set-version {{version}}
just changelog
just lint
just test
@echo "Ready for release {{version}}"
# Create release build
release-build:
cargo build --release
@echo "Binaries at: target/release/rledger-*"
@ls -lh target/release/rledger-*
# ============================================================================
# PACKAGING
# ============================================================================
# Test AUR PKGBUILD locally (requires Docker)
test-aur:
./packaging/arch/test-pkgbuild.sh
# Push PKGBUILD to AUR (after testing!)
push-aur:
#!/usr/bin/env bash
set -euo pipefail
cd /tmp
rm -rf aur-rustledger-push
git clone ssh://aur@aur.archlinux.org/rustledger.git aur-rustledger-push
cp "$OLDPWD/packaging/arch/rustledger/PKGBUILD" aur-rustledger-push/
cd aur-rustledger-push
makepkg --printsrcinfo > .SRCINFO 2>/dev/null || echo "Warning: makepkg not available, .SRCINFO not updated"
git add -A
git diff --cached --stat
echo ""
read -p "Push to AUR? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git commit -m "Update to $(grep pkgver= PKGBUILD | cut -d= -f2)"
git push origin master
echo "✓ Pushed to AUR"
else
echo "Aborted"
fi