.PHONY: lint test generate-client check-generated build publish clean
# Tools come from uv, so CI and laptops need nothing on PATH but uv itself.
# mypy runs in the synced project env (no --no-sync): it type-checks against the package's dependencies (httpx), which a
# fresh CI venv has only after uv installs them. --no-sync passed locally only where an earlier `uv run` had synced .venv.
# types-protobuf: the generated *_pb2.pyi stubs import google.protobuf, which ships no type information of its own.
# --extra mcp: the MCP server (devzero_sandbox.mcp.server, ADR-003-W11) is type-checked and tested with its optional
# dependency installed; the SDK itself never imports it.
lint: ; uvx ruff check . && uvx ruff format --check . && uv run --extra mcp --with mypy --with types-protobuf mypy --strict src
test: ; mkdir -p _output && uv run --extra mcp --with pytest pytest -q --junitxml=_output/junit.xml
# The SandboxService client (ADR-007-W13): protobuf messages from buf's pinned remote plugins (buf.gen.yaml; versions in
# the repo's buf.pins.yaml), then the Connect stub from a buf image that keeps the proto comments (tools/gen_connect.py).
# The proto in dakr/proto/sandbox/v1 is the contract (devzero-inc/services#11988); the output is checked in.
BUF := $(CURDIR)/../../tools/scripts/buf.sh
PROTOS := --path proto/sandbox/v1/service.proto --path proto/sandbox/v1/error.proto
generate-client:
	rm -rf -- src/devzero_sandbox/_proto
	mkdir -p _output
	cd ../../dakr && $(BUF) generate --template $(CURDIR)/buf.gen.yaml -o $(CURDIR) $(PROTOS)
	cd ../../dakr && $(BUF) build -o $(CURDIR)/_output/sandbox.binpb $(PROTOS)
	uv run python tools/gen_connect.py _output/sandbox.binpb src/devzero_sandbox/_proto
# CI freshness check: the checked-in client is what the current proto generates.
check-generated: generate-client
	@git diff --exit-code -- src/devzero_sandbox/_proto && test -z "$$(git ls-files --others --exclude-standard -- src/devzero_sandbox/_proto)" \
	  || { git ls-files --others --exclude-standard -- src/devzero_sandbox/_proto; \
	       echo "stale client: run make generate-client and commit the result" >&2; exit 1; }
build: ; python -m build
publish: ; @echo "publish runs in CI (sandbox-sdk-python-publish.yml)"; exit 1
clean: ; rm -rf dist _output .mypy_cache .ruff_cache
