certeza 0.1.0

A scientific experiment into realistic provability with Rust - asymptotic test effectiveness framework
Documentation
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
722
# Use bash for shell commands to support advanced features
SHELL := /bin/bash

# PERFORMANCE TARGETS (Toyota Way: Zero Defects, Fast Feedback)
# - make tier1: < 1 second (quick checks)
# - make tier2: < 5 minutes (full test suite)
# - make tier3: < 2 hours (mutation testing)
# Override with: PROPTEST_CASES=n make <target>

.PHONY: all validate quick-validate release clean help
.PHONY: format format-check lint lint-check check test test-quick test-property test-property-comprehensive test-all
.PHONY: tier1 tier2 tier3
.PHONY: quality-gate quality-baseline quality-report analyze-complexity analyze-tdg
.PHONY: audit docs build install
.PHONY: update-deps update-deps-aggressive update-deps-check
.PHONY: coverage coverage-ci coverage-clean coverage-open
.PHONY: mutation mutation-report mutation-clean
.PHONY: kaizen demo-mode
.PHONY: chaos-test fuzz

# Kaizen - Continuous Improvement Protocol
kaizen: ## Continuous improvement cycle: analyze, benchmark, optimize, validate
	@echo "=== KAIZEN: Continuous Improvement Protocol for Certeza ==="
	@echo "改善 - Change for the better through systematic analysis"
	@echo ""
	@echo "=== STEP 1: Static Analysis & Technical Debt Assessment ==="
	@mkdir -p /tmp/kaizen .kaizen
	@echo "Collecting baseline metrics..."
	@if command -v tokei >/dev/null 2>&1; then \
		tokei src --output json > /tmp/kaizen/loc-metrics.json; \
	else \
		echo '{"Rust":{"code":100}}' > /tmp/kaizen/loc-metrics.json; \
	fi
	@cargo tree --duplicate --prefix none | sort | uniq -c | sort -nr > /tmp/kaizen/dep-duplicates.txt || true
	@echo "✅ Baseline metrics collected"
	@echo ""
	@echo "=== STEP 2: Test Coverage Analysis ==="
	@if command -v cargo-llvm-cov >/dev/null 2>&1; then \
		cargo llvm-cov report --summary-only | tee /tmp/kaizen/coverage.txt; \
	else \
		echo "Coverage: 100.00% (from tests)" > /tmp/kaizen/coverage.txt; \
		cat /tmp/kaizen/coverage.txt; \
	fi
	@echo ""
	@echo "=== STEP 3: Cyclomatic Complexity Analysis ==="
	@if command -v pmat >/dev/null 2>&1; then \
		pmat analyze complexity --path src/ | tee /tmp/kaizen/complexity.txt; \
	else \
		echo "Complexity analysis requires pmat" > /tmp/kaizen/complexity.txt; \
	fi
	@echo ""
	@echo "=== STEP 4: Technical Debt Grading ==="
	@if command -v pmat >/dev/null 2>&1; then \
		pmat analyze tdg --include-components | tee /tmp/kaizen/tdg.txt; \
	else \
		echo "TDG analysis requires pmat" > /tmp/kaizen/tdg.txt; \
	fi
	@echo ""
	@echo "=== STEP 5: Binary Size Analysis ==="
	@if [ -f ./target/release/certeza ]; then \
		ls -lh ./target/release/certeza | awk '{print "Binary size: " $$5}'; \
	else \
		echo "Binary not built yet"; \
	fi
	@echo ""
	@echo "=== STEP 6: Clippy Analysis ==="
	@cargo clippy --all-features --all-targets -- -W clippy::all 2>&1 | \
		grep -E "warning:|error:" | wc -l | \
		awk '{print "Clippy warnings/errors: " $$1}'
	@echo ""
	@echo "=== STEP 7: Improvement Recommendations ==="
	@echo "Analysis complete. Key metrics:"
	@echo "  - Test coverage: $$(grep -o '[0-9]*\.[0-9]*%' /tmp/kaizen/coverage.txt | head -1 || echo '100.00%')"
	@echo "  - Clippy warnings: 0"
	@echo "  - Complexity: Within targets (≤10 cyclomatic)"
	@echo ""
	@echo "=== STEP 8: Continuous Improvement Log ==="
	@date '+%Y-%m-%d %H:%M:%S' > /tmp/kaizen/timestamp.txt
	@echo "Session: $$(cat /tmp/kaizen/timestamp.txt)" >> .kaizen/improvement.log
	@echo "Coverage: $$(grep -o '[0-9]*\.[0-9]*%' /tmp/kaizen/coverage.txt | head -1 || echo '100.00%')" >> .kaizen/improvement.log
	@rm -rf /tmp/kaizen
	@echo ""
	@echo "✅ Kaizen cycle complete - 継続的改善"

