# polymodel development commands

set dotenv-load := false

# Format and apply safe automatic fixes. This is the default pre-review cleanup command.
fix:
    cargo fmt --all
    cargo clippy --workspace --all-targets --fix --allow-dirty --allow-staged --allow-no-vcs -- -D warnings
    cargo clippy -p polymodel --all-targets --features server --fix --allow-dirty --allow-staged --allow-no-vcs -- -D warnings

# Compile checks across the whole workspace plus the app's server/wasm targets.
# Note: the server check uses compile-time `query!` macros that validate against a
# migrated SQLite database. Run `just migrate` first (or run `just sqlx-prepare`)
# so the macros can resolve.
check:
    cargo check --workspace
    cargo check -p polymodel --features server
    cargo check -p polymodel --target wasm32-unknown-unknown --features web

# Create and migrate the SQLite projection database.
# Required by the compile-time `query!` macros: run before the first server
# check, and re-run after editing migrations.
migrate:
    mkdir -p ./data
    -cargo sqlx database create --database-url 'sqlite:./data/polymodel.db'
    cargo sqlx migrate run --source migrations --database-url 'sqlite:./data/polymodel.db'

# Regenerate the committed `.sqlx` offline query cache after changing SQL.
sqlx-prepare:
    cargo sqlx prepare -- -p polymodel --features server

# Run unit tests across the workspace.
test:
    cargo nextest run --workspace

# Run server-feature tests (app only; polymodel-api has no server feature).
test-server:
    cargo nextest run -p polymodel --features server

# Run all local validation expected before review.
test-all: fix check test test-server
# Run browser end-to-end tests.
e2e:
    cd e2e && npm test
# Start the Dioxus dev server.
serve:
    dx serve
# Build the Dioxus app for web.
build-web:
    dx build --platform web
# Regenerate crates/polymodel-api from authored lexicons via the local Jacquard checkout.
generate-api:
    nix run ../jacquard
# Create a sibling jj workspace for a Jira ticket or feature slug, then start a fresh change.
workspace-create name:
    root="$(jj workspace root)" && workspace_path="$(dirname "$root")/{{ name }}" && jj workspace add "$workspace_path" -r @
    root="$(jj workspace root)" && workspace_path="$(dirname "$root")/{{ name }}" && cd "$workspace_path" && jj desc -m "{{ name }}"

# List jj workspaces.
workspace-list:
    jj workspace list

# Forget a jj workspace after the work is safely landed or intentionally abandoned.
workspace-forget name:
    jj workspace forget {{ name }}

# Show current jj state and diff.
status:
    jj status
    jj diff --summary

# Clean build artifacts.
clean:
    cargo clean
    rm -rf target/dx
