#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" PYTHONPATH=router python3 -m py_compile \ router/agent_hier.py router/router.py router/agent_stream.py \ router/path_resolve.py router/hierarchical.py router/progress_ui.py \ router/runtime_probe.py PYTHONPATH=router python3 -m unittest discover -s test/unit -q scp router/agent_hier.py router/router.py router/agent_stream.py \ router/path_resolve.py router/hierarchical.py router/progress_ui.py \ router/runtime_probe.py \ eventhub-ift:/opt/ai-router-stack/router/ scp config/orchestration.yaml eventhub-ift:/opt/ai-router-stack/config/ ssh -o BatchMode=yes eventhub-ift bash -s <<'REMOTE' set -euo pipefail cd /opt/ai-router-stack set -a; source .env; set +a sed -i 's/\r$//' router/*.py config/orchestration.yaml || true docker build -f router/Dockerfile -t "${ROUTER_IMAGE:-git.sabilin.com/eventhub/ai-router-gateway:ift}" . TS=$(date +%Y%m%d%H%M%S) ORCH="orchestration_config_${TS}" docker config create "$ORCH" ./config/orchestration.yaml OLD_ORCH=$(docker service inspect ai-router_router --format '{{range .Spec.TaskTemplate.ContainerSpec.Configs}}{{println .ConfigName}}{{end}}' | grep orchestration | tail -1 || true) RARGS=(--image "${ROUTER_IMAGE:-git.sabilin.com/eventhub/ai-router-gateway:ift}" --force) RARGS+=(--config-add "source=${ORCH},target=/app/config/orchestration.yaml") [[ -n "${OLD_ORCH:-}" ]] && RARGS+=(--config-rm "$OLD_ORCH") docker service update "${RARGS[@]}" ai-router_router >/dev/null for i in $(seq 1 40); do curl -sf --max-time 5 https://ai-router.ift.calentiq.com/health >/dev/null && break sleep 2 done docker exec "$(docker ps -q -f name=ai-router_router | head -1)" \ grep -E 'runtime_probe_enabled|path_resolve_enabled' /app/config/orchestration.yaml test -f /opt/ai-router-stack/router/runtime_probe.py echo RUNTIME_PROBE_OK REMOTE