Skip to content

Commit f9e380e

Browse files
authored
test(quiz): pin mid-save failures and the start form's assumptions; fix two doc claims (#79) (#86)
* test(quiz): pin mid-save failures and the start form's assumptions; fix two doc claims (#79) - A failure after the first verified autosave (a 500, a network error or session expiry on the second POST, or a second readback that disagrees or expires) is LearnerSaveUnknownError after exactly two POSTs. - The start form's assumptions of the summary each refuse before sending, and are documented as a known limitation: no captured summary is in the tests yet. - The RPC address names the d2lfile path; the parity sentence says a change made twice is saved once. * test(quiz): isolate the outside-question refusal; correct start-limitation docs (#79) - A stray checkbox, not a text input, pins the outside-question check: a text input is also refused when it has no answer (Grok 4.7). - A second form or repeated hidden field is an unreadable page, shown as "Brightspace did not return a supported current page of this attempt", not the form refusal (Grok 4.7). - The parity sentence says the start request was compared only by URL and headers (Grok 4.7), and that one attempt answer saves its final value once, while two commands save twice (CodeRabbit). - The mid-save test asserts exact page reads and has a third pending answer, so two POSTs also show the save stopped (MiniMax M3.1 Flash plan review). - Every control must be named once, not only the bookkeeping ones (MiniMax M3.1 Flash plan review).
1 parent cb66fb7 commit f9e380e

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

‎docs/agent-quizzes.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ blocks every write on its page, including navigation and submission, because
104104
Brightspace posts the whole page form. Do not try to skip it with
105105
`--allow-unanswered`. Complete that attempt through Brightspace instead.
106106
Password-protected quizzes and quizzes requiring a browser step such as
107-
LockDown Browser are also refused.
107+
LockDown Browser are also refused. So is any quiz page, the summary that
108+
`start` posts included, whose form the CLI cannot send as a browser would
109+
("This quiz page is not one the CLI can send as a browser would"), or that
110+
it cannot read ("Brightspace did not return a supported current page of
111+
this attempt"): nothing is sent, so complete that quiz through Brightspace.
108112

109113
## Submit and verify
110114

‎docs/quiz-protocol.md‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ with one question on each of two pages, forward-only) added:
235235

236236
A graded attempt was recorded in a browser on Lighthouse (Brightspace
237237
20.26.10): ten pages, one single-choice question on each, forward-only. The
238-
CLI's learner commands send the same requests, fields and Referers. Values
239-
here are placeholders (`ou=1001`, `qi=2002`, `ai=3003`, question ids 4xxx).
238+
CLI's learner commands send the same request shapes, fields and Referers
239+
(the start request was compared only by URL and headers; see Form fields),
240+
but not the same number of saves: the browser autosaves every change to an
241+
answer, while one `attempt answer` saves only the final value it is given
242+
(two commands save twice). Values here are placeholders (`ou=1001`,
243+
`qi=2002`, `ai=3003`, question ids 4xxx).
240244

241245
- Start: the summary is `quiz_summary.d2l?qi=2002&ou=1001`, and the start
242246
POST goes to the same URL plus `&cfql=0&inProgress=false` (`true` to
@@ -277,6 +281,16 @@ here are placeholders (`ou=1001`, `qi=2002`, `ai=3003`, question ids 4xxx).
277281
page's `JsonDeserializerMin.Deserialize([...])`: 336 on attempt pages,
278282
327 on the summary). The summary form has no `QuizTabId`. The CLI
279283
refuses, with nothing sent, a page whose form it cannot fill this way.
284+
The start form is built the same way, so `attempt start` assumes the
285+
summary is shaped like the recorded one: one form, every control named
286+
once (those bookkeeping controls among them), `d2l_state` as
287+
`[scopes, []]`, one `Deserialize` call, no `QuizTabId`, and no visible
288+
control outside a question. The recorded summary passed this (the replay's start request
289+
matched the browser's URL and headers), but its fields were not compared
290+
one by one and the tests use a synthetic summary, so a summary shaped
291+
otherwise is a known limitation: `attempt start` stops before sending
292+
anything (a second form or a repeated hidden field makes the summary an
293+
unsupported page; anything else above is this refusal).
280294
- Answer: each change is one autosave, a multipart POST to
281295
`quiz_attempt_save_auto.d2l?d2l_body_type=3&ou=1001&fromQB=0` with
282296
`3,<page>,<tid>,<tvid>,<question number>` and the whole page form,
@@ -335,8 +349,9 @@ here are placeholders (`ou=1001`, `qi=2002`, `ai=3003`, question ids 4xxx).
335349
- Submit: the finish save goes to
336350
`?dnb=0&cfql=0&fromQB=0&d2l_body_type=3&ou` with `5,<page>`, then the
337351
confirmation page loads with that save's URL as Referer. The RPC posts
338-
to the attempt frame's own URL (its `pg` is the page the attempt opened
339-
on, here `1` from page 10) plus `&d2l_rh=rpc&d2l_rt=call`, Referer the
352+
to the attempt frame's URL with `file` appended to its path
353+
(`quiz_attempt_iframe_auto.d2lfile`; its `pg` is the page the attempt
354+
opened on, here `1` from page 10) plus `&d2l_rh=rpc&d2l_rt=call`, Referer the
340355
frame URL, with the body urlencoded in the order `d2l_rf`, `params`,
341356
`d2l_referrer`, `d2l_hitcode`, `d2l_action=rpc`. The receipt then loads
342357
with the frame URL as Referer.

‎tests/test_quiz_learner.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,12 @@ def test_a_summary_just_read_is_not_requested_again():
11901190
(summary(**PROCESSING, password="true"), {}, REFUSE_START_PROCESSING.format(10)), # pragma: allowlist secret
11911191
(summary(fields={"d2l_controlMap": "[{},{},{}]"}), {}, REFUSE_LEARNER_FORM),
11921192
(summary(extra='<input type="hidden" name="d2l_stateScopes" value="">'), {}, REFUSE_LEARNER_FORM),
1193+
# What the start form assumes of the summary (docs/quiz-protocol.md, Form fields).
1194+
(summary().replace(b'<input type="hidden" name="d2l_controlMapPrev" value="">', b""), {}, REFUSE_LEARNER_FORM),
1195+
(summary(fields={"d2l_state": '[{"1":["pagenum"]},[1]]'}), {}, REFUSE_LEARNER_FORM),
1196+
(summary(extra='<input type="hidden" name="QuizTabId" value="1234567890123">'), {}, REFUSE_LEARNER_FORM),
1197+
(summary(extra='<input type="checkbox" name="agree" value="1">'), {}, REFUSE_LEARNER_FORM),
1198+
(summary().replace(b"JsonDeserializerMin.Deserialize", b"JsonDeserializerMin.Read"), {}, REFUSE_LEARNER_FORM),
11931199
# The open time is told only for a start the countdown holds back.
11941200
(summary(**NOT_OPEN), {"continue_only": True}, REFUSE_NOTHING_IN_PROGRESS),
11951201
(summary(**IN_PROGRESS, **NOT_OPEN), {}, REFUSE_START_UNAVAILABLE),
@@ -1204,6 +1210,17 @@ def test_start_refusals_send_nothing(page, kwargs, message):
12041210
client._request.assert_not_called()
12051211

12061212

1213+
@pytest.mark.parametrize("page", [
1214+
summary() + b"<form></form>",
1215+
summary(extra='<input type="hidden" name="drc" value="1">'),
1216+
], ids=["second-form", "repeated-hidden-field"])
1217+
def test_a_summary_with_a_second_form_or_repeated_field_is_not_read_and_sends_nothing(page):
1218+
client = write_client(page)
1219+
with pytest.raises(PreviewPageError):
1220+
start_learner(client, course_id=10, quiz_id=20)
1221+
client._request.assert_not_called()
1222+
1223+
12071224
@pytest.mark.parametrize("calls", ["", "function StartCountdown(startDateTicks) {}",
12081225
"window.StartCountdown(639355968000000000);", "StartCountdown(1, 2);",
12091226
"var x = StartCountdown(639355968000000000);"])
@@ -1446,6 +1463,33 @@ def test_unverified_save_is_unknown_and_not_retried(post, readback):
14461463
post.close.assert_called_once()
14471464

14481465

1466+
FIRST_SAVED = body(questions(sc=("o2",), saved=("True", "False", "False")))
1467+
1468+
1469+
@pytest.mark.parametrize("second, readback, reads", [
1470+
(posted(saved_reply("102"), status=500), None, 2),
1471+
(NetworkError("connection reset"), None, 2),
1472+
(SessionExpiredError("session expired"), None, 2),
1473+
(posted(saved_reply("102")), FIRST_SAVED, 3), # 200 without the second answer persisted
1474+
(posted(saved_reply("102")), SessionExpiredError("session expired"), 3),
1475+
], ids=["server-error", "network-error", "post-auth-expiry", "not-persisted", "readback-auth-expiry"])
1476+
def test_a_failure_after_the_first_verified_save_is_unknown_and_not_retried(second, readback, reads):
1477+
# The first answer is saved and verified; only the second fails, inside
1478+
# the per-answer check rather than before its POST. A third answer is
1479+
# pending, so two POSTs also show the save stopped instead of going on.
1480+
first = posted(saved_reply("101"))
1481+
pages = [body(questions()), FIRST_SAVED] + ([] if readback is None else [readback])
1482+
client = write_client(*pages, posts=[first, second])
1483+
with pytest.raises(LearnerSaveUnknownError) as exc_info:
1484+
save_learner_answers(client, VIEW, answers={101: "o2", 102: ["o11"], 103: ["four", "six"]})
1485+
assert type(exc_info.value) is LearnerSaveUnknownError
1486+
assert client._request.call_count == 2
1487+
assert client.get_raw.call_count == reads
1488+
for response in (first, second):
1489+
if isinstance(response, Mock):
1490+
response.close.assert_called_once()
1491+
1492+
14491493
def test_later_pages_are_never_read_from_a_bare_view():
14501494
# Reading past the last page breaks the attempt, so pages after the
14511495
# first come from a verified readback.

0 commit comments

Comments
 (0)