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

.PHONY: benchmark benchmark-m1 benchmark-m1-smoke benchmark-m2 benchmark-m2-smoke benchmark-smoke build compile contract dependencies format-check gate lint lock test type

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_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

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

gate: format-check lint type compile contract test lock dependencies build benchmark-smoke benchmark-m1-smoke benchmark-m2-smoke
