🔒 keep a finished sitting finished when a state frame disagrees
Browse files at this commitb695a7e7ba3d4ec960436ca6f9b342b56692dd0aParent: 63ca057- fix
- 🔒 keep a finished sitting finished when a state frame disagrees
2 changed files +35 -2
src/components/exams/exam-room-ws.test.tsxmodified+28 -0
| @@ -397,3 +397,31 @@ test("an expired frame zeroes the clock and a later state frame does not reopen | |||
| 397 | expect(closedBanners().length).toBeGreaterThan(0); | 397 | expect(closedBanners().length).toBeGreaterThan(0); |
| 398 | expect(choice("Paris").disabled).toBe(true); | 398 | expect(choice("Paris").disabled).toBe(true); |
| 399 | }); | 399 | }); |
| 400 | + | ||
| 401 | +// The other direction of the rejoin hazard: a live-looking `state` frame must | ||
| 402 | +// not un-finish a sitting that is already over. | ||
| 403 | +test("a state frame claiming in_progress cannot reopen a finished sheet", async () => { | ||
| 404 | + await openWritableRoom(); | ||
| 405 | + socket().deliver({ type: "finished", finished_at: Date.now() }); | ||
| 406 | + await tick(); | ||
| 407 | + | ||
| 408 | + socket().deliver(liveState); // status: "in_progress", a full hour left | ||
| 409 | + await tick(); | ||
| 410 | + expect(closedBanners().length).toBeGreaterThan(0); | ||
| 411 | + expect(choice("Paris").disabled).toBe(true); | ||
| 412 | + expect(badge("Submitted")).toBe(true); | ||
| 413 | + expect(badge("00:00:00")).toBe(true); // the countdown does not come back either | ||
| 414 | +}); | ||
| 415 | + | ||
| 416 | +test("a state frame claiming in_progress cannot reopen an expired sheet", async () => { | ||
| 417 | + await openWritableRoom(); | ||
| 418 | + socket().deliver({ type: "expired" }); | ||
| 419 | + await tick(); | ||
| 420 | + | ||
| 421 | + socket().deliver(liveState); | ||
| 422 | + await tick(); | ||
| 423 | + expect(closedBanners().length).toBeGreaterThan(0); | ||
| 424 | + expect(choice("Paris").disabled).toBe(true); | ||
| 425 | + expect(badge("Expired")).toBe(true); | ||
| 426 | + expect(badge("00:00:00")).toBe(true); | ||
| 427 | +}); | ||
src/components/exams/exam-room-ws.tsxmodified+7 -2
| @@ -190,12 +190,17 @@ export function ExamRoomWS(props: { exam: Exam }) { | |||
| 190 | // stamp server-side. Keeping the stale value would leave a student who | 190 | // stamp server-side. Keeping the stale value would leave a student who |
| 191 | // merely reopened the room reading as "left" — every answer disabled | 191 | // merely reopened the room reading as "left" — every answer disabled |
| 192 | // on a sitting the server would still take. | 192 | // on a sitting the server would still take. |
| 193 | + // Terminal is terminal, the other direction of the same hazard: once | ||
| 194 | + // this sitting is submitted or expired, a frame claiming `in_progress` | ||
| 195 | + // must not reopen it — status and clock stay put, only the harmless | ||
| 196 | + // counters catch up. | ||
| 197 | + const over = attempt()?.status === "submitted" || attempt()?.status === "expired"; | ||
| 193 | setAttempt((prev) => | 198 | setAttempt((prev) => |
| 194 | prev | 199 | prev |
| 195 | - ? { ...prev, status: msg.status as any, left_at: null, deadline: msg.deadline, remaining_ms: msg.remaining_ms, answered: msg.answered, question_count: msg.question_count, now: msg.now } | 200 | + ? { ...prev, status: over ? prev.status : (msg.status as any), left_at: null, deadline: msg.deadline, remaining_ms: over ? 0 : msg.remaining_ms, answered: msg.answered, question_count: msg.question_count, now: msg.now } |
| 196 | : prev, | 201 | : prev, |
| 197 | ); | 202 | ); |
| 198 | - setRemainingMs(msg.remaining_ms); | 203 | + setRemainingMs(over ? 0 : msg.remaining_ms); |
| 199 | break; | 204 | break; |
| 200 | } | 205 | } |
| 201 | case "saved": { | 206 | case "saved": { |