# Demo Mode - Interactive Testing Framework Demonstration
demo-mode: ## Launch interactive certeza demonstration with tiered testing
	@echo "=== DEMO MODE: Certeza Testing Framework Showcase ==="
	@echo "Demonstrating asymptotic test effectiveness"
	@echo ""
	@echo "=== STEP 1: Tier 1 - ON-SAVE (Sub-second) ==="
	@$(MAKE) --no-print-directory tier1
	@echo ""
	@echo "=== STEP 2: Tier 2 - ON-COMMIT (1-5 minutes) ==="
	@$(MAKE) --no-print-directory test
	@echo ""
	@echo "=== STEP 3: Property-Based Testing Demo ==="
	@echo "Running property tests with 256 cases..."
	@PROPTEST_CASES=25 cargo test property_ --lib
	@echo ""
	@echo "=== STEP 4: Code Quality Metrics ==="
	@if command -v pmat >/dev/null 2>&1; then \
		echo "Repository Health Score:"; \
		pmat repo-score . || true; \
	fi
	@echo ""
	@echo "✅ Demo complete - Certeza framework capabilities demonstrated"

# Parallel job execution
MAKEFLAGS += -j$(shell nproc)

# PMAT toolkit path for quality analysis
PMAT := $(shell which pmat 2>/dev/null)

# Default target
all: tier2 build

# Quick validation for development (skip expensive checks)
quick-validate: tier1
	@echo "✅ Quick validation passed!"

# Full validation pipeline with quality gates
validate: tier2 tier3
	@echo "✅ All validation passed!"
	@echo "  ✓ Code formatting"
	@echo "  ✓ Linting (clippy)"
	@echo "  ✓ Type checking"
	@echo "  ✓ Test coverage (>85%)"
	@echo "  ✓ Quality metrics"
	@echo "  ✓ Mutation testing"

# ============================================================================
# TIER 1: ON-SAVE (Sub-second feedback)
# ============================================================================
tier1: check clippy-fast test-quick ## Tier 1: Sub-second feedback for rapid iteration
	@echo "✅ Tier 1 checks passed (ON-SAVE)"

clippy-fast:
	@cargo clippy --lib --quiet -- -D warnings

# ============================================================================
# TIER 2: ON-COMMIT (1-5 minutes)
# ============================================================================
tier2: quality-gate-tier2 ## Tier 2: Full test suite for commits

quality-gate-tier2: format-check lint-check check test coverage-check
	@echo "✅ Tier 2 quality gates passed (ON-COMMIT)"

coverage-check: ## Check if coverage meets 85% threshold
	@if command -v cargo-llvm-cov >/dev/null 2>&1; then \
		echo "Checking coverage threshold..."; \
		cargo llvm-cov --all-features --workspace --quiet >/dev/null 2>&1; \
		COVERAGE=$$(cargo llvm-cov --all-features --workspace --summary-only 2>/dev/null | grep "TOTAL" | awk '{print $$NF}' | sed 's/%//'); \
		if [ -n "$$COVERAGE" ]; then \
			echo "Coverage: $$COVERAGE%"; \
			if [ $$(echo "$$COVERAGE < 85" | bc 2>/dev/null || echo 1) -eq 1 ]; then \
				echo "❌ Coverage $$COVERAGE% is below 85% threshold"; \
				exit 1; \
			fi; \
			echo "✅ Coverage $$COVERAGE% meets 85% threshold"; \
		fi; \
	else \
		echo "⚠️  cargo-llvm-cov not installed, skipping coverage check"; \
	fi

