PYTHON := .venv/bin/python
PYRIGHT := pyright
UV := uv
NPM := npm
PYTHONPYCACHEPREFIX := /tmp/docforge-quality-pycache
PYTEST_BASETEMP := /tmp/docforge-quality-pytest

.PHONY: accessibility benchmark benchmark-m1 benchmark-m1-smoke benchmark-m2 benchmark-m2-smoke benchmark-m3 benchmark-m3-full benchmark-m3-smoke benchmark-m4 benchmark-m4-full benchmark-m4-smoke benchmark-smoke build command-reference-check compile contract dependencies format-check gate lint lock test type

accessibility:
	$(NPM) run test:accessibility

format-check:
	$(PYTHON) -m ruff format --check src tests tools

lint:
	$(PYTHON) -m ruff check src tests tools
	$(NPM) run lint:web

type:
	$(PYRIGHT) --pythonpath .venv/bin/python

compile:
	PYTHONPYCACHEPREFIX=$(PYTHONPYCACHEPREFIX) $(PYTHON) -m compileall -q src tests tools

contract:
	PYTHONPYCACHEPREFIX=$(PYTHONPYCACHEPREFIX) $(PYTHON) -m pytest -q \
		-p no:cacheprovider --basetemp=$(PYTEST_BASETEMP) \
		tests/test_public_contract.py \
		tests/test_policy.py \
		tests/test_projection_policy.py \
		tests/test_projection_policy_integration.py \
		tests/test_projection_worker.py \
		tests/test_projection_fragments.py \
		tests/test_retrieval.py \
		tests/test_generation_diff.py \
		tests/test_client_integration.py \
		tests/test_projection_contract.py \
		tests/test_projection_schemas.py \
		tests/test_graph_projection.py \
		tests/test_graph_rendering.py \
		tests/test_graph_publication.py \
		tests/test_observability.py::TelemetryContractTests::test_schema_fixed_names_match_the_implementation \
		tests/test_adapter_contract.py::AdapterContractTests::test_no_ast_index_policy_rejects_logic_publication \
		tests/test_adapter_contract.py::AdapterContractTests::test_no_ast_index_accepts_legacy_and_non_logic_incremental_adapters \
		tests/test_adapter_contract.py::AdapterContractTests::test_no_ast_rejects_preexisting_logic_index_and_viewer_snapshot \
		tests/test_mcp_server.py::DocForgeMcpTests::test_no_ast_binding_preserves_adapter_and_blocks_logic

test:
	PYTHONPYCACHEPREFIX=$(PYTHONPYCACHEPREFIX) $(PYTHON) -m pytest -q \
		-p no:cacheprovider --basetemp=$(PYTEST_BASETEMP)

lock:
	$(UV) lock --check

dependencies:
	$(NPM) ls --all

build:
	$(UV) build

command-reference-check:
	$(PYTHON) tools/generate_command_reference.py \
		--output docs/COMMAND_REFERENCE.md --check > /dev/null

benchmark-smoke:
	$(PYTHON) tools/milestone0_baseline.py --nodes 25 --samples 1 --cold-samples 1 \
		--output /tmp/docforge-milestone0-smoke.json > /dev/null

benchmark:
	$(PYTHON) tools/milestone0_baseline.py --nodes 1000 --samples 10 --cold-samples 3

benchmark-m1-smoke:
	$(PYTHON) tools/milestone1_benchmark.py --nodes 25 --samples 1 \
		--output /tmp/docforge-milestone1-smoke.json > /dev/null

benchmark-m1:
	$(PYTHON) tools/milestone1_benchmark.py --nodes 1000 --samples 10

benchmark-m2-smoke:
	$(PYTHON) tools/milestone2_benchmark.py --nodes 25 --samples 1 \
		--output /tmp/docforge-milestone2-smoke.json > /dev/null

benchmark-m2:
	$(PYTHON) tools/milestone2_benchmark.py --nodes 1000 --samples 10

benchmark-m3-smoke:
	$(PYTHON) tools/milestone3_benchmark.py --mode smoke \
		--output /tmp/docforge-milestone3-smoke.json > /dev/null

benchmark-m3:
	$(PYTHON) tools/milestone3_benchmark.py --mode full

benchmark-m3-full: benchmark-m3

benchmark-m4-smoke:
	$(PYTHON) tools/milestone4_benchmark.py --mode smoke \
		--output /tmp/docforge-milestone4-smoke.json > /dev/null

benchmark-m4:
	$(PYTHON) tools/milestone4_benchmark.py --mode full

benchmark-m4-full: benchmark-m4

gate: format-check lint type compile contract test accessibility lock dependencies build command-reference-check benchmark-smoke benchmark-m1-smoke benchmark-m2-smoke benchmark-m3-smoke benchmark-m4-smoke
