Ctrl K
ComunidadGuías…

Justfile

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
# The nightly cargo-fuzz builds against. Pinned rather than `nightly`, for the
# same reason rust-toolchain.toml pins 1.98.1: a gate that can fail without a
# change to this repository is not a signal.
FUZZ_TOOLCHAIN := "nightly-2026-01-31"

default:
    @echo "Run 'just --list' to view available tasks."

kube-create:
    @echo "[kube:create] Creating k3d cluster using infra/k3d-config.yaml"
    k3d cluster create --config infra/k3d-config.yaml

kube-delete:
    @echo "[kube:delete] Deleting k3d cluster guardyn-poc"
    k3d cluster delete guardyn-poc || true

kube-bootstrap:
    @echo "[kube:bootstrap] Installing core components"
    bash infra/scripts/bootstrap.sh

k8s-deploy service:
    bash infra/scripts/deploy.sh "{{service}}"

verify-kube:
    @echo "[verify:kube] Running smoke checks"
    bash infra/scripts/verify.sh

teardown:
    @echo "[teardown] Destroying cluster and cleaning up"
    just kube-delete

# Port-forwarding with auto-restart watchdog
port-forward:
    @echo "[port-forward] Starting port-forward watchdog (Ctrl+C to stop)"
    bash infra/scripts/port-forward-watchdog.sh

# Port-forwarding without Envoy (for native apps only)
port-forward-native:
    @echo "[port-forward] Starting port-forward watchdog for native apps"
    bash infra/scripts/port-forward-watchdog.sh --no-envoy --no-chromedriver

# Port-forwarding status check
port-forward-status:
    bash infra/scripts/port-forward-watchdog.sh --status

# Stop all port-forwards
port-forward-stop:
    bash infra/scripts/port-forward-watchdog.sh --stop

# Run two-user chat E2E test
test-chat:
    @echo "[test] Running two-user chat E2E test"
    bash backend/crates/e2e-tests/scripts/test-two-user-chat.sh

# Run all messaging E2E tests
test-messaging:
    @echo "[test] Running all messaging E2E tests"
    bash backend/crates/e2e-tests/scripts/test-two-user-chat.sh --all

# =============================================================================
# User Management Commands
# =============================================================================

# List all registered users
list-users:
    @echo "[users] Listing registered users..."
    bash infra/scripts/user-management.sh list

# Delete a specific user and all their data
delete-user username:
    @echo "[users] Deleting user: {{username}}"
    bash infra/scripts/user-management.sh delete "{{username}}"

# Delete ALL users and data (DANGEROUS!)
delete-all-users:
    @echo "[users] ⚠️  Deleting ALL user data..."
    bash infra/scripts/user-management.sh delete-all

# =============================================================================
# Local Development Commands (Fast Rebuild)
# =============================================================================
# These commands run services locally with port-forwards to cluster databases.
# Benefits: ~5-10 sec rebuild (vs ~60+ sec with Docker), hot-reload, direct debug

# Start port-forwards to cluster databases only
dev-ports:
    @echo "[dev] Starting port-forwards to databases..."
    bash infra/scripts/dev-local.sh ports-only

# Stop all port-forwards
dev-stop:
    @echo "[dev] Stopping all port-forwards..."
    bash infra/scripts/dev-local.sh stop

# Check port-forward status
dev-status:
    @echo "[dev] Checking port-forward status..."
    bash infra/scripts/dev-local.sh status

# Run auth-service locally (with port-forwards)
dev-auth:
    @echo "[dev] Starting auth-service locally..."
    bash infra/scripts/dev-local.sh auth

# Run messaging-service locally (with port-forwards)
dev-messaging:
    @echo "[dev] Starting messaging-service locally..."
    bash infra/scripts/dev-local.sh messaging

# Run presence-service locally (with port-forwards)
dev-presence:
    @echo "[dev] Starting presence-service locally..."
    bash infra/scripts/dev-local.sh presence

# Run media-service locally (with port-forwards)
dev-media:
    @echo "[dev] Starting media-service locally..."
    bash infra/scripts/dev-local.sh media

# Run all services locally in tmux
dev-all:
    @echo "[dev] Starting all services in tmux..."
    bash infra/scripts/dev-local.sh all

