# Justfile for carapace
# Install just: cargo install just
# Run: just <recipe>

# Default recipe - show available commands
default:
    @just --list

# Build the project
build:
    cargo build

# Build in release mode
build-release:
    cargo build --release

# Run the full local test lane.
test:
    ./scripts/run-nextest-guarded.sh --all-targets -P full

# Run the fastest broad local Rust test lane.
test-fast:
    ./scripts/run-nextest-guarded.sh --all-targets -P fast

# Run the full golden lane (WebSocket traces + golden/schema integration checks).
test-golden:
    ./scripts/cargo-serial nextest run --all-targets -P golden

# Run the slower integration lane.
test-integration:
    ./scripts/run-nextest-guarded.sh --all-targets -P integration

# Run the broad full lane used for push-time validation.
test-full:
    ./scripts/run-nextest-guarded.sh --all-targets -P full

# Run library tests only
test-lib:
    ./scripts/run-nextest-guarded.sh --lib -P full

# Run tests with verbose output
test-verbose:
    ./scripts/run-nextest-guarded.sh --all-targets -P full --no-capture

# Run a specific test by name
test-one NAME:
    ./scripts/run-nextest-guarded.sh --all-targets -P full {{NAME}}

# Run the full golden lane.
test-ws-golden:
    @just test-golden

# Run the fastest websocket golden guard for update/status contract drift.
test-ws-golden-quick:
    ./scripts/run-nextest-guarded.sh --all-targets -P golden --test cara server::ws::golden_tests::golden_trace::golden_update_status

# Run tests and show coverage summary
test-coverage:
    cargo tarpaulin --out Html --output-dir target/coverage

# Run clippy linter
lint:
    cargo clippy

# Run clippy with warnings as errors
lint-strict:
    cargo clippy -- -D warnings

# Format code
fmt:
    cargo fmt

# Check formatting without making changes
fmt-check:
    cargo fmt --check

# Run all checks (lint + fmt + Matrix wire guard + test)
check: lint fmt-check matrix-wire-guard test

# Enforce Matrix public wire coverage across kind/docs/CLI/HTTP/WS projections.
matrix-wire-guard:
    ./scripts/check-matrix-wire-guards.sh
    ./scripts/check-matrix-wire-guards.sh --self-test

# Enforce sync/async runtime bridge boundaries.
runtime-bridge-guard:
    ./scripts/check-runtime-bridge-usage.sh

# Build documentation
doc:
    cargo doc --no-deps

# Build and open documentation
doc-open:
    cargo doc --no-deps --open

# Clean build artifacts
clean:
    cargo clean

# Watch for changes and run tests
watch:
    cargo watch -x 'nextest run'

# Watch for changes and run clippy
watch-lint:
    cargo watch -x clippy

# Run the same markdown tab check used in CI docs-check.
docs-check:
    @echo "Checking Markdown files for hard tabs"
    @tab="$$(printf '\t')"; \
      if grep -RIn "$$tab" --include='*.md' --exclude-dir=.git --exclude-dir=target .; then \
        echo "Found tab characters in Markdown files; please use spaces."; \
        exit 1; \
      fi

# Run the same workflow lint used in CI (requires actionlint).
workflow-lint:
    @if command -v actionlint >/dev/null 2>&1; then \
      actionlint -color -shellcheck=; \
    else \
      echo "actionlint not found. Install from https://github.com/rhysd/actionlint"; \
      exit 1; \
    fi

# Setup git hooks for pre-commit and pre-push checks.
setup-hooks:
    ./scripts/setup-hooks.sh

# Run pre-commit hook checks manually.
pre-commit:
    ./scripts/hooks/pre-commit

# Run pre-push hook checks manually.
pre-push:
    ./scripts/hooks/pre-push origin </dev/null

# Create a PR safely from a markdown body file (avoids shell backtick expansion).
pr-create TITLE BODY_FILE BASE='master' HEAD='':
    ./scripts/create-pr.sh "{{TITLE}}" "{{BODY_FILE}}" "{{BASE}}" "{{HEAD}}"