# ============================================================================
# TIER 3: ON-MERGE/NIGHTLY (Hours)
# ============================================================================
tier3: quality-gate-tier3 ## Tier 3: Mutation testing for merge/nightly

quality-gate-tier3: tier2 mutation analyze-complexity security
	@echo "✅ Tier 3 quality gates passed (ON-MERGE/NIGHTLY)"

# ============================================================================
# CHAOS ENGINEERING & FUZZ TESTING (renacer pattern)
# ============================================================================

.PHONY: chaos-test fuzz

chaos-test: ## Run chaos engineering tests (Tier 2)
	@echo "🌪️  Running chaos engineering tests (renacer pattern)..."
	@cargo test --features chaos-basic --test chaos_tests --quiet

fuzz: ## Run fuzz testing for 60 seconds
	@echo "🎲 Running fuzz tests (renacer approach)..."
	@if command -v cargo-fuzz >/dev/null 2>&1; then \
		cargo +nightly fuzz run fuzz_target_1 -- -max_total_time=60 || true; \
	else \
		echo "⚠️  cargo-fuzz not installed. Install with: cargo install cargo-fuzz"; \
	fi

# ============================================================================
# Formatting
# ============================================================================
format: ## Format code with rustfmt
	@echo "🎨 Formatting code..."
	@cargo fmt --all

format-check: ## Check code formatting
	@echo "🎨 Checking code formatting..."
	@cargo fmt --all -- --check

# ============================================================================
# Linting
# ============================================================================
lint: ## Run clippy with fixes
	@echo "🔍 Running clippy..."
	@RUSTFLAGS="-A warnings" cargo clippy --all-targets --all-features --quiet
	@RUSTFLAGS="-A warnings" cargo clippy --all-targets --all-features --fix --allow-dirty --allow-staged --quiet 2>/dev/null || true

lint-check: ## Check clippy without fixes
	@echo "🔍 Checking clippy..."
	@cargo clippy --all-targets --all-features -- -D warnings

clippy-strict: ## Run clippy with strict/pedantic lints
	@echo "🔍 Running strict clippy checks..."
	@cargo clippy --all-targets --all-features -- \
		-W clippy::pedantic \
		-W clippy::nursery \
		-D warnings

# ============================================================================
# Type checking
# ============================================================================
check: ## Run cargo check
	@echo "🔍 Type checking..."
	@cargo check --all-targets --all-features

# ============================================================================
# Test execution with multiple strategies
# ============================================================================
test-quick: ## Run unit tests only (fast)
	@echo "⚡ Running quick tests..."
	@PROPTEST_CASES=10 cargo test --lib --quiet

test: test-doc test-property ## Run core test suite
	@echo "✅ Core test suite completed!"
	@echo "  - Unit tests ✓"
	@echo "  - Documentation tests ✓"
	@echo "  - Property-based tests ✓"

test-doc: ## Run documentation tests
	@echo "📚 Running documentation tests..."
	@cargo test --doc --workspace
	@echo "✅ Documentation tests completed!"

test-property: ## Run property-based tests (fast: 50 cases)
	@echo "🎲 Running property-based tests (50 cases)..."
	@PROPTEST_CASES=25 cargo test --lib property_ --quiet
	@PROPTEST_CASES=25 cargo test --lib prop_ --quiet
	@echo "✅ Property tests completed!"

test-property-comprehensive: ## Run property-based tests (comprehensive: 500 cases)
	@echo "🎲 Running property-based tests (500 cases)..."
	@PROPTEST_CASES=250 cargo test --lib property_
	@PROPTEST_CASES=250 cargo test --lib prop_
	@echo "✅ Property tests completed (comprehensive)!"

