.PHONY: install test probe conformance fidelity consensus rate track real all clean live assets video-captures

install:
	uv venv --python 3.12 2>/dev/null || true
	. .venv/bin/activate && uv pip install -e ".[chain,dev]"

test:
	. .venv/bin/activate && python -m pytest -q

probe:
	@. .venv/bin/activate && \
	for m in naive_flat quality_only hardened winner_take_all; do \
	  echo ""; echo "=============== $$m ==============="; \
	  assay run examples/$$m.py --no-color || true; \
	done

conformance:
	. .venv/bin/activate && assay conformance

# validator-side: consensus, stake capture, concentration
consensus:
	@. .venv/bin/activate && \
	for m in hardened winner_take_all; do \
	  echo ""; echo "=============== $$m ==============="; \
	  assay consensus examples/$$m.py --no-color || true; \
	done

# scoring rules reproduced from real subnets
real:
	@. .venv/bin/activate && \
	for m in subnet_template ranked_reward; do \
	  echo ""; echo "=============== $$m ==============="; \
	  assay run examples/real/$$m.py --no-color || true; \
	done

# structural score across the largest subnets
rate:
	. .venv/bin/activate && assay rate --top 12 --no-color

# record today's observation, then read the trend back
track:
	@. .venv/bin/activate && assay history --record --top 24
	@. .venv/bin/activate && assay history --all --no-color

# verify the weights-into-rewards model against the chain
fidelity:
	. .venv/bin/activate && assay fidelity --netuid 64

# what CI runs
all: test conformance
	@. .venv/bin/activate && assay run examples/hardened.py -f json -o assay.json \
	  && echo "gate: hardened mechanism still holds"

# live replay needs network + the chain extra
live:
	@. .venv/bin/activate && \
	for n in 1 4 8 64; do assay live --netuid $$n --no-color || true; done

# capture real stdout for the demo film — the film reads these files, so this
# must run before rendering and after any change to the CLI output format
video-captures:
	@mkdir -p /tmp/vid
	. .venv/bin/activate && assay run examples/winner_take_all.py --no-color > /tmp/vid/wta.txt 2>&1 || true
	. .venv/bin/activate && assay run examples/hardened.py --no-color > /tmp/vid/hardened.txt 2>&1
	. .venv/bin/activate && assay scan --top 8 --no-color > /tmp/vid/scan.txt 2>&1
	. .venv/bin/activate && assay rate --top 8 --no-color > /tmp/vid/rate.txt 2>&1
	. .venv/bin/activate && assay consensus examples/winner_take_all.py --no-color > /tmp/vid/consensus.txt 2>&1 || true
	@echo "captured 5 files into /tmp/vid"

# regenerate the README images from real output
assets:
	. .venv/bin/activate && python tools/render_terminal_svg.py

clean:
	rm -rf .pytest_cache assay.json
	find . -name __pycache__ -type d -prune -exec rm -rf {} +