# Stop local Envoy (if running from k8s proxy)
dev-envoy-stop:
    @echo "[dev] Stopping Envoy containers..."
    docker stop envoy-local 2>/dev/null || true
    docker rm envoy-local 2>/dev/null || true

# Run Envoy port-forward from k8s (for testing with cluster services)
dev-envoy-k8s:
    @echo "[dev] Starting Envoy port-forward from k8s on :18080 (API Gateway)..."
    kubectl port-forward -n apps svc/guardyn-envoy 18080:8080

# Stop all services (tmux session + port-forwards)
dev-kill:
    @echo "[dev] Stopping all services and port-forwards..."
    tmux kill-session -t guardyn-dev 2>/dev/null || true
    bash infra/scripts/dev-local.sh stop

# Run a service with hot-reload (requires cargo-watch)
dev-watch service:
    @echo "[dev] Starting {{service}} with hot-reload..."
    cd backend && cargo watch -x "run --bin {{service}}"

# =============================================================================
# Resource Optimization Commands
# =============================================================================

# Scale down services for development (saves ~9 pods)
scale-dev:
    @echo "[scale] Scaling services to dev mode (1 replica each)..."
    kubectl scale deployment -n apps auth-service --replicas=1
    kubectl scale deployment -n apps messaging-service --replicas=1
    kubectl scale deployment -n apps presence-service --replicas=1
    kubectl scale deployment -n apps media-service --replicas=1
    @echo "[scale] Done. Pods reduced from ~10 to ~4 in apps namespace."

# Scale down ALL app services to 0 (for local dev mode)
scale-local:
    @echo "[scale] Scaling all app services to 0 (local dev mode)..."
    kubectl scale deployment -n apps auth-service messaging-service presence-service media-service guardyn-envoy --replicas=0
    @echo "[scale] Done. All app pods stopped. Use 'just dev-all' + 'just dev-envoy-local' for local development."

# Scale up services for testing (original replicas)
scale-prod:
    @echo "[scale] Scaling services to prod mode..."
    kubectl scale deployment -n apps auth-service --replicas=2
    kubectl scale deployment -n apps messaging-service --replicas=3
    kubectl scale deployment -n apps presence-service --replicas=2
    kubectl scale deployment -n apps media-service --replicas=2
    @echo "[scale] Done. Services scaled to production replicas."

# Show current resource usage
resources:
    @echo "[resources] Current pod resource usage:"
    @echo "=== Apps namespace ==="
    kubectl top pods -n apps 2>/dev/null || echo "Metrics not available (install metrics-server)"
    @echo ""
    @echo "=== Data namespace ==="
    kubectl top pods -n data 2>/dev/null || echo "Metrics not available"
    @echo ""
    @echo "=== Pod counts ==="
    @echo "Apps: $(kubectl get pods -n apps --no-headers 2>/dev/null | wc -l) pods"
    @echo "Data: $(kubectl get pods -n data --no-headers 2>/dev/null | wc -l) pods"

# =============================================================================
# Flutter Mobile Client Commands (iOS/Android only)
# For Desktop (Windows/macOS/Linux) use Tauri: just dev-desktop
# =============================================================================

# Run Tauri Desktop client (Windows/macOS/Linux)
dev-desktop:
    @echo "[dev] Starting Tauri Desktop client..."
    @echo "[dev] Make sure backend is running: docker compose -f docker-compose.dev.yml up -d"
    cd client-desktop && npm run tauri dev

# Build Tauri Desktop for production
build-desktop:
    @echo "[build] Building Tauri Desktop client..."
    cd client-desktop && npm run tauri build

# Run Tauri Desktop tests
test-desktop:
    @echo "[test] Running Tauri Desktop tests..."
    cd client-desktop && npm run test

# Run Flutter Android client (requires Docker Compose backend)
dev-android:
    @echo "[dev] Starting Flutter Android client..."
    @echo "[dev] Make sure backend is running: docker compose -f docker-compose.dev.yml up -d"
    @echo "[dev] Make sure Android emulator is running: flutter run -d <emulator_id>"
    cd client-mobile && flutter run -d emulator-5554