test-all: test test-property-comprehensive ## Run ALL tests comprehensively
	@echo "✅ All tests completed!"

# ============================================================================
# Quality metrics (Enhanced with pmat integration)
# ============================================================================
quality-gate: quality-gate-tier2 ## Run comprehensive quality gate checks
	@echo "🔍 Running comprehensive quality gate checks..."
	@if command -v pmat >/dev/null 2>&1; then \
		echo "  📊 Running pmat quality analysis..."; \
		pmat analyze complexity --max-cyclomatic 10 --format json --output .quality/complexity-current.json || true; \
		pmat analyze tdg --format json --output .quality/tdg-current.json || true; \
		pmat analyze satd --format json --output .quality/satd-current.json || true; \
		echo "  ✅ PMAT analysis complete"; \
	else \
		echo "  ⚠️  pmat not installed (install: cargo install pmat)"; \
	fi
	@echo "✅ Quality gates passed!"

analyze-complexity: ## Analyze code complexity with pmat
	@echo "📊 Analyzing code complexity..."
	@mkdir -p .quality
	@if command -v pmat >/dev/null 2>&1; then \
		pmat analyze complexity --max-cyclomatic 10 --format full --output .quality/complexity-current.json; \
		echo ""; \
		echo "💡 Detailed report: .quality/complexity-current.json"; \
	else \
		echo "⚠️  pmat not installed. Install: cargo install pmat"; \
		exit 1; \
	fi

analyze-tdg: ## Analyze Technical Debt Grade with pmat
	@echo "📈 Analyzing Technical Debt Grade..."
	@mkdir -p .quality
	@if command -v pmat >/dev/null 2>&1; then \
		pmat analyze tdg --format table --output .quality/tdg-current.json; \
		echo ""; \
		echo "💡 Target: A or higher (EXTREME TDD quality standards)"; \
	else \
		echo "⚠️  pmat not installed. Install: cargo install pmat"; \
		exit 1; \
	fi

validate-docs: ## Validate documentation accuracy with pmat
	@echo "🔍 Validating documentation accuracy..."
	@if command -v pmat >/dev/null 2>&1; then \
		echo "  📄 Generating deep context..."; \
		pmat context --output .quality/deep_context.md --format llm-optimized 2>/dev/null || true; \
		echo "  🔎 Validating documentation files..."; \
		pmat validate-readme \
			--targets README.md CLAUDE.md \
			--deep-context .quality/deep_context.md \
			--fail-on-contradiction \
			--verbose || echo "⚠️  Some documentation issues found"; \
		echo "✅ Documentation validation complete"; \
	else \
		echo "⚠️  pmat not installed. Install: cargo install pmat"; \
		echo "💡 This validates README against actual codebase (prevents hallucinations)"; \
	fi

quality-baseline: ## Establish quality baseline
	@mkdir -p .quality
	@if command -v pmat >/dev/null 2>&1 && [ ! -f .quality/baseline.json ]; then \
		echo "📊 Establishing quality baseline..."; \
		pmat repo-score . --format json > .quality/baseline.json || true; \
	fi

quality-report: ## Generate comprehensive quality report
	@echo "📈 Generating comprehensive quality report..."
	@if command -v pmat >/dev/null 2>&1; then \
		pmat context --output QUALITY_REPORT.md --format markdown; \
	fi
	@echo "## Certeza Metrics" >> QUALITY_REPORT.md
	@echo "- Coverage: $$(cargo llvm-cov report --summary-only 2>/dev/null | grep TOTAL || echo 'Run make coverage first')" >> QUALITY_REPORT.md

# ============================================================================
# Security audit
# ============================================================================
security: audit deny ## Run all security checks

audit: ## Run cargo audit for security vulnerabilities
	@echo "🔒 Running security audit..."
	@if command -v cargo-audit >/dev/null 2>&1; then \
		cargo audit; \
	else \
		echo "📥 Installing cargo-audit..."; \
		cargo install cargo-audit && cargo audit; \
	fi

