@qti-components/delivery 0.1.0-next.11 → 0.1.0-next.13

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/dist/index.d.ts CHANGED
@@ -13,5 +13,6 @@ export * from './state/commands.js';
13
13
  export * from './state/create-delivery-state.js';
14
14
  export * from './state/delivery-state.js';
15
15
  export * from './processing.js';
16
+ export * from './sequencing/sequencing.js';
16
17
  export * from './timing/timing.js';
17
18
  export * from './timing/time-limits.js';
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ export * from './state/commands.js';
12
12
  export * from './state/create-delivery-state.js';
13
13
  export * from './state/delivery-state.js';
14
14
  export * from './processing.js';
15
+ export * from './sequencing/sequencing.js';
15
16
  export * from './timing/timing.js';
16
17
  export * from './timing/time-limits.js';
17
18
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport * from './model/item-facts.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './lifecycle/item-lifecycle.js';\nexport * from './lifecycle/item-rules.js';\nexport * from './lifecycle/item-session.js';\nexport * from './lifecycle/part-submission.js';\nexport * from './random/seeded-random.js';\nexport * from './random/selection.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\nexport * from './timing/timing.js';\nexport * from './timing/time-limits.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport * from './model/item-facts.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './lifecycle/item-lifecycle.js';\nexport * from './lifecycle/item-rules.js';\nexport * from './lifecycle/item-session.js';\nexport * from './lifecycle/part-submission.js';\nexport * from './random/seeded-random.js';\nexport * from './random/selection.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\nexport * from './sequencing/sequencing.js';\nexport * from './timing/timing.js';\nexport * from './timing/time-limits.js';\n"]}
@@ -87,13 +87,14 @@ export interface ItemLifecycleInput {
87
87
  /**
88
88
  * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it
89
89
  * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its
90
- * response processing set `completionStatus` to `completed`.
90
+ * response processing set `completionStatus` to `completed`. In a part with simultaneous submission
91
+ * every item has "one and only one attempt" (§4.1), used when the part is submitted.
91
92
  */
92
- export declare function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus }: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>): boolean;
93
+ export declare function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus, submissionMode }: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> & Partial<Pick<ItemLifecycleInput, 'submissionMode'>>): boolean;
93
94
  /** The guards of one item session, from its session control, its facts, its part and its variables. */
94
95
  export declare function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards;
95
96
  /** What a version 1 state, or a test restored from one, tells about an item session. */
