@pie-qti/assessment-player 1.0.0-beta.4 → 1.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -7
- package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
- package/dist/components/createPlayerConnection.svelte.js +151 -0
- package/dist/components/createPlayerConnection.svelte.js.map +1 -0
- package/dist/components/displaySettings.svelte.d.ts +23 -0
- package/dist/components/displaySettings.svelte.js +40 -0
- package/dist/components/displaySettings.svelte.js.map +1 -0
- package/dist/components/srOnly.d.ts +29 -0
- package/dist/components/srOnly.js +55 -0
- package/dist/components/srOnly.js.map +1 -0
- package/dist/components/submitDialogAction.d.ts +25 -0
- package/dist/components/submitDialogAction.js +89 -0
- package/dist/components/submitDialogAction.js.map +1 -0
- package/dist/core/AssessmentPlayer.d.ts +1102 -53
- package/dist/core/AssessmentPlayer.js +2835 -460
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
- package/dist/core/AssessmentSessionCoordinator.js +185 -10
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/core/AutosaveManager.d.ts +104 -0
- package/dist/core/AutosaveManager.js +181 -0
- package/dist/core/AutosaveManager.js.map +1 -0
- package/dist/core/ItemSessionController.d.ts +17 -26
- package/dist/core/ItemSessionController.js +33 -73
- package/dist/core/ItemSessionController.js.map +1 -1
- package/dist/core/NavigationManager.d.ts +18 -50
- package/dist/core/NavigationManager.js +21 -83
- package/dist/core/NavigationManager.js.map +1 -1
- package/dist/core/TimeManager.d.ts +62 -16
- package/dist/core/TimeManager.js +148 -57
- package/dist/core/TimeManager.js.map +1 -1
- package/dist/core/autosave.d.ts +44 -0
- package/dist/core/autosave.js +46 -0
- package/dist/core/autosave.js.map +1 -0
- package/dist/core/deliveryStructure.d.ts +54 -0
- package/dist/core/deliveryStructure.js +72 -0
- package/dist/core/deliveryStructure.js.map +1 -0
- package/dist/core/errors.d.ts +116 -0
- package/dist/core/errors.js +77 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exitBoundaries.d.ts +64 -0
- package/dist/core/exitBoundaries.js +98 -0
- package/dist/core/exitBoundaries.js.map +1 -0
- package/dist/core/feedback.d.ts +46 -0
- package/dist/core/feedback.js +47 -0
- package/dist/core/feedback.js.map +1 -0
- package/dist/core/formatTime.d.ts +8 -0
- package/dist/core/formatTime.js +20 -0
- package/dist/core/formatTime.js.map +1 -0
- package/dist/core/index.d.ts +7 -4
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/navigationPolicy.d.ts +42 -0
- package/dist/core/navigationPolicy.js +62 -0
- package/dist/core/navigationPolicy.js.map +1 -0
- package/dist/core/pause.d.ts +58 -0
- package/dist/core/pause.js +101 -0
- package/dist/core/pause.js.map +1 -0
- package/dist/core/playerEvents.d.ts +51 -0
- package/dist/core/playerEvents.js +66 -0
- package/dist/core/playerEvents.js.map +1 -0
- package/dist/core/reviewState.d.ts +81 -0
- package/dist/core/reviewState.js +113 -0
- package/dist/core/reviewState.js.map +1 -0
- package/dist/core/reviewViews.d.ts +43 -0
- package/dist/core/reviewViews.js +88 -0
- package/dist/core/reviewViews.js.map +1 -0
- package/dist/core/scopeLocks.d.ts +36 -0
- package/dist/core/scopeLocks.js +78 -0
- package/dist/core/scopeLocks.js.map +1 -0
- package/dist/core/sessionRecords.d.ts +31 -0
- package/dist/core/sessionRecords.js +74 -0
- package/dist/core/sessionRecords.js.map +1 -0
- package/dist/core/submissionPolicy.d.ts +62 -0
- package/dist/core/submissionPolicy.js +67 -0
- package/dist/core/submissionPolicy.js.map +1 -0
- package/dist/core/templateDefaults.d.ts +26 -0
- package/dist/core/templateDefaults.js +53 -0
- package/dist/core/templateDefaults.js.map +1 -0
- package/dist/core/testStructure.d.ts +118 -3
- package/dist/core/testStructure.js +252 -6
- package/dist/core/testStructure.js.map +1 -1
- package/dist/core/timePolicy.d.ts +40 -0
- package/dist/core/timePolicy.js +106 -0
- package/dist/core/timePolicy.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
- package/dist/integration/ReferenceBackendAdapter.js +216 -1035
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
- package/dist/integration/api-contract.d.ts +179 -17
- package/dist/integration/api-contract.js.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +56 -5
- package/dist/integration/assessment-item-scorer.js +116 -13
- package/dist/integration/assessment-item-scorer.js.map +1 -1
- package/dist/integration/index.d.ts +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/qti-test-parser.d.ts +44 -0
- package/dist/integration/qti-test-parser.js +529 -0
- package/dist/integration/qti-test-parser.js.map +1 -0
- package/dist/integration/session-store.d.ts +54 -0
- package/dist/integration/session-store.js +75 -0
- package/dist/integration/session-store.js.map +1 -0
- package/dist/integration/test-navigation.d.ts +23 -0
- package/dist/integration/test-navigation.js +32 -0
- package/dist/integration/test-navigation.js.map +1 -0
- package/dist/integration/toSectionComposition.js +8 -1
- package/dist/integration/toSectionComposition.js.map +1 -1
- package/dist/reporting/index.d.ts +3 -0
- package/dist/reporting/index.js +3 -0
- package/dist/reporting/index.js.map +1 -0
- package/dist/reporting/inferBaseType.d.ts +13 -0
- package/dist/reporting/inferBaseType.js +26 -0
- package/dist/reporting/inferBaseType.js.map +1 -0
- package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
- package/dist/reporting/serializeAssessmentResult.js +377 -0
- package/dist/reporting/serializeAssessmentResult.js.map +1 -0
- package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
- package/dist/reporting/toAssessmentResultXml.js +304 -0
- package/dist/reporting/toAssessmentResultXml.js.map +1 -0
- package/dist/reporting/types.d.ts +85 -0
- package/dist/reporting/types.js +8 -0
- package/dist/reporting/types.js.map +1 -0
- package/dist/types/index.d.ts +96 -9
- package/dist/types/index.js.map +1 -1
- package/package.json +21 -15
- package/dist/core/StatePersistenceManager.d.ts +0 -125
- package/dist/core/StatePersistenceManager.js +0 -268
- package/dist/core/StatePersistenceManager.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -114
- package/dist/utils/PerformanceMonitor.js +0 -172
- package/dist/utils/PerformanceMonitor.js.map +0 -1
|
@@ -11,13 +11,38 @@ import { createAssessmentItemDefinition, } from '@pie-qti/item-player';
|
|
|
11
11
|
import { DefaultI18nProvider } from '@pie-qti/i18n';
|
|
12
12
|
import { isShownByIdentifier } from '@pie-qti/qti-common';
|
|
13
13
|
import { AssessmentSessionCoordinator } from './AssessmentSessionCoordinator.js';
|
|
14
|
+
import { AssessmentPlayerError, isAssessmentPlayerError } from './errors.js';
|
|
15
|
+
import { attemptFeedbackVisible, resolveMaxAttempts } from './feedback.js';
|
|
14
16
|
import { NavigationManager } from './NavigationManager.js';
|
|
15
|
-
import {
|
|
17
|
+
import { addItemVariableDeclarations, applyVariableMappings, endAttemptInteractionInfo, firstEligibleItem, isAdaptiveItemXml, nextItemIdentifier, recordedItemVariableValues, resolveItemSessionControl, testOutcomeDeclarations, } from './testStructure.js';
|
|
16
18
|
import { extendTimeLimit, TimeManager } from './TimeManager.js';
|
|
19
|
+
import { asResponseValues, cloneData, cloneResponseRecord, closedItemSession, isWritableItemLifecycle, responseDefaultsOf, responseValuesEqual, valuesFromItemSession, } from './sessionRecords.js';
|
|
20
|
+
import { TypedEventEmitter } from './playerEvents.js';
|
|
21
|
+
import { flattenItems, partOrderOf, presentedSectionOf, presentedSections, } from './deliveryStructure.js';
|
|
22
|
+
import { ScopeLocks, isItemLocked, lockingScopeOf, scopeKey, scopeLimitRanOut, } from './scopeLocks.js';
|
|
23
|
+
import { canNavigateByTestPart, isLegalSectionTarget } from './navigationPolicy.js';
|
|
24
|
+
import { branchExitLeavesPart, branchLandingOf, branchTargetIndex, endedEnclosingSection, resolveExitBoundary, } from './exitBoundaries.js';
|
|
25
|
+
import { submissionBlockerFor, submissionGate as submissionGatePolicy, throwForBlockers, } from './submissionPolicy.js';
|
|
26
|
+
import { ReviewInfoCache, resultsSummaryOf, reviewItemRow } from './reviewViews.js';
|
|
27
|
+
import { assertMinTimeElapsed, effectiveItemTimeLimits, submitTimingEvidence, } from './timePolicy.js';
|
|
28
|
+
import { templateDefaultsFor } from './templateDefaults.js';
|
|
29
|
+
import { PauseController } from './pause.js';
|
|
30
|
+
import { createSessionAutosave } from './autosave.js';
|
|
31
|
+
import { interactionRequirementFromXml, itemAnswerStatus, } from './reviewState.js';
|
|
17
32
|
export class AssessmentPlayer {
|
|
18
33
|
static async create(config) {
|
|
19
34
|
const init = await config.backend.initSession(config.initSession);
|
|
20
|
-
|
|
35
|
+
const player = new AssessmentPlayer(config, init);
|
|
36
|
+
// Restored terminal and paused states set no listener off during construction:
|
|
37
|
+
// the host hooks hear them once here, so an embedding (the element's
|
|
38
|
+
// `session-finalized` / `player-pause` events) never misses them.
|
|
39
|
+
if (player.finalized && player.finalResults) {
|
|
40
|
+
config.onFinalized?.({ restored: true, results: player.finalResults });
|
|
41
|
+
}
|
|
42
|
+
else if (player.paused) {
|
|
43
|
+
config.onPauseChange?.(true, player.pauseReason);
|
|
44
|
+
}
|
|
45
|
+
return player;
|
|
21
46
|
}
|
|
22
47
|
constructor(config, init) {
|
|
23
48
|
this.config = config;
|
|
@@ -25,22 +50,136 @@ export class AssessmentPlayer {
|
|
|
25
50
|
this.items = [];
|
|
26
51
|
this.currentItemIndex = -1;
|
|
27
52
|
this.itemDefinitions = new Map();
|
|
53
|
+
/** endAttemptInteraction bindings per item: response identifier → countAttempt. */
|
|
54
|
+
this.endAttemptResponses = new Map();
|
|
28
55
|
this.currentItemSession = null;
|
|
29
56
|
this.currentItemSessionUnsubscribe = null;
|
|
30
57
|
/** Test-level outcomes from the last outcome processing; null until it first runs. */
|
|
31
58
|
this.testOutcomes = null;
|
|
32
59
|
this.finalized = false;
|
|
60
|
+
/** Set by destroy(); a scheduled end-attempt submission after teardown is dropped. */
|
|
61
|
+
this.destroyed = false;
|
|
62
|
+
/** Results produced by the finalization; returned when submit() is called again after the end. */
|
|
63
|
+
this.finalResults = null;
|
|
33
64
|
/** Scopes whose time limit expired without late submission, keyed `scope:identifier`. */
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
this.scopeLocks = new ScopeLocks();
|
|
66
|
+
/**
|
|
67
|
+
* Navigation serialization: exactly one navigation or submission transition may run at
|
|
68
|
+
* a time. While set, further navigation and submit calls are rejected as busy.
|
|
69
|
+
*/
|
|
70
|
+
this.transitionInFlight = false;
|
|
71
|
+
/**
|
|
72
|
+
* Scope-expiry hops waiting for the transition in flight to settle (the timer fired
|
|
73
|
+
* while it ran). The transition checks this to leave the move to the hop, the way it
|
|
74
|
+
* previously detected the move an unlocked hop had already made mid-flight.
|
|
75
|
+
*/
|
|
76
|
+
this.queuedExpiryHops = 0;
|
|
77
|
+
/** Last reported test-level outcome-processing failure, so hosts hear about each new one once. */
|
|
78
|
+
this.reportedOutcomeProcessingError = null;
|
|
79
|
+
/**
|
|
80
|
+
* Test-scope branch rules and preConditions already reported as unevaluable, keyed by
|
|
81
|
+
* condition XML + failure message: the rules re-evaluate on every forward step, and the
|
|
82
|
+
* host must hear about each distinct failed rule once, not on every step.
|
|
83
|
+
*/
|
|
84
|
+
this.reportedTestConditionFailures = new Set();
|
|
85
|
+
/** Item scoring failures already reported, keyed by item identifier + failure message. */
|
|
86
|
+
this.reportedItemScoringErrors = new Set();
|
|
87
|
+
/** False while an opt-in begin gate holds delivery: no item is entered and no clock runs. */
|
|
88
|
+
this.started = true;
|
|
89
|
+
/** The whole-test hard limit expired (no late submission); delivery collects and ends. */
|
|
90
|
+
this.assessmentExpired = false;
|
|
91
|
+
/** The live attempt was suspended by a pause; resume() reopens it from its pause snapshot. */
|
|
92
|
+
this.suspendedForPause = false;
|
|
93
|
+
/** Debounced draft persistence through `saveState` (autosave); null when disabled. */
|
|
94
|
+
this.autosave = null;
|
|
95
|
+
/** True while the session carries a backend-restored snapshot (a resume). */
|
|
96
|
+
this.restoredFromSnapshot = false;
|
|
97
|
+
/**
|
|
98
|
+
* Item feedback the most recent item-level submission produced (item modal feedback
|
|
99
|
+
* from the session's response processing, else the backend's `result.feedback`).
|
|
100
|
+
* Shells show it after a check-answer or a submit-on-move; it clears on the next
|
|
101
|
+
* submission or when the shell dismisses it.
|
|
102
|
+
*/
|
|
103
|
+
this.lastItemFeedback = null;
|
|
104
|
+
/**
|
|
105
|
+
* The responses each item's last counted submission carried. Moving on from an item
|
|
106
|
+
* that already has a recorded result (a practice check) re-submits only when the
|
|
107
|
+
* candidate changed something: an unchanged response does not spend another attempt.
|
|
108
|
+
*/
|
|
109
|
+
this.lastSubmittedResponses = new Map();
|
|
110
|
+
/**
|
|
111
|
+
* Template defaults of nonlinear test parts, evaluated once at part entry for every
|
|
112
|
+
* item ref (QTI): test part identifier → item identifier → defaults.
|
|
113
|
+
*/
|
|
114
|
+
this.templateDefaultsByPart = new Map();
|
|
115
|
+
/** The presentation policy the live session was opened with (null: the item-player default). */
|
|
116
|
+
this.liveSessionPresentation = null;
|
|
117
|
+
/** Set during a proctor force-submit: submissions carry `submissionReason: 'proctor'`. */
|
|
118
|
+
this.administrativeReason = null;
|
|
119
|
+
/**
|
|
120
|
+
* Items the running end of the test collects although their QTI skipping/validation
|
|
121
|
+
* control would refuse them, because the candidate can no longer reach them (their
|
|
122
|
+
* test part was left): they go out as they stand, `submissionReason: 'unreachable'`.
|
|
123
|
+
*/
|
|
124
|
+
this.unreachableCollection = new Set();
|
|
125
|
+
/** Why the running (or finished) end of the test happens; the first caller decides. */
|
|
126
|
+
this.endReason = null;
|
|
127
|
+
/**
|
|
128
|
+
* Scopes that expired while an end of the test ran: they closed at once, but delivery
|
|
129
|
+
* leaves them only if that end does not finalize (the end of the test never navigates).
|
|
130
|
+
*/
|
|
131
|
+
this.expiriesDuringEnd = [];
|
|
132
|
+
/** The delivered items as the delivery rules walk them (index-aligned with `items`). */
|
|
133
|
+
this.deliveredForRules = [];
|
|
134
|
+
/** Flat index per item identifier. */
|
|
135
|
+
this.indexByIdentifier = new Map();
|
|
136
|
+
/**
|
|
137
|
+
* Whether the test carries branch rules or preconditions at all; without them the next item
|
|
138
|
+
* is always the adjacent open one, and no rule is evaluated.
|
|
139
|
+
*/
|
|
140
|
+
this.hasDeliveryRules = false;
|
|
141
|
+
/** Set while the end of the test persists its final snapshot: every item session in it is closed. */
|
|
142
|
+
this.snapshotsCloseItemSessions = false;
|
|
143
|
+
/** Rejections for transitions queued behind a transition (`runWhenIdle`), settled on destroy(). */
|
|
144
|
+
this.queuedIdleTransitions = new Set();
|
|
145
|
+
/** A restored whole-test expiry's automatic finalize is scheduled (or ran). */
|
|
146
|
+
this.restoredExpiryFinalizeScheduled = false;
|
|
147
|
+
// Event listeners (typed emitter; the host-config callbacks stay in the notify helpers)
|
|
148
|
+
this.events = new TypedEventEmitter();
|
|
149
|
+
/** Declared response default values per item (QTI: a response equal to its default is no response). */
|
|
150
|
+
this.responseDefaultsCache = new Map();
|
|
151
|
+
/** The item entry a failed hop will retry: the initial item, or an expiry hop target. */
|
|
152
|
+
this.pendingEntryIndex = null;
|
|
153
|
+
/** The last failed item entry, for the shell's typed failure screen. */
|
|
154
|
+
this.entryError = null;
|
|
155
|
+
/**
|
|
156
|
+
* The reporter the delivery-rules walk (`nextItemIdentifier`, `firstEligibleItem`)
|
|
157
|
+
* hands each unevaluable branch rule or preCondition to. A broken rule reads as false
|
|
158
|
+
* (delivery proceeds on the default path — the same rule never blocks or aborts the
|
|
159
|
+
* test), but the host learns of it through `config.onError` as a coded
|
|
160
|
+
* `testConditionFailed` error, once per distinct failed rule rather than on every
|
|
161
|
+
* re-evaluation.
|
|
162
|
+
*/
|
|
163
|
+
this.reportTestConditionFailure = (conditionXml, error) => {
|
|
164
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
165
|
+
this.reportOnce(this.reportedTestConditionFailures, `${conditionXml}\n${message}`, () => new AssessmentPlayerError('testConditionFailed', message, {}, { cause: error }));
|
|
166
|
+
};
|
|
167
|
+
this.pauseControl = new PauseController({
|
|
168
|
+
isBusy: () => this.transitionInFlight,
|
|
169
|
+
onTransitionActivity: (listener) => this.onBusyChange(listener),
|
|
170
|
+
freeze: () => {
|
|
171
|
+
this.timeManager?.pause();
|
|
172
|
+
this.suspendLiveSessionForPause();
|
|
173
|
+
},
|
|
174
|
+
unfreeze: () => {
|
|
175
|
+
this.timeManager?.resume();
|
|
176
|
+
this.reopenLiveSessionAfterPause();
|
|
177
|
+
},
|
|
178
|
+
unfreezeAllowed: () => this.started && !this.finalized,
|
|
179
|
+
changed: () => this.notifyPauseChange(),
|
|
180
|
+
afterResume: () => this.finalizeRestoredExpiryWhenRunning(),
|
|
181
|
+
isDestroyed: () => this.destroyed,
|
|
182
|
+
});
|
|
44
183
|
this.backend = config.backend;
|
|
45
184
|
this.sessionId = init.sessionId;
|
|
46
185
|
this.assessment = init.assessment;
|
|
@@ -55,191 +194,936 @@ export class AssessmentPlayer {
|
|
|
55
194
|
itemSessions: {},
|
|
56
195
|
timing: { startedAt: Date.now(), itemTimes: {}, totalTime: 0 },
|
|
57
196
|
};
|
|
58
|
-
this.items =
|
|
59
|
-
|
|
60
|
-
|
|
197
|
+
this.items = flattenItems(this.assessment);
|
|
198
|
+
this.deliveredForRules = this.items.map(({ item, testPart, sections }) => ({ item, testPart, sections }));
|
|
199
|
+
for (const q of this.items)
|
|
200
|
+
this.indexByIdentifier.set(q.identifier, q.index);
|
|
201
|
+
this.reviewInfoCache = new ReviewInfoCache(this.items);
|
|
202
|
+
const ruled = (holder) => (holder.preConditions?.length ?? 0) > 0 || (holder.branchRule?.length ?? 0) > 0;
|
|
203
|
+
this.hasDeliveryRules = this.items.some((q) => ruled(q.item) || ruled(q.testPart) || q.sections.some((section) => ruled(section)));
|
|
204
|
+
this.navigationManager = new NavigationManager();
|
|
205
|
+
// Visited marks ride the snapshot: a resumed session keeps them, not only a
|
|
206
|
+
// host-driven restoreState().
|
|
207
|
+
this.navigationManager.restoreState(this.visitedIndexes(initialState.visitedItems));
|
|
61
208
|
// Item session control is a UI hint; backend remains authoritative.
|
|
62
209
|
this.sessionCoordinator = new AssessmentSessionCoordinator({
|
|
63
210
|
state: initialState,
|
|
64
211
|
itemIdentifiers: this.items.map((q) => q.identifier),
|
|
65
212
|
itemSessionControlByItem: Object.fromEntries(this.items.map((q) => [q.identifier, resolveItemSessionControl(q.testPart, q.sections, q.item)])),
|
|
66
213
|
});
|
|
214
|
+
// A resumed session's snapshot carries the test outcomes its submissions produced:
|
|
215
|
+
// the delivery rules read them, so the restored session navigates like the live one.
|
|
216
|
+
if (initialState.testOutcomes) {
|
|
217
|
+
this.testOutcomes = cloneData(initialState.testOutcomes);
|
|
218
|
+
}
|
|
219
|
+
else if (init.outcomes) {
|
|
220
|
+
this.sessionCoordinator.setTestOutcomes(init.outcomes);
|
|
221
|
+
}
|
|
67
222
|
this.timeManager = new TimeManager({
|
|
68
223
|
assessmentTimeLimits: this.assessment.timeLimits,
|
|
69
|
-
|
|
224
|
+
// The default warning (60 s unless the host moves it; 0 turns it off — a 0 threshold
|
|
225
|
+
// never fires), then any additional ones.
|
|
226
|
+
warningThresholds: [config.timeWarningThreshold ?? 60, ...(config.timeWarningThresholds ?? [])],
|
|
70
227
|
now: config.now,
|
|
71
228
|
extendedTime: config.pnp?.content?.extendedTime,
|
|
72
229
|
onWarning: (remainingSeconds) => this.notifyTimeWarning(remainingSeconds),
|
|
73
|
-
onExpired: () => this.
|
|
230
|
+
onExpired: () => this.handleAssessmentTimeExpired(),
|
|
74
231
|
onScopeExpired: (scope, identifier) => this.handleScopeExpired(scope, identifier),
|
|
75
232
|
onTick: (remainingSeconds, elapsedSeconds) => this.notifyTimeTick(remainingSeconds, elapsedSeconds),
|
|
76
233
|
});
|
|
234
|
+
// Items whose recorded result the snapshot carries were submitted with their
|
|
235
|
+
// snapshot responses: identical responses must not re-submit (and re-spend an
|
|
236
|
+
// attempt) on the next move or at finalize after a resume.
|
|
237
|
+
this.seedSubmittedResponses(initialState);
|
|
77
238
|
if (init.restoredState?.timing) {
|
|
78
239
|
this.restoreTimeTracking(init.restoredState.timing);
|
|
240
|
+
// Expiries are not in the snapshot: every scope whose restored clock already ran
|
|
241
|
+
// out locks now, before any item is entered, so none reopens editable.
|
|
242
|
+
this.lockExpiredScopesFromClocks(init.restoredState.timing);
|
|
79
243
|
}
|
|
80
|
-
//
|
|
244
|
+
// A session saved during a proctor pause reopens paused, its clocks frozen.
|
|
245
|
+
this.pauseControl.setFromRestore(init.restoredState?.timing?.isPaused === true, init.restoredState?.timing?.pauseReason);
|
|
246
|
+
this.restoredFromSnapshot = init.restoredState !== undefined;
|
|
247
|
+
this.restoredSavedAt = init.restoredState?.timing?.savedAt;
|
|
248
|
+
this.createAutosave();
|
|
249
|
+
// A session the backend stored as finalized restores terminal: submit() returns
|
|
250
|
+
// the stored results instead of failing, no item is entered, no clock runs, and
|
|
251
|
+
// nothing autosaves. The shell shows its already-submitted view for it.
|
|
252
|
+
if (init.finalized === true) {
|
|
253
|
+
this.finalized = true;
|
|
254
|
+
this.finalResults = this.finalResultsFromInit(init);
|
|
255
|
+
this.autosave?.stop();
|
|
256
|
+
this.timeManager?.pause();
|
|
257
|
+
this.timeManager?.stopTimer();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (config.beginGate === true) {
|
|
261
|
+
// The begin gate holds delivery: no item is entered and no clock runs until start().
|
|
262
|
+
this.started = false;
|
|
263
|
+
this.timeManager.pause();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
this.enterInitialItem();
|
|
267
|
+
this.finalizeRestoredExpiryWhenRunning();
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Enter the backend-provided current item (or the first) as delivery begins. The
|
|
271
|
+
* restoring navigation has no await before the session is attached, so the live
|
|
272
|
+
* session exists when this returns. A failure is recorded (not swallowed): the shell
|
|
273
|
+
* shows its typed failure screen with Retry instead of an eternal loading state.
|
|
274
|
+
* An item an expired limit closed is never entered editable: delivery lands on the
|
|
275
|
+
* next open item, like the live expiry's hop, or — with none left — shows the closed
|
|
276
|
+
* item read-only and asks for the submission (reported once listeners can hear it).
|
|
277
|
+
*/
|
|
278
|
+
enterInitialItem() {
|
|
81
279
|
const startId = this.state.currentItemIdentifier;
|
|
82
280
|
const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
|
|
83
|
-
|
|
84
|
-
|
|
281
|
+
const requested = idx >= 0 ? idx : this.items.length > 0 ? 0 : -1;
|
|
282
|
+
if (requested < 0)
|
|
283
|
+
return;
|
|
284
|
+
const { index: target, deadEnd } = this.restoringEntryTarget(requested);
|
|
285
|
+
this.pendingEntryIndex = target;
|
|
286
|
+
this.performNavigateTo(target, { restoring: true })
|
|
287
|
+
.then(() => {
|
|
288
|
+
if (this.pendingEntryIndex === target)
|
|
289
|
+
this.pendingEntryIndex = null;
|
|
290
|
+
// The shell attaches its listeners right after creation; report the dead end
|
|
291
|
+
// on the next task so it is heard.
|
|
292
|
+
if (deadEnd)
|
|
293
|
+
setTimeout(() => this.notifyExpiryDeadEnd(), 0);
|
|
294
|
+
})
|
|
295
|
+
.catch((error) => {
|
|
296
|
+
this.recordEntryFailure(error);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Where a restoring entry lands: the requested item when it is open; else the open item
|
|
301
|
+
* the live expiry would have moved the candidate to (forward in the part, an open earlier
|
|
302
|
+
* question of a nonlinear part, the next part); else — nothing open remains — the
|
|
303
|
+
* requested item itself, shown read-only, as an expiry dead end.
|
|
304
|
+
*/
|
|
305
|
+
restoringEntryTarget(index) {
|
|
306
|
+
const q = this.items[index];
|
|
307
|
+
if (!q || !this.isItemLocked(q))
|
|
308
|
+
return { index, deadEnd: false };
|
|
309
|
+
const open = this.openItemAfterClosure(index);
|
|
310
|
+
return open >= 0 ? { index: open, deadEnd: false } : { index, deadEnd: true };
|
|
311
|
+
}
|
|
312
|
+
/** Flat indexes of the snapshot's visited item identifiers. */
|
|
313
|
+
visitedIndexes(identifiers) {
|
|
314
|
+
return (identifiers ?? [])
|
|
315
|
+
.map((id) => this.items.findIndex((q) => q.identifier === id))
|
|
316
|
+
.filter((index) => index >= 0);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Lock every scope whose restored clock already ran past its hard maximum (no late
|
|
320
|
+
* submission): its live expiry never fired in this runtime, so without this its items
|
|
321
|
+
* would reopen editable until the next tick. A whole-test limit that ran out marks the
|
|
322
|
+
* test expired. The live timer is told, so it does not fire these expiries again.
|
|
323
|
+
*/
|
|
324
|
+
lockExpiredScopesFromClocks(timing) {
|
|
325
|
+
if (!timing)
|
|
326
|
+
return;
|
|
327
|
+
const extended = this.config.pnp?.content?.extendedTime;
|
|
328
|
+
const ranOut = (limits, elapsedMs) => scopeLimitRanOut(limits, elapsedMs, extended);
|
|
329
|
+
const expired = [];
|
|
330
|
+
const lock = (scope, identifier) => {
|
|
331
|
+
if (this.scopeLocks.lock(scope, identifier))
|
|
332
|
+
expired.push(scopeKey(scope, identifier));
|
|
333
|
+
};
|
|
334
|
+
for (const q of this.items) {
|
|
335
|
+
if (ranOut(q.testPart.timeLimits, timing.testPartTimes?.[q.testPart.identifier])) {
|
|
336
|
+
lock('testPart', q.testPart.identifier);
|
|
337
|
+
}
|
|
338
|
+
for (const section of q.sections) {
|
|
339
|
+
if (ranOut(section.timeLimits, timing.sectionTimes?.[section.identifier]))
|
|
340
|
+
lock('section', section.identifier);
|
|
341
|
+
}
|
|
342
|
+
if (ranOut(q.item.timeLimits, timing.itemTimes?.[q.identifier]))
|
|
343
|
+
lock('item', q.identifier);
|
|
85
344
|
}
|
|
86
|
-
|
|
87
|
-
this.
|
|
345
|
+
if (ranOut(this.assessment.timeLimits, timing.totalTime)) {
|
|
346
|
+
this.assessmentExpired = true;
|
|
347
|
+
expired.push('assessment');
|
|
88
348
|
}
|
|
349
|
+
this.timeManager?.markExpired(expired);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* A whole-test limit that ran out while the session was away finalizes like a live
|
|
353
|
+
* expiry — once delivery runs (not behind a begin gate, not during a pause), and on
|
|
354
|
+
* the next task so the shell's listeners hear it.
|
|
355
|
+
*/
|
|
356
|
+
finalizeRestoredExpiryWhenRunning() {
|
|
357
|
+
if (!this.assessmentExpired || this.restoredExpiryFinalizeScheduled)
|
|
358
|
+
return;
|
|
359
|
+
if (this.finalized || this.destroyed || !this.started || this.paused)
|
|
360
|
+
return;
|
|
361
|
+
this.restoredExpiryFinalizeScheduled = true;
|
|
362
|
+
setTimeout(() => {
|
|
363
|
+
if (this.finalized || this.destroyed || !this.started || this.paused) {
|
|
364
|
+
this.restoredExpiryFinalizeScheduled = false;
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
this.autoFinalizeForTimeExpiry();
|
|
368
|
+
}, 0);
|
|
369
|
+
}
|
|
370
|
+
recordEntryFailure(error) {
|
|
371
|
+
this.entryError = error instanceof Error ? error : new Error(String(error));
|
|
372
|
+
this.config.onError?.(this.entryError);
|
|
373
|
+
}
|
|
374
|
+
/** Whether the last item entry (the first item, or an expiry hop) failed. */
|
|
375
|
+
hasEntryFailure() {
|
|
376
|
+
return this.entryError !== null;
|
|
377
|
+
}
|
|
378
|
+
/** The failed item entry's error, for host logs and localized shell display. */
|
|
379
|
+
getEntryError() {
|
|
380
|
+
return this.entryError;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Retry the failed item entry: re-enter the initial item, or re-run the expiry hop
|
|
384
|
+
* that failed. Serialized with all other transitions; a renewed failure is reported
|
|
385
|
+
* through `onError` and this rejects.
|
|
386
|
+
*/
|
|
387
|
+
async retryEntry() {
|
|
388
|
+
const target = this.pendingEntryIndex;
|
|
389
|
+
this.entryError = null;
|
|
390
|
+
if (target === null || target < 0 || this.destroyed)
|
|
391
|
+
return;
|
|
392
|
+
await this.runExclusive(async () => {
|
|
393
|
+
try {
|
|
394
|
+
await this.performNavigateTo(target, { restoring: true });
|
|
395
|
+
if (this.pendingEntryIndex === target)
|
|
396
|
+
this.pendingEntryIndex = null;
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
// Still broken: the failure is recorded again (the shell's error screen
|
|
400
|
+
// stays) and the rejection surfaces to the caller.
|
|
401
|
+
this.recordEntryFailure(error);
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
404
|
+
});
|
|
89
405
|
}
|
|
90
406
|
get state() {
|
|
91
407
|
return this.sessionCoordinator.state;
|
|
92
408
|
}
|
|
93
|
-
|
|
94
|
-
|
|
409
|
+
/**
|
|
410
|
+
* Whether a navigation or submission transition is currently in flight. Shells must
|
|
411
|
+
* disable navigation controls while this is set.
|
|
412
|
+
*/
|
|
413
|
+
isBusy() {
|
|
414
|
+
return this.transitionInFlight;
|
|
95
415
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
416
|
+
/**
|
|
417
|
+
* Serialize navigation and submission transitions. Exactly one transition runs at a
|
|
418
|
+
* time; concurrent navigation or submit calls reject with a typed `navigationInFlight`
|
|
419
|
+
* error instead of racing the in-flight backend request. The in-flight flag is set
|
|
420
|
+
* inside the try so nothing before the operation — a throwing listener included —
|
|
421
|
+
* can leave it stuck true (every later transition would then be rejected as busy
|
|
422
|
+
* forever); the `finally` always resets it.
|
|
423
|
+
*/
|
|
424
|
+
async runExclusive(operation) {
|
|
425
|
+
if (this.transitionInFlight) {
|
|
426
|
+
throw new AssessmentPlayerError('navigationInFlight', 'A navigation or submission transition is already in progress.');
|
|
427
|
+
}
|
|
428
|
+
try {
|
|
429
|
+
this.transitionInFlight = true;
|
|
430
|
+
this.notifyBusyChange(true);
|
|
431
|
+
return await operation();
|
|
432
|
+
}
|
|
433
|
+
finally {
|
|
434
|
+
this.transitionInFlight = false;
|
|
435
|
+
this.notifyBusyChange(false);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* A candidate-initiated transition (navigation, submission): rejected with a coded
|
|
440
|
+
* error during a proctor pause or before the begin gate opens, otherwise serialized
|
|
441
|
+
* like every transition.
|
|
442
|
+
*/
|
|
443
|
+
runCandidateTransition(operation) {
|
|
444
|
+
try {
|
|
445
|
+
this.assertCandidateActionAllowed();
|
|
446
|
+
}
|
|
447
|
+
catch (error) {
|
|
448
|
+
return Promise.reject(error);
|
|
449
|
+
}
|
|
450
|
+
return this.runExclusive(operation);
|
|
451
|
+
}
|
|
452
|
+
/** Whether a proctor pause is in force (owned by `PauseController`). */
|
|
453
|
+
get paused() {
|
|
454
|
+
return this.pauseControl.paused;
|
|
455
|
+
}
|
|
456
|
+
/** The candidate-facing reason given for the current pause, if any. */
|
|
457
|
+
get pauseReason() {
|
|
458
|
+
return this.pauseControl.reason;
|
|
459
|
+
}
|
|
460
|
+
assertCandidateActionAllowed() {
|
|
461
|
+
if (this.paused) {
|
|
462
|
+
throw new AssessmentPlayerError('assessmentPaused', 'The assessment is paused.');
|
|
463
|
+
}
|
|
464
|
+
if (!this.started) {
|
|
465
|
+
throw new AssessmentPlayerError('navigationNotAllowed', 'The assessment has not started yet.');
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// ---------------------------------------------------------------------------
|
|
469
|
+
// Autosave: debounced draft persistence through BackendAdapter.saveState
|
|
470
|
+
// ---------------------------------------------------------------------------
|
|
471
|
+
/**
|
|
472
|
+
* Create the autosave engine. ON by default when the backend reports the save
|
|
473
|
+
* capability (`canSaveState !== false`); `config.autosave === false` disables it
|
|
474
|
+
* for hosts that persist state themselves.
|
|
475
|
+
*/
|
|
476
|
+
createAutosave() {
|
|
477
|
+
this.autosave = createSessionAutosave({
|
|
478
|
+
autosave: this.config.autosave,
|
|
479
|
+
autosaveIntervalMs: this.config.autosaveIntervalMs,
|
|
480
|
+
canSaveState: this.backend.canSaveState,
|
|
481
|
+
sessionId: this.sessionId,
|
|
482
|
+
getSnapshot: () => this.getState({ includeItemSessions: true }),
|
|
483
|
+
snapshotsCloseItemSessions: () => this.snapshotsCloseItemSessions,
|
|
484
|
+
isBlocked: () => this.transitionInFlight,
|
|
485
|
+
isStopped: () => this.destroyed || this.finalized,
|
|
486
|
+
saveState: (request) => this.backend.saveState(request),
|
|
487
|
+
onStateChange: (state) => this.notifyAutosaveChange(state),
|
|
488
|
+
onError: (error) => this.config.onAutosaveFailed?.(error),
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
/** A due save is deferred while a transition runs and retried once it settles. */
|
|
492
|
+
notifyAutosaveActivity() {
|
|
493
|
+
this.autosave?.notify();
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Save the current draft immediately (best-effort): the shell calls this from
|
|
497
|
+
* `visibilitychange`/`pagehide`, and hosts may call it before their own teardown.
|
|
498
|
+
* While a transition is in flight the save is re-queued instead of racing it.
|
|
499
|
+
* Resolves once a save attempt settled (or immediately when autosave is off).
|
|
500
|
+
*/
|
|
501
|
+
flushAutosave() {
|
|
502
|
+
return this.autosave?.flush() ?? Promise.resolve();
|
|
503
|
+
}
|
|
504
|
+
/** The current save-indicator state (`idle` when autosave is disabled). */
|
|
505
|
+
getAutosaveState() {
|
|
506
|
+
return this.autosave?.getState() ?? { status: 'idle' };
|
|
507
|
+
}
|
|
508
|
+
/** Whether autosave is active for this session (backend capability + config). */
|
|
509
|
+
isAutosaveEnabled() {
|
|
510
|
+
return this.autosave !== null;
|
|
511
|
+
}
|
|
512
|
+
/** Fires on every save-indicator state change. */
|
|
513
|
+
onAutosaveChange(listener) {
|
|
514
|
+
return this.events.on('autosaveChange', listener);
|
|
515
|
+
}
|
|
516
|
+
notifyAutosaveChange(state) {
|
|
517
|
+
this.events.emit('autosaveChange', state);
|
|
518
|
+
this.config.onAutosaveChange?.(state);
|
|
519
|
+
}
|
|
520
|
+
// ---------------------------------------------------------------------------
|
|
521
|
+
// Resume + start over
|
|
522
|
+
// ---------------------------------------------------------------------------
|
|
523
|
+
/**
|
|
524
|
+
* Whether the session was created from a backend snapshot that already carries
|
|
525
|
+
* candidate work (a resume worth offering: saved answers). Shells show their
|
|
526
|
+
* resume prompt from this. Elapsed time alone does not count: a session that was
|
|
527
|
+
* merely started (or started over) has nothing to resume.
|
|
528
|
+
*/
|
|
529
|
+
hasRestoredProgress() {
|
|
530
|
+
if (!this.restoredFromSnapshot)
|
|
531
|
+
return false;
|
|
532
|
+
const responses = this.state.itemResponses ?? {};
|
|
533
|
+
return Object.values(responses).some((responsesForItem) => responsesForItem !== undefined && Object.keys(responsesForItem).length > 0);
|
|
534
|
+
}
|
|
535
|
+
/** When the restored snapshot was last saved (client clock), for the resume prompt. */
|
|
536
|
+
getRestoredSavedAt() {
|
|
537
|
+
return this.hasRestoredProgress() ? this.restoredSavedAt : undefined;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Discard the candidate's draft and restart delivery. Start over clears what the
|
|
541
|
+
* candidate authored and the backend has not accepted — responses, flags, comments,
|
|
542
|
+
* visited state, the timer preference and unrecorded check state — and persists the
|
|
543
|
+
* blank draft at once. It keeps the time accounting: every clock, each expired scope
|
|
544
|
+
* and a whole-test expiry persist, so restarting never grants a fresh time allowance
|
|
545
|
+
* after the questions were seen. Items the backend already accepted keep their
|
|
546
|
+
* recorded results (the backend stays authoritative for them). Delivery repositions
|
|
547
|
+
* to the first item that is still open; when none is, the closed item is shown
|
|
548
|
+
* read-only and the expiry's submit path is requested again (`onTimeExpired` with
|
|
549
|
+
* `submissionRequired`). Rejects while paused, behind a begin gate, once finalized,
|
|
550
|
+
* and while another transition runs.
|
|
551
|
+
*/
|
|
552
|
+
async startOver() {
|
|
553
|
+
return this.runCandidateTransition(async () => {
|
|
554
|
+
if (this.finalized) {
|
|
555
|
+
throw new AssessmentPlayerError('testFinalized', 'Cannot start over: the assessment has ended.');
|
|
112
556
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
557
|
+
const snapshot = this.getState({ includeItemSessions: true });
|
|
558
|
+
// Test parts are delivered in order and a left part is never re-entered — not
|
|
559
|
+
// even by a restart. The restart covers the furthest part reached and what
|
|
560
|
+
// follows; questions of parts already left stay closed exactly as they stand
|
|
561
|
+
// (the end of the test collects them so), visited marks included.
|
|
562
|
+
const reachedIndex = Math.max(this.currentItemIndex, ...this.navigationManager.getVisited(), 0);
|
|
563
|
+
const reachedPart = partOrderOf(this.assessment, this.items[reachedIndex]);
|
|
564
|
+
const left = new Set(this.items.filter((q) => partOrderOf(this.assessment, q) < reachedPart).map((q) => q.identifier));
|
|
565
|
+
// Accepted items keep their recorded state; everything else is the draft.
|
|
566
|
+
const accepted = new Set(this.items.filter((q) => this.sessionCoordinator.hasItemResult(q.identifier)).map((q) => q.identifier));
|
|
567
|
+
const keepAccepted = (record) => Object.fromEntries(Object.entries(record ?? {}).filter(([identifier]) => accepted.has(identifier) || left.has(identifier)));
|
|
568
|
+
const keepLeft = (record) => Object.fromEntries(Object.entries(record ?? {}).filter(([identifier]) => left.has(identifier)));
|
|
569
|
+
const fresh = {
|
|
570
|
+
currentItemIdentifier: this.items[0]?.identifier ?? '',
|
|
571
|
+
visitedItems: snapshot.visitedItems.filter((identifier) => left.has(identifier)),
|
|
572
|
+
itemResponses: keepAccepted(snapshot.itemResponses),
|
|
573
|
+
itemScores: keepAccepted(snapshot.itemScores),
|
|
574
|
+
itemSessions: keepAccepted(snapshot.itemSessions),
|
|
575
|
+
itemSessionStates: keepAccepted(snapshot.itemSessionStates),
|
|
576
|
+
itemFlags: keepLeft(snapshot.itemFlags),
|
|
577
|
+
itemComments: keepLeft(snapshot.itemComments),
|
|
578
|
+
// The clocks continue: the live TimeManager is not reset, and the draft's
|
|
579
|
+
// timing reflects it.
|
|
580
|
+
timing: snapshot.timing,
|
|
581
|
+
};
|
|
582
|
+
// Replaces coordinator state (responses, sessions, results, flags) and clears
|
|
583
|
+
// visited/navigation state beyond the left parts. Locked scopes, the whole-test
|
|
584
|
+
// expiry and the timer's fired-limit record stay as they are.
|
|
585
|
+
this.sessionCoordinator.restoreState(fresh);
|
|
586
|
+
this.navigationManager.restoreState(this.visitedIndexes(fresh.visitedItems));
|
|
587
|
+
// (A pause cannot be in force here: startOver is a candidate transition, and a
|
|
588
|
+
// pause requested while it runs applies once it settles.)
|
|
589
|
+
// The resumable draft is gone; the shell's resume prompt must not reappear.
|
|
590
|
+
this.restoredFromSnapshot = false;
|
|
591
|
+
this.restoredSavedAt = undefined;
|
|
592
|
+
// Unrecorded check state goes with the draft; the memory of accepted responses stays.
|
|
593
|
+
for (const identifier of [...this.lastSubmittedResponses.keys()]) {
|
|
594
|
+
if (!accepted.has(identifier))
|
|
595
|
+
this.lastSubmittedResponses.delete(identifier);
|
|
120
596
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
597
|
+
this.lastItemFeedback = null;
|
|
598
|
+
this.templateDefaultsByPart.clear();
|
|
599
|
+
// Delivery repositions to the first open item of the furthest part reached (else
|
|
600
|
+
// the first open item after it); with none left, the expiry dead end: the
|
|
601
|
+
// candidate's way out is the submission.
|
|
602
|
+
const inReach = (q) => partOrderOf(this.assessment, q) >= reachedPart;
|
|
603
|
+
const inPart = this.items.findIndex((q) => partOrderOf(this.assessment, q) === reachedPart && this.isOpenTarget(q));
|
|
604
|
+
const firstOpen = inPart >= 0 ? inPart : this.items.findIndex((q) => partOrderOf(this.assessment, q) > reachedPart && !this.isItemLocked(q));
|
|
605
|
+
const target = firstOpen >= 0 ? firstOpen : Math.max(0, this.items.findIndex(inReach));
|
|
606
|
+
if (this.items[target]) {
|
|
607
|
+
this.sessionCoordinator.setCurrentItem(this.items[target].identifier);
|
|
608
|
+
await this.performNavigateTo(target, { restoring: true });
|
|
609
|
+
if (firstOpen < 0)
|
|
610
|
+
this.notifyExpiryDeadEnd();
|
|
124
611
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
612
|
+
// Persist the blank draft now so a refresh cannot resurrect the discarded answers.
|
|
613
|
+
await this.autosave?.flushImmediate();
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
getEffectiveItemTimeLimits(flat) {
|
|
617
|
+
return effectiveItemTimeLimits(flat, this.assessment.timeLimits, this.config.pnp?.content?.extendedTime);
|
|
130
618
|
}
|
|
131
619
|
getCurrentEffectiveTimeLimits() {
|
|
132
620
|
const q = this.items[this.currentItemIndex];
|
|
133
621
|
return q ? this.getEffectiveItemTimeLimits(q) : {};
|
|
134
622
|
}
|
|
135
|
-
getSubmitTimingEvidence(q, elapsedMs) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const tracked = this.timeManager?.getScopeElapsedMs(effective.source, scopeIdentifier);
|
|
148
|
-
const scopedElapsedMs = tracked ?? elapsedMs;
|
|
149
|
-
return {
|
|
150
|
-
scope: effective.source,
|
|
151
|
-
elapsedMs: scopedElapsedMs,
|
|
152
|
-
limitSeconds,
|
|
153
|
-
expired: scopedElapsedMs >= limitSeconds * 1000,
|
|
154
|
-
allowLateSubmission: effective.timeLimits?.allowLateSubmission,
|
|
155
|
-
};
|
|
623
|
+
getSubmitTimingEvidence(q, elapsedMs, submissionReason) {
|
|
624
|
+
return submitTimingEvidence({
|
|
625
|
+
q,
|
|
626
|
+
effective: this.getEffectiveItemTimeLimits(q),
|
|
627
|
+
elapsedMs,
|
|
628
|
+
scopeElapsedMs: (scope, identifier) => this.timeManager?.getScopeElapsedMs(scope, identifier),
|
|
629
|
+
assessmentLimitSeconds: this.assessment.timeLimits?.maxTime === undefined
|
|
630
|
+
? undefined
|
|
631
|
+
: extendTimeLimit(this.assessment.timeLimits.maxTime, this.config.pnp?.content?.extendedTime),
|
|
632
|
+
assessmentElapsedMs: this.timeManager ? this.timeManager.getScopeElapsedMs('assessment') : undefined,
|
|
633
|
+
submissionReason,
|
|
634
|
+
});
|
|
156
635
|
}
|
|
157
|
-
assertMinimumTime(scope, q) {
|
|
636
|
+
assertMinimumTime(scope, q, section = q.section) {
|
|
158
637
|
const limits = scope === 'assessment'
|
|
159
638
|
? this.assessment.timeLimits
|
|
160
639
|
: scope === 'testPart'
|
|
161
640
|
? q.testPart.timeLimits
|
|
162
641
|
: scope === 'section'
|
|
163
|
-
?
|
|
642
|
+
? section.timeLimits
|
|
164
643
|
: q.item.timeLimits;
|
|
165
644
|
if (limits?.minTime === undefined)
|
|
166
645
|
return;
|
|
167
646
|
const identifier = scope === 'testPart'
|
|
168
647
|
? q.testPart.identifier
|
|
169
648
|
: scope === 'section'
|
|
170
|
-
?
|
|
649
|
+
? section.identifier
|
|
171
650
|
: scope === 'item'
|
|
172
651
|
? q.identifier
|
|
173
652
|
: undefined;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
653
|
+
assertMinTimeElapsed(scope, limits, this.timeManager?.getScopeElapsedMs(scope, identifier) ?? 0);
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Every enclosing section's minimum time gates leaving it: a transition out of an
|
|
657
|
+
* enclosing scope (another section, another test part, or the end of the test) waits
|
|
658
|
+
* for the outer sections' minimums too, not only the innermost section's.
|
|
659
|
+
*/
|
|
660
|
+
assertEnclosingSectionMinimumTime(q, target) {
|
|
661
|
+
for (const section of q.sections) {
|
|
662
|
+
if (target?.sections.some((enclosing) => enclosing.identifier === section.identifier))
|
|
663
|
+
continue;
|
|
664
|
+
this.assertMinimumTime('section', q, section);
|
|
178
665
|
}
|
|
179
666
|
}
|
|
180
667
|
assertTransitionMinimum(current, target) {
|
|
181
668
|
if (current === target)
|
|
182
669
|
return;
|
|
183
670
|
this.assertMinimumTime('item', current);
|
|
184
|
-
|
|
185
|
-
this.assertMinimumTime('section', current);
|
|
671
|
+
this.assertEnclosingSectionMinimumTime(current, target);
|
|
186
672
|
if (current.testPart !== target.testPart)
|
|
187
673
|
this.assertMinimumTime('testPart', current);
|
|
188
674
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
675
|
+
/**
|
|
676
|
+
* Whether an item still owes the backend a submission: it has no recorded result yet
|
|
677
|
+
* (the candidate left it open, answered or not), or its live responses differ from the
|
|
678
|
+
* ones its last counted submission carried (a practice answer revised after the
|
|
679
|
+
* check, or a revised answer a nonlinear jump left behind). Unchanged responses are
|
|
680
|
+
* never re-sent, so an accepted item spends no extra attempt here.
|
|
681
|
+
*/
|
|
682
|
+
itemNeedsSubmission(q) {
|
|
683
|
+
if (!this.sessionCoordinator.hasItemResult(q.identifier))
|
|
684
|
+
return true;
|
|
685
|
+
return !this.responsesUnchangedSinceSubmission(q.identifier, this.sessionCoordinator.getResponses(q.identifier));
|
|
686
|
+
}
|
|
687
|
+
isIndividual(q) {
|
|
688
|
+
return q.testPart.submissionMode === 'individual';
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Whether submissions carry the serialized item session: always for a backend that
|
|
692
|
+
* scores from it (`requiresItemSession` — the reference adapter: a templated item must be
|
|
693
|
+
* scored against the instance the candidate saw), else as the host configured.
|
|
694
|
+
*/
|
|
695
|
+
sendsItemSession() {
|
|
696
|
+
return this.backend.requiresItemSession === true || this.config.sendItemSessionToBackend === true;
|
|
697
|
+
}
|
|
698
|
+
/** The item's current responses: the live session's for the active item, else the stored ones. */
|
|
699
|
+
currentResponsesFor(q) {
|
|
700
|
+
if (this.items[this.currentItemIndex] === q && this.currentItemSession) {
|
|
701
|
+
return cloneResponseRecord(this.currentItemSession.state().responses);
|
|
702
|
+
}
|
|
703
|
+
return this.sessionCoordinator.getResponses(q.identifier);
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* QTI itemSessionControl `allowSkipping` / `validateResponses` for one item's
|
|
707
|
+
* responses. Both are "only applicable when the item is in a testPart with individual
|
|
708
|
+
* submission mode", so a simultaneous part is never gated. A skipped item (no
|
|
709
|
+
* response at all: every response NULL, empty or still equal to its declared default —
|
|
710
|
+
* the test `numberResponded` applies) may be submitted only when skipping is allowed,
|
|
711
|
+
* and is then not validated; an answered item validates when the item asks for it.
|
|
712
|
+
*/
|
|
713
|
+
submissionGate(q, responses) {
|
|
714
|
+
return submissionGatePolicy({
|
|
715
|
+
individual: this.isIndividual(q),
|
|
716
|
+
settings: this.sessionCoordinator.getItemSettings(q.identifier),
|
|
717
|
+
responses,
|
|
718
|
+
defaults: this.responseDefaultsFor(q),
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* The declared default of each response variable, as the item's own session holds it
|
|
723
|
+
* (template processing may set it): the live session for the active item, the persisted
|
|
724
|
+
* handoff otherwise, else — for an item never opened — a fresh session's declarations.
|
|
725
|
+
*/
|
|
726
|
+
responseDefaultsFor(q) {
|
|
727
|
+
const live = this.items[this.currentItemIndex] === q ? this.currentItemSession : null;
|
|
728
|
+
const serialized = live ? live.serialize() : this.state.itemSessions?.[q.identifier];
|
|
729
|
+
if (serialized)
|
|
730
|
+
return responseDefaultsOf(serialized);
|
|
731
|
+
const cached = this.responseDefaultsCache.get(q.identifier);
|
|
732
|
+
if (cached)
|
|
733
|
+
return cached;
|
|
734
|
+
let defaults = {};
|
|
735
|
+
let session = null;
|
|
736
|
+
try {
|
|
737
|
+
session = this.getItemDefinition(q).openSession({});
|
|
738
|
+
defaults = responseDefaultsOf(session.serialize());
|
|
739
|
+
}
|
|
740
|
+
catch {
|
|
741
|
+
// An item that cannot even open has no defaults to honour; the gate stays NULL-based.
|
|
742
|
+
}
|
|
743
|
+
finally {
|
|
744
|
+
session?.dispose();
|
|
745
|
+
}
|
|
746
|
+
this.responseDefaultsCache.set(q.identifier, defaults);
|
|
747
|
+
return defaults;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* The item's response validation (a QTI valid response: every value well-formed and,
|
|
751
|
+
* where an interaction requires input — minChoices, minStrings, matchMin… — complete),
|
|
752
|
+
* checked on a detached session so the live attempt is untouched. Null when nothing is
|
|
753
|
+
* left to validate: the attempt already closed (accepted as it is), or the session could
|
|
754
|
+
* not be opened (the submission reports that, the gate invents no failure).
|
|
755
|
+
*/
|
|
756
|
+
responseValidationFor(q) {
|
|
757
|
+
const live = this.items[this.currentItemIndex] === q ? this.currentItemSession : null;
|
|
758
|
+
const restore = live ? live.serialize() : this.state.itemSessions?.[q.identifier];
|
|
759
|
+
let session = null;
|
|
760
|
+
try {
|
|
761
|
+
session = this.getItemDefinition(q).openSession({
|
|
762
|
+
restore,
|
|
763
|
+
responses: live ? undefined : this.sessionCoordinator.getResponses(q.identifier),
|
|
764
|
+
activate: true,
|
|
765
|
+
});
|
|
766
|
+
if (!isWritableItemLifecycle(session.state().lifecycleStatus))
|
|
767
|
+
return null;
|
|
768
|
+
const validation = session.dispatch({ action: 'suspendAttempt' }).result?.validation;
|
|
769
|
+
if (!validation)
|
|
770
|
+
return null;
|
|
771
|
+
const unmet = Object.values(validation.entries).find((entry) => !entry.valid || (entry.required && !entry.complete));
|
|
772
|
+
if (validation.valid && !unmet)
|
|
773
|
+
return { ok: true };
|
|
774
|
+
const constraint = unmet?.valid ? interactionRequirementFromXml(q.item.itemXml, unmet.responseId) : undefined;
|
|
775
|
+
return { ok: false, requirement: constraint ?? { kind: 'incomplete' } };
|
|
776
|
+
}
|
|
777
|
+
catch {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
finally {
|
|
781
|
+
session?.dispose();
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
/** Whether the item's responses satisfy their interactions' constraints (see `responseValidationFor`). */
|
|
785
|
+
responsesSatisfyConstraints(q) {
|
|
786
|
+
return this.responseValidationFor(q)?.ok !== false;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Whether the end of the test would submit this item: mirrors `endTestInternal`'s
|
|
790
|
+
* collection — the open current item without an accepted (unchanged) result, and every
|
|
791
|
+
* visited individual-mode item whose responses the backend has not accepted yet.
|
|
792
|
+
*/
|
|
793
|
+
wouldCollectAtFinalize(q) {
|
|
794
|
+
if (!this.isIndividual(q) || this.isItemLocked(q))
|
|
795
|
+
return false;
|
|
796
|
+
if (q.index === this.currentItemIndex) {
|
|
797
|
+
if (!this.sessionCoordinator.hasItemResult(q.identifier))
|
|
798
|
+
return true;
|
|
799
|
+
const status = this.currentItemSession?.state().lifecycleStatus;
|
|
800
|
+
return (status !== undefined &&
|
|
801
|
+
isWritableItemLifecycle(status) &&
|
|
802
|
+
this.sessionCoordinator.canSubmit(q.identifier) &&
|
|
803
|
+
!this.responsesUnchangedSinceSubmission(q.identifier));
|
|
804
|
+
}
|
|
805
|
+
return this.navigationManager.isVisited(q.index) && this.itemNeedsSubmission(q);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* The QTI submission control that would refuse this item's submission now, if any:
|
|
809
|
+
* `required` (allowSkipping=false, no response) or `invalid` (validateResponses=true,
|
|
810
|
+
* responses that do not satisfy the interactions), with what the response still owes.
|
|
811
|
+
*/
|
|
812
|
+
blockerFor(q) {
|
|
813
|
+
const gate = this.submissionGate(q, this.currentResponsesFor(q));
|
|
814
|
+
let reason = gate.mustAnswer ? 'required' : null;
|
|
815
|
+
let requirement;
|
|
816
|
+
if (!reason && gate.validate) {
|
|
817
|
+
const validation = this.responseValidationFor(q);
|
|
818
|
+
if (validation && !validation.ok) {
|
|
819
|
+
reason = 'invalid';
|
|
820
|
+
requirement = validation.requirement;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (!reason)
|
|
824
|
+
return null;
|
|
825
|
+
return submissionBlockerFor(q, reason, requirement, this.isNavigationTargetLegal(q.index));
|
|
826
|
+
}
|
|
827
|
+
/** Every item the end of the test would collect against its submission controls, reachable or not. */
|
|
828
|
+
blockerCandidates(filter = () => true) {
|
|
829
|
+
if (this.finalized)
|
|
830
|
+
return [];
|
|
831
|
+
const blockers = [];
|
|
832
|
+
for (const q of this.items) {
|
|
833
|
+
if (!filter(q) || !this.wouldCollectAtFinalize(q))
|
|
834
|
+
continue;
|
|
835
|
+
const blocker = this.blockerFor(q);
|
|
836
|
+
if (blocker)
|
|
837
|
+
blockers.push(blocker);
|
|
838
|
+
}
|
|
839
|
+
return blockers;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Items a candidate-initiated end of the test would refuse to submit: in individual
|
|
843
|
+
* parts, an item without any response while `allowSkipping=false` (`required`), or an
|
|
844
|
+
* answered item whose responses fail validation while `validateResponses=true`
|
|
845
|
+
* (`invalid`). Only items the end of the test would actually submit are considered
|
|
846
|
+
* (presented ones the backend has not accepted), and only those the candidate can still
|
|
847
|
+
* reach: a question in a test part already left cannot hold Submit — it is collected as
|
|
848
|
+
* it stands (`getUnreachableSubmissionBlockers()`, `submissionReason: 'unreachable'`).
|
|
849
|
+
* An item an expired limit closed is collected as it stands too. Empty once the delivery
|
|
850
|
+
* is closed by time or finalized. Shells list these in the submit confirmation;
|
|
851
|
+
* `submit()` rejects naming them.
|
|
852
|
+
*/
|
|
853
|
+
getSubmissionBlockers() {
|
|
854
|
+
if (this.isTimeClosedDelivery())
|
|
855
|
+
return [];
|
|
856
|
+
return this.blockerCandidates().filter((blocker) => blocker.reachable);
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Questions the end of the test collects although their QTI skipping/validation control
|
|
860
|
+
* would refuse them, because the candidate can no longer reach them (their test part was
|
|
861
|
+
* left — a session restored from before the leave gate, a branch rule). They never hold
|
|
862
|
+
* Submit: the end of the test sends them as they stand with `submissionReason: 'unreachable'`.
|
|
863
|
+
*/
|
|
864
|
+
getUnreachableSubmissionBlockers() {
|
|
865
|
+
return this.blockerCandidates().filter((blocker) => !blocker.reachable);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Questions of the current test part that would be left behind owing an answer: QTI
|
|
869
|
+
* parts cannot be re-entered, so leaving an individual part with them would strand them.
|
|
870
|
+
* The shell's "Leave this part?" confirmation lists them (with jumps) and holds Continue;
|
|
871
|
+
* `next()` / `navigateTo()` refuse to leave the part while any remains
|
|
872
|
+
* (`leavePartResponseRequired` / `leavePartResponseInvalid`). Only questions the
|
|
873
|
+
* candidate can still reach count — one behind them in a linear part (a session restored
|
|
874
|
+
* from before this gate) could never be answered, so it cannot hold the way out; the end
|
|
875
|
+
* of the test collects it as it stands (`unreachable`). Empty for a simultaneous part
|
|
876
|
+
* (QTI: the controls do not apply), once finalized, and in a time-closed delivery.
|
|
877
|
+
*/
|
|
878
|
+
getTestPartBlockers() {
|
|
879
|
+
const current = this.items[this.currentItemIndex];
|
|
880
|
+
if (!current || this.isTimeClosedDelivery())
|
|
881
|
+
return [];
|
|
882
|
+
return this.blockerCandidates((q) => q.testPart === current.testPart).filter((blocker) => blocker.reachable);
|
|
883
|
+
}
|
|
884
|
+
/** Reject a candidate-initiated end of the test that would submit held-back items, naming them. */
|
|
885
|
+
assertNoSubmissionBlockers() {
|
|
886
|
+
this.throwForBlockers(this.getSubmissionBlockers(), 'finalize');
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Reject leaving the test part `from` belongs to while questions in it (or, for an
|
|
890
|
+
* EXIT_SECTION, in the ended scope) still owe an answer the candidate can still give.
|
|
891
|
+
* `exclude` is the item the move itself submits (next() submits the current item before
|
|
892
|
+
* it moves). An unreachable question never holds the way out (see `getTestPartBlockers`).
|
|
893
|
+
*/
|
|
894
|
+
assertCanLeaveScope(from, options = {}) {
|
|
895
|
+
if (!this.isIndividual(from))
|
|
896
|
+
return;
|
|
897
|
+
const inScope = options.scope ?? ((q) => q.testPart === from.testPart);
|
|
898
|
+
this.throwForBlockers(this.blockerCandidates((q) => q !== options.exclude && inScope(q)).filter((blocker) => blocker.reachable), 'leavePart');
|
|
899
|
+
}
|
|
900
|
+
throwForBlockers(blockers, context) {
|
|
901
|
+
throwForBlockers(blockers, context);
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* QTI feedback visibility is attempt-relative: with more than one attempt allowed,
|
|
905
|
+
* feedback for every non-final attempt must be shown; once the last attempt has
|
|
906
|
+
* ended, `showFeedback` governs. Adaptive items always show their feedback.
|
|
907
|
+
* `attemptsAfter` counts the attempts once the attempt being judged has ended.
|
|
908
|
+
*/
|
|
909
|
+
feedbackVisible(q, attemptsAfter) {
|
|
910
|
+
const control = this.sessionCoordinator.getItemSettings(q.identifier);
|
|
911
|
+
const adaptive = isAdaptiveItemXml(q.item.itemXml);
|
|
912
|
+
return attemptFeedbackVisible({
|
|
913
|
+
showFeedback: control.showFeedback === true,
|
|
914
|
+
maxAttempts: resolveMaxAttempts(control, adaptive),
|
|
915
|
+
attempts: attemptsAfter,
|
|
916
|
+
adaptive,
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Sections presented to the candidate: visible themselves and under visible ancestors.
|
|
921
|
+
* A QTI `visible="false"` section is not presented as a section — its content appears as
|
|
922
|
+
* part of the parent — so neither it nor its descendants surface a title here. Items
|
|
923
|
+
* inside keep being delivered in order.
|
|
924
|
+
*/
|
|
925
|
+
presentedSectionList() {
|
|
926
|
+
return presentedSections(this.assessment);
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Whether jumping to a presented section is legal right now: in linear navigation there
|
|
930
|
+
* is no jumping at all; in nonlinear navigation only sections of the current test part
|
|
931
|
+
* are reachable, never locked items or items review has closed. Finalized tests have no
|
|
932
|
+
* legal targets.
|
|
933
|
+
*/
|
|
934
|
+
isLegalSectionTarget(section) {
|
|
935
|
+
return isLegalSectionTarget({
|
|
936
|
+
section,
|
|
937
|
+
items: this.items,
|
|
938
|
+
finalized: this.finalized,
|
|
939
|
+
currentIndex: this.currentItemIndex,
|
|
940
|
+
isItemLocked: (q) => this.isItemLocked(q),
|
|
941
|
+
canReviewItem: (q) => this.canReviewItem(q),
|
|
202
942
|
});
|
|
203
943
|
}
|
|
204
944
|
// ---------------------------------------------------------------------------
|
|
205
945
|
// Public API used by components
|
|
206
946
|
// ---------------------------------------------------------------------------
|
|
947
|
+
/**
|
|
948
|
+
* The assessmentTest `title` the backend returned, trimmed, or `undefined` when it
|
|
949
|
+
* has none. Shells fall back to a localized generic title, never the identifier.
|
|
950
|
+
*/
|
|
951
|
+
getAssessmentTitle() {
|
|
952
|
+
const title = this.assessment.title?.trim();
|
|
953
|
+
return title ? title : undefined;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Candidate-facing sections: visible sections only (QTI `visible="false"` sections are
|
|
957
|
+
* not presented as sections and their titles never surface), each with whether jumping
|
|
958
|
+
* to it is legal right now for the current navigationMode.
|
|
959
|
+
*/
|
|
207
960
|
getAllSections() {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
961
|
+
return this.presentedSectionList().map((section, index) => ({
|
|
962
|
+
id: section.identifier,
|
|
963
|
+
title: section.title,
|
|
964
|
+
index,
|
|
965
|
+
navigable: this.isLegalSectionTarget(section),
|
|
966
|
+
}));
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Whether jumping straight to a delivered item is legal right now: false once the test
|
|
970
|
+
* has finalized, and — for any item other than the current one — false while the target
|
|
971
|
+
* is time-locked, its review policy forbids returning, or the navigation rules (linear
|
|
972
|
+
* mode, test-part sequencing) do not reach it. The review screen renders illegal targets
|
|
973
|
+
* status-only; `navigateTo()` still enforces this authoritatively.
|
|
974
|
+
*/
|
|
975
|
+
isNavigationTargetLegal(index) {
|
|
976
|
+
return this.isNavigationTargetLegalWith(index, this.lazyForward());
|
|
977
|
+
}
|
|
978
|
+
/** `isNavigationTargetLegal` with the forward step computed once for a batch of targets. */
|
|
979
|
+
isNavigationTargetLegalWith(index, forward) {
|
|
980
|
+
if (this.finalized || this.currentItemIndex < 0)
|
|
981
|
+
return false;
|
|
982
|
+
const target = this.items[index];
|
|
983
|
+
if (!target)
|
|
984
|
+
return false;
|
|
985
|
+
if (target !== this.items[this.currentItemIndex]) {
|
|
986
|
+
if (this.isItemLocked(target))
|
|
987
|
+
return false;
|
|
988
|
+
if (!this.canReviewItem(target))
|
|
989
|
+
return false;
|
|
990
|
+
if (!this.canNavigateByTestPart(index, this.currentItemIndex, forward))
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
return true;
|
|
994
|
+
}
|
|
995
|
+
reviewInfoFor(itemIdentifier) {
|
|
996
|
+
return this.reviewInfoCache.for(itemIdentifier);
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Answered / partially answered / unanswered for one delivered item, from its
|
|
1000
|
+
* candidate responses (one verdict per interaction for composite items). The single
|
|
1001
|
+
* definition of "answered" the review screen, section menu and submit confirmation share.
|
|
1002
|
+
*/
|
|
1003
|
+
getItemAnswerStatus(itemIdentifier) {
|
|
1004
|
+
const info = this.reviewInfoFor(itemIdentifier);
|
|
1005
|
+
return itemAnswerStatus(this.sessionCoordinator.getResponses(itemIdentifier), info.responseIds);
|
|
1006
|
+
}
|
|
1007
|
+
/** How many delivered items carry a response (answered or partially answered). */
|
|
1008
|
+
getAnsweredItemCount() {
|
|
1009
|
+
return this.items.filter((item) => this.getItemAnswerStatus(item.identifier) !== 'unanswered').length;
|
|
1010
|
+
}
|
|
1011
|
+
/** Every delivered item as the review screen lists it: status, flag, visited, jump legality. */
|
|
1012
|
+
getReviewItems() {
|
|
1013
|
+
const forward = this.lazyForward();
|
|
1014
|
+
return this.items.map((item) => reviewItemRow(item, {
|
|
1015
|
+
title: this.reviewInfoFor(item.identifier).title,
|
|
1016
|
+
status: this.getItemAnswerStatus(item.identifier),
|
|
1017
|
+
flagged: this.sessionCoordinator.isItemFlagged(item.identifier),
|
|
1018
|
+
visited: this.navigationManager.isVisited(item.index) || item.index === this.currentItemIndex,
|
|
1019
|
+
jumpAllowed: this.isNavigationTargetLegalWith(item.index, forward),
|
|
1020
|
+
isCurrent: item.index === this.currentItemIndex,
|
|
1021
|
+
}));
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Candidate-facing results for a shell's opt-in completion summary: per delivered
|
|
1025
|
+
* item the answered status and — when the backend returned one — its score, plus the
|
|
1026
|
+
* finalized totals. Null until the assessment has been finalized; high-stakes hosts
|
|
1027
|
+
* simply never render it (the shell's `showResultsSummary` stays off by default).
|
|
1028
|
+
*/
|
|
1029
|
+
getResultsSummary() {
|
|
1030
|
+
if (!this.finalized || !this.finalResults)
|
|
1031
|
+
return null;
|
|
1032
|
+
return resultsSummaryOf({
|
|
1033
|
+
items: this.items,
|
|
1034
|
+
results: this.finalResults,
|
|
1035
|
+
titleOf: (itemIdentifier) => this.reviewInfoFor(itemIdentifier).title,
|
|
1036
|
+
statusOf: (itemIdentifier) => this.getItemAnswerStatus(itemIdentifier),
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* What the candidate's next forward step would do. QTI test parts are delivered in
|
|
1041
|
+
* sequence and cannot be re-entered, so a step that leaves the current part is the
|
|
1042
|
+
* irreversible move the shell confirms before making.
|
|
1043
|
+
*/
|
|
1044
|
+
getForwardTransitionInfo() {
|
|
1045
|
+
const current = this.items[this.currentItemIndex];
|
|
1046
|
+
if (!current || this.finalized)
|
|
1047
|
+
return { nextIndex: null, leavesTestPart: false };
|
|
1048
|
+
// A decision the backend made for this item and delivery has not followed yet (a
|
|
1049
|
+
// check's, a branch exit held back while questions of the part still owed an answer)
|
|
1050
|
+
// is what Next does now — unless Next re-submits a changed response, which decides anew.
|
|
1051
|
+
const kept = this.nextSubmits(current) ? null : this.keptBranchDecisionFor(current);
|
|
1052
|
+
if (kept) {
|
|
1053
|
+
const landing = branchLandingOf(kept, this.branchTargetIndex(current, kept));
|
|
1054
|
+
if (landing.kind !== 'skipped') {
|
|
1055
|
+
return {
|
|
1056
|
+
nextIndex: landing.kind === 'item' ? landing.index : null,
|
|
1057
|
+
leavesTestPart: this.branchExitLeavesPart(current, kept),
|
|
1058
|
+
};
|
|
219
1059
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
visit(section);
|
|
1060
|
+
// A literal decision that resolves to nothing forward is skipped (the rule does
|
|
1061
|
+
// not fire): Next falls through to the delivery rules, so that is what the step
|
|
1062
|
+
// reports.
|
|
224
1063
|
}
|
|
225
|
-
|
|
1064
|
+
const nextIndex = this.forwardStepIndex(current);
|
|
1065
|
+
const next = nextIndex >= 0 ? this.items[nextIndex] : undefined;
|
|
1066
|
+
return {
|
|
1067
|
+
nextIndex: next ? nextIndex : null,
|
|
1068
|
+
leavesTestPart: Boolean(next && next.testPart !== current.testPart),
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Set (or clear) the candidate's flag-for-review on an item; defaults to the current
|
|
1073
|
+
* item. Flag state lives in the session state (`itemFlags`), survives navigation and
|
|
1074
|
+
* is part of `getState()` snapshots.
|
|
1075
|
+
*/
|
|
1076
|
+
setItemFlag(flagged, itemIdentifier) {
|
|
1077
|
+
const id = itemIdentifier ?? this.items[this.currentItemIndex]?.identifier;
|
|
1078
|
+
if (!id)
|
|
1079
|
+
return;
|
|
1080
|
+
this.sessionCoordinator.setItemFlag(id, flagged);
|
|
1081
|
+
this.events.emit('flagChange', id, flagged);
|
|
1082
|
+
// Flags are part of the persisted draft.
|
|
1083
|
+
this.notifyAutosaveActivity();
|
|
1084
|
+
}
|
|
1085
|
+
/** Toggle the current (or given) item's flag; returns the new state. */
|
|
1086
|
+
toggleItemFlag(itemIdentifier) {
|
|
1087
|
+
const id = itemIdentifier ?? this.items[this.currentItemIndex]?.identifier;
|
|
1088
|
+
if (!id)
|
|
1089
|
+
return false;
|
|
1090
|
+
const flagged = !this.sessionCoordinator.isItemFlagged(id);
|
|
1091
|
+
this.setItemFlag(flagged, id);
|
|
1092
|
+
return flagged;
|
|
1093
|
+
}
|
|
1094
|
+
isItemFlagged(itemIdentifier) {
|
|
1095
|
+
const id = itemIdentifier ?? this.items[this.currentItemIndex]?.identifier;
|
|
1096
|
+
return id ? this.sessionCoordinator.isItemFlagged(id) : false;
|
|
1097
|
+
}
|
|
1098
|
+
/** Identifiers of the items currently flagged for review. */
|
|
1099
|
+
getFlaggedItemIdentifiers() {
|
|
1100
|
+
return this.sessionCoordinator.getFlaggedItemIdentifiers();
|
|
1101
|
+
}
|
|
1102
|
+
/** Fires when an item's flag-for-review state changes. */
|
|
1103
|
+
onFlagChange(listener) {
|
|
1104
|
+
return this.events.on('flagChange', listener);
|
|
226
1105
|
}
|
|
227
1106
|
getNavigationState() {
|
|
1107
|
+
const presented = this.presentedSectionList();
|
|
1108
|
+
const sectionIndexes = new Map(presented.map((section, index) => [section.identifier, index]));
|
|
228
1109
|
const total = this.items.length;
|
|
229
|
-
const canPrevious = this.canPrevious();
|
|
230
|
-
const canNext = this.canNext();
|
|
231
1110
|
const q = this.items[this.currentItemIndex];
|
|
232
|
-
const
|
|
1111
|
+
const presentedSection = q ? presentedSectionOf(q.sections) : undefined;
|
|
233
1112
|
return {
|
|
234
1113
|
currentIndex: this.currentItemIndex,
|
|
235
1114
|
totalItems: total,
|
|
236
|
-
canNext,
|
|
237
|
-
canPrevious,
|
|
238
|
-
isLoading:
|
|
239
|
-
|
|
240
|
-
|
|
1115
|
+
canNext: !this.finalized && this.canNext(),
|
|
1116
|
+
canPrevious: !this.finalized && this.canPrevious(),
|
|
1117
|
+
isLoading: this.transitionInFlight,
|
|
1118
|
+
isComplete: this.finalized,
|
|
1119
|
+
currentSection: presentedSection
|
|
1120
|
+
? {
|
|
1121
|
+
id: presentedSection.identifier,
|
|
1122
|
+
title: presentedSection.title,
|
|
1123
|
+
index: sectionIndexes.get(presentedSection.identifier) ?? -1,
|
|
1124
|
+
}
|
|
241
1125
|
: undefined,
|
|
242
|
-
totalSections,
|
|
1126
|
+
totalSections: presented.length,
|
|
243
1127
|
};
|
|
244
1128
|
}
|
|
245
1129
|
getCurrentItem() {
|
|
@@ -248,7 +1132,7 @@ export class AssessmentPlayer {
|
|
|
248
1132
|
return null;
|
|
249
1133
|
return {
|
|
250
1134
|
identifier: q.item.identifier,
|
|
251
|
-
title: q.
|
|
1135
|
+
title: q.presentedSection?.title,
|
|
252
1136
|
required: q.item.required,
|
|
253
1137
|
itemXml: q.item.itemXml,
|
|
254
1138
|
deliveryContext: q.item.deliveryContext,
|
|
@@ -277,13 +1161,42 @@ export class AssessmentPlayer {
|
|
|
277
1161
|
href: itemRef.href,
|
|
278
1162
|
title: itemRef.title,
|
|
279
1163
|
itemXml: itemRef.itemXml,
|
|
280
|
-
|
|
1164
|
+
// Shared by reference, not cloned: the delivery context is a static
|
|
1165
|
+
// content record the backend returned, composition rebuilds share it so
|
|
1166
|
+
// unchanged items keep identical props, and callers treat it read-only.
|
|
1167
|
+
deliveryContext: itemRef.deliveryContext,
|
|
281
1168
|
};
|
|
282
1169
|
});
|
|
283
1170
|
}
|
|
284
1171
|
getResponsesForItem(itemIdentifier) {
|
|
285
1172
|
return cloneData(this.sessionCoordinator.getResponses(itemIdentifier)) ?? {};
|
|
286
1173
|
}
|
|
1174
|
+
/**
|
|
1175
|
+
* The assessment identifier the backend drew this session for (`SecureAssessment.identifier`).
|
|
1176
|
+
* Section tool bars and host integrations name the assessment with it.
|
|
1177
|
+
*/
|
|
1178
|
+
getAssessmentId() {
|
|
1179
|
+
return this.assessment.identifier;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* The delivered items of the active item's innermost section, with their current
|
|
1183
|
+
* response records shared by reference (a shallow copy of the outer map only).
|
|
1184
|
+
* For section composition building: the values are read-only views of session
|
|
1185
|
+
* state and must not be mutated by callers — the deep-cloning accessors above
|
|
1186
|
+
* remain the boundary for persistence and events.
|
|
1187
|
+
*/
|
|
1188
|
+
getSectionItemResponses() {
|
|
1189
|
+
const current = this.items[this.currentItemIndex];
|
|
1190
|
+
if (!current)
|
|
1191
|
+
return {};
|
|
1192
|
+
const out = {};
|
|
1193
|
+
for (const item of this.items) {
|
|
1194
|
+
if (item.section.identifier !== current.section.identifier)
|
|
1195
|
+
continue;
|
|
1196
|
+
out[item.identifier] = { ...this.sessionCoordinator.getResponses(item.identifier) };
|
|
1197
|
+
}
|
|
1198
|
+
return out;
|
|
1199
|
+
}
|
|
287
1200
|
getCurrentSharedRubricBlocks() {
|
|
288
1201
|
const q = this.items[this.currentItemIndex];
|
|
289
1202
|
if (!q)
|
|
@@ -307,15 +1220,9 @@ export class AssessmentPlayer {
|
|
|
307
1220
|
*/
|
|
308
1221
|
getVisibleFeedback() {
|
|
309
1222
|
const outcomes = this.testOutcomes;
|
|
310
|
-
const parts = this.assessment.testParts ?? [];
|
|
311
|
-
const hasStructured = (this.assessment.testFeedback?.length ?? 0) > 0 || parts.some((part) => (part.testFeedback?.length ?? 0) > 0);
|
|
312
|
-
if (!hasStructured) {
|
|
313
|
-
return this.finalized && this.legacyFeedback
|
|
314
|
-
? [{ key: 'testFeedback', identifier: 'testFeedback', content: this.legacyFeedback, access: 'atEnd' }]
|
|
315
|
-
: [];
|
|
316
|
-
}
|
|
317
1223
|
if (!outcomes)
|
|
318
1224
|
return [];
|
|
1225
|
+
const parts = this.assessment.testParts ?? [];
|
|
319
1226
|
const shown = [];
|
|
320
1227
|
const add = (items, ended, current, part) => {
|
|
321
1228
|
items?.forEach((fb, index) => {
|
|
@@ -329,6 +1236,7 @@ export class AssessmentPlayer {
|
|
|
329
1236
|
content: fb.content,
|
|
330
1237
|
access: fb.access,
|
|
331
1238
|
...(part ? { testPartIdentifier: part.identifier } : {}),
|
|
1239
|
+
...(fb.language ? { language: fb.language } : {}),
|
|
332
1240
|
});
|
|
333
1241
|
});
|
|
334
1242
|
};
|
|
@@ -347,12 +1255,15 @@ export class AssessmentPlayer {
|
|
|
347
1255
|
if (!outcomes)
|
|
348
1256
|
return;
|
|
349
1257
|
this.testOutcomes = cloneData(outcomes);
|
|
1258
|
+
// The snapshot carries them: delivery rules read the same values after a restore.
|
|
1259
|
+
this.sessionCoordinator.setTestOutcomes(outcomes);
|
|
350
1260
|
this.notifyTestFeedbackChange();
|
|
351
1261
|
}
|
|
352
1262
|
updateResponse(responseId, value) {
|
|
353
1263
|
const active = this.items[this.currentItemIndex];
|
|
354
1264
|
if (!active)
|
|
355
1265
|
return;
|
|
1266
|
+
this.assertCandidateActionAllowed();
|
|
356
1267
|
if (this.currentItemSession) {
|
|
357
1268
|
this.currentItemSession.dispatch({
|
|
358
1269
|
action: 'setResponse',
|
|
@@ -371,6 +1282,7 @@ export class AssessmentPlayer {
|
|
|
371
1282
|
* the same responseIdentifier like "RESPONSE" across items).
|
|
372
1283
|
*/
|
|
373
1284
|
updateResponseForItem(itemIdentifier, responseId, value) {
|
|
1285
|
+
this.assertCandidateActionAllowed();
|
|
374
1286
|
const active = this.items[this.currentItemIndex];
|
|
375
1287
|
if (active?.identifier === itemIdentifier && this.currentItemSession) {
|
|
376
1288
|
const liveValue = this.currentItemSession.state().responses[responseId];
|
|
@@ -387,7 +1299,7 @@ export class AssessmentPlayer {
|
|
|
387
1299
|
}
|
|
388
1300
|
const persisted = this.sessionCoordinator.getPersistedItemSession(itemIdentifier);
|
|
389
1301
|
if (persisted && !isWritableItemLifecycle(persisted.lifecycleStatus)) {
|
|
390
|
-
throw new
|
|
1302
|
+
throw new AssessmentPlayerError('itemSessionLocked', `Cannot update responses while item session is ${persisted.lifecycleStatus}`, { status: persisted.lifecycleStatus });
|
|
391
1303
|
}
|
|
392
1304
|
this.sessionCoordinator.updateResponseForItem(itemIdentifier, responseId, value);
|
|
393
1305
|
this.notifyResponseChange();
|
|
@@ -415,19 +1327,28 @@ export class AssessmentPlayer {
|
|
|
415
1327
|
this.sessionCoordinator.saveItemSession(q.identifier, responses, itemSession, transition?.current.duration ?? currentView.duration);
|
|
416
1328
|
return itemSession;
|
|
417
1329
|
}
|
|
418
|
-
endItemSessionForSubmit(q, responses, itemSession) {
|
|
419
|
-
|
|
1330
|
+
endItemSessionForSubmit(q, responses, itemSession, options = {}) {
|
|
1331
|
+
// Responses frozen by an expired time limit are final as they stand: validation
|
|
1332
|
+
// cannot ask the candidate to correct them any more.
|
|
1333
|
+
const validateResponses = options.validate !== false && this.sessionCoordinator.mustValidateResponses(q.identifier);
|
|
420
1334
|
const endAttempt = (session) => {
|
|
1335
|
+
// A session whose attempt already ended contributes its accepted state unchanged;
|
|
1336
|
+
// dispatching another end-attempt on it would throw and fail the final submission.
|
|
1337
|
+
if (!isWritableItemLifecycle(session.state().lifecycleStatus)) {
|
|
1338
|
+
return session.serialize();
|
|
1339
|
+
}
|
|
421
1340
|
const result = session.dispatch({ action: 'endAttempt', validateResponses }).result;
|
|
422
1341
|
if (result?.validation && !result.validation.valid) {
|
|
423
|
-
|
|
1342
|
+
// Coded, naming the item, so a shell shows which question to fix instead of a
|
|
1343
|
+
// generic failure that no retry can clear.
|
|
1344
|
+
throw new AssessmentPlayerError('finalizeResponseInvalid', result.validation.issues[0]?.message || `Submit failed: invalid response for item ${q.identifier}`, { items: String(q.index + 1), itemIdentifiers: q.identifier, count: 1 });
|
|
424
1345
|
}
|
|
425
1346
|
return result?.sessionState ?? session.serialize();
|
|
426
1347
|
};
|
|
427
1348
|
const active = this.items[this.currentItemIndex];
|
|
428
1349
|
if (active === q &&
|
|
429
1350
|
this.currentItemSession &&
|
|
430
|
-
this.currentItemSession.state().lifecycleStatus
|
|
1351
|
+
isWritableItemLifecycle(this.currentItemSession.state().lifecycleStatus)) {
|
|
431
1352
|
return endAttempt(this.currentItemSession);
|
|
432
1353
|
}
|
|
433
1354
|
const session = this.getItemDefinition(q).openSession({
|
|
@@ -442,6 +1363,38 @@ export class AssessmentPlayer {
|
|
|
442
1363
|
session.dispose();
|
|
443
1364
|
}
|
|
444
1365
|
}
|
|
1366
|
+
/**
|
|
1367
|
+
* How an item presents feedback and solutions under its resolved item session
|
|
1368
|
+
* control, for its current attempt count (feedback visibility is attempt-relative,
|
|
1369
|
+
* see `feedbackVisible`).
|
|
1370
|
+
*/
|
|
1371
|
+
presentationFor(q, attemptsAfter = this.sessionCoordinator.getItemSessionInfo(q.identifier).attemptCount) {
|
|
1372
|
+
const control = this.sessionCoordinator.getItemSettings(q.identifier);
|
|
1373
|
+
return {
|
|
1374
|
+
showFeedback: this.feedbackVisible(q, attemptsAfter),
|
|
1375
|
+
showSolution: control.showSolution === true,
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
/**
|
|
1379
|
+
* A counted submission can change what the item shows: feedback a non-final attempt
|
|
1380
|
+
* revealed hides once the last attempt ended (unless showFeedback is on), and the
|
|
1381
|
+
* first non-final attempt reveals it. Reopen the live session under the new policy
|
|
1382
|
+
* when it differs; the item stays where it is.
|
|
1383
|
+
*/
|
|
1384
|
+
refreshLivePresentation(q, itemSession) {
|
|
1385
|
+
const live = this.currentItemSession;
|
|
1386
|
+
if (!live || this.items[this.currentItemIndex] !== q)
|
|
1387
|
+
return;
|
|
1388
|
+
const next = this.presentationFor(q);
|
|
1389
|
+
const current = this.liveSessionPresentation ?? { showFeedback: true, showSolution: false };
|
|
1390
|
+
if (current.showFeedback === next.showFeedback && current.showSolution === next.showSolution)
|
|
1391
|
+
return;
|
|
1392
|
+
const restore = isWritableItemLifecycle(live.state().lifecycleStatus) ? live.serialize() : (itemSession ?? live.serialize());
|
|
1393
|
+
const session = this.getItemDefinition(q).openSession({ restore, presentation: next });
|
|
1394
|
+
this.releaseCurrentItemSession();
|
|
1395
|
+
this.attachCurrentItemSession(q, session, next);
|
|
1396
|
+
this.notifyItemChange();
|
|
1397
|
+
}
|
|
445
1398
|
getItemDefinition(q) {
|
|
446
1399
|
const cached = this.itemDefinitions.get(q.identifier);
|
|
447
1400
|
if (cached)
|
|
@@ -457,27 +1410,78 @@ export class AssessmentPlayer {
|
|
|
457
1410
|
pci: this.config.pci,
|
|
458
1411
|
plugins: this.config.plugins,
|
|
459
1412
|
deliveryContext: q.item.deliveryContext,
|
|
1413
|
+
...(this.config.stringComparison ? { stringComparison: this.config.stringComparison } : {}),
|
|
460
1414
|
});
|
|
461
1415
|
this.itemDefinitions.set(q.identifier, definition);
|
|
462
1416
|
return definition;
|
|
463
1417
|
}
|
|
464
1418
|
mirrorSessionResponses(itemIdentifier, responses) {
|
|
465
|
-
|
|
466
|
-
if (responseValuesEqual(current, responses))
|
|
467
|
-
return false;
|
|
468
|
-
const snapshot = cloneResponseRecord(responses);
|
|
469
|
-
this.state.itemResponses[itemIdentifier] = snapshot;
|
|
470
|
-
this.sessionCoordinator.markAnswered(itemIdentifier, snapshot);
|
|
471
|
-
return true;
|
|
1419
|
+
return this.sessionCoordinator.mirrorResponses(itemIdentifier, responses);
|
|
472
1420
|
}
|
|
473
|
-
attachCurrentItemSession(q, session) {
|
|
1421
|
+
attachCurrentItemSession(q, session, presentation) {
|
|
474
1422
|
this.currentItemSession = session;
|
|
1423
|
+
this.liveSessionPresentation = presentation ?? null;
|
|
475
1424
|
this.currentItemSessionUnsubscribe = session.subscribe((transition) => {
|
|
476
1425
|
if (this.currentItemSession !== session)
|
|
477
1426
|
return;
|
|
478
1427
|
if (this.mirrorSessionResponses(q.identifier, transition.current.responses)) {
|
|
479
1428
|
this.notifyResponseChange();
|
|
480
1429
|
}
|
|
1430
|
+
this.scheduleEndAttemptSubmission(q, session, transition);
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
/** The item's endAttemptInteraction bindings, parsed from its item XML once and cached. */
|
|
1434
|
+
endAttemptResponseMap(q) {
|
|
1435
|
+
let map = this.endAttemptResponses.get(q.identifier);
|
|
1436
|
+
if (!map) {
|
|
1437
|
+
map = new Map();
|
|
1438
|
+
for (const info of endAttemptInteractionInfo(q.item.itemXml)) {
|
|
1439
|
+
map.set(info.responseIdentifier, info.countAttempt);
|
|
1440
|
+
}
|
|
1441
|
+
this.endAttemptResponses.set(q.identifier, map);
|
|
1442
|
+
}
|
|
1443
|
+
return map;
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* QTI endAttempt on the response path: a candidate activating an endAttemptInteraction writes
|
|
1447
|
+
* its boolean response. Assessment delivery decides what that means — the item session is
|
|
1448
|
+
* owned here and must never be closed by a renderer. In a simultaneous test part the response
|
|
1449
|
+
* processing is deferred to the end of the part, so the response is recorded like any other.
|
|
1450
|
+
* In an individual test part the item is submitted through the normal per-item path with the
|
|
1451
|
+
* interaction's countAttempt honored; the candidate stays on the item.
|
|
1452
|
+
*/
|
|
1453
|
+
scheduleEndAttemptSubmission(q, session, transition) {
|
|
1454
|
+
const command = transition.command;
|
|
1455
|
+
if (command.action !== 'setResponse')
|
|
1456
|
+
return;
|
|
1457
|
+
const responseId = command.responseIdentifier;
|
|
1458
|
+
// Only the change to true activates the interaction; re-writing the value is inert.
|
|
1459
|
+
if (transition.current.responses[responseId] !== true || transition.previous.responses[responseId] === true) {
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
const countAttempt = this.endAttemptResponseMap(q).get(responseId);
|
|
1463
|
+
if (countAttempt === undefined)
|
|
1464
|
+
return;
|
|
1465
|
+
if (q.testPart.submissionMode !== 'individual')
|
|
1466
|
+
return;
|
|
1467
|
+
queueMicrotask(() => {
|
|
1468
|
+
void this.runExclusive(async () => {
|
|
1469
|
+
if (this.destroyed ||
|
|
1470
|
+
this.finalized ||
|
|
1471
|
+
this.currentItemSession !== session ||
|
|
1472
|
+
this.items[this.currentItemIndex] !== q) {
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (!isWritableItemLifecycle(session.state().lifecycleStatus))
|
|
1476
|
+
return;
|
|
1477
|
+
await this.submitCurrentItemInternal({ countAttempt, followBranching: false });
|
|
1478
|
+
}).catch((error) => {
|
|
1479
|
+
// A concurrent navigation or submission owns the transition; its own path submits
|
|
1480
|
+
// this response. Anything else surfaces to the host without breaking delivery.
|
|
1481
|
+
if (isAssessmentPlayerError(error) && error.code === 'navigationInFlight')
|
|
1482
|
+
return;
|
|
1483
|
+
this.config.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
1484
|
+
});
|
|
481
1485
|
});
|
|
482
1486
|
}
|
|
483
1487
|
releaseCurrentItemSession() {
|
|
@@ -486,16 +1490,60 @@ export class AssessmentPlayer {
|
|
|
486
1490
|
this.currentItemSession?.dispose();
|
|
487
1491
|
this.currentItemSession = null;
|
|
488
1492
|
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Freeze the live attempt for a proctor pause: suspend it (its responses become
|
|
1495
|
+
* read-only and its QTI `duration` is captured in the persisted snapshot). The
|
|
1496
|
+
* suspended session stays attached so the item keeps rendering, disabled, behind the
|
|
1497
|
+
* pause; `reopenLiveSessionAfterPause()` reopens it from the snapshot so the paused
|
|
1498
|
+
* time never counts as time on task.
|
|
1499
|
+
*/
|
|
1500
|
+
suspendLiveSessionForPause() {
|
|
1501
|
+
if (this.suspendedForPause)
|
|
1502
|
+
return;
|
|
1503
|
+
const session = this.currentItemSession;
|
|
1504
|
+
if (!session || !isWritableItemLifecycle(session.state().lifecycleStatus))
|
|
1505
|
+
return;
|
|
1506
|
+
this.saveCurrentItemSession();
|
|
1507
|
+
this.suspendedForPause = true;
|
|
1508
|
+
}
|
|
1509
|
+
/** Reopen the attempt a proctor pause froze, at the exact state the pause captured. */
|
|
1510
|
+
reopenLiveSessionAfterPause() {
|
|
1511
|
+
if (!this.suspendedForPause)
|
|
1512
|
+
return;
|
|
1513
|
+
this.suspendedForPause = false;
|
|
1514
|
+
const q = this.items[this.currentItemIndex];
|
|
1515
|
+
const snapshot = q ? this.state.itemSessions?.[q.identifier] : undefined;
|
|
1516
|
+
if (!q || !snapshot)
|
|
1517
|
+
return;
|
|
1518
|
+
this.releaseCurrentItemSession();
|
|
1519
|
+
const presentation = this.presentationFor(q);
|
|
1520
|
+
this.attachCurrentItemSession(q, this.getItemDefinition(q).openSession({
|
|
1521
|
+
restore: snapshot,
|
|
1522
|
+
activate: true,
|
|
1523
|
+
presentation,
|
|
1524
|
+
}), presentation);
|
|
1525
|
+
}
|
|
489
1526
|
/**
|
|
490
1527
|
* Get the current session state snapshot (client-side view).
|
|
491
1528
|
* Note: backend remains authoritative; this is intended for simple save/resume.
|
|
492
1529
|
*/
|
|
493
1530
|
getState(options = {}) {
|
|
494
1531
|
const snapshot = this.sessionCoordinator.snapshot(options);
|
|
1532
|
+
// Every item the candidate has been presented is visited (not only submitted ones),
|
|
1533
|
+
// so the review screen's "not yet visited" marks survive a reload.
|
|
1534
|
+
const visited = new Set(snapshot.visitedItems);
|
|
1535
|
+
for (const index of this.navigationManager.getVisited()) {
|
|
1536
|
+
const identifier = this.items[index]?.identifier;
|
|
1537
|
+
if (identifier)
|
|
1538
|
+
visited.add(identifier);
|
|
1539
|
+
}
|
|
1540
|
+
snapshot.visitedItems = this.items.map((q) => q.identifier).filter((identifier) => visited.has(identifier));
|
|
495
1541
|
const current = this.items[this.currentItemIndex];
|
|
496
|
-
if (options.includeItemSessions && current && this.currentItemSession) {
|
|
1542
|
+
if (options.includeItemSessions && current && this.currentItemSession && !this.paused) {
|
|
497
1543
|
// Navigation snapshots may predate edits made after revisiting this item.
|
|
498
1544
|
// Serialize the live authority without suspending the learner's attempt.
|
|
1545
|
+
// (While paused, the snapshot taken at the pause is current: serializing the
|
|
1546
|
+
// suspended session would count the paused time as time on task.)
|
|
499
1547
|
snapshot.itemSessions = {
|
|
500
1548
|
...snapshot.itemSessions,
|
|
501
1549
|
[current.identifier]: this.currentItemSession.serialize(),
|
|
@@ -512,7 +1560,10 @@ export class AssessmentPlayer {
|
|
|
512
1560
|
currentItemIdentifier: timing.currentItemId,
|
|
513
1561
|
currentSectionIdentifier: timing.currentSectionId,
|
|
514
1562
|
currentTestPartIdentifier: timing.currentTestPartId,
|
|
515
|
-
|
|
1563
|
+
// The proctor pause, not the begin gate's hold: a restored snapshot reopens
|
|
1564
|
+
// paused only when a proctor paused it.
|
|
1565
|
+
isPaused: this.paused,
|
|
1566
|
+
...(this.paused && this.pauseReason ? { pauseReason: this.pauseReason } : {}),
|
|
516
1567
|
};
|
|
517
1568
|
}
|
|
518
1569
|
return snapshot;
|
|
@@ -520,22 +1571,54 @@ export class AssessmentPlayer {
|
|
|
520
1571
|
/**
|
|
521
1572
|
* Restore a previously saved session state.
|
|
522
1573
|
*/
|
|
523
|
-
|
|
524
|
-
this.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
1574
|
+
restoreState(state) {
|
|
1575
|
+
return this.runExclusive(async () => {
|
|
1576
|
+
this.sessionCoordinator.restoreState(state);
|
|
1577
|
+
this.seedSubmittedResponses(state);
|
|
1578
|
+
this.restoreTimeTracking(state.timing);
|
|
1579
|
+
// The snapshot's clocks are the time accounting from here on: expiries are
|
|
1580
|
+
// recomputed from them before any item is entered, so a scope that already ran
|
|
1581
|
+
// out never reopens editable (and one that has not is not held locked).
|
|
1582
|
+
this.scopeLocks.clear();
|
|
1583
|
+
this.assessmentExpired = false;
|
|
1584
|
+
this.restoredExpiryFinalizeScheduled = false;
|
|
1585
|
+
this.timeManager?.resetExpiryRecord();
|
|
1586
|
+
this.lockExpiredScopesFromClocks(state.timing);
|
|
1587
|
+
this.templateDefaultsByPart.clear();
|
|
1588
|
+
// The snapshot replaces delivery — kept branch decisions included, so a restored
|
|
1589
|
+
// session lands identically (a snapshot from before the feature simply carries
|
|
1590
|
+
// none). The test outcomes ride it too: the delivery rules read the values the
|
|
1591
|
+
// session's submissions produced, as the live session did. The snapshot carries
|
|
1592
|
+
// the proctor pause; the begin gate keeps holding the clocks.
|
|
1593
|
+
this.testOutcomes = state.testOutcomes ? cloneData(state.testOutcomes) : null;
|
|
1594
|
+
const pauseChanged = this.pauseControl.setFromRestore(state.timing?.isPaused === true, state.timing?.pauseReason);
|
|
1595
|
+
if (!this.started)
|
|
1596
|
+
this.timeManager?.pause();
|
|
1597
|
+
// Restore visited state for UI navigation hints.
|
|
1598
|
+
this.navigationManager.restoreState(this.visitedIndexes(state.visitedItems));
|
|
1599
|
+
// Behind a begin gate no item is entered yet: start() enters the restored one.
|
|
1600
|
+
let deadEnd = false;
|
|
1601
|
+
if (this.started) {
|
|
1602
|
+
const currentId = state.currentItemIdentifier;
|
|
1603
|
+
const idx = currentId ? this.items.findIndex((q) => q.identifier === currentId) : -1;
|
|
1604
|
+
const requested = idx >= 0 ? idx : this.items.length > 0 ? 0 : -1;
|
|
1605
|
+
if (requested >= 0) {
|
|
1606
|
+
const entry = this.restoringEntryTarget(requested);
|
|
1607
|
+
deadEnd = entry.deadEnd;
|
|
1608
|
+
await this.performNavigateTo(entry.index, { restoring: true });
|
|
1609
|
+
}
|
|
1610
|
+
// The (re-)entry succeeded: a previous entry failure is repaired.
|
|
1611
|
+
this.entryError = null;
|
|
1612
|
+
this.pendingEntryIndex = null;
|
|
1613
|
+
}
|
|
1614
|
+
if (pauseChanged)
|
|
1615
|
+
this.notifyPauseChange();
|
|
1616
|
+
if (deadEnd)
|
|
1617
|
+
this.notifyExpiryDeadEnd();
|
|
1618
|
+
this.finalizeRestoredExpiryWhenRunning();
|
|
1619
|
+
// A host-restored snapshot is the new draft; the save runs once this settles.
|
|
1620
|
+
this.notifyAutosaveActivity();
|
|
1621
|
+
});
|
|
539
1622
|
}
|
|
540
1623
|
restoreTimeTracking(timing) {
|
|
541
1624
|
this.timeManager?.restoreState({
|
|
@@ -550,29 +1633,47 @@ export class AssessmentPlayer {
|
|
|
550
1633
|
isPaused: timing.isPaused === true,
|
|
551
1634
|
});
|
|
552
1635
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
1636
|
+
/**
|
|
1637
|
+
* Navigate to an item by index. Serialized with all other navigation and submission
|
|
1638
|
+
* transitions: while one is in flight this rejects with a `navigationInFlight` error,
|
|
1639
|
+
* and once the test has finalized it rejects with `testFinalized`.
|
|
1640
|
+
*/
|
|
1641
|
+
navigateTo(index, options = {}) {
|
|
1642
|
+
return this.runCandidateTransition(() => this.performNavigateTo(index, options));
|
|
1643
|
+
}
|
|
1644
|
+
async performNavigateTo(index, options = {}) {
|
|
1645
|
+
if (index < 0 || index >= this.items.length) {
|
|
1646
|
+
throw new AssessmentPlayerError('invalidNavigationTarget', `Invalid item index: ${index}`, { index });
|
|
1647
|
+
}
|
|
1648
|
+
if (this.finalized && !options.restoring) {
|
|
1649
|
+
throw new AssessmentPlayerError('testFinalized', 'Cannot navigate: the assessment has ended.');
|
|
1650
|
+
}
|
|
556
1651
|
// Enforce navigation rules (UI hints, still backend-authoritative for real deployments).
|
|
557
1652
|
if (!options.restoring && this.currentItemIndex >= 0 && !this.canNavigateByTestPart(index, this.currentItemIndex)) {
|
|
558
|
-
const currentMode = this.items[this.currentItemIndex]?.testPart.navigationMode
|
|
1653
|
+
const currentMode = this.items[this.currentItemIndex]?.testPart.navigationMode;
|
|
559
1654
|
if (currentMode === 'linear' && index > this.nextUnlockedIndex(this.currentItemIndex)) {
|
|
560
|
-
throw new
|
|
1655
|
+
throw new AssessmentPlayerError('linearNavigationOnly', 'In linear navigation mode, you can only move to the next question.');
|
|
561
1656
|
}
|
|
562
|
-
throw new
|
|
1657
|
+
throw new AssessmentPlayerError('navigationNotAllowed', 'Navigation is not allowed.');
|
|
563
1658
|
}
|
|
564
1659
|
const target = this.items[index];
|
|
565
1660
|
if (!options.restoring && target && this.isItemLocked(target)) {
|
|
566
|
-
throw new
|
|
1661
|
+
throw new AssessmentPlayerError('itemTimeExpired', 'The time limit for this question has expired.');
|
|
567
1662
|
}
|
|
568
|
-
if (!options.restoring && target && !this.
|
|
569
|
-
throw new
|
|
1663
|
+
if (!options.restoring && target && !this.canReviewItem(target)) {
|
|
1664
|
+
throw new AssessmentPlayerError('reviewNotAllowed', 'You cannot go back to previous questions in this assessment.');
|
|
570
1665
|
}
|
|
571
1666
|
const currentItem = this.items[this.currentItemIndex];
|
|
572
1667
|
if (!options.restoring && currentItem && target) {
|
|
573
1668
|
this.assertTransitionMinimum(currentItem, target);
|
|
574
|
-
|
|
575
|
-
|
|
1669
|
+
// QTI parts cannot be re-entered: a candidate-initiated step into the next part
|
|
1670
|
+
// refuses while questions of the current part still owe an answer (a left part
|
|
1671
|
+
// can never be revisited, and the end of the test only collects unreachable
|
|
1672
|
+
// questions as they stand). The move's own submission already ran for next();
|
|
1673
|
+
// a direct jump leaves the current item behind, so it is included here.
|
|
1674
|
+
if (target.testPart !== currentItem.testPart)
|
|
1675
|
+
this.assertCanLeaveScope(currentItem);
|
|
1676
|
+
if (target.testPart !== currentItem.testPart && currentItem.testPart.submissionMode === 'simultaneous') {
|
|
576
1677
|
// Commit this part before leaving it; a failed request keeps the learner
|
|
577
1678
|
// in the current part so its remaining answers can be retried.
|
|
578
1679
|
await this.submitSimultaneousItems(this.items.filter((q) => q.testPart === currentItem.testPart));
|
|
@@ -595,117 +1696,639 @@ export class AssessmentPlayer {
|
|
|
595
1696
|
this.timeManager?.endItem(currentItem.identifier);
|
|
596
1697
|
}
|
|
597
1698
|
this.currentItemIndex = index;
|
|
1699
|
+
this.navigationManager.markVisited(index);
|
|
598
1700
|
const q = this.items[index];
|
|
599
|
-
this.
|
|
1701
|
+
this.sessionCoordinator.setCurrentItem(q.identifier);
|
|
600
1702
|
this.timeManager?.activateScopes({
|
|
601
1703
|
testPart: { identifier: q.testPart.identifier, timeLimits: q.testPart.timeLimits },
|
|
602
1704
|
section: { identifier: q.section.identifier, timeLimits: q.section.timeLimits },
|
|
1705
|
+
// Every enclosing section runs its own clock, outermost first.
|
|
1706
|
+
sections: q.sections.map((section) => ({
|
|
1707
|
+
identifier: section.identifier,
|
|
1708
|
+
timeLimits: section.timeLimits,
|
|
1709
|
+
})),
|
|
603
1710
|
item: { identifier: q.identifier, timeLimits: q.item.timeLimits },
|
|
604
1711
|
});
|
|
605
1712
|
// Restore responses into one live session owned by the assessment. The section
|
|
606
1713
|
// composition and item renderer receive this exact object.
|
|
607
1714
|
const responses = this.sessionCoordinator.activateItem(q.identifier);
|
|
608
1715
|
const restoredItemSession = this.state.itemSessions?.[q.identifier];
|
|
609
|
-
const control = this.sessionCoordinator.getItemSettings(q.identifier);
|
|
610
1716
|
this.releaseCurrentItemSession();
|
|
1717
|
+
const presentation = this.presentationFor(q);
|
|
611
1718
|
const session = this.getItemDefinition(q).openSession({
|
|
612
1719
|
restore: restoredItemSession,
|
|
613
1720
|
responses: restoredItemSession ? undefined : responses,
|
|
614
1721
|
activate: true,
|
|
615
|
-
templateDefaults: restoredItemSession ? undefined : this.
|
|
616
|
-
presentation
|
|
617
|
-
// Feedback during an adaptive item's attempts is part of the item, whatever showFeedback says.
|
|
618
|
-
showFeedback: control.showFeedback === true || isAdaptiveItemXml(q.item.itemXml),
|
|
619
|
-
showSolution: control.showSolution === true,
|
|
620
|
-
},
|
|
1722
|
+
templateDefaults: restoredItemSession ? undefined : this.templateDefaultsFor(q),
|
|
1723
|
+
presentation,
|
|
621
1724
|
});
|
|
622
|
-
this.attachCurrentItemSession(q, session);
|
|
1725
|
+
this.attachCurrentItemSession(q, session, presentation);
|
|
1726
|
+
this.suspendedForPause = false;
|
|
1727
|
+
// An expired limit closed this item (a restoring entry at an expiry dead end, or a
|
|
1728
|
+
// branch into a closed scope): it shows read-only, never editable.
|
|
1729
|
+
if (this.isItemLocked(q))
|
|
1730
|
+
this.saveCurrentItemSession();
|
|
1731
|
+
// Entered during a proctor pause (a restore, or a held start): the attempt stays frozen.
|
|
1732
|
+
if (this.paused)
|
|
1733
|
+
this.suspendLiveSessionForPause();
|
|
623
1734
|
this.notifyItemChange();
|
|
624
1735
|
this.notifySectionChange();
|
|
625
1736
|
if (currentItem?.testPart.identifier !== q.testPart.identifier)
|
|
626
1737
|
this.notifyTestFeedbackChange();
|
|
627
1738
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
1739
|
+
/**
|
|
1740
|
+
* Navigate to a section by identifier. Legal targets only: a presented (visible)
|
|
1741
|
+
* section reachable under the current navigationMode. Illegal jumps reject with a
|
|
1742
|
+
* typed `AssessmentPlayerError` instead of throwing plain errors.
|
|
1743
|
+
*/
|
|
1744
|
+
navigateToSection(sectionId) {
|
|
1745
|
+
return this.runCandidateTransition(async () => {
|
|
1746
|
+
if (this.finalized) {
|
|
1747
|
+
throw new AssessmentPlayerError('testFinalized', `Cannot navigate to section "${sectionId}": the assessment has ended.`);
|
|
1748
|
+
}
|
|
1749
|
+
const idx = this.items.findIndex((q) => q.sections.some((s) => s.identifier === sectionId));
|
|
1750
|
+
if (idx < 0) {
|
|
1751
|
+
throw new AssessmentPlayerError('invalidNavigationTarget', `Unknown section: ${sectionId}`, { sectionId });
|
|
1752
|
+
}
|
|
1753
|
+
const presented = this.presentedSectionList().find((s) => s.identifier === sectionId);
|
|
1754
|
+
if (!presented || !this.isLegalSectionTarget(presented)) {
|
|
1755
|
+
throw new AssessmentPlayerError('navigationNotAllowed', `Navigation to section "${sectionId}" is not allowed.`, { sectionId });
|
|
1756
|
+
}
|
|
1757
|
+
await this.performNavigateTo(idx);
|
|
1758
|
+
});
|
|
632
1759
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
1760
|
+
/** Move forward. Serialized with all other transitions; rejects as busy while one is in flight. */
|
|
1761
|
+
next() {
|
|
1762
|
+
return this.runCandidateTransition(() => this.performNext());
|
|
1763
|
+
}
|
|
1764
|
+
async performNext() {
|
|
1765
|
+
const q = this.items[this.currentItemIndex];
|
|
1766
|
+
if (!q || this.finalized)
|
|
636
1767
|
return;
|
|
1768
|
+
const responses = this.sessionCoordinator.getActiveResponses();
|
|
1769
|
+
// In individual submission mode the move submits the current item unless its attempts
|
|
1770
|
+
// are used up, it is already closed, or its recorded result already carries these exact
|
|
1771
|
+
// responses (a practice item moved on unchanged): the backend then decides where it goes.
|
|
1772
|
+
const submits = this.nextSubmits(q, responses);
|
|
1773
|
+
// A move that submits nothing follows the backend's decision kept for this item (a
|
|
1774
|
+
// check's, an end-attempt's, a branch exit held back, an end of the test that did not
|
|
1775
|
+
// complete); with none on record, the delivery rules decide (`ruleForwardIndex`).
|
|
1776
|
+
const kept = submits ? null : this.keptBranchDecisionFor(q);
|
|
1777
|
+
// Next from a simultaneous part's last item always crosses (or ends the test): the
|
|
1778
|
+
// part commits at the crossing, and only then is a decision on record to follow.
|
|
1779
|
+
const crossesSimultaneousPart = !submits && !kept && this.crossingFlushDue(q);
|
|
1780
|
+
// On a crossing the pre-flush rule result is provisional: the flush can still change
|
|
1781
|
+
// the outcomes the rules read, so the landing is computed again after it.
|
|
1782
|
+
const forward = crossesSimultaneousPart
|
|
1783
|
+
? this.nextUnlockedIndex(q.index)
|
|
1784
|
+
: submits
|
|
1785
|
+
? this.nextUnlockedIndex(q.index)
|
|
1786
|
+
: kept
|
|
1787
|
+
? -1
|
|
1788
|
+
: this.ruleForwardIndex(q);
|
|
1789
|
+
if (!kept && forward < 0 && !crossesSimultaneousPart)
|
|
1790
|
+
return;
|
|
1791
|
+
this.sessionCoordinator.markAnswered(q.identifier, responses);
|
|
1792
|
+
// QTI allowSkipping (individual parts only): an item that is about to be submitted
|
|
1793
|
+
// without any response may only be skipped when skipping is allowed. A simultaneous
|
|
1794
|
+
// part, an item already closed, or one an expired limit closed (collected as it
|
|
1795
|
+
// stands) is never held here.
|
|
1796
|
+
if (submits && !this.isItemLocked(q) && this.submissionGate(q, responses).mustAnswer) {
|
|
1797
|
+
throw new AssessmentPlayerError('responseRequired', 'You must answer this question before continuing.');
|
|
1798
|
+
}
|
|
1799
|
+
// A step out of the part (the next item lies in the next part, or a kept decision
|
|
1800
|
+
// leaves it) is refused before anything is submitted while another question of the
|
|
1801
|
+
// part still owes an answer: the part cannot be re-entered. The current item is this
|
|
1802
|
+
// move's own submission (or already accepted as it stands).
|
|
1803
|
+
const leavesPart = kept
|
|
1804
|
+
? this.branchExitLeavesPart(q, kept)
|
|
1805
|
+
: crossesSimultaneousPart || this.items[forward].testPart !== q.testPart;
|
|
1806
|
+
if (leavesPart && !this.isItemLocked(q))
|
|
1807
|
+
this.assertCanLeaveScope(q, { exclude: q });
|
|
1808
|
+
if (submits) {
|
|
1809
|
+
const before = this.currentItemIndex;
|
|
1810
|
+
this.clearKeptBranchDecisions();
|
|
1811
|
+
await this.submitCurrentItemInternal();
|
|
1812
|
+
// The submission may branch, navigate, or finalize the test (EXIT_TEST); in those
|
|
1813
|
+
// cases navigation stops here. So does a scope expiry that fired while the
|
|
1814
|
+
// submission was in flight: its hop is queued behind this transition and moves
|
|
1815
|
+
// delivery (its routing decides where an open question is).
|
|
1816
|
+
if (this.currentItemIndex !== before || this.finalized || this.queuedExpiryHops > 0)
|
|
1817
|
+
return;
|
|
1818
|
+
}
|
|
1819
|
+
else if (kept) {
|
|
1820
|
+
// The decision the backend made for this item's accepted submission is followed now.
|
|
1821
|
+
// The move submits nothing, so its minimum times are checked here (an end of the
|
|
1822
|
+
// test checks its own). One that can no longer be followed (it would re-enter a part
|
|
1823
|
+
// already left) leaves the forward step to the delivery rules.
|
|
1824
|
+
const target = this.items[this.branchTargetIndex(q, kept)];
|
|
1825
|
+
if (target && !this.isItemLocked(q))
|
|
1826
|
+
this.assertTransitionMinimum(q, target);
|
|
1827
|
+
const before = this.currentItemIndex;
|
|
1828
|
+
await this.followBranch(q, kept);
|
|
1829
|
+
if (this.currentItemIndex !== before || this.finalized)
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
else if (crossesSimultaneousPart) {
|
|
1833
|
+
await this.crossSimultaneousPart(q);
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
// The candidate may still return and re-attempt this item: reopen it writable while
|
|
1837
|
+
// attempts remain (a no-op for closed single-attempt or writable items), so the
|
|
1838
|
+
// revisit restores an attemptable state instead of the closed one.
|
|
1839
|
+
this.reopenForRemainingAttempts(q);
|
|
1840
|
+
// No backend decision moved delivery (none was returned, or it could not be followed):
|
|
1841
|
+
// the delivery rules decide, as the navigation rules check them.
|
|
1842
|
+
const nextIndex = this.unsubmittedForwardIndex(q);
|
|
1843
|
+
if (nextIndex < 0)
|
|
1844
|
+
return;
|
|
1845
|
+
await this.performNavigateTo(nextIndex);
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Leave the simultaneous test part `last` belongs to: its pending responses go out
|
|
1849
|
+
* first (a failed request throws and keeps the candidate here for a retry), and the
|
|
1850
|
+
* branch decision the flush returns for the part's last item — the part's testPart
|
|
1851
|
+
* branchRule ran there, with every item's variables committed — is what delivery
|
|
1852
|
+
* follows, through `followBranch`'s part-leave, EXIT_TEST and finalized guards. With
|
|
1853
|
+
* no decision (or one that led nowhere) the delivery rules decide on the committed
|
|
1854
|
+
* state, honouring the following parts' preconditions.
|
|
1855
|
+
*/
|
|
1856
|
+
async crossSimultaneousPart(last) {
|
|
1857
|
+
await this.submitSimultaneousItems(this.items.filter((item) => item.testPart === last.testPart));
|
|
1858
|
+
const target = this.partCrossingDecisionTarget(last);
|
|
1859
|
+
if (target !== null) {
|
|
1860
|
+
const before = this.currentItemIndex;
|
|
1861
|
+
await this.followBranch(last, target);
|
|
1862
|
+
if (this.currentItemIndex !== before || this.finalized)
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
// No decision moved delivery: the delivery rules decide, as the navigation rules
|
|
1866
|
+
// check them — on the state the flush just committed.
|
|
1867
|
+
const nextIndex = this.unsubmittedForwardIndex(last);
|
|
1868
|
+
if (nextIndex < 0)
|
|
1869
|
+
return;
|
|
1870
|
+
await this.performNavigateTo(nextIndex);
|
|
1871
|
+
}
|
|
1872
|
+
/**
|
|
1873
|
+
* The branch decision a simultaneous part's flush left for its last item, when it takes
|
|
1874
|
+
* delivery out of the part that is ending. A target inside that part is rejected: the
|
|
1875
|
+
* part is being left, its responses are out, and its rules cannot deliver into it again.
|
|
1876
|
+
*/
|
|
1877
|
+
partCrossingDecisionTarget(last) {
|
|
1878
|
+
const target = this.keptBranchDecisionFor(last);
|
|
1879
|
+
if (!target)
|
|
1880
|
+
return null;
|
|
1881
|
+
const targetIndex = this.indexOfItem(target);
|
|
1882
|
+
if (targetIndex >= 0 && this.items[targetIndex].testPart === last.testPart)
|
|
1883
|
+
return null;
|
|
1884
|
+
return target;
|
|
1885
|
+
}
|
|
1886
|
+
/** Whether the delivered item after `q` lies outside `q`'s test part (or nothing does). */
|
|
1887
|
+
endsTestPart(q) {
|
|
1888
|
+
return this.items[q.index + 1]?.testPart !== q.testPart;
|
|
1889
|
+
}
|
|
1890
|
+
/** The part's effective QTI submission mode. */
|
|
1891
|
+
isSimultaneousSubmission(q) {
|
|
1892
|
+
return q.testPart.submissionMode === 'simultaneous';
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Whether `next()` from the item submits it: an individual part's item whose attempts
|
|
1896
|
+
* remain, that is not closed, and whose responses differ from its last counted submission
|
|
1897
|
+
* (or that has none).
|
|
1898
|
+
*/
|
|
1899
|
+
nextSubmits(q, responses = this.sessionCoordinator.getActiveResponses()) {
|
|
1900
|
+
return (this.isIndividual(q) &&
|
|
1901
|
+
this.sessionCoordinator.canSubmit(q.identifier) &&
|
|
1902
|
+
this.itemLifecycleOf(q.identifier) !== 'closed' &&
|
|
1903
|
+
!this.responsesUnchangedSinceSubmission(q.identifier, responses));
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* The backend's decisions for leaving an item (`nextItemIdentifier`), keyed per item on
|
|
1907
|
+
* the session state (`state.branchDecisions`) with that item's last-submission record,
|
|
1908
|
+
* so a restored session lands identically. A counted submission that stays on the item
|
|
1909
|
+
* (a practice check, a counted endAttemptInteraction) keeps its decision; so does a
|
|
1910
|
+
* branch exit refused while questions of the part still owed an answer, and a
|
|
1911
|
+
* simultaneous part's crossing flush keeps the decision made for its last item. The next
|
|
1912
|
+
* forward step from that item that submits nothing — the candidate moves on with the
|
|
1913
|
+
* response unchanged — follows it; a changed response re-submits and the fresh decision
|
|
1914
|
+
* replaces it. At most the freshest decision is kept: any later counted submission voids
|
|
1915
|
+
* the earlier ones (the outcomes they were decided on have moved), and following a
|
|
1916
|
+
* decision clears it.
|
|
1917
|
+
*/
|
|
1918
|
+
/** The backend decision kept for `q` that delivery has not followed yet (its target). */
|
|
1919
|
+
keptDecisionTarget(q) {
|
|
1920
|
+
return this.sessionCoordinator.getBranchDecision(q.identifier) ?? null;
|
|
1921
|
+
}
|
|
1922
|
+
/** Keep `target` as the one decision delivery may still follow — the item's freshest. */
|
|
1923
|
+
keepBranchDecision(q, target) {
|
|
1924
|
+
this.sessionCoordinator.keepBranchDecision(q.identifier, target);
|
|
1925
|
+
}
|
|
1926
|
+
/** Every kept decision is void: a counted submission moved the outcomes they decided on. */
|
|
1927
|
+
clearKeptBranchDecisions() {
|
|
1928
|
+
this.sessionCoordinator.clearBranchDecisions();
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* The backend decision kept for leaving `q` — its item's entry in the session state
|
|
1932
|
+
* (`branchDecisions`), made by `q`'s last counted submission — if delivery has not
|
|
1933
|
+
* followed it yet. A decision onto an item an expired time limit has closed since is
|
|
1934
|
+
* passed over like the item itself: the delivery rules then find the next open item.
|
|
1935
|
+
*/
|
|
1936
|
+
keptBranchDecisionFor(q) {
|
|
1937
|
+
const target = this.keptDecisionTarget(q);
|
|
1938
|
+
if (!target)
|
|
1939
|
+
return null;
|
|
1940
|
+
const targetItem = this.items[this.indexOfItem(target)];
|
|
1941
|
+
return targetItem && this.isItemLocked(targetItem) ? null : target;
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Where the candidate's Next goes from `q`: when it submits the item — or crosses out of
|
|
1945
|
+
* a simultaneous part whose responses still have to go out (`crossingFlushDue`) — the
|
|
1946
|
+
* backend decides once the submissions are accepted (the adjacent open item stands for
|
|
1947
|
+
* that decision until then; the pre-flush rules read uncommitted state); otherwise the
|
|
1948
|
+
* destination is known now (`unsubmittedForwardIndex`). -1 when nothing follows — Submit
|
|
1949
|
+
* is the way on.
|
|
1950
|
+
*/
|
|
1951
|
+
forwardStepIndex(q) {
|
|
1952
|
+
return this.nextSubmits(q) || this.crossingFlushDue(q)
|
|
1953
|
+
? this.nextUnlockedIndex(q.index)
|
|
1954
|
+
: this.unsubmittedForwardIndex(q);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Whether `next()` from `q` crosses out of its simultaneous part with some of the part's
|
|
1958
|
+
* responses not yet accepted: the crossing flushes them, and that flush decides the landing.
|
|
1959
|
+
*/
|
|
1960
|
+
crossingFlushDue(q) {
|
|
1961
|
+
return (this.endsTestPart(q) &&
|
|
1962
|
+
this.isSimultaneousSubmission(q) &&
|
|
1963
|
+
!this.keptBranchDecisionFor(q) &&
|
|
1964
|
+
this.items.some((item) => item.testPart === q.testPart && this.itemNeedsSubmission(item)));
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Where a forward step from `q` that submits nothing lands — a move on after a practice
|
|
1968
|
+
* check, a move out of a simultaneous part, a jump into the next test part: the backend's
|
|
1969
|
+
* decision kept for `q`, else the next item the delivery rules make eligible
|
|
1970
|
+
* (`ruleForwardIndex`). -1 when nothing follows (an EXIT_* decision nothing follows, or
|
|
1971
|
+
* nothing eligible). A decision whose literal target resolves to nothing forward is
|
|
1972
|
+
* skipped — the rule does not fire — so the delivery rules decide, exactly as the
|
|
1973
|
+
* backend's own walk falls through from an unresolvable target.
|
|
1974
|
+
*/
|
|
1975
|
+
unsubmittedForwardIndex(q) {
|
|
1976
|
+
const kept = this.keptBranchDecisionFor(q);
|
|
1977
|
+
if (!kept)
|
|
1978
|
+
return this.ruleForwardIndex(q);
|
|
1979
|
+
const landing = branchLandingOf(kept, this.branchTargetIndex(q, kept));
|
|
1980
|
+
switch (landing.kind) {
|
|
1981
|
+
case 'item':
|
|
1982
|
+
return landing.index;
|
|
1983
|
+
case 'exit':
|
|
1984
|
+
// Nothing follows the EXIT_* boundary; Submit is the way on (its own handling
|
|
1985
|
+
// ends the scope or the test — see `followBranch`).
|
|
1986
|
+
return -1;
|
|
1987
|
+
case 'skipped':
|
|
1988
|
+
return this.ruleForwardIndex(q);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* The next item after `q` when no backend decision applies, by the reference backend's own
|
|
1993
|
+
* rules (`nextItemIdentifier`): branch rules first — in a linear part the item's and those
|
|
1994
|
+
* of each section it ends, the test part's at its end — then preconditions: a test part's on
|
|
1995
|
+
* entering it in any navigation mode, a linear part's sections and items on reaching them.
|
|
1996
|
+
* They read the test outcomes the backend last returned and the recorded variables of every
|
|
1997
|
+
* item it accepted (`ITEM.VARIABLE`), as the backend does. Items an expired time limit closed
|
|
1998
|
+
* are passed over. A test without branch rules or preconditions moves to the adjacent open item.
|
|
1999
|
+
*/
|
|
2000
|
+
ruleForwardIndex(q) {
|
|
2001
|
+
if (!this.hasDeliveryRules)
|
|
2002
|
+
return this.nextUnlockedIndex(q.index);
|
|
2003
|
+
const decls = this.navigationDeclarationsFor(q);
|
|
2004
|
+
const first = this.indexOfItem(nextItemIdentifier(this.deliveredForRules, q.index, decls, Math.random, this.reportTestConditionFailure));
|
|
2005
|
+
if (first < 0)
|
|
2006
|
+
return -1;
|
|
2007
|
+
if (!this.isItemLocked(this.items[first]))
|
|
2008
|
+
return first;
|
|
2009
|
+
for (const index of this.eligibleIndexesAfter(first, decls)) {
|
|
2010
|
+
if (!this.isItemLocked(this.items[index]))
|
|
2011
|
+
return index;
|
|
2012
|
+
}
|
|
2013
|
+
return -1;
|
|
2014
|
+
}
|
|
2015
|
+
/**
|
|
2016
|
+
* The items the delivery rules reach after `fromIndex`, in order: each one whose
|
|
2017
|
+
* preconditions hold as the sequence enters its test part (any navigation mode) and, in a
|
|
2018
|
+
* linear part, its sections and the item itself. Without rules, every following item.
|
|
2019
|
+
*/
|
|
2020
|
+
*eligibleIndexesAfter(fromIndex, decls) {
|
|
2021
|
+
if (!this.hasDeliveryRules) {
|
|
2022
|
+
for (let index = fromIndex + 1; index < this.items.length; index++)
|
|
2023
|
+
yield index;
|
|
2024
|
+
return;
|
|
2025
|
+
}
|
|
2026
|
+
const from = this.items[fromIndex];
|
|
2027
|
+
if (!from)
|
|
2028
|
+
return;
|
|
2029
|
+
const declarations = decls ?? this.navigationDeclarationsFor(from);
|
|
2030
|
+
let previous = this.deliveredForRules[fromIndex];
|
|
2031
|
+
let start = fromIndex + 1;
|
|
2032
|
+
while (start < this.items.length) {
|
|
2033
|
+
const index = this.indexOfItem(firstEligibleItem(this.deliveredForRules, start, previous, declarations, Math.random, this.reportTestConditionFailure));
|
|
2034
|
+
if (index < 0)
|
|
2035
|
+
return;
|
|
2036
|
+
yield index;
|
|
2037
|
+
previous = this.deliveredForRules[index];
|
|
2038
|
+
start = index + 1;
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* The declarations branch rules and preconditions read, built as the reference backend
|
|
2043
|
+
* builds them for a decision about leaving `from`: the test outcomes the backend last
|
|
2044
|
+
* returned, every item with a recorded result as `ITEM.VARIABLE` (an item without one reads
|
|
2045
|
+
* as NULL), and `from`'s own variables unprefixed where the test declares no such outcome.
|
|
2046
|
+
*/
|
|
2047
|
+
navigationDeclarationsFor(from) {
|
|
2048
|
+
const recorded = {};
|
|
2049
|
+
for (const item of this.items) {
|
|
2050
|
+
const scoring = this.state.itemScores?.[item.identifier];
|
|
2051
|
+
if (!scoring && !this.sessionCoordinator.hasItemResult(item.identifier))
|
|
2052
|
+
continue;
|
|
2053
|
+
const variables = recordedItemVariableValues(this.state.itemSessions?.[item.identifier], scoring?.outcomeValues);
|
|
2054
|
+
if (scoring && !variables.SCORE)
|
|
2055
|
+
variables.SCORE = { kind: 'value', baseType: 'float', cardinality: 'single', value: scoring.score };
|
|
2056
|
+
recorded[item.identifier] = applyVariableMappings(variables, item.item.variableMappings);
|
|
2057
|
+
}
|
|
2058
|
+
return addItemVariableDeclarations(testOutcomeDeclarations(this.assessment, this.testOutcomes ?? this.sessionCoordinator.getTestOutcomes()), recorded, recorded[from.identifier] ?? {});
|
|
2059
|
+
}
|
|
2060
|
+
indexOfItem(identifier) {
|
|
2061
|
+
return identifier === undefined ? -1 : (this.indexByIdentifier.get(identifier) ?? -1);
|
|
2062
|
+
}
|
|
2063
|
+
/** The forward step, computed at most once for a batch of legality checks. */
|
|
2064
|
+
lazyForward() {
|
|
2065
|
+
let forward;
|
|
2066
|
+
return () => {
|
|
2067
|
+
if (forward === undefined) {
|
|
2068
|
+
const current = this.items[this.currentItemIndex];
|
|
2069
|
+
forward = current ? this.unsubmittedForwardIndex(current) : -1;
|
|
2070
|
+
}
|
|
2071
|
+
return forward;
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* Whether the item's last counted submission already carried these responses.
|
|
2076
|
+
* False when nothing was recorded: the caller then submits as usual.
|
|
2077
|
+
*/
|
|
2078
|
+
responsesUnchangedSinceSubmission(itemIdentifier, responses) {
|
|
2079
|
+
const submitted = this.lastSubmittedResponses.get(itemIdentifier);
|
|
2080
|
+
if (!submitted)
|
|
2081
|
+
return false;
|
|
2082
|
+
const current = responses ?? this.sessionCoordinator.getActiveResponses();
|
|
2083
|
+
return responseValuesEqual(submitted, current);
|
|
2084
|
+
}
|
|
2085
|
+
/**
|
|
2086
|
+
* Seed the submitted-response memory from a restored snapshot: an item whose recorded
|
|
2087
|
+
* result the snapshot carries was accepted with exactly those responses, so moving on
|
|
2088
|
+
* (or finalizing) with them unchanged re-submits nothing and re-spends no attempt.
|
|
2089
|
+
*/
|
|
2090
|
+
seedSubmittedResponses(state) {
|
|
2091
|
+
const scores = state.itemScores ?? {};
|
|
2092
|
+
for (const [itemIdentifier, responses] of Object.entries(state.itemResponses ?? {})) {
|
|
2093
|
+
if (!scores[itemIdentifier])
|
|
2094
|
+
continue;
|
|
2095
|
+
if (this.lastSubmittedResponses.has(itemIdentifier))
|
|
2096
|
+
continue;
|
|
2097
|
+
this.lastSubmittedResponses.set(itemIdentifier, cloneResponseRecord(responses));
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
/** Move back. Serialized with all other transitions; rejects as busy while one is in flight. */
|
|
2101
|
+
previous() {
|
|
2102
|
+
return this.runCandidateTransition(async () => {
|
|
2103
|
+
const state = this.getNavigationState();
|
|
2104
|
+
if (!state.canPrevious)
|
|
2105
|
+
return;
|
|
2106
|
+
await this.performNavigateTo(this.currentItemIndex - 1);
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* Submit current item (server-side scoring). Serialized with all other navigation and
|
|
2111
|
+
* submission transitions; rejects as busy while one is in flight.
|
|
2112
|
+
*/
|
|
2113
|
+
submitCurrentItem() {
|
|
2114
|
+
return this.runCandidateTransition(() => this.submitCurrentItemInternal());
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Whether the shell should offer the item-level "Check answer" control on the active
|
|
2118
|
+
* item, with the attempt facts it displays. The control exists only in `individual`
|
|
2119
|
+
* submission-mode parts where more than one attempt is allowed (or the item is
|
|
2120
|
+
* adaptive): QTI shows feedback for every non-final attempt then, whatever
|
|
2121
|
+
* `showFeedback` says, so checking in place always reveals something. A single
|
|
2122
|
+
* attempt keeps the submit-on-move delivery (its feedback, under `showFeedback`, rides
|
|
2123
|
+
* the transition); QTI simultaneous parts have no per-item submission.
|
|
2124
|
+
*/
|
|
2125
|
+
getCheckAnswerState() {
|
|
637
2126
|
const q = this.items[this.currentItemIndex];
|
|
638
|
-
if (q)
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
2127
|
+
if (!q)
|
|
2128
|
+
return null;
|
|
2129
|
+
const id = q.identifier;
|
|
2130
|
+
const mode = q.testPart.submissionMode;
|
|
2131
|
+
const adaptive = isAdaptiveItemXml(q.item.itemXml);
|
|
2132
|
+
if (mode !== 'individual') {
|
|
2133
|
+
return {
|
|
2134
|
+
available: false,
|
|
2135
|
+
reason: 'simultaneous',
|
|
2136
|
+
adaptive,
|
|
2137
|
+
attemptsUsed: 0,
|
|
2138
|
+
maxAttempts: null,
|
|
2139
|
+
remainingAttempts: null,
|
|
2140
|
+
attemptsExhausted: false,
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
const info = this.sessionCoordinator.getItemSessionInfo(id);
|
|
2144
|
+
const maxAttempts = resolveMaxAttempts(this.sessionCoordinator.getItemSettings(id), adaptive);
|
|
2145
|
+
const remainingAttempts = maxAttempts === null ? null : Math.max(0, maxAttempts - info.attemptCount);
|
|
2146
|
+
const attemptsExhausted = maxAttempts !== null && info.attemptCount >= maxAttempts;
|
|
2147
|
+
// maxAttempts 1 delivers feedback on the move (submit-on-move): no check control.
|
|
2148
|
+
const available = maxAttempts === null || maxAttempts > 1;
|
|
2149
|
+
return {
|
|
2150
|
+
available,
|
|
2151
|
+
reason: available ? null : 'feedbackOff',
|
|
2152
|
+
adaptive,
|
|
2153
|
+
attemptsUsed: info.attemptCount,
|
|
2154
|
+
maxAttempts,
|
|
2155
|
+
remainingAttempts,
|
|
2156
|
+
attemptsExhausted,
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Practice flow: submit the active item through the normal per-item path and STAY on
|
|
2161
|
+
* it, so its feedback becomes visible (the shell shows `getLastItemFeedback()`).
|
|
2162
|
+
* The submission counts toward `maxAttempts`; while attempts remain the item reopens
|
|
2163
|
+
* writable afterwards (non-adaptive items reopen from the pre-submit state with the
|
|
2164
|
+
* computed outcomes restored), so the candidate can revise and check again. Adaptive
|
|
2165
|
+
* items keep their engine-driven attempt loop. Once the attempts are used up this
|
|
2166
|
+
* rejects with a coded `maxAttemptsReached`; moving on with `next()` then needs no
|
|
2167
|
+
* further submission. Serialized with all other transitions.
|
|
2168
|
+
*/
|
|
2169
|
+
checkCurrentItem() {
|
|
2170
|
+
return this.runCandidateTransition(async () => {
|
|
2171
|
+
const q = this.items[this.currentItemIndex];
|
|
2172
|
+
if (!q)
|
|
2173
|
+
return null;
|
|
2174
|
+
const state = this.getCheckAnswerState();
|
|
2175
|
+
if (!state?.available) {
|
|
2176
|
+
throw new AssessmentPlayerError('navigationNotAllowed', 'Checking answers is not available for this item.');
|
|
644
2177
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const lifecycle = this.currentItemSession?.state().lifecycleStatus;
|
|
648
|
-
if ((q.testPart.submissionMode ?? this.assessment.submissionMode) === 'individual' &&
|
|
649
|
-
this.sessionCoordinator.canSubmit(q.identifier) &&
|
|
650
|
-
lifecycle !== 'closed') {
|
|
651
|
-
const before = this.currentItemIndex;
|
|
652
|
-
await this.submitCurrentItem();
|
|
653
|
-
// submitCurrentItem may branch/navigate; if it did, we're done.
|
|
654
|
-
if (this.currentItemIndex !== before)
|
|
655
|
-
return;
|
|
2178
|
+
if (state.attemptsExhausted || !this.sessionCoordinator.canSubmit(q.identifier)) {
|
|
2179
|
+
throw new AssessmentPlayerError('maxAttemptsReached', `No attempts remain for item "${q.identifier}".`);
|
|
656
2180
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
2181
|
+
const live = this.currentItemSession;
|
|
2182
|
+
if (live && !isWritableItemLifecycle(live.state().lifecycleStatus)) {
|
|
2183
|
+
// The attempt already ended (and attempts remain only for adaptive items the
|
|
2184
|
+
// engine kept open); nothing to check until delivery reopens the item.
|
|
2185
|
+
return null;
|
|
2186
|
+
}
|
|
2187
|
+
const result = await this.submitCurrentItemInternal({ countAttempt: true, followBranching: false });
|
|
2188
|
+
this.reopenForRemainingAttempts(q);
|
|
2189
|
+
return result;
|
|
2190
|
+
});
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* While counted attempts remain on a non-adaptive item whose attempt just ended (a
|
|
2194
|
+
* practice check, a submit-on-move the candidate may come back to), reopen it writable
|
|
2195
|
+
* from that processed attempt: the session keeps the attempt count (the engine restores
|
|
2196
|
+
* `contextVariables.numAttempts`, so the next counted attempt runs response processing as
|
|
2197
|
+
* attempt k+1) and the outcomes response processing computed — the integrated feedback
|
|
2198
|
+
* renders from them while the candidate revises — with its lifecycle set back to
|
|
2199
|
+
* `interacting`. What the item persists from then on is the attempt the backend accepted.
|
|
2200
|
+
*/
|
|
2201
|
+
reopenForRemainingAttempts(q) {
|
|
2202
|
+
if (isAdaptiveItemXml(q.item.itemXml))
|
|
660
2203
|
return;
|
|
661
|
-
|
|
2204
|
+
// Only the item delivery stands on: this swaps the live session, and another
|
|
2205
|
+
// item's is never replaced.
|
|
2206
|
+
if (this.items[this.currentItemIndex] !== q)
|
|
2207
|
+
return;
|
|
2208
|
+
// An item an expired time limit closed stays closed.
|
|
2209
|
+
if (this.isItemLocked(q))
|
|
2210
|
+
return;
|
|
2211
|
+
const live = this.currentItemSession;
|
|
2212
|
+
if (!live || live.state().lifecycleStatus !== 'closed')
|
|
2213
|
+
return;
|
|
2214
|
+
if (!this.sessionCoordinator.canSubmit(q.identifier))
|
|
2215
|
+
return;
|
|
2216
|
+
const presentation = this.presentationFor(q);
|
|
2217
|
+
const session = this.getItemDefinition(q).openSession({
|
|
2218
|
+
restore: { ...live.serialize(), lifecycleStatus: 'interacting' },
|
|
2219
|
+
presentation,
|
|
2220
|
+
});
|
|
2221
|
+
this.releaseCurrentItemSession();
|
|
2222
|
+
this.attachCurrentItemSession(q, session, presentation);
|
|
2223
|
+
this.notifyItemChange();
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* The item feedback the most recent item-level submission produced (item modal
|
|
2227
|
+
* feedback from response processing, or the backend's `result.feedback`), or null.
|
|
2228
|
+
* Shells show it after `checkCurrentItem()` and after a submit-on-move `next()`.
|
|
2229
|
+
*/
|
|
2230
|
+
getLastItemFeedback() {
|
|
2231
|
+
return this.lastItemFeedback ? { ...this.lastItemFeedback, feedback: [...this.lastItemFeedback.feedback] } : null;
|
|
662
2232
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
2233
|
+
/** Discard the captured item feedback once the shell has shown it. */
|
|
2234
|
+
clearLastItemFeedback() {
|
|
2235
|
+
this.lastItemFeedback = null;
|
|
2236
|
+
}
|
|
2237
|
+
getLastItemFeedbackFor(itemIdentifier) {
|
|
2238
|
+
return this.lastItemFeedback?.itemIdentifier === itemIdentifier ? this.lastItemFeedback : null;
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Capture an item-level submission's feedback for the shell, under the item's
|
|
2242
|
+
* attempt-relative feedback visibility (`attemptsAfter`: the counted attempts once this
|
|
2243
|
+
* submission is recorded). A submission that produces none clears a stale capture for
|
|
2244
|
+
* the flow that follows it.
|
|
2245
|
+
*/
|
|
2246
|
+
captureItemFeedback(q, feedback, attemptsAfter) {
|
|
2247
|
+
if (!this.feedbackVisible(q, attemptsAfter) || !feedback || feedback.length === 0) {
|
|
2248
|
+
this.lastItemFeedback = null;
|
|
666
2249
|
return;
|
|
667
|
-
|
|
2250
|
+
}
|
|
2251
|
+
this.lastItemFeedback = {
|
|
2252
|
+
itemIdentifier: q.identifier,
|
|
2253
|
+
feedback: cloneData([...feedback]),
|
|
2254
|
+
};
|
|
668
2255
|
}
|
|
669
|
-
|
|
670
|
-
|
|
2256
|
+
async submitCurrentItemInternal(options = {}) {
|
|
2257
|
+
const countAttempt = options.countAttempt ?? true;
|
|
671
2258
|
const q = this.items[this.currentItemIndex];
|
|
672
2259
|
if (!q)
|
|
673
|
-
throw new
|
|
674
|
-
this
|
|
2260
|
+
throw new AssessmentPlayerError('invalidNavigationTarget', 'No current item');
|
|
2261
|
+
// An expired limit closed this attempt (or a proctor ends the test): neither its
|
|
2262
|
+
// minimum time nor the skipping/validation gates can hold it open, and the backend
|
|
2263
|
+
// receives it as the collection of the responses as they stand.
|
|
2264
|
+
const submissionReason = this.submissionReasonFor(q);
|
|
2265
|
+
const administrative = submissionReason !== undefined;
|
|
2266
|
+
if (!administrative)
|
|
2267
|
+
this.assertMinimumTime('item', q);
|
|
2268
|
+
const responses = this.currentItemSession
|
|
2269
|
+
? cloneResponseRecord(this.currentItemSession.state().responses)
|
|
2270
|
+
: this.sessionCoordinator.getActiveResponses();
|
|
2271
|
+
// QTI allowSkipping / validateResponses on the per-item path (individual parts only).
|
|
2272
|
+
// A hint (countAttempt=false) is not an attempt and is not held back.
|
|
2273
|
+
const gate = administrative || !countAttempt ? { mustAnswer: false, validate: false } : this.submissionGate(q, responses);
|
|
2274
|
+
if (gate.mustAnswer) {
|
|
2275
|
+
throw new AssessmentPlayerError('responseRequired', 'You must answer this question before continuing.');
|
|
2276
|
+
}
|
|
2277
|
+
if (gate.validate && !this.responsesSatisfyConstraints(q)) {
|
|
2278
|
+
throw new AssessmentPlayerError('attemptValidationFailed', `Submit failed: the responses for item ${q.identifier} do not satisfy its interactions`);
|
|
2279
|
+
}
|
|
2280
|
+
// The counted attempts once this submission is recorded: feedback visibility is
|
|
2281
|
+
// attempt-relative (a non-final attempt shows feedback whatever showFeedback says).
|
|
2282
|
+
const attemptsAfter = this.sessionCoordinator.getItemSessionInfo(q.identifier).attemptCount + (countAttempt ? 1 : 0);
|
|
675
2283
|
const submittedAt = Date.now();
|
|
676
2284
|
let itemSession;
|
|
677
2285
|
const submittedSession = this.currentItemSession;
|
|
678
2286
|
const preSubmitSession = submittedSession?.serialize();
|
|
679
|
-
const responses = this.currentItemSession
|
|
680
|
-
? cloneResponseRecord(this.currentItemSession.state().responses)
|
|
681
|
-
: this.sessionCoordinator.getActiveResponses();
|
|
682
2287
|
let res;
|
|
683
2288
|
try {
|
|
684
2289
|
if (submittedSession) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
2290
|
+
// A session whose attempt already ended contributes its accepted state unchanged;
|
|
2291
|
+
// dispatching another end-attempt on it would throw and fail the submission.
|
|
2292
|
+
const transition = isWritableItemLifecycle(submittedSession.state().lifecycleStatus)
|
|
2293
|
+
? submittedSession.dispatch({
|
|
2294
|
+
action: 'endAttempt',
|
|
2295
|
+
countAttempt,
|
|
2296
|
+
validateResponses: gate.validate,
|
|
2297
|
+
})
|
|
2298
|
+
: undefined;
|
|
2299
|
+
const attempt = transition?.result;
|
|
2300
|
+
if (transition && !attempt)
|
|
691
2301
|
throw new Error('Item session did not produce an end-attempt result');
|
|
692
|
-
if (attempt
|
|
693
|
-
throw new
|
|
2302
|
+
if (attempt?.validation && !attempt.validation.valid) {
|
|
2303
|
+
throw new AssessmentPlayerError('attemptValidationFailed', attempt.validation.issues[0]?.message || 'Submit failed: invalid response');
|
|
694
2304
|
}
|
|
695
|
-
itemSession = attempt.
|
|
2305
|
+
itemSession = attempt?.sessionState ?? submittedSession.serialize();
|
|
2306
|
+
this.captureItemFeedback(q, attempt?.scoring?.modalFeedback, attemptsAfter);
|
|
696
2307
|
}
|
|
697
2308
|
res = await this.backend.submitResponses({
|
|
698
2309
|
sessionId: this.sessionId,
|
|
699
2310
|
itemIdentifier: q.identifier,
|
|
700
|
-
responses: responses,
|
|
2311
|
+
responses: asResponseValues(responses),
|
|
701
2312
|
submittedAt,
|
|
2313
|
+
countAttempt,
|
|
702
2314
|
timeSpent: itemSession?.duration,
|
|
703
|
-
timing: this.getSubmitTimingEvidence(q, itemSession?.duration ?? 0),
|
|
704
|
-
itemSession: this.
|
|
2315
|
+
timing: this.getSubmitTimingEvidence(q, itemSession?.duration ?? 0, submissionReason),
|
|
2316
|
+
itemSession: this.sendsItemSession() ? itemSession : undefined,
|
|
705
2317
|
comment: this.sessionCoordinator.getItemComment(q.identifier),
|
|
706
2318
|
});
|
|
707
2319
|
if (!res.success || !res.result) {
|
|
708
|
-
|
|
2320
|
+
// Backend error text stays on the Error (logs/host callbacks); candidates
|
|
2321
|
+
// see the localized `assessment.errors.codes.submitFailed` message instead.
|
|
2322
|
+
throw new AssessmentPlayerError('submitFailed', res.error || 'Submit failed');
|
|
2323
|
+
}
|
|
2324
|
+
// A backend that produced no session-side modal feedback (production item XML
|
|
2325
|
+
// is delivered without responseProcessing) may still return feedback entries
|
|
2326
|
+
// from its own scoring: the same capture, backend-authored.
|
|
2327
|
+
if (res.result.feedback?.length && !this.getLastItemFeedbackFor(q.identifier)) {
|
|
2328
|
+
this.captureItemFeedback(q, res.result.feedback.map((item) => ({
|
|
2329
|
+
identifier: item.type,
|
|
2330
|
+
content: item.content,
|
|
2331
|
+
})), attemptsAfter);
|
|
709
2332
|
}
|
|
710
2333
|
}
|
|
711
2334
|
catch (error) {
|
|
@@ -717,82 +2340,205 @@ export class AssessmentPlayer {
|
|
|
717
2340
|
this.currentItemSession === submittedSession &&
|
|
718
2341
|
this.items[this.currentItemIndex] === q) {
|
|
719
2342
|
this.releaseCurrentItemSession();
|
|
720
|
-
|
|
2343
|
+
const presentation = this.presentationFor(q);
|
|
2344
|
+
this.attachCurrentItemSession(q, this.getItemDefinition(q).openSession({ restore: preSubmitSession, presentation }), presentation);
|
|
721
2345
|
this.notifyItemChange();
|
|
722
2346
|
}
|
|
2347
|
+
// Nothing committed: no feedback belongs to this attempt.
|
|
2348
|
+
this.lastItemFeedback = null;
|
|
723
2349
|
throw error;
|
|
724
2350
|
}
|
|
725
2351
|
if (itemSession) {
|
|
726
2352
|
this.sessionCoordinator.setItemSession(q.identifier, itemSession);
|
|
727
2353
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
this.sessionCoordinator.
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
2354
|
+
this.setTestOutcomes(res.outcomes);
|
|
2355
|
+
this.reportOutcomeProcessingError(res.outcomeProcessingError);
|
|
2356
|
+
this.reportItemScoringError(res.result);
|
|
2357
|
+
// An uncounted submission (QTI endAttempt countAttempt=false, a hint request) persists the
|
|
2358
|
+
// response and session but records no result and consumes no attempt: the candidate stays
|
|
2359
|
+
// on the item and a later submission carries the final response.
|
|
2360
|
+
if (countAttempt) {
|
|
2361
|
+
// The attempt count before this submission: a backend `updatedState` carries its own
|
|
2362
|
+
// authoritative count (`itemSessionStates`), which must not be counted twice.
|
|
2363
|
+
const attemptsBefore = this.sessionCoordinator.getItemSessionInfo(q.identifier).attemptCount;
|
|
2364
|
+
if (res.updatedState) {
|
|
2365
|
+
this.sessionCoordinator.recordSubmittedItemInUpdatedState(q.identifier, responses, res.updatedState);
|
|
2366
|
+
}
|
|
2367
|
+
else {
|
|
2368
|
+
// Minimal state update when backend doesn't return full state.
|
|
2369
|
+
this.sessionCoordinator.recordIndividualSubmission(q.identifier, responses, itemSession, res.result);
|
|
2370
|
+
}
|
|
2371
|
+
const itemResult = {
|
|
2372
|
+
itemIdentifier: q.identifier,
|
|
2373
|
+
score: res.result.score,
|
|
2374
|
+
maxScore: res.result.maxScore,
|
|
2375
|
+
responses: { ...responses },
|
|
2376
|
+
};
|
|
2377
|
+
this.sessionCoordinator.setItemResult(itemResult);
|
|
2378
|
+
// The counted submission's response set: a later move-time or end-of-test
|
|
2379
|
+
// submission of the same responses is skipped (no wasted attempt).
|
|
2380
|
+
this.lastSubmittedResponses.set(q.identifier, cloneResponseRecord(responses));
|
|
2381
|
+
// Track item session rules (review/attempts) and visited items for navigation hints.
|
|
2382
|
+
// The backend already counted this attempt when its `updatedState` restored a
|
|
2383
|
+
// higher count; only a backend without state updates records locally.
|
|
2384
|
+
this.sessionCoordinator.recordAttemptIfUncounted(q.identifier, attemptsBefore);
|
|
2385
|
+
this.sessionCoordinator.markAnswered(q.identifier, responses);
|
|
2386
|
+
// The submitted item: delivery stands on it for the whole submission (a scope
|
|
2387
|
+
// expiry in flight only queues its hop behind this transition).
|
|
2388
|
+
this.navigationManager.markVisited(q.index);
|
|
2389
|
+
// Apply the backend's branching decision, if any. QTI branchRule semantics:
|
|
2390
|
+
// - EXIT_TEST terminates the test: remaining items are not presented and the test
|
|
2391
|
+
// finalizes exactly like a normal end of test.
|
|
2392
|
+
// - EXIT_TESTPART ends the current test part; EXIT_SECTION ends the current section.
|
|
2393
|
+
// Delivery continues with the next item outside the ended scope; when none follows
|
|
2394
|
+
// (for the part, or the test), the ended scope finalizes like a normal end of test.
|
|
2395
|
+
// A submission that stays on the item (a practice check, a counted end-attempt) keeps
|
|
2396
|
+
// the decision instead: the next forward step from the item that submits nothing
|
|
2397
|
+
// follows it. Either way it voids every earlier decision, which was made on outcomes
|
|
2398
|
+
// this submission has moved.
|
|
2399
|
+
this.clearKeptBranchDecisions();
|
|
2400
|
+
if (options.followBranching === false) {
|
|
2401
|
+
if (res.nextItemIdentifier) {
|
|
2402
|
+
this.keepBranchDecision(q, res.nextItemIdentifier);
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
else if (res.nextItemIdentifier) {
|
|
2406
|
+
await this.followBranch(q, res.nextItemIdentifier);
|
|
2407
|
+
}
|
|
2408
|
+
// Still on the item (a check, a hint, the last item): what it shows follows the
|
|
2409
|
+
// attempt count — a final attempt hides feedback a non-final one revealed.
|
|
2410
|
+
if (!this.finalized && this.items[this.currentItemIndex] === q) {
|
|
2411
|
+
this.refreshLivePresentation(q, itemSession);
|
|
741
2412
|
}
|
|
2413
|
+
return itemResult;
|
|
742
2414
|
}
|
|
743
|
-
|
|
744
|
-
|
|
2415
|
+
// The hint consumed no attempt: the item session must be as open as it was before it.
|
|
2416
|
+
// Response processing may have marked the item completed (a hint on a correct answer),
|
|
2417
|
+
// which closes the session and would leave the candidate with no way to answer —
|
|
2418
|
+
// reopen it while attempts remain, as a counted check reopens.
|
|
2419
|
+
// The backend accepted these exact responses (it ran response processing on them), so
|
|
2420
|
+
// they stand as the item's last submitted set: moving on unchanged re-submits nothing
|
|
2421
|
+
// and follows the counted decision on record, never a fresh one on the hint's state.
|
|
2422
|
+
this.lastSubmittedResponses.set(q.identifier, cloneResponseRecord(responses));
|
|
2423
|
+
this.reopenForRemainingAttempts(q);
|
|
2424
|
+
this.sessionCoordinator.markAnswered(q.identifier, responses);
|
|
2425
|
+
return {
|
|
745
2426
|
itemIdentifier: q.identifier,
|
|
746
2427
|
score: res.result.score,
|
|
747
2428
|
maxScore: res.result.maxScore,
|
|
748
2429
|
responses: { ...responses },
|
|
749
2430
|
};
|
|
750
|
-
|
|
751
|
-
|
|
2431
|
+
}
|
|
2432
|
+
/**
|
|
2433
|
+
* Follow the backend's branching decision for the item just submitted. A decision that
|
|
2434
|
+
* would leave the test part (EXIT_TESTPART, an EXIT_SECTION with nothing after it in
|
|
2435
|
+
* the part, a target in a later part) or end the test (EXIT_TEST) while other questions
|
|
2436
|
+
* of the part still owe an answer is refused like a candidate's own step out of the
|
|
2437
|
+
* part: the candidate stays, the coded error names the questions, and the decision is
|
|
2438
|
+
* kept — the next `next()` from this item follows it once they are answered (a changed
|
|
2439
|
+
* response re-submits and replaces it).
|
|
2440
|
+
*
|
|
2441
|
+
* The end of the test never navigates: a decision its own submission returns is kept
|
|
2442
|
+
* the same way and the collection runs where the candidate stands. A decision whose
|
|
2443
|
+
* submission a scope expiry raced (the item's scope ran out while the submission was in
|
|
2444
|
+
* flight) is not followed — the expiry's queued hop moves delivery, and the decision
|
|
2445
|
+
* would undo that move or land in the closed scope — and a test part delivery already
|
|
2446
|
+
* left is never re-entered.
|
|
2447
|
+
*/
|
|
2448
|
+
async followBranch(q, target) {
|
|
2449
|
+
// Literal targets resolve forward-only (QTI 2.2 §5.15: a delivered test never re-enters
|
|
2450
|
+
// presented items) through the same resolver the landing pre-checks use, so the hop
|
|
2451
|
+
// cannot disagree with what `branchTargetIndex` reported; an unresolvable literal is
|
|
2452
|
+
// skipped and delivery falls through to the delivery rules, as on the backend. EXIT_*
|
|
2453
|
+
// land through their own boundary handling below (-1 never navigates).
|
|
2454
|
+
const targetIndex = branchTargetIndex(q, target, this.items, this.currentItemIndex);
|
|
2455
|
+
const standing = this.items[this.currentItemIndex] ?? q;
|
|
2456
|
+
// A test part delivery already left is never re-entered, whatever the decision says.
|
|
2457
|
+
if (targetIndex >= 0 && partOrderOf(this.assessment, this.items[targetIndex]) < partOrderOf(this.assessment, standing)) {
|
|
2458
|
+
this.clearKeptBranchDecisions();
|
|
2459
|
+
return;
|
|
2460
|
+
}
|
|
2461
|
+
// An end of the test is running: it collects where the candidate stands.
|
|
2462
|
+
if (this.endReason !== null) {
|
|
2463
|
+
this.keepBranchDecision(q, target);
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2466
|
+
// A scope expiry fired while the submission was in flight: its hop is queued behind
|
|
2467
|
+
// this transition and moves delivery, so the decision is not followed — the same
|
|
2468
|
+
// outcome as a decision that arrived after delivery moved on.
|
|
2469
|
+
if (this.queuedExpiryHops > 0)
|
|
2470
|
+
return;
|
|
752
2471
|
try {
|
|
753
|
-
|
|
2472
|
+
if (target === 'EXIT_TEST')
|
|
2473
|
+
this.assertNoSubmissionBlockers();
|
|
2474
|
+
else if (this.branchExitLeavesPart(q, target))
|
|
2475
|
+
this.assertCanLeaveScope(q, { exclude: q });
|
|
754
2476
|
}
|
|
755
|
-
catch {
|
|
756
|
-
|
|
2477
|
+
catch (error) {
|
|
2478
|
+
this.keepBranchDecision(q, target);
|
|
2479
|
+
throw error;
|
|
757
2480
|
}
|
|
758
|
-
this.
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
: item.testPart.identifier !== currentItem?.testPart.identifier));
|
|
778
|
-
if (nextIdx >= 0) {
|
|
779
|
-
await this.navigateTo(nextIdx, { restoring: true });
|
|
780
|
-
}
|
|
781
|
-
else {
|
|
782
|
-
// No further items — signal completion
|
|
783
|
-
for (const l of this.completeListeners)
|
|
784
|
-
l();
|
|
785
|
-
this.config.onComplete?.();
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
const nextIdx = this.items.findIndex((x) => x.identifier === special);
|
|
790
|
-
if (nextIdx >= 0) {
|
|
791
|
-
await this.navigateTo(nextIdx, { restoring: true });
|
|
792
|
-
}
|
|
2481
|
+
this.clearKeptBranchDecisions();
|
|
2482
|
+
if (target === 'EXIT_TEST') {
|
|
2483
|
+
await this.endTestInternal({ reason: 'branch' });
|
|
2484
|
+
return;
|
|
2485
|
+
}
|
|
2486
|
+
if (target === 'EXIT_TESTPART' || target === 'EXIT_SECTION') {
|
|
2487
|
+
await this.applyExitBoundary(target, q);
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
if (targetIndex >= 0) {
|
|
2491
|
+
// A target in the same part leaves this item revisitable: while attempts remain
|
|
2492
|
+
// (QTI allowReview governs only after the last one) its handoff must be
|
|
2493
|
+
// attemptable, exactly as on the candidate's own move — reopen it writable and
|
|
2494
|
+
// hand it off before the hop (a branch hop does not save the outgoing session).
|
|
2495
|
+
if (this.items[targetIndex].testPart === q.testPart) {
|
|
2496
|
+
this.reopenForRemainingAttempts(q);
|
|
2497
|
+
const status = this.currentItemSession?.state().lifecycleStatus;
|
|
2498
|
+
if (status !== undefined && isWritableItemLifecycle(status))
|
|
2499
|
+
this.saveCurrentItemSession();
|
|
793
2500
|
}
|
|
2501
|
+
await this.performNavigateTo(targetIndex, { restoring: true });
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
/** Where a branch decision lands: an item index, or -1 when it ends the test or resolves to nothing forward. */
|
|
2505
|
+
branchTargetIndex(q, target) {
|
|
2506
|
+
return branchTargetIndex(q, target, this.items, this.currentItemIndex);
|
|
2507
|
+
}
|
|
2508
|
+
/** Whether a branch decision takes delivery out of the item's test part (or ends the test). */
|
|
2509
|
+
branchExitLeavesPart(q, target) {
|
|
2510
|
+
return branchExitLeavesPart(q, target, this.items, this.currentItemIndex);
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Leave the scope ended by an EXIT_TESTPART / EXIT_SECTION branch rule: continue with
|
|
2514
|
+
* the first delivered item outside it, finalizing the ended test part (or, when nothing
|
|
2515
|
+
* follows anywhere, the whole test) through the same finalization path as submit().
|
|
2516
|
+
*
|
|
2517
|
+
* The literal resolves over the item's full enclosing chain (like the backend's
|
|
2518
|
+
* branch-rule walk), not the innermost section alone: an outer-section EXIT lands
|
|
2519
|
+
* outside the whole outer section.
|
|
2520
|
+
*/
|
|
2521
|
+
async applyExitBoundary(special, current) {
|
|
2522
|
+
const nextIdx = resolveExitBoundary(special, current, this.items, this.currentItemIndex);
|
|
2523
|
+
const partEnded = nextIdx < 0 || this.items[nextIdx].testPart !== current.testPart;
|
|
2524
|
+
if (partEnded) {
|
|
2525
|
+
// The part's pending simultaneous-mode responses are due when it ends.
|
|
2526
|
+
await this.submitSimultaneousItems(this.items.filter((item) => item.testPart === current.testPart &&
|
|
2527
|
+
item.testPart.submissionMode === 'simultaneous'));
|
|
2528
|
+
}
|
|
2529
|
+
if (nextIdx >= 0) {
|
|
2530
|
+
await this.performNavigateTo(nextIdx, { restoring: true });
|
|
2531
|
+
return;
|
|
794
2532
|
}
|
|
795
|
-
|
|
2533
|
+
// No further test part: end the test exactly like a normal end of test.
|
|
2534
|
+
await this.endTestInternal({ reason: 'branch' });
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* The enclosing section a literal EXIT_SECTION leaves (see
|
|
2538
|
+
* `exitBoundaries.endedEnclosingSection`).
|
|
2539
|
+
*/
|
|
2540
|
+
endedEnclosingSection(current) {
|
|
2541
|
+
return endedEnclosingSection(current, this.items, this.currentItemIndex);
|
|
796
2542
|
}
|
|
797
2543
|
canPrevious() {
|
|
798
2544
|
if (this.currentItemIndex <= 0)
|
|
@@ -802,38 +2548,52 @@ export class AssessmentPlayer {
|
|
|
802
2548
|
return false;
|
|
803
2549
|
if (!this.canNavigateByTestPart(this.currentItemIndex - 1, this.currentItemIndex))
|
|
804
2550
|
return false;
|
|
805
|
-
return this.
|
|
2551
|
+
return this.canReviewItem(prev);
|
|
2552
|
+
}
|
|
2553
|
+
/**
|
|
2554
|
+
* QTI `allowReview` for returning to an item: it governs only once the item's session is
|
|
2555
|
+
* over — after its last attempt, or (adaptive) once it completed. While attempts remain
|
|
2556
|
+
* the candidate may come back and use them.
|
|
2557
|
+
*/
|
|
2558
|
+
canReviewItem(q) {
|
|
2559
|
+
const completed = isAdaptiveItemXml(q.item.itemXml) && this.itemLifecycleOf(q.identifier) === 'closed';
|
|
2560
|
+
return this.sessionCoordinator.canReview(q.identifier, { completed });
|
|
2561
|
+
}
|
|
2562
|
+
/** The lifecycle of an item's session: the live one for the active item, else the persisted handoff. */
|
|
2563
|
+
itemLifecycleOf(itemIdentifier) {
|
|
2564
|
+
const current = this.items[this.currentItemIndex];
|
|
2565
|
+
if (current?.identifier === itemIdentifier) {
|
|
2566
|
+
return (this.currentItemSession?.state().lifecycleStatus ??
|
|
2567
|
+
this.state.itemSessions?.[itemIdentifier]?.lifecycleStatus);
|
|
2568
|
+
}
|
|
2569
|
+
return this.state.itemSessions?.[itemIdentifier]?.lifecycleStatus;
|
|
806
2570
|
}
|
|
807
2571
|
canNext() {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
const nextIdx = this.nextUnlockedIndex(this.currentItemIndex);
|
|
811
|
-
if (nextIdx < 0)
|
|
812
|
-
return false;
|
|
813
|
-
if (!this.canNavigateByTestPart(nextIdx, this.currentItemIndex))
|
|
2572
|
+
const current = this.items[this.currentItemIndex];
|
|
2573
|
+
if (!current)
|
|
814
2574
|
return false;
|
|
815
2575
|
// Note: itemSessionControl constraints on leaving current item are enforced in next().
|
|
816
|
-
return
|
|
2576
|
+
return this.forwardStepIndex(current) >= 0;
|
|
817
2577
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
2578
|
+
/**
|
|
2579
|
+
* Whether a candidate-initiated move from `currentIndex` to `targetIndex` follows the
|
|
2580
|
+
* navigation rules (see `navigationPolicy.canNavigateByTestPart`).
|
|
2581
|
+
*/
|
|
2582
|
+
canNavigateByTestPart(targetIndex, currentIndex, forward = () => {
|
|
821
2583
|
const current = this.items[currentIndex];
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
return targetIndex === nextIndex;
|
|
831
|
-
}
|
|
832
|
-
const mode = current.testPart.navigationMode ?? this.assessment.navigationMode ?? 'nonlinear';
|
|
833
|
-
return mode === 'nonlinear' || targetIndex === currentIndex || targetIndex === nextIndex;
|
|
2584
|
+
return current ? this.unsubmittedForwardIndex(current) : -1;
|
|
2585
|
+
}) {
|
|
2586
|
+
return canNavigateByTestPart({
|
|
2587
|
+
targetIndex,
|
|
2588
|
+
currentIndex,
|
|
2589
|
+
items: this.items,
|
|
2590
|
+
forward,
|
|
2591
|
+
});
|
|
834
2592
|
}
|
|
835
2593
|
async submitSimultaneousItems(items) {
|
|
836
|
-
|
|
2594
|
+
// Items the backend already accepted with exactly these responses are done; one
|
|
2595
|
+
// whose recorded result predates the current responses still goes out.
|
|
2596
|
+
if (items.every((q) => !this.itemNeedsSubmission(q)))
|
|
837
2597
|
return;
|
|
838
2598
|
const current = this.items[this.currentItemIndex];
|
|
839
2599
|
const submittedItem = current && items.includes(current) ? current : undefined;
|
|
@@ -849,14 +2609,18 @@ export class AssessmentPlayer {
|
|
|
849
2609
|
// Some backend adapters return an updatedState snapshot that may only include
|
|
850
2610
|
// responses for items that have been submitted so far, which would otherwise
|
|
851
2611
|
// wipe out responses for later items during this loop.
|
|
852
|
-
const allItemResponses = cloneData(this.state.itemResponses
|
|
853
|
-
allItemSessions = cloneData(this.state.itemSessions
|
|
2612
|
+
const allItemResponses = cloneData(this.state.itemResponses) ?? {};
|
|
2613
|
+
allItemSessions = cloneData(this.state.itemSessions) ?? {};
|
|
854
2614
|
for (const q of items) {
|
|
855
|
-
if (this.
|
|
2615
|
+
if (!this.itemNeedsSubmission(q))
|
|
856
2616
|
continue;
|
|
857
2617
|
const submittedAt = Date.now();
|
|
858
|
-
const responsesForItem =
|
|
859
|
-
|
|
2618
|
+
const responsesForItem = allItemResponses[q.identifier] || {};
|
|
2619
|
+
// An item an expired limit closed (or a proctor's end of the test) submits its
|
|
2620
|
+
// responses as they stand. Response validation is an individual-part control
|
|
2621
|
+
// (QTI), and a candidate's end of the test checked those items already.
|
|
2622
|
+
const submissionReason = this.submissionReasonFor(q);
|
|
2623
|
+
const itemSession = this.endItemSessionForSubmit(q, responsesForItem, allItemSessions[q.identifier], { validate: submissionReason === undefined && this.isIndividual(q) });
|
|
860
2624
|
allItemSessions[q.identifier] = itemSession;
|
|
861
2625
|
const res = await this.backend.submitResponses({
|
|
862
2626
|
sessionId: this.sessionId,
|
|
@@ -864,31 +2628,41 @@ export class AssessmentPlayer {
|
|
|
864
2628
|
responses: responsesForItem,
|
|
865
2629
|
submittedAt,
|
|
866
2630
|
timeSpent: itemSession.duration,
|
|
867
|
-
timing: this.getSubmitTimingEvidence(q, itemSession.duration),
|
|
868
|
-
itemSession: this.
|
|
2631
|
+
timing: this.getSubmitTimingEvidence(q, itemSession.duration, submissionReason),
|
|
2632
|
+
itemSession: this.sendsItemSession() ? itemSession : undefined,
|
|
869
2633
|
comment: this.sessionCoordinator.getItemComment(q.identifier),
|
|
870
2634
|
});
|
|
871
2635
|
if (!res.success || !res.result) {
|
|
872
|
-
|
|
2636
|
+
// Backend error text stays on the Error for logs/host callbacks only.
|
|
2637
|
+
throw new AssessmentPlayerError('submitFailed', res.error || `Submit failed for item ${q.identifier}`);
|
|
873
2638
|
}
|
|
874
2639
|
if (res.updatedState) {
|
|
875
2640
|
this.sessionCoordinator.replaceStatePreservingResponsesAndSessions(res.updatedState, allItemResponses, allItemSessions);
|
|
2641
|
+
this.sessionCoordinator.setItemResult({
|
|
2642
|
+
itemIdentifier: q.identifier,
|
|
2643
|
+
score: res.result.score,
|
|
2644
|
+
maxScore: res.result.maxScore,
|
|
2645
|
+
responses: this.state.itemResponses[q.identifier] || {},
|
|
2646
|
+
});
|
|
876
2647
|
}
|
|
877
2648
|
else {
|
|
878
|
-
this.
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
2649
|
+
this.sessionCoordinator.recordSimultaneousSubmission(q.identifier, responsesForItem, itemSession, res.result);
|
|
2650
|
+
}
|
|
2651
|
+
// The accepted response set: a retry, a later collection pass, or finalize
|
|
2652
|
+
// must not re-submit identical responses for this item.
|
|
2653
|
+
this.lastSubmittedResponses.set(q.identifier, cloneResponseRecord(responsesForItem));
|
|
2654
|
+
// This submission voids every earlier decision (the outcomes they were decided
|
|
2655
|
+
// on have moved). Only a part crossing keeps the fresh one — the decision the
|
|
2656
|
+
// part's last item returns is what the crossing follows — while the end of the
|
|
2657
|
+
// test's own collection (the same submit path, for every item) stores none: it
|
|
2658
|
+
// never navigates.
|
|
2659
|
+
this.clearKeptBranchDecisions();
|
|
2660
|
+
if (this.endReason === null && res.nextItemIdentifier) {
|
|
2661
|
+
this.keepBranchDecision(q, res.nextItemIdentifier);
|
|
884
2662
|
}
|
|
885
|
-
this.sessionCoordinator.setItemResult({
|
|
886
|
-
itemIdentifier: q.identifier,
|
|
887
|
-
score: res.result.score,
|
|
888
|
-
maxScore: res.result.maxScore,
|
|
889
|
-
responses: this.state.itemResponses[q.identifier] || {},
|
|
890
|
-
});
|
|
891
2663
|
this.setTestOutcomes(res.outcomes);
|
|
2664
|
+
this.reportOutcomeProcessingError(res.outcomeProcessingError);
|
|
2665
|
+
this.reportItemScoringError(res.result);
|
|
892
2666
|
}
|
|
893
2667
|
// The attached item must represent the same accepted lifecycle as persistence.
|
|
894
2668
|
// Replace the provisional suspended object with one restored from the accepted
|
|
@@ -897,7 +2671,8 @@ export class AssessmentPlayer {
|
|
|
897
2671
|
const accepted = allItemSessions[submittedItem.identifier];
|
|
898
2672
|
if (accepted) {
|
|
899
2673
|
this.releaseCurrentItemSession();
|
|
900
|
-
|
|
2674
|
+
const presentation = this.presentationFor(submittedItem);
|
|
2675
|
+
this.attachCurrentItemSession(submittedItem, this.getItemDefinition(submittedItem).openSession({ restore: accepted, presentation }), presentation);
|
|
901
2676
|
this.notifyItemChange();
|
|
902
2677
|
}
|
|
903
2678
|
}
|
|
@@ -916,7 +2691,8 @@ export class AssessmentPlayer {
|
|
|
916
2691
|
}
|
|
917
2692
|
this.releaseCurrentItemSession();
|
|
918
2693
|
if (restored) {
|
|
919
|
-
|
|
2694
|
+
const presentation = this.presentationFor(submittedItem);
|
|
2695
|
+
this.attachCurrentItemSession(submittedItem, this.getItemDefinition(submittedItem).openSession({ restore: restored, presentation }), presentation);
|
|
920
2696
|
this.notifyItemChange();
|
|
921
2697
|
this.notifyResponseChange();
|
|
922
2698
|
}
|
|
@@ -924,28 +2700,239 @@ export class AssessmentPlayer {
|
|
|
924
2700
|
throw error;
|
|
925
2701
|
}
|
|
926
2702
|
}
|
|
927
|
-
/**
|
|
928
|
-
|
|
2703
|
+
/**
|
|
2704
|
+
* Submit the entire assessment and finalize on the backend — the single terminal
|
|
2705
|
+
* transition, also used for QTI `EXIT_TEST` (and for EXIT_TESTPART / EXIT_SECTION when
|
|
2706
|
+
* nothing follows the ended scope). Serialized with all other navigation and submission
|
|
2707
|
+
* transitions. Calling it again after the test has ended returns the same results.
|
|
2708
|
+
*
|
|
2709
|
+
* A candidate's submit is rejected while paused, and — with a coded
|
|
2710
|
+
* `finalizeResponseRequired` / `finalizeResponseInvalid` naming the items
|
|
2711
|
+
* (`getSubmissionBlockers()`) — while items in individual parts would be submitted
|
|
2712
|
+
* against their `allowSkipping=false` / `validateResponses=true` controls.
|
|
2713
|
+
*
|
|
2714
|
+
* `{ force: true }` is the proctor's administrative end of the test: it runs during a
|
|
2715
|
+
* pause, and neither minimum times nor the skipping/validation gates hold it back; the
|
|
2716
|
+
* collected submissions carry `timing.submissionReason: 'proctor'` — except items an
|
|
2717
|
+
* expired time limit closed, which go out as `time-expired` (time wins), and the end is
|
|
2718
|
+
* an `expiry` end when the time had already closed the delivery. It never fails for
|
|
2719
|
+
* concurrency: while a candidate's navigation or submission is in flight, it waits for
|
|
2720
|
+
* that transition to settle and then ends the test (when the transition itself ended
|
|
2721
|
+
* the test, it resolves with those results).
|
|
2722
|
+
*/
|
|
2723
|
+
submit(options = {}) {
|
|
2724
|
+
if (options.force === true) {
|
|
2725
|
+
return this.runWhenIdle(async () => {
|
|
2726
|
+
this.administrativeReason = 'proctor';
|
|
2727
|
+
try {
|
|
2728
|
+
return await this.endTestInternal({ administrative: true, reason: 'proctor' });
|
|
2729
|
+
}
|
|
2730
|
+
finally {
|
|
2731
|
+
this.administrativeReason = null;
|
|
2732
|
+
}
|
|
2733
|
+
});
|
|
2734
|
+
}
|
|
2735
|
+
return this.runCandidateTransition(() => this.endTestInternal({ reason: 'candidate' }));
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Run an administrative transition exclusively as soon as the lock is free: queued
|
|
2739
|
+
* behind the transition in flight (a pause, a force submit, an expiry hop) instead of
|
|
2740
|
+
* rejecting as busy. The lock is taken synchronously when the in-flight transition
|
|
2741
|
+
* releases it, so no candidate action can slip in between. Rejects only when the
|
|
2742
|
+
* player is destroyed.
|
|
2743
|
+
*/
|
|
2744
|
+
runWhenIdle(operation) {
|
|
2745
|
+
if (this.destroyed) {
|
|
2746
|
+
return Promise.reject(new AssessmentPlayerError('navigationNotAllowed', 'The assessment player was destroyed.'));
|
|
2747
|
+
}
|
|
2748
|
+
if (!this.transitionInFlight)
|
|
2749
|
+
return this.runExclusive(operation);
|
|
2750
|
+
return new Promise((resolve, reject) => {
|
|
2751
|
+
const cancel = (error) => {
|
|
2752
|
+
off();
|
|
2753
|
+
reject(error);
|
|
2754
|
+
};
|
|
2755
|
+
const off = this.onBusyChange((busy) => {
|
|
2756
|
+
if (busy || this.transitionInFlight)
|
|
2757
|
+
return;
|
|
2758
|
+
off();
|
|
2759
|
+
this.queuedIdleTransitions.delete(cancel);
|
|
2760
|
+
this.runWhenIdle(operation).then(resolve, reject);
|
|
2761
|
+
});
|
|
2762
|
+
this.queuedIdleTransitions.add(cancel);
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Whether an expired hard limit closed the delivery: the whole test expired, or the
|
|
2767
|
+
* current item sits inside an expired scope and no open question remains reachable from
|
|
2768
|
+
* it (an expiry dead end). An earlier question still open in the part keeps delivery
|
|
2769
|
+
* open — the expiry moves the candidate there instead — so its skipping/validation
|
|
2770
|
+
* controls and minimum times keep applying. Only a closed delivery is collected as
|
|
2771
|
+
* `time-expired` without them.
|
|
2772
|
+
*/
|
|
2773
|
+
isTimeClosedDelivery() {
|
|
2774
|
+
if (this.assessmentExpired)
|
|
2775
|
+
return true;
|
|
929
2776
|
const current = this.items[this.currentItemIndex];
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
2777
|
+
return current !== undefined && this.isItemLocked(current) && this.openItemAfterClosure(current.index) < 0;
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
* Why an item's submission runs: an item an expired hard limit closed submits the
|
|
2781
|
+
* responses frozen at the expiry (`time-expired`) — its own scope expired, or the
|
|
2782
|
+
* whole test did; a proctor's forced end of the test collects as `proctor`; a question
|
|
2783
|
+
* the candidate can no longer reach although its QTI skipping/validation control would
|
|
2784
|
+
* refuse it is collected as it stands (`unreachable`); everything else is a normal
|
|
2785
|
+
* candidate submission.
|
|
2786
|
+
*/
|
|
2787
|
+
submissionReasonFor(q) {
|
|
2788
|
+
if (this.assessmentExpired || this.isItemLocked(q))
|
|
2789
|
+
return 'time-expired';
|
|
2790
|
+
if (this.administrativeReason)
|
|
2791
|
+
return this.administrativeReason;
|
|
2792
|
+
if (this.unreachableCollection.has(q.identifier))
|
|
2793
|
+
return 'unreachable';
|
|
2794
|
+
return undefined;
|
|
2795
|
+
}
|
|
2796
|
+
/**
|
|
2797
|
+
* The one normal-end-of-test path: pending simultaneous-mode responses are submitted,
|
|
2798
|
+
* the current individual-mode item is submitted if needed, then the backend finalizes
|
|
2799
|
+
* (outcome processing runs, results are produced) and navigation closes. Individual-
|
|
2800
|
+
* mode attempts an expired limit closed are collected as well: their responses were
|
|
2801
|
+
* frozen when the time ran out. The same is true for any visited individual-mode item
|
|
2802
|
+
* whose responses never reached the backend because the candidate jumped away without
|
|
2803
|
+
* a forward submission (nonlinear `navigateTo`/`previous` submit nothing): it is
|
|
2804
|
+
* collected through the same detached end-attempt loop instead of being finalized
|
|
2805
|
+
* from NULL.
|
|
2806
|
+
*
|
|
2807
|
+
* A candidate-initiated end of the test first checks the QTI submission controls of
|
|
2808
|
+
* individual parts: it never submits an item without a response while
|
|
2809
|
+
* `allowSkipping=false`, nor an answered item whose responses fail validation while
|
|
2810
|
+
* `validateResponses=true` — it rejects naming them instead, as long as the candidate
|
|
2811
|
+
* can still reach them. A question in a test part already left cannot hold the end of
|
|
2812
|
+
* the test: it is collected as it stands (`submissionReason: 'unreachable'`). An
|
|
2813
|
+
* administrative end (a time expiry, a proctor's forced submit) collects everything as
|
|
2814
|
+
* it stands; an item a skipping control held back is then recorded as skipped.
|
|
2815
|
+
*
|
|
2816
|
+
* `reason` records why the test ends; the outermost caller decides (a candidate's
|
|
2817
|
+
* submit whose final submission branches to EXIT_TEST stays a candidate end) — except
|
|
2818
|
+
* that an end collecting a delivery the time already closed (the whole test expired, or
|
|
2819
|
+
* an expiry dead end left nothing open) is an `expiry` end whoever triggers it: the
|
|
2820
|
+
* auto-finalize, the candidate's Submit after it failed, a proctor's force-submit.
|
|
2821
|
+
*
|
|
2822
|
+
* The end never navigates: it collects where the candidate stands. A branch decision
|
|
2823
|
+
* its own submission returns is kept on record (`followBranch`), and a scope expiry
|
|
2824
|
+
* while it runs only closes the scope — moving delivery off it waits for this end and
|
|
2825
|
+
* happens only if the end does not finalize.
|
|
2826
|
+
*/
|
|
2827
|
+
async endTestInternal(options = {}) {
|
|
2828
|
+
if (this.finalized && this.finalResults)
|
|
2829
|
+
return this.finalResults;
|
|
2830
|
+
const outermost = this.endReason === null;
|
|
2831
|
+
if (outermost)
|
|
2832
|
+
this.endReason = this.isTimeClosedDelivery() ? 'expiry' : (options.reason ?? 'candidate');
|
|
2833
|
+
try {
|
|
2834
|
+
return await this.collectAndFinalize(options.administrative === true);
|
|
2835
|
+
}
|
|
2836
|
+
finally {
|
|
2837
|
+
if (outermost) {
|
|
2838
|
+
this.unreachableCollection = new Set();
|
|
2839
|
+
const heldExpiries = this.expiriesDuringEnd.splice(0);
|
|
2840
|
+
if (!this.finalized) {
|
|
2841
|
+
// A refused or failed end leaves the test running: no reason is pending,
|
|
2842
|
+
// and delivery now leaves the scopes that expired while it ran — inline,
|
|
2843
|
+
// under the lock the end still holds.
|
|
2844
|
+
this.endReason = null;
|
|
2845
|
+
for (const expiry of heldExpiries)
|
|
2846
|
+
void this.leaveExpiredScopeLocked(expiry.scope, expiry.identifier);
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
async collectAndFinalize(administrative) {
|
|
2852
|
+
const closed = administrative || this.isTimeClosedDelivery();
|
|
2853
|
+
const current = this.items[this.currentItemIndex];
|
|
2854
|
+
if (current && !closed) {
|
|
2855
|
+
// A current item an expired limit closed is collected as it stands: its own and
|
|
2856
|
+
// its scopes' minimum times cannot hold the end of the test.
|
|
2857
|
+
if (!this.isItemLocked(current)) {
|
|
2858
|
+
this.assertMinimumTime('item', current);
|
|
2859
|
+
this.assertEnclosingSectionMinimumTime(current);
|
|
2860
|
+
this.assertMinimumTime('testPart', current);
|
|
2861
|
+
}
|
|
934
2862
|
this.assertMinimumTime('assessment', current);
|
|
935
2863
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
2864
|
+
if (!closed)
|
|
2865
|
+
this.assertNoSubmissionBlockers();
|
|
2866
|
+
// Questions the candidate can no longer reach go out as they stand, marked so the
|
|
2867
|
+
// backend never mistakes them for a normal candidate submission.
|
|
2868
|
+
if (!administrative) {
|
|
2869
|
+
this.unreachableCollection = new Set(this.getUnreachableSubmissionBlockers().map((blocker) => blocker.identifier));
|
|
2870
|
+
}
|
|
2871
|
+
const isIndividual = (q) => this.isIndividual(q);
|
|
2872
|
+
await this.submitSimultaneousItems(this.items.filter((q) => q.testPart.submissionMode === 'simultaneous'));
|
|
2873
|
+
if (this.finalized && this.finalResults)
|
|
2874
|
+
return this.finalResults;
|
|
2875
|
+
await this.submitSimultaneousItems(this.items.filter((q) => q !== current &&
|
|
2876
|
+
isIndividual(q) &&
|
|
2877
|
+
this.navigationManager.isVisited(q.index) &&
|
|
2878
|
+
// Only what the backend has not accepted yet: an expired limit froze the
|
|
2879
|
+
// item's responses, but responses it already accepted are never re-sent
|
|
2880
|
+
// (that would spend another attempt and fail the end of the test).
|
|
2881
|
+
this.itemNeedsSubmission(q)));
|
|
939
2882
|
const q = this.items[this.currentItemIndex];
|
|
940
|
-
if (q && (q
|
|
941
|
-
|
|
942
|
-
|
|
2883
|
+
if (q && isIndividual(q)) {
|
|
2884
|
+
const liveStatus = this.currentItemSession?.state().lifecycleStatus;
|
|
2885
|
+
const liveWritable = liveStatus !== undefined && isWritableItemLifecycle(liveStatus);
|
|
2886
|
+
const hasResult = this.sessionCoordinator.hasItemResult(q.identifier);
|
|
2887
|
+
// An item without a recorded result is collected as it stands (an expired limit
|
|
2888
|
+
// closed it, or the candidate is leaving it open). An item with a recorded
|
|
2889
|
+
// result — a practice check — re-submits only when the live attempt is still
|
|
2890
|
+
// open, attempts remain, and the candidate changed their response.
|
|
2891
|
+
const needsSubmission = !hasResult
|
|
2892
|
+
? true
|
|
2893
|
+
: liveWritable
|
|
2894
|
+
? this.sessionCoordinator.canSubmit(q.identifier) &&
|
|
2895
|
+
!this.responsesUnchangedSinceSubmission(q.identifier)
|
|
2896
|
+
: false;
|
|
2897
|
+
if (needsSubmission) {
|
|
2898
|
+
// Collected where the candidate stands: a branch decision this submission
|
|
2899
|
+
// returns is kept on record, never followed (`followBranch`).
|
|
2900
|
+
await this.submitCurrentItemInternal();
|
|
2901
|
+
if (this.finalized && this.finalResults)
|
|
2902
|
+
return this.finalResults;
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
return this.finalizeInternal();
|
|
2906
|
+
}
|
|
2907
|
+
async finalizeInternal() {
|
|
2908
|
+
if (this.finalized && this.finalResults)
|
|
2909
|
+
return this.finalResults;
|
|
2910
|
+
// Persist the final draft before the backend finalizes: outcome processing reads
|
|
2911
|
+
// the stored timing (the built-in durations), so it must see the end-of-test
|
|
2912
|
+
// clocks, not the last debounced autosave. Safe mid-transition (inside the
|
|
2913
|
+
// exclusive lock); a failed save stays non-fatal. It is the record of the ended
|
|
2914
|
+
// test, so every item session in it is over: a practice item reopened for attempts
|
|
2915
|
+
// the candidate did not use stands closed, as the backend last accepted it (the
|
|
2916
|
+
// collection re-sent every changed response).
|
|
2917
|
+
this.snapshotsCloseItemSessions = true;
|
|
2918
|
+
try {
|
|
2919
|
+
await this.autosave?.flushImmediate();
|
|
2920
|
+
}
|
|
2921
|
+
finally {
|
|
2922
|
+
this.snapshotsCloseItemSessions = false;
|
|
2923
|
+
}
|
|
2924
|
+
let finalized;
|
|
2925
|
+
try {
|
|
2926
|
+
finalized = await this.backend.finalizeAssessment({ sessionId: this.sessionId });
|
|
2927
|
+
if (!finalized.success)
|
|
2928
|
+
throw new AssessmentPlayerError('finalizeFailed', 'Finalize failed');
|
|
2929
|
+
}
|
|
2930
|
+
catch (error) {
|
|
2931
|
+
// The test goes on: the stored draft gets its open sessions back, so attempts the
|
|
2932
|
+
// candidate may still use survive a reload.
|
|
2933
|
+
await this.autosave?.flushImmediate();
|
|
2934
|
+
throw error;
|
|
943
2935
|
}
|
|
944
|
-
const finalized = await this.backend.finalizeAssessment({
|
|
945
|
-
sessionId: this.sessionId,
|
|
946
|
-
});
|
|
947
|
-
if (!finalized.success)
|
|
948
|
-
throw new Error('Finalize failed');
|
|
949
2936
|
// Map backend itemScores to ItemResult[]
|
|
950
2937
|
const itemScores = finalized.itemScores || {};
|
|
951
2938
|
const itemResults = Object.values(itemScores).map((r) => ({
|
|
@@ -957,23 +2944,125 @@ export class AssessmentPlayer {
|
|
|
957
2944
|
// Outcome processing has run by the end of the test, so a backend returning no outcomes
|
|
958
2945
|
// leaves them all NULL.
|
|
959
2946
|
this.finalized = true;
|
|
960
|
-
|
|
2947
|
+
// A proctor's forced end of the test may land during a pause: the session is over,
|
|
2948
|
+
// so the pause no longer holds anything (no pause event — the end of the test is it).
|
|
2949
|
+
this.pauseControl.clearSilently();
|
|
2950
|
+
this.suspendedForPause = false;
|
|
2951
|
+
// The test ended through its real submission: draft autosave has nothing left to do.
|
|
2952
|
+
this.autosave?.stop();
|
|
2953
|
+
// Delivery is over: no clock keeps running, and no later expiry can fire.
|
|
2954
|
+
this.timeManager?.pause();
|
|
2955
|
+
this.timeManager?.stopTimer();
|
|
961
2956
|
this.testOutcomes = cloneData(finalized.outcomes ?? this.testOutcomes ?? {});
|
|
2957
|
+
// The persisted snapshot carries them (testFeedback and rules read them on a resume).
|
|
2958
|
+
this.sessionCoordinator.setTestOutcomes(this.testOutcomes);
|
|
962
2959
|
this.notifyTestFeedbackChange();
|
|
963
|
-
this.
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
2960
|
+
this.reportOutcomeProcessingError(finalized.outcomeProcessingError);
|
|
2961
|
+
const endReason = this.endReason ?? 'candidate';
|
|
2962
|
+
this.endReason = endReason;
|
|
2963
|
+
const results = {
|
|
967
2964
|
totalScore: finalized.totalScore,
|
|
968
2965
|
maxScore: finalized.maxScore,
|
|
969
2966
|
itemResults,
|
|
970
2967
|
completedAt: new Date(finalized.finalizedAt),
|
|
2968
|
+
endReason,
|
|
971
2969
|
};
|
|
2970
|
+
if (this.reportedOutcomeProcessingError) {
|
|
2971
|
+
results.outcomeProcessingError = this.reportedOutcomeProcessingError;
|
|
2972
|
+
}
|
|
2973
|
+
this.finalResults = results;
|
|
2974
|
+
// The test is over: no decision remains for delivery to follow.
|
|
2975
|
+
this.clearKeptBranchDecisions();
|
|
2976
|
+
// Every delivered item session is over, the active one included: the player's record
|
|
2977
|
+
// of the ended test reports each as final, never as owing a submission.
|
|
2978
|
+
this.closeItemSessionsForEnd();
|
|
2979
|
+
// Completion listeners run once the results exist, so `getResultsSummary()` (the
|
|
2980
|
+
// shell's completion screen), `getEndReason()` and `submit()` already report them.
|
|
2981
|
+
// Every ending reaches them alike — a candidate submit, a proctor's force-submit, an
|
|
2982
|
+
// EXIT_TEST branch, a whole-test expiry — so a shell hands the results to its host
|
|
2983
|
+
// from here.
|
|
2984
|
+
this.notifyComplete(results);
|
|
2985
|
+
if (this.config.onComplete)
|
|
2986
|
+
this.config.onComplete(results);
|
|
2987
|
+
this.config.onFinalized?.({ restored: false, results, endReason });
|
|
2988
|
+
return results;
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* Why the test ended in this delivery (`candidate`, `expiry`, `proctor` or `branch`);
|
|
2992
|
+
* null while it runs and for a session restored already finalized.
|
|
2993
|
+
*/
|
|
2994
|
+
getEndReason() {
|
|
2995
|
+
return this.finalized ? this.endReason : null;
|
|
2996
|
+
}
|
|
2997
|
+
/**
|
|
2998
|
+
* The test ended: close every delivered item session in the player's record. Nothing
|
|
2999
|
+
* can be submitted any more, so an item a practice check reopened for attempts the
|
|
3000
|
+
* candidate did not use stands as the backend accepted it; the active item's live
|
|
3001
|
+
* session is replaced by a closed one (read-only; no item change — the end never
|
|
3002
|
+
* navigates).
|
|
3003
|
+
*/
|
|
3004
|
+
closeItemSessionsForEnd() {
|
|
3005
|
+
this.sessionCoordinator.closeAllItemSessions();
|
|
3006
|
+
const q = this.items[this.currentItemIndex];
|
|
3007
|
+
const live = this.currentItemSession;
|
|
3008
|
+
if (!q || !live || live.state().lifecycleStatus === 'closed')
|
|
3009
|
+
return;
|
|
3010
|
+
const closed = closedItemSession(live.serialize());
|
|
3011
|
+
this.sessionCoordinator.setItemSession(q.identifier, closed);
|
|
3012
|
+
const presentation = this.presentationFor(q);
|
|
3013
|
+
this.releaseCurrentItemSession();
|
|
3014
|
+
this.attachCurrentItemSession(q, this.getItemDefinition(q).openSession({ restore: closed, presentation }), presentation);
|
|
3015
|
+
}
|
|
3016
|
+
/**
|
|
3017
|
+
* Surface a backend test-level outcome-processing failure to the host (onError and,
|
|
3018
|
+
* for finalize, the results). Candidate responses stay accepted and persisted; only
|
|
3019
|
+
* SCORE/testFeedback computation failed.
|
|
3020
|
+
*/
|
|
3021
|
+
reportOutcomeProcessingError(error) {
|
|
3022
|
+
if (!error)
|
|
3023
|
+
return;
|
|
3024
|
+
const isNew = !this.reportedOutcomeProcessingError ||
|
|
3025
|
+
this.reportedOutcomeProcessingError.message !== error.message ||
|
|
3026
|
+
this.reportedOutcomeProcessingError.code !== error.code;
|
|
3027
|
+
this.reportedOutcomeProcessingError = error;
|
|
3028
|
+
if (isNew) {
|
|
3029
|
+
this.config.onError?.(new AssessmentPlayerError('outcomeProcessingFailed', error.message, { code: error.code }));
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
/**
|
|
3033
|
+
* A backend scoring result whose response processing failed carries a degenerate 0
|
|
3034
|
+
* (its declared maximum where known) plus a `scoringError` — the item-level mirror of
|
|
3035
|
+
* `outcomeProcessingError`. The submission stands and delivery continues, but the host
|
|
3036
|
+
* must be able to tell "answered wrong" from "the engine failed to score"; each
|
|
3037
|
+
* distinct item failure is reported once.
|
|
3038
|
+
*/
|
|
3039
|
+
reportItemScoringError(result) {
|
|
3040
|
+
const error = result?.scoringError;
|
|
3041
|
+
if (!error)
|
|
3042
|
+
return;
|
|
3043
|
+
const itemIdentifier = result?.itemIdentifier;
|
|
3044
|
+
this.reportOnce(this.reportedItemScoringErrors, `${itemIdentifier}\n${error.message}`, () => new AssessmentPlayerError('itemScoringFailed', error.message, {
|
|
3045
|
+
itemIdentifier: itemIdentifier ?? '',
|
|
3046
|
+
code: error.code,
|
|
3047
|
+
}));
|
|
3048
|
+
}
|
|
3049
|
+
/**
|
|
3050
|
+
* Report a distinct failure to the host once: `seen` holds the keys already reported,
|
|
3051
|
+
* `key` encodes what makes one failure distinct from another (each reporter composes
|
|
3052
|
+
* its own), and `build` constructs the coded error the host hears through
|
|
3053
|
+
* `config.onError` the first time the key is seen.
|
|
3054
|
+
*/
|
|
3055
|
+
reportOnce(seen, key, build) {
|
|
3056
|
+
if (seen.has(key))
|
|
3057
|
+
return;
|
|
3058
|
+
seen.add(key);
|
|
3059
|
+
this.config.onError?.(build());
|
|
972
3060
|
}
|
|
973
3061
|
// ---------------------------------------------------------------------------
|
|
974
3062
|
// Session info + time helpers
|
|
975
3063
|
// ---------------------------------------------------------------------------
|
|
976
|
-
|
|
3064
|
+
/** The current item's session-control state (attempts, feedback, review, skipping, comments); null before delivery. */
|
|
3065
|
+
getItemSessionInfo() {
|
|
977
3066
|
const q = this.items[this.currentItemIndex];
|
|
978
3067
|
if (!q)
|
|
979
3068
|
return null;
|
|
@@ -989,6 +3078,8 @@ export class AssessmentPlayer {
|
|
|
989
3078
|
if (!id)
|
|
990
3079
|
throw new Error('No current item');
|
|
991
3080
|
this.sessionCoordinator.setItemComment(id, comment);
|
|
3081
|
+
// Comments ride the persisted snapshot (`itemComments`), so autosave runs too.
|
|
3082
|
+
this.notifyAutosaveActivity();
|
|
992
3083
|
}
|
|
993
3084
|
getItemComment(itemIdentifier) {
|
|
994
3085
|
const id = itemIdentifier ?? this.items[this.currentItemIndex]?.identifier;
|
|
@@ -1005,103 +3096,262 @@ export class AssessmentPlayer {
|
|
|
1005
3096
|
return this.timeManager?.isExpired() ?? false;
|
|
1006
3097
|
}
|
|
1007
3098
|
// ---------------------------------------------------------------------------
|
|
3099
|
+
// Time administration: begin gate, proctor pause, countdown state
|
|
3100
|
+
// ---------------------------------------------------------------------------
|
|
3101
|
+
/** Whether delivery has begun. False only while an opt-in begin gate holds the start screen. */
|
|
3102
|
+
hasStarted() {
|
|
3103
|
+
return this.started;
|
|
3104
|
+
}
|
|
3105
|
+
/**
|
|
3106
|
+
* Open the begin gate (`beginGate` config): enter the first — or restored — item and
|
|
3107
|
+
* start every clock. The shell calls it from its Begin button. Idempotent, and a no-op
|
|
3108
|
+
* without a begin gate (the player then started at creation). A proctor pause in
|
|
3109
|
+
* force keeps the clocks frozen until `resume()`.
|
|
3110
|
+
*/
|
|
3111
|
+
start() {
|
|
3112
|
+
// A test that already ended (a proctor's force-submit behind the gate) never starts.
|
|
3113
|
+
if (this.started || this.destroyed || this.finalized)
|
|
3114
|
+
return;
|
|
3115
|
+
this.started = true;
|
|
3116
|
+
if (!this.paused)
|
|
3117
|
+
this.timeManager?.resume();
|
|
3118
|
+
this.enterInitialItem();
|
|
3119
|
+
this.finalizeRestoredExpiryWhenRunning();
|
|
3120
|
+
}
|
|
3121
|
+
/**
|
|
3122
|
+
* Proctor pause. Freezes every clock — assessment, test part, section and item; the
|
|
3123
|
+
* live attempt is suspended so its QTI `duration` stops too — and rejects candidate
|
|
3124
|
+
* actions with a coded `assessmentPaused` error until `resume()`. `reason` is
|
|
3125
|
+
* host-supplied, candidate-facing text shown with the pause (localize it in the host).
|
|
3126
|
+
* A pause requested during a navigation or submission applies once it settles; while
|
|
3127
|
+
* already paused, a new reason replaces the shown one. No-op after the test ended.
|
|
3128
|
+
*/
|
|
3129
|
+
pause(reason) {
|
|
3130
|
+
if (this.finalized || this.destroyed)
|
|
3131
|
+
return;
|
|
3132
|
+
this.pauseControl.pause(reason);
|
|
3133
|
+
}
|
|
3134
|
+
/** End a proctor pause: the clocks continue and the live attempt reopens where it stood. */
|
|
3135
|
+
resume() {
|
|
3136
|
+
this.pauseControl.resume();
|
|
3137
|
+
}
|
|
3138
|
+
isPaused() {
|
|
3139
|
+
return this.paused;
|
|
3140
|
+
}
|
|
3141
|
+
/** The candidate-facing reason given for the current pause, if any. */
|
|
3142
|
+
getPauseReason() {
|
|
3143
|
+
return this.paused ? this.pauseReason : undefined;
|
|
3144
|
+
}
|
|
3145
|
+
/** The countdown a shell shows: the active scope's nearest hard maximum and the clock state. */
|
|
3146
|
+
getTimeState() {
|
|
3147
|
+
const nearest = this.timeManager?.getNearestLimit() ?? null;
|
|
3148
|
+
return {
|
|
3149
|
+
limited: nearest !== null,
|
|
3150
|
+
remainingSeconds: nearest ? Math.max(0, Math.ceil(nearest.remainingSeconds)) : null,
|
|
3151
|
+
elapsedSeconds: this.getElapsedTime(),
|
|
3152
|
+
expired: nearest !== null && nearest.remainingSeconds <= 0,
|
|
3153
|
+
scope: nearest?.scope ?? null,
|
|
3154
|
+
allowLateSubmission: nearest?.allowLateSubmission ?? false,
|
|
3155
|
+
paused: this.paused,
|
|
3156
|
+
started: this.started,
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
/**
|
|
3160
|
+
* Whether the session is terminal: the test has ended here, or the backend restored a
|
|
3161
|
+
* session it had already finalized. Shells show their completed view; `submit()`
|
|
3162
|
+
* returns the stored results without another backend round trip.
|
|
3163
|
+
*/
|
|
3164
|
+
isFinalized() {
|
|
3165
|
+
return this.finalized;
|
|
3166
|
+
}
|
|
3167
|
+
/** The stored results of a session restored already finalized. */
|
|
3168
|
+
finalResultsFromInit(init) {
|
|
3169
|
+
const summary = init.finalResults;
|
|
3170
|
+
const itemScores = summary?.itemScores ?? {};
|
|
3171
|
+
const itemResults = Object.values(itemScores).map((r) => ({
|
|
3172
|
+
itemIdentifier: r.itemIdentifier,
|
|
3173
|
+
score: r.score,
|
|
3174
|
+
maxScore: r.maxScore,
|
|
3175
|
+
responses: (this.state.itemResponses[r.itemIdentifier] ?? {}),
|
|
3176
|
+
}));
|
|
3177
|
+
return {
|
|
3178
|
+
totalScore: summary?.totalScore ?? 0,
|
|
3179
|
+
maxScore: summary?.maxScore ?? 0,
|
|
3180
|
+
itemResults,
|
|
3181
|
+
completedAt: new Date(summary?.finalizedAt ?? Date.now()),
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
/**
|
|
3185
|
+
* What a start screen shows before delivery begins: the test title, the time the
|
|
3186
|
+
* candidate has for the whole test (PNP extended time applied; what remains of it for
|
|
3187
|
+
* a resumed session), whether parts, sections or items carry their own limits, and the
|
|
3188
|
+
* first test part's rubric blocks (role-filter them before display).
|
|
3189
|
+
*/
|
|
3190
|
+
getStartInfo() {
|
|
3191
|
+
const extended = this.config.pnp?.content?.extendedTime;
|
|
3192
|
+
const limited = (limits) => limits?.maxTime !== undefined && extendTimeLimit(limits.maxTime, extended) !== undefined;
|
|
3193
|
+
const testRemaining = this.timeManager?.getAssessmentRemainingSeconds() ?? null;
|
|
3194
|
+
const firstPart = this.items[0]?.testPart ?? this.assessment.testParts?.[0];
|
|
3195
|
+
return {
|
|
3196
|
+
title: this.getAssessmentTitle(),
|
|
3197
|
+
testTimeLimitSeconds: testRemaining === null ? undefined : Math.max(0, Math.ceil(testRemaining)),
|
|
3198
|
+
hasScopedTimeLimits: this.items.some((q) => limited(q.testPart.timeLimits) ||
|
|
3199
|
+
q.sections.some((section) => limited(section.timeLimits)) ||
|
|
3200
|
+
limited(q.item.timeLimits)),
|
|
3201
|
+
rubricBlocks: (firstPart?.rubricBlocks ?? []).map((block) => ({ ...block, view: [...block.view] })),
|
|
3202
|
+
totalItems: this.items.length,
|
|
3203
|
+
resuming: (this.state.timing?.totalTime ?? 0) > 0 || this.state.visitedItems.length > 0,
|
|
3204
|
+
savedAt: this.getRestoredSavedAt(),
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3207
|
+
/** Whether the candidate hid the countdown. Persisted in the session state, like flags. */
|
|
3208
|
+
isTimerHidden() {
|
|
3209
|
+
return this.state.timerHidden === true;
|
|
3210
|
+
}
|
|
3211
|
+
setTimerHidden(hidden) {
|
|
3212
|
+
this.sessionCoordinator.setTimerHidden(hidden);
|
|
3213
|
+
// The preference rides the persisted snapshot, like flags.
|
|
3214
|
+
this.notifyAutosaveActivity();
|
|
3215
|
+
}
|
|
3216
|
+
// ---------------------------------------------------------------------------
|
|
1008
3217
|
// Event subscriptions
|
|
1009
3218
|
// ---------------------------------------------------------------------------
|
|
1010
3219
|
onItemChange(listener) {
|
|
1011
|
-
this.
|
|
1012
|
-
return () => this.itemChangeListeners.delete(listener);
|
|
3220
|
+
return this.events.on('itemChange', listener);
|
|
1013
3221
|
}
|
|
1014
3222
|
onSectionChange(listener) {
|
|
1015
|
-
this.
|
|
1016
|
-
return () => this.sectionChangeListeners.delete(listener);
|
|
3223
|
+
return this.events.on('sectionChange', listener);
|
|
1017
3224
|
}
|
|
1018
3225
|
onResponseChange(listener) {
|
|
1019
|
-
this.
|
|
1020
|
-
return () => this.responseChangeListeners.delete(listener);
|
|
3226
|
+
return this.events.on('responseChange', listener);
|
|
1021
3227
|
}
|
|
3228
|
+
/**
|
|
3229
|
+
* The test ended in this delivery — by any path: a candidate submit, a proctor's
|
|
3230
|
+
* force-submit, a QTI EXIT_TEST branch, a whole-test expiry — with its results.
|
|
3231
|
+
*/
|
|
1022
3232
|
onComplete(listener) {
|
|
1023
|
-
this.
|
|
1024
|
-
|
|
3233
|
+
return this.events.on('complete', listener);
|
|
3234
|
+
}
|
|
3235
|
+
/** Fires when a navigation/submission transition starts or ends (`getNavigationState().isLoading` mirrors this). */
|
|
3236
|
+
onBusyChange(listener) {
|
|
3237
|
+
return this.events.on('busyChange', listener);
|
|
1025
3238
|
}
|
|
1026
3239
|
/** Called when `getVisibleFeedback()` may have changed: new outcomes, a new test part, or the end. */
|
|
1027
3240
|
onTestFeedbackChange(listener) {
|
|
1028
|
-
this.
|
|
1029
|
-
return () => this.testFeedbackChangeListeners.delete(listener);
|
|
3241
|
+
return this.events.on('testFeedbackChange', listener);
|
|
1030
3242
|
}
|
|
1031
3243
|
onTimeWarning(listener) {
|
|
1032
|
-
this.
|
|
1033
|
-
return () => this.timeWarningListeners.delete(listener);
|
|
3244
|
+
return this.events.on('timeWarning', listener);
|
|
1034
3245
|
}
|
|
3246
|
+
/**
|
|
3247
|
+
* A hard time limit ran out with no late submission: the whole test (the core then
|
|
3248
|
+
* finalizes automatically; the event follows with `autoFinalized`, or with
|
|
3249
|
+
* `submissionRequired` when finalization failed), or a scope whose expiry leaves nothing
|
|
3250
|
+
* unlocked (`submissionRequired`: the candidate must submit now).
|
|
3251
|
+
*/
|
|
1035
3252
|
onTimeExpired(listener) {
|
|
1036
|
-
this.
|
|
1037
|
-
|
|
3253
|
+
return this.events.on('timeExpired', listener);
|
|
3254
|
+
}
|
|
3255
|
+
/** A test part, section or item limit expired: its items closed, delivery moved on if it could. */
|
|
3256
|
+
onScopeTimeExpired(listener) {
|
|
3257
|
+
return this.events.on('scopeTimeExpired', listener);
|
|
3258
|
+
}
|
|
3259
|
+
/** Fires when a proctor pause starts (with its reason) or ends. */
|
|
3260
|
+
onPauseChange(listener) {
|
|
3261
|
+
return this.events.on('pauseChange', listener);
|
|
1038
3262
|
}
|
|
1039
3263
|
onTimeTick(listener) {
|
|
1040
|
-
this.
|
|
1041
|
-
return () => this.timeTickListeners.delete(listener);
|
|
3264
|
+
return this.events.on('timeTick', listener);
|
|
1042
3265
|
}
|
|
1043
3266
|
destroy() {
|
|
3267
|
+
this.destroyed = true;
|
|
3268
|
+
// A transition queued behind the one in flight can no longer run.
|
|
3269
|
+
for (const cancel of [...this.queuedIdleTransitions]) {
|
|
3270
|
+
cancel(new AssessmentPlayerError('navigationNotAllowed', 'The assessment player was destroyed.'));
|
|
3271
|
+
}
|
|
3272
|
+
this.queuedIdleTransitions.clear();
|
|
3273
|
+
this.autosave?.stop();
|
|
1044
3274
|
this.timeManager?.destroy();
|
|
1045
3275
|
this.releaseCurrentItemSession();
|
|
3276
|
+
this.lastItemFeedback = null;
|
|
3277
|
+
this.clearKeptBranchDecisions();
|
|
1046
3278
|
this.itemDefinitions.clear();
|
|
1047
|
-
this.
|
|
1048
|
-
this.
|
|
1049
|
-
this.responseChangeListeners.clear();
|
|
1050
|
-
this.completeListeners.clear();
|
|
1051
|
-
this.testFeedbackChangeListeners.clear();
|
|
1052
|
-
this.timeWarningListeners.clear();
|
|
1053
|
-
this.timeExpiredListeners.clear();
|
|
1054
|
-
this.timeTickListeners.clear();
|
|
3279
|
+
this.events.clear();
|
|
3280
|
+
this.reviewInfoCache.clear();
|
|
1055
3281
|
}
|
|
1056
3282
|
// ---------------------------------------------------------------------------
|
|
1057
3283
|
// Internal notify helpers
|
|
1058
3284
|
// ---------------------------------------------------------------------------
|
|
1059
3285
|
notifyItemChange() {
|
|
1060
|
-
|
|
1061
|
-
l(this.currentItemIndex, this.items.length);
|
|
3286
|
+
this.events.emit('itemChange', this.currentItemIndex, this.items.length);
|
|
1062
3287
|
this.config.onItemChange?.(this.currentItemIndex, this.items.length);
|
|
3288
|
+
// A navigation settles into a new draft worth persisting.
|
|
3289
|
+
this.notifyAutosaveActivity();
|
|
1063
3290
|
}
|
|
1064
3291
|
notifySectionChange() {
|
|
1065
3292
|
const q = this.items[this.currentItemIndex];
|
|
1066
|
-
const sectionIndex = q?.sectionIndex ??
|
|
1067
|
-
const totalSections = this.
|
|
1068
|
-
|
|
1069
|
-
l(sectionIndex, totalSections);
|
|
3293
|
+
const sectionIndex = q?.sectionIndex ?? -1;
|
|
3294
|
+
const totalSections = this.presentedSectionList().length;
|
|
3295
|
+
this.events.emit('sectionChange', sectionIndex, totalSections);
|
|
1070
3296
|
this.config.onSectionChange?.(sectionIndex, totalSections);
|
|
1071
3297
|
}
|
|
1072
3298
|
notifyResponseChange() {
|
|
1073
3299
|
const responses = this.sessionCoordinator.getActiveResponses();
|
|
1074
|
-
|
|
1075
|
-
l(responses);
|
|
3300
|
+
this.events.emit('responseChange', responses);
|
|
1076
3301
|
this.config.onResponseChange?.(responses);
|
|
3302
|
+
// Candidate input happened: restart the autosave debounce.
|
|
3303
|
+
this.notifyAutosaveActivity();
|
|
3304
|
+
}
|
|
3305
|
+
notifyComplete(results) {
|
|
3306
|
+
this.events.emit('complete', results);
|
|
1077
3307
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
l();
|
|
3308
|
+
notifyBusyChange(busy) {
|
|
3309
|
+
this.events.emit('busyChange', busy);
|
|
1081
3310
|
}
|
|
1082
3311
|
notifyTestFeedbackChange() {
|
|
1083
|
-
|
|
1084
|
-
l();
|
|
3312
|
+
this.events.emit('testFeedbackChange');
|
|
1085
3313
|
}
|
|
1086
3314
|
notifyTimeWarning(remainingSeconds) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
3315
|
+
this.events.emit('timeWarning', remainingSeconds);
|
|
3316
|
+
}
|
|
3317
|
+
notifyPauseChange() {
|
|
3318
|
+
const reason = this.pauseReason;
|
|
3319
|
+
this.events.emit('pauseChange', this.paused, reason);
|
|
3320
|
+
this.config.onPauseChange?.(this.paused, reason);
|
|
3321
|
+
// The pause rides the snapshot (`timing.isPaused`), so persist it too.
|
|
3322
|
+
this.notifyAutosaveActivity();
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* The template defaults an item's new session starts from (QTI `templateDefault`;
|
|
3326
|
+
* see `templateDefaults.templateDefaultsFor`). The part cache is the player's.
|
|
3327
|
+
*/
|
|
3328
|
+
templateDefaultsFor(q) {
|
|
3329
|
+
return templateDefaultsFor({
|
|
3330
|
+
q,
|
|
3331
|
+
items: this.items,
|
|
3332
|
+
assessment: this.assessment,
|
|
3333
|
+
outcomes: this.testOutcomes,
|
|
3334
|
+
persistedSessions: this.state.itemSessions,
|
|
3335
|
+
byPart: this.templateDefaultsByPart,
|
|
3336
|
+
});
|
|
1100
3337
|
}
|
|
1101
3338
|
isItemLocked(q) {
|
|
1102
|
-
return (this.
|
|
1103
|
-
|
|
1104
|
-
|
|
3339
|
+
return isItemLocked(q, this.scopeLocks, this.assessmentExpired);
|
|
3340
|
+
}
|
|
3341
|
+
/** The expired scope that closes an item (outermost first); the assessment for a whole-test expiry. */
|
|
3342
|
+
lockingScopeOf(q) {
|
|
3343
|
+
return lockingScopeOf(q, this.scopeLocks, this.assessmentExpired);
|
|
3344
|
+
}
|
|
3345
|
+
/**
|
|
3346
|
+
* Nothing open remains (a restore, or a start over, landed on an expired scope with
|
|
3347
|
+
* no open item after it): the candidate must submit now — the same report the live
|
|
3348
|
+
* expiry dead end makes, so the shell offers Submit wherever the candidate is.
|
|
3349
|
+
*/
|
|
3350
|
+
notifyExpiryDeadEnd() {
|
|
3351
|
+
if (this.finalized || this.destroyed)
|
|
3352
|
+
return;
|
|
3353
|
+
const scope = this.lockingScopeOf(this.items[this.currentItemIndex]);
|
|
3354
|
+
this.notifyTimeExpired({ ...scope, autoFinalized: false, submissionRequired: true });
|
|
1105
3355
|
}
|
|
1106
3356
|
nextUnlockedIndex(fromIndex) {
|
|
1107
3357
|
for (let i = fromIndex + 1; i < this.items.length; i++) {
|
|
@@ -1110,31 +3360,191 @@ export class AssessmentPlayer {
|
|
|
1110
3360
|
}
|
|
1111
3361
|
return -1;
|
|
1112
3362
|
}
|
|
3363
|
+
/**
|
|
3364
|
+
* Whether delivery may land on the item after a closure: no expired limit closed it and
|
|
3365
|
+
* the review policy lets the candidate be there (QTI `allowReview` once its attempts are
|
|
3366
|
+
* used up). Later parts are entered fresh, so only the time lock applies to them.
|
|
3367
|
+
*/
|
|
3368
|
+
isOpenTarget(q) {
|
|
3369
|
+
return !this.isItemLocked(q) && this.canReviewItem(q);
|
|
3370
|
+
}
|
|
3371
|
+
/**
|
|
3372
|
+
* Where delivery goes when the item at `fromIndex` closes (a scope expiry, or a restore
|
|
3373
|
+
* that lands on a closed item), looking across the whole reachable delivery rather than
|
|
3374
|
+
* only forward: the next open item of its test part; else — in a nonlinear part — the
|
|
3375
|
+
* nearest open item before it; else the first open item of a later part (parts are
|
|
3376
|
+
* delivered in order, so earlier parts are never re-entered, and a part is left only
|
|
3377
|
+
* when nothing in it is open any more). Forward, only items the delivery rules reach
|
|
3378
|
+
* count: a part (or, in a linear part, a section or item) whose precondition fails is
|
|
3379
|
+
* skipped as on any forward step. -1 when nothing open remains: the expiry dead end,
|
|
3380
|
+
* where the candidate's way out is the submission.
|
|
3381
|
+
*/
|
|
3382
|
+
openItemAfterClosure(fromIndex) {
|
|
3383
|
+
const from = this.items[fromIndex];
|
|
3384
|
+
if (!from)
|
|
3385
|
+
return -1;
|
|
3386
|
+
const decls = this.hasDeliveryRules ? this.navigationDeclarationsFor(from) : undefined;
|
|
3387
|
+
for (const i of this.eligibleIndexesAfter(fromIndex, decls)) {
|
|
3388
|
+
const q = this.items[i];
|
|
3389
|
+
if (q.testPart !== from.testPart)
|
|
3390
|
+
break;
|
|
3391
|
+
if (this.isOpenTarget(q))
|
|
3392
|
+
return i;
|
|
3393
|
+
}
|
|
3394
|
+
const mode = from.testPart.navigationMode;
|
|
3395
|
+
if (mode === 'nonlinear') {
|
|
3396
|
+
for (let i = fromIndex - 1; i >= 0; i--) {
|
|
3397
|
+
const q = this.items[i];
|
|
3398
|
+
if (q.testPart !== from.testPart)
|
|
3399
|
+
break;
|
|
3400
|
+
if (this.isOpenTarget(q))
|
|
3401
|
+
return i;
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
for (const i of this.eligibleIndexesAfter(fromIndex, decls)) {
|
|
3405
|
+
const q = this.items[i];
|
|
3406
|
+
if (q.testPart !== from.testPart && !this.isItemLocked(q))
|
|
3407
|
+
return i;
|
|
3408
|
+
}
|
|
3409
|
+
return -1;
|
|
3410
|
+
}
|
|
1113
3411
|
/**
|
|
1114
3412
|
* A test part, section or item without late submission ran out of time: its items close for the
|
|
1115
|
-
* candidate, and delivery moves to the next item
|
|
3413
|
+
* candidate, and delivery moves to the next open item — forward in the part, else an open
|
|
3414
|
+
* question earlier in a nonlinear part, else the next part. Only when nothing open
|
|
3415
|
+
* remains anywhere reachable is it the expiry dead end.
|
|
3416
|
+
*
|
|
3417
|
+
* The end of the test never navigates: while one runs, the expiry only closes the scope
|
|
3418
|
+
* (the collection takes its items as they stand, `time-expired`). Leaving it — the move
|
|
3419
|
+
* and its report — waits for that end, and is moot once the end finalized.
|
|
1116
3420
|
*/
|
|
1117
3421
|
handleScopeExpired(scope, identifier) {
|
|
1118
|
-
this.
|
|
3422
|
+
this.scopeLocks.lock(scope, identifier);
|
|
3423
|
+
if (this.endReason !== null) {
|
|
3424
|
+
this.expiriesDuringEnd.push({ scope, identifier });
|
|
3425
|
+
return;
|
|
3426
|
+
}
|
|
3427
|
+
this.leaveExpiredScope(scope, identifier);
|
|
3428
|
+
}
|
|
3429
|
+
/**
|
|
3430
|
+
* Close an expired scope for the candidate: move delivery off it, or report the dead
|
|
3431
|
+
* end. Called from the timer's expiry (`handleScopeExpired`), so the hop is a
|
|
3432
|
+
* state-changing transition like any other: it queues behind the navigation or
|
|
3433
|
+
* submission transition in flight and takes the transition lock once that settles,
|
|
3434
|
+
* instead of racing the in-flight backend request.
|
|
3435
|
+
*/
|
|
3436
|
+
leaveExpiredScope(scope, identifier) {
|
|
3437
|
+
this.queuedExpiryHops += 1;
|
|
3438
|
+
this.runWhenIdle(async () => {
|
|
3439
|
+
this.queuedExpiryHops -= 1;
|
|
3440
|
+
// An end of the test finalized while the hop waited: the move is moot.
|
|
3441
|
+
if (this.finalized)
|
|
3442
|
+
return;
|
|
3443
|
+
await this.leaveExpiredScopeLocked(scope, identifier);
|
|
3444
|
+
}).catch((error) => {
|
|
3445
|
+
// Silent only when the player was destroyed while the hop waited behind a
|
|
3446
|
+
// transition: nothing left to close. Any other rejection (a host listener
|
|
3447
|
+
// slipping through, a destroyed-queue cancellation race) is a real expiry
|
|
3448
|
+
// failure — report it like the automatic finalization does, instead of
|
|
3449
|
+
// swallowing it with the scope left locked.
|
|
3450
|
+
if (this.destroyed)
|
|
3451
|
+
return;
|
|
3452
|
+
this.config.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
3453
|
+
});
|
|
3454
|
+
}
|
|
3455
|
+
/** The hop itself, run under the transition lock (or inline while the end holds it). */
|
|
3456
|
+
async leaveExpiredScopeLocked(scope, identifier) {
|
|
1119
3457
|
const current = this.items[this.currentItemIndex];
|
|
1120
|
-
if (!current || !this.isItemLocked(current))
|
|
3458
|
+
if (!current || !this.isItemLocked(current)) {
|
|
3459
|
+
// Delivery is already outside the expired scope; the shell still learns it closed.
|
|
3460
|
+
this.notifyScopeTimeExpired(scope, identifier, true);
|
|
1121
3461
|
return;
|
|
3462
|
+
}
|
|
1122
3463
|
this.saveCurrentItemSession();
|
|
1123
3464
|
this.notifyItemChange();
|
|
1124
|
-
const nextIndex = this.
|
|
3465
|
+
const nextIndex = this.openItemAfterClosure(this.currentItemIndex);
|
|
1125
3466
|
if (nextIndex < 0) {
|
|
1126
|
-
|
|
3467
|
+
// Nothing unlocked remains: the candidate must submit now (a later expiry of
|
|
3468
|
+
// another already-covered scope reports through its own scope event).
|
|
3469
|
+
this.notifyTimeExpired({
|
|
3470
|
+
scope,
|
|
3471
|
+
identifier,
|
|
3472
|
+
autoFinalized: false,
|
|
3473
|
+
submissionRequired: true,
|
|
3474
|
+
});
|
|
3475
|
+
this.notifyScopeTimeExpired(scope, identifier, false);
|
|
3476
|
+
return;
|
|
3477
|
+
}
|
|
3478
|
+
this.notifyScopeTimeExpired(scope, identifier, true, nextIndex);
|
|
3479
|
+
this.pendingEntryIndex = nextIndex;
|
|
3480
|
+
try {
|
|
3481
|
+
await this.performNavigateTo(nextIndex, { restoring: true });
|
|
3482
|
+
}
|
|
3483
|
+
catch (error) {
|
|
3484
|
+
// The expiry's hop failed: the shell's typed failure screen (localized, with
|
|
3485
|
+
// Retry) replaces the "moving on" flow instead of a silently stuck delivery.
|
|
3486
|
+
this.recordEntryFailure(error);
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
/**
|
|
3490
|
+
* The whole-test hard limit expired without late submission (TimeManager calls this
|
|
3491
|
+
* only for that case): finalize like a submit so pending responses are collected and
|
|
3492
|
+
* outcomes computed, then report the expiry. If finalization fails, the session stays
|
|
3493
|
+
* open and the shell offers the Submit action.
|
|
3494
|
+
*/
|
|
3495
|
+
handleAssessmentTimeExpired() {
|
|
3496
|
+
this.assessmentExpired = true;
|
|
3497
|
+
if (this.finalized) {
|
|
3498
|
+
this.notifyTimeExpired({ scope: 'assessment', autoFinalized: false, submissionRequired: false });
|
|
1127
3499
|
return;
|
|
1128
3500
|
}
|
|
1129
|
-
this.
|
|
3501
|
+
void this.autoFinalizeForTimeExpiry();
|
|
3502
|
+
}
|
|
3503
|
+
autoFinalizeForTimeExpiry() {
|
|
3504
|
+
if (this.destroyed || this.finalized)
|
|
3505
|
+
return;
|
|
3506
|
+
// Queued behind a candidate transition in flight, however many administrative
|
|
3507
|
+
// transitions (queued expiry hops, a force submit, a host acting on idle) take the
|
|
3508
|
+
// lock before it: `runWhenIdle` takes the lock the moment it settles, so the end is
|
|
3509
|
+
// never starved and no candidate action slips in first.
|
|
3510
|
+
void this.runWhenIdle(async () => {
|
|
3511
|
+
// The transition in flight ended the test itself: nothing left to finalize, and
|
|
3512
|
+
// (as before) no expiry notice on top of its own ending.
|
|
3513
|
+
if (this.finalized)
|
|
3514
|
+
return false;
|
|
3515
|
+
await this.endTestInternal({ reason: 'expiry' });
|
|
3516
|
+
return true;
|
|
3517
|
+
})
|
|
3518
|
+
.then((ended) => {
|
|
3519
|
+
if (!ended || this.destroyed || !this.finalized)
|
|
3520
|
+
return;
|
|
3521
|
+
this.notifyTimeExpired({ scope: 'assessment', autoFinalized: true, submissionRequired: false });
|
|
3522
|
+
})
|
|
3523
|
+
.catch((error) => {
|
|
3524
|
+
if (this.destroyed)
|
|
3525
|
+
return;
|
|
3526
|
+
// Finalization failed: the shell's expiry notice with a Submit action and the
|
|
3527
|
+
// host's error surface keep the candidate unstuck and the host informed.
|
|
3528
|
+
this.config.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
3529
|
+
this.notifyTimeExpired({ scope: 'assessment', autoFinalized: false, submissionRequired: true });
|
|
3530
|
+
});
|
|
1130
3531
|
}
|
|
1131
|
-
notifyTimeExpired() {
|
|
1132
|
-
|
|
1133
|
-
|
|
3532
|
+
notifyTimeExpired(event) {
|
|
3533
|
+
this.events.emit('timeExpired', event);
|
|
3534
|
+
this.config.onTimeExpired?.(event);
|
|
3535
|
+
}
|
|
3536
|
+
notifyScopeTimeExpired(scope, identifier, deliveryContinues, nextIndex) {
|
|
3537
|
+
const event = {
|
|
3538
|
+
scope,
|
|
3539
|
+
identifier,
|
|
3540
|
+
deliveryContinues,
|
|
3541
|
+
...(nextIndex === undefined ? {} : { nextIndex }),
|
|
3542
|
+
};
|
|
3543
|
+
this.events.emit('scopeTimeExpired', event);
|
|
3544
|
+
this.config.onScopeTimeExpired?.(event);
|
|
1134
3545
|
}
|
|
1135
3546
|
notifyTimeTick(remainingSeconds, elapsedSeconds) {
|
|
1136
|
-
|
|
1137
|
-
l(remainingSeconds, elapsedSeconds);
|
|
3547
|
+
this.events.emit('timeTick', remainingSeconds, elapsedSeconds);
|
|
1138
3548
|
}
|
|
1139
3549
|
/**
|
|
1140
3550
|
* Get the i18n provider instance
|
|
@@ -1151,39 +3561,4 @@ export class AssessmentPlayer {
|
|
|
1151
3561
|
return new DefaultI18nProvider('en-US');
|
|
1152
3562
|
}
|
|
1153
3563
|
}
|
|
1154
|
-
function cloneData(value) {
|
|
1155
|
-
return value === undefined ? undefined : structuredClone(value);
|
|
1156
|
-
}
|
|
1157
|
-
function cloneResponseRecord(responses) {
|
|
1158
|
-
return structuredClone(responses);
|
|
1159
|
-
}
|
|
1160
|
-
function valuesFromItemSession(state) {
|
|
1161
|
-
return Object.fromEntries(Object.entries(state.responseVariables).map(([identifier, variable]) => [
|
|
1162
|
-
identifier,
|
|
1163
|
-
cloneData(variable.value),
|
|
1164
|
-
]));
|
|
1165
|
-
}
|
|
1166
|
-
function responseValuesEqual(left, right) {
|
|
1167
|
-
if (Object.is(left, right))
|
|
1168
|
-
return true;
|
|
1169
|
-
if (Array.isArray(left) || Array.isArray(right)) {
|
|
1170
|
-
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length)
|
|
1171
|
-
return false;
|
|
1172
|
-
return left.every((value, index) => responseValuesEqual(value, right[index]));
|
|
1173
|
-
}
|
|
1174
|
-
if (!isRecord(left) || !isRecord(right))
|
|
1175
|
-
return false;
|
|
1176
|
-
const leftKeys = Object.keys(left);
|
|
1177
|
-
const rightKeys = Object.keys(right);
|
|
1178
|
-
if (leftKeys.length !== rightKeys.length)
|
|
1179
|
-
return false;
|
|
1180
|
-
const rightKeySet = new Set(rightKeys);
|
|
1181
|
-
return leftKeys.every((key) => rightKeySet.has(key) && responseValuesEqual(left[key], right[key]));
|
|
1182
|
-
}
|
|
1183
|
-
function isRecord(value) {
|
|
1184
|
-
return value !== null && typeof value === 'object';
|
|
1185
|
-
}
|
|
1186
|
-
function isWritableItemLifecycle(lifecycleStatus) {
|
|
1187
|
-
return lifecycleStatus === 'initial' || lifecycleStatus === 'interacting';
|
|
1188
|
-
}
|
|
1189
3564
|
//# sourceMappingURL=AssessmentPlayer.js.map
|