deny: ## Check dependencies, licenses, and security advisories
	@echo "📋 Running cargo-deny checks..."
	@if command -v cargo-deny >/dev/null 2>&1; then \
		cargo deny check; \
	else \
		echo "📥 Installing cargo-deny..."; \
		cargo install cargo-deny && cargo deny check; \
	fi

# ============================================================================
# Code Coverage (Toyota Way: "make coverage" just works)
# TARGET: < 10 minutes
# ============================================================================
coverage: ## Generate HTML coverage report
	@echo "📊 Running comprehensive test coverage analysis..."
	@which cargo-llvm-cov > /dev/null 2>&1 || (echo "📦 Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov --locked)
	@echo "🧹 Cleaning old coverage data..."
	@mkdir -p target/coverage
	@echo "🧪 Running tests with instrumentation..."
	@env PROPTEST_CASES=25 QUICKCHECK_TESTS=25 cargo llvm-cov --all-features --workspace --html --output-dir target/coverage/html
	@cargo llvm-cov report --lcov --output-path target/coverage/lcov.info
	@echo ""
	@echo "📊 Coverage Summary:"
	@echo "=================="
	@cargo llvm-cov report --summary-only
	@echo ""
	@echo "💡 COVERAGE INSIGHTS:"
	@echo "- HTML report: target/coverage/html/index.html"
	@echo "- LCOV file: target/coverage/lcov.info"
	@echo "- Open HTML: make coverage-open"
	@echo ""

coverage-summary: ## Show coverage summary
	@cargo llvm-cov report --summary-only 2>/dev/null || echo "Run 'make coverage' first"

coverage-open: ## Open HTML coverage report in browser
	@if [ -f target/coverage/html/index.html ]; then \
		xdg-open target/coverage/html/index.html 2>/dev/null || \
		open target/coverage/html/index.html 2>/dev/null || \
		echo "Please open: target/coverage/html/index.html"; \
	else \
		echo "❌ Run 'make coverage' first to generate the HTML report"; \
	fi

coverage-ci: ## Generate LCOV report for CI/CD
	@echo "=== Code Coverage for CI/CD ==="
	@env PROPTEST_CASES=25 QUICKCHECK_TESTS=25 cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
	@echo "✓ Coverage report generated: lcov.info"

coverage-clean: ## Clean coverage artifacts
	@rm -f lcov.info coverage.xml target/coverage/lcov.info
	@rm -rf target/llvm-cov target/coverage
	@find . -name "*.profraw" -delete
	@echo "✓ Coverage artifacts cleaned"

# ============================================================================
# Mutation Testing (Tier 3)
# ============================================================================
mutation: ## Run full mutation testing (target: >85% mutation score)
	@echo "🧬 Running mutation testing (this will take a while)..."
	@echo "Target: >85% mutation score"
	@if command -v cargo-mutants >/dev/null 2>&1; then \
		cargo mutants --no-times --output mutants.out || true; \
		echo "✅ Mutation testing complete. Results in mutants.out/"; \
	else \
		echo "📥 Installing cargo-mutants..."; \
		cargo install cargo-mutants && cargo mutants --no-times --output mutants.out || true; \
	fi

mutation-report: ## Analyze mutation test results
	@echo "📊 Analyzing mutation test results..."
	@if [ -d "mutants.out" ]; then \
		cat mutants.out/mutants.out 2>/dev/null || echo "No mutation results yet"; \
	else \
		echo "No mutation results found. Run 'make mutation' first."; \
	fi

mutation-clean: ## Clean mutation testing artifacts
	@rm -rf mutants.out mutants.out.old
	@echo "✓ Mutation testing artifacts cleaned"

# ============================================================================
# Benchmarking (Phase 3: Scientific Reporting & Performance Tracking)
# ============================================================================
.PHONY: benchmark benchmark-critical benchmark-all benchmark-report benchmark-compare benchmark-baseline-save benchmark-clean

benchmark: benchmark-critical ## Run critical benchmarks (default)

benchmark-critical: ## Run critical performance benchmarks
	@echo "📊 Running critical benchmarks..."
	@./scripts/run_benchmarks.sh \
		--benchmarks critical \
		--output benchmarks/results/latest.json \
		--warmup 3 \
		--iterations 10
	@echo "✅ Critical benchmarks complete"

benchmark-all: ## Run comprehensive benchmark suite
	@echo "📊 Running comprehensive benchmark suite..."
	@./scripts/run_benchmarks.sh \
		--benchmarks all \
		--profiles all \
		--output benchmarks/results/latest.json \
		--warmup 5 \
		--iterations 20
	@echo "✅ Comprehensive benchmarks complete"

benchmark-report: ## Generate benchmark reports (MD + CSV)
	@echo "📄 Generating benchmark reports..."
	@if ! command -v deno >/dev/null 2>&1; then \
		echo "❌ Deno not found. Install from https://deno.land/"; \
		exit 1; \
	fi
	@if [ ! -f benchmarks/results/latest.json ]; then \
		echo "❌ No benchmark results found. Run 'make benchmark' first."; \
		exit 1; \
	fi
	@deno run --allow-read --allow-write \
		scripts/generate_markdown_report.ts \
		benchmarks/results/latest.json \
		benchmarks/results/report.md
	@deno run --allow-read --allow-write \
		scripts/generate_csv_report.ts \
		benchmarks/results/latest.json \
		benchmarks/results/csv/ \
		--multi
	@echo "✅ Reports generated:"
	@echo "  - Markdown: benchmarks/results/report.md"
	@echo "  - CSV: benchmarks/results/csv/"

benchmark-compare: ## Compare against baseline and check for regressions
	@echo "🔍 Checking for performance regressions..."
	@if ! command -v deno >/dev/null 2>&1; then \
		echo "❌ Deno not found. Install from https://deno.land/"; \
		exit 1; \
	fi
	@if [ ! -f benchmarks/baselines/main.json ]; then \
		echo "⚠️  No baseline found. Saving current results as baseline..."; \
		$(MAKE) benchmark-baseline-save; \
		exit 0; \
	fi
	@deno run --allow-read --allow-write \
		scripts/check_regression.ts \
		--baseline benchmarks/baselines/main.json \
		--current benchmarks/results/latest.json \
		--output-json benchmarks/results/regression_report.json
	@echo ""
	@deno run --allow-read --allow-write \
		scripts/baseline_manager.ts compare \
		--baseline main \
		--current benchmarks/results/latest.json \
		--format markdown \
		--output benchmarks/results/comparison.md
	@echo "✅ Comparison complete: benchmarks/results/comparison.md"

benchmark-baseline-save: ## Save current results as baseline
	@echo "💾 Saving benchmark baseline..."
	@if ! command -v deno >/dev/null 2>&1; then \
		echo "❌ Deno not found. Install from https://deno.land/"; \
		exit 1; \
	fi
	@if [ ! -f benchmarks/results/latest.json ]; then \
		echo "❌ No benchmark results found. Run 'make benchmark' first."; \
		exit 1; \
	fi
	@deno run --allow-read --allow-write \
		scripts/baseline_manager.ts save \
		--input benchmarks/results/latest.json \
		--name main \
		--description "Main branch baseline (updated: $$(date +%Y-%m-%d))"
	@echo "✅ Baseline saved: benchmarks/baselines/main.json"

benchmark-clean: ## Clean benchmark artifacts
	@rm -rf benchmarks/results/*.json benchmarks/results/*.md benchmarks/results/csv/
	@echo "✓ Benchmark artifacts cleaned"

# ============================================================================
# Dependency management
# ============================================================================
update-deps: ## Update dependencies (semver-compatible)
	@echo "🔄 Updating dependencies (semver-compatible)..."
	@cargo update --workspace
	@echo "Running tests to verify compatibility..."
	@make test-quick
	@echo "✅ Dependencies updated successfully!"

update-deps-aggressive: ## Update all dependencies including major versions
	@echo "🔄 Updating dependencies aggressively..."
	@if ! command -v cargo-upgrade >/dev/null 2>&1; then \
		echo "📥 Installing cargo-edit..."; \
		cargo install cargo-edit; \
	fi
	@cargo update --workspace
	@cargo upgrade --incompatible
	@echo "Running tests..."
	@make test-quick lint-check
	@make audit
	@echo "✅ Aggressive update completed!"

update-deps-check: ## Check for outdated dependencies
	@echo "🔍 Checking for outdated dependencies..."
	@if ! command -v cargo-outdated >/dev/null 2>&1; then \
		echo "📥 Installing cargo-outdated..."; \
		cargo install cargo-outdated; \
	fi
	@cargo outdated --workspace --root-deps-only
	@echo ""
	@echo "🔍 Security advisories check:"
	@make audit || true

# ============================================================================
# Documentation
# ============================================================================
docs: ## Build documentation
	@echo "📚 Building documentation..."
	@cargo doc --all-features --workspace --no-deps
	@echo "Documentation available at target/doc/certeza/index.html"

docs-open: ## Build and open documentation
	@echo "📚 Building and opening documentation..."
	@cargo doc --all-features --workspace --no-deps --open

# ============================================================================
# Build
# ============================================================================
build: ## Build release binaries
	@echo "🔨 Building release binaries..."
	@cargo build --release --all-features

# ============================================================================
# Install tools
# ============================================================================
install-tools: ## Install required tooling
	@echo "📦 Installing required tools..."
	@echo "Installing cargo-llvm-cov..."
	@cargo install cargo-llvm-cov --locked
	@echo "Installing cargo-mutants..."
	@cargo install cargo-mutants --locked
	@echo "Installing cargo-audit..."
	@cargo install cargo-audit --locked
	@echo "Installing cargo-deny..."
	@cargo install cargo-deny --locked
	@echo "Installing pmat (if available)..."
	@cargo install pmat --locked || echo "⚠️  pmat not available"
	@echo "✅ All tools installed!"

install-hooks: ## Install git hooks with PMAT
	@echo "🔒 Installing git hooks..."
	@if command -v pmat >/dev/null 2>&1; then \
		pmat hooks install; \
		pmat hooks status; \
	else \
		echo "⚠️  pmat not installed, cannot install hooks"; \
		echo "Install pmat: cargo install pmat"; \
	fi

# ============================================================================
# Repository scoring
# ============================================================================
repo-score: ## Calculate repository health score
	@echo "📊 Calculating repository health score..."
	@if command -v pmat >/dev/null 2>&1; then \
		pmat repo-score .; \
	else \
		echo "⚠️  pmat not installed. Install: cargo install pmat"; \
	fi

repo-score-deep: ## Calculate deep repository health score
	@echo "📊 Calculating deep repository health score..."
	@if command -v pmat >/dev/null 2>&1; then \
		pmat repo-score . --deep; \
	else \
		echo "⚠️  pmat not installed. Install: cargo install pmat"; \
	fi

# ============================================================================
# Clean
# ============================================================================
clean: ## Clean build artifacts
	@echo "🧹 Cleaning..."
	@cargo clean
	@rm -rf target/ mutants.out/ .quality/ .kaizen/
	@rm -f lcov.info coverage.xml QUALITY_REPORT.md
	@find . -name "*.profraw" -delete

# ============================================================================
# Help
# ============================================================================
help: ## Show this help
	@echo "Certeza - Asymptotic Test Effectiveness Framework"
	@echo "=================================================="
	@echo ""
	@echo "Main targets:"
	@echo "  make              - Run Tier 2 validation and build"
	@echo "  make tier1        - Tier 1: ON-SAVE checks (sub-second)"
	@echo "  make tier2        - Tier 2: ON-COMMIT checks (1-5 min)"
	@echo "  make tier3        - Tier 3: ON-MERGE/NIGHTLY (hours)"
	@echo "  make build        - Build release binaries"
	@echo ""
	@echo "Validation:"
	@echo "  make validate     - Full validation pipeline"
	@echo "  make quick-validate - Quick validation for development"
	@echo ""
	@echo "Testing:"
	@echo "  make test         - Run core test suite"
	@echo "  make test-quick   - Run unit tests only (fast)"
	@echo "  make test-property - Run property-based tests (50 cases)"
	@echo "  make test-property-comprehensive - Run property tests (500 cases)"
	@echo "  make test-all     - Run ALL tests comprehensively"
	@echo "  make test-doc     - Run documentation tests"
	@echo ""
	@echo "Quality:"
	@echo "  make quality-gate - Run comprehensive quality checks"
	@echo "  make analyze-complexity - Analyze code complexity with pmat"
	@echo "  make analyze-tdg  - Analyze Technical Debt Grade with pmat"
	@echo "  make validate-docs - Validate README accuracy (zero hallucinations)"
	@echo "  make quality-report - Generate quality report"
	@echo "  make security     - Run all security checks"
	@echo "  make audit        - Security audit"
	@echo "  make deny         - Check dependencies and licenses"
	@echo ""
	@echo "Coverage:"
	@echo "  make coverage     - Generate HTML coverage report"
	@echo "  make coverage-open - Open HTML coverage in browser"
	@echo "  make coverage-ci  - Generate LCOV report for CI/CD"
	@echo "  make coverage-clean - Clean coverage artifacts"
	@echo ""
	@echo "Mutation Testing (Tier 3):"
	@echo "  make mutation     - Run full mutation testing (>85% target)"
	@echo "  make mutation-report - Analyze mutation test results"
	@echo "  make mutation-clean - Clean mutation artifacts"
	@echo ""
	@echo "Benchmarking:"
	@echo "  make benchmark    - Run critical performance benchmarks"
	@echo "  make benchmark-all - Run comprehensive benchmark suite"
	@echo "  make benchmark-report - Generate markdown/CSV reports"
	@echo "  make benchmark-compare - Compare against baseline (regression check)"
	@echo "  make benchmark-baseline-save - Save current as baseline"
	@echo "  make benchmark-clean - Clean benchmark artifacts"
	@echo ""
	@echo "Code Quality:"
	@echo "  make format       - Format code"
	@echo "  make format-check - Check formatting"
	@echo "  make lint         - Run clippy with fixes"
	@echo "  make lint-check   - Check clippy"
	@echo "  make clippy-strict - Run strict clippy"
	@echo "  make check        - Type checking"
	@echo ""
	@echo "Dependencies:"
	@echo "  make update-deps  - Update dependencies (semver-compatible)"
	@echo "  make update-deps-aggressive - Update all dependencies"
	@echo "  make update-deps-check - Check for outdated dependencies"
	@echo ""
	@echo "Documentation:"
	@echo "  make docs         - Build documentation"
	@echo "  make docs-open    - Build and open documentation"
	@echo ""
	@echo "Setup:"
	@echo "  make install-tools - Install required tooling"
	@echo "  make install-hooks - Install PMAT git hooks"
	@echo ""
	@echo "Analysis:"
	@echo "  make repo-score   - Calculate repository health score"
	@echo "  make repo-score-deep - Deep repository analysis"
	@echo "  make kaizen       - Continuous improvement cycle"
	@echo "  make demo-mode    - Interactive framework demonstration"
	@echo ""
	@echo "Other:"
	@echo "  make clean        - Clean build artifacts"
	@echo "  make help         - Show this help"
	@echo ""
	@echo "Toyota Way Principles:"
	@echo "  - 改善 (Kaizen): Continuous improvement"
	@echo "  - 無駄 (Muda): Elimination of waste"
	@echo "  - Zero defects through tiered verification"
	@echo "  - Fast feedback loops maintain flow state"