# List available Flutter devices
dev-devices:
    @echo "[dev] Available Flutter devices:"
    flutter devices

# =============================================================================
# Client Data Management
# =============================================================================

# Clear all client data (E2EE sessions, keys) - interactive mode
clear-client-data:
    @echo "[client] Clearing client data (E2EE sessions, keys)..."
    bash client-mobile/scripts/clear-client-data.sh

# Force clear all client data without confirmation
clear-client-data-force:
    @echo "[client] Force clearing all client data..."
    bash client-mobile/scripts/clear-client-data.sh --force

# =============================================================================
# Docker Compose Local Development (Recommended for beginners)
# =============================================================================
# Fast local development with hot-reload. No k8s required!
# Start: just dc-up   |  Stop: just dc-down   |  Logs: just dc-logs

COMPOSE := "docker compose -f docker-compose.dev.yml"

# Start all services (data layer + backend + envoy)
dc-up:
    @echo "[docker] Starting all services (~30 seconds)..."
    {{COMPOSE}} up -d
    @echo ""
    @echo "✅ Services starting. Check status: just dc-ps"
    @echo "📊 Redpanda Console: http://localhost:8088"
    @echo "🪣 MinIO Console: http://localhost:9001 (guardyn/guardyn-dev-secret)"
    @echo "🔌 Envoy (API Gateway): http://localhost:8080"

# Start only data layer (TiKV, ScyllaDB, Redpanda, MinIO)
dc-up-data:
    @echo "[docker] Starting data layer only..."
    {{COMPOSE}} up -d pd tikv scylladb redpanda minio minio-init
    @echo "✅ Data layer started. Wait for health checks: just dc-ps"

# Start specific service(s)
dc-up-service +services:
    @echo "[docker] Starting: {{services}}..."
    {{COMPOSE}} up -d {{services}}

# Stop all services (keep volumes)
dc-down:
    @echo "[docker] Stopping all services..."
    {{COMPOSE}} down

# Stop all services and DELETE volumes (reset all data)
dc-reset:
    @echo "[docker] ⚠️  Stopping and removing ALL data..."
    {{COMPOSE}} down -v
    @echo "✅ All containers and volumes removed"

# Show running containers
dc-ps:
    {{COMPOSE}} ps

# Show container status with health
dc-status:
    @echo "[docker] Container status:"
    {{COMPOSE}} ps --format "table {{{{.Name}}}}\t{{{{.Status}}}}\t{{{{.Ports}}}}"

# Follow logs for all services
dc-logs:
    {{COMPOSE}} logs -f

# Follow logs for specific service
dc-log service:
    {{COMPOSE}} logs -f {{service}}

# Rebuild and restart a specific service
dc-rebuild service:
    @echo "[docker] Rebuilding {{service}}..."
    {{COMPOSE}} up -d --build {{service}}

# Rebuild all backend services
dc-rebuild-all:
    @echo "[docker] Rebuilding all backend services..."
    {{COMPOSE}} up -d --build auth-service messaging-service presence-service media-service notification-service

# Rebuild a specific service without cache (clean build)
dc-rebuild-clean service:
    @echo "[docker] Rebuilding {{service}} (no cache)..."
    {{COMPOSE}} build --no-cache {{service}}
    {{COMPOSE}} up -d {{service}}

# Rebuild all backend services without cache (clean build)
dc-rebuild-all-clean:
    @echo "[docker] Rebuilding all backend services (no cache)..."
    {{COMPOSE}} build --no-cache auth-service messaging-service presence-service media-service notification-service
    {{COMPOSE}} up -d auth-service messaging-service presence-service media-service notification-service

# Restart a specific service
dc-restart service:
    {{COMPOSE}} restart {{service}}

# Execute command in a running container
dc-exec service +cmd:
    {{COMPOSE}} exec {{service}} {{cmd}}

# Open shell in a running container
dc-shell service:
    {{COMPOSE}} exec {{service}} /bin/sh

# Check ScyllaDB status
dc-scylla-status:
    {{COMPOSE}} exec scylladb nodetool status

# Open CQL shell to ScyllaDB
dc-cqlsh:
    {{COMPOSE}} exec scylladb cqlsh