96
- export interface ItemLifecycleSeedInput extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> {
97
+ export interface ItemLifecycleSeedInput extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>, Partial<Pick<ItemLifecycleInput, 'submissionMode'>> {
97
98
  /** The item is on screen: the current item, or one of the section on screen with `navigate="section"`. */
98
99
  presented: boolean;
99
100
  /** The item comes before the current one in a linear part: the candidate has left it for good. */
@@ -102,7 +103,7 @@ export interface ItemLifecycleSeedInput extends Pick<ItemLifecycleInput, 'sessio
102
103
  /**
103
104
  * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored
104
105
  * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part
105
- * has passed it; interacting when it is on screen; initial before its first ended attempt; else
106
- * suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
106
+ * with individual submission has passed it; interacting when it is on screen; initial before its
107
+ * first ended attempt (in a simultaneous part: never opened); else suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
107
108
  */
108
109
  export declare function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState;
@@ -121,9 +121,12 @@ export function transition(state, event, guards) {
121
121
  /**
122
122
  * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it
123
123
  * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its
124
- * response processing set `completionStatus` to `completed`.
124
+ * response processing set `completionStatus` to `completed`. In a part with simultaneous submission
125
+ * every item has "one and only one attempt" (§4.1), used when the part is submitted.
125
126
  */
126
- export function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus }) {
127
+ export function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus, submissionMode }) {
128
+ if (submissionMode === 'simultaneous')
129
+ return numAttempts === 0;
127
130
  if (adaptive)
128
131
  return completionStatus !== 'completed';
129
132
  return maxAttempts === 0 || numAttempts < maxAttempts;
@@ -144,12 +147,17 @@ export function itemLifecycleGuards(input) {
144
147
  /**
145
148
  * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored
146
149
  * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part
147
- * has passed it; interacting when it is on screen; initial before its first ended attempt; else
148
- * suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
150
+ * with individual submission has passed it; interacting when it is on screen; initial before its
151
+ * first ended attempt (in a simultaneous part: never opened); else suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
149
152
  */
150
153
  export function seedItemLifecycle(input) {
151
- if (!hasAttemptsLeft(input) || input.passed)
154
+ // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): passing an
155
+ // item in a linear one does not close it; submitting the part does.
156
+ const closedByPassing = input.passed && input.submissionMode !== 'simultaneous';
157
+ if (!hasAttemptsLeft(input) || closedByPassing)
152
158
  return 'closed';
159
+ if (input.passed)
160
+ return input.completionStatus === 'not_attempted' ? 'initial' : 'suspended';
153
161
  if (input.presented)
154
162
  return 'interacting';
155
163
  return input.numAttempts === 0 ? 'initial' : 'suspended';
@@ -1 +1 @@
1
- {"version":3,"file":"item-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/item-lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,aAAa;IACb,eAAe;IACf,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;CACF,CAAC;AAIX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,YAAY;IACZ,qBAAqB;IACrB,uBAAuB;IACvB,gBAAgB;IAChB,aAAa;IACb,WAAW;IACX,eAAe;IACf,aAAa;CACL,CAAC;AAIX,gGAAgG;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,sBAAsB;IACtB,eAAe;IACf,WAAW;IACX,aAAa;IACb,cAAc;CACN,CAAC;AAgBX,gEAAgE;AAChE,MAAM,CAAC,MAAM,cAAc,GAEvB;IACF,OAAO,EAAE;QACP,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7D,cAAc,EAAE,QAAQ;KACzB;IACD,WAAW,EAAE;QACX,iFAAiF;QACjF,UAAU,EAAE;YACV,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE;YAC1E,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,sBAAsB,EAAE,cAAc,EAAE,eAAe,CAAC,EAAE;YACxF,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,sBAAsB,EAAE,cAAc,CAAC,E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E,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC3G,CAAC;IACF,OAAO,MAAM,EAAE,EAAE,IAAI,IAAI,CAAC;AAC5B,CAAC;AAuBD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,cAAc,EAAE,EAAE,WAAW,EAAE,EAC/B,QAAQ,EACR,WAAW,EACX,gBAAgB,EAC6E;IAC7F,IAAI,QAAQ;QAAE,OAAO,gBAAgB,KAAK,WAAW,CAAC;IACtD,OAAO,WAAW,KAAK,CAAC,IAAI,WAAW,GAAG,WAAW,CAAC;AACxD,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,OAAO;QACL,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC;QACpC,wFAAwF;QACxF,oBAAoB,EAAE,KAAK,CAAC,cAAc,KAAK,YAAY;QAC3D,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,6FAA6F;QAC7F,SAAS,EAAE,KAAK,CAAC,cAAc,KAAK,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI;QAC9D,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW;QAC7C,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY;KAChD,CAAC;AACJ,CAAC;AAWD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,QAAQ,CAAC;IAC7D,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,aAAa,CAAC;IAC1C,OAAO,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3D,CAAC","sourcesContent":["import type { SessionControl, TestPartModel } from '../model/test-model.js';\n\n/**\n * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per\n * item instance: every item session is in exactly one of these states, and only the transitions in\n * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.\n *\n * ```mermaid\n * stateDiagram-v2\n * [*] --> initial\n * initial --> interacting: beginAttempt [attemptsLeft]\n * initial --> closed: endItemSession\n * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]\n * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]\n * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]\n * interacting --> suspended: endCandidateSession\n * interacting --> closed: endItemSession\n * modalFeedback --> interacting: beginAttempt [attemptsLeft]\n * modalFeedback --> suspended: endCandidateSession\n * modalFeedback --> closed: endItemSession\n * suspended --> interacting: beginCandidateSession [mayResume]\n * suspended --> closed: endItemSession\n * closed --> review: beginReview [allowReview]\n * review --> closed: endReview\n * closed --> solution: beginSolution [showSolution]\n * solution --> closed: endSolution\n * ```\n *\n * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and\n * `review` the responses show but are fixed; in `solution` the correct responses show instead. An\n * item that goes from `initial` straight to `closed` keeps NULL responses.\n *\n * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this\n * plan reads it): the item after an attempt whose response processing set modal feedback, with\n * attempts left (\"modal feedback is shown to the candidate directly following response\n * processing\", §2.6). The candidate reads it before trying again.\n *\n * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.\n */\nexport const ITEM_LIFECYCLE_STATES = [\n 'initial',\n 'interacting',\n 'modalFeedback',\n 'suspended',\n 'closed',\n 'review',\n 'solution'\n] as const;\n\nexport type ItemLifecycleState = (typeof ITEM_LIFECYCLE_STATES)[number];\n\n/**\n * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands\n * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.\n */\nexport const ITEM_LIFECYCLE_EVENTS = [\n 'beginAttempt',\n 'endAttempt',\n 'endCandidateSession',\n 'beginCandidateSession',\n 'endItemSession',\n 'beginReview',\n 'endReview',\n 'beginSolution',\n 'endSolution'\n] as const;\n\nexport type ItemLifecycleEvent = (typeof ITEM_LIFECYCLE_EVENTS)[number];\n\n/** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */\nexport const ITEM_LIFECYCLE_GUARDS = [\n 'attemptsLeft',\n 'individualSubmission',\n 'modalFeedback',\n 'mayResume',\n 'allowReview',\n 'showSolution'\n] as const;\n\nexport type ItemLifecycleGuard = (typeof ITEM_LIFECYCLE_GUARDS)[number];\n\nexport type ItemLifecycleGuards = Readonly<Record<ItemLifecycleGuard, boolean>>;\n\n/** One way out of a state: taken when every `when` guard holds and no `unless` guard does. */\nexport interface ItemLifecycleBranch {\n readonly to: ItemLifecycleState;\n readonly when?: readonly ItemLifecycleGuard[];\n readonly unless?: readonly ItemLifecycleGuard[];\n}\n\n/** A state with no guard, or branches tried in order, the first that holds taken. */\nexport type ItemLifecycleTarget = ItemLifecycleState | readonly ItemLifecycleBranch[];\n\n/** The transition table: a pair it does not list is refused. */\nexport const ITEM_LIFECYCLE: Readonly<\n Record<ItemLifecycleState, Readonly<Partial<Record<ItemLifecycleEvent, ItemLifecycleTarget>>>>\n> = {\n initial: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endItemSession: 'closed'\n },\n interacting: {\n // The guards are read after response processing, with the ended attempt counted.\n endAttempt: [\n { to: 'closed', when: ['individualSubmission'], unless: ['attemptsLeft'] },\n { to: 'modalFeedback', when: ['individualSubmission', 'attemptsLeft', 'modalFeedback'] },\n { to: 'interacting', when: ['individualSubmission', 'attemptsLeft'] }\n ],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n modalFeedback: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n suspended: {\n beginCandidateSession: [{ to: 'interacting', when: ['mayResume'] }],\n endItemSession: 'closed'\n },\n closed: {\n beginReview: [{ to: 'review', when: ['allowReview'] }],\n beginSolution: [{ to: 'solution', when: ['showSolution'] }]\n },\n review: {\n endReview: 'closed'\n },\n solution: {\n endSolution: 'closed'\n }\n};\n\n/**\n * The state an item session goes to on `event`, or null when the table refuses it: the pair is not\n * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer\n * on every runtime.\n */\nexport function transition(\n state: ItemLifecycleState,\n event: ItemLifecycleEvent,\n guards: ItemLifecycleGuards\n): ItemLifecycleState | null {\n const target = ITEM_LIFECYCLE[state][event];\n if (target === undefined) return null;\n if (typeof target === 'string') return target;\n const branch = target.find(\n ({ when = [], unless = [] }) => when.every(guard => guards[guard]) && !unless.some(guard => guards[guard])\n );\n return branch?.to ?? null;\n}\n\n/** What the guards of one item session are read from. */\nexport interface ItemLifecycleInput {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: Pick<SessionControl, 'maxAttempts' | 'allowReview' | 'showSolution'>;\n /** From the item's facts (`ItemFacts.adaptive`). */\n adaptive: boolean;\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /**\n * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this\n * delivery counts it when it ends, and T3d keeps that (`plans/delivery-state.md`).\n */\n numAttempts: number;\n /** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */\n completionStatus: string | null;\n /** The candidate has moved on from the item; in a linear part there is no way back. */\n left: boolean;\n /** The last response processing set modal feedback to show. */\n modalFeedback: boolean;\n}\n\n/**\n * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it\n * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its\n * response processing set `completionStatus` to `completed`.\n */\nexport function hasAttemptsLeft({\n sessionControl: { maxAttempts },\n adaptive,\n numAttempts,\n completionStatus\n}: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>): boolean {\n if (adaptive) return completionStatus !== 'completed';\n return maxAttempts === 0 || numAttempts < maxAttempts;\n}\n\n/** The guards of one item session, from its session control, its facts, its part and its variables. */\nexport function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards {\n return {\n attemptsLeft: hasAttemptsLeft(input),\n // In a simultaneous part every response is processed when the part is submitted (§4.1).\n individualSubmission: input.submissionMode === 'individual',\n modalFeedback: input.modalFeedback,\n // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).\n mayResume: input.navigationMode === 'nonlinear' || !input.left,\n allowReview: input.sessionControl.allowReview,\n showSolution: input.sessionControl.showSolution\n };\n}\n\n/** What a version 1 state, or a test restored from one, tells about an item session. */\nexport interface ItemLifecycleSeedInput\n extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> {\n /** The item is on screen: the current item, or one of the section on screen with `navigate=\"section\"`. */\n presented: boolean;\n /** The item comes before the current one in a linear part: the candidate has left it for good. */\n passed: boolean;\n}\n\n/**\n * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored\n * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part\n * has passed it; interacting when it is on screen; initial before its first ended attempt; else\n * suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.\n */\nexport function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState {\n if (!hasAttemptsLeft(input) || input.passed) return 'closed';\n if (input.presented) return 'interacting';\n return input.numAttempts === 0 ? 'initial' : 'suspended';\n}\n"]}
1
+ {"version":3,"file":"item-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/item-lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,aAAa;IACb,eAAe;IACf,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;CACF,CAAC;AAIX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACn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,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,OAAO;QACL,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC;QACpC,wFAAwF;QACxF,oBAAoB,EAAE,KAAK,CAAC,cAAc,KAAK,YAAY;QAC3D,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,6FAA6F;QAC7F,SAAS,EAAE,KAAK,CAAC,cAAc,KAAK,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI;QAC9D,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW;QAC7C,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY;KAChD,CAAC;AACJ,CAAC;AAYD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,mGAAmG;IACnG,oEAAoE;IACpE,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,cAAc,KAAK,cAAc,CAAC;IAChF,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,eAAe;QAAE,OAAO,QAAQ,CAAC;IAChE,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC,gBAAgB,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;IAC9F,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,aAAa,CAAC;IAC1C,OAAO,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3D,CAAC","sourcesContent":["import type { SessionControl, TestPartModel } from '../model/test-model.js';\n\n/**\n * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per\n * item instance: every item session is in exactly one of these states, and only the transitions in\n * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.\n *\n * ```mermaid\n * stateDiagram-v2\n * [*] --> initial\n * initial --> interacting: beginAttempt [attemptsLeft]\n * initial --> closed: endItemSession\n * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]\n * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]\n * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]\n * interacting --> suspended: endCandidateSession\n * interacting --> closed: endItemSession\n * modalFeedback --> interacting: beginAttempt [attemptsLeft]\n * modalFeedback --> suspended: endCandidateSession\n * modalFeedback --> closed: endItemSession\n * suspended --> interacting: beginCandidateSession [mayResume]\n * suspended --> closed: endItemSession\n * closed --> review: beginReview [allowReview]\n * review --> closed: endReview\n * closed --> solution: beginSolution [showSolution]\n * solution --> closed: endSolution\n * ```\n *\n * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and\n * `review` the responses show but are fixed; in `solution` the correct responses show instead. An\n * item that goes from `initial` straight to `closed` keeps NULL responses.\n *\n * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this\n * plan reads it): the item after an attempt whose response processing set modal feedback, with\n * attempts left (\"modal feedback is shown to the candidate directly following response\n * processing\", §2.6). The candidate reads it before trying again.\n *\n * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.\n */\nexport const ITEM_LIFECYCLE_STATES = [\n 'initial',\n 'interacting',\n 'modalFeedback',\n 'suspended',\n 'closed',\n 'review',\n 'solution'\n] as const;\n\nexport type ItemLifecycleState = (typeof ITEM_LIFECYCLE_STATES)[number];\n\n/**\n * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands\n * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.\n */\nexport const ITEM_LIFECYCLE_EVENTS = [\n 'beginAttempt',\n 'endAttempt',\n 'endCandidateSession',\n 'beginCandidateSession',\n 'endItemSession',\n 'beginReview',\n 'endReview',\n 'beginSolution',\n 'endSolution'\n] as const;\n\nexport type ItemLifecycleEvent = (typeof ITEM_LIFECYCLE_EVENTS)[number];\n\n/** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */\nexport const ITEM_LIFECYCLE_GUARDS = [\n 'attemptsLeft',\n 'individualSubmission',\n 'modalFeedback',\n 'mayResume',\n 'allowReview',\n 'showSolution'\n] as const;\n\nexport type ItemLifecycleGuard = (typeof ITEM_LIFECYCLE_GUARDS)[number];\n\nexport type ItemLifecycleGuards = Readonly<Record<ItemLifecycleGuard, boolean>>;\n\n/** One way out of a state: taken when every `when` guard holds and no `unless` guard does. */\nexport interface ItemLifecycleBranch {\n readonly to: ItemLifecycleState;\n readonly when?: readonly ItemLifecycleGuard[];\n readonly unless?: readonly ItemLifecycleGuard[];\n}\n\n/** A state with no guard, or branches tried in order, the first that holds taken. */\nexport type ItemLifecycleTarget = ItemLifecycleState | readonly ItemLifecycleBranch[];\n\n/** The transition table: a pair it does not list is refused. */\nexport const ITEM_LIFECYCLE: Readonly<\n Record<ItemLifecycleState, Readonly<Partial<Record<ItemLifecycleEvent, ItemLifecycleTarget>>>>\n> = {\n initial: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endItemSession: 'closed'\n },\n interacting: {\n // The guards are read after response processing, with the ended attempt counted.\n endAttempt: [\n { to: 'closed', when: ['individualSubmission'], unless: ['attemptsLeft'] },\n { to: 'modalFeedback', when: ['individualSubmission', 'attemptsLeft', 'modalFeedback'] },\n { to: 'interacting', when: ['individualSubmission', 'attemptsLeft'] }\n ],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n modalFeedback: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n suspended: {\n beginCandidateSession: [{ to: 'interacting', when: ['mayResume'] }],\n endItemSession: 'closed'\n },\n closed: {\n beginReview: [{ to: 'review', when: ['allowReview'] }],\n beginSolution: [{ to: 'solution', when: ['showSolution'] }]\n },\n review: {\n endReview: 'closed'\n },\n solution: {\n endSolution: 'closed'\n }\n};\n\n/**\n * The state an item session goes to on `event`, or null when the table refuses it: the pair is not\n * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer\n * on every runtime.\n */\nexport function transition(\n state: ItemLifecycleState,\n event: ItemLifecycleEvent,\n guards: ItemLifecycleGuards\n): ItemLifecycleState | null {\n const target = ITEM_LIFECYCLE[state][event];\n if (target === undefined) return null;\n if (typeof target === 'string') return target;\n const branch = target.find(\n ({ when = [], unless = [] }) => when.every(guard => guards[guard]) && !unless.some(guard => guards[guard])\n );\n return branch?.to ?? null;\n}\n\n/** What the guards of one item session are read from. */\nexport interface ItemLifecycleInput {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: Pick<SessionControl, 'maxAttempts' | 'allowReview' | 'showSolution'>;\n /** From the item's facts (`ItemFacts.adaptive`). */\n adaptive: boolean;\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /**\n * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this\n * delivery counts it when it ends, and T3d keeps that (`plans/delivery-state.md`).\n */\n numAttempts: number;\n /** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */\n completionStatus: string | null;\n /** The candidate has moved on from the item; in a linear part there is no way back. */\n left: boolean;\n /** The last response processing set modal feedback to show. */\n modalFeedback: boolean;\n}\n\n/**\n * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it\n * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its\n * response processing set `completionStatus` to `completed`. In a part with simultaneous submission\n * every item has \"one and only one attempt\" (§4.1), used when the part is submitted.\n */\nexport function hasAttemptsLeft({\n sessionControl: { maxAttempts },\n adaptive,\n numAttempts,\n completionStatus,\n submissionMode\n}: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> &\n Partial<Pick<ItemLifecycleInput, 'submissionMode'>>): boolean {\n if (submissionMode === 'simultaneous') return numAttempts === 0;\n if (adaptive) return completionStatus !== 'completed';\n return maxAttempts === 0 || numAttempts < maxAttempts;\n}\n\n/** The guards of one item session, from its session control, its facts, its part and its variables. */\nexport function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards {\n return {\n attemptsLeft: hasAttemptsLeft(input),\n // In a simultaneous part every response is processed when the part is submitted (§4.1).\n individualSubmission: input.submissionMode === 'individual',\n modalFeedback: input.modalFeedback,\n // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).\n mayResume: input.navigationMode === 'nonlinear' || !input.left,\n allowReview: input.sessionControl.allowReview,\n showSolution: input.sessionControl.showSolution\n };\n}\n\n/** What a version 1 state, or a test restored from one, tells about an item session. */\nexport interface ItemLifecycleSeedInput\n extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>,\n Partial<Pick<ItemLifecycleInput, 'submissionMode'>> {\n /** The item is on screen: the current item, or one of the section on screen with `navigate=\"section\"`. */\n presented: boolean;\n /** The item comes before the current one in a linear part: the candidate has left it for good. */\n passed: boolean;\n}\n\n/**\n * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored\n * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part\n * with individual submission has passed it; interacting when it is on screen; initial before its\n * first ended attempt (in a simultaneous part: never opened); else suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.\n */\nexport function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState {\n // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): passing an\n // item in a linear one does not close it; submitting the part does.\n const closedByPassing = input.passed && input.submissionMode !== 'simultaneous';\n if (!hasAttemptsLeft(input) || closedByPassing) return 'closed';\n if (input.passed) return input.completionStatus === 'not_attempted' ? 'initial' : 'suspended';\n if (input.presented) return 'interacting';\n return input.numAttempts === 0 ? 'initial' : 'suspended';\n}\n"]}
@@ -39,7 +39,8 @@ export interface ItemRules {
39
39
  /**
40
40
  * Feedback, modal and integrated, may show: always while attempts are left, after the last
41
41
  * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its
42
- * feedback whatever `show-feedback` says (§7.19, `allow-review`).
42
+ * feedback whatever `show-feedback` says (§7.19, `allow-review`). In a part with simultaneous
43
+ * submission none shows during the test (§4.1); once the part is submitted, `show-feedback` decides.
43
44
  */
44
45
  readonly mayShowFeedback: boolean;
45
46
  /**
@@ -6,16 +6,19 @@ export function itemRules(input) {
6
6
  const individual = guards.individualSubmission;
7
7
  const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;
8
8
  const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);
9
+ const done = state === 'closed' || state === 'review' || state === 'solution';
9
10
  return {
10
11
  attemptsLeft: guards.attemptsLeft,
11
12
  attemptsUsed: !guards.attemptsLeft,
12
13
  interactive: state === 'interacting',
13
- done: state === 'closed' || state === 'review' || state === 'solution',
14
+ done,
14
15
  mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,
15
16
  maySubmit,
16
17
  maySkip,
17
- mayShowFeedback: guards.attemptsLeft ||
18
- sessionControl.showFeedback ||
18
+ // In a simultaneous part "feedback cannot be seen during the test" (§4.1): nothing until the
19
+ // part is submitted, then what `show-feedback` allows.
20
+ mayShowFeedback: (individual && guards.attemptsLeft) ||
21
+ (sessionControl.showFeedback && (individual || done)) ||
19
22
  (state === 'review' && adaptive && sessionControl.allowReview),
20
23
  mayBeginReview: transition(state, 'beginReview', guards) !== null,
21
24
  mayBeginSolution: transition(state, 'beginSolution', guards) !== null,
@@ -1 +1 @@
1
- {"version":3,"file":"item-rules.js","sourceRoot":"","sources":["../../src/lifecycle/item-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA+EtE,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,mBAAmB,C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AAc,KAAK,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC;IAC1G,OAAO;QACL,SAAS,EAAE,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC;QAC7E,aAAa,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,IAAI,cAAc,KAAK,WAAW;KACrE,CAAC;AACJ,CAAC","sourcesContent":["import { itemLifecycleGuards, transition } from './item-lifecycle.js';\n\nimport type { SessionControl, TestPartModel } from '../model/test-model.js';\nimport type { ItemLifecycleInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/**\n * What one item session may do now, answered from its lifecycle state, its session control and its\n * responses. Every reader of attempts, skipping, feedback, review or the solution asks here instead\n * of working the rule out itself (roadmap 1, T3b).\n *\n * The answers follow QTI 3 (`qti-item-session-control`, info model §7.19; implementation guide\n * §4.1 and §4.4.2) and nothing else: whether the last attempt was optimal decides none of them\n * (decided 2026-11-27, `plans/host-api.md`).\n *\n * Experimental (0.x).\n */\nexport interface ItemRules {\n /**\n * Another attempt is allowed: `max-attempts` not reached (0 is unlimited), or, for an adaptive\n * item, which ignores `max-attempts`, `completionStatus` not `completed`.\n */\n readonly attemptsLeft: boolean;\n /** No further attempt is allowed: the negation of `attemptsLeft`. */\n readonly attemptsUsed: boolean;\n /** The responses can change: only while `interacting`. In every other state they are fixed or not shown. */\n readonly interactive: boolean;\n /** The item session is over: `closed`, or in `review` or `solution`, which come back to `closed`. */\n readonly done: boolean;\n /**\n * The candidate may end the attempt now: the item is `interacting` in a part with individual\n * submission, and `maySubmit` holds.\n */\n readonly mayEndAttempt: boolean;\n /**\n * The responses may be submitted as they are: `allow-skipping=\"false\"` refuses an item with no\n * response, `validate-responses` an invalid one. Two separate rules, both for individual\n * submission only (§7.19).\n */\n readonly maySubmit: boolean;\n /** Submitting no response is allowed: `allow-skipping`, or a response given, or simultaneous submission. */\n readonly maySkip: boolean;\n /**\n * Feedback, modal and integrated, may show: always while attempts are left, after the last\n * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its\n * feedback whatever `show-feedback` says (§7.19, `allow-review`).\n */\n readonly mayShowFeedback: boolean;\n /**\n * The item session may enter `review` now: it is `closed`, with `allow-review`. False in `review`\n * itself; whether review shows is the state.\n */\n readonly mayBeginReview: boolean;\n /**\n * The item session may enter `solution`, which shows the correct responses: it is `closed`, with\n * `show-solution`. False in `solution` itself; whether the solution shows is the state.\n */\n readonly mayBeginSolution: boolean;\n /**\n * The candidate may set a comment on the item now: `allow-comment`, while `interacting`. The\n * comment is not assessed; QTI leaves capturing it to the delivery (§7.19, `allow-comment`).\n */\n readonly mayComment: boolean;\n}\n\n/** What the rules of one item session are read from: its lifecycle input, its state and its responses. */\nexport interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: SessionControl;\n /** The item session's lifecycle state. */\n state: ItemLifecycleState;\n /**\n * The candidate gave no response: every response variable holds its default or NULL. False for an\n * item with no response variables, which \"by definition cannot be skipped\" (§7.19).\n */\n skipped: boolean;\n /** Every interaction's response satisfies its constraints (the item's `valid`). */\n valid: boolean;\n}\n\n/** The rules of one item session. Pure: the same input gives the same answers on every runtime. */\nexport function itemRules(input: ItemRulesInput): ItemRules {\n const { state, sessionControl, adaptive } = input;\n const guards = itemLifecycleGuards(input);\n const individual = guards.individualSubmission;\n const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;\n const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);\n return {\n attemptsLeft: guards.attemptsLeft,\n attemptsUsed: !guards.attemptsLeft,\n interactive: state === 'interacting',\n done: state === 'closed' || state === 'review' || state === 'solution',\n mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,\n maySubmit,\n maySkip,\n mayShowFeedback:\n guards.attemptsLeft ||\n sessionControl.showFeedback ||\n (state === 'review' && adaptive && sessionControl.allowReview),\n mayBeginReview: transition(state, 'beginReview', guards) !== null,\n mayBeginSolution: transition(state, 'beginSolution', guards) !== null,\n mayComment: sessionControl.allowComment && state === 'interacting'\n };\n}\n\n/** Where the candidate is in a part, for its navigation answers. */\nexport interface NavigationRulesInput {\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /** The current item's position among the part's items in order, from 0; -1 when none is current. */\n index: number;\n /** The number of items in the part. */\n count: number;\n /** The rules of the current item. */\n current: Pick<ItemRules, 'maySubmit' | 'interactive'>;\n}\n\n/** Whether the candidate may move to the next or the previous item of a part. */\nexport interface NavigationRules {\n /**\n * There is a next item and, in a linear part with individual submission, the current item may be\n * left: Next ends an attempt that was not ended and closes the item (decided 2026-11-27), so its\n * responses must be ones the candidate may submit.\n */\n readonly mayGoNext: boolean;\n /** There is a previous item, in a nonlinear part: a linear part never goes back (§4.1). */\n readonly mayGoPrevious: boolean;\n}\n\n/** The navigation answers of a part. Pure. */\nexport function navigationRules({\n navigationMode,\n submissionMode,\n index,\n count,\n current\n}: NavigationRulesInput): NavigationRules {\n const onItem = index >= 0 && index < count;\n const endsAttempt = navigationMode === 'linear' && submissionMode === 'individual' && current.interactive;\n return {\n mayGoNext: onItem && index < count - 1 && (!endsAttempt || current.maySubmit),\n mayGoPrevious: onItem && index > 0 && navigationMode === 'nonlinear'\n };\n}\n"]}
1
+ {"version":3,"file":"item-rules.js","sourceRoot":"","sources":["../../src/lifecycle/item-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAgFtE,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,oBAAoB,CAAC;IAC/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C,MAAM,WAAW,GAAG,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC;IAC1G,OAAO;QACL,SAAS,EAAE,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC;QAC7E,aAAa,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,IAAI,cAAc,KAAK,WAAW;KACrE,CAAC;AACJ,CAAC","sourcesContent":["import { itemLifecycleGuards, transition } from './item-lifecycle.js';\n\nimport type { SessionControl, TestPartModel } from '../model/test-model.js';\nimport type { ItemLifecycleInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/**\n * What one item session may do now, answered from its lifecycle state, its session control and its\n * responses. Every reader of attempts, skipping, feedback, review or the solution asks here instead\n * of working the rule out itself (roadmap 1, T3b).\n *\n * The answers follow QTI 3 (`qti-item-session-control`, info model §7.19; implementation guide\n * §4.1 and §4.4.2) and nothing else: whether the last attempt was optimal decides none of them\n * (decided 2026-11-27, `plans/host-api.md`).\n *\n * Experimental (0.x).\n */\nexport interface ItemRules {\n /**\n * Another attempt is allowed: `max-attempts` not reached (0 is unlimited), or, for an adaptive\n * item, which ignores `max-attempts`, `completionStatus` not `completed`.\n */\n readonly attemptsLeft: boolean;\n /** No further attempt is allowed: the negation of `attemptsLeft`. */\n readonly attemptsUsed: boolean;\n /** The responses can change: only while `interacting`. In every other state they are fixed or not shown. */\n readonly interactive: boolean;\n /** The item session is over: `closed`, or in `review` or `solution`, which come back to `closed`. */\n readonly done: boolean;\n /**\n * The candidate may end the attempt now: the item is `interacting` in a part with individual\n * submission, and `maySubmit` holds.\n */\n readonly mayEndAttempt: boolean;\n /**\n * The responses may be submitted as they are: `allow-skipping=\"false\"` refuses an item with no\n * response, `validate-responses` an invalid one. Two separate rules, both for individual\n * submission only (§7.19).\n */\n readonly maySubmit: boolean;\n /** Submitting no response is allowed: `allow-skipping`, or a response given, or simultaneous submission. */\n readonly maySkip: boolean;\n /**\n * Feedback, modal and integrated, may show: always while attempts are left, after the last\n * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its\n * feedback whatever `show-feedback` says (§7.19, `allow-review`). In a part with simultaneous\n * submission none shows during the test (§4.1); once the part is submitted, `show-feedback` decides.\n */\n readonly mayShowFeedback: boolean;\n /**\n * The item session may enter `review` now: it is `closed`, with `allow-review`. False in `review`\n * itself; whether review shows is the state.\n */\n readonly mayBeginReview: boolean;\n /**\n * The item session may enter `solution`, which shows the correct responses: it is `closed`, with\n * `show-solution`. False in `solution` itself; whether the solution shows is the state.\n */\n readonly mayBeginSolution: boolean;\n /**\n * The candidate may set a comment on the item now: `allow-comment`, while `interacting`. The\n * comment is not assessed; QTI leaves capturing it to the delivery (§7.19, `allow-comment`).\n */\n readonly mayComment: boolean;\n}\n\n/** What the rules of one item session are read from: its lifecycle input, its state and its responses. */\nexport interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: SessionControl;\n /** The item session's lifecycle state. */\n state: ItemLifecycleState;\n /**\n * The candidate gave no response: every response variable holds its default or NULL. False for an\n * item with no response variables, which \"by definition cannot be skipped\" (§7.19).\n */\n skipped: boolean;\n /** Every interaction's response satisfies its constraints (the item's `valid`). */\n valid: boolean;\n}\n\n/** The rules of one item session. Pure: the same input gives the same answers on every runtime. */\nexport function itemRules(input: ItemRulesInput): ItemRules {\n const { state, sessionControl, adaptive } = input;\n const guards = itemLifecycleGuards(input);\n const individual = guards.individualSubmission;\n const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;\n const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);\n const done = state === 'closed' || state === 'review' || state === 'solution';\n return {\n attemptsLeft: guards.attemptsLeft,\n attemptsUsed: !guards.attemptsLeft,\n interactive: state === 'interacting',\n done,\n mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,\n maySubmit,\n maySkip,\n // In a simultaneous part \"feedback cannot be seen during the test\" (§4.1): nothing until the\n // part is submitted, then what `show-feedback` allows.\n mayShowFeedback:\n (individual && guards.attemptsLeft) ||\n (sessionControl.showFeedback && (individual || done)) ||\n (state === 'review' && adaptive && sessionControl.allowReview),\n mayBeginReview: transition(state, 'beginReview', guards) !== null,\n mayBeginSolution: transition(state, 'beginSolution', guards) !== null,\n mayComment: sessionControl.allowComment && state === 'interacting'\n };\n}\n\n/** Where the candidate is in a part, for its navigation answers. */\nexport interface NavigationRulesInput {\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /** The current item's position among the part's items in order, from 0; -1 when none is current. */\n index: number;\n /** The number of items in the part. */\n count: number;\n /** The rules of the current item. */\n current: Pick<ItemRules, 'maySubmit' | 'interactive'>;\n}\n\n/** Whether the candidate may move to the next or the previous item of a part. */\nexport interface NavigationRules {\n /**\n * There is a next item and, in a linear part with individual submission, the current item may be\n * left: Next ends an attempt that was not ended and closes the item (decided 2026-11-27), so its\n * responses must be ones the candidate may submit.\n */\n readonly mayGoNext: boolean;\n /** There is a previous item, in a nonlinear part: a linear part never goes back (§4.1). */\n readonly mayGoPrevious: boolean;\n}\n\n/** The navigation answers of a part. Pure. */\nexport function navigationRules({\n navigationMode,\n submissionMode,\n index,\n count,\n current\n}: NavigationRulesInput): NavigationRules {\n const onItem = index >= 0 && index < count;\n const endsAttempt = navigationMode === 'linear' && submissionMode === 'individual' && current.interactive;\n return {\n mayGoNext: onItem && index < count - 1 && (!endsAttempt || current.maySubmit),\n mayGoPrevious: onItem && index > 0 && navigationMode === 'nonlinear'\n };\n}\n"]}
@@ -10,11 +10,12 @@ export interface ItemSession {
10
10
  /** What a delivery knows about an item session at an update. */
11
11
  export interface ItemSessionFacts extends ItemLifecycleSeedInput, Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {
12
12
  sessionControl: ItemLifecycleInput['sessionControl'];
13
+ submissionMode: ItemLifecycleInput['submissionMode'];
13
14
  }
14
15
  /**
15
16
  * The session after the candidate moved (or a state was restored), through the lifecycle table: an
16
17
  * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a
17
- * linear part has passed is closed. A session not seen before, or whose attempts changed outside
18
+ * linear part with individual submission has passed is closed. A session not seen before, or whose attempts changed outside
18
19
  * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came
19
20
  * later), is seeded again with `seedItemLifecycle`.
20
21
  */
@@ -6,7 +6,7 @@ const OVER = ['closed', 'review', 'solution'];
6
6
  /**
7
7
  * The session after the candidate moved (or a state was restored), through the lifecycle table: an
8
8
  * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a
9
- * linear part has passed is closed. A session not seen before, or whose attempts changed outside
9
+ * linear part with individual submission has passed is closed. A session not seen before, or whose attempts changed outside
10
10
  * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came
11
11
  * later), is seeded again with `seedItemLifecycle`.
12
12
  */
@@ -17,11 +17,14 @@ export function followItemSession(previous, facts) {
17
17
  }
18
18
  const guards = guardsFor(facts);
19
19
  let state = previous.state;
20
- if (facts.passed) {
20
+ // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): a passed
21
+ // item is suspended like any item off screen, and closes when the part is submitted.
22
+ const closes = facts.passed && facts.submissionMode !== 'simultaneous';
23
+ if (closes) {
21
24
  if (!OVER.includes(state))
22
25
  state = transition(state, 'endItemSession', guards) ?? state;
23
26
  }
24
- else if (facts.presented) {
27
+ else if (facts.presented && !facts.passed) {
25
28
  if (state === 'initial')
26
29
  state = transition(state, 'beginAttempt', guards) ?? state;
27
30
  else if (state === 'suspended')
@@ -1 +1 @@
1
- {"version":3,"file":"item-session.js","sourceRoot":"","sources":["../../src/lifecycle/item-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAoBzF,MAAM,SAAS,GAAG,C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AE,CAAC;QAChE,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,qBAAqB,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAiC,EAAE,KAAuB;IACvF,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,QAAQ,EAAE,KAAK,KAAK,aAAa,EAAE,CAAC;QACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IAC5F,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACtH,CAAC","sourcesContent":["import { itemLifecycleGuards, seedItemLifecycle, transition } from './item-lifecycle.js';\n\nimport type { ItemLifecycleInput, ItemLifecycleSeedInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/** One item session as a delivery keeps it between updates: its state, and the attempts it was last seen with. */\nexport interface ItemSession {\n readonly state: ItemLifecycleState;\n /** The ended attempts when `state` was last set; a different count means the state came from elsewhere. */\n readonly numAttempts: number;\n /** Whether the item was adaptive when `state` was last set; its facts may arrive after the first update. */\n readonly adaptive: boolean;\n}\n\n/** What a delivery knows about an item session at an update. */\nexport interface ItemSessionFacts\n extends ItemLifecycleSeedInput,\n Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {\n sessionControl: ItemLifecycleInput['sessionControl'];\n}\n\nconst guardsFor = (facts: ItemSessionFacts) =>\n // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.\n itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n\nconst OVER: readonly ItemLifecycleState[] = ['closed', 'review', 'solution'];\n\n/**\n * The session after the candidate moved (or a state was restored), through the lifecycle table: an\n * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a\n * linear part has passed is closed. A session not seen before, or whose attempts changed outside\n * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came\n * later), is seeded again with `seedItemLifecycle`.\n */\nexport function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (!previous || previous.numAttempts !== numAttempts || previous.adaptive !== adaptive) {\n return { state: seedItemLifecycle(facts), numAttempts, adaptive };\n }\n const guards = guardsFor(facts);\n let state = previous.state;\n if (facts.passed) {\n if (!OVER.includes(state)) state = transition(state, 'endItemSession', guards) ?? state;\n } else if (facts.presented) {\n if (state === 'initial') state = transition(state, 'beginAttempt', guards) ?? state;\n else if (state === 'suspended') state = transition(state, 'beginCandidateSession', guards) ?? state;\n } else if (state === 'interacting' || state === 'modalFeedback') {\n state = transition(state, 'endCandidateSession', guards) ?? state;\n }\n return { state, numAttempts, adaptive };\n}\n\n/**\n * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes\n * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery\n * saw it begin, so it is seeded as an item on screen.\n */\nexport function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (previous?.state !== 'interacting') {\n return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };\n }\n return { state: transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting', numAttempts, adaptive };\n}\n"]}
1
+ {"version":3,"file":"item-session.js","sourceRoot":"","sources":["../../src/lifecycle/item-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAqBzF,MAAM,SAAS,GAA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U,CAAC,KAAK,EAAE,uBAAuB,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC;IACtG,CAAC;SAAM,IAAI,KAAK,KAAK,aAAa,IAAI,KAAK,KAAK,eAAe,EAAE,CAAC;QAChE,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,qBAAqB,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC;IACpE,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAiC,EAAE,KAAuB;IACvF,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,QAAQ,EAAE,KAAK,KAAK,aAAa,EAAE,CAAC;QACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;IAC5F,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACtH,CAAC","sourcesContent":["import { itemLifecycleGuards, seedItemLifecycle, transition } from './item-lifecycle.js';\n\nimport type { ItemLifecycleInput, ItemLifecycleSeedInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/** One item session as a delivery keeps it between updates: its state, and the attempts it was last seen with. */\nexport interface ItemSession {\n readonly state: ItemLifecycleState;\n /** The ended attempts when `state` was last set; a different count means the state came from elsewhere. */\n readonly numAttempts: number;\n /** Whether the item was adaptive when `state` was last set; its facts may arrive after the first update. */\n readonly adaptive: boolean;\n}\n\n/** What a delivery knows about an item session at an update. */\nexport interface ItemSessionFacts\n extends ItemLifecycleSeedInput,\n Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {\n sessionControl: ItemLifecycleInput['sessionControl'];\n submissionMode: ItemLifecycleInput['submissionMode'];\n}\n\nconst guardsFor = (facts: ItemSessionFacts) =>\n // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.\n itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n\nconst OVER: readonly ItemLifecycleState[] = ['closed', 'review', 'solution'];\n\n/**\n * The session after the candidate moved (or a state was restored), through the lifecycle table: an\n * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a\n * linear part with individual submission has passed is closed. A session not seen before, or whose attempts changed outside\n * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came\n * later), is seeded again with `seedItemLifecycle`.\n */\nexport function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (!previous || previous.numAttempts !== numAttempts || previous.adaptive !== adaptive) {\n return { state: seedItemLifecycle(facts), numAttempts, adaptive };\n }\n const guards = guardsFor(facts);\n let state = previous.state;\n // In a simultaneous part sessions pass between interacting and suspended only (§2.8.2): a passed\n // item is suspended like any item off screen, and closes when the part is submitted.\n const closes = facts.passed && facts.submissionMode !== 'simultaneous';\n if (closes) {\n if (!OVER.includes(state)) state = transition(state, 'endItemSession', guards) ?? state;\n } else if (facts.presented && !facts.passed) {\n if (state === 'initial') state = transition(state, 'beginAttempt', guards) ?? state;\n else if (state === 'suspended') state = transition(state, 'beginCandidateSession', guards) ?? state;\n } else if (state === 'interacting' || state === 'modalFeedback') {\n state = transition(state, 'endCandidateSession', guards) ?? state;\n }\n return { state, numAttempts, adaptive };\n}\n\n/**\n * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes\n * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery\n * saw it begin, so it is seeded as an item on screen.\n */\nexport function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (previous?.state !== 'interacting') {\n return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };\n }\n return { state: transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting', numAttempts, adaptive };\n}\n"]}
@@ -29,6 +29,6 @@ export interface PartSubmission {
29
29
  *
30
30
  * Returns null for a part with individual submission: its items are submitted one by one.
31
31
  *
32
- * Experimental (0.x): roadmap 1 phase T6; see `plans/submission-mode-scoring.md`.
32
+ * Experimental (0.x): roadmap 1 phase T6; see `plans/host-api.md` → "A simultaneous part is a paper exam".
33
33
  */
34
34
  export declare function submitTestPart(items: readonly PartSubmissionItem[]): PartSubmission | null;
@@ -12,7 +12,7 @@ const OVER = new Set(['closed', 'review', 'solution']);
12
12
  *
13
13
  * Returns null for a part with individual submission: its items are submitted one by one.
14
14
  *
15
- * Experimental (0.x): roadmap 1 phase T6; see `plans/submission-mode-scoring.md`.
15
+ * Experimental (0.x): roadmap 1 phase T6; see `plans/host-api.md` → "A simultaneous part is a paper exam".
16
16
  */
17
17
  export function submitTestPart(items) {
18
18
  if (items.some(({ facts }) => facts.submissionMode !== 'simultaneous'))
@@ -1 +1 @@
1
- {"version":3,"file":"part-submission.js","sourceRoot":"","sources":["../../src/lifecycle/part-submission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAqBzF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,KAAoC;IACjE,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,KAAK,cAAc,CAAC;QAAE,OAAO,IAAI,CAAC;IACpF,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAChD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;QAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAC3B,MAAM,KAAK,GAAG,QAAQ,EAAE,KAAK,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtF,SAAS;QACX,CAAC;QACD,oGAAoG;QACpG,MAAM,MAAM,GAAG,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,gBAAgB,KAAK,eAAe,CAAC;QACjF,MAAM,MAAM,GAAG,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI;YACJ,OAAO,EAAE;gBACP,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,MAAM,CAAC,IAAI,QAAQ;gBAC9D,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjD,QAAQ;aACT;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["import { seedItemLifecycle, transition, itemLifecycleGuards } from './item-lifecycle.js';\n\nimport type { Effect } from '../state/commands.js';\nimport type { ItemInstanceId } from '../state/delivery-state.js';\nimport type { ItemSession, ItemSessionFacts } from './item-session.js';\n\n/** One item session of the part being submitted: its instance, its session so far, and its facts now. */\nexport interface PartSubmissionItem {\n readonly item: ItemInstanceId;\n /** The session as the delivery kept it; null when it has none yet (a restored state). */\n readonly previous: ItemSession | null;\n readonly facts: ItemSessionFacts;\n}\n\n/** The part's item sessions after the submission, in the order given, and what the runtime has to run. */\nexport interface PartSubmission {\n readonly sessions: { readonly item: ItemInstanceId; readonly session: ItemSession }[];\n /** `runOutcomeProcessing` once, after the items. */\n readonly effects: Effect[];\n}\n\nconst OVER = new Set(['closed', 'review', 'solution']);\n\n/**\n * Submits a part with simultaneous submission as a whole (QTI 3 info model §2.8.2, implementation\n * guide §4.1): \"response processing cannot take place until the test part is complete\", and then\n * the candidate's responses \"are all submitted together\". Each item the candidate opened has its one\n * and only attempt counted and its session closes. Its responses were already processed in the\n * background while the part ran, without ending the attempt (the paper-exam model, decided\n * 2026-12-01), so nothing is processed again here. An item never opened (`completionStatus`\n * `not_attempted`) is closed with its NULL responses and counts no attempt, as a skipped item is. A\n * session already over is left as it is. Outcome processing runs once, after the items (§2.9).\n *\n * Returns null for a part with individual submission: its items are submitted one by one.\n *\n * Experimental (0.x): roadmap 1 phase T6; see `plans/submission-mode-scoring.md`.\n */\nexport function submitTestPart(items: readonly PartSubmissionItem[]): PartSubmission | null {\n if (items.some(({ facts }) => facts.submissionMode !== 'simultaneous')) return null;\n const sessions: PartSubmission['sessions'] = [];\n const effects: Effect[] = [];\n for (const { item, previous, facts } of items) {\n const { adaptive } = facts;\n const state = previous?.state ?? seedItemLifecycle(facts);\n if (OVER.has(state)) {\n sessions.push({ item, session: { state, numAttempts: facts.numAttempts, adaptive } });\n continue;\n }\n // A restored session not on screen seeds as `initial`; `completionStatus` still says it was opened.\n const opened = state !== 'initial' || facts.completionStatus !== 'not_attempted';\n const guards = itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n sessions.push({\n item,\n session: {\n state: transition(state, 'endItemSession', guards) ?? 'closed',\n numAttempts: facts.numAttempts + (opened ? 1 : 0),\n adaptive\n }\n });\n }\n effects.push({ type: 'runOutcomeProcessing' });\n return { sessions, effects };\n}\n"]}
1
+ {"version":3,"file":"part-submission.js","sourceRoot":"","sources":["../../src/lifecycle/part-submission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAqBzF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,KAAoC;IACjE,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,KAAK,cAAc,CAAC;QAAE,OAAO,IAAI,CAAC;IACpF,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAChD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,KAAK,EAAE,CAAC;QAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;QAC3B,MAAM,KAAK,GAAG,QAAQ,EAAE,KAAK,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;YACtF,SAAS;QACX,CAAC;QACD,oGAAoG;QACpG,MAAM,MAAM,GAAG,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,gBAAgB,KAAK,eAAe,CAAC;QACjF,MAAM,MAAM,GAAG,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI;YACJ,OAAO,EAAE;gBACP,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,gBAAgB,EAAE,MAAM,CAAC,IAAI,QAAQ;gBAC9D,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjD,QAAQ;aACT;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["import { seedItemLifecycle, transition, itemLifecycleGuards } from './item-lifecycle.js';\n\nimport type { Effect } from '../state/commands.js';\nimport type { ItemInstanceId } from '../state/delivery-state.js';\nimport type { ItemSession, ItemSessionFacts } from './item-session.js';\n\n/** One item session of the part being submitted: its instance, its session so far, and its facts now. */\nexport interface PartSubmissionItem {\n readonly item: ItemInstanceId;\n /** The session as the delivery kept it; null when it has none yet (a restored state). */\n readonly previous: ItemSession | null;\n readonly facts: ItemSessionFacts;\n}\n\n/** The part's item sessions after the submission, in the order given, and what the runtime has to run. */\nexport interface PartSubmission {\n readonly sessions: { readonly item: ItemInstanceId; readonly session: ItemSession }[];\n /** `runOutcomeProcessing` once, after the items. */\n readonly effects: Effect[];\n}\n\nconst OVER = new Set(['closed', 'review', 'solution']);\n\n/**\n * Submits a part with simultaneous submission as a whole (QTI 3 info model §2.8.2, implementation\n * guide §4.1): \"response processing cannot take place until the test part is complete\", and then\n * the candidate's responses \"are all submitted together\". Each item the candidate opened has its one\n * and only attempt counted and its session closes. Its responses were already processed in the\n * background while the part ran, without ending the attempt (the paper-exam model, decided\n * 2026-12-01), so nothing is processed again here. An item never opened (`completionStatus`\n * `not_attempted`) is closed with its NULL responses and counts no attempt, as a skipped item is. A\n * session already over is left as it is. Outcome processing runs once, after the items (§2.9).\n *\n * Returns null for a part with individual submission: its items are submitted one by one.\n *\n * Experimental (0.x): roadmap 1 phase T6; see `plans/host-api.md` → \"A simultaneous part is a paper exam\".\n */\nexport function submitTestPart(items: readonly PartSubmissionItem[]): PartSubmission | null {\n if (items.some(({ facts }) => facts.submissionMode !== 'simultaneous')) return null;\n const sessions: PartSubmission['sessions'] = [];\n const effects: Effect[] = [];\n for (const { item, previous, facts } of items) {\n const { adaptive } = facts;\n const state = previous?.state ?? seedItemLifecycle(facts);\n if (OVER.has(state)) {\n sessions.push({ item, session: { state, numAttempts: facts.numAttempts, adaptive } });\n continue;\n }\n // A restored session not on screen seeds as `initial`; `completionStatus` still says it was opened.\n const opened = state !== 'initial' || facts.completionStatus !== 'not_attempted';\n const guards = itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n sessions.push({\n item,\n session: {\n state: transition(state, 'endItemSession', guards) ?? 'closed',\n numAttempts: facts.numAttempts + (opened ? 1 : 0),\n adaptive\n }\n });\n }\n effects.push({ type: 'runOutcomeProcessing' });\n return { sessions, effects };\n}\n"]}
@@ -18,16 +18,36 @@ export interface TestPartModel {
18
18
  navigationMode: 'linear' | 'nonlinear';
19
19
  submissionMode: 'individual' | 'simultaneous';
20
20
  sessionControl: SessionControl;
21
+ /** How many `qti-pre-condition`s the part has; a part's are always considered (impl. guide §4.5.3). */
22
+ preConditions: number;
23
+ /** Its `qti-branch-rule`s, in document order; a part's are always considered. */
24
+ branchRules: BranchRuleModel[];
21
25
  /** The part's own `qti-time-limits`; absent when it declares none. */
22
26
  timeLimits?: TimeLimits;
23
27
  sections: SectionModel[];
24
28
  }
29
+ /** A `qti-branch-rule`: where the test goes when its expression is true (info model §5.23). */
30
+ export interface BranchRuleModel {
31
+ /** An item-ref, section or test part identifier, or `EXIT_SECTION`, `EXIT_TESTPART`, `EXIT_TEST`. */
32
+ target: string;
33
+ }
34
+ /** The attribute `qtiTransformTest` puts on a section it merged from a `qti-assessment-section-ref`. */
35
+ export declare const SECTION_REF_ATTRIBUTE = "data-qc-section-ref";
25
36
  export interface SectionModel {
26
37
  kind: 'section';
27
38
  identifier: string;
28
39
  title: string;
29
40
  visible: boolean;
30
41
  sessionControl: SessionControl;
42
+ /**
43
+ * Merged from a `qti-assessment-section-ref`: branch rules outside it treat it as a leaf and
44
+ * cannot target what is inside it (info model §7.5).
45
+ */
46
+ fromSectionRef: boolean;
47
+ /** How many `qti-pre-condition`s it has; considered only in a linear part. */
48
+ preConditions: number;
49
+ /** Its `qti-branch-rule`s, in document order; considered only in a linear part. */
50
+ branchRules: BranchRuleModel[];
31
51
  /** The section's own `qti-time-limits`; absent when it declares none. */
32
52
  timeLimits?: TimeLimits;
33
53
  /** The item-refs and sections directly inside this one, in document order, as the XML has them. */
@@ -41,6 +61,10 @@ export interface ItemRefModel {
41
61
  sessionControl: SessionControl;
42
62
  /** What this item-ref's own `qti-item-session-control` declares, nothing inherited. */
43
63
  declaredSessionControl: Partial<SessionControl>;
64
+ /** How many `qti-pre-condition`s it has; considered only in a linear part. */
65
+ preConditions: number;
66
+ /** Its `qti-branch-rule`s, in document order; considered only in a linear part. */
67
+ branchRules: BranchRuleModel[];
44
68
  /** The item-ref's own `qti-time-limits`; absent when it declares none. */
45
69
  timeLimits?: TimeLimits;
46
70
  }
@@ -1,4 +1,6 @@
1
1
  import { booleanAttribute, childElement, childElements, integerAttribute, nonNegativeNumberAttribute } from './xml-node.js';
2
+ /** The attribute `qtiTransformTest` puts on a section it merged from a `qti-assessment-section-ref`. */
3
+ export const SECTION_REF_ATTRIBUTE = 'data-qc-section-ref';
2
4
  /**
3
5
  * The values when no level declares an attribute: the XSD defaults, and 1 for `max-attempts`,
4
6
  * which the spec text gives ("if it is unspecified it is treated as 1 for non-adaptive items").
@@ -40,6 +42,7 @@ function buildTestPart(part) {
40
42
  navigationMode: part.getAttribute('navigation-mode') === 'linear' ? 'linear' : 'nonlinear',
41
43
  submissionMode: part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual',
42
44
  sessionControl,
45
+ ...sequencingRules(part),
43
46
  ...timeLimitsOf(part),
44
47
  sections: childElements(part, 'qti-assessment-section').map(section => buildSection(section, sessionControl))
45
48
  };
@@ -52,6 +55,8 @@ function buildSection(section, inherited) {
52
55
  title: section.getAttribute('title') ?? '',
53
56
  visible: booleanAttribute(section, 'visible') ?? true,
54
57
  sessionControl,
58
+ fromSectionRef: section.getAttribute(SECTION_REF_ATTRIBUTE) !== null,
59
+ ...sequencingRules(section),
55
60
  ...timeLimitsOf(section),
56
61
  content: childElements(section, 'qti-assessment-section', 'qti-assessment-item-ref').map(child => child.localName === 'qti-assessment-section'
57
62
  ? buildSection(child, sessionControl)
@@ -67,9 +72,17 @@ function buildItemRef(itemRef, inherited) {
67
72
  categories: category ? category.split(/\s+/) : [],
68
73
  sessionControl: resolveSessionControl(inherited, itemRef),
69
74
  declaredSessionControl: declaredSessionControl(itemRef),
75
+ ...sequencingRules(itemRef),
70
76
  ...timeLimitsOf(itemRef)
71
77
  };
72
78
  }
79
+ /** The `qti-pre-condition`s (counted) and `qti-branch-rule`s directly inside `owner`. */
80
+ function sequencingRules(owner) {
81
+ return {
82
+ preConditions: childElements(owner, 'qti-pre-condition').length,
83
+ branchRules: childElements(owner, 'qti-branch-rule').map(rule => ({ target: rule.getAttribute('target') ?? '' }))
84
+ };
85
+ }
73
86
  /** `inherited`, with what `owner`'s own `qti-item-session-control` declares on top. */
74
87
  function resolveSessionControl(inherited, owner) {
75
88
  return { ...inherited, ...declaredSessionControl(owner) };
@@ -1 +1 @@
1
- {"version":3,"file":"test-model.js","sourceRoot":"","sources":["../../src/model/test-model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,eA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AE,iBAAiB,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,OAAO;QACL,UAAU,EAAE;YACV,OAAO,EAAE,0BAA0B,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,IAAI;YAChE,OAAO,EAAE,0BAA0B,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,IAAI;YAChE,mBAAmB,EAAE,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,CAAC,IAAI,KAAK;SACjF;KACF,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAqB,EAAkB,EAAE,CACnE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAyB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;AAErF,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAAC,QAAwB;IACtD,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,OAAO;QACP,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAyB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;KACvG,CAAC,CAAC;AACL,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,eAAe,CAAC,QAA0B;IACxD,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC","sourcesContent":["import {\n booleanAttribute,\n childElement,\n childElements,\n integerAttribute,\n nonNegativeNumberAttribute\n} from './xml-node.js';\n\nimport type { XmlElement } from './xml-node.js';\n\n/**\n * The structure and the resolved rules of a `qti-assessment-test`, read from its XML once per load.\n * Plain JSON, so a server can build it from the same file.\n *\n * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.\n */\nexport interface TestModel {\n identifier: string;\n title: string;\n /** The test's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n testParts: TestPartModel[];\n}\n\nexport interface TestPartModel {\n identifier: string;\n /** Defined on the test part only (QTI 3 XSD); a section never changes it. */\n navigationMode: 'linear' | 'nonlinear';\n submissionMode: 'individual' | 'simultaneous';\n sessionControl: SessionControl;\n /** The part's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n sections: SectionModel[];\n}\n\nexport interface SectionModel {\n kind: 'section';\n identifier: string;\n title: string;\n visible: boolean;\n sessionControl: SessionControl;\n /** The section's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n /** The item-refs and sections directly inside this one, in document order, as the XML has them. */\n content: SectionContent[];\n}\n\nexport interface ItemRefModel {\n kind: 'itemRef';\n identifier: string;\n href: string;\n categories: string[];\n sessionControl: SessionControl;\n /** What this item-ref's own `qti-item-session-control` declares, nothing inherited. */\n declaredSessionControl: Partial<SessionControl>;\n /** The item-ref's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n}\n\nexport type SectionContent = SectionModel | ItemRefModel;\n\n/** `qti-item-session-control`, resolved for one level (QTI 3 info model §7.19). */\nexport interface SessionControl {\n /** 0 is unlimited. Ignored for adaptive items, which end by `completionStatus`. */\n maxAttempts: number;\n showFeedback: boolean;\n allowReview: boolean;\n showSolution: boolean;\n allowComment: boolean;\n /** Applies only in a test part with individual submission. */\n allowSkipping: boolean;\n /** Applies only in a test part with individual submission. */\n validateResponses: boolean;\n}\n\n/**\n * `qti-time-limits` as one level declares it (QTI 3 info model §7.40, §2.8.5). Never inherited: each\n * limit is on the time spent in its own level, the item-ref's on the item session's `duration`, a\n * section's, part's or test's on all the time spent in it, navigation included.\n */\nexport interface TimeLimits {\n /**\n * Seconds; null when not declared. On a section or item-ref it applies only in a linear part\n * (§2.8.5); `timeLimitRules` leaves it out elsewhere.\n */\n minTime: number | null;\n /** Seconds; null when not declared. */\n maxTime: number | null;\n /** Whether a response given after `maxTime` is still accepted. False when not declared (the XSD default). */\n allowLateSubmission: boolean;\n}\n\n/**\n * The values when no level declares an attribute: the XSD defaults, and 1 for `max-attempts`,\n * which the spec text gives (\"if it is unspecified it is treated as 1 for non-adaptive items\").\n */\nexport const DEFAULT_SESSION_CONTROL: Readonly<SessionControl> = Object.freeze({\n maxAttempts: 1,\n showFeedback: false,\n allowReview: true,\n showSolution: false,\n allowComment: false,\n allowSkipping: true,\n validateResponses: false\n});\n\n/**\n * Build the model of a test from its `qti-assessment-test` element: the XML document under Node, the\n * rendered element in the browser. Reads attributes and child elements only, so no element needs\n * to be registered.\n *\n * Session control inherits per attribute: each one comes from the closest level that declares it\n * (item-ref, then each enclosing section, then the test part), and its default only when none does.\n * The spec: a test-part setting applies \"unless the setting is overridden\", and the defaults \"are\n * used only in the absence of any applicable constraint\" (implementation guide §4.4.2).\n */\nexport function buildTestModel(test: XmlElement): TestModel {\n if (test.localName !== 'qti-assessment-test') {\n throw new TypeError(`Expected a qti-assessment-test element, not ${String(test.localName)}.`);\n }\n return {\n identifier: test.getAttribute('identifier') ?? '',\n title: test.getAttribute('title') ?? '',\n ...timeLimitsOf(test),\n testParts: childElements(test, 'qti-test-part').map(buildTestPart)\n };\n}\n\nfunction buildTestPart(part: XmlElement): TestPartModel {\n const sessionControl = resolveSessionControl(DEFAULT_SESSION_CONTROL, part);\n return {\n identifier: part.getAttribute('identifier') ?? '',\n navigationMode: part.getAttribute('navigation-mode') === 'linear' ? 'linear' : 'nonlinear',\n submissionMode: part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual',\n sessionControl,\n ...timeLimitsOf(part),\n sections: childElements(part, 'qti-assessment-section').map(section => buildSection(section, sessionControl))\n };\n}\n\nfunction buildSection(section: XmlElement, inherited: SessionControl): SectionModel {\n const sessionControl = resolveSessionControl(inherited, section);\n return {\n kind: 'section',\n identifier: section.getAttribute('identifier') ?? '',\n title: section.getAttribute('title') ?? '',\n visible: booleanAttribute(section, 'visible') ?? true,\n sessionControl,\n ...timeLimitsOf(section),\n content: childElements(section, 'qti-assessment-section', 'qti-assessment-item-ref').map(child =>\n child.localName === 'qti-assessment-section'\n ? buildSection(child, sessionControl)\n : buildItemRef(child, sessionControl)\n )\n };\n}\n\nfunction buildItemRef(itemRef: XmlElement, inherited: SessionControl): ItemRefModel {\n const category = itemRef.getAttribute('category')?.trim();\n return {\n kind: 'itemRef',\n identifier: itemRef.getAttribute('identifier') ?? '',\n href: itemRef.getAttribute('href') ?? '',\n categories: category ? category.split(/\\s+/) : [],\n sessionControl: resolveSessionControl(inherited, itemRef),\n declaredSessionControl: declaredSessionControl(itemRef),\n ...timeLimitsOf(itemRef)\n };\n}\n\n/** `inherited`, with what `owner`'s own `qti-item-session-control` declares on top. */\nfunction resolveSessionControl(inherited: Readonly<SessionControl>, owner: XmlElement): SessionControl {\n return { ...inherited, ...declaredSessionControl(owner) };\n}\n\n/** Only the attributes `owner`'s `qti-item-session-control` declares, so an absent one inherits. */\nfunction declaredSessionControl(owner: XmlElement): Partial<SessionControl> {\n const element = childElement(owner, 'qti-item-session-control');\n if (!element) return {};\n const declared: Partial<SessionControl> = {\n maxAttempts: integerAttribute(element, 'max-attempts'),\n showFeedback: booleanAttribute(element, 'show-feedback'),\n allowReview: booleanAttribute(element, 'allow-review'),\n showSolution: booleanAttribute(element, 'show-solution'),\n allowComment: booleanAttribute(element, 'allow-comment'),\n allowSkipping: booleanAttribute(element, 'allow-skipping'),\n validateResponses: booleanAttribute(element, 'validate-responses')\n };\n return Object.fromEntries(Object.entries(declared).filter(([, value]) => value !== undefined));\n}\n\n/**\n * `owner`'s own `qti-time-limits` as `{ timeLimits }`, or nothing when it declares none, so the\n * model holds the key only where the XML has the element. A value that is not a non-negative number\n * counts as not declared.\n */\nfunction timeLimitsOf(owner: XmlElement): { timeLimits?: TimeLimits } {\n const element = childElement(owner, 'qti-time-limits');\n if (!element) return {};\n return {\n timeLimits: {\n minTime: nonNegativeNumberAttribute(element, 'min-time') ?? null,\n maxTime: nonNegativeNumberAttribute(element, 'max-time') ?? null,\n allowLateSubmission: booleanAttribute(element, 'allow-late-submission') ?? false\n }\n };\n}\n\n/** The item-refs directly inside a section, in document order; not those of its subsections. */\nexport const ownItemRefs = (section: SectionModel): ItemRefModel[] =>\n section.content.filter((child): child is ItemRefModel => child.kind === 'itemRef');\n\n/** Every section, depth first in document order: a section before its subsections. */\nexport function sectionsInOrder(sections: SectionModel[]): SectionModel[] {\n return sections.flatMap(section => [\n section,\n ...sectionsInOrder(section.content.filter((child): child is SectionModel => child.kind === 'section'))\n ]);\n}\n\n/** Every item-ref inside the given sections, at any depth, in document order. */\nexport function itemRefsInOrder(sections: SectionContent[]): ItemRefModel[] {\n return sections.flatMap(child => (child.kind === 'itemRef' ? [child] : itemRefsInOrder(child.content)));\n}\n"]}
1
+ {"version":3,"file":"test-model.js","sourceRoot":"","sources":["../../src/model/test-model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,eAAe,CAAC;AAuCvB,wGAAwG;AACxG,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAwE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA6B,MAAM,CAAC,MAAM,CAAC;IAC7E,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,KAAK;IACnB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,KAAK;CACzB,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,IAAI,IAAI,CAAC,SAAS,KAAK,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","sourcesContent":["import {\n booleanAttribute,\n childElement,\n childElements,\n integerAttribute,\n nonNegativeNumberAttribute\n} from './xml-node.js';\n\nimport type { XmlElement } from './xml-node.js';\n\n/**\n * The structure and the resolved rules of a `qti-assessment-test`, read from its XML once per load.\n * Plain JSON, so a server can build it from the same file.\n *\n * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.\n */\nexport interface TestModel {\n identifier: string;\n title: string;\n /** The test's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n testParts: TestPartModel[];\n}\n\nexport interface TestPartModel {\n identifier: string;\n /** Defined on the test part only (QTI 3 XSD); a section never changes it. */\n navigationMode: 'linear' | 'nonlinear';\n submissionMode: 'individual' | 'simultaneous';\n sessionControl: SessionControl;\n /** How many `qti-pre-condition`s the part has; a part's are always considered (impl. guide §4.5.3). */\n preConditions: number;\n /** Its `qti-branch-rule`s, in document order; a part's are always considered. */\n branchRules: BranchRuleModel[];\n /** The part's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n sections: SectionModel[];\n}\n\n/** A `qti-branch-rule`: where the test goes when its expression is true (info model §5.23). */\nexport interface BranchRuleModel {\n /** An item-ref, section or test part identifier, or `EXIT_SECTION`, `EXIT_TESTPART`, `EXIT_TEST`. */\n target: string;\n}\n\n/** The attribute `qtiTransformTest` puts on a section it merged from a `qti-assessment-section-ref`. */\nexport const SECTION_REF_ATTRIBUTE = 'data-qc-section-ref';\n\nexport interface SectionModel {\n kind: 'section';\n identifier: string;\n title: string;\n visible: boolean;\n sessionControl: SessionControl;\n /**\n * Merged from a `qti-assessment-section-ref`: branch rules outside it treat it as a leaf and\n * cannot target what is inside it (info model §7.5).\n */\n fromSectionRef: boolean;\n /** How many `qti-pre-condition`s it has; considered only in a linear part. */\n preConditions: number;\n /** Its `qti-branch-rule`s, in document order; considered only in a linear part. */\n branchRules: BranchRuleModel[];\n /** The section's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n /** The item-refs and sections directly inside this one, in document order, as the XML has them. */\n content: SectionContent[];\n}\n\nexport interface ItemRefModel {\n kind: 'itemRef';\n identifier: string;\n href: string;\n categories: string[];\n sessionControl: SessionControl;\n /** What this item-ref's own `qti-item-session-control` declares, nothing inherited. */\n declaredSessionControl: Partial<SessionControl>;\n /** How many `qti-pre-condition`s it has; considered only in a linear part. */\n preConditions: number;\n /** Its `qti-branch-rule`s, in document order; considered only in a linear part. */\n branchRules: BranchRuleModel[];\n /** The item-ref's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n}\n\nexport type SectionContent = SectionModel | ItemRefModel;\n\n/** `qti-item-session-control`, resolved for one level (QTI 3 info model §7.19). */\nexport interface SessionControl {\n /** 0 is unlimited. Ignored for adaptive items, which end by `completionStatus`. */\n maxAttempts: number;\n showFeedback: boolean;\n allowReview: boolean;\n showSolution: boolean;\n allowComment: boolean;\n /** Applies only in a test part with individual submission. */\n allowSkipping: boolean;\n /** Applies only in a test part with individual submission. */\n validateResponses: boolean;\n}\n\n/**\n * `qti-time-limits` as one level declares it (QTI 3 info model §7.40, §2.8.5). Never inherited: each\n * limit is on the time spent in its own level, the item-ref's on the item session's `duration`, a\n * section's, part's or test's on all the time spent in it, navigation included.\n */\nexport interface TimeLimits {\n /**\n * Seconds; null when not declared. On a section or item-ref it applies only in a linear part\n * (§2.8.5); `timeLimitRules` leaves it out elsewhere.\n */\n minTime: number | null;\n /** Seconds; null when not declared. */\n maxTime: number | null;\n /** Whether a response given after `maxTime` is still accepted. False when not declared (the XSD default). */\n allowLateSubmission: boolean;\n}\n\n/**\n * The values when no level declares an attribute: the XSD defaults, and 1 for `max-attempts`,\n * which the spec text gives (\"if it is unspecified it is treated as 1 for non-adaptive items\").\n */\nexport const DEFAULT_SESSION_CONTROL: Readonly<SessionControl> = Object.freeze({\n maxAttempts: 1,\n showFeedback: false,\n allowReview: true,\n showSolution: false,\n allowComment: false,\n allowSkipping: true,\n validateResponses: false\n});\n\n/**\n * Build the model of a test from its `qti-assessment-test` element: the XML document under Node, the\n * rendered element in the browser. Reads attributes and child elements only, so no element needs\n * to be registered.\n *\n * Session control inherits per attribute: each one comes from the closest level that declares it\n * (item-ref, then each enclosing section, then the test part), and its default only when none does.\n * The spec: a test-part setting applies \"unless the setting is overridden\", and the defaults \"are\n * used only in the absence of any applicable constraint\" (implementation guide §4.4.2).\n */\nexport function buildTestModel(test: XmlElement): TestModel {\n if (test.localName !== 'qti-assessment-test') {\n throw new TypeError(`Expected a qti-assessment-test element, not ${String(test.localName)}.`);\n }\n return {\n identifier: test.getAttribute('identifier') ?? '',\n title: test.getAttribute('title') ?? '',\n ...timeLimitsOf(test),\n testParts: childElements(test, 'qti-test-part').map(buildTestPart)\n };\n}\n\nfunction buildTestPart(part: XmlElement): TestPartModel {\n const sessionControl = resolveSessionControl(DEFAULT_SESSION_CONTROL, part);\n return {\n identifier: part.getAttribute('identifier') ?? '',\n navigationMode: part.getAttribute('navigation-mode') === 'linear' ? 'linear' : 'nonlinear',\n submissionMode: part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual',\n sessionControl,\n ...sequencingRules(part),\n ...timeLimitsOf(part),\n sections: childElements(part, 'qti-assessment-section').map(section => buildSection(section, sessionControl))\n };\n}\n\nfunction buildSection(section: XmlElement, inherited: SessionControl): SectionModel {\n const sessionControl = resolveSessionControl(inherited, section);\n return {\n kind: 'section',\n identifier: section.getAttribute('identifier') ?? '',\n title: section.getAttribute('title') ?? '',\n visible: booleanAttribute(section, 'visible') ?? true,\n sessionControl,\n fromSectionRef: section.getAttribute(SECTION_REF_ATTRIBUTE) !== null,\n ...sequencingRules(section),\n ...timeLimitsOf(section),\n content: childElements(section, 'qti-assessment-section', 'qti-assessment-item-ref').map(child =>\n child.localName === 'qti-assessment-section'\n ? buildSection(child, sessionControl)\n : buildItemRef(child, sessionControl)\n )\n };\n}\n\nfunction buildItemRef(itemRef: XmlElement, inherited: SessionControl): ItemRefModel {\n const category = itemRef.getAttribute('category')?.trim();\n return {\n kind: 'itemRef',\n identifier: itemRef.getAttribute('identifier') ?? '',\n href: itemRef.getAttribute('href') ?? '',\n categories: category ? category.split(/\\s+/) : [],\n sessionControl: resolveSessionControl(inherited, itemRef),\n declaredSessionControl: declaredSessionControl(itemRef),\n ...sequencingRules(itemRef),\n ...timeLimitsOf(itemRef)\n };\n}\n\n/** The `qti-pre-condition`s (counted) and `qti-branch-rule`s directly inside `owner`. */\nfunction sequencingRules(owner: XmlElement): { preConditions: number; branchRules: BranchRuleModel[] } {\n return {\n preConditions: childElements(owner, 'qti-pre-condition').length,\n branchRules: childElements(owner, 'qti-branch-rule').map(rule => ({ target: rule.getAttribute('target') ?? '' }))\n };\n}\n\n/** `inherited`, with what `owner`'s own `qti-item-session-control` declares on top. */\nfunction resolveSessionControl(inherited: Readonly<SessionControl>, owner: XmlElement): SessionControl {\n return { ...inherited, ...declaredSessionControl(owner) };\n}\n\n/** Only the attributes `owner`'s `qti-item-session-control` declares, so an absent one inherits. */\nfunction declaredSessionControl(owner: XmlElement): Partial<SessionControl> {\n const element = childElement(owner, 'qti-item-session-control');\n if (!element) return {};\n const declared: Partial<SessionControl> = {\n maxAttempts: integerAttribute(element, 'max-attempts'),\n showFeedback: booleanAttribute(element, 'show-feedback'),\n allowReview: booleanAttribute(element, 'allow-review'),\n showSolution: booleanAttribute(element, 'show-solution'),\n allowComment: booleanAttribute(element, 'allow-comment'),\n allowSkipping: booleanAttribute(element, 'allow-skipping'),\n validateResponses: booleanAttribute(element, 'validate-responses')\n };\n return Object.fromEntries(Object.entries(declared).filter(([, value]) => value !== undefined));\n}\n\n/**\n * `owner`'s own `qti-time-limits` as `{ timeLimits }`, or nothing when it declares none, so the\n * model holds the key only where the XML has the element. A value that is not a non-negative number\n * counts as not declared.\n */\nfunction timeLimitsOf(owner: XmlElement): { timeLimits?: TimeLimits } {\n const element = childElement(owner, 'qti-time-limits');\n if (!element) return {};\n return {\n timeLimits: {\n minTime: nonNegativeNumberAttribute(element, 'min-time') ?? null,\n maxTime: nonNegativeNumberAttribute(element, 'max-time') ?? null,\n allowLateSubmission: booleanAttribute(element, 'allow-late-submission') ?? false\n }\n };\n}\n\n/** The item-refs directly inside a section, in document order; not those of its subsections. */\nexport const ownItemRefs = (section: SectionModel): ItemRefModel[] =>\n section.content.filter((child): child is ItemRefModel => child.kind === 'itemRef');\n\n/** Every section, depth first in document order: a section before its subsections. */\nexport function sectionsInOrder(sections: SectionModel[]): SectionModel[] {\n return sections.flatMap(section => [\n section,\n ...sectionsInOrder(section.content.filter((child): child is SectionModel => child.kind === 'section'))\n ]);\n}\n\n/** Every item-ref inside the given sections, at any depth, in document order. */\nexport function itemRefsInOrder(sections: SectionContent[]): ItemRefModel[] {\n return sections.flatMap(child => (child.kind === 'itemRef' ? [child] : itemRefsInOrder(child.content)));\n}\n"]}
@@ -0,0 +1,62 @@
1
+ import type { TestModel } from '../model/test-model.js';
2
+ import type { ItemInstanceId } from '../state/delivery-state.js';
3
+ /**
4
+ * Sequencing between items (QTI 3 implementation guide §4.5.3, info model §2.8.3): which item a
5
+ * test presents next, from the test model and the order of item instances, never the live DOM.
6
+ *
7
+ * The rules' expressions are QTI expressions, which this package does not evaluate (roadmap 3), so
8
+ * the caller answers each one through `evaluate`. The structure is decided here: which rules count
9
+ * (on items and sections only in a linear part, on test parts always), in what order, and where a
10
+ * target lands.
11
+ */
12
+ export type SequencingLevel = 'testPart' | 'section' | 'itemRef';
13
+ /** One `qti-pre-condition` or `qti-branch-rule`, by its owner and its place among the owner's rules. */
14
+ export interface SequencingRule {
15
+ level: SequencingLevel;
16
+ /** The identifier of the test part, section or item-ref (instance id) that holds the rule. */
17
+ owner: string;
18
+ kind: 'preCondition' | 'branchRule';
19
+ /** Its index among the owner's rules of this kind, in document order. */
20
+ index: number;
21
+ }
22
+ /** Answers whether a rule's expression is true now. */
23
+ export type EvaluateRule = (rule: SequencingRule) => boolean;
24
+ /** A stable text key for a rule, `level:owner:kind:index`, as the test vectors write it. */
25
+ export declare const ruleKey: ({ level, owner, kind, index }: SequencingRule) => string;
26
+ export declare const EXIT_SECTION = "EXIT_SECTION";
27
+ export declare const EXIT_TESTPART = "EXIT_TESTPART";
28
+ export declare const EXIT_TEST = "EXIT_TEST";
29
+ export interface NextItem {
30
+ /** The item instance to present, or null when the test has no item left. */
31
+ id: ItemInstanceId | null;
32
+ /** The item instances passed over on the way, in order: not presented. */
33
+ skipped: ItemInstanceId[];
34
+ /** Branch targets ignored because selection or ordering left them nowhere ahead (§4.5.3: "not defined"). */
35
+ warnings: string[];
36
+ }
37
+ /**
38
+ * The item to present after `current`: branch rules first (the item's, then those of each section
39
+ * it ends from the inside out, then the test part's when it ends the part), the first one that is
40
+ * true wins; then pre-conditions on the target and on, skipping forward until all pass (impl. guide
41
+ * §4.5.3 steps 2 and 3).
42
+ *
43
+ * @param model the test model, built from the test as rendered: after selection and ordering
44
+ * @param current the item instance that was just presented
45
+ */
46
+ export declare function nextItem(model: TestModel, current: ItemInstanceId, evaluate: EvaluateRule): NextItem;
47
+ /** The first item to present: the first one whose test part, sections and own pre-conditions pass. */
48
+ export declare function firstItem(model: TestModel, evaluate: EvaluateRule): NextItem;
49
+ /** A branch target QTI forbids (info model §2.8.3.2, §7.5). */
50
+ export interface SequencingError {
51
+ level: SequencingLevel;
52
+ owner: string;
53
+ target: string;
54
+ reason: 'backward' | 'other-part' | 'not-a-part' | 'not-found' | 'inside-section-ref';
55
+ }
56
+ /**
57
+ * The branch rules whose target QTI forbids, in the test as authored (before selection and
58
+ * ordering): an item or section target must be ahead in the same test part and not inside a
59
+ * section merged from a section-ref that the rule is outside of; a test part's target must be a
60
+ * later test part. Reserved targets are always allowed.
61
+ */
62
+ export declare function sequencingErrors(model: TestModel): SequencingError[];
@@ -0,0 +1,226 @@
1
+ import { parseItemInstanceId } from '../state/delivery-state.js';
2
+ /** A stable text key for a rule, `level:owner:kind:index`, as the test vectors write it. */
3
+ export const ruleKey = ({ level, owner, kind, index }) => `${level}:${owner}:${kind}:${index}`;
4
+ export const EXIT_SECTION = 'EXIT_SECTION';
5
+ export const EXIT_TESTPART = 'EXIT_TESTPART';
6
+ export const EXIT_TEST = 'EXIT_TEST';
7
+ const RESERVED_TARGETS = new Set([EXIT_SECTION, EXIT_TESTPART, EXIT_TEST]);
8
+ /** Array.prototype.findLastIndex, which this package's ES2022 target lacks. */
9
+ function lastIndex(items, matches) {
10
+ for (let i = items.length - 1; i >= 0; i--)
11
+ if (matches(items[i]))
12
+ return i;
13
+ return -1;
14
+ }
15
+ function stepsOf(model) {
16
+ const steps = [];
17
+ const walk = (part, content, sections) => {
18
+ for (const child of content) {
19
+ if (child.kind === 'itemRef')
20
+ steps.push({ part, sections, itemRef: child });
21
+ else
22
+ walk(part, child.content, [...sections, child]);
23
+ }
24
+ };
25
+ for (const part of model.testParts)
26
+ walk(part, part.sections, []);
27
+ return steps;
28
+ }
29
+ /**
30
+ * The item to present after `current`: branch rules first (the item's, then those of each section
31
+ * it ends from the inside out, then the test part's when it ends the part), the first one that is
32
+ * true wins; then pre-conditions on the target and on, skipping forward until all pass (impl. guide
33
+ * §4.5.3 steps 2 and 3).
34
+ *
35
+ * @param model the test model, built from the test as rendered: after selection and ordering
36
+ * @param current the item instance that was just presented
37
+ */
38
+ export function nextItem(model, current, evaluate) {
39
+ const steps = stepsOf(model);
40
+ const index = steps.findIndex(step => step.itemRef.identifier === current);
41
+ if (index < 0)
42
+ throw new RangeError(`Item "${current}" is not in the test.`);
43
+ const from = steps[index];
44
+ const warnings = [];
45
+ let start = index + 1;
46
+ const fired = firingBranchRule(steps, index, evaluate);
47
+ if (fired) {
48
+ const target = branchTarget(steps, index, fired);
49
+ if (target === undefined) {
50
+ warnings.push(`qti-branch-rule target "${fired.rule.target}" of "${fired.owner}" is nowhere ahead in the test; ignored.`);
51
+ }
52
+ else
53
+ start = target;
54
+ }
55
+ const skipped = steps.slice(index + 1, start).map(step => step.itemRef.identifier);
56
+ return { ...presentable(steps, start, from, evaluate, skipped), warnings };
57
+ }
58
+ /** The first item to present: the first one whose test part, sections and own pre-conditions pass. */
59
+ export function firstItem(model, evaluate) {
60
+ return { ...presentable(stepsOf(model), 0, undefined, evaluate, []), warnings: [] };
61
+ }
62
+ function firingBranchRule(steps, index, evaluate) {
63
+ const from = steps[index];
64
+ const next = steps[index + 1];
65
+ const owners = [];
66
+ const rulesOf = new Map();
67
+ const add = (owner, rules) => {
68
+ owners.push(owner);
69
+ rulesOf.set(owner, rules);
70
+ };
71
+ if (from.part.navigationMode === 'linear') {
72
+ add({ level: 'itemRef', owner: from.itemRef.identifier }, from.itemRef.branchRules);
73
+ for (const section of [...from.sections].reverse()) {
74
+ if (next?.sections.includes(section))
75
+ break; // not its last item, nor of any section around it
76
+ add({ level: 'section', owner: section.identifier, section }, section.branchRules);
77
+ }
78
+ }
79
+ if (!next || next.part !== from.part)
80
+ add({ level: 'testPart', owner: from.part.identifier }, from.part.branchRules);
81
+ for (const owner of owners) {
82
+ const rules = rulesOf.get(owner);
83
+ for (let i = 0; i < rules.length; i++) {
84
+ if (evaluate({ level: owner.level, owner: owner.owner, kind: 'branchRule', index: i })) {
85
+ return { ...owner, rule: rules[i] };
86
+ }
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ /** The index of the first step to consider after a branch, `steps.length` for the end, undefined when nowhere ahead. */
92
+ function branchTarget(steps, index, fired) {
93
+ const from = steps[index];
94
+ const after = (inside) => lastIndex(steps, inside) + 1;
95
+ const ahead = (matches) => {
96
+ const found = steps.findIndex((step, i) => i > index && matches(step));
97
+ return found < 0 ? undefined : found;
98
+ };
99
+ const target = fired.rule.target;
100
+ switch (target) {
101
+ case EXIT_TEST:
102
+ return steps.length;
103
+ case EXIT_TESTPART:
104
+ return after(step => step.part === from.part);
105
+ case EXIT_SECTION: {
106
+ const section = fired.level === 'section' ? fired.section : from.sections.at(-1);
107
+ return section ? after(step => step.sections.includes(section)) : undefined;
108
+ }
109
+ }
110
+ if (fired.level === 'testPart') {
111
+ return ahead(step => step.part !== from.part && step.part.identifier === target);
112
+ }
113
+ return ahead(step => step.part === from.part && targetableIn(step, from).includes(target));
114
+ }
115
+ /**
116
+ * What a rule of `from`'s item or sections may target in `step`: the sections it has not entered,
117
+ * down to a section merged from a section-ref, which is a leaf (info model §7.5), and the item.
118
+ */
119
+ function targetableIn(step, from) {
120
+ const ids = [];
121
+ for (const section of step.sections) {
122
+ if (from.sections.includes(section))
123
+ continue;
124
+ ids.push(section.identifier);
125
+ if (section.fromSectionRef)
126
+ return ids;
127
+ }
128
+ const { identifier } = step.itemRef;
129
+ return [...ids, identifier, parseItemInstanceId(identifier).itemRefIdentifier];
130
+ }
131
+ /** From `start` on, the first step whose entered levels' pre-conditions all pass. */
132
+ function presentable(steps, start, from, evaluate, skipped) {
133
+ const passed = new Map();
134
+ const passes = (level, owner) => {
135
+ if (!passed.has(owner)) {
136
+ let all = true;
137
+ for (let i = 0; all && i < owner.preConditions; i++) {
138
+ all = evaluate({ level, owner: owner.identifier, kind: 'preCondition', index: i });
139
+ }
140
+ passed.set(owner, all);
141
+ }
142
+ return passed.get(owner);
143
+ };
144
+ const skipTo = (from, to) => {
145
+ skipped.push(...steps.slice(from, to).map(step => step.itemRef.identifier));
146
+ return to;
147
+ };
148
+ let i = start;
149
+ while (i < steps.length) {
150
+ const step = steps[i];
151
+ if ((!from || step.part !== from.part) && !passes('testPart', step.part)) {
152
+ i = skipTo(i, lastIndex(steps, (s) => s.part === step.part) + 1);
153
+ continue;
154
+ }
155
+ if (step.part.navigationMode === 'linear') {
156
+ const failed = step.sections.find(section => !from?.sections.includes(section) && !passes('section', section));
157
+ if (failed) {
158
+ i = skipTo(i, lastIndex(steps, (s) => s.sections.includes(failed)) + 1);
159
+ continue;
160
+ }
161
+ if (!passes('itemRef', step.itemRef)) {
162
+ i = skipTo(i, i + 1);
163
+ continue;
164
+ }
165
+ }
166
+ return { id: step.itemRef.identifier, skipped };
167
+ }
168
+ return { id: null, skipped };
169
+ }
170
+ /**
171
+ * The branch rules whose target QTI forbids, in the test as authored (before selection and
172
+ * ordering): an item or section target must be ahead in the same test part and not inside a
173
+ * section merged from a section-ref that the rule is outside of; a test part's target must be a
174
+ * later test part. Reserved targets are always allowed.
175
+ */
176
+ export function sequencingErrors(model) {
177
+ const errors = [];
178
+ const nodesByPart = model.testParts.map(part => nodesOf(part.sections));
179
+ const anywhere = (target) => model.testParts.some(part => part.identifier === target) ||
180
+ nodesByPart.some(nodes => nodes.some(node => matches(node, target)));
181
+ model.testParts.forEach((part, partIndex) => {
182
+ for (const { target } of part.branchRules) {
183
+ if (RESERVED_TARGETS.has(target))
184
+ continue;
185
+ const targetIndex = model.testParts.findIndex(p => p.identifier === target);
186
+ if (targetIndex > partIndex)
187
+ continue;
188
+ const reason = targetIndex >= 0 ? 'backward' : anywhere(target) ? 'not-a-part' : 'not-found';
189
+ errors.push({ level: 'testPart', owner: part.identifier, target, reason });
190
+ }
191
+ const nodes = nodesByPart[partIndex];
192
+ for (const node of nodes) {
193
+ for (const { target } of node.model.branchRules) {
194
+ if (RESERVED_TARGETS.has(target))
195
+ continue;
196
+ const error = (reason) => errors.push({ level: node.level, owner: node.model.identifier, target, reason });
197
+ const found = nodes.find(other => matches(other, target));
198
+ if (!found)
199
+ error(anywhere(target) ? 'other-part' : 'not-found');
200
+ else if (found.start <= node.end)
201
+ error('backward');
202
+ else if (found.ancestors.some(section => section.fromSectionRef && section !== node.model && !node.ancestors.includes(section))) {
203
+ error('inside-section-ref');
204
+ }
205
+ }
206
+ }
207
+ });
208
+ return errors;
209
+ }
210
+ const matches = (node, target) => node.model.identifier === target ||
211
+ (node.level === 'itemRef' && parseItemInstanceId(node.model.identifier).itemRefIdentifier === target);
212
+ function nodesOf(content) {
213
+ const nodes = [];
214
+ const walk = (children, ancestors) => {
215
+ for (const child of children) {
216
+ const node = { level: child.kind, model: child, start: nodes.length, end: nodes.length, ancestors };
217
+ nodes.push(node);
218
+ if (child.kind === 'section')
219
+ walk(child.content, [...ancestors, child]);
220
+ node.end = nodes.length - 1;
221
+ }
222
+ };
223
+ walk(content, []);
224
+ return nodes;
225
+ }
226
+ //# sourceMappingURL=sequencing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequencing.js","sourceRoot":"","sources":["../../src/sequencing/sequencing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAqCjE,4FAA4F;AAC5F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAkB,EAAU,EAAE,CAAC,GAAG,KAAK,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;AAEvH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAC3C,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;AAW3E,+EAA+E;AAC/E,SAAS,SAAS,CAAI,KAAU,EAAE,OAA6B;IAC7D,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IAC5E,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAUD,SAAS,OAAO,CAAC,KAAgB;IAC/B,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,MAAM,IAAI,GAAG,CAAC,IAAmB,EAAE,OAAyB,EAAE,QAAwB,EAAE,EAAE;QACxF,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;gBAAE,KAAK,CAAC,IAAI,CAAC,EAAE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IAAI,KAAK,SAAS;gBAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;YACzE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { parseItemInstanceId } from '../state/delivery-state.js';\n\nimport type {\n BranchRuleModel,\n ItemRefModel,\n SectionContent,\n SectionModel,\n TestModel,\n TestPartModel\n} from '../model/test-model.js';\nimport type { ItemInstanceId } from '../state/delivery-state.js';\n\n/**\n * Sequencing between items (QTI 3 implementation guide §4.5.3, info model §2.8.3): which item a\n * test presents next, from the test model and the order of item instances, never the live DOM.\n *\n * The rules' expressions are QTI expressions, which this package does not evaluate (roadmap 3), so\n * the caller answers each one through `evaluate`. The structure is decided here: which rules count\n * (on items and sections only in a linear part, on test parts always), in what order, and where a\n * target lands.\n */\n\nexport type SequencingLevel = 'testPart' | 'section' | 'itemRef';\n\n/** One `qti-pre-condition` or `qti-branch-rule`, by its owner and its place among the owner's rules. */\nexport interface SequencingRule {\n level: SequencingLevel;\n /** The identifier of the test part, section or item-ref (instance id) that holds the rule. */\n owner: string;\n kind: 'preCondition' | 'branchRule';\n /** Its index among the owner's rules of this kind, in document order. */\n index: number;\n}\n\n/** Answers whether a rule's expression is true now. */\nexport type EvaluateRule = (rule: SequencingRule) => boolean;\n\n/** A stable text key for a rule, `level:owner:kind:index`, as the test vectors write it. */\nexport const ruleKey = ({ level, owner, kind, index }: SequencingRule): string => `${level}:${owner}:${kind}:${index}`;\n\nexport const EXIT_SECTION = 'EXIT_SECTION';\nexport const EXIT_TESTPART = 'EXIT_TESTPART';\nexport const EXIT_TEST = 'EXIT_TEST';\nconst RESERVED_TARGETS = new Set([EXIT_SECTION, EXIT_TESTPART, EXIT_TEST]);\n\nexport interface NextItem {\n /** The item instance to present, or null when the test has no item left. */\n id: ItemInstanceId | null;\n /** The item instances passed over on the way, in order: not presented. */\n skipped: ItemInstanceId[];\n /** Branch targets ignored because selection or ordering left them nowhere ahead (§4.5.3: \"not defined\"). */\n warnings: string[];\n}\n\n/** Array.prototype.findLastIndex, which this package's ES2022 target lacks. */\nfunction lastIndex<T>(items: T[], matches: (item: T) => boolean): number {\n for (let i = items.length - 1; i >= 0; i--) if (matches(items[i])) return i;\n return -1;\n}\n\n/** One item instance in the order of the test, with the part and the sections around it. */\ninterface Step {\n part: TestPartModel;\n /** Outermost first. */\n sections: SectionModel[];\n itemRef: ItemRefModel;\n}\n\nfunction stepsOf(model: TestModel): Step[] {\n const steps: Step[] = [];\n const walk = (part: TestPartModel, content: SectionContent[], sections: SectionModel[]) => {\n for (const child of content) {\n if (child.kind === 'itemRef') steps.push({ part, sections, itemRef: child });\n else walk(part, child.content, [...sections, child]);\n }\n };\n for (const part of model.testParts) walk(part, part.sections, []);\n return steps;\n}\n\n/**\n * The item to present after `current`: branch rules first (the item's, then those of each section\n * it ends from the inside out, then the test part's when it ends the part), the first one that is\n * true wins; then pre-conditions on the target and on, skipping forward until all pass (impl. guide\n * §4.5.3 steps 2 and 3).\n *\n * @param model the test model, built from the test as rendered: after selection and ordering\n * @param current the item instance that was just presented\n */\nexport function nextItem(model: TestModel, current: ItemInstanceId, evaluate: EvaluateRule): NextItem {\n const steps = stepsOf(model);\n const index = steps.findIndex(step => step.itemRef.identifier === current);\n if (index < 0) throw new RangeError(`Item \"${current}\" is not in the test.`);\n\n const from = steps[index];\n const warnings: string[] = [];\n let start = index + 1;\n const fired = firingBranchRule(steps, index, evaluate);\n if (fired) {\n const target = branchTarget(steps, index, fired);\n if (target === undefined) {\n warnings.push(\n `qti-branch-rule target \"${fired.rule.target}\" of \"${fired.owner}\" is nowhere ahead in the test; ignored.`\n );\n } else start = target;\n }\n const skipped = steps.slice(index + 1, start).map(step => step.itemRef.identifier);\n return { ...presentable(steps, start, from, evaluate, skipped), warnings };\n}\n\n/** The first item to present: the first one whose test part, sections and own pre-conditions pass. */\nexport function firstItem(model: TestModel, evaluate: EvaluateRule): NextItem {\n return { ...presentable(stepsOf(model), 0, undefined, evaluate, []), warnings: [] };\n}\n\ninterface FiredRule {\n level: SequencingLevel;\n owner: string;\n rule: BranchRuleModel;\n section?: SectionModel;\n}\n\nfunction firingBranchRule(steps: Step[], index: number, evaluate: EvaluateRule): FiredRule | null {\n const from = steps[index];\n const next = steps[index + 1];\n const owners: Omit<FiredRule, 'rule'>[] = [];\n const rulesOf = new Map<Omit<FiredRule, 'rule'>, BranchRuleModel[]>();\n const add = (owner: Omit<FiredRule, 'rule'>, rules: BranchRuleModel[]) => {\n owners.push(owner);\n rulesOf.set(owner, rules);\n };\n\n if (from.part.navigationMode === 'linear') {\n add({ level: 'itemRef', owner: from.itemRef.identifier }, from.itemRef.branchRules);\n for (const section of [...from.sections].reverse()) {\n if (next?.sections.includes(section)) break; // not its last item, nor of any section around it\n add({ level: 'section', owner: section.identifier, section }, section.branchRules);\n }\n }\n if (!next || next.part !== from.part) add({ level: 'testPart', owner: from.part.identifier }, from.part.branchRules);\n\n for (const owner of owners) {\n const rules = rulesOf.get(owner)!;\n for (let i = 0; i < rules.length; i++) {\n if (evaluate({ level: owner.level, owner: owner.owner, kind: 'branchRule', index: i })) {\n return { ...owner, rule: rules[i] };\n }\n }\n }\n return null;\n}\n\n/** The index of the first step to consider after a branch, `steps.length` for the end, undefined when nowhere ahead. */\nfunction branchTarget(steps: Step[], index: number, fired: FiredRule): number | undefined {\n const from = steps[index];\n const after = (inside: (step: Step) => boolean) => lastIndex(steps, inside) + 1;\n const ahead = (matches: (step: Step) => boolean) => {\n const found = steps.findIndex((step, i) => i > index && matches(step));\n return found < 0 ? undefined : found;\n };\n const target = fired.rule.target;\n\n switch (target) {\n case EXIT_TEST:\n return steps.length;\n case EXIT_TESTPART:\n return after(step => step.part === from.part);\n case EXIT_SECTION: {\n const section = fired.level === 'section' ? fired.section : from.sections.at(-1);\n return section ? after(step => step.sections.includes(section)) : undefined;\n }\n }\n if (fired.level === 'testPart') {\n return ahead(step => step.part !== from.part && step.part.identifier === target);\n }\n return ahead(step => step.part === from.part && targetableIn(step, from).includes(target));\n}\n\n/**\n * What a rule of `from`'s item or sections may target in `step`: the sections it has not entered,\n * down to a section merged from a section-ref, which is a leaf (info model §7.5), and the item.\n */\nfunction targetableIn(step: Step, from: Step): string[] {\n const ids: string[] = [];\n for (const section of step.sections) {\n if (from.sections.includes(section)) continue;\n ids.push(section.identifier);\n if (section.fromSectionRef) return ids;\n }\n const { identifier } = step.itemRef;\n return [...ids, identifier, parseItemInstanceId(identifier).itemRefIdentifier];\n}\n\n/** From `start` on, the first step whose entered levels' pre-conditions all pass. */\nfunction presentable(\n steps: Step[],\n start: number,\n from: Step | undefined,\n evaluate: EvaluateRule,\n skipped: ItemInstanceId[]\n): Omit<NextItem, 'warnings'> {\n const passed = new Map<object, boolean>();\n const passes = (level: SequencingLevel, owner: TestPartModel | SectionModel | ItemRefModel) => {\n if (!passed.has(owner)) {\n let all = true;\n for (let i = 0; all && i < owner.preConditions; i++) {\n all = evaluate({ level, owner: owner.identifier, kind: 'preCondition', index: i });\n }\n passed.set(owner, all);\n }\n return passed.get(owner)!;\n };\n const skipTo = (from: number, to: number) => {\n skipped.push(...steps.slice(from, to).map(step => step.itemRef.identifier));\n return to;\n };\n\n let i = start;\n while (i < steps.length) {\n const step = steps[i];\n if ((!from || step.part !== from.part) && !passes('testPart', step.part)) {\n i = skipTo(i, lastIndex(steps, (s: Step) => s.part === step.part) + 1);\n continue;\n }\n if (step.part.navigationMode === 'linear') {\n const failed = step.sections.find(section => !from?.sections.includes(section) && !passes('section', section));\n if (failed) {\n i = skipTo(i, lastIndex(steps, (s: Step) => s.sections.includes(failed)) + 1);\n continue;\n }\n if (!passes('itemRef', step.itemRef)) {\n i = skipTo(i, i + 1);\n continue;\n }\n }\n return { id: step.itemRef.identifier, skipped };\n }\n return { id: null, skipped };\n}\n\n/** A branch target QTI forbids (info model §2.8.3.2, §7.5). */\nexport interface SequencingError {\n level: SequencingLevel;\n owner: string;\n target: string;\n reason: 'backward' | 'other-part' | 'not-a-part' | 'not-found' | 'inside-section-ref';\n}\n\ninterface Node {\n level: 'section' | 'itemRef';\n model: SectionModel | ItemRefModel;\n /** Pre-order position in its test part, and that of its last descendant. */\n start: number;\n end: number;\n ancestors: SectionModel[];\n}\n\n/**\n * The branch rules whose target QTI forbids, in the test as authored (before selection and\n * ordering): an item or section target must be ahead in the same test part and not inside a\n * section merged from a section-ref that the rule is outside of; a test part's target must be a\n * later test part. Reserved targets are always allowed.\n */\nexport function sequencingErrors(model: TestModel): SequencingError[] {\n const errors: SequencingError[] = [];\n const nodesByPart = model.testParts.map(part => nodesOf(part.sections));\n const anywhere = (target: string) =>\n model.testParts.some(part => part.identifier === target) ||\n nodesByPart.some(nodes => nodes.some(node => matches(node, target)));\n\n model.testParts.forEach((part, partIndex) => {\n for (const { target } of part.branchRules) {\n if (RESERVED_TARGETS.has(target)) continue;\n const targetIndex = model.testParts.findIndex(p => p.identifier === target);\n if (targetIndex > partIndex) continue;\n const reason = targetIndex >= 0 ? 'backward' : anywhere(target) ? 'not-a-part' : 'not-found';\n errors.push({ level: 'testPart', owner: part.identifier, target, reason });\n }\n\n const nodes = nodesByPart[partIndex];\n for (const node of nodes) {\n for (const { target } of node.model.branchRules) {\n if (RESERVED_TARGETS.has(target)) continue;\n const error = (reason: SequencingError['reason']) =>\n errors.push({ level: node.level, owner: node.model.identifier, target, reason });\n const found = nodes.find(other => matches(other, target));\n if (!found) error(anywhere(target) ? 'other-part' : 'not-found');\n else if (found.start <= node.end) error('backward');\n else if (\n found.ancestors.some(\n section => section.fromSectionRef && section !== node.model && !node.ancestors.includes(section)\n )\n ) {\n error('inside-section-ref');\n }\n }\n }\n });\n return errors;\n}\n\nconst matches = (node: Node, target: string) =>\n node.model.identifier === target ||\n (node.level === 'itemRef' && parseItemInstanceId(node.model.identifier).itemRefIdentifier === target);\n\nfunction nodesOf(content: SectionContent[]): Node[] {\n const nodes: Node[] = [];\n const walk = (children: SectionContent[], ancestors: SectionModel[]) => {\n for (const child of children) {\n const node: Node = { level: child.kind, model: child, start: nodes.length, end: nodes.length, ancestors };\n nodes.push(node);\n if (child.kind === 'section') walk(child.content, [...ancestors, child]);\n node.end = nodes.length - 1;\n }\n };\n walk(content, []);\n return nodes;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qti-components/delivery",
3
3
  "description": "The QTI 3 delivery engine: test model, item session lifecycle, sequencing and session state, with no browser globals",
4
- "version": "0.1.0-next.11",
4
+ "version": "0.1.0-next.13",
5
5
  "author": "",
6
6
  "keywords": [
7
7
  "qti",