fix(runtime): hear the statements content sends as it starts

Merged
AL
3h ago
+55-23

Summary

Closes #343. The frame's boot script listened for xAPI only after H5P.init(), so a statement content sends as it starts never reached the page: Accordion's consumed, the attempted the core's setActivityStarted() sends, and the completed a Course Presentation resumed on its summary slide says again. The listener is now attached before init, as the core's own relay is.

finished does not change. H5P's core starts listening for a result only once the content is attached, and so does finished: a result said during the start is an xapi statement only. Without that, reopening a finished deck would raise finished on load and the SCORM bridge would write its score and status again.

Changes

  • packages/runtime/src/frame-boot.ts: the xAPI listener moves above H5P.init(), and posts finished only once init has returned. Statements from the start reach the element before its ready event. The element already relays a statement in any state, and holds it until the revision is known.
  • design/frame.md: a rule, The frame hears the content from its start. design/results.md and docs/api.md: a result said while the content attaches is a statement and no finished.
  • Journeys:
    • Accordion checks that its consumed (completion: true, no score) arrives, and nothing more.
    • Course Presentation, new case: a learner who comes back to the summary slide hears attempted, progressed, completed, and no finished.
    • Drag and Drop, Course Presentation and Interactive Video list attempted where they list every verb. Course Presentation finds its progressed statement by verb.
  • Rides along: the Column case requires the page's id to be an address (CodeRabbit's follow-up on #342, pushed after it merged).

Verification

  • pnpm test in apps/journeys (Chromium): 13 files, 95 passed. Before the fix, Accordion heard no statement. The new Course Presentation case fails both ways: no statement without the move, one finished without the hold.

  • pnpm sweep --modes untrusted on this branch: 55 of 55 plays pass. 40 content types now deliver a statement before ready (attempted for 37, consume for Accordion and Collage, progressed for Documentation Tool); none sends a result there from a fresh start.

  • pnpm test:browser in packages/player (Chromium, both projects): 32 files, 219 passed.

  • pnpm --filter @missing-elements/h5p-runtime --filter @missing-elements/h5p-journeys typecheck, pnpm lint, node scripts/comments.mjs: pass.

  • Tests added or updated where behavior changed

  • Documentation updated where public behavior or deployment changed

  • Relevant type checks, tests, and builds pass

  • No security-sensitive details or credentials are included

Screenshots or reproduction

Play an Accordion and listen for xapi on the element: before, no event; after, one consumed as it starts.


Summary by cubic

The frame's boot script now attaches its xAPI listener before H5P.init(), so statements content sends as it starts — Accordion's consumed and the core's attempted from setActivityStarted() — reach the page instead of being lost. A result said while the content attaches is still posted, but only as an xapi statement, not as finished, matching the core's own behavior.

  • The xAPI listener in packages/runtime/src/frame-boot.ts now attaches before H5P.init(), and finished is gated until init returns: a Course Presentation resumed on its summary slide repeats completed as it is drawn, but raises no finished.
  • Journey tests pin the new consumed and attempted statements: Accordion expects only consume, Drag and Drop, Course Presentation, and Interactive Video list attempted alongside their other verbs, and Course Presentation resumes to a repeated completed with no finished.
  • The Column test now parses the page id as a URL, requiring an HTTP(S) host so parent matches can't succeed vacuously.
  • design/frame.md, design/results.md, and docs/api.md document that the frame hears the content from its start and that a result repeated as the content attaches is an xapi statement only.