# ContractMe dev commands. Bare `just` lists the recipes.
# These wrap the canonical uv invocations — prefer a recipe to an ad-hoc command,
# and when a new command starts getting repeated, promote it to a recipe here.

set positional-arguments

# List available recipes
default:
    @just --list

# Run pytest; args pass through (e.g. `just test tests/test_contracting.py::test_square_root -x`)
test *args:
    uv run pytest "$@"

# Extra args pass through to pytest — CI adds XML reports, and a later
# --cov-fail-under overrides the baked-in 100 (last one wins).
[doc('Tests + the coverage gate: 100% statements *and* branches (same gate as CI and pre-commit)')]
cov *args:
    uv run pytest --cov --cov-report term-missing --cov-fail-under=100 "$@"

# Mirrors the checks-optimized CI job; violation tests skip via tests/conftest.py.
# The ignored warning is pytest noticing library asserts are off — the point of the run.
[doc('Differential run: contracts compiled out via -O, valid-path behavior must be identical')]
test-optimized *args:
    uv run python -O -m pytest -W ignore::pytest.PytestConfigWarning "$@"

# Format the code (black, line length 100)
fmt:
    uv run black .

# Lint: formatting drift (check only) + flake8
lint:
    uv run black --check .
    uv run flake8

# Static typing: pinned pyright from the dev deps (matches CI); the repo stays at 0 errors
types *args:
    uv run pyright . "$@"

# No fail-fast: one run reports every failing step by recipe name,
# so each can be rerun on its own (`just types`).
[doc('The full local gate — everything CI checks, reporting all failures at once')]
check:
    #!/usr/bin/env bash
    set -u
    failed=()
    for recipe in cov test-optimized lint types; do
        printf '\n━━━ %s ━━━\n' "$recipe"
        just "$recipe" || failed+=("$recipe")
    done
    printf '\n'
    if ((${#failed[@]})); then
        echo "FAILED: ${failed[*]}"
        exit 1
    fi
    echo "all checks passed"

# Build sdist+wheel locally (real releases are built and published by CI — see CLAUDE.md)
build:
    uv build

# Checks the tag matches pyproject.toml and CHANGELOG.md, then writes release_notes.md.
[doc('CI release gate: validate the tag and extract its release notes')]
release-notes:
    uv run python release/release_notes.py

# Sets the pyproject version, refreshes uv.lock, checks the CHANGELOG section.
[doc("Prepare a release (omit the version to reuse pyproject's)")]
prerelease *version:
    uv run python release/prerelease.py "$@"