# Check TiKV cluster status
dc-tikv-status:
    {{COMPOSE}} exec pd /pd-ctl store

# Check Redpanda cluster health
dc-redpanda-health:
    {{COMPOSE}} exec redpanda rpk cluster health

# List Redpanda topics
dc-redpanda-topics:
    {{COMPOSE}} exec redpanda rpk topic list

# Show resource usage
dc-stats:
    docker stats --no-stream $({{COMPOSE}} ps -q)

# Clean up unused Docker resources
dc-prune:
    @echo "[docker] Cleaning unused resources..."
    docker system prune -f
    @echo "✅ Cleanup complete"

# Pull latest images
dc-pull:
    @echo "[docker] Pulling latest images..."
    {{COMPOSE}} pull

# =============================================================================
# Rust FFI Commands (Native Crypto Library)
# =============================================================================

# Build crypto-ffi for all platforms
ffi-build-all:
    @echo "[ffi] Building crypto-ffi for all platforms..."
    cd backend/crates/crypto-ffi && ./build-mobile.sh all

# Build crypto-ffi for Android
ffi-build-android:
    @echo "[ffi] Building crypto-ffi for Android..."
    cd backend/crates/crypto-ffi && ./build-mobile.sh android

# Build crypto-ffi for iOS (macOS only)
ffi-build-ios:
    @echo "[ffi] Building crypto-ffi for iOS..."
    cd backend/crates/crypto-ffi && ./build-mobile.sh ios

# Build crypto-ffi for desktop (current platform)
ffi-build-desktop:
    @echo "[ffi] Building crypto-ffi for desktop..."
    cd backend/crates/crypto-ffi && ./build-mobile.sh desktop

# Generate Dart bindings with flutter_rust_bridge
ffi-generate:
    @echo "[ffi] Generating Dart bindings..."
    cd backend/crates/crypto-ffi && ./build-mobile.sh generate

# Test crypto-ffi crate
ffi-test:
    @echo "[ffi] Testing crypto-ffi..."
    cd backend && cargo test -p guardyn-crypto-ffi --features full

# Check crypto-ffi compiles
ffi-check:
    @echo "[ffi] Checking crypto-ffi..."
    cd backend && cargo check -p guardyn-crypto-ffi --features full

# Run FFI integration tests on Android device
ffi-test-android:
    @echo "[ffi] Running integration tests on Android..."
    client-mobile/scripts/run-mobile-ffi-tests.sh android

# Run FFI integration tests on iOS device (macOS only)
ffi-test-ios:
    @echo "[ffi] Running integration tests on iOS..."
    client-mobile/scripts/run-mobile-ffi-tests.sh ios

# Run FFI integration tests on all connected mobile devices
ffi-test-mobile:
    @echo "[ffi] Running integration tests on all mobile devices..."
    client-mobile/scripts/run-mobile-ffi-tests.sh all

# List available devices for FFI testing
ffi-devices:
    @echo "[ffi] Available devices:"
    client-mobile/scripts/run-mobile-ffi-tests.sh list

# Run two-client E2EE messaging test (Android + Tauri Desktop)
test-two-client-messaging:
    @echo "[test] Running two-client E2EE messaging test..."
    client-mobile/scripts/run-two-client-messaging.sh

# =============================================================================
# Authentication Tests
# =============================================================================

# Run auth integration tests on Android (registration + login flow)
test-auth-android:
    @echo "[test] Running auth integration tests on Android..."
    client-mobile/scripts/run-auth-test-android.sh

# Run auth tests - full flow only
test-auth-android-full:
    @echo "[test] Running full auth flow test on Android..."
    client-mobile/scripts/run-auth-test-android.sh --full

# Run auth tests - validation only
test-auth-android-validation:
    @echo "[test] Running auth validation tests on Android..."
    client-mobile/scripts/run-auth-test-android.sh --validation

# =============================================================================
# Mobile Client Tests
# =============================================================================

# Run the mobile checks exactly as .github/workflows/mobile.yml runs them
test-mobile:
    @echo "[test] Running mobile analyze and tests..."
    cd client-mobile && flutter analyze --no-fatal-infos
    cd client-mobile && flutter test

