- chg_0001_dth_scaffold (skip_coverage): openspec framework + NestJS+React+PGlite scaffold - chg_0002_sp1_experiment_platform_mvp: 6 scenarios S1-S6 + 21 perm-smoke + 16 e2e + 3 demo operators (hello-mpc/pir/vertical-lr) Sandbox task exit 0. Independent verification: check_spec_coverage.sh gap=0 PASS. Co-Authored-By: Claude Opus 4.8 <[email protected]>
111 lines
5.1 KiB
Bash
Executable File
111 lines
5.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# dth_experiment.test.sh — e2e verification for S1..S6 of chg_0002.
|
|
# Exit 0 only if all 6 scenarios pass. Each assertion is a hard-fail.
|
|
#
|
|
# Usage:
|
|
# DTH_BASE=http://127.0.0.1:30000 bash tests/e2e/dth_experiment.test.sh
|
|
#
|
|
# Pre-req: backend is running and admin seed is loaded (run.sh dev).
|
|
|
|
set -uo pipefail
|
|
|
|
BASE="${DTH_BASE:-http://127.0.0.1:${PORT:-30000}}"
|
|
LOGIN_URL="$BASE/api/ssw/dth/auth/login"
|
|
OPS_URL="$BASE/api/ssw/dth/experiment/operators"
|
|
RUNS_URL="$BASE/api/ssw/dth/experiment/runs"
|
|
|
|
pass=0; fail=0; fails=()
|
|
|
|
json_get() { # extract "code":N or "field":"val" by jq-less sed
|
|
local field="$1"; local body="$2"
|
|
python3 -c "import json,sys; d=json.loads(sys.argv[1]); print(d${field})" "$body" 2>/dev/null
|
|
}
|
|
|
|
login() {
|
|
curl -s -X POST "$LOGIN_URL" -H 'Content-Type: application/json' -d "{\"username\":\"$1\",\"password\":\"$2\"}"
|
|
}
|
|
|
|
assert() {
|
|
local id="$1"; local cond="$2"; local detail="$3"
|
|
if eval "$cond"; then
|
|
pass=$((pass+1))
|
|
printf " ✓ %s\n" "$id"
|
|
else
|
|
fail=$((fail+1))
|
|
fails+=("$id: $detail")
|
|
printf " ✗ %s — %s\n" "$id" "$detail"
|
|
fi
|
|
}
|
|
|
|
# ----- pre: login admin + non-admin -----
|
|
ADMIN_BODY="$(login admin 123456)"
|
|
USER_BODY="$(login test-user user-pass)"
|
|
ADMIN_TOKEN="$(json_get "['data']['token']" "$ADMIN_BODY")"
|
|
USER_TOKEN="$(json_get "['data']['token']" "$USER_BODY")"
|
|
|
|
assert "pre_admin_login" "[ -n '$ADMIN_TOKEN' ]" "admin token empty; login body=$ADMIN_BODY"
|
|
assert "pre_user_login" "[ -n '$USER_TOKEN' ]" "user token empty; login body=$USER_BODY"
|
|
|
|
# ----- S1: list ≥3 operators -----
|
|
LIST_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" "$OPS_URL")"
|
|
LIST_LEN="$(json_get "['data'].__len__()" "$LIST_BODY" 2>/dev/null || python3 -c "import json,sys; d=json.loads(sys.argv[1]); print(len(d['data']))" "$LIST_BODY")"
|
|
FIRST_CODE="$(json_get "['data'][0]['code']" "$LIST_BODY")"
|
|
HAS_SCHEMA="$(python3 -c "import json,sys; d=json.loads(sys.argv[1]); print(all('schema' in o for o in d['data']))" "$LIST_BODY")"
|
|
assert "S1_three_operators" "[ '$LIST_LEN' -ge 3 ]" "got $LIST_LEN"
|
|
assert "S1_has_code" "[ '$FIRST_CODE' = 'hello-mpc' ]" "first.code=$FIRST_CODE"
|
|
assert "S1_has_schema" "[ '$HAS_SCHEMA' = 'True' ]" "missing schema field"
|
|
|
|
# ----- S2: POST /runs returns UUID + status success -----
|
|
RUN_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
|
-d '{"operator":"hello-mpc","input":{"x":42}}' "$RUNS_URL")"
|
|
RUN_ID="$(json_get "['data']['run_id']" "$RUN_BODY")"
|
|
RUN_STATUS="$(json_get "['data']['status']" "$RUN_BODY")"
|
|
assert "S2_run_id_uuid" "echo '$RUN_ID' | grep -Eq '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'" "run_id=$RUN_ID"
|
|
assert "S2_status_success" "[ '$RUN_STATUS' = 'success' ]" "status=$RUN_STATUS"
|
|
|
|
# ----- S3: GET /runs/:id returns real output_json -----
|
|
GET_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" "$RUNS_URL/$RUN_ID")"
|
|
OUTPUT_OK="$(json_get "['data']['output_json']['ok']" "$GET_BODY")"
|
|
OUTPUT_ECHO="$(json_get "['data']['output_json']['echo']['x']" "$GET_BODY")"
|
|
OUTPUT_MPC_PROTO="$(json_get "['data']['output_json']['mpc']['protocol']" "$GET_BODY")"
|
|
assert "S3_output_ok_true" "[ '$OUTPUT_OK' = 'True' ]" "output_json.ok=$OUTPUT_OK"
|
|
assert "S3_echo_x_42" "[ '$OUTPUT_ECHO' = '42' ]" "echo.x=$OUTPUT_ECHO"
|
|
assert "S3_mpc_protocol" "[ -n '$OUTPUT_MPC_PROTO' ]" "mpc.protocol empty"
|
|
|
|
# ----- S4: no token returns code=600 -----
|
|
NO_AUTH_BODY="$(curl -s "$OPS_URL")"
|
|
NO_AUTH_CODE="$(json_get "['code']" "$NO_AUTH_BODY")"
|
|
assert "S4_no_token_600" "[ '$NO_AUTH_CODE' = '600' ]" "code=$NO_AUTH_CODE"
|
|
|
|
# ----- S5: unknown operator returns code=400 -----
|
|
BAD_OP_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
|
-d '{"operator":"does-not-exist"}' "$RUNS_URL")"
|
|
BAD_OP_CODE="$(json_get "['code']" "$BAD_OP_BODY")"
|
|
BAD_OP_MSG="$(json_get "['msg']" "$BAD_OP_BODY")"
|
|
assert "S5_unknown_op_400" "[ '$BAD_OP_CODE' = '400' ]" "code=$BAD_OP_CODE"
|
|
assert "S5_msg_unknown" "echo '$BAD_OP_MSG' | grep -q 'unknown operator'" "msg=$BAD_OP_MSG"
|
|
|
|
# ----- S6: non-admin gets code=403 -----
|
|
USER_BODY_LIST="$(curl -s -H "Authorization: Bearer $USER_TOKEN" "$OPS_URL")"
|
|
USER_CODE="$(json_get "['code']" "$USER_BODY_LIST")"
|
|
assert "S6_user_403" "[ '$USER_CODE' = '403' ]" "code=$USER_CODE"
|
|
|
|
# ----- extra: real compute via pir + vertical-lr -----
|
|
PIR_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
|
-d '{"operator":"pir","input":{"keyword":"alice"}}' "$RUNS_URL")"
|
|
PIR_OK="$(json_get "['data']['status']" "$PIR_BODY")"
|
|
assert "extra_pir_success" "[ '$PIR_OK' = 'success' ]" "pir status=$PIR_OK"
|
|
|
|
LR_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
|
-d '{"operator":"vertical-lr","input":{"features":[[1.0,0.5],[0.3,0.8],[0.7,0.2]],"labels":[1,0,1]}}' "$RUNS_URL")"
|
|
LR_OK="$(json_get "['data']['status']" "$LR_BODY")"
|
|
assert "extra_vert_lr_success" "[ '$LR_OK' = 'success' ]" "lr status=$LR_OK"
|
|
|
|
echo "---"
|
|
echo "e2e dth_experiment: pass=$pass fail=$fail"
|
|
if [ $fail -gt 0 ]; then
|
|
printf 'FAILED:\n'; printf ' - %s\n' "${fails[@]}"
|
|
exit 1
|
|
fi
|
|
exit 0
|