# One command surface (InnerLoop §agentic-efficiency #3). Deterministic,
# greppable output; precursor of the `cb` CLI.

CARGO := cargo

.PHONY: check test sim bench bench-test coverage dep-weight cost cost-test cost-pin loc all

## fmt + clippy (deny warnings) + HashMap deny-lint
check:
	$(CARGO) fmt --all --check
	$(CARGO) clippy --workspace --all-targets -- -D warnings

## unit + scenario-format tests
test:
	$(CARGO) test --workspace

## run all GROUND scenarios through cb-sim
dep-weight:
	python3 tools/dep-weight.py

coverage:
	python3 tools/rule-coverage.py

# M-D2-CST (specs/CostAccounting.md). cost-test is the positive control and
# runs first: a cost number from an unverified collector is void.
cost: cost-test
	python3 tools/cb-cost.py --composition --by-task

cost-test:
	python3 tools/cb-cost.py --self-test

cost-pin: cost-test
	python3 tools/cb-cost.py --pin fc76445 --composition --by-task

sim:
	$(CARGO) run -q -p cb-sim -- scenarios/ground/*.yaml

## Criterion benches (AM-6/AM-7)
bench:
	$(CARGO) bench -p games-ground

## InnerLoop positive control: run every bench once, no measurement.
## Fails if a workload stalls or produces the wrong event count.
bench-test:
	$(CARGO) bench -p games-ground --bench synthetic -- --test


## AM-2/AM-3 input: source LOC per crate (excludes tests would need tokei)
loc:
	@for d in crates/cb-kernel crates/cb-events crates/cb-game-runtime games/ground tools/cb-sim; do \
		printf '%-28s %s\n' $$d "$$(find $$d/src -name '*.rs' | xargs cat | grep -vcE '^\s*(//|$$)')"; \
	done

all: check test sim coverage dep-weight cost-test bench-test
