# Justfile for fastapi-openrpc

# 默认目标：运行所有测试
default: test

# 安装依赖
install:
    uv sync

# 开发依赖
install-dev:
    uv sync --extra dev

# 运行所有测试
test:
    uv run pytest tests/ -v

# 运行测试并显示覆盖率
test-cov:
    uv run pytest tests/ -v --cov=src/fastapi_openrpc --cov-report=term-missing

# 启动 minimal 示例（PORT 环境变量可覆盖，如 PORT=9000 just run-minimal）
run-minimal:
    uv run uvicorn examples.minimal_app:app --host 0.0.0.0 --port 10333 --reload

# 测试 minimal 示例（启动服务，退出时关闭）
test-minimal:
    bash -c 'uv run uvicorn examples.minimal_app:app --host 0.0.0.0 --port 10333 & UV_PID=$!; npx httpyac tests/http/minimal.http -a; kill -TERM $UV_PID 2>/dev/null; wait $UV_PID 2>/dev/null; true'

# 启动 HMAC 认证示例（需先设置 HMAC_SECRET_KEY）
run-hmac:
    HEADER_SIGNING_KEY=my-secret-key uv run uvicorn examples.hmac_auth_dependency:app --host 0.0.0.0 --port 10334 --reload

test-hmac:
    bash -c 'HMAC_SECRET_KEY=my-secret-key uv run uvicorn examples.hmac_auth_dependency:app --host 0.0.0.0 --port 10334 & UV_PID=$!; npx httpyac tests/http/hmac.http -a; kill -TERM $UV_PID 2>/dev/null; wait $UV_PID 2>/dev/null; true'

# 启动 Pydantic 模型示例
run-pydantic:
    uv run uvicorn examples.pydantic_models:app --host 0.0.0.0 --port 10335 --reload

test-pydantic:
    bash -c 'uv run uvicorn examples.pydantic_models:app --host 0.0.0.0 --port 10335 & UV_PID=$!; npx httpyac tests/http/pydantic.http -a; kill -TERM $UV_PID 2>/dev/null; wait $UV_PID 2>/dev/null; true'

# Lint
lint:
    uv run ruff check src/ tests/

# 格式化
fmt:
    uv run ruff format src/ tests/

# 类型检查
typecheck:
    uv run pyright

# 完整开发检查：lint + typecheck + test
check: lint typecheck test

# 运行 pre-commit（仅 staged 文件）
precommit:
    uv run pre-commit run

# 运行 pre-commit 所有文件
precommit-all:
    uv run pre-commit run --all-files

# 安装 pre-commit hook（首次克隆后运行一次）
precommit-install:
    pre-commit install

# 列出所有可用目标
help:
    just --list
