@pie-qti/assessment-player 1.0.0-beta.4 → 1.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -7
- package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
- package/dist/components/createPlayerConnection.svelte.js +151 -0
- package/dist/components/createPlayerConnection.svelte.js.map +1 -0
- package/dist/components/displaySettings.svelte.d.ts +23 -0
- package/dist/components/displaySettings.svelte.js +40 -0
- package/dist/components/displaySettings.svelte.js.map +1 -0
- package/dist/components/srOnly.d.ts +29 -0
- package/dist/components/srOnly.js +55 -0
- package/dist/components/srOnly.js.map +1 -0
- package/dist/components/submitDialogAction.d.ts +25 -0
- package/dist/components/submitDialogAction.js +89 -0
- package/dist/components/submitDialogAction.js.map +1 -0
- package/dist/core/AssessmentPlayer.d.ts +1102 -53
- package/dist/core/AssessmentPlayer.js +2835 -460
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
- package/dist/core/AssessmentSessionCoordinator.js +185 -10
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/core/AutosaveManager.d.ts +104 -0
- package/dist/core/AutosaveManager.js +181 -0
- package/dist/core/AutosaveManager.js.map +1 -0
- package/dist/core/ItemSessionController.d.ts +17 -26
- package/dist/core/ItemSessionController.js +33 -73
- package/dist/core/ItemSessionController.js.map +1 -1
- package/dist/core/NavigationManager.d.ts +18 -50
- package/dist/core/NavigationManager.js +21 -83
- package/dist/core/NavigationManager.js.map +1 -1
- package/dist/core/TimeManager.d.ts +62 -16
- package/dist/core/TimeManager.js +148 -57
- package/dist/core/TimeManager.js.map +1 -1
- package/dist/core/autosave.d.ts +44 -0
- package/dist/core/autosave.js +46 -0
- package/dist/core/autosave.js.map +1 -0
- package/dist/core/deliveryStructure.d.ts +54 -0
- package/dist/core/deliveryStructure.js +72 -0
- package/dist/core/deliveryStructure.js.map +1 -0
- package/dist/core/errors.d.ts +116 -0
- package/dist/core/errors.js +77 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exitBoundaries.d.ts +64 -0
- package/dist/core/exitBoundaries.js +98 -0
- package/dist/core/exitBoundaries.js.map +1 -0
- package/dist/core/feedback.d.ts +46 -0
- package/dist/core/feedback.js +47 -0
- package/dist/core/feedback.js.map +1 -0
- package/dist/core/formatTime.d.ts +8 -0
- package/dist/core/formatTime.js +20 -0
- package/dist/core/formatTime.js.map +1 -0
- package/dist/core/index.d.ts +7 -4
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/navigationPolicy.d.ts +42 -0
- package/dist/core/navigationPolicy.js +62 -0
- package/dist/core/navigationPolicy.js.map +1 -0
- package/dist/core/pause.d.ts +58 -0
- package/dist/core/pause.js +101 -0
- package/dist/core/pause.js.map +1 -0
- package/dist/core/playerEvents.d.ts +51 -0
- package/dist/core/playerEvents.js +66 -0
- package/dist/core/playerEvents.js.map +1 -0
- package/dist/core/reviewState.d.ts +81 -0
- package/dist/core/reviewState.js +113 -0
- package/dist/core/reviewState.js.map +1 -0
- package/dist/core/reviewViews.d.ts +43 -0
- package/dist/core/reviewViews.js +88 -0
- package/dist/core/reviewViews.js.map +1 -0
- package/dist/core/scopeLocks.d.ts +36 -0
- package/dist/core/scopeLocks.js +78 -0
- package/dist/core/scopeLocks.js.map +1 -0
- package/dist/core/sessionRecords.d.ts +31 -0
- package/dist/core/sessionRecords.js +74 -0
- package/dist/core/sessionRecords.js.map +1 -0
- package/dist/core/submissionPolicy.d.ts +62 -0
- package/dist/core/submissionPolicy.js +67 -0
- package/dist/core/submissionPolicy.js.map +1 -0
- package/dist/core/templateDefaults.d.ts +26 -0
- package/dist/core/templateDefaults.js +53 -0
- package/dist/core/templateDefaults.js.map +1 -0
- package/dist/core/testStructure.d.ts +118 -3
- package/dist/core/testStructure.js +252 -6
- package/dist/core/testStructure.js.map +1 -1
- package/dist/core/timePolicy.d.ts +40 -0
- package/dist/core/timePolicy.js +106 -0
- package/dist/core/timePolicy.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
- package/dist/integration/ReferenceBackendAdapter.js +216 -1035
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
- package/dist/integration/api-contract.d.ts +179 -17
- package/dist/integration/api-contract.js.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +56 -5
- package/dist/integration/assessment-item-scorer.js +116 -13
- package/dist/integration/assessment-item-scorer.js.map +1 -1
- package/dist/integration/index.d.ts +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/qti-test-parser.d.ts +44 -0
- package/dist/integration/qti-test-parser.js +529 -0
- package/dist/integration/qti-test-parser.js.map +1 -0
- package/dist/integration/session-store.d.ts +54 -0
- package/dist/integration/session-store.js +75 -0
- package/dist/integration/session-store.js.map +1 -0
- package/dist/integration/test-navigation.d.ts +23 -0
- package/dist/integration/test-navigation.js +32 -0
- package/dist/integration/test-navigation.js.map +1 -0
- package/dist/integration/toSectionComposition.js +8 -1
- package/dist/integration/toSectionComposition.js.map +1 -1
- package/dist/reporting/index.d.ts +3 -0
- package/dist/reporting/index.js +3 -0
- package/dist/reporting/index.js.map +1 -0
- package/dist/reporting/inferBaseType.d.ts +13 -0
- package/dist/reporting/inferBaseType.js +26 -0
- package/dist/reporting/inferBaseType.js.map +1 -0
- package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
- package/dist/reporting/serializeAssessmentResult.js +377 -0
- package/dist/reporting/serializeAssessmentResult.js.map +1 -0
- package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
- package/dist/reporting/toAssessmentResultXml.js +304 -0
- package/dist/reporting/toAssessmentResultXml.js.map +1 -0
- package/dist/reporting/types.d.ts +85 -0
- package/dist/reporting/types.js +8 -0
- package/dist/reporting/types.js.map +1 -0
- package/dist/types/index.d.ts +96 -9
- package/dist/types/index.js.map +1 -1
- package/package.json +21 -15
- package/dist/core/StatePersistenceManager.d.ts +0 -125
- package/dist/core/StatePersistenceManager.js +0 -268
- package/dist/core/StatePersistenceManager.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -114
- package/dist/utils/PerformanceMonitor.js +0 -172
- package/dist/utils/PerformanceMonitor.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testStructure.js","sourceRoot":"","sources":["../../src/core/testStructure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,eAAe,EACf,kBAAkB,EAElB,QAAQ,EACR,gBAAgB,EAChB,QAAQ,EAER,OAAO,EACP,QAAQ,GACR,MAAM,yBAAyB,CAAC;AAcjC,gGAAgG;AAChG,MAAM,CAAC,MAAM,4BAA4B,GAAyC,MAAM,CAAC,MAAM,CAAC;IAC/F,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;CACxB,CAAC,CAAC;AAEH,MAAM,yBAAyB,GAAG,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAA4C,CAAC;AAEvH,MAAM,kBAAkB,GAAG,yFAAyF,CAAC;AAErH,0DAA0D;AAC1D,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAChD,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACxC,QAAwB,EACxB,QAAkC,EAClC,IAAmB;IAEnB,MAAM,GAAG,GAA+B,EAAE,GAAG,4BAA4B,EAAE,CAAC;IAC5E,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAA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,UAAU,qBAAqB,CAAC,aAAqB,EAAE,KAAqB,EAAE,GAAiB;IACpG,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,sBAAsB,CAAC,aAAa,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9D,OAAO,GAAG,CAAC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC;IACnD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,wDAAwD,EAAE,GAAG,CAAC,CAAC;QAC5E,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,aAAa,CAAC,KAAe;IAC5C,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACpD,CAAC","sourcesContent":["/**\n * QTI test structure shared by backends and the client: the itemSessionControl cascade, the\n * session-start draw of selection and ordering, delivery order, and test-scope expressions.\n */\n\nimport {\n\tbuildExpression,\n\tDeclarationContext,\n\ttype DeclarationMap,\n\tevalExpr,\n\tOperatorRegistry,\n\tparseXml,\n\ttype QtiValue,\n\tqtiNull,\n\tqtiValue,\n} from '@pie-qti/qti-processing';\nimport type {\n\tSecureAssessment,\n\tSecureItemRef,\n\tSecureItemSessionControl,\n\tSecureSection,\n\tSecureSectionComponent,\n\tSecureTestPart,\n\tTestOutcomeValue,\n\tTestOutcomeValues,\n} from '../integration/api-contract.js';\n\nexport type ResolvedItemSessionControl = Required<SecureItemSessionControl>;\n\n/** QTI itemSessionControl defaults, applied where no level of the cascade sets an attribute. */\nexport const DEFAULT_ITEM_SESSION_CONTROL: Readonly<ResolvedItemSessionControl> = Object.freeze({\n\tmaxAttempts: 1,\n\tshowFeedback: false,\n\tallowReview: true,\n\tshowSolution: false,\n\tallowComment: false,\n\tallowSkipping: true,\n\tvalidateResponses: false,\n});\n\nconst ITEM_SESSION_CONTROL_KEYS = Object.keys(DEFAULT_ITEM_SESSION_CONTROL) as Array<keyof ResolvedItemSessionControl>;\n\nconst ADAPTIVE_ITEM_ROOT = /<(?:[\\w-]+:)?(?:qti-assessment-item|assessmentItem)\\b[^>]*\\badaptive\\s*=\\s*[\"']true[\"']/;\n\n/** True when the item root declares `adaptive=\"true\"`. */\nexport function isAdaptiveItemXml(itemXml: string): boolean {\n\treturn ADAPTIVE_ITEM_ROOT.test(itemXml);\n}\n\n/**\n * Effective itemSessionControl for an item: the test part, each enclosing section from outer to\n * inner, then the item ref, each set attribute overriding the level above. Adaptive items allow\n * unlimited attempts whatever maxAttempts says.\n */\nexport function resolveItemSessionControl(\n\ttestPart: SecureTestPart,\n\tsections: readonly SecureSection[],\n\titem: SecureItemRef,\n): ResolvedItemSessionControl {\n\tconst out: ResolvedItemSessionControl = { ...DEFAULT_ITEM_SESSION_CONTROL };\n\tconst levels = [testPart.itemSessionControl, ...sections.map((s) => s.itemSessionControl), item.itemSessionControl];\n\tfor (const level of levels) {\n\t\tif (!level) continue;\n\t\tfor (const key of ITEM_SESSION_CONTROL_KEYS) {\n\t\t\tconst value = level[key];\n\t\t\tif (value === undefined || (typeof value === 'number' && !Number.isFinite(value))) continue;\n\t\t\t(out as Record<string, unknown>)[key] = value;\n\t\t}\n\t}\n\tif (isAdaptiveItemXml(item.itemXml)) out.maxAttempts = 0;\n\treturn out;\n}\n\n/** Direct delivery components of a section, in document order. */\nexport function sectionComponents(section: SecureSection): SecureSectionComponent[] {\n\treturn section.children\n\t\t? [...section.children]\n\t\t: [\n\t\t\t...(section.assessmentItemRefs ?? []).map((item) => ({ type: 'item' as const, item })),\n\t\t\t...(section.sections ?? []).map((child) => ({ type: 'section' as const, section: child })),\n\t\t];\n}\n\nexport interface DeliveredItem {\n\titem: SecureItemRef;\n\ttestPart: SecureTestPart;\n\t/** Enclosing sections, outermost first. */\n\tsections: SecureSection[];\n}\n\n/** Items in delivery order. Draws nothing: call it on an assessment the backend has drawn. */\nexport function deliveredItems(assessment: SecureAssessment): DeliveredItem[] {\n\tconst out: DeliveredItem[] = [];\n\tconst visit = (section: SecureSection, testPart: SecureTestPart, path: SecureSection[]): void => {\n\t\tconst sections = [...path, section];\n\t\tfor (const component of sectionComponents(section)) {\n\t\t\tif (component.type === 'item') out.push({ item: component.item, testPart, sections });\n\t\t\telse visit(component.section, testPart, sections);\n\t\t}\n\t};\n\tfor (const testPart of assessment.testParts ?? []) {\n\t\tfor (const section of testPart.sections ?? []) visit(section, testPart, []);\n\t}\n\treturn out;\n}\n\n/**\n * Draws selection and ordering for one session. Required children are always selected; selected\n * children keep source order before ordering shuffles the non-fixed ones. A child selected more\n * than once with replacement is cloned, its identifier and every descendant identifier suffixed\n * `.2`, `.3` and so on. An invisible child section with keepTogether false is mixed into its\n * parent's shuffle. The result carries no selection or ordering, so drawing it again changes\n * nothing.\n */\nexport function drawAssessment(assessment: SecureAssessment, rng: () => number): SecureAssessment {\n\tconst copy = structuredClone(assessment);\n\treturn {\n\t\t...copy,\n\t\ttestParts: copy.testParts.map((testPart) => ({\n\t\t\t...testPart,\n\t\t\tsections: testPart.sections.map((section) => drawSection(section, rng)),\n\t\t})),\n\t};\n}\n\nfunction drawSection(section: SecureSection, rng: () => number): SecureSection {\n\tlet components = sectionComponents(section);\n\tif (section.selection) components = selectComponents(section, components, rng);\n\tcomponents = components.map((component) =>\n\t\tcomponent.type === 'section' ? { type: 'section', section: drawSection(component.section, rng) } : component\n\t);\n\n\tif (section.ordering?.shuffle) {\n\t\tconst sourceOf = new Map<SecureSection, SecureSection>();\n\t\tconst expanded: SecureSectionComponent[] = [];\n\t\tfor (const component of components) {\n\t\t\tif (component.type === 'section' && !component.section.visible && component.section.keepTogether === false) {\n\t\t\t\tfor (const child of sectionComponents(component.section)) {\n\t\t\t\t\tconst fragment = withComponents({ ...component.section, fixed: isFixedSectionComponent(child) }, [child]);\n\t\t\t\t\tsourceOf.set(fragment, component.section);\n\t\t\t\t\texpanded.push({ type: 'section', section: fragment });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\texpanded.push(component);\n\t\t\t}\n\t\t}\n\t\tcomponents = mergeAdjacentFragments(shuffleSectionComponents(expanded, rng), sourceOf);\n\t}\n\n\tconst { selection: _selection, ordering: _ordering, ...rest } = section;\n\treturn withComponents(rest, components);\n}\n\nfunction selectComponents(\n\tsection: SecureSection,\n\tcomponents: SecureSectionComponent[],\n\trng: () => number,\n): SecureSectionComponent[] {\n\tconst count = Math.max(0, section.selection?.select ?? components.length);\n\tconst indexed = components.map((component, sourceIndex) => ({ component, sourceIndex }));\n\tconst required = indexed.filter(({ component }) => isRequiredSectionComponent(component));\n\tif (count < required.length) {\n\t\tthrow new Error(\n\t\t\t`Section \"${section.identifier}\" selects ${count} components but contains ${required.length} required components.`,\n\t\t);\n\t}\n\tlet chosen: typeof indexed;\n\tif (section.selection?.withReplacement === true) {\n\t\tif (indexed.length === 0 && count > 0) {\n\t\t\tthrow new Error(`Section \"${section.identifier}\" selects ${count} components but contains none.`);\n\t\t}\n\t\tconst draws = Array.from(\n\t\t\t{ length: count - required.length },\n\t\t\t() => indexed[Math.min(indexed.length - 1, Math.floor(rng() * indexed.length))]!,\n\t\t);\n\t\tchosen = [...required, ...draws];\n\t} else {\n\t\tif (count > indexed.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Section \"${section.identifier}\" selects ${count} components without replacement but only contains ${indexed.length}.`,\n\t\t\t);\n\t\t}\n\t\tconst optional = shuffleArray(indexed.filter(({ component }) => !isRequiredSectionComponent(component)), rng);\n\t\tchosen = [...required, ...optional.slice(0, count - required.length)];\n\t}\n\tconst seen = new Map<number, number>();\n\treturn chosen\n\t\t.sort((a, b) => a.sourceIndex - b.sourceIndex)\n\t\t.map(({ component, sourceIndex }) => {\n\t\t\tconst occurrence = (seen.get(sourceIndex) ?? 0) + 1;\n\t\t\tseen.set(sourceIndex, occurrence);\n\t\t\treturn occurrence === 1 ? component : renameComponent(component, `.${occurrence}`);\n\t\t});\n}\n\nfunction renameComponent(component: SecureSectionComponent, suffix: string): SecureSectionComponent {\n\tconst copy = structuredClone(component);\n\tconst renamed = new Set<object>();\n\tconst renameItem = (item: SecureItemRef): void => {\n\t\tif (renamed.has(item)) return;\n\t\trenamed.add(item);\n\t\titem.identifier += suffix;\n\t};\n\tconst renameSection = (section: SecureSection): void => {\n\t\tif (renamed.has(section)) return;\n\t\trenamed.add(section);\n\t\tsection.identifier += suffix;\n\t\tfor (const item of section.assessmentItemRefs ?? []) renameItem(item);\n\t\tfor (const child of section.sections ?? []) renameSection(child);\n\t\tfor (const child of section.children ?? []) {\n\t\t\tif (child.type === 'item') renameItem(child.item);\n\t\t\telse renameSection(child.section);\n\t\t}\n\t};\n\tif (copy.type === 'item') renameItem(copy.item);\n\telse renameSection(copy.section);\n\treturn copy;\n}\n\nfunction withComponents(section: SecureSection, components: SecureSectionComponent[]): SecureSection {\n\tconst sections = components.flatMap((c) => (c.type === 'section' ? [c.section] : []));\n\treturn {\n\t\t...section,\n\t\tchildren: components,\n\t\tassessmentItemRefs: components.flatMap((c) => (c.type === 'item' ? [c.item] : [])),\n\t\tsections: sections.length > 0 ? sections : undefined,\n\t};\n}\n\nfunction mergeAdjacentFragments(\n\tcomponents: SecureSectionComponent[],\n\tsourceOf: Map<SecureSection, SecureSection>,\n): SecureSectionComponent[] {\n\tconst out: SecureSectionComponent[] = [];\n\tfor (const component of components) {\n\t\tconst previous = out[out.length - 1];\n\t\tconst source = component.type === 'section' ? sourceOf.get(component.section) : undefined;\n\t\tif (source && previous?.type === 'section' && sourceOf.get(previous.section) === source && component.type === 'section') {\n\t\t\tconst merged = withComponents(previous.section, [\n\t\t\t\t...sectionComponents(previous.section),\n\t\t\t\t...sectionComponents(component.section),\n\t\t\t]);\n\t\t\tsourceOf.set(merged, source);\n\t\t\tout[out.length - 1] = { type: 'section', section: merged };\n\t\t} else {\n\t\t\tout.push(component);\n\t\t}\n\t}\n\treturn out;\n}\n\n/** Fisher-Yates shuffle using a provided RNG (returns a new array). */\nexport function shuffleArray<T>(arr: readonly T[], rng: () => number): T[] {\n\tconst out = [...arr];\n\tfor (let i = out.length - 1; i > 0; i--) {\n\t\tconst j = Math.floor(rng() * (i + 1));\n\t\t[out[i], out[j]] = [out[j]!, out[i]!];\n\t}\n\treturn out;\n}\n\nfunction isRequiredSectionComponent(component: SecureSectionComponent): boolean {\n\treturn component.type === 'item' ? component.item.required === true : component.section.required === true;\n}\n\nfunction isFixedSectionComponent(component: SecureSectionComponent): boolean {\n\treturn component.type === 'item' ? component.item.fixed === true : component.section.fixed === true;\n}\n\n/** Shuffle non-fixed children while retaining fixed children at their post-selection positions. */\nfunction shuffleSectionComponents(components: SecureSectionComponent[], rng: () => number): SecureSectionComponent[] {\n\tconst result = [...components];\n\tconst movableIndexes = components.flatMap((component, index) => (isFixedSectionComponent(component) ? [] : [index]));\n\tconst shuffled = shuffleArray(movableIndexes.map((index) => components[index]!), rng);\n\tfor (let index = 0; index < movableIndexes.length; index++) {\n\t\tresult[movableIndexes[index]!] = shuffled[index]!;\n\t}\n\treturn result;\n}\n\n// ---------------------------------------------------------------------------\n// Test-scope expressions\n// ---------------------------------------------------------------------------\n\n/** Canonical QTI 2.x element name for a QTI 2.x or QTI 3 (`qti-` kebab-case) element name. */\nexport function toCanonicalQtiName(name: string | null | undefined): string {\n\tconst withoutPrefix = (name ?? '').replace(/^qti-/, '');\n\treturn withoutPrefix.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase());\n}\n\n/** Reads QTI 2.x camelCase and QTI 3 `qti-` kebab-case element names alike. */\nexport const qtiElementNameMapper = {\n\tversion: 'qti2x-or-qti3',\n\ttoCanonical: (elementName: string) => toCanonicalQtiName(elementName).toLowerCase(),\n\ttoNative: (canonicalName: string) => canonicalName,\n\tisValidElementName: () => true,\n};\n\nfunction toQtiValue(baseType: string, cardinality: string, value: unknown): QtiValue {\n\tif (value === null || value === undefined) return qtiNull(baseType as never, cardinality as never);\n\treturn qtiValue(baseType as never, cardinality as never, value);\n}\n\nfunction declaration(identifier: string, value: QtiValue, defaultValue: QtiValue = value): DeclarationMap[string] {\n\treturn {\n\t\tidentifier,\n\t\tbaseType: value.baseType,\n\t\tcardinality: value.cardinality ?? 'single',\n\t\tdefaultValue,\n\t\tvalue: { ...value },\n\t};\n}\n\n/**\n * Declarations for the test's outcome variables, set to `outcomes` where given and to their\n * defaults otherwise. A numeric outcome with no declared default starts at 0.\n */\nexport function testOutcomeDeclarations(\n\tassessment: SecureAssessment,\n\toutcomes?: TestOutcomeValues | null,\n): DeclarationMap {\n\tconst decls: DeclarationMap = {};\n\tfor (const d of assessment.outcomeDeclarations ?? []) {\n\t\tconst defaultValue =\n\t\t\td.defaultValue !== undefined\n\t\t\t\t? toQtiValue(d.baseType, d.cardinality, d.defaultValue)\n\t\t\t\t: d.baseType === 'float' || d.baseType === 'integer'\n\t\t\t\t\t? qtiValue(d.baseType, 'single', 0)\n\t\t\t\t\t: qtiNull(d.baseType as never, d.cardinality as never);\n\t\tconst current = outcomes && d.identifier in outcomes\n\t\t\t? toQtiValue(d.baseType, d.cardinality, outcomes[d.identifier] as TestOutcomeValue)\n\t\t\t: defaultValue;\n\t\tdecls[d.identifier] = {\n\t\t\tidentifier: d.identifier,\n\t\t\tbaseType: d.baseType as never,\n\t\t\tcardinality: d.cardinality as never,\n\t\t\tdefaultValue,\n\t\t\tvalue: { ...current },\n\t\t};\n\t}\n\treturn decls;\n}\n\n/**\n * Adds item variables as `itemIdentifier.VARIABLE`, the form test-scope expressions use, and the\n * `unprefixed` variables under their own identifiers where the test declares no such outcome.\n */\nexport function addItemVariableDeclarations(\n\tdecls: DeclarationMap,\n\titemVariables: Record<string, Record<string, QtiValue>>,\n\tunprefixed: Record<string, QtiValue> = {},\n): DeclarationMap {\n\tfor (const [itemIdentifier, variables] of Object.entries(itemVariables)) {\n\t\tfor (const [identifier, value] of Object.entries(variables)) {\n\t\t\tconst key = `${itemIdentifier}.${identifier}`;\n\t\t\tif (!decls[key]) decls[key] = declaration(key, value);\n\t\t}\n\t}\n\tfor (const [identifier, value] of Object.entries(unprefixed)) {\n\t\tif (!decls[identifier]) decls[identifier] = declaration(identifier, value);\n\t}\n\treturn decls;\n}\n\n/** Item variables with each variableMapping's source also readable as its target identifier. */\nexport function applyVariableMappings(\n\tvariables: Record<string, QtiValue>,\n\tmappings: SecureItemRef['variableMappings'],\n): Record<string, QtiValue> {\n\tif (!mappings?.length) return variables;\n\tconst out = { ...variables };\n\tfor (const { sourceIdentifier, targetIdentifier } of mappings) {\n\t\tconst value = variables[sourceIdentifier];\n\t\tif (value) out[targetIdentifier] = value;\n\t}\n\treturn out;\n}\n\n/** Evaluates a serialized test-scope expression (QTI 2.x or 3) against `decls`. */\nexport function evaluateTestExpression(expressionXml: string, decls: DeclarationMap, rng: () => number): QtiValue {\n\tconst root = parseXml(expressionXml).documentElement;\n\tif (!root) return qtiNull();\n\tconst expr = buildExpression(root, { scope: 'test', elementNameMapper: qtiElementNameMapper });\n\treturn evalExpr({ ctx: new DeclarationContext(structuredClone(decls)), ops: new OperatorRegistry(), rng }, expr);\n}\n\n/** True only when the expression evaluates to boolean true; NULL and errors read as false. */\nexport function evaluateTestCondition(expressionXml: string, decls: DeclarationMap, rng: () => number): boolean {\n\ttry {\n\t\tconst out = evaluateTestExpression(expressionXml, decls, rng);\n\t\treturn out.kind === 'value' && out.value === true;\n\t} catch (err) {\n\t\tconsole.warn('[assessment-player] test condition failed to evaluate:', err);\n\t\treturn false;\n\t}\n}\n\n/** Plain value of a QTI value, null for NULL, in the shape item template defaults take. */\nexport function plainQtiValue(value: QtiValue): unknown {\n\treturn value.kind === 'value' ? value.value : null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"testStructure.js","sourceRoot":"","sources":["../../src/core/testStructure.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,eAAe,EACf,kBAAkB,EAElB,+BAA+B,EAC/B,QAAQ,EACR,QAAQ,EAER,OAAO,EACP,QAAQ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E,CAAC;YACxD,GAAG,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC","sourcesContent":["/**\n * QTI test structure shared by backends and the client: the itemSessionControl cascade, the\n * session-start draw of selection and ordering, delivery order, the delivery-rules walk\n * (branch rules, preconditions, eligibility), and test-scope expressions.\n */\n\nimport {\n\tbuildExpression,\n\tDeclarationContext,\n\ttype DeclarationMap,\n\tdurationSecondsFromMilliseconds,\n\tevalExpr,\n\tparseXml,\n\ttype QtiValue,\n\tqtiNull,\n\tqtiValue,\n} from '@pie-qti/qti-processing';\nimport type {\n\tSecureAssessment,\n\tSecureBranchRule,\n\tSecureItemRef,\n\tSecureItemSessionControl,\n\tSecureSection,\n\tSecureSectionComponent,\n\tSecureTestPart,\n\tTestOutcomeValue,\n\tTestOutcomeValues,\n} from '../integration/api-contract.js';\n\nexport type ResolvedItemSessionControl = Required<SecureItemSessionControl>;\n\n/** QTI itemSessionControl defaults, applied where no level of the cascade sets an attribute. */\nexport const DEFAULT_ITEM_SESSION_CONTROL: Readonly<ResolvedItemSessionControl> = Object.freeze({\n\tmaxAttempts: 1,\n\tshowFeedback: false,\n\tallowReview: true,\n\tshowSolution: false,\n\tallowComment: false,\n\tallowSkipping: true,\n\tvalidateResponses: false,\n});\n\nconst ITEM_SESSION_CONTROL_KEYS = Object.keys(DEFAULT_ITEM_SESSION_CONTROL) as Array<keyof ResolvedItemSessionControl>;\n\nconst ADAPTIVE_ITEM_ROOT = /<(?:[\\w-]+:)?(?:qti-assessment-item|assessmentItem)\\b[^>]*\\badaptive\\s*=\\s*[\"']true[\"']/;\n\n/** True when the item root declares `adaptive=\"true\"`. */\nexport function isAdaptiveItemXml(itemXml: string): boolean {\n\treturn ADAPTIVE_ITEM_ROOT.test(itemXml);\n}\n\nexport interface EndAttemptInteractionInfo {\n\t/** The response declaration the interaction is bound to. */\n\tresponseIdentifier: string;\n\t/** QTI `countAttempt` (QTI 3 `count-attempt`); true unless authored as false. */\n\tcountAttempt: boolean;\n}\n\n/**\n * The item's endAttemptInteraction bindings, read from the item XML. Assessment delivery uses this\n * to recognize an end-attempt response on the session's normal response path: activation counts the\n * attempt unless authored with countAttempt=\"false\" (a hint request).\n */\nexport function endAttemptInteractionInfo(itemXml: string): EndAttemptInteractionInfo[] {\n\tconst out: EndAttemptInteractionInfo[] = [];\n\tlet root: Element | null = null;\n\ttry {\n\t\troot = parseXml(itemXml).documentElement;\n\t} catch {\n\t\treturn out;\n\t}\n\tif (!root) return out;\n\tconst visit = (element: Element): void => {\n\t\tconst name = toCanonicalQtiName(element.localName ?? element.nodeName).toLowerCase();\n\t\tif (name === 'endattemptinteraction') {\n\t\t\tconst responseIdentifier =\n\t\t\t\telement.getAttribute('responseIdentifier') ?? element.getAttribute('response-identifier');\n\t\t\tconst raw = element.getAttribute('countAttempt') ?? element.getAttribute('count-attempt');\n\t\t\tif (responseIdentifier) {\n\t\t\t\tout.push({\n\t\t\t\t\tresponseIdentifier,\n\t\t\t\t\tcountAttempt: raw ? raw.trim().toLowerCase() !== 'false' : true,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tfor (let child = element.firstChild; child; child = child.nextSibling) {\n\t\t\tif (child.nodeType === 1) visit(child as Element);\n\t\t}\n\t};\n\tvisit(root);\n\treturn out;\n}\n\n/**\n * Effective itemSessionControl for an item: the test part, each enclosing section from outer to\n * inner, then the item ref, each set attribute overriding the level above. Adaptive items allow\n * unlimited attempts whatever maxAttempts says.\n */\nexport function resolveItemSessionControl(\n\ttestPart: SecureTestPart,\n\tsections: readonly SecureSection[],\n\titem: SecureItemRef,\n): ResolvedItemSessionControl {\n\tconst out: ResolvedItemSessionControl = { ...DEFAULT_ITEM_SESSION_CONTROL };\n\tconst levels = [testPart.itemSessionControl, ...sections.map((s) => s.itemSessionControl), item.itemSessionControl];\n\tfor (const level of levels) {\n\t\tif (!level) continue;\n\t\tfor (const key of ITEM_SESSION_CONTROL_KEYS) {\n\t\t\tconst value = level[key];\n\t\t\tif (value === undefined || (typeof value === 'number' && !Number.isFinite(value))) continue;\n\t\t\t(out as Record<string, unknown>)[key] = value;\n\t\t}\n\t}\n\tif (isAdaptiveItemXml(item.itemXml)) out.maxAttempts = 0;\n\treturn out;\n}\n\n/** Direct delivery components of a section, in document order. */\nexport function sectionComponents(section: SecureSection): SecureSectionComponent[] {\n\treturn section.children\n\t\t? [...section.children]\n\t\t: [\n\t\t\t...(section.assessmentItemRefs ?? []).map((item) => ({ type: 'item' as const, item })),\n\t\t\t...(section.sections ?? []).map((child) => ({ type: 'section' as const, section: child })),\n\t\t];\n}\n\nexport interface DeliveredItem {\n\titem: SecureItemRef;\n\ttestPart: SecureTestPart;\n\t/** Enclosing sections, outermost first. */\n\tsections: SecureSection[];\n}\n\n/** Items in delivery order. Draws nothing: call it on an assessment the backend has drawn. */\nexport function deliveredItems(assessment: SecureAssessment): DeliveredItem[] {\n\tconst out: DeliveredItem[] = [];\n\tconst visit = (section: SecureSection, testPart: SecureTestPart, path: SecureSection[]): void => {\n\t\tconst sections = [...path, section];\n\t\tfor (const component of sectionComponents(section)) {\n\t\t\tif (component.type === 'item') out.push({ item: component.item, testPart, sections });\n\t\t\telse visit(component.section, testPart, sections);\n\t\t}\n\t};\n\tfor (const testPart of assessment.testParts ?? []) {\n\t\tfor (const section of testPart.sections ?? []) visit(section, testPart, []);\n\t}\n\treturn out;\n}\n\n/**\n * Next item after `delivered[index]`. Branch rules come first: the item's, then each enclosing\n * section's it ends (inner to outer), then the test part's when it ends that too. Item and\n * section rules apply in linear navigation only. With no matching rule, navigation falls through\n * to the following item. Preconditions then skip forward from the target. EXIT_TEST means the\n * remaining items are all skipped; undefined means the current item was the last. `onError`\n * receives any condition evaluation failure (see `evaluateTestCondition`).\n */\nexport function nextItemIdentifier(\n\tdelivered: DeliveredItem[],\n\tindex: number,\n\tdecls: DeclarationMap,\n\trng: () => number,\n\tonError?: (expressionXml: string, error: unknown) => void,\n): string | undefined {\n\tconst start = branchTarget(delivered, index, decls, rng, onError) ?? index + 1;\n\tconst next = firstEligibleItem(delivered, start, delivered[index], decls, rng, onError);\n\treturn next ?? (index + 1 < delivered.length ? 'EXIT_TEST' : undefined);\n}\n\nfunction branchTarget(\n\tdelivered: DeliveredItem[],\n\tindex: number,\n\tdecls: DeclarationMap,\n\trng: () => number,\n\tonError?: (expressionXml: string, error: unknown) => void,\n): number | undefined {\n\tconst current = delivered[index]!;\n\tconst following = delivered[index + 1];\n\tconst linear = current.testPart.navigationMode === 'linear';\n\tconst holders: Array<{ rules?: SecureBranchRule[]; exitSection?: SecureSection }> = [];\n\tif (linear) {\n\t\tholders.push({ rules: current.item.branchRule, exitSection: current.sections[current.sections.length - 1] });\n\t\tfor (let level = current.sections.length - 1; level >= 0; level--) {\n\t\t\tconst section = current.sections[level]!;\n\t\t\tif (following?.sections.includes(section)) break;\n\t\t\tholders.push({ rules: section.branchRule, exitSection: current.sections[level - 1] });\n\t\t}\n\t}\n\tif (following?.testPart !== current.testPart) holders.push({ rules: current.testPart.branchRule });\n\n\tfor (const { rules, exitSection } of holders) {\n\t\tfor (const rule of rules ?? []) {\n\t\t\tif (rule.conditionXml && !evaluateTestCondition(rule.conditionXml, decls, rng, onError)) continue;\n\t\t\tconst target = resolveBranchTarget(rule.target, delivered, index, exitSection);\n\t\t\tif (target !== undefined) return target;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** The delivered-item shape literal branch-target resolution reads (`DeliveredItem` and `FlatItem` both). */\nexport type ScopedDeliveredItem = {\n\titem: { identifier: string };\n\t/** Enclosing sections, outermost first. */\n\tsections: readonly { identifier: string }[];\n\ttestPart: { identifier: string };\n};\n\n/**\n * The one literal branch-target resolver both live engines share — the reference backend's\n * `resolveBranchTarget` and the client's `exitBoundaries.branchTargetIndex` — so identical\n * branch XML cannot branch differently on the two paths. Forward-only per QTI 2.2 §5.15\n * (\"the test jumps forward … the target must refer to an item or section … that has not yet\n * been presented\"): the first delivered item strictly after `currentIndex` whose item,\n * enclosing-section, or test-part identifier matches `target`, tried in that order;\n * `undefined` when none does. A target naming an already-presented item therefore resolves\n * to nothing (the rule is skipped, delivery falls through), never backwards.\n */\nexport function firstForwardBranchTarget(\n\ttarget: string,\n\titems: readonly ScopedDeliveredItem[],\n\tcurrentIndex: number,\n): number | undefined {\n\treturn (\n\t\tfirstAfter(items, currentIndex, (item) => item.item.identifier === target) ??\n\t\tfirstAfter(items, currentIndex, (item) => item.sections.some((section) => section.identifier === target)) ??\n\t\tfirstAfter(items, currentIndex, (item) => item.testPart.identifier === target)\n\t);\n}\n\n/** The first element strictly after `from` that satisfies `match`; undefined when none does. */\nfunction firstAfter<T>(items: readonly T[], from: number, match: (item: T) => boolean): number | undefined {\n\tfor (let j = from + 1; j < items.length; j++) if (match(items[j]!)) return j;\n\treturn undefined;\n}\n\n/** Index a branch target resolves to, forward of `index`; delivered.length ends the test. */\nfunction resolveBranchTarget(\n\ttarget: string,\n\tdelivered: DeliveredItem[],\n\tindex: number,\n\texitSection: SecureSection | undefined,\n): number | undefined {\n\tconst current = delivered[index]!;\n\tswitch (target) {\n\t\tcase 'EXIT_TEST':\n\t\t\treturn delivered.length;\n\t\tcase 'EXIT_TESTPART':\n\t\t\treturn firstAfter(delivered, index, (d) => d.testPart !== current.testPart) ?? delivered.length;\n\t\tcase 'EXIT_SECTION':\n\t\t\tif (!exitSection) return undefined;\n\t\t\treturn firstAfter(delivered, index, (d) => !d.sections.includes(exitSection)) ?? delivered.length;\n\t\tdefault:\n\t\t\treturn firstForwardBranchTarget(target, delivered, index);\n\t}\n}\n\n/**\n * First item from `start` whose preconditions hold. A test part's are checked on entering it in\n * any navigation mode; a newly entered section's (outermost first) and the item's only in linear\n * navigation. A failing part or section skips everything inside it. `onError` receives any\n * condition evaluation failure (see `evaluateTestCondition`).\n */\nexport function firstEligibleItem(\n\tdelivered: DeliveredItem[],\n\tstart: number,\n\tfrom: DeliveredItem | undefined,\n\tdecls: DeclarationMap,\n\trng: () => number,\n\tonError?: (expressionXml: string, error: unknown) => void,\n): string | undefined {\n\tconst holds = (conditions: string[] | undefined): boolean =>\n\t\t(conditions ?? []).every((condition) => evaluateTestCondition(condition, decls, rng, onError));\n\tconst skipPast = (j: number, inside: (d: DeliveredItem) => boolean): number => {\n\t\tlet next = j + 1;\n\t\twhile (next < delivered.length && inside(delivered[next]!)) next++;\n\t\treturn next;\n\t};\n\tlet j = start;\n\tcandidates: while (j < delivered.length) {\n\t\tconst candidate = delivered[j]!;\n\t\tconst previous = j === start ? from : delivered[j - 1];\n\t\tif (candidate.testPart !== previous?.testPart && !holds(candidate.testPart.preConditions)) {\n\t\t\tj = skipPast(j, (d) => d.testPart === candidate.testPart);\n\t\t\tcontinue;\n\t\t}\n\t\tif (candidate.testPart.navigationMode === 'linear') {\n\t\t\tfor (const section of candidate.sections) {\n\t\t\t\tif (previous?.sections.includes(section) || holds(section.preConditions)) continue;\n\t\t\t\tj = skipPast(j, (d) => d.sections.includes(section));\n\t\t\t\tcontinue candidates;\n\t\t\t}\n\t\t\tif (!holds(candidate.item.preConditions)) {\n\t\t\t\tj++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\treturn candidate.item.identifier;\n\t}\n\treturn undefined;\n}\n\n\n/**\n * Draws selection and ordering for one session. Required children are always selected; selected\n * children keep source order before ordering shuffles the non-fixed ones. A child selected more\n * than once with replacement is cloned, its identifier and every descendant identifier suffixed\n * `.2`, `.3` and so on. An invisible child section with keepTogether false is mixed into its\n * parent's shuffle. The result carries no selection or ordering, so drawing it again changes\n * nothing.\n */\nexport function drawAssessment(assessment: SecureAssessment, rng: () => number): SecureAssessment {\n\tconst copy = structuredClone(assessment);\n\treturn {\n\t\t...copy,\n\t\ttestParts: copy.testParts.map((testPart) => ({\n\t\t\t...testPart,\n\t\t\tsections: testPart.sections.map((section) => drawSection(section, rng)),\n\t\t})),\n\t};\n}\n\nfunction drawSection(section: SecureSection, rng: () => number): SecureSection {\n\tlet components = sectionComponents(section);\n\tif (section.selection) components = selectComponents(section, components, rng);\n\tcomponents = components.map((component) =>\n\t\tcomponent.type === 'section' ? { type: 'section', section: drawSection(component.section, rng) } : component\n\t);\n\n\tif (section.ordering?.shuffle) {\n\t\tconst sourceOf = new Map<SecureSection, SecureSection>();\n\t\tconst expanded: SecureSectionComponent[] = [];\n\t\tfor (const component of components) {\n\t\t\tif (component.type === 'section' && !component.section.visible && component.section.keepTogether === false) {\n\t\t\t\tfor (const child of sectionComponents(component.section)) {\n\t\t\t\t\tconst fragment = withComponents({ ...component.section, fixed: isFixedSectionComponent(child) }, [child]);\n\t\t\t\t\tsourceOf.set(fragment, component.section);\n\t\t\t\t\texpanded.push({ type: 'section', section: fragment });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\texpanded.push(component);\n\t\t\t}\n\t\t}\n\t\tcomponents = mergeAdjacentFragments(shuffleSectionComponents(expanded, rng), sourceOf);\n\t}\n\n\tconst { selection: _selection, ordering: _ordering, ...rest } = section;\n\treturn withComponents(rest, components);\n}\n\nfunction selectComponents(\n\tsection: SecureSection,\n\tcomponents: SecureSectionComponent[],\n\trng: () => number,\n): SecureSectionComponent[] {\n\tconst count = Math.max(0, section.selection?.select ?? components.length);\n\tconst indexed = components.map((component, sourceIndex) => ({ component, sourceIndex }));\n\tconst required = indexed.filter(({ component }) => isRequiredSectionComponent(component));\n\tif (count < required.length) {\n\t\tthrow new Error(\n\t\t\t`Section \"${section.identifier}\" selects ${count} components but contains ${required.length} required components.`,\n\t\t);\n\t}\n\tlet chosen: typeof indexed;\n\tif (section.selection?.withReplacement === true) {\n\t\tif (indexed.length === 0 && count > 0) {\n\t\t\tthrow new Error(`Section \"${section.identifier}\" selects ${count} components but contains none.`);\n\t\t}\n\t\tconst draws = Array.from(\n\t\t\t{ length: count - required.length },\n\t\t\t() => indexed[Math.min(indexed.length - 1, Math.floor(rng() * indexed.length))]!,\n\t\t);\n\t\tchosen = [...required, ...draws];\n\t} else {\n\t\tif (count > indexed.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Section \"${section.identifier}\" selects ${count} components without replacement but only contains ${indexed.length}.`,\n\t\t\t);\n\t\t}\n\t\tconst optional = shuffleArray(indexed.filter(({ component }) => !isRequiredSectionComponent(component)), rng);\n\t\tchosen = [...required, ...optional.slice(0, count - required.length)];\n\t}\n\tconst seen = new Map<number, number>();\n\treturn chosen\n\t\t.sort((a, b) => a.sourceIndex - b.sourceIndex)\n\t\t.map(({ component, sourceIndex }) => {\n\t\t\tconst occurrence = (seen.get(sourceIndex) ?? 0) + 1;\n\t\t\tseen.set(sourceIndex, occurrence);\n\t\t\treturn occurrence === 1 ? component : renameComponent(component, `.${occurrence}`);\n\t\t});\n}\n\nfunction renameComponent(component: SecureSectionComponent, suffix: string): SecureSectionComponent {\n\tconst copy = structuredClone(component);\n\tconst renamed = new Set<object>();\n\tconst renameItem = (item: SecureItemRef): void => {\n\t\tif (renamed.has(item)) return;\n\t\trenamed.add(item);\n\t\titem.identifier += suffix;\n\t};\n\tconst renameSection = (section: SecureSection): void => {\n\t\tif (renamed.has(section)) return;\n\t\trenamed.add(section);\n\t\tsection.identifier += suffix;\n\t\tfor (const item of section.assessmentItemRefs ?? []) renameItem(item);\n\t\tfor (const child of section.sections ?? []) renameSection(child);\n\t\tfor (const child of section.children ?? []) {\n\t\t\tif (child.type === 'item') renameItem(child.item);\n\t\t\telse renameSection(child.section);\n\t\t}\n\t};\n\tif (copy.type === 'item') renameItem(copy.item);\n\telse renameSection(copy.section);\n\treturn copy;\n}\n\nfunction withComponents(section: SecureSection, components: SecureSectionComponent[]): SecureSection {\n\tconst sections = components.flatMap((c) => (c.type === 'section' ? [c.section] : []));\n\treturn {\n\t\t...section,\n\t\tchildren: components,\n\t\tassessmentItemRefs: components.flatMap((c) => (c.type === 'item' ? [c.item] : [])),\n\t\tsections: sections.length > 0 ? sections : undefined,\n\t};\n}\n\nfunction mergeAdjacentFragments(\n\tcomponents: SecureSectionComponent[],\n\tsourceOf: Map<SecureSection, SecureSection>,\n): SecureSectionComponent[] {\n\tconst out: SecureSectionComponent[] = [];\n\tfor (const component of components) {\n\t\tconst previous = out[out.length - 1];\n\t\tconst source = component.type === 'section' ? sourceOf.get(component.section) : undefined;\n\t\tif (source && previous?.type === 'section' && sourceOf.get(previous.section) === source && component.type === 'section') {\n\t\t\tconst merged = withComponents(previous.section, [\n\t\t\t\t...sectionComponents(previous.section),\n\t\t\t\t...sectionComponents(component.section),\n\t\t\t]);\n\t\t\tsourceOf.set(merged, source);\n\t\t\tout[out.length - 1] = { type: 'section', section: merged };\n\t\t} else {\n\t\t\tout.push(component);\n\t\t}\n\t}\n\treturn out;\n}\n\n/** Fisher-Yates shuffle using a provided RNG (returns a new array). */\nexport function shuffleArray<T>(arr: readonly T[], rng: () => number): T[] {\n\tconst out = [...arr];\n\tfor (let i = out.length - 1; i > 0; i--) {\n\t\tconst j = Math.floor(rng() * (i + 1));\n\t\t[out[i], out[j]] = [out[j]!, out[i]!];\n\t}\n\treturn out;\n}\n\nfunction isRequiredSectionComponent(component: SecureSectionComponent): boolean {\n\treturn component.type === 'item' ? component.item.required === true : component.section.required === true;\n}\n\nfunction isFixedSectionComponent(component: SecureSectionComponent): boolean {\n\treturn component.type === 'item' ? component.item.fixed === true : component.section.fixed === true;\n}\n\n/** Shuffle non-fixed children while retaining fixed children at their post-selection positions. */\nfunction shuffleSectionComponents(components: SecureSectionComponent[], rng: () => number): SecureSectionComponent[] {\n\tconst result = [...components];\n\tconst movableIndexes = components.flatMap((component, index) => (isFixedSectionComponent(component) ? [] : [index]));\n\tconst shuffled = shuffleArray(movableIndexes.map((index) => components[index]!), rng);\n\tfor (let index = 0; index < movableIndexes.length; index++) {\n\t\tresult[movableIndexes[index]!] = shuffled[index]!;\n\t}\n\treturn result;\n}\n\n// ---------------------------------------------------------------------------\n// Test-scope expressions\n// ---------------------------------------------------------------------------\n\n/** Canonical QTI 2.x element name for a QTI 2.x or QTI 3 (`qti-` kebab-case) element name. */\nexport function toCanonicalQtiName(name: string | null | undefined): string {\n\tconst withoutPrefix = (name ?? '').replace(/^qti-/, '');\n\treturn withoutPrefix.replace(/-([a-z])/g, (_, char: string) => char.toUpperCase());\n}\n\n/** Reads QTI 2.x camelCase and QTI 3 `qti-` kebab-case element names alike. */\nexport const qtiElementNameMapper = {\n\tversion: 'qti2x-or-qti3',\n\ttoCanonical: (elementName: string) => toCanonicalQtiName(elementName).toLowerCase(),\n\ttoNative: (canonicalName: string) => canonicalName,\n\tisValidElementName: () => true,\n};\n\nfunction toQtiValue(baseType: string, cardinality: string, value: unknown): QtiValue {\n\tif (value === null || value === undefined) return qtiNull(baseType as never, cardinality as never);\n\treturn qtiValue(baseType as never, cardinality as never, value);\n}\n\nfunction declaration(identifier: string, value: QtiValue, defaultValue: QtiValue = value): DeclarationMap[string] {\n\treturn {\n\t\tidentifier,\n\t\tbaseType: value.baseType,\n\t\tcardinality: value.cardinality ?? 'single',\n\t\tdefaultValue,\n\t\tvalue: { ...value },\n\t};\n}\n\n/**\n * Declarations for the test's outcome variables, set to `outcomes` where given and to their\n * defaults otherwise. A numeric outcome with no declared default starts at 0.\n */\nexport function testOutcomeDeclarations(\n\tassessment: SecureAssessment,\n\toutcomes?: TestOutcomeValues | null,\n): DeclarationMap {\n\tconst decls: DeclarationMap = {};\n\tfor (const d of assessment.outcomeDeclarations ?? []) {\n\t\tconst defaultValue =\n\t\t\td.defaultValue !== undefined\n\t\t\t\t? toQtiValue(d.baseType, d.cardinality, d.defaultValue)\n\t\t\t\t: d.baseType === 'float' || d.baseType === 'integer'\n\t\t\t\t\t? qtiValue(d.baseType, 'single', 0)\n\t\t\t\t\t: qtiNull(d.baseType as never, d.cardinality as never);\n\t\tconst current = outcomes && d.identifier in outcomes\n\t\t\t? toQtiValue(d.baseType, d.cardinality, outcomes[d.identifier] as TestOutcomeValue)\n\t\t\t: defaultValue;\n\t\tdecls[d.identifier] = {\n\t\t\tidentifier: d.identifier,\n\t\t\tbaseType: d.baseType as never,\n\t\t\tcardinality: d.cardinality as never,\n\t\t\tdefaultValue,\n\t\t\tvalue: { ...current },\n\t\t};\n\t}\n\treturn decls;\n}\n\n/**\n * Adds item variables as `itemIdentifier.VARIABLE`, the form test-scope expressions use, and the\n * `unprefixed` variables under their own identifiers where the test declares no such outcome.\n */\nexport function addItemVariableDeclarations(\n\tdecls: DeclarationMap,\n\titemVariables: Record<string, Record<string, QtiValue>>,\n\tunprefixed: Record<string, QtiValue> = {},\n): DeclarationMap {\n\tfor (const [itemIdentifier, variables] of Object.entries(itemVariables)) {\n\t\tfor (const [identifier, value] of Object.entries(variables)) {\n\t\t\tconst key = `${itemIdentifier}.${identifier}`;\n\t\t\tif (!decls[key]) decls[key] = declaration(key, value);\n\t\t}\n\t}\n\tfor (const [identifier, value] of Object.entries(unprefixed)) {\n\t\tif (!decls[identifier]) decls[identifier] = declaration(identifier, value);\n\t}\n\treturn decls;\n}\n\n/** Millisecond scope clocks the timing state carries; absent clocks read as 0 seconds. */\nexport interface ScopeTiming {\n\t/** Total assessment elapsed time (ms). */\n\ttotalTime?: number;\n\t/** Elapsed time per testPart identifier (ms). */\n\ttestPartTimes?: Record<string, number>;\n\t/** Elapsed time per section identifier (ms). */\n\tsectionTimes?: Record<string, number>;\n}\n\n/**\n * Adds the QTI built-in duration variables test-scope expressions read: `duration` for the whole\n * test, `TESTPART_ID.duration` and `SECTION_ID.duration` for each delivered part and section.\n * QTI durations are seconds; the timing state keeps milliseconds, so the values are converted.\n * Authored identifiers win: an existing declaration is never replaced.\n */\nexport function addScopeDurationDeclarations(\n\tdecls: DeclarationMap,\n\tassessment: SecureAssessment,\n\ttiming: ScopeTiming | undefined,\n): DeclarationMap {\n\tconst durationSeconds = (ms: number | undefined): number =>\n\t\tdurationSecondsFromMilliseconds(Number(ms) || 0);\n\tconst putDuration = (identifier: string, seconds: number): void => {\n\t\tif (!decls[identifier]) decls[identifier] = declaration(identifier, qtiValue('duration', 'single', seconds));\n\t};\n\tputDuration('duration', durationSeconds(timing?.totalTime));\n\tconst visitSections = (sections: readonly SecureSection[]): void => {\n\t\tfor (const section of sections) {\n\t\t\tputDuration(`${section.identifier}.duration`, durationSeconds(timing?.sectionTimes?.[section.identifier]));\n\t\t\tvisitSections(section.sections ?? []);\n\t\t}\n\t};\n\tfor (const testPart of assessment.testParts ?? []) {\n\t\tputDuration(`${testPart.identifier}.duration`, durationSeconds(timing?.testPartTimes?.[testPart.identifier]));\n\t\tvisitSections(testPart.sections ?? []);\n\t}\n\treturn decls;\n}\n\n/** Item variables with each variableMapping's source also readable as its target identifier. */\nexport function applyVariableMappings(\n\tvariables: Record<string, QtiValue>,\n\tmappings: SecureItemRef['variableMappings'],\n): Record<string, QtiValue> {\n\tif (!mappings?.length) return variables;\n\tconst out = { ...variables };\n\tfor (const { sourceIdentifier, targetIdentifier } of mappings) {\n\t\tconst value = variables[sourceIdentifier];\n\t\tif (value) out[targetIdentifier] = value;\n\t}\n\treturn out;\n}\n\n/** Evaluates a serialized test-scope expression (QTI 2.x or 3) against `decls`. */\nexport function evaluateTestExpression(expressionXml: string, decls: DeclarationMap, rng: () => number): QtiValue {\n\tconst root = parseXml(expressionXml).documentElement;\n\tif (!root) return qtiNull();\n\tconst expr = buildExpression(root, { scope: 'test', elementNameMapper: qtiElementNameMapper });\n\treturn evalExpr({ ctx: new DeclarationContext(structuredClone(decls)), rng }, expr);\n}\n\n/**\n * True only when the expression evaluates to boolean true; NULL reads as false (QTI:\n * a NULL condition result is false).\n *\n * An evaluation ERROR also reads as false, but unlike a NULL it is reported: delivery\n * proceeds on the default path (a broken branchRule or preCondition must never abort a\n * candidate's test), yet the failure is never indistinguishable from an authored false.\n * Callers that own an error surface pass `onError` — the AssessmentPlayer reports a\n * coded `testConditionFailed` through `config.onError` — and without one the failure\n * stays a console warning (the reference backend's own evaluation).\n *\n * Documented divergence from the strict spec reading: QTI 2.1/3.0 leave undefined how\n * delivery proceeds when a condition expression cannot be evaluated; reading it as\n * false keeps delivery on the default path and reporting keeps it observable.\n */\nexport function evaluateTestCondition(\n\texpressionXml: string,\n\tdecls: DeclarationMap,\n\trng: () => number,\n\tonError?: (expressionXml: string, error: unknown) => void,\n): boolean {\n\ttry {\n\t\tconst out = evaluateTestExpression(expressionXml, decls, rng);\n\t\treturn out.kind === 'value' && out.value === true;\n\t} catch (err) {\n\t\tif (onError) onError(expressionXml, err);\n\t\telse console.warn('[assessment-player] test condition failed to evaluate:', err);\n\t\treturn false;\n\t}\n}\n\n/** Plain value of a QTI value, null for NULL, in the shape item template defaults take. */\nexport function plainQtiValue(value: QtiValue): unknown {\n\treturn value.kind === 'value' ? value.value : null;\n}\n\n/** A serialized item-session variable, as `SerializedItemSessionState` carries it. */\ninterface SerializedVariableShape {\n\tbaseType?: string;\n\tcardinality: string;\n\tvalue: unknown;\n}\n\n/**\n * The QTI values of a serialized item session's response, outcome and template\n * variables (NULL where unset), keyed by variable identifier — the item's variables a\n * test-scope expression reads as `ITEM.VARIABLE`.\n */\nexport function itemSessionVariableValues(session: {\n\tresponseVariables?: Record<string, SerializedVariableShape>;\n\toutcomeVariables?: Record<string, SerializedVariableShape>;\n\ttemplateVariables?: Record<string, SerializedVariableShape>;\n}): Record<string, QtiValue> {\n\tconst out: Record<string, QtiValue> = {};\n\tfor (const group of [session.responseVariables, session.outcomeVariables, session.templateVariables]) {\n\t\tfor (const [identifier, variable] of Object.entries(group ?? {})) {\n\t\t\tout[identifier] = toQtiValue(variable.baseType as string, variable.cardinality, variable.value);\n\t\t}\n\t}\n\treturn out;\n}\n\n/**\n * An item's variables as test-level branch rules and preconditions read them (`ITEM.VARIABLE`),\n * in the shape the reference backend records after a counted submission (its item test state):\n * the session's context (numAttempts, duration, completionStatus), template, outcome and response\n * variables, with `scoredOutcomes` — the backend's scored outcome values, authoritative where the\n * delivered item carries no response processing — over them, typed by the session's own\n * declarations (a value without one is read as the reference backend reads a bare score: a\n * number as float, anything else as string). Record outcomes keep the session's value.\n */\nexport function recordedItemVariableValues(\n\tsession:\n\t\t| {\n\t\t\t\tcontextVariables?: Record<string, SerializedVariableShape>;\n\t\t\t\tresponseVariables?: Record<string, SerializedVariableShape>;\n\t\t\t\toutcomeVariables?: Record<string, SerializedVariableShape>;\n\t\t\t\ttemplateVariables?: Record<string, SerializedVariableShape>;\n\t\t }\n\t\t| undefined,\n\tscoredOutcomes: Record<string, unknown> | undefined,\n): Record<string, QtiValue> {\n\tconst out: Record<string, QtiValue> = {};\n\tfor (const group of [\n\t\tsession?.contextVariables,\n\t\tsession?.templateVariables,\n\t\tsession?.outcomeVariables,\n\t\tsession?.responseVariables,\n\t]) {\n\t\tfor (const [identifier, variable] of Object.entries(group ?? {})) {\n\t\t\tout[identifier] = toQtiValue(variable.baseType as string, variable.cardinality, variable.value);\n\t\t}\n\t}\n\tfor (const [identifier, value] of Object.entries(scoredOutcomes ?? {})) {\n\t\tconst declared = out[identifier];\n\t\tif (value === undefined || declared?.cardinality === 'record') continue;\n\t\tif (declared?.baseType) {\n\t\t\tout[identifier] = toQtiValue(declared.baseType, declared.cardinality ?? 'single', value);\n\t\t} else if (typeof value === 'number') {\n\t\t\tout[identifier] = qtiValue('float', 'single', value);\n\t\t} else if (value !== null && typeof value !== 'object') {\n\t\t\tout[identifier] = qtiValue('string', 'single', String(value));\n\t\t}\n\t}\n\treturn out;\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time policy: effective limits for an item across its scope chain, the submit
|
|
3
|
+
* timing evidence a backend receives, and the minimum-time gate.
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions
|
|
6
|
+
* and queries over explicit inputs — the orchestrator resolves the scope chain,
|
|
7
|
+
* the PNP extended time and the TimeManager's elapsed readings and passes them in.
|
|
8
|
+
* None of this takes the transition lock.
|
|
9
|
+
*/
|
|
10
|
+
import type { SubmitTimingEvidence } from '../integration/api-contract.js';
|
|
11
|
+
import type { TimeLimits } from '../types/index.js';
|
|
12
|
+
import type { FlatItem } from './deliveryStructure.js';
|
|
13
|
+
import type { ExtendedTime } from './TimeManager.js';
|
|
14
|
+
export interface EffectiveItemTimeLimits {
|
|
15
|
+
timeLimits?: TimeLimits;
|
|
16
|
+
source?: 'item' | 'section' | 'testPart' | 'assessment';
|
|
17
|
+
/**
|
|
18
|
+
* Identifier of the scope that supplied the binding maximum (the section among the
|
|
19
|
+
* enclosing chain when a section limit binds; undefined for the assessment scope).
|
|
20
|
+
*/
|
|
21
|
+
scopeIdentifier?: string;
|
|
22
|
+
}
|
|
23
|
+
/** The nearest binding limits across the item's scopes (assessment → part → sections → item). */
|
|
24
|
+
export declare function effectiveItemTimeLimits(flat: FlatItem, assessmentTimeLimits: TimeLimits | undefined, extendedTime: ExtendedTime | undefined): EffectiveItemTimeLimits;
|
|
25
|
+
/** The submit timing evidence for one item submission, from its effective limits and clock readings. */
|
|
26
|
+
export declare function submitTimingEvidence(options: {
|
|
27
|
+
q: FlatItem;
|
|
28
|
+
effective: EffectiveItemTimeLimits;
|
|
29
|
+
/** Wall-clock fallback elapsed for the item (the serialized session duration). */
|
|
30
|
+
elapsedMs: number;
|
|
31
|
+
/** The TimeManager's per-scope elapsed reading; undefined when there is none. */
|
|
32
|
+
scopeElapsedMs: (scope: 'assessment' | 'testPart' | 'section' | 'item', identifier?: string) => number | undefined;
|
|
33
|
+
/** The PNP-extended whole-test maximum in seconds; undefined when the test has none. */
|
|
34
|
+
assessmentLimitSeconds: number | undefined;
|
|
35
|
+
/** The TimeManager's whole-test elapsed reading; undefined when there is none. */
|
|
36
|
+
assessmentElapsedMs: number | undefined;
|
|
37
|
+
submissionReason?: SubmitTimingEvidence['submissionReason'];
|
|
38
|
+
}): SubmitTimingEvidence | undefined;
|
|
39
|
+
/** The minimum-time gate: a coded refusal while the scope's minimum has not elapsed. */
|
|
40
|
+
export declare function assertMinTimeElapsed(scope: 'assessment' | 'testPart' | 'section' | 'item', limits: TimeLimits | undefined, elapsedMs: number): void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time policy: effective limits for an item across its scope chain, the submit
|
|
3
|
+
* timing evidence a backend receives, and the minimum-time gate.
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions
|
|
6
|
+
* and queries over explicit inputs — the orchestrator resolves the scope chain,
|
|
7
|
+
* the PNP extended time and the TimeManager's elapsed readings and passes them in.
|
|
8
|
+
* None of this takes the transition lock.
|
|
9
|
+
*/
|
|
10
|
+
import { extendTimeLimit } from './TimeManager.js';
|
|
11
|
+
import { AssessmentPlayerError } from './errors.js';
|
|
12
|
+
/** The nearest binding limits across the item's scopes (assessment → part → sections → item). */
|
|
13
|
+
export function effectiveItemTimeLimits(flat, assessmentTimeLimits, extendedTime) {
|
|
14
|
+
const scopes = [
|
|
15
|
+
{ source: 'assessment', limits: assessmentTimeLimits },
|
|
16
|
+
{ source: 'testPart', identifier: flat.testPart.identifier, limits: flat.testPart.timeLimits },
|
|
17
|
+
// Every enclosing section limits the item, not only the innermost one.
|
|
18
|
+
...flat.sections.map((section) => ({
|
|
19
|
+
source: 'section',
|
|
20
|
+
identifier: section.identifier,
|
|
21
|
+
limits: section.timeLimits,
|
|
22
|
+
})),
|
|
23
|
+
{ source: 'item', identifier: flat.identifier, limits: flat.item.timeLimits },
|
|
24
|
+
];
|
|
25
|
+
let source;
|
|
26
|
+
let scopeIdentifier;
|
|
27
|
+
let minTime;
|
|
28
|
+
let maxTime;
|
|
29
|
+
let allowLateSubmission;
|
|
30
|
+
for (const scope of scopes) {
|
|
31
|
+
if (!scope.limits)
|
|
32
|
+
continue;
|
|
33
|
+
if (scope.limits.minTime !== undefined) {
|
|
34
|
+
minTime = minTime === undefined ? scope.limits.minTime : Math.max(minTime, scope.limits.minTime);
|
|
35
|
+
}
|
|
36
|
+
if (scope.limits.maxTime !== undefined) {
|
|
37
|
+
const scopedMaxTime = extendTimeLimit(scope.limits.maxTime, extendedTime);
|
|
38
|
+
if (scopedMaxTime !== undefined && (maxTime === undefined || scopedMaxTime < maxTime)) {
|
|
39
|
+
maxTime = scopedMaxTime;
|
|
40
|
+
source = scope.source;
|
|
41
|
+
scopeIdentifier = scope.identifier;
|
|
42
|
+
allowLateSubmission = scope.limits.allowLateSubmission;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (scope.limits.allowLateSubmission !== undefined && maxTime === undefined) {
|
|
46
|
+
allowLateSubmission = scope.limits.allowLateSubmission;
|
|
47
|
+
source = scope.source;
|
|
48
|
+
scopeIdentifier = scope.identifier;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (maxTime === undefined && minTime === undefined && allowLateSubmission === undefined) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
return { source, scopeIdentifier, timeLimits: { minTime, maxTime, allowLateSubmission } };
|
|
55
|
+
}
|
|
56
|
+
/** The submit timing evidence for one item submission, from its effective limits and clock readings. */
|
|
57
|
+
export function submitTimingEvidence(options) {
|
|
58
|
+
const { q, effective, elapsedMs, scopeElapsedMs, assessmentLimitSeconds, assessmentElapsedMs, submissionReason } = options;
|
|
59
|
+
const limitSeconds = effective.timeLimits?.maxTime;
|
|
60
|
+
if (!effective.source || limitSeconds === undefined) {
|
|
61
|
+
// An administrative collection (a proctor's forced end) reports its reason even
|
|
62
|
+
// when nothing is timed.
|
|
63
|
+
return submissionReason
|
|
64
|
+
? {
|
|
65
|
+
scope: 'assessment',
|
|
66
|
+
elapsedMs: scopeElapsedMs('assessment') ?? elapsedMs,
|
|
67
|
+
submissionReason,
|
|
68
|
+
}
|
|
69
|
+
: undefined;
|
|
70
|
+
}
|
|
71
|
+
const scopeIdentifier = effective.source === 'assessment'
|
|
72
|
+
? undefined
|
|
73
|
+
: (effective.scopeIdentifier ??
|
|
74
|
+
(effective.source === 'item'
|
|
75
|
+
? q.identifier
|
|
76
|
+
: effective.source === 'section'
|
|
77
|
+
? q.section.identifier
|
|
78
|
+
: q.testPart.identifier));
|
|
79
|
+
const scopedElapsedMs = scopeElapsedMs(effective.source, scopeIdentifier) ?? elapsedMs;
|
|
80
|
+
return {
|
|
81
|
+
scope: effective.source,
|
|
82
|
+
elapsedMs: scopedElapsedMs,
|
|
83
|
+
limitSeconds,
|
|
84
|
+
expired: scopedElapsedMs >= limitSeconds * 1000,
|
|
85
|
+
allowLateSubmission: effective.timeLimits?.allowLateSubmission,
|
|
86
|
+
// The candidate's own test clock: it excludes begin-gate and proctor-pause time,
|
|
87
|
+
// which a backend wall clock measured from session creation would count.
|
|
88
|
+
...(assessmentLimitSeconds !== undefined && assessmentElapsedMs !== undefined
|
|
89
|
+
? {
|
|
90
|
+
assessmentElapsedMs,
|
|
91
|
+
assessmentLimitSeconds,
|
|
92
|
+
}
|
|
93
|
+
: {}),
|
|
94
|
+
...(submissionReason ? { submissionReason } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** The minimum-time gate: a coded refusal while the scope's minimum has not elapsed. */
|
|
98
|
+
export function assertMinTimeElapsed(scope, limits, elapsedMs) {
|
|
99
|
+
if (limits?.minTime === undefined)
|
|
100
|
+
return;
|
|
101
|
+
if (elapsedMs < limits.minTime * 1000) {
|
|
102
|
+
const remaining = Math.ceil(limits.minTime - elapsedMs / 1000);
|
|
103
|
+
throw new AssessmentPlayerError('minTimeNotElapsed', `The ${scope} minimum time has not elapsed (${remaining}s remaining).`, { scope, remaining });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=timePolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timePolicy.js","sourceRoot":"","sources":["../../src/core/timePolicy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,a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AK,SAAS;QAAE,OAAO;IAC1C,IAAI,SAAS,GAAG,MAAM,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;QAC/D,MAAM,IAAI,qBAAqB,CAC9B,mBAAmB,EACnB,OAAO,KAAK,kCAAkC,SAAS,eAAe,EACtE,EAAE,KAAK,EAAE,SAAS,EAAE,CACpB,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["/**\n * Time policy: effective limits for an item across its scope chain, the submit\n * timing evidence a backend receives, and the minimum-time gate.\n *\n * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions\n * and queries over explicit inputs — the orchestrator resolves the scope chain,\n * the PNP extended time and the TimeManager's elapsed readings and passes them in.\n * None of this takes the transition lock.\n */\n\nimport type { SubmitTimingEvidence } from '../integration/api-contract.js';\nimport type { TimeLimits } from '../types/index.js';\nimport type { FlatItem } from './deliveryStructure.js';\nimport type { ExtendedTime } from './TimeManager.js';\nimport { extendTimeLimit } from './TimeManager.js';\nimport { AssessmentPlayerError } from './errors.js';\n\nexport interface EffectiveItemTimeLimits {\n\ttimeLimits?: TimeLimits;\n\tsource?: 'item' | 'section' | 'testPart' | 'assessment';\n\t/**\n\t * Identifier of the scope that supplied the binding maximum (the section among the\n\t * enclosing chain when a section limit binds; undefined for the assessment scope).\n\t */\n\tscopeIdentifier?: string;\n}\n\n/** The nearest binding limits across the item's scopes (assessment → part → sections → item). */\nexport function effectiveItemTimeLimits(\n\tflat: FlatItem,\n\tassessmentTimeLimits: TimeLimits | undefined,\n\textendedTime: ExtendedTime | undefined,\n): EffectiveItemTimeLimits {\n\tconst scopes: Array<{\n\t\tsource: EffectiveItemTimeLimits['source'];\n\t\tidentifier?: string;\n\t\tlimits?: TimeLimits;\n\t}> = [\n\t\t{ source: 'assessment', limits: assessmentTimeLimits },\n\t\t{ source: 'testPart', identifier: flat.testPart.identifier, limits: flat.testPart.timeLimits },\n\t\t// Every enclosing section limits the item, not only the innermost one.\n\t\t...flat.sections.map((section) => ({\n\t\t\tsource: 'section' as const,\n\t\t\tidentifier: section.identifier,\n\t\t\tlimits: section.timeLimits,\n\t\t})),\n\t\t{ source: 'item', identifier: flat.identifier, limits: flat.item.timeLimits },\n\t];\n\tlet source: EffectiveItemTimeLimits['source'];\n\tlet scopeIdentifier: string | undefined;\n\tlet minTime: number | undefined;\n\tlet maxTime: number | undefined;\n\tlet allowLateSubmission: boolean | undefined;\n\tfor (const scope of scopes) {\n\t\tif (!scope.limits) continue;\n\t\tif (scope.limits.minTime !== undefined) {\n\t\t\tminTime = minTime === undefined ? scope.limits.minTime : Math.max(minTime, scope.limits.minTime);\n\t\t}\n\t\tif (scope.limits.maxTime !== undefined) {\n\t\t\tconst scopedMaxTime = extendTimeLimit(scope.limits.maxTime, extendedTime);\n\t\t\tif (scopedMaxTime !== undefined && (maxTime === undefined || scopedMaxTime < maxTime)) {\n\t\t\t\tmaxTime = scopedMaxTime;\n\t\t\t\tsource = scope.source;\n\t\t\t\tscopeIdentifier = scope.identifier;\n\t\t\t\tallowLateSubmission = scope.limits.allowLateSubmission;\n\t\t\t}\n\t\t} else if (scope.limits.allowLateSubmission !== undefined && maxTime === undefined) {\n\t\t\tallowLateSubmission = scope.limits.allowLateSubmission;\n\t\t\tsource = scope.source;\n\t\t\tscopeIdentifier = scope.identifier;\n\t\t}\n\t}\n\n\tif (maxTime === undefined && minTime === undefined && allowLateSubmission === undefined) {\n\t\treturn {};\n\t}\n\treturn { source, scopeIdentifier, timeLimits: { minTime, maxTime, allowLateSubmission } };\n}\n\n/** The submit timing evidence for one item submission, from its effective limits and clock readings. */\nexport function submitTimingEvidence(options: {\n\tq: FlatItem;\n\teffective: EffectiveItemTimeLimits;\n\t/** Wall-clock fallback elapsed for the item (the serialized session duration). */\n\telapsedMs: number;\n\t/** The TimeManager's per-scope elapsed reading; undefined when there is none. */\n\tscopeElapsedMs: (scope: 'assessment' | 'testPart' | 'section' | 'item', identifier?: string) => number | undefined;\n\t/** The PNP-extended whole-test maximum in seconds; undefined when the test has none. */\n\tassessmentLimitSeconds: number | undefined;\n\t/** The TimeManager's whole-test elapsed reading; undefined when there is none. */\n\tassessmentElapsedMs: number | undefined;\n\tsubmissionReason?: SubmitTimingEvidence['submissionReason'];\n}): SubmitTimingEvidence | undefined {\n\tconst { q, effective, elapsedMs, scopeElapsedMs, assessmentLimitSeconds, assessmentElapsedMs, submissionReason } =\n\t\toptions;\n\tconst limitSeconds = effective.timeLimits?.maxTime;\n\tif (!effective.source || limitSeconds === undefined) {\n\t\t// An administrative collection (a proctor's forced end) reports its reason even\n\t\t// when nothing is timed.\n\t\treturn submissionReason\n\t\t\t? {\n\t\t\t\t\tscope: 'assessment',\n\t\t\t\t\telapsedMs: scopeElapsedMs('assessment') ?? elapsedMs,\n\t\t\t\t\tsubmissionReason,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n\tconst scopeIdentifier = effective.source === 'assessment'\n\t\t? undefined\n\t\t: (effective.scopeIdentifier ??\n\t\t\t(effective.source === 'item'\n\t\t\t\t? q.identifier\n\t\t\t\t: effective.source === 'section'\n\t\t\t\t\t? q.section.identifier\n\t\t\t\t\t: q.testPart.identifier));\n\tconst scopedElapsedMs = scopeElapsedMs(effective.source, scopeIdentifier) ?? elapsedMs;\n\treturn {\n\t\tscope: effective.source,\n\t\telapsedMs: scopedElapsedMs,\n\t\tlimitSeconds,\n\t\texpired: scopedElapsedMs >= limitSeconds * 1000,\n\t\tallowLateSubmission: effective.timeLimits?.allowLateSubmission,\n\t\t// The candidate's own test clock: it excludes begin-gate and proctor-pause time,\n\t\t// which a backend wall clock measured from session creation would count.\n\t\t...(assessmentLimitSeconds !== undefined && assessmentElapsedMs !== undefined\n\t\t\t? {\n\t\t\t\t\tassessmentElapsedMs,\n\t\t\t\t\tassessmentLimitSeconds,\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(submissionReason ? { submissionReason } : {}),\n\t};\n}\n\n/** The minimum-time gate: a coded refusal while the scope's minimum has not elapsed. */\nexport function assertMinTimeElapsed(\n\tscope: 'assessment' | 'testPart' | 'section' | 'item',\n\tlimits: TimeLimits | undefined,\n\telapsedMs: number,\n): void {\n\tif (limits?.minTime === undefined) return;\n\tif (elapsedMs < limits.minTime * 1000) {\n\t\tconst remaining = Math.ceil(limits.minTime - elapsedMs / 1000);\n\t\tthrow new AssessmentPlayerError(\n\t\t\t'minTimeNotElapsed',\n\t\t\t`The ${scope} minimum time has not elapsed (${remaining}s remaining).`,\n\t\t\t{ scope, remaining },\n\t\t);\n\t}\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export type { BackendAssessmentPlayerConfig } from './core/AssessmentPlayer.js';
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
1
|
+
export type { BackendAssessmentPlayerConfig, EffectiveItemTimeLimits, AssessmentEndReason, AssessmentFinalizedEvent, AssessmentStartInfo, AssessmentTimeExpiryEvent, AssessmentTimeState, ScopeTimeExpiryEvent, SubmissionBlocker, } from './core/AssessmentPlayer.js';
|
|
2
|
+
export type { ForwardTransitionInfo, ItemAnswerStatus, ReviewItemView } from './core/index.js';
|
|
3
|
+
export type { AutosaveState, AutosaveStatus } from './core/index.js';
|
|
4
|
+
export { AssessmentPlayer } from './core/index.js';
|
|
5
|
+
export { AssessmentPlayerError, assessmentErrorDisplay, isAssessmentPlayerError, type AssessmentErrorDisplay, type AssessmentPlayerErrorCode, type AssessmentPlayerErrorParams, } from './core/errors.js';
|
|
4
6
|
export { toCanonicalQtiName } from './core/testStructure.js';
|
|
5
7
|
export * from './integration/index.js';
|
|
6
|
-
export
|
|
8
|
+
export * from './reporting/index.js';
|
|
9
|
+
export type { AssessmentResults, CandidateSectionView, CheckAnswerState, ItemFeedbackEntry, ItemFeedbackView, ItemResult, NavigationState, QTIRole, ResultsSummary, VisibleTestFeedback, } from './types/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// Core classes
|
|
2
|
-
export { AssessmentPlayer
|
|
2
|
+
export { AssessmentPlayer } from './core/index.js';
|
|
3
|
+
// Coded errors thrown by the core; shells localize them via `assessment.errors.codes.*`.
|
|
4
|
+
export { AssessmentPlayerError, assessmentErrorDisplay, isAssessmentPlayerError, } from './core/errors.js';
|
|
3
5
|
// Shared QTI XML scan primitives used by the adapter and the element discovery parser.
|
|
4
6
|
export { toCanonicalQtiName } from './core/testStructure.js';
|
|
5
7
|
// Backend integration API + reference adapter
|
|
6
8
|
export * from './integration/index.js';
|
|
9
|
+
// QTI Results Reporting (assessmentResult) output
|
|
10
|
+
export * from './reporting/index.js';
|
|
7
11
|
//# 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,eAAe;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAgBf,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,yFAAyF;AACzF,OAAO,EACN,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,GAIvB,MAAM,kBAAkB,CAAC;AAC1B,uFAAuF;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,8CAA8C;AAC9C,cAAc,wBAAwB,CAAC;AACvC,kDAAkD;AAClD,cAAc,sBAAsB,CAAC","sourcesContent":["// Core classes\n\nexport type {\n\tBackendAssessmentPlayerConfig,\n\tEffectiveItemTimeLimits,\n\tAssessmentEndReason,\n\tAssessmentFinalizedEvent,\n\tAssessmentStartInfo,\n\tAssessmentTimeExpiryEvent,\n\tAssessmentTimeState,\n\tScopeTimeExpiryEvent,\n\tSubmissionBlocker,\n} from './core/AssessmentPlayer.js';\nexport type { ForwardTransitionInfo, ItemAnswerStatus, ReviewItemView } from './core/index.js';\n// Autosave: debounced draft persistence through BackendAdapter.saveState.\nexport type { AutosaveState, AutosaveStatus } from './core/index.js';\nexport { AssessmentPlayer } from './core/index.js';\n// Coded errors thrown by the core; shells localize them via `assessment.errors.codes.*`.\nexport {\n\tAssessmentPlayerError,\n\tassessmentErrorDisplay,\n\tisAssessmentPlayerError,\n\ttype AssessmentErrorDisplay,\n\ttype AssessmentPlayerErrorCode,\n\ttype AssessmentPlayerErrorParams,\n} from './core/errors.js';\n// Shared QTI XML scan primitives used by the adapter and the element discovery parser.\nexport { toCanonicalQtiName } from './core/testStructure.js';\n// Backend integration API + reference adapter\nexport * from './integration/index.js';\n// QTI Results Reporting (assessmentResult) output\nexport * from './reporting/index.js';\n// Public UI/data types\nexport type {\n\tAssessmentResults,\n\tCandidateSectionView,\n\tCheckAnswerState,\n\tItemFeedbackEntry,\n\tItemFeedbackView,\n\tItemResult,\n\tNavigationState,\n\tQTIRole,\n\tResultsSummary,\n\tVisibleTestFeedback,\n} from './types/index.js';\n"]}
|
|
@@ -25,8 +25,25 @@
|
|
|
25
25
|
* - Performs scoring server-side
|
|
26
26
|
* - Validates all requests with authentication
|
|
27
27
|
* - Filters sensitive data based on role
|
|
28
|
+
*
|
|
29
|
+
* ## Persistence failure semantics
|
|
30
|
+
*
|
|
31
|
+
* A localStorage write that does not land (quota exceeded, private-mode eviction) means
|
|
32
|
+
* the operation did not complete, and every backend method reports it honestly:
|
|
33
|
+
* `saveState` returns `success: false` (the autosave engine shows `failed`, retries with
|
|
34
|
+
* backoff and reports onError), `submitResponses` returns `success: false` (the player
|
|
35
|
+
* restores the pre-submit state and throws its coded `submitFailed` — accepting the
|
|
36
|
+
* submission anyway would silently lose the answer on the next resume), and
|
|
37
|
+
* `finalizeAssessment` returns `success: false` (the `finalized` flag never persisted, so
|
|
38
|
+
* reporting a completion would resurrect the test on resume; the player throws its coded
|
|
39
|
+
* `finalizeFailed` and the test stays open for a retry). The initial session write and
|
|
40
|
+
* the outcome-processing-error bookkeeping are the only best-effort writes: their response
|
|
41
|
+
* shapes carry no failure, and a lost init write merely leaves a fresh session without a
|
|
42
|
+
* resumable draft — which the very next save reports through the paths above.
|
|
28
43
|
*/
|
|
29
|
-
import
|
|
44
|
+
import { type StringComparisonOptions } from '@pie-qti/qti-processing';
|
|
45
|
+
import type { BackendAdapter, FinalizeAssessmentRequest, FinalizeAssessmentResponse, InitSessionRequest, InitSessionResponse, SaveAssessmentStateRequest, SaveAssessmentStateResponse, SecureAssessment, SessionId, SubmitResponsesRequest, SubmitResponsesResponse } from './api-contract.js';
|
|
46
|
+
import { parseAssessmentTestXml } from './qti-test-parser.js';
|
|
30
47
|
/**
|
|
31
48
|
* Reference Backend Adapter using localStorage
|
|
32
49
|
*
|
|
@@ -42,10 +59,31 @@ import type { BackendAdapter, FinalizeAssessmentRequest, FinalizeAssessmentRespo
|
|
|
42
59
|
export interface ReferenceBackendAdapterOptions {
|
|
43
60
|
/** RNG for the session-start draw of selection and ordering. Defaults to Math.random. */
|
|
44
61
|
rng?: () => number;
|
|
62
|
+
/**
|
|
63
|
+
* String comparison folds the scorer applies beyond QTI's equality, as the delivery's input
|
|
64
|
+
* needs them (see the item player's `AssessmentItemDefinitionConfig.stringComparison`). Set
|
|
65
|
+
* the same value as the player's `stringComparison`. Exact when absent.
|
|
66
|
+
*/
|
|
67
|
+
stringComparison?: StringComparisonOptions;
|
|
45
68
|
}
|
|
46
69
|
export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
70
|
+
/** @see ./qti-test-parser.ts — the parser lives in its own module. */
|
|
71
|
+
static parseAssessmentTestXml: typeof parseAssessmentTestXml;
|
|
72
|
+
/**
|
|
73
|
+
* The adapter persists drafts: sessions live in localStorage and `saveState` writes
|
|
74
|
+
* the candidate's snapshot into them, so shell autosave is ON by default.
|
|
75
|
+
*/
|
|
76
|
+
readonly canSaveState = true;
|
|
77
|
+
/**
|
|
78
|
+
* The adapter scores from the candidate's serialized item session: a templated item is
|
|
79
|
+
* scored against the instance the candidate saw (never a fresh template draw), and an
|
|
80
|
+
* adaptive item's accumulated outcomes are taken as submitted. The player therefore
|
|
81
|
+
* always sends it (reference mode); a templated or adaptive item without one is refused.
|
|
82
|
+
*/
|
|
83
|
+
readonly requiresItemSession = true;
|
|
47
84
|
private registeredAssessments;
|
|
48
85
|
private readonly rng;
|
|
86
|
+
private readonly stringComparison;
|
|
49
87
|
constructor(options?: ReferenceBackendAdapterOptions);
|
|
50
88
|
/**
|
|
51
89
|
* Register/override a client-provided assessment structure for a given assessmentId.
|
|
@@ -56,7 +94,6 @@ export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
56
94
|
*/
|
|
57
95
|
registerAssessment(assessmentId: string, assessment: SecureAssessment): void;
|
|
58
96
|
private getAssessment;
|
|
59
|
-
private hasAnyResponse;
|
|
60
97
|
/**
|
|
61
98
|
* Initialize a new assessment session
|
|
62
99
|
*/
|
|
@@ -73,18 +110,37 @@ export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
73
110
|
* Finalize assessment and compute final scores
|
|
74
111
|
*/
|
|
75
112
|
finalizeAssessment(request: FinalizeAssessmentRequest): Promise<FinalizeAssessmentResponse>;
|
|
76
|
-
/**
|
|
113
|
+
/**
|
|
114
|
+
* Outcome values and any outcome-processing failure after the submissions so far; both
|
|
115
|
+
* undefined before the first submission.
|
|
116
|
+
*/
|
|
77
117
|
private currentOutcomes;
|
|
118
|
+
/**
|
|
119
|
+
* The stored final totals of a finalized session, for the terminal init response:
|
|
120
|
+
* the same fallback totals `finalizeAssessment` reports (per-item scores included so
|
|
121
|
+
* a shell can render its completion summary).
|
|
122
|
+
*/
|
|
123
|
+
private storedFinalResults;
|
|
78
124
|
/**
|
|
79
125
|
* Execute test-level outcome processing (T9/T1).
|
|
80
|
-
*
|
|
81
|
-
*
|
|
126
|
+
*
|
|
127
|
+
* Returns every declared outcome's value (null for NULL), or null when no
|
|
128
|
+
* outcomeProcessing is defined. A failure is reported as a typed
|
|
129
|
+
* `OutcomeProcessingError` (persisted on the session) — it never fails delivery and
|
|
130
|
+
* candidate responses always stay persisted, but it must surface to the host instead
|
|
131
|
+
* of SCORE/testFeedback silently never computing.
|
|
82
132
|
*/
|
|
83
133
|
private runOutcomeProcessing;
|
|
84
134
|
/**
|
|
85
135
|
* Resume existing session (alias for initSession with resumeSessionId)
|
|
86
136
|
*/
|
|
87
137
|
resumeSession(sessionId: SessionId): Promise<InitSessionResponse>;
|
|
138
|
+
/**
|
|
139
|
+
* The identifier of this adapter's most recent unfinalized session for an
|
|
140
|
+
* assessment and candidate, or null. Hosts pass it as `initSession.resumeSessionId`
|
|
141
|
+
* to resume the stored draft — the reference resume path after a refresh.
|
|
142
|
+
*/
|
|
143
|
+
latestSessionId(assessmentId: string, candidateId: string): SessionId | null;
|
|
88
144
|
/**
|
|
89
145
|
* Query item bank for random item selection
|
|
90
146
|
*
|
|
@@ -96,104 +152,11 @@ export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
96
152
|
* @param request - Item bank query request
|
|
97
153
|
* @returns Selected items from bank
|
|
98
154
|
*/
|
|
99
|
-
queryItemBank(request: QueryItemBankRequest): Promise<QueryItemBankResponse>;
|
|
100
|
-
private generateSessionId;
|
|
101
|
-
private loadSession;
|
|
102
|
-
private saveSession;
|
|
103
|
-
/**
|
|
104
|
-
* Create demo assessment for testing
|
|
105
|
-
*
|
|
106
|
-
* In production, this would fetch from database
|
|
107
|
-
*/
|
|
108
155
|
private createDemoAssessment;
|
|
109
156
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* - S1: section-level itemSessionControl
|
|
114
|
-
* - S9: assessmentSectionRef href resolution (requires fileResolver)
|
|
115
|
-
* - T9/T1: outcomeDeclarations + outcomeProcessing extraction
|
|
116
|
-
*
|
|
117
|
-
* @param testXml - Raw QTI assessmentTest XML string
|
|
118
|
-
* @param options.role - Role to assign to items (default: 'candidate')
|
|
119
|
-
* @param options.itemXmlMap - Map of item identifier -> itemXml for pre-loaded items
|
|
120
|
-
* @param options.fileResolver - Async function to load external files by relative href
|
|
121
|
-
* @param options.baseUrl - Base URL for resolving relative hrefs
|
|
122
|
-
*/
|
|
123
|
-
static parseAssessmentTestXml(testXml: string, options?: {
|
|
124
|
-
role?: SecureItemRef['role'];
|
|
125
|
-
itemXmlMap?: Record<string, string>;
|
|
126
|
-
fileResolver?: (href: string) => Promise<string>;
|
|
127
|
-
baseUrl?: string;
|
|
128
|
-
/**
|
|
129
|
-
* Shared catalog files the package manifest lists (resource type
|
|
130
|
-
* `imsqti_catalog_xmlv3p0`): href, XML, or both. Their entries back
|
|
131
|
-
* every item's `data-catalog-idref` terms; item-level catalogs win
|
|
132
|
-
* identifier collisions (QTI 3.0 §6.3).
|
|
133
|
-
*/
|
|
134
|
-
sharedCatalogs?: ReadonlyArray<{
|
|
135
|
-
href?: string;
|
|
136
|
-
xml?: string;
|
|
137
|
-
}>;
|
|
138
|
-
sectionReferenceLimits?: {
|
|
139
|
-
/** Maximum total inline and external assessmentSection nesting. Defaults to 32. */
|
|
140
|
-
maxDepth?: number;
|
|
141
|
-
};
|
|
142
|
-
}): Promise<SecureAssessment>;
|
|
143
|
-
/**
|
|
144
|
-
* Context for branch rules and preconditions: test outcomes, every submitted item's variables as
|
|
145
|
-
* `itemIdentifier.VARIABLE`, and `current` unprefixed where the test declares no such outcome.
|
|
146
|
-
*/
|
|
147
|
-
private navigationDeclarations;
|
|
148
|
-
/**
|
|
149
|
-
* Next item after `delivered[index]`. Branch rules come first: the item's, then each enclosing
|
|
150
|
-
* section's it ends (inner to outer), then the test part's when it ends that too. Item and
|
|
151
|
-
* section rules apply in linear navigation only. With no matching rule, navigation falls through
|
|
152
|
-
* to the following item. Preconditions then skip forward from the target. EXIT_TEST means the
|
|
153
|
-
* remaining items are all skipped; undefined means the current item was the last.
|
|
154
|
-
*/
|
|
155
|
-
private nextItemIdentifier;
|
|
156
|
-
private branchTarget;
|
|
157
|
-
/** Index a branch target resolves to, forward of `index`; delivered.length ends the test. */
|
|
158
|
-
private resolveBranchTarget;
|
|
159
|
-
/**
|
|
160
|
-
* First item from `start` whose preconditions hold. A test part's are checked on entering it in
|
|
161
|
-
* any navigation mode; a newly entered section's (outermost first) and the item's only in linear
|
|
162
|
-
* navigation. A failing part or section skips everything inside it.
|
|
163
|
-
*/
|
|
164
|
-
private firstEligibleItem;
|
|
165
|
-
private isLinear;
|
|
166
|
-
/** Delivered item refs in order, each with the identifiers of the sections containing it (outermost first). */
|
|
167
|
-
private getItemRefsInOrder;
|
|
168
|
-
/**
|
|
169
|
-
* Test-level view of every delivered item. Items not yet submitted carry their declared defaults
|
|
170
|
-
* and count as not presented; sessions stored before item test states existed fall back to the
|
|
171
|
-
* submitted scores, leaving correctness to SCORE/MAXSCORE inference.
|
|
157
|
+
* Test-level view of every delivered item. A submitted item is presented and carries the state
|
|
158
|
+
* its latest counted submission recorded (a score without one carries only its SCORE); an item
|
|
159
|
+
* not yet submitted carries its declared defaults and counts as not presented.
|
|
172
160
|
*/
|
|
173
161
|
private buildTestItems;
|
|
174
|
-
/** Variables recoverable from a scoring result alone: numbers as float, everything else as string. */
|
|
175
|
-
private scoredItemVariables;
|
|
176
|
-
/**
|
|
177
|
-
* Generate cache key for item bank query
|
|
178
|
-
*/
|
|
179
|
-
private getBankCacheKey;
|
|
180
|
-
/**
|
|
181
|
-
* Load item bank cache from localStorage
|
|
182
|
-
*/
|
|
183
|
-
private loadBankCache;
|
|
184
|
-
/**
|
|
185
|
-
* Save item bank cache to localStorage
|
|
186
|
-
*/
|
|
187
|
-
private saveBankCache;
|
|
188
|
-
/**
|
|
189
|
-
* Fetch items from item bank with retry logic
|
|
190
|
-
*
|
|
191
|
-
* **DEMO IMPLEMENTATION**: Returns hardcoded items
|
|
192
|
-
* In production, this would make HTTP request to item bank service
|
|
193
|
-
*/
|
|
194
|
-
private fetchItemsFromBank;
|
|
195
|
-
/**
|
|
196
|
-
* Delay helper for async operations
|
|
197
|
-
*/
|
|
198
|
-
private delay;
|
|
199
162
|
}
|