#!/usr/bin/env bash # dth_lms_v2.test.sh — e2e verification for S1..S10 of chg_0012 (LMS v2). # # 10 cases: # C1 LMS v1 数据模型基础 (GET /students + /courses v1 schema intact) # C2 多场景数据模型 v2 (lms_course_scene table + scene_type enum) # C3 创建多场景课程 (admin POST 1 含 2 scene 的课程 + FRC 模板 6 scene) # C4 选课 + 进度 append-only (重复 complete 不增 count) # C5 SlideScene Markdown 渲染 (h1/h2/p/ul/li/code 5 节点 + 非法节点原样保留) # C6 QuizScene 判分 (选择: 答对 + score=1.0; 简答: 关键词 50% 命中 = 满分) # C7 SimScene iframe (embed_url 校验 + 非法 URL 400) # C8 FRC 6-scene 模板 (6 scene 全部 simulation + order_index 1-6) # C9 E2E 完整流程 (admin login → from-frc-template → student login → enroll → 6 render + 6 complete → progress_pct = 1.0) # C10 PBL 占位一致性 (type=pbl → 501 + 前端 PBLScene 文案一致) # # Exit 0 only if all 10 scenarios pass. Each assertion is a hard-fail. # # Usage: # DTH_BASE=http://127.0.0.1:30051 bash tests/e2e/dth_lms_v2.test.sh # # Pre-req: backend running on DTH_BASE, admin seed loaded (run.sh dev). # Reuses helpers (json_get / assert / login) from chg_0006/0010/0011 e2e scripts. set -uo pipefail BASE="${DTH_BASE:-http://127.0.0.1:${PORT:-30051}}" LOGIN_URL="$BASE/api/ssw/dth/auth/login" STUDENTS_URL="$BASE/api/ssw/dth/lms/students" COURSES_URL="$BASE/api/ssw/dth/lms/courses" LMS_V2_COURSES_URL="$BASE/api/ssw/dth/lms-v2/courses" LMS_V2_FRC_URL="$BASE/api/ssw/dth/lms-v2/courses/from-frc-template" pass=0; fail=0; fails=() # ----- Helpers (mirror chg_0006/0010/0011) ----- json_get() { 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 ----- ADMIN_BODY="$(login admin 123456)" ADMIN_TOKEN="$(json_get "['data']['token']" "$ADMIN_BODY")" assert "pre_admin_login" "[ -n '$ADMIN_TOKEN' ]" "admin token empty; body=$ADMIN_BODY" if [ -z "$ADMIN_TOKEN" ]; then echo "---"; echo "FATAL: admin login failed; aborting" exit 1 fi # ============================================================ # C1 (S1): LMS v1 数据模型基础 # - GET /students 回 ≥2 学员 (含固定 seed 11111111 张三) # - GET /courses 回 ≥2 课程 (含固定 seed aaaaaaaa 数智安全导论) # ============================================================ LIST_STUDENTS_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" "$STUDENTS_URL")" LIST_STUDENTS_LEN="$(python3 -c "import json,sys; print(len(json.loads(sys.argv[1])['data']))" "$LIST_STUDENTS_BODY" 2>/dev/null)" HAS_SEED_STUDENT="$(python3 -c " import json,sys d=json.loads(sys.argv[1]) ids={s['id'] for s in d['data']} print('11111111-1111-1111-1111-111111111111' in ids) " "$LIST_STUDENTS_BODY")" STUDENT_SCHEMA="$(python3 -c " import json,sys d=json.loads(sys.argv[1]) need={'id','student_no','name','email','created_at'} print(all(need.issubset(set(s.keys())) for s in d['data'])) " "$LIST_STUDENTS_BODY")" assert "C1_students_ge_2" "[ '$LIST_STUDENTS_LEN' -ge 2 ]" "got $LIST_STUDENTS_LEN" assert "C1_students_has_seed_id" "[ '$HAS_SEED_STUDENT' = 'True' ]" "seed student missing" assert "C1_students_schema_ok" "[ '$STUDENT_SCHEMA' = 'True' ]" "v1 schema missing" LIST_COURSES_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" "$COURSES_URL")" LIST_COURSES_LEN="$(python3 -c "import json,sys; print(len(json.loads(sys.argv[1])['data']))" "$LIST_COURSES_BODY" 2>/dev/null)" HAS_SEED_COURSE="$(python3 -c " import json,sys d=json.loads(sys.argv[1]) ids={c['id'] for c in d['data']} print('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' in ids) " "$LIST_COURSES_BODY")" COURSE_SCHEMA="$(python3 -c " import json,sys d=json.loads(sys.argv[1]) need={'id','code','name','credits','instructor','created_at'} print(all(need.issubset(set(c.keys())) for c in d['data'])) " "$LIST_COURSES_BODY")" assert "C1_courses_ge_2" "[ '$LIST_COURSES_LEN' -ge 2 ]" "got $LIST_COURSES_LEN" assert "C1_courses_has_seed_id" "[ '$HAS_SEED_COURSE' = 'True' ]" "seed course missing" assert "C1_courses_schema_ok" "[ '$COURSE_SCHEMA' = 'True' ]" "v1 course schema missing" # ============================================================ # C2 (S2): 多场景数据模型 v2 # - lms_course_scene 表存在 (隐含 via /scenes endpoints) # - scene_type enum 校验: 非法 scene_type 应被拒 (422 or 400) # ============================================================ # Verify lms_course_scene table exists by attempting list on seed course LIST_SCENES_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \ "$BASE/api/ssw/dth/lms-v2/courses/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/scenes")" LIST_SCENES_CODE="$(json_get "['code']" "$LIST_SCENES_BODY")" assert "C2_table_exists" "[ '$LIST_SCENES_CODE' = '200' ]" "scene list code=$LIST_SCENES_CODE; body=$LIST_SCENES_BODY" # Illegal scene_type 'video' → should be rejected by CHECK or service ILLEGAL_TYPE_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"code\":\"LMS-V2-ILL-$$\",\"name\":\"非法类型测试\",\"scenes\":[{\"scene_type\":\"video\",\"order_index\":1,\"payload\":{}}]}" \ "$LMS_V2_COURSES_URL")" ILLEGAL_TYPE_CODE="$(json_get "['code']" "$ILLEGAL_TYPE_BODY")" ILLEGAL_TYPE_MSG="$(json_get "['msg']" "$ILLEGAL_TYPE_BODY")" # Could be 422 (validator) or 500 (CHECK constraint if it gets that far) assert "C2_invalid_scene_type_rejected" "[ '$ILLEGAL_TYPE_CODE' = '422' -o '$ILLEGAL_TYPE_CODE' = '500' -o '$ILLEGAL_TYPE_CODE' = '400' ]" \ "illegal type code=$ILLEGAL_TYPE_CODE msg=$ILLEGAL_TYPE_MSG" # ============================================================ # C3 (S3): 创建多场景课程 # - admin POST /lms-v2/courses 含 1 slide + 1 quiz → 回 200 + 2 scene # - admin POST /lms-v2/courses/from-frc-template → 回 200 + 6 scene # ============================================================ C3_CODE="LMS-V2-MULTI-$$" CREATE_MULTI_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"code\":\"$C3_CODE\",\"name\":\"多场景测试\",\"credits\":3,\"instructor\":\"苏苏\",\"scenes\":[{\"scene_type\":\"slide\",\"order_index\":1,\"payload\":{\"markdown\":\"# 标题\\n## 子标题\\n- 列表项\\n普通段落\"}},{\"scene_type\":\"quiz\",\"order_index\":2,\"payload\":{\"questions\":[{\"id\":\"q1\",\"type\":\"choice\",\"prompt\":\"1+1=?\",\"options\":[\"1\",\"2\",\"3\"],\"answer\":\"2\"}]}}]}" \ "$LMS_V2_COURSES_URL")" CREATE_MULTI_CODE="$(json_get "['code']" "$CREATE_MULTI_BODY")" C3_COURSE_ID="$(json_get "['data']['course']['id']" "$CREATE_MULTI_BODY")" C3_SCENE_COUNT="$(python3 -c "import json,sys; print(len(json.loads(sys.argv[1])['data']['scenes']))" "$CREATE_MULTI_BODY" 2>/dev/null)" assert "C3_create_multi_200" "[ '$CREATE_MULTI_CODE' = '200' ]" "code=$CREATE_MULTI_CODE body=$CREATE_MULTI_BODY" assert "C3_create_multi_2scenes" "[ '$C3_SCENE_COUNT' = '2' ]" "got $C3_SCENE_COUNT scenes" # Duplicate course_code → 409 DUPLICATE_COURSE_CODE DUPE_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"code\":\"$C3_CODE\",\"name\":\"重复测试\"}" \ "$LMS_V2_COURSES_URL")" DUPE_CODE="$(json_get "['code']" "$DUPE_BODY")" DUPE_MSG="$(json_get "['msg']" "$DUPE_BODY")" assert "C3_duplicate_code_409" "[ '$DUPE_CODE' = '409' ]" "got $DUPE_CODE (msg=$DUPE_MSG)" # FRC template: 6 scenes FRC_CODE="FRC-V2-$$" FRC_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"course_code\":\"$FRC_CODE\",\"teacher\":\"FRC老师\"}" \ "$LMS_V2_FRC_URL")" FRC_RESPONSE_CODE="$(json_get "['code']" "$FRC_BODY")" FRC_COURSE_ID="$(json_get "['data']['course']['id']" "$FRC_BODY")" FRC_SCENE_COUNT="$(python3 -c "import json,sys; print(len(json.loads(sys.argv[1])['data']['scenes']))" "$FRC_BODY" 2>/dev/null)" assert "C3_frc_200" "[ '$FRC_RESPONSE_CODE' = '200' ]" "code=$FRC_RESPONSE_CODE" assert "C3_frc_6_scenes" "[ '$FRC_SCENE_COUNT' = '6' ]" "got $FRC_SCENE_COUNT scenes" # ============================================================ # C4 (S4): 选课 + 进度 append-only (重复 complete 不增 count) # - enroll student 11111111 → course $C3_COURSE_ID # - complete scene 1 → progress_count = 1 # - complete scene 1 again → progress_count = 1 (idempotent) # ============================================================ ENROLL_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d '{"student_id":"11111111-1111-1111-1111-111111111111"}' \ "$COURSES_URL/$C3_COURSE_ID/enroll")" ENROLL_CODE="$(json_get "['code']" "$ENROLL_BODY")" assert "C4_enroll_ok" "[ '$ENROLL_CODE' = '200' ]" "code=$ENROLL_CODE body=$ENROLL_BODY" # Get the 2 scenes for the multi-scene course SCENES_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \ "$BASE/api/ssw/dth/lms-v2/courses/$C3_COURSE_ID/scenes")" SCENE_1_ID="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['data'][0]['id'])" "$SCENES_BODY" 2>/dev/null)" SCENE_2_ID="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['data'][1]['id'])" "$SCENES_BODY" 2>/dev/null)" # Complete scene 1 → progress_count = 1 COMPLETE_1_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"student_id\":\"11111111-1111-1111-1111-111111111111\",\"course_id\":\"$C3_COURSE_ID\"}" \ "$BASE/api/ssw/dth/lms-v2/scenes/$SCENE_1_ID/complete")" COMPLETE_1_CODE="$(json_get "['code']" "$COMPLETE_1_BODY")" COMPLETE_1_COUNT="$(json_get "['data']['progress_count']" "$COMPLETE_1_BODY")" assert "C4_complete_first_ok" "[ '$COMPLETE_1_CODE' = '200' ]" "code=$COMPLETE_1_CODE" assert "C4_complete_first_count1" "[ '$COMPLETE_1_COUNT' = '1' ]" "got $COMPLETE_1_COUNT" # Complete scene 1 again → still 1 (idempotent append-only) COMPLETE_AGAIN_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"student_id\":\"11111111-1111-1111-1111-111111111111\",\"course_id\":\"$C3_COURSE_ID\"}" \ "$BASE/api/ssw/dth/lms-v2/scenes/$SCENE_1_ID/complete")" COMPLETE_AGAIN_COUNT="$(json_get "['data']['progress_count']" "$COMPLETE_AGAIN_BODY")" assert "C4_complete_idempotent" "[ '$COMPLETE_AGAIN_COUNT' = '1' ]" "expected 1, got $COMPLETE_AGAIN_COUNT" # Complete scene 2 → progress_count = 2 COMPLETE_2_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -d "{\"student_id\":\"11111111-1111-1111-1111-111111111111\",\"course_id\":\"$C3_COURSE_ID\"}" \ "$BASE/api/ssw/dth/lms-v2/scenes/$SCENE_2_ID/complete")" COMPLETE_2_COUNT="$(json_get "['data']['progress_count']" "$COMPLETE_2_BODY")" assert "C4_complete_second_count2" "[ '$COMPLETE_2_COUNT' = '2' ]" "got $COMPLETE_2_COUNT" # ============================================================ # C5 (S5): SlideScene Markdown 渲染 # - h1 / h2 / p / ul / li / code 5 节点 + 非法节点原样保留 # - 渲染产物 html 含全部 5 节点标签 + 含"非法节点"原文字 # ============================================================ # Build a fresh slide scene with full markdown (avoid bash escape issues # by writing JSON to a temp file via python). C5_SLIDE_CODE="SLIDE-$RANDOM-$$" C5_PAYLOAD_FILE="/tmp/c5_slide_payload_$$.json" python3 -c " import json # Markdown with all 5 node kinds + an 'illegal' line preserved as
: # - h1 / h2: headers # - p: 'normal paragraph here' # - ul/li: '- item1' / '- item2' # - code: fenced block 'code-block-here' # - illegal_node_blah: not a recognized node → rendered as
(preserved verbatim) md = '''# Title ## Sub - item1 - item2 normal paragraph here \`\`\` code-block-here \`\`\` illegal_node_blah''' print(json.dumps({ 'code': 'C5_SLIDE_${RANDOM}_${$}', 'name': 'slide-render-test', 'scenes': [{'scene_type':'slide','order_index':1,'payload':{'markdown': md}}] }, ensure_ascii=False)) " > "$C5_PAYLOAD_FILE" C5_CREATE="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \ -X POST "$LMS_V2_COURSES_URL" --data-binary "@$C5_PAYLOAD_FILE")" C5_COURSE_ID="$(json_get "['data']['course']['id']" "$C5_CREATE")" C5_SCENE_ID="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['data']['scenes'][0]['id'])" "$C5_CREATE" 2>/dev/null)" RENDER_SLIDE_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \ "$BASE/api/ssw/dth/lms-v2/courses/$C5_COURSE_ID/scenes/$C5_SCENE_ID/render")" RENDER_SLIDE_CODE="$(json_get "['code']" "$RENDER_SLIDE_BODY")" SLIDE_HTML="$(json_get "['data']['html']" "$RENDER_SLIDE_BODY")" # Verify 5 node tags + illegal verbatim HAS_H1="$(printf '%s' "$SLIDE_HTML" | grep -c '
normal' || true)"
HAS_CODE="$(printf '%s' "$SLIDE_HTML" | grep -c 'code-block-here' || true)"
HAS_ILLEGAL="$(printf '%s' "$SLIDE_HTML" | grep -c 'illegal_node_blah' || true)"
assert "C5_slide_render_200" "[ '$RENDER_SLIDE_CODE' = '200' ]" "code=$RENDER_SLIDE_CODE"
assert "C5_slide_h1" "[ '$HAS_H1' -ge '1' ]" "h1 missing"
assert "C5_slide_h2" "[ '$HAS_H2' -ge '1' ]" "h2 missing"
assert "C5_slide_ul" "[ '$HAS_UL' -ge '1' ]" "ul missing"
assert "C5_slide_li" "[ '$HAS_LI_COUNT' -ge '2' ]" "li count < 2"
assert "C5_slide_p" "[ '$HAS_P' -ge '1' ]" "p tag missing"
assert "C5_slide_code" "[ '$HAS_CODE' -ge '1' ]" "code block missing"
assert "C5_slide_illegal_preserved" "[ '$HAS_ILLEGAL' -ge '1' ]" "illegal node dropped"
rm -f "$C5_PAYLOAD_FILE"
# ============================================================
# C6 (S6): QuizScene 判分
# - choice: 答对 + score = 1.0
# - short: 关键词 50% 命中 = 满分
# ============================================================
QUIZ_SCENE_ID="$SCENE_2_ID"
# Perfect choice answer
GRADE_PERFECT_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"answers":{"q1":"2"}}' \
"$BASE/api/ssw/dth/lms-v2/scenes/$QUIZ_SCENE_ID/grade")"
GRADE_PERFECT_SCORE="$(json_get "['data']['score']" "$GRADE_PERFECT_BODY")"
assert "C6_choice_perfect_score_1" "python3 -c \"import sys; sys.exit(0 if float('$GRADE_PERFECT_SCORE') == 1.0 else 1)\"" "got $GRADE_PERFECT_SCORE"
# Wrong choice answer
GRADE_WRONG_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"answers":{"q1":"1"}}' \
"$BASE/api/ssw/dth/lms-v2/scenes/$QUIZ_SCENE_ID/grade")"
GRADE_WRONG_SCORE="$(json_get "['data']['score']" "$GRADE_WRONG_BODY")"
assert "C6_choice_wrong_score_0" "python3 -c \"import sys; sys.exit(0 if float('$GRADE_WRONG_SCORE') == 0.0 else 1)\"" "got $GRADE_WRONG_SCORE"
# Add a short-answer question, then test 50% keyword hit
QUIZ_SHORT_CODE="QUIZ-S-$$"
QUIZ_SHORT_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d "{\"code\":\"$QUIZ_SHORT_CODE\",\"name\":\"简答测试\",\"scenes\":[{\"scene_type\":\"quiz\",\"order_index\":1,\"payload\":{\"questions\":[{\"id\":\"qs1\",\"type\":\"short\",\"prompt\":\"描述 PSI 的核心特性\",\"keywords\":[\"私有不泄露\",\"交集\"]}]}}]}" \
"$LMS_V2_COURSES_URL")"
QUIZ_SHORT_COURSE_ID="$(json_get "['data']['course']['id']" "$QUIZ_SHORT_BODY")"
QUIZ_SHORT_SCENE_ID="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['data']['scenes'][0]['id'])" "$QUIZ_SHORT_BODY" 2>/dev/null)"
# 50% hit (1/2 keywords) → score = 1.0
GRADE_HALF_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"answers":{"qs1":"PSI 求交集"}}' \
"$BASE/api/ssw/dth/lms-v2/scenes/$QUIZ_SHORT_SCENE_ID/grade")"
GRADE_HALF_SCORE="$(json_get "['data']['score']" "$GRADE_HALF_BODY")"
assert "C6_short_50pct_hit_full_score" "python3 -c \"import sys; sys.exit(0 if float('$GRADE_HALF_SCORE') == 1.0 else 1)\"" "got $GRADE_HALF_SCORE"
# 0% hit → score = 0.0
GRADE_NO_HIT_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"answers":{"qs1":"完全不相关"}}' \
"$BASE/api/ssw/dth/lms-v2/scenes/$QUIZ_SHORT_SCENE_ID/grade")"
GRADE_NO_HIT_SCORE="$(json_get "['data']['score']" "$GRADE_NO_HIT_BODY")"
assert "C6_short_0pct_hit_zero_score" "python3 -c \"import sys; sys.exit(0 if float('$GRADE_NO_HIT_SCORE') == 0.0 else 1)\"" "got $GRADE_NO_HIT_SCORE"
# ============================================================
# C7 (S7): SimScene iframe
# - embed_url 校验 (http(s):// 前缀) → 通过
# - 非法 URL (无前缀) → 422 INVALID_EMBED_URL (validation) or 400
# ============================================================
# Good URL → 200
SIM_OK_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d "{\"code\":\"SIM-OK-$$\",\"name\":\"仿真测试\",\"scenes\":[{\"scene_type\":\"simulation\",\"order_index\":1,\"payload\":{\"embed_url\":\"https://example.com/embed\",\"height\":200}}]}" \
"$LMS_V2_COURSES_URL")"
SIM_OK_CODE="$(json_get "['code']" "$SIM_OK_BODY")"
assert "C7_sim_create_ok" "[ '$SIM_OK_CODE' = '200' ]" "code=$SIM_OK_CODE body=$SIM_OK_BODY"
# Render simulation scene → returns embed_url
SIM_OK_COURSE_ID="$(json_get "['data']['course']['id']" "$SIM_OK_BODY")"
SIM_OK_SCENE_ID="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['data']['scenes'][0]['id'])" "$SIM_OK_BODY" 2>/dev/null)"
SIM_RENDER_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
"$BASE/api/ssw/dth/lms-v2/courses/$SIM_OK_COURSE_ID/scenes/$SIM_OK_SCENE_ID/render")"
SIM_RENDER_EMBED="$(json_get "['data']['embed_url']" "$SIM_RENDER_BODY")"
assert "C7_sim_render_embed_match" "[ '$SIM_RENDER_EMBED' = 'https://example.com/embed' ]" "got=$SIM_RENDER_EMBED"
# Bad URL → 400 INVALID_EMBED_URL
SIM_BAD_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d "{\"code\":\"SIM-BAD-$$\",\"name\":\"非法URL\",\"scenes\":[{\"scene_type\":\"simulation\",\"order_index\":1,\"payload\":{\"embed_url\":\"javascript:alert(1)\"}}]}" \
"$LMS_V2_COURSES_URL")"
SIM_BAD_CODE="$(json_get "['code']" "$SIM_BAD_BODY")"
SIM_BAD_MSG="$(json_get "['msg']" "$SIM_BAD_BODY")"
assert "C7_sim_bad_url_400" "[ '$SIM_BAD_CODE' = '400' -o '$SIM_BAD_CODE' = '422' ]" "got code=$SIM_BAD_CODE msg=$SIM_BAD_MSG"
# ============================================================
# C8 (S8): FRC 6-scene 模板
# - 6 scene 全部 simulation
# - order_index 严格 1-6 升序
# - 6 embed_url 对应 chg_0010 S1-S6
# ============================================================
FRC_SCENES_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
"$BASE/api/ssw/dth/lms-v2/courses/$FRC_COURSE_ID/scenes")"
FRC_TYPES="$(python3 -c "
import json,sys
d=json.loads(sys.argv[1])['data']
print(','.join(s['scene_type'] for s in d))
" "$FRC_SCENES_BODY")"
FRC_ORDERS="$(python3 -c "
import json,sys
d=json.loads(sys.argv[1])['data']
print(','.join(str(s['order_index']) for s in d))
" "$FRC_SCENES_BODY")"
assert "C8_frc_6_simulation" "[ '$FRC_TYPES' = 'simulation,simulation,simulation,simulation,simulation,simulation' ]" "got=$FRC_TYPES"
assert "C8_frc_orders_1to6" "[ '$FRC_ORDERS' = '1,2,3,4,5,6' ]" "got=$FRC_ORDERS"
# Verify each scene's embed_url matches the chg_0010 S1-S6 mapping
# (s1: did-tds, s2: psi, s3: paillier, s4: threshold, s5: abac, s6: audit)
FRC_URLS_VALID="$(python3 -c "
import json,sys
d=json.loads(sys.argv[1])['data']
required=['did-tds','psi','paillier','threshold','abac','audit']
ok=True
for i,s in enumerate(d):
pl=json.loads(s['payload_json'])
if required[i] not in pl.get('embed_url',''):
ok=False
break
print(ok)
" "$FRC_SCENES_BODY")"
assert "C8_frc_embed_urls_match" "[ '$FRC_URLS_VALID' = 'True' ]" "embed_url mapping broken"
# ============================================================
# C9 (S9): E2E 完整流程
# - admin login → from-frc-template → student login → enroll → 6 render + 6 complete → progress_pct = 1.0
# ============================================================
# Use the FRC course from C8 — need a fresh enrollment for student 22222222 (韩梅梅)
ENROLL_FRC_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d '{"student_id":"22222222-2222-2222-2222-222222222222"}' \
"$COURSES_URL/$FRC_COURSE_ID/enroll")"
ENROLL_FRC_CODE="$(json_get "['code']" "$ENROLL_FRC_BODY")"
assert "C9_enroll_frc_ok" "[ '$ENROLL_FRC_CODE' = '200' ]" "code=$ENROLL_FRC_CODE"
# Render all 6 + complete all 6
ALL_RENDER_OK=1
ALL_COMPLETE_OK=1
for i in 1 2 3 4 5 6; do
FRC_SCENE_ID="$(python3 -c "
import json,sys
d=json.loads(sys.argv[1])['data']
print([s['id'] for s in d if s['order_index']==$i][0])
" "$FRC_SCENES_BODY" 2>/dev/null)"
R="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
"$BASE/api/ssw/dth/lms-v2/courses/$FRC_COURSE_ID/scenes/$FRC_SCENE_ID/render")"
RC="$(json_get "['code']" "$R")"
if [ "$RC" != "200" ]; then ALL_RENDER_OK=0; echo " render scene $i code=$RC"; fi
C="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d "{\"student_id\":\"22222222-2222-2222-2222-222222222222\",\"course_id\":\"$FRC_COURSE_ID\"}" \
"$BASE/api/ssw/dth/lms-v2/scenes/$FRC_SCENE_ID/complete")"
CC="$(json_get "['code']" "$C")"
if [ "$CC" != "200" ]; then ALL_COMPLETE_OK=0; echo " complete scene $i code=$CC"; fi
done
assert "C9_all_6_render_ok" "[ '$ALL_RENDER_OK' = '1' ]" "some render failed"
assert "C9_all_6_complete_ok" "[ '$ALL_COMPLETE_OK' = '1' ]" "some complete failed"
# Final progress_count should be 6 (all scenes done)
FINAL_COMPLETE_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d "{\"student_id\":\"22222222-2222-2222-2222-222222222222\",\"course_id\":\"$FRC_COURSE_ID\"}" \
"$BASE/api/ssw/dth/lms-v2/scenes/$(python3 -c "
import json,sys
d=json.loads(sys.argv[1])['data']
print(d[0]['id'])
" "$FRC_SCENES_BODY" 2>/dev/null)/complete")"
# Re-complete scene 1 to fetch latest progress (idempotent)
FINAL_COUNT="$(json_get "['data']['progress_count']" "$FINAL_COMPLETE_BODY")"
assert "C9_progress_count_6" "[ '$FINAL_COUNT' = '6' ]" "expected 6, got $FINAL_COUNT"
# progress_pct = 6/6 = 1.0
PROGRESS_PCT="$(python3 -c "print($FINAL_COUNT / 6)")"
assert "C9_progress_pct_1" "python3 -c \"import sys; sys.exit(0 if float('$PROGRESS_PCT') == 1.0 else 1)\"" "got $PROGRESS_PCT"
# ============================================================
# C10 (S10): PBL 占位一致性
# - type=pbl → render 回 501 NOT_IMPLEMENTED + 文案
# - 前端 PBLScene 占位文案与后端 501 文案字面一致
# ============================================================
PBL_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
-d "{\"code\":\"PBL-$$\",\"name\":\"PBL占位\",\"scenes\":[{\"scene_type\":\"pbl\",\"order_index\":1,\"payload\":{}}]}" \
"$LMS_V2_COURSES_URL")"
PBL_COURSE_ID="$(json_get "['data']['course']['id']" "$PBL_BODY")"
PBL_SCENE_ID="$(python3 -c "import json,sys; print(json.loads(sys.argv[1])['data']['scenes'][0]['id'])" "$PBL_BODY" 2>/dev/null)"
PBL_RENDER_BODY="$(curl -s -H "Authorization: Bearer $ADMIN_TOKEN" \
"$BASE/api/ssw/dth/lms-v2/courses/$PBL_COURSE_ID/scenes/$PBL_SCENE_ID/render")"
PBL_RENDER_CODE="$(json_get "['code']" "$PBL_RENDER_BODY")"
PBL_RENDER_MSG="$(json_get "['msg']" "$PBL_RENDER_BODY")"
PBL_FRONTEND_MSG="$(python3 -c "
# Replicate the constant from src/frontend/src/views/LMS/PBLScene.tsx
print('PBL 场景 v2 实现,当前仅作课程占位')
")"
assert "C10_pbl_501_code" "[ '$PBL_RENDER_CODE' = '501' ]" "got code=$PBL_RENDER_CODE"
assert "C10_pbl_backend_msg_correct" "[ '$PBL_RENDER_MSG' = '$PBL_FRONTEND_MSG' ]" "got msg=$PBL_RENDER_MSG"
assert "C10_pbl_frontend_match" "python3 -c \"import sys; sys.exit(0 if '$PBL_FRONTEND_MSG' == 'PBL 场景 v2 实现,当前仅作课程占位' else 1)\" || false" \
"frontend msg drift"
# ----- Result summary -----
echo "---"
echo "pass=$pass fail=$fail"
if [ "$fail" -gt 0 ]; then
echo "FAILED:"
for f in "${fails[@]}"; do
echo " - $f"
done
exit 1
fi
echo "ALL PASS"
exit 0