feat(routing): add route acceptance matrix scripts
This commit is contained in:
@@ -660,6 +660,258 @@ EOF
|
||||
[[ -f "$sensitive_root/20260522_foo/05-subscription-access-prep.sql" ]] || fail "sql file was not moved to sensitive mirror"
|
||||
}
|
||||
|
||||
run_test_verify_route_control_plane_script() {
|
||||
local tmpdir fakebin artifact_dir stdout_file
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' RETURN
|
||||
fakebin="$tmpdir/bin"
|
||||
artifact_dir="$tmpdir/artifacts"
|
||||
stdout_file="$tmpdir/verify_route_control_plane.stdout.txt"
|
||||
mkdir -p "$fakebin" "$artifact_dir"
|
||||
|
||||
cat > "$fakebin/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
method="GET"
|
||||
url=""
|
||||
payload=""
|
||||
prev=""
|
||||
for arg in "$@"; do
|
||||
case "$prev" in
|
||||
-X) method="$arg"; prev=""; continue ;;
|
||||
-d|--data) payload="$arg"; prev=""; continue ;;
|
||||
esac
|
||||
case "$arg" in
|
||||
-X|-d|--data) prev="$arg"; continue ;;
|
||||
http://*|https://*) url="$arg" ;;
|
||||
esac
|
||||
done
|
||||
case "$method $url" in
|
||||
"POST http://crm.example.com/api/logical-groups")
|
||||
printf '%s\n' '{"logical_group":{"logical_group_id":"p2t4-cp-1700000000","display_name":"P2T4 Control Plane p2t4-cp-1700000000","status":"active"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-cp-1700000000/models")
|
||||
printf '%s\n' '{"logical_group_model":{"public_model":"gpt-5.4","status":"active"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-cp-1700000000/routes")
|
||||
printf '%s\n' '{"logical_group_route":{"route_id":"primary-1700000000","logical_group_id":"p2t4-cp-1700000000","name":"Primary primary-1700000000","status":"active","priority":10,"weight":100,"shadow_group_id":"shadow-group-1700000000","shadow_host_id":"shadow-host-1700000000"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-cp-1700000000/routes/primary-1700000000/models")
|
||||
printf '%s\n' '{"logical_group_route_model":{"public_model":"gpt-5.4","shadow_model":"gpt-5.4","status":"active"}}'
|
||||
;;
|
||||
"GET http://crm.example.com/api/logical-groups/p2t4-cp-1700000000")
|
||||
printf '%s\n' '{"logical_group":{"logical_group_id":"p2t4-cp-1700000000","display_name":"P2T4 Control Plane p2t4-cp-1700000000","status":"active","models":[{"public_model":"gpt-5.4"}],"routes":[{"route_id":"primary-1700000000"}]}}'
|
||||
;;
|
||||
"PUT http://crm.example.com/api/logical-groups/p2t4-cp-1700000000")
|
||||
printf '%s\n' '{"logical_group":{"logical_group_id":"p2t4-cp-1700000000","display_name":"P2T4 Control Plane Updated p2t4-cp-1700000000","status":"active"}}'
|
||||
;;
|
||||
"PUT http://crm.example.com/api/logical-groups/p2t4-cp-1700000000/routes/primary-1700000000")
|
||||
printf '%s\n' '{"logical_group_route":{"route_id":"primary-1700000000","logical_group_id":"p2t4-cp-1700000000","name":"Primary Route Updated","status":"active","priority":12,"weight":80,"shadow_group_id":"shadow-group-1700000000","shadow_host_id":"shadow-host-1700000000"}}'
|
||||
;;
|
||||
"GET http://crm.example.com/api/logical-groups/p2t4-cp-1700000000/routes")
|
||||
printf '%s\n' '{"routes":[{"route_id":"primary-1700000000","weight":80}]}'
|
||||
;;
|
||||
"GET http://crm.example.com/api/logical-groups/p2t4-cp-1700000000/routes/primary-1700000000/models")
|
||||
printf '%s\n' '{"models":[{"public_model":"gpt-5.4","shadow_model":"gpt-5.4","status":"active"}]}'
|
||||
;;
|
||||
*)
|
||||
echo "unexpected curl request: $method $url payload=$payload" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$fakebin/curl"
|
||||
|
||||
PATH="$fakebin:$PATH" \
|
||||
CRM_BASE="http://crm.example.com" \
|
||||
CRM_ADMIN_TOKEN="token" \
|
||||
TS="1700000000" \
|
||||
ARTIFACT_DIR="$artifact_dir" \
|
||||
bash "$ROOT_DIR/scripts/acceptance/verify_route_control_plane.sh" >"$stdout_file"
|
||||
|
||||
local summary stdout_text
|
||||
summary="$(cat "$artifact_dir/10-summary.json")"
|
||||
stdout_text="$(cat "$stdout_file")"
|
||||
assert_contains "$summary" '"group_id": "p2t4-cp-1700000000"'
|
||||
assert_contains "$summary" '"route_id": "primary-1700000000"'
|
||||
assert_contains "$summary" '"route_updated": true'
|
||||
assert_contains "$stdout_text" '"route_model_listed": true'
|
||||
}
|
||||
|
||||
run_test_verify_route_data_plane_script() {
|
||||
local tmpdir fakebin artifact_dir stdout_file payload_log
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' RETURN
|
||||
fakebin="$tmpdir/bin"
|
||||
artifact_dir="$tmpdir/artifacts"
|
||||
stdout_file="$tmpdir/verify_route_data_plane.stdout.txt"
|
||||
payload_log="$tmpdir/payload.log"
|
||||
mkdir -p "$fakebin" "$artifact_dir"
|
||||
|
||||
cat > "$fakebin/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
method="GET"
|
||||
url=""
|
||||
payload=""
|
||||
prev=""
|
||||
for arg in "$@"; do
|
||||
case "$prev" in
|
||||
-X) method="$arg"; prev=""; continue ;;
|
||||
-d|--data) payload="$arg"; prev=""; continue ;;
|
||||
esac
|
||||
case "$arg" in
|
||||
-X|-d|--data) prev="$arg"; continue ;;
|
||||
http://*|https://*) url="$arg" ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$payload" >> "${PAYLOAD_LOG:?missing PAYLOAD_LOG}"
|
||||
case "$method $url" in
|
||||
"POST http://crm.example.com/api/logical-groups")
|
||||
printf '%s\n' '{"logical_group":{"logical_group_id":"p2t4-dp-1700000001","display_name":"P2T4 Data Plane p2t4-dp-1700000001","status":"active"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-dp-1700000001/models")
|
||||
printf '%s\n' '{"logical_group_model":{"public_model":"gpt-5.4","status":"active"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-dp-1700000001/routes")
|
||||
printf '%s\n' '{"logical_group_route":{"route_id":"primary-1700000001","shadow_group_id":"shadow-group-9","shadow_host_id":"shadow-host-real"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-dp-1700000001/routes/primary-1700000001/models")
|
||||
printf '%s\n' '{"logical_group_route_model":{"public_model":"gpt-5.4","shadow_model":"gpt-5.4"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/routing/chat/completions")
|
||||
printf '%s\n' '{"request_id":"req-p2t4-dp-1700000001","logical_group_id":"p2t4-dp-1700000001","model":"gpt-5.4","selected_route":{"route_id":"primary-1700000001","shadow_host_id":"shadow-host-real","shadow_group_id":"shadow-group-9","shadow_model":"gpt-5.4"},"forward":{"upstream_status":200,"effective_gateway_key_source":"managed_subscription"}}'
|
||||
;;
|
||||
"GET http://crm.example.com/api/routing/logs/decisions?request_id=req-p2t4-dp-1700000001&limit=5")
|
||||
printf '%s\n' '{"decision_logs":[{"request_id":"req-p2t4-dp-1700000001","selected_route_id":"primary-1700000001"}]}'
|
||||
;;
|
||||
*)
|
||||
echo "unexpected curl request: $method $url payload=$payload" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$fakebin/curl"
|
||||
|
||||
PATH="$fakebin:$PATH" \
|
||||
PAYLOAD_LOG="$payload_log" \
|
||||
CRM_BASE="http://crm.example.com" \
|
||||
CRM_ADMIN_TOKEN="token" \
|
||||
TS="1700000001" \
|
||||
SHADOW_HOST_ID="shadow-host-real" \
|
||||
SHADOW_GROUP_ID="shadow-group-9" \
|
||||
SUBSCRIPTION_USER_ID="36" \
|
||||
ARTIFACT_DIR="$artifact_dir" \
|
||||
bash "$ROOT_DIR/scripts/acceptance/verify_route_data_plane.sh" >"$stdout_file"
|
||||
|
||||
local summary payloads
|
||||
summary="$(cat "$artifact_dir/07-summary.json")"
|
||||
payloads="$(cat "$payload_log")"
|
||||
assert_contains "$summary" '"forward_upstream_status": 200'
|
||||
assert_contains "$summary" '"effective_gateway_key_source": "managed_subscription"'
|
||||
assert_contains "$payloads" '"subscription_user_id": "36"'
|
||||
}
|
||||
|
||||
run_test_verify_route_health_ui_script() {
|
||||
local tmpdir fakebin artifact_dir stdout_file
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' RETURN
|
||||
fakebin="$tmpdir/bin"
|
||||
artifact_dir="$tmpdir/artifacts"
|
||||
stdout_file="$tmpdir/verify_route_health_ui.stdout.txt"
|
||||
mkdir -p "$fakebin" "$artifact_dir"
|
||||
|
||||
cat > "$fakebin/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
method="GET"
|
||||
url=""
|
||||
payload=""
|
||||
output_file=""
|
||||
prev=""
|
||||
for arg in "$@"; do
|
||||
case "$prev" in
|
||||
-X) method="$arg"; prev=""; continue ;;
|
||||
-d|--data) payload="$arg"; prev=""; continue ;;
|
||||
-o) output_file="$arg"; prev=""; continue ;;
|
||||
esac
|
||||
case "$arg" in
|
||||
-X|-d|--data|-o) prev="$arg"; continue ;;
|
||||
http://*|https://*) url="$arg" ;;
|
||||
esac
|
||||
done
|
||||
write_body() {
|
||||
local body="$1"
|
||||
if [[ -n "$output_file" ]]; then
|
||||
printf '%s\n' "$body" > "$output_file"
|
||||
else
|
||||
printf '%s\n' "$body"
|
||||
fi
|
||||
}
|
||||
case "$method $url" in
|
||||
"GET http://portal.example.com/route-health.html")
|
||||
write_body '<html><title>Route Health Admin</title><body>Route Health Admin</body></html>'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups")
|
||||
write_body '{"logical_group":{"logical_group_id":"p2t4-health-1700000002","status":"active"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-health-1700000002/models")
|
||||
write_body '{"logical_group_model":{"public_model":"gpt-5.4","status":"active"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-health-1700000002/routes")
|
||||
if [[ "$payload" == *'"route_id":"primary-1700000002"'* ]]; then
|
||||
write_body '{"logical_group_route":{"route_id":"primary-1700000002"}}'
|
||||
elif [[ "$payload" == *'"route_id":"fallback-1700000002"'* ]]; then
|
||||
write_body '{"logical_group_route":{"route_id":"fallback-1700000002"}}'
|
||||
else
|
||||
write_body '{"logical_group_route":{"route_id":"failing-1700000002"}}'
|
||||
fi
|
||||
;;
|
||||
"POST http://crm.example.com/api/logical-groups/p2t4-health-1700000002/routes/primary-1700000002/models"|"POST http://crm.example.com/api/logical-groups/p2t4-health-1700000002/routes/fallback-1700000002/models"|"POST http://crm.example.com/api/logical-groups/p2t4-health-1700000002/routes/failing-1700000002/models")
|
||||
write_body '{"logical_group_route_model":{"public_model":"gpt-5.4","shadow_model":"gpt-5.4"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/routing/sticky/cooldowns")
|
||||
write_body '{"route_cooldown":{"route_id":"primary-1700000002","reason":"degraded"}}'
|
||||
;;
|
||||
"POST http://crm.example.com/api/routing/sticky/route-failures")
|
||||
write_body '{"route_failure":{"route_id":"failing-1700000002","failure_count":2,"last_error_class":"timeout"}}'
|
||||
;;
|
||||
"GET http://crm.example.com/api/routing/routes/health?logical_group_id=p2t4-health-1700000002")
|
||||
if [[ ! -f /tmp/p2t4-health-switch ]]; then
|
||||
write_body '{"route_health":[{"route_id":"primary-1700000002","runtime_status":"cooldown"},{"route_id":"fallback-1700000002","runtime_status":"healthy","recent_failover_count":0},{"route_id":"failing-1700000002","runtime_status":"failing"}]}'
|
||||
else
|
||||
write_body '{"route_health":[{"route_id":"primary-1700000002","runtime_status":"cooldown"},{"route_id":"fallback-1700000002","runtime_status":"healthy","recent_failover_count":1,"last_selected_at":"2026-05-29T12:00:00Z"},{"route_id":"failing-1700000002","runtime_status":"failing"}]}'
|
||||
fi
|
||||
;;
|
||||
"POST http://crm.example.com/api/routing/resolve")
|
||||
: > /tmp/p2t4-health-switch
|
||||
write_body '{"resolve":{"request_id":"req-p2t4-health-1700000002","route_id":"fallback-1700000002","fallback_used":true}}'
|
||||
;;
|
||||
"GET http://crm.example.com/api/routing/logs/failovers?request_id=req-p2t4-health-1700000002&limit=5")
|
||||
write_body '{"failover_events":[{"from_route_id":"primary-1700000002","to_route_id":"fallback-1700000002","reason":"active_cooldown:degraded"}]}'
|
||||
;;
|
||||
*)
|
||||
echo "unexpected curl request: $method $url payload=$payload" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$fakebin/curl"
|
||||
|
||||
PATH="$fakebin:$PATH" \
|
||||
CRM_BASE="http://crm.example.com" \
|
||||
CRM_ADMIN_TOKEN="token" \
|
||||
ROUTE_HEALTH_PAGE_URL="http://portal.example.com/route-health.html" \
|
||||
TS="1700000002" \
|
||||
ARTIFACT_DIR="$artifact_dir" \
|
||||
bash "$ROOT_DIR/scripts/acceptance/verify_route_health_ui.sh" >"$stdout_file"
|
||||
|
||||
local summary
|
||||
summary="$(cat "$artifact_dir/12-summary.json")"
|
||||
assert_contains "$summary" '"resolve_route_id": "fallback-1700000002"'
|
||||
assert_contains "$summary" '"fallback_recent_failover_count": 1'
|
||||
}
|
||||
|
||||
run_test_remote43_patched_stack_renderers() {
|
||||
# shellcheck disable=SC1091
|
||||
source "$ROOT_DIR/scripts/deploy/remote43_patched_stack_lib.sh"
|
||||
@@ -784,6 +1036,9 @@ run_test_real_host_acceptance_after_import_hook
|
||||
run_test_check_deepseek_completion_split
|
||||
run_test_import_remote43_provider_subscription_prep
|
||||
run_test_migrate_historical_artifacts
|
||||
run_test_verify_route_control_plane_script
|
||||
run_test_verify_route_data_plane_script
|
||||
run_test_verify_route_health_ui_script
|
||||
run_test_remote43_patched_stack_renderers
|
||||
run_test_setup_remote43_patched_stack_dry_run
|
||||
|
||||
|
||||
Reference in New Issue
Block a user