[QTI] Render embedded Perseus questions in the QTI viewer
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Render the Perseus questions carried in a mixed QTI package (delivered as a Perseus custom interaction, see Contract) so the whole exercise renders in one viewer.
Complexity: High Target branch: develop
Context
- #11428 builds the QTI renderer for the core interaction types.
- Studio publishes mixed exercises as one QTI package (learningequality/studio#6047), wrapping each Perseus question as a Perseus custom interaction.
- Kolibri already has a Perseus renderer.
- Asset resolution is the hard part.
- The zip loader builds the image-key → URL map for
replaceImageUrls/restoreImageUrls. - The
itemDataprop path skips that map, so images break. - The zip loader also assumes a fixed layout — items at the zip root, images under
images/. - Studio packages assets under
perseus/images/, so that assumption is violated. - The manifest declares every file the perseus resource depends on — enough to build the map without parsing the item JSON.
- Injected URLs must round-trip through the
restoreImageUrlsswap-out, or resolved URLs leak into answer data.
Contract — Perseus-in-QTI custom interaction
Shared with the Studio publish issue; concretised by learningequality/studio#6047.
- Each raw Perseus question is a
qti-custom-interactionwith adata-type="perseus"marker. - It is the spec's delivery-engine-specific element — no JS module required.
- The Perseus JSON is a package resource, referenced by
data-perseus-path. - Every file it references (images, graphie
.svg/-data.json) is packaged and declared as a manifest dependency of that resource. - The host's Perseus renderer, keyed off
data-type="perseus", owns rendering and grading. - It reports correct/incorrect back through the QTI response — no QTI-native response-processing template.
<qti-custom-interaction
response-identifier="RESPONSE"
data-type="perseus"
data-perseus-path="perseus/{assessment_id}.json"/>
Wrapper item structure (Studio side, #6047)
The wrapper is a complete, self-grading QTI item — the renderer reports an outcome, the item's own response processing derives the score:
<qti-response-declaration identifier="RESPONSE" cardinality="record"/>
<qti-outcome-declaration identifier="SCORE" cardinality="single" base-type="float"/>
<qti-item-body>
<qti-custom-interaction response-identifier="RESPONSE" data-type="perseus"
data-perseus-path="perseus/{assessment_id}.json"/>
</qti-item-body>
<qti-response-processing>
<!-- if RESPONSE.correct then SCORE = 1 else SCORE = 0 -->
</qti-response-processing>
RESPONSEis a record variable with no declared schema — each field carries its own base-type at runtime.- The renderer writes three fields:
correct(boolean) — drives gradingsimpleAnswer(string)answerState(arbitrary object; need not be stringified)
- The custom interaction binds one response variable, so the record is how a single interaction carries grade plus answer state together.
- Perseus answer state exists only in
checkAnswer's return, sosimpleAnswer/answerStatemust ride the response — the renderer does not persist them otherwise. - Inline response processing reads
correctand setsSCORE(single, float) to1/0. - Inline because no standard template can inspect a record field.
- The renderer must not compute
SCORE— the wrapper does.
Packaged layout (Studio side, #6047)
- Perseus JSON at
perseus/{assessment_id}.json. - Assets under
perseus/images/. - Plain images are stored as
{checksum}.{ext}. - Graphie is stored as
{name}.svgplus{name}-data.json. - Plain asset refs in the JSON are rewritten to
${☣ LOCALPATH}/perseus/images/…. - Graphie refs are rewritten to
web+graphie:${☣ LOCALPATH}/perseus/images/{name}. - These are not zip-root
images/, hence the map plus forgiving basename match. - The item resource declares
perseus/{id}.jsonplus every asset path as manifestfile_dependencies— the map source.
The Change
- Detect the Perseus custom interaction by its
data-type="perseus"marker in the QTI Viewer. - Build the image-url map (a blob URL per file) from the perseus resource's declared manifest dependencies.
- Pass the item JSON plus the map as an embellished
itemDatathrough the renderer's existing pipeline. - Feed the injected map where the zip loader's
packageFilesgo, soreplaceImageUrls/restoreImageUrlswork unchanged. - Skip
setUpPerseusFile. - Match Perseus's image lookups to map keys forgivingly (e.g. by basename).
- Write the
RESPONSErecord fromcheckAnswer's result.
Acceptance Criteria
- [ ] A mixed package renders its Perseus questions and native QTI interactions together in one exercise
- [ ] The image-url map is built from the manifest's declared dependencies, without parsing the item JSON
- [ ] Plain and
web+graphie:images resolve fromperseus/images/ - [ ] Package paths are matched forgivingly to Perseus's lookup names (e.g. by basename)
- [ ] The answer swap-out restores original
${☣ LOCALPATH}/…refs - [ ] No resolved URLs persist into stored item or answer data
- [ ] Grading a Perseus question writes
correctto theRESPONSErecord - [ ] The resulting
SCOREmatches the standalone Perseus renderer's correct/incorrect result - [ ] The rendered Perseus question meets the same accessibility standards as native QTI items
- [ ] QTI Sandbox fixtures are extended to include some representative Perseus items sampled from the Kolibri QA Channel
- [ ] Tests cover rendering with graphie images
References
- #11428 — Allow Kolibri to render QTI assessments
- learningequality/studio#6047 — Publish mixed Perseus + native QTI exercise nodes as one QTI package (publish counterpart)
AI usage
Claude drafted this issue and added the response-record and packaged-layout detail from the Studio publish PR (learningequality/studio#6047); the maintainer steered and reviewed throughout.
Plan: Render the Perseus questions carried in a mixed QTI package (each wrapped as a qti-custom-interaction with data-type="perseus") inside the QTI viewer, so a mixed exercise renders — and grades — in one viewer.
- [x] Parse
<file>dependencies and expose a package file accessor - [x] Embellished-
itemDatapath + basename-forgiving lookup - [x]
PerseusCustomInteraction.vue— render a Perseus item in-place - [x] Commit
RESPONSErecord on check →SCORE - [x] Sandbox Perseus-in-QTI fixtures with a mock package
- [x] Graphie rendering + accessibility coverage
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.