# =============================================================================
# Desktop Client Tests
# =============================================================================

# Run Desktop unit tests (Vitest)
test-desktop-unit:
    @echo "[test] Running Desktop unit tests..."
    cd client-desktop && npm run test

# Run Desktop auth unit tests only
test-desktop-auth-unit:
    @echo "[test] Running Desktop auth unit tests..."
    cd client-desktop && npm run test -- src/components/auth/ src/pages/Login.test.tsx src/pages/Register.test.tsx

# Run Desktop E2E tests (Playwright - auto-starts dev server, requires backend)
test-desktop-e2e:
    @echo "[test] Running Desktop E2E tests..."
    @echo "[test] Make sure backend is running: just dc-up"
    client-desktop/scripts/run-auth-tests.sh

# Run Desktop E2E auth tests in headed mode (visible browser)
test-desktop-e2e-headed:
    @echo "[test] Running Desktop E2E tests (headed mode)..."
    @echo "[test] Make sure backend is running: just dc-up"
    client-desktop/scripts/run-auth-tests.sh --headed

# Run Desktop E2E tests with interactive UI
test-desktop-e2e-ui:
    @echo "[test] Running Desktop E2E tests with Playwright UI..."
    @echo "[test] Make sure backend is running: just dc-up"
    client-desktop/scripts/run-auth-tests.sh --ui

# Run all Desktop tests (unit + E2E)
test-desktop-all:
    @echo "[test] Running all Desktop tests..."
    @echo "==> Unit tests"
    cd client-desktop && npm run test
    @echo ""
    @echo "==> E2E tests"
    client-desktop/scripts/run-auth-tests.sh

# Install the repository git hooks (protected-branch guard). Run once per clone.
install-hooks:
    @git config core.hooksPath .githooks
    @echo "[hooks] core.hooksPath -> .githooks"

# Verify the documentation base: frontmatter, impact, glossary, links, language, staleness.
docs-verify:
    @bash infra/scripts/docs-verify.sh

# docs-verify check 6 fails when the committed file differs from this output.
# Regenerate docs/roadmap/STATE.md from docs/roadmap/roadmap.yaml.
docs-state:
    @bash infra/scripts/docs-state.sh --write

# Reconcile docs/roadmap/roadmap.yaml into GitHub Issues and the Project board.
# Dry by default; pass 0 to write. Requires GUARDYN_PROJECT_TOKEN for the board half.
roadmap-sync dry="1":
    @ROADMAP_SYNC_DRY_RUN={{dry}} bash infra/scripts/roadmap-sync.sh

# Verify the code-style predicates of .claude/rules/20-code-style.md.
rules-verify:
    @bash infra/scripts/rules-verify.sh

# Fuzz one parser. Targets: padme_unpad, ratchet_message, sealed_sender_envelope,
# x3dh_prekey_message, pqxdh_decapsulate. Runs until interrupted unless `secs` is given.
#
# The nightly is pinned, not floating: cargo-fuzz needs -Z sanitizer=address,
# which stable does not have, and a bare `nightly` reintroduces exactly the
# drift rust-toolchain.toml exists to prevent.
fuzz target secs="60":
    cd backend/crates/crypto && \
      cargo +{{FUZZ_TOOLCHAIN}} fuzz run {{target}} -- -max_total_time={{secs}}

# Build every fuzz target without running one - the cheap check that a parser
# signature has not drifted out from under its harness.
fuzz-build:
    cd backend/crates/crypto && cargo +{{FUZZ_TOOLCHAIN}} fuzz build

# Benchmark the crypto primitives. Pass a criterion filter to run one group,
# e.g. `just bench PQXDH`; with no argument every group runs.
#
# The agreement benches are the point: the classical and hybrid arms go through
# the same two functions, so the difference between them is the ML-KEM price and
# not two unrelated numbers. Needs the `pq` feature, which is on by default.
#
# No CI job runs these. build.yml already compiles the bench target through
# `cargo clippy --all-targets`, which is the drift check fuzz-build had to exist
# for; timings on a shared runner vary by more than the effect being measured.
bench filter="":
    cd backend/crates/crypto && cargo bench -- {{filter}}