Implement nested question remediation and review content

This commit is contained in:
hz
2026-07-16 21:46:56 -05:00
parent 0f5a1122d4
commit c8bfc26645
14 changed files with 1339 additions and 245 deletions
+4
View File
@@ -24,6 +24,10 @@ func _initialize() -> void:
var legacy: Dictionary = service._prepare_question_choices(_question(5))
_check_presented(legacy)
_assert(_ids(legacy.get("presented_choices", [])).size() == 5, "legacy five-choice questions must show all choices")
service.session_kind = "block"
service.session_initial_seconds = 900.0
service.seconds_remaining = 450.0
_assert(is_equal_approx(service.get_session_timer_ratio(), 0.5), "timed block progress should use the full session duration")
service.free()
quit(1 if failures > 0 else 0)
+145 -3
View File
@@ -11,10 +11,17 @@ func _initialize() -> void:
_test_eliminated_choice_uses_rich_text_strikeout()
_test_explanation_highlighting_has_no_status_heading()
_test_collapsed_followup_review_expands()
_test_review_content_normalization()
_test_followup_attempt_order_is_stable()
_test_answer_review_collapses_nested_wrong_followups()
_test_review_followup_is_optional_and_single_attempt()
_test_question_failure_retry_classification()
_test_transient_question_failure_keeps_player_waiting()
_test_feedback_context_excludes_study_content()
_test_feedback_form_validation()
_test_revisitable_navigation_prefers_unanswered_questions()
_test_submit_styles_keep_stable_geometry()
await _test_player_runtime_construction()
quit(1 if failures > 0 else 0)
@@ -93,7 +100,7 @@ func _test_eliminated_choice_uses_rich_text_strikeout() -> void:
player.presented_choices = [{"id": "A", "text": "Observation only"}]
player._set_choice_button_text(0, player.presented_choices[0])
_assert(player.choice_buttons[0].text == "", "eliminated choice should not use combining characters in button text")
_assert(strike_label.text == "[s]A. Observation only[/s]", "eliminated choice should use native rich-text strikeout")
_assert(strike_label.text == "[s]Observation only[/s]", "eliminated choice should use native rich-text strikeout")
_assert(not "[eliminated]" in strike_label.text, "eliminated choice should not include a redundant label")
player.choice_buttons[0].free()
player.choice_percent_labels[0].free()
@@ -133,9 +140,10 @@ func _test_collapsed_followup_review_expands() -> void:
"teaching_point": "Review the finding.", "resolved": true, "collapsed": true
}
player._render_followup_state("B")
var review_button := content.get_child(0) as Button
var review_button := content.find_child("FollowupSummary", true, false) as Button
_assert(review_button != null, "collapsed follow-up should render a review button")
review_button.pressed.emit()
if review_button != null:
review_button.pressed.emit()
_assert(not bool(player.followup_states["B"].get("collapsed", true)), "review button should expand the resolved follow-up")
player.choice_buttons[0].free()
player.choice_percent_labels[0].free()
@@ -145,6 +153,90 @@ func _test_collapsed_followup_review_expands() -> void:
player.free()
func _test_review_content_normalization() -> void:
var service = load("res://scripts/autoload/question_bank_service.gd").new()
var normalized: Dictionary = service._normalize_api_question({
"id": "mongo-id",
"externalId": "review-test",
"stem": "Stem",
"leadIn": "Lead",
"choices": [{"id": "A", "text": "One"}, {"id": "B", "text": "Two"}],
"correctChoiceId": "A",
"explanation": "Explanation",
"keyTakeaway": "Takeaway",
"usmlePearl": "Pearl",
"reviewFollowups": [{
"prompt": "Prompt",
"choices": [{"id": "A", "text": "One"}, {"id": "B", "text": "Two"}],
"correctChoiceId": "B",
"teachingPoint": "Teaching"
}],
"system": "System",
"discipline": "Medicine"
})
_assert(normalized.get("key_takeaway", "") == "Takeaway", "key takeaway should be normalized")
_assert(normalized.get("usmle_pearl", "") == "Pearl", "USMLE pearl should be normalized")
var review_followups: Array = normalized.get("review_followups", [])
_assert(review_followups.size() == 1, "review follow-ups should be normalized")
_assert(review_followups[0].get("correct_choice_id", "") == "B", "review follow-up answer keys should be normalized")
service.free()
func _test_followup_attempt_order_is_stable() -> void:
var player = load("res://scripts/ui/question_player.gd").new()
player._append_followup_attempt("C")
player._append_followup_attempt("A")
_assert(player.followup_attempt_order == ["C", "A"], "follow-up state should preserve answer attempt order")
player._append_followup_attempt("C")
_assert(player.followup_attempt_order == ["C", "A"], "repeat rendering should not duplicate an attempted answer")
player.free()
func _test_answer_review_collapses_nested_wrong_followups() -> void:
var player = load("res://scripts/ui/question_player.gd").new()
player.followup_states["C"] = {"resolved": true, "collapsed": false, "is_main_correct": false}
player.followup_attempt_order = ["C"]
player._ensure_answer_review_followups()
_assert(bool(player.followup_states["C"].get("collapsed", false)), "resolved distractor remediation should collapse for final review")
_assert(not player.followup_states.has("B"), "the correct answer should not become a distractor-remediation card")
player.free()
func _test_review_followup_is_optional_and_single_attempt() -> void:
var session = root.get_node("BlockSessionService")
var prior_questions: Array = session.active_questions.duplicate(true)
var prior_index: int = session.current_index
session.active_questions = [{
"review_followups": [{
"prompt": "Prompt",
"choices": [{"id": "A", "text": "One"}, {"id": "B", "text": "Two"}],
"correct_choice_id": "A",
"teaching_point": "Teaching point"
}]
}]
session.current_index = 0
var player = load("res://scripts/ui/question_player.gd").new()
player.next_button = Button.new()
player.next_button.disabled = false
player.review_followups_section = VBoxContainer.new()
var heading := Label.new()
heading.name = "ReviewFollowupHeading"
player.review_followups_section.add_child(heading)
player.review_followups_content = VBoxContainer.new()
player.review_followups_section.add_child(player.review_followups_content)
player._render_review_followups()
_assert(not player.next_button.disabled, "optional review follow-ups must not lock Next")
player._answer_review_followup(0, "B")
_assert(bool(player.review_followup_states[0].get("answered", false)), "a review follow-up should record its first response")
player._answer_review_followup(0, "A")
_assert(player.review_followup_states[0].get("selected_choice_id", "") == "B", "review follow-ups should accept only one attempt")
player.review_followups_section.free()
player.next_button.free()
player.free()
session.active_questions = prior_questions
session.current_index = prior_index
func _test_question_failure_retry_classification() -> void:
var service = load("res://scripts/autoload/question_bank_service.gd").new()
_assert(service._is_transient_question_failure(HTTPRequest.RESULT_CANT_CONNECT, 0), "connection failures should retry")
@@ -189,6 +281,56 @@ func _test_feedback_form_validation() -> void:
_assert(not dialog_script.is_valid_submission("bug", "Too short"), "short feedback should be rejected")
func _test_revisitable_navigation_prefers_unanswered_questions() -> void:
var session = root.get_node("BlockSessionService")
var prior_questions: Array = session.active_questions.duplicate(true)
var prior_answers: Array = session.answers.duplicate(true)
var prior_index: int = session.current_index
session.active_questions = [{"id": "one"}, {"id": "two"}, {"id": "three"}]
session.answers = [{"selected_choice_id": "A"}, null, null]
session.current_index = 0
var player = load("res://scripts/ui/question_player.gd").new()
_assert(player._next_revisitable_index() == 1, "skip should advance to the next unanswered question")
session.answers[1] = {"selected_choice_id": "B"}
session.current_index = 2
_assert(player._next_revisitable_index() == 0, "skip should wrap rather than reload the same unanswered question")
player.free()
session.active_questions = prior_questions
session.answers = prior_answers
session.current_index = prior_index
func _test_player_runtime_construction() -> void:
var host := Control.new()
root.add_child(host)
var player = load("res://scripts/ui/question_player.gd").new()
player.main = host
host.add_child(player)
await process_frame
_assert(player.question_card != null, "question player should construct its branded card")
_assert(player.navigator_popup != null, "question player should construct its popup navigator")
_assert(player.choice_badges.size() == 5, "question player should construct an answer badge for every visible choice slot")
_assert(player.choice_followup_panels[2].get_parent() == player.choice_rows[2], "distractor remediation should remain nested inside its answer choice")
player.choice_followup_panels[2].visible = true
player.locked_wrong_choice_ids = ["C"]
player.presented_choices = [{"id": "A", "text": "First"}, {"id": "B", "text": "Second"}, {"id": "C", "text": "Seek a court order"}]
player._set_choice_button_text(2, player.presented_choices[2])
_assert(not player.choice_top_labels[2].visible, "nested remediation should not add a second label over the answer row")
_assert(player.choice_buttons[2].text == "Seek a court order", "wrong-answer rows should retain their answer text")
_assert(is_equal_approx(player.choice_badges[2].anchor_top, 0.0), "expanded answer badges should remain pinned to the answer strip")
host.queue_free()
await process_frame
func _test_submit_styles_keep_stable_geometry() -> void:
var player = load("res://scripts/ui/question_player.gd").new()
var normal: StyleBoxFlat = player._primary_action_box(true, "normal")
var disabled: StyleBoxFlat = player._primary_action_box(true, "disabled")
_assert(normal.corner_radius_top_left == disabled.corner_radius_top_left, "enabled and disabled Submit styles should keep the same corner radius")
_assert(is_equal_approx(normal.content_margin_top, disabled.content_margin_top), "enabled and disabled Submit styles should keep the same vertical margins")
player.free()
func _assert(condition: bool, message: String) -> void:
if condition:
return