From b17c0915e5a147868595acfc62ede096382a8c33 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 22:10:46 +0200 Subject: [PATCH 1/6] fix(author): a Question Set's poolSize that hides questions, or draws none, is noted (#268) poolSize reads as the number of questions and is how many are shown, drawn at random. A chat in ChatGPT wrote 3 for three questions, added three more, and the quiz went on showing three of six. Below the number of questions the build now says how many of how many are shown; at or above it, that it draws nothing and would hide a question added later. The Question Set type file says poolSize is not the number of questions, and to leave it out unless a random draw is asked for. --- design/author.md | 8 ++++++-- packages/author/lib/mistakes.mjs | 12 +++++++++++- packages/author/tests/build.test.ts | 14 ++++++++++++++ .../h5p-author/references/types/H5P.QuestionSet.md | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/design/author.md b/design/author.md index 02df5ea0..dcdb5e99 100644 --- a/design/author.md +++ b/design/author.md @@ -455,8 +455,12 @@ text to the content check's rules, and `apps/skills` plays every example untrust answers, Multimedia Choice's options; Find the Hotspot's areas are refused already), two answers or statements alike as a learner reads them, without tags or entities and in any case (Multiple Choice, a Single Choice Set question, a Summary set), a text with no gap (Fill in the - Blanks, Drag the Words, Mark the Words), and a picture with no alt text where its field is - optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required). + Blanks, Drag the Words, Mark the Words), a picture with no alt text where its field is + optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required), + and a Question Set's `poolSize` (#268): below the number of questions it shows that many, + drawn at random, and leaves the rest out, which is said with both numbers since it may be + meant; at or above it, it draws nothing and hides a question added later. A chat in ChatGPT + wrote 3 for three questions, added three, and the quiz went on showing three (2026-11-23). Each says what to write. `lib/mistakes.mjs` runs in `checkContent`, so a build says them and so does a check of saved content, and every type file's example says none. Of the owner's 88 real packages, the 79 checked against their own libraries give 36 notes of a picture with no alt diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index 49326ae7..8eed1a46 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -3,7 +3,8 @@ import { blanksGaps } from './types.mjs' /** * What builds and is almost surely a mistake (#241, item 4 of #219): no answer marked correct, two - * answers alike, a text with no gap, a picture with no alt text where its field is optional. H5P + * answers alike, a text with no gap, a picture with no alt text where its field is optional, a + * quiz's pool that leaves questions out or draws none (#268). H5P * allows each, so each is a note and not a problem, and nothing about the content is judged: whether * an answer is right stays the person's. Run by `checkContent` on content as H5P stores it, so a * build says them, and so does a check of saved content. @@ -100,6 +101,15 @@ const CHECKS = { 'H5P.MultiMediaChoice'(params, path, note) { if (noneCorrect(params.options)) note(`${path}.options`, 'marks no option correct, so no learner can score: set "correct": true on the right one') }, + // `poolSize` reads as "how many questions there are", and is how many are shown: a chat wrote 3 + // for three questions, added three more, and the quiz went on showing three, drawn at random. + 'H5P.QuestionSet'(params, path, note) { + const count = Array.isArray(params.questions) ? params.questions.length : 0 + const pool = params.poolSize + if (!count || typeof pool !== 'number' || pool < 1) return + if (pool < count) note(`${path}.poolSize`, `shows ${pool} of the ${count} questions each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) + else note(`${path}.poolSize`, `is not below the number of questions, ${count}, so it draws nothing, and a question added later would be left out at random: leave it out`) + }, 'H5P.SingleChoiceSet'(params, path, note) { if (!Array.isArray(params.choices)) return params.choices.forEach((choice, i) => alike(choice?.answers, (answer) => answer, `${path}.choices[${i}].answers`, 'answer', note)) diff --git a/packages/author/tests/build.test.ts b/packages/author/tests/build.test.ts index 16153190..5af844f0 100644 --- a/packages/author/tests/build.test.ts +++ b/packages/author/tests/build.test.ts @@ -638,6 +638,20 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { ]) }) + it('says where a quiz\'s pool leaves questions out, or draws none (#268)', async () => { + const question = (text: string) => ({ library: 'H5P.TrueFalse', params: { question: text, correct: 'true' } }) + const questions = ['The Danube reaches the Black Sea.', 'The Seine flows through Paris.', 'The Volga is in Europe.'].map(question) + const quiz = (poolSize?: number) => notesOf({ ...META, type: 'H5P.QuestionSet', params: { questions, ...(poolSize === undefined ? {} : { poolSize }) } }) + expect(await quiz(2)).toEqual([ + { path: 'params.poolSize', message: 'shows 2 of the 3 questions each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + ]) + // As many as there are draws nothing, and is what hides a question added later. + expect(await quiz(3)).toEqual([ + { path: 'params.poolSize', message: 'is not below the number of questions, 3, so it draws nothing, and a question added later would be left out at random: leave it out' } + ]) + expect(await quiz()).toEqual([]) + }) + it('says where a choice of pictures marks none correct', async () => { const at = await mkdtemp(join(dir, 'pictures-')) await writeFile(join(at, 'delta.png'), png(64, 48)) diff --git a/skills/h5p-author/references/types/H5P.QuestionSet.md b/skills/h5p-author/references/types/H5P.QuestionSet.md index c884785c..f9058e41 100644 --- a/skills/h5p-author/references/types/H5P.QuestionSet.md +++ b/skills/h5p-author/references/types/H5P.QuestionSet.md @@ -5,7 +5,7 @@ A quiz: questions one after another, then a result page with the score. - Each item of `questions` is sub-content: `{ "library": "H5P.MultiChoice", "params": { … }, "metadata": { "title": "…" } }`. Write each question's `params` from its own type file. The result page lists questions by `metadata.title`; without one a question is "Question 2" in the content's language. - `passPercentage` is the pass mark; `endGame.overallFeedback` holds the score ranges' messages. Question Set 1.21 draws neither on its result page, an H5P bug (h5p/h5p-question-set#183): screen readers announce the message, and a learner sees only the score. Tell the user. - An intro screen: `introPage.showIntroPage: true`, with `title` and `introduction`. -- `randomQuestions` shuffles them; `poolSize` draws that many from the list each time. +- `randomQuestions` shuffles them. `poolSize` is not the number of questions: it shows only that many, drawn at random each time, and leaves the rest out. Leave it out unless the user asks for a random draw. - Its navigation and result screen ("Previous", "Next", "Results", "Score") are English in all but one or two of its 48 translations; the build lists what stayed English. ## Example From 21af05f192a1c90ef6bb3bc578d3fa54b9aebef7 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 22:22:15 +0200 Subject: [PATCH 2/6] fix(author): what goes stale when a chat changes a content is noted, and the outline says a draw's how many of how many (#268) A scan of the 80 libraries with semantics in the pack, for settings a chat that adds, removes or renames items may leave as they were: - a number of items drawn at random: Memory Game's numCardsToUse and Crossword's poolSize, as Question Set's poolSize, by one rule; at the list's length it now says it draws nothing, and above it, that it draws nothing until there are more than it; - a number of items to find: Find Multiple Hotspots' numberHotspots, against the hotspots marked correct; - a part named by what is not there: a Course Presentation button's slide, a drop zone's right element, Agamotto's start image, a Virtual Tour's scene id, a Personality Quiz answer's personality. Each is a note. None fires in the owner's 88 real packages, though drop zones name their right elements in some 20 of them. The outline's first line says how many of how many a quiz, a memory game or a crossword shows, where it draws. The Memory Game type file says numCardsToUse is not the number of cards. --- design/author.md | 17 ++- packages/author/lib/mistakes.mjs | 111 ++++++++++++++++-- packages/author/lib/outline.mjs | 21 +++- packages/author/tests/build.test.ts | 39 +++++- packages/author/tests/confine.test.ts | 10 ++ .../references/types/H5P.MemoryGame.md | 1 + 6 files changed, 182 insertions(+), 17 deletions(-) diff --git a/design/author.md b/design/author.md index dcdb5e99..43dea560 100644 --- a/design/author.md +++ b/design/author.md @@ -457,15 +457,22 @@ text to the content check's rules, and `apps/skills` plays every example untrust (Multiple Choice, a Single Choice Set question, a Summary set), a text with no gap (Fill in the Blanks, Drag the Words, Mark the Words), a picture with no alt text where its field is optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required), - and a Question Set's `poolSize` (#268): below the number of questions it shows that many, - drawn at random, and leaves the rest out, which is said with both numbers since it may be - meant; at or above it, it draws nothing and hides a question added later. A chat in ChatGPT - wrote 3 for three questions, added three, and the quiz went on showing three (2026-11-23). + and what goes stale when a chat changes a content and keeps a setting (#268): a number of items + drawn at random (Question Set's `poolSize`, Memory Game's `numCardsToUse`, Crossword's + `poolSize`) or to find (Find Multiple Hotspots' `numberHotspots`), said with both numbers below + the list's length, since it may be meant, and at or above it as drawing nothing now and hiding + what is added later; and a part named by what is not there: a Course Presentation button's + slide, a drop zone's right element, Agamotto's start image, a Virtual Tour's scene id, a + Personality Quiz answer's personality. A chat in ChatGPT wrote `poolSize` 3 for three + questions, added three, and the quiz went on showing three (2026-11-23). The outline's first + line says a draw's how many of how many. Video times are #260's. Each says what to write. `lib/mistakes.mjs` runs in `checkContent`, so a build says them and so does a check of saved content, and every type file's example says none. Of the owner's 88 real packages, the 79 checked against their own libraries give 36 notes of a picture with no alt text in 8 packages, and 4 of answers alike in one, a test whose answers all read "Test"; no - question with no answer marked correct, and no text with no gap. + question with no answer marked correct, and no text with no gap. The notes of #268 fire in none + of the 88, though drop zones name their right elements in some 20 of them, and slide buttons + and a tour's scene ids are among them too. - **A source names the version of its type it was built with, and the build writes that** (#219, the owner's calls). A source handed over beside a package is built again later, on the build page or by a newer release, with a newer pack. So a build hands back the source with diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index 8eed1a46..c185d2ac 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -3,8 +3,10 @@ import { blanksGaps } from './types.mjs' /** * What builds and is almost surely a mistake (#241, item 4 of #219): no answer marked correct, two - * answers alike, a text with no gap, a picture with no alt text where its field is optional, a - * quiz's pool that leaves questions out or draws none (#268). H5P + * answers alike, a text with no gap, a picture with no alt text where its field is optional. And + * what goes stale when a chat changes a content and leaves a setting as it was (#268): a number + * of items to draw or to find that is not below how many there are, and a part named by its + * number, id or name that is not there. H5P * allows each, so each is a note and not a problem, and nothing about the content is judged: whether * an answer is right stays the person's. Run by `checkContent` on content as H5P stores it, so a * build says them, and so does a check of saved content. @@ -24,6 +26,26 @@ function plain(value) { return typeof value === 'string' ? decodeEntities(stripTags(value)).replace(/\s+/g, ' ').trim().toLowerCase() : '' } +/** @param {unknown} value */ +const count = (value) => (Array.isArray(value) ? value.length : 0) + +/** + * A number of items drawn at random from a list, against how many the list holds. Below it, which + * may be meant, both numbers are said; at or above it, it draws nothing now, and leaves items out + * at random once more are added: what a chat that adds items and keeps the setting gets (#268). + * @param {unknown} drawn + * @param {number} total + * @param {string} what the items, as "questions" + * @param {string} at the setting's path + * @param {Note} note + */ +function draws(drawn, total, what, at, note) { + if (!total || typeof drawn !== 'number' || drawn < 1) return + if (drawn < total) note(at, `shows ${drawn} of the ${total} ${what} each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) + else if (drawn === total) note(at, `is the number of ${what}, ${total}, so it draws nothing, and one added later would leave one out at random: leave it out`) + else note(at, `is above the number of ${what}, ${total}, so it draws nothing until more than ${drawn} are, and then leaves some out at random: leave it out`) +} + /** * Each item of a list that reads as an earlier one does. * @param {unknown} items @@ -104,11 +126,86 @@ const CHECKS = { // `poolSize` reads as "how many questions there are", and is how many are shown: a chat wrote 3 // for three questions, added three more, and the quiz went on showing three, drawn at random. 'H5P.QuestionSet'(params, path, note) { - const count = Array.isArray(params.questions) ? params.questions.length : 0 - const pool = params.poolSize - if (!count || typeof pool !== 'number' || pool < 1) return - if (pool < count) note(`${path}.poolSize`, `shows ${pool} of the ${count} questions each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) - else note(`${path}.poolSize`, `is not below the number of questions, ${count}, so it draws nothing, and a question added later would be left out at random: leave it out`) + draws(params.poolSize, count(params.questions), 'questions', `${path}.poolSize`, note) + }, + 'H5P.MemoryGame'(params, path, note) { + draws(params.behaviour?.numCardsToUse, count(params.cards), 'cards', `${path}.behaviour.numCardsToUse`, note) + }, + // Words fixed on the grid are always among those drawn; 0 means all. + 'H5P.Crossword'(params, path, note) { + draws(params.behaviour?.poolSize, count(params.words), 'words', `${path}.behaviour.poolSize`, note) + }, + 'H5P.ImageMultipleHotspotQuestion'(params, path, note) { + const settings = params.imageMultipleHotspotQuestion?.hotspotSettings + const wanted = settings?.numberHotspots + const correct = Array.isArray(settings?.hotspot) ? settings.hotspot.filter((/** @type {any} */ spot) => spot?.userSettings?.correct === true).length : 0 + if (typeof wanted !== 'number' || wanted < 1 || !correct) return + const at = `${path}.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots` + if (wanted > correct) note(at, `asks for ${wanted} hotspots, and ${correct} are marked correct, so no learner can finish: leave it out to ask for all of them`) + else if (wanted < correct) note(at, `ends the task once ${wanted} of the ${correct} correct hotspots are found: leave it out to ask for all of them, or tell the user`) + else note(at, `is the number of correct hotspots, ${correct}, so it changes nothing, and one added later would not be asked for: leave it out`) + }, + // A button that goes to a slide by its number: one that is not there goes nowhere. + 'H5P.CoursePresentation'(params, path, note) { + const slides = params.presentation?.slides + if (!Array.isArray(slides)) return + slides.forEach((/** @type {any} */ slide, /** @type {number} */ i) => { + if (!Array.isArray(slide?.elements)) return + slide.elements.forEach((/** @type {any} */ element, /** @type {number} */ j) => { + const to = element?.goToSlide + if ((element?.goToSlideType ?? 'specified') !== 'specified' || typeof to !== 'number') return + if (!Number.isInteger(to) || to < 1 || to > slides.length) note(`${path}.presentation.slides[${i}].elements[${j}].goToSlide`, `goes to slide ${to}, and there ${slides.length === 1 ? 'is 1 slide' : `are ${slides.length} slides`}, so the button goes nowhere: name a slide by its number, from 1`) + }) + }) + }, + // A drop zone names its right elements by their place in the list of elements, as text. + 'H5P.DragQuestion'(params, path, note) { + const task = params.question?.task + const elements = count(task?.elements) + if (!Array.isArray(task?.dropZones)) return + task.dropZones.forEach((/** @type {any} */ zone, /** @type {number} */ i) => { + if (!Array.isArray(zone?.correctElements)) return + zone.correctElements.forEach((/** @type {any} */ named, /** @type {number} */ j) => { + const index = Number(named) + if (!Number.isInteger(index) || index < 0 || index >= elements) note(`${path}.question.task.dropZones[${i}].correctElements[${j}]`, `names element ${JSON.stringify(named)}, and there ${elements === 1 ? 'is 1 element' : `are ${elements} elements`}, counted from 0, so no element is right there: name each by its place in elements, from 0`) + }) + }) + }, + 'H5P.Agamotto'(params, path, note) { + const start = params.behaviour?.startImage + const items = count(params.items) + if (typeof start === 'number' && items && (!Number.isInteger(start) || start < 1 || start > items)) note(`${path}.behaviour.startImage`, `starts at image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}: name one by its number, from 1, or leave it out`) + }, + // A tour's scenes are named by their ids: where it starts, and where a "go to scene" leads. + 'H5P.ThreeImage'(params, path, note) { + const tour = params.threeImage + if (!Array.isArray(tour?.scenes)) return + const ids = new Set(tour.scenes.map((/** @type {any} */ scene) => scene?.sceneId).filter((/** @type {any} */ id) => id !== undefined)) + const listed = [...ids].join(', ') + if (tour.startSceneId !== undefined && !ids.has(tour.startSceneId)) note(`${path}.threeImage.startSceneId`, `is ${tour.startSceneId}, which no scene has; the scenes' ids are ${listed}: the tour has no scene to start on`) + tour.scenes.forEach((/** @type {any} */ scene, /** @type {number} */ i) => { + if (!Array.isArray(scene?.interactions)) return + scene.interactions.forEach((/** @type {any} */ interaction, /** @type {number} */ j) => { + const action = interaction?.action + const to = action?.params?.nextSceneId + if (!/^H5P\.GoToScene\b/.test(String(action?.library ?? '')) || to === undefined || ids.has(to)) return + note(`${path}.threeImage.scenes[${i}].interactions[${j}].action.params.nextSceneId`, `is ${to}, which no scene has; the scenes' ids are ${listed}: it leads nowhere`) + }) + }) + }, + // An answer names its personalities by name, a comma between them: a name that is no + // personality's counts for none, as after a personality is renamed. + 'H5P.PersonalityQuiz'(params, path, note) { + if (!Array.isArray(params.personalities) || !Array.isArray(params.questions)) return + const names = new Set(params.personalities.map((/** @type {any} */ one) => plain(one?.name)).filter(Boolean)) + params.questions.forEach((/** @type {any} */ question, /** @type {number} */ i) => { + if (!Array.isArray(question?.answers)) return + question.answers.forEach((/** @type {any} */ answer, /** @type {number} */ j) => { + if (typeof answer?.personality !== 'string') return + const unknown = answer.personality.split(',').map((/** @type {any} */ name) => name.trim()).filter((/** @type {any} */ name) => name && !names.has(plain(name))) + if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called, so the answer counts for none: name the personalities as they are called`) + }) + }) }, 'H5P.SingleChoiceSet'(params, path, note) { if (!Array.isArray(params.choices)) return diff --git a/packages/author/lib/outline.mjs b/packages/author/lib/outline.mjs index 234c6380..5023bef8 100644 --- a/packages/author/lib/outline.mjs +++ b/packages/author/lib/outline.mjs @@ -42,15 +42,21 @@ const UNLABELLED = new Set(['text', 'question']) * - `links`: a scenario's `nextContentId`, the index of the content a choice or a content leads * to, negative for the end; and `endScreenScore`, the score an end gives. * - `labels`: a label for a field whose semantics give none. + * - `draws`: a setting that shows only some of a list's items, drawn at random each time, a + * number a chat that adds items may leave as it was (#268): the type's first line says how many + * of how many, where it is below the list's length. * @type {Record, titles?: Record string>, - * times?: Record, links?: boolean, labels?: Record + * times?: Record, links?: boolean, labels?: Record, + * draws?: { setting: string, list: string, what: string } * }>} */ const TYPES = { 'H5P.SingleChoiceSet': { right: ['choices[].answers'] }, 'H5P.Summary': { right: ['summaries[].summary'] }, - 'H5P.QuestionSet': { items: { questions: 'Question' }, titles: { questions: questionTitle } }, + 'H5P.QuestionSet': { items: { questions: 'Question' }, titles: { questions: questionTitle }, draws: { setting: 'poolSize', list: 'questions', what: 'questions' } }, + 'H5P.MemoryGame': { draws: { setting: 'behaviour.numCardsToUse', list: 'cards', what: 'cards' } }, + 'H5P.Crossword': { draws: { setting: 'behaviour.poolSize', list: 'words', what: 'words' } }, 'H5P.InteractiveBook': { items: { chapters: 'Chapter' } }, 'H5P.CoursePresentation': { items: { 'presentation.slides': 'Slide' }, labels: { 'presentation.slides[].keywords[].main': 'Keyword' } }, 'H5P.BranchingScenario': { items: { 'branchingScenario.content': 'Content', 'branchingScenario.endScreens': 'End screen' }, links: true }, @@ -61,6 +67,9 @@ const TYPES = { } } +/** A value at a dotted path in parameters. @param {Record} params @param {string} path */ +const valueAt = (params, path) => path.split('.').reduce((/** @type {any} */ value, name) => (isObject(value) ? value[name] : undefined), params) + /** The kinds of file field, as a line names them. */ const MEDIA = /** @type {Record} */ ({ image: 'Image', video: 'Video', audio: 'Audio', file: 'File' }) @@ -168,7 +177,13 @@ export function outlineOf(libraries, content, { limit = Infinity } = {}) { */ const walkFields = (fields, params, depth, type, path, bare = false) => { if (!isObject(params)) return - if (!path) semanticsOf.set(type, fields) + if (!path) { + semanticsOf.set(type, fields) + const draws = TYPES[type]?.draws + const drawn = draws && valueAt(params, draws.setting) + const items = draws && valueAt(params, draws.list) + if (draws && typeof drawn === 'number' && drawn >= 1 && Array.isArray(items) && drawn < items.length) emit(depth, `Shows ${drawn} of the ${items.length} ${draws.what} each time, drawn at random`) + } for (const field of fields) walk(field, params[field.name], depth, type, path ? `${path}.${field.name}` : field.name, bare, params) } diff --git a/packages/author/tests/build.test.ts b/packages/author/tests/build.test.ts index 5af844f0..256ed3e3 100644 --- a/packages/author/tests/build.test.ts +++ b/packages/author/tests/build.test.ts @@ -645,13 +645,48 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { expect(await quiz(2)).toEqual([ { path: 'params.poolSize', message: 'shows 2 of the 3 questions each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } ]) - // As many as there are draws nothing, and is what hides a question added later. + // As many as there are draws nothing, and is what hides a question added later; more, once there are more still. expect(await quiz(3)).toEqual([ - { path: 'params.poolSize', message: 'is not below the number of questions, 3, so it draws nothing, and a question added later would be left out at random: leave it out' } + { path: 'params.poolSize', message: 'is the number of questions, 3, so it draws nothing, and one added later would leave one out at random: leave it out' } + ]) + expect(await quiz(5)).toEqual([ + { path: 'params.poolSize', message: 'is above the number of questions, 3, so it draws nothing until more than 5 are, and then leaves some out at random: leave it out' } ]) expect(await quiz()).toEqual([]) }) + it('says where a memory game or a crossword draws, as a quiz does (#268)', async () => { + const card = (text: string) => ({ image: { path: 'river.png' }, imageAlt: text }) + const at = await mkdtemp(join(dir, 'cards-')) + await writeFile(join(at, 'river.png'), png(64, 48)) + expect(await notesOf({ ...META, type: 'H5P.MemoryGame', params: { cards: [card('A river'), card('A lake'), card('A sea')], behaviour: { numCardsToUse: 2 } } }, at)).toEqual([ + { path: 'params.behaviour.numCardsToUse', message: 'shows 2 of the 3 cards each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + ]) + const word = (clue: string, answer: string) => ({ clue, answer }) + expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: [word('A long river', 'Danube'), word('Through Paris', 'Seine')], behaviour: { poolSize: 2 } } })).toEqual([ + { path: 'params.behaviour.poolSize', message: 'is the number of words, 2, so it draws nothing, and one added later would leave one out at random: leave it out' } + ]) + }) + + it('says where a part is named by a number, an id or a name that is not there (#268)', async () => { + const text = (html: string) => ({ action: { library: 'H5P.AdvancedText', params: { text: html } } }) + // A Course Presentation button to slide 3 of 2. + expect(await notesOf({ ...META, type: 'H5P.CoursePresentation', params: { presentation: { slides: [ + { elements: [text('

Rivers

'), { goToSlideType: 'specified', goToSlide: 3, x: 10, y: 10, width: 20, height: 10 }] }, + { elements: [text('

Lakes

')] } + ] } } })).toEqual([ + { path: 'params.presentation.slides[0].elements[1].goToSlide', message: 'goes to slide 3, and there are 2 slides, so the button goes nowhere: name a slide by its number, from 1' } + ]) + // A Personality Quiz answer naming a personality renamed since. + expect(await notesOf({ ...META, type: 'H5P.PersonalityQuiz', params: { + titleScreen: { title: { text: 'Which traveller are you?' } }, + personalities: [{ name: 'Explorer', description: 'Goes far.' }, { name: 'Builder', description: 'Makes things.' }], + questions: [{ text: 'On a free day you…', answers: [{ text: 'walk somewhere new', personality: 'Explorer' }, { text: 'fix something', personality: 'Maker, builder' }] }] + } })).toEqual([ + { path: 'params.questions[0].answers[1].personality', message: 'names "Maker", which no personality is called, so the answer counts for none: name the personalities as they are called' } + ]) + }) + it('says where a choice of pictures marks none correct', async () => { const at = await mkdtemp(join(dir, 'pictures-')) await writeFile(join(at, 'delta.png'), png(64, 48)) diff --git a/packages/author/tests/confine.test.ts b/packages/author/tests/confine.test.ts index e643fbf4..ed70ac58 100644 --- a/packages/author/tests/confine.test.ts +++ b/packages/author/tests/confine.test.ts @@ -285,6 +285,16 @@ describe('outline', () => { expect(await outline({ ...quiz, language: 'de' })).toBe(expected) }) + it('says first how many of how many a quiz, a memory game or a crossword shows, where it draws (#268)', async () => { + const question = (text: string) => ({ library: 'H5P.TrueFalse', params: { question: text, correct: 'true' } }) + const questions = ['Water is wet.', 'Ice is cold.', 'Steam is hot.'].map(question) + expect((await outline({ type: 'H5P.QuestionSet', params: { questions, poolSize: 2 } })).split('\n')[0]).toBe('Shows 2 of the 3 questions each time, drawn at random') + // At or above the number of questions it draws nothing, and says nothing. + expect((await outline({ type: 'H5P.QuestionSet', params: { questions, poolSize: 3 } })).split('\n')[0]).toBe(' Question 1') + const words = [{ clue: 'A long river', answer: 'Danube' }, { clue: 'Through Paris', answer: 'Seine' }, { clue: 'Through Rome', answer: 'Tiber' }] + expect((await outline({ type: 'H5P.Crossword', params: { words, behaviour: { poolSize: 2 } } })).split('\n')[0]).toBe('Shows 2 of the 3 words each time, drawn at random') + }) + it('keeps a text\'s paragraphs, lines and list items apart, and numbers slides, with each slide\'s keyword', async () => { const text = (html: string) => ({ action: { library: 'H5P.AdvancedText', params: { text: html } } }) expect(await outline({ diff --git a/skills/h5p-author/references/types/H5P.MemoryGame.md b/skills/h5p-author/references/types/H5P.MemoryGame.md index 3c6760b6..a0a43ad8 100644 --- a/skills/h5p-author/references/types/H5P.MemoryGame.md +++ b/skills/h5p-author/references/types/H5P.MemoryGame.md @@ -5,6 +5,7 @@ Cards face down, turned two at a time, until every pair is found. - Each item of `cards` is a pair: `image` and `imageAlt`, and, for a pair of two different pictures, `match` and `matchAlt`. Without `match` the pair is two copies of `image`. - `description` is shown when the pair is found: say what it shows. - Square-ish pictures work best; at least two cards. +- `behaviour.numCardsToUse` is not the number of cards: it shows only that many pairs, drawn at random each time. Leave it out unless the user asks for a random draw. ## Example From b3fe8e815dd97b647b691070f1f506791936bd28 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 22:31:43 +0200 Subject: [PATCH 3/6] fix(author): the notes of #268 say what each library does, read in its script, and Drag and Drop's other list of places is read too (#268) A review of the issue found the notes written from the fields' labels. Read in the libraries' scripts: - Personality Quiz takes a name only as its personality has it, parted at a comma and a space: the note took another capital, or a comma with no space, as fine. - Find Multiple Hotspots does not use a number above its hotspots: the note said no learner could finish. - Agamotto holds a start image to the images there are: the note says where it starts. - Memory Game's number is of pairs, and the note and the outline say pairs. - A Course Presentation button and a Virtual Tour's scene id: the notes say what is named and what there is, not an effect that was not run. The scan had missed a Drag and Drop element's dropZones, the zones it can be dropped in: a zone that is not there is noted, and an element no zone it can reach takes as right. One real package names two elements right in a zone they cannot be dropped in, beside the one they can; that is left unsaid. The design says what is known of the ChatGPT case (a quiz of six with poolSize 3 after questions were added; its first source is not known), which of the checked types the 88 real packages hold, and what the scan did not look for. --- design/author.md | 26 +++++++---- packages/author/lib/mistakes.mjs | 68 ++++++++++++++++++++--------- packages/author/lib/outline.mjs | 2 +- packages/author/tests/build.test.ts | 23 +++++++--- 4 files changed, 83 insertions(+), 36 deletions(-) diff --git a/design/author.md b/design/author.md index 43dea560..ba9e5115 100644 --- a/design/author.md +++ b/design/author.md @@ -457,22 +457,30 @@ text to the content check's rules, and `apps/skills` plays every example untrust (Multiple Choice, a Single Choice Set question, a Summary set), a text with no gap (Fill in the Blanks, Drag the Words, Mark the Words), a picture with no alt text where its field is optional (`ALT_TEXTS`, held to the pack's fields by `build.test.ts`; H5P.Image's is required), - and what goes stale when a chat changes a content and keeps a setting (#268): a number of items + and what goes stale when a content is changed and a setting kept (#268): a number of items drawn at random (Question Set's `poolSize`, Memory Game's `numCardsToUse`, Crossword's `poolSize`) or to find (Find Multiple Hotspots' `numberHotspots`), said with both numbers below - the list's length, since it may be meant, and at or above it as drawing nothing now and hiding - what is added later; and a part named by what is not there: a Course Presentation button's - slide, a drop zone's right element, Agamotto's start image, a Virtual Tour's scene id, a - Personality Quiz answer's personality. A chat in ChatGPT wrote `poolSize` 3 for three - questions, added three, and the quiz went on showing three (2026-11-23). The outline's first - line says a draw's how many of how many. Video times are #260's. + the list's length, since it may be meant, and at or above it as drawing nothing now; and a part + named by what is not there: a Course Presentation button's slide, a Drag and Drop zone's right + element or an element's zone, and an element no zone it can reach takes as right, Agamotto's + start image, a Virtual Tour's scene id, a Personality Quiz answer's personality. Each note says + what its library does, read in the library's script, not its field's label: Find Multiple + Hotspots does not use a number above its hotspots, Agamotto holds a start image to those there + are, and Personality Quiz takes a name only as its personality has it, parted at ", ". In + ChatGPT a quiz of six questions came with `poolSize` 3 after the chat was asked to add + questions, and showed three (2026-11-23); whether its first source had it is not known. The + outline's first line says a draw's how many of how many. Not looked for: a select tied to the + content, as Multiple Choice's single or multiple answers; Advanced Blanks' gaps against its + list and its snippets by name; a Game Map restriction's stage id; video times (#260). Each says what to write. `lib/mistakes.mjs` runs in `checkContent`, so a build says them and so does a check of saved content, and every type file's example says none. Of the owner's 88 real packages, the 79 checked against their own libraries give 36 notes of a picture with no alt text in 8 packages, and 4 of answers alike in one, a test whose answers all read "Test"; no question with no answer marked correct, and no text with no gap. The notes of #268 fire in none - of the 88, though drop zones name their right elements in some 20 of them, and slide buttons - and a tour's scene ids are among them too. + of the 88, of which 18 hold a Course Presentation, 15 a Drag and Drop, 12 a Question Set, 2 a + Virtual Tour and 1 a Crossword; none holds a Memory Game, a Personality Quiz, an Agamotto or a + Find Multiple Hotspots, so for those four it says nothing. One Drag and Drop there names two + elements right in a zone they cannot be dropped in, beside the one they can: left unsaid. - **A source names the version of its type it was built with, and the build writes that** (#219, the owner's calls). A source handed over beside a package is built again later, on the build page or by a newer release, with a newer pack. So a build hands back the source with diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index c185d2ac..5af74a08 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -123,25 +123,30 @@ const CHECKS = { 'H5P.MultiMediaChoice'(params, path, note) { if (noneCorrect(params.options)) note(`${path}.options`, 'marks no option correct, so no learner can score: set "correct": true on the right one') }, - // `poolSize` reads as "how many questions there are", and is how many are shown: a chat wrote 3 - // for three questions, added three more, and the quiz went on showing three, drawn at random. + // `poolSize`, labelled "Number of questions to be shown", is how many are drawn at random: in + // ChatGPT a quiz of six came with it at 3 after the chat was asked to add questions (#268). 'H5P.QuestionSet'(params, path, note) { draws(params.poolSize, count(params.questions), 'questions', `${path}.poolSize`, note) }, + // An item of `cards` is a pair, and the number is of pairs (memory-game.js: the pool is cut to 2 × it). 'H5P.MemoryGame'(params, path, note) { - draws(params.behaviour?.numCardsToUse, count(params.cards), 'cards', `${path}.behaviour.numCardsToUse`, note) + draws(params.behaviour?.numCardsToUse, count(params.cards), 'pairs', `${path}.behaviour.numCardsToUse`, note) }, // Words fixed on the grid are always among those drawn; 0 means all. 'H5P.Crossword'(params, path, note) { draws(params.behaviour?.poolSize, count(params.words), 'words', `${path}.behaviour.poolSize`, note) }, + // The task ends at this many found. Above the number of hotspots, right or not, the library + // does not use it (image-multiple-hotspot-question.js). 'H5P.ImageMultipleHotspotQuestion'(params, path, note) { const settings = params.imageMultipleHotspotQuestion?.hotspotSettings const wanted = settings?.numberHotspots - const correct = Array.isArray(settings?.hotspot) ? settings.hotspot.filter((/** @type {any} */ spot) => spot?.userSettings?.correct === true).length : 0 + const spots = Array.isArray(settings?.hotspot) ? settings.hotspot : [] + const correct = spots.filter((/** @type {any} */ spot) => spot?.userSettings?.correct === true).length if (typeof wanted !== 'number' || wanted < 1 || !correct) return const at = `${path}.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots` - if (wanted > correct) note(at, `asks for ${wanted} hotspots, and ${correct} are marked correct, so no learner can finish: leave it out to ask for all of them`) + if (wanted > spots.length) note(at, `is above the number of hotspots, ${spots.length}, so it is not used: leave it out`) + else if (wanted > correct) note(at, `asks for ${wanted} hotspots, and ${correct} ${correct === 1 ? 'is' : 'are'} marked correct, so no learner can finish: leave it out, or mark more correct`) else if (wanted < correct) note(at, `ends the task once ${wanted} of the ${correct} correct hotspots are found: leave it out to ask for all of them, or tell the user`) else note(at, `is the number of correct hotspots, ${correct}, so it changes nothing, and one added later would not be asked for: leave it out`) }, @@ -154,27 +159,47 @@ const CHECKS = { slide.elements.forEach((/** @type {any} */ element, /** @type {number} */ j) => { const to = element?.goToSlide if ((element?.goToSlideType ?? 'specified') !== 'specified' || typeof to !== 'number') return - if (!Number.isInteger(to) || to < 1 || to > slides.length) note(`${path}.presentation.slides[${i}].elements[${j}].goToSlide`, `goes to slide ${to}, and there ${slides.length === 1 ? 'is 1 slide' : `are ${slides.length} slides`}, so the button goes nowhere: name a slide by its number, from 1`) + if (!Number.isInteger(to) || to < 1 || to > slides.length) note(`${path}.presentation.slides[${i}].elements[${j}].goToSlide`, `goes to slide ${to}, and there ${slides.length === 1 ? 'is 1 slide' : `are ${slides.length} slides`}, so the button has no slide to go to: name a slide by its number, from 1`) }) }) }, - // A drop zone names its right elements by their place in the list of elements, as text. + // A drop zone names its right elements, and an element the zones it can be dropped in, by + // their place in the other list, as text (h5p-drag-question.js reads both). An element that + // can be dropped in none of the zones it is right in can never be put right. One that can be + // in some of them is left: a real package of the owner's names two elements right in a zone + // they cannot reach, beside the one they can, and plays as meant. 'H5P.DragQuestion'(params, path, note) { const task = params.question?.task - const elements = count(task?.elements) - if (!Array.isArray(task?.dropZones)) return - task.dropZones.forEach((/** @type {any} */ zone, /** @type {number} */ i) => { + const elements = Array.isArray(task?.elements) ? task.elements : [] + const zones = Array.isArray(task?.dropZones) ? task.dropZones : [] + const at = `${path}.question.task` + /** @param {unknown} named @param {number} total */ + const placed = (named, total) => { const index = Number(named); return typeof named !== 'boolean' && named !== '' && Number.isInteger(index) && index >= 0 && index < total } + const none = (/** @type {number} */ total, /** @type {string} */ one) => (total === 1 ? `is 1 ${one}` : `are ${total} ${one}s`) + zones.forEach((/** @type {any} */ zone, /** @type {number} */ i) => { if (!Array.isArray(zone?.correctElements)) return zone.correctElements.forEach((/** @type {any} */ named, /** @type {number} */ j) => { - const index = Number(named) - if (!Number.isInteger(index) || index < 0 || index >= elements) note(`${path}.question.task.dropZones[${i}].correctElements[${j}]`, `names element ${JSON.stringify(named)}, and there ${elements === 1 ? 'is 1 element' : `are ${elements} elements`}, counted from 0, so no element is right there: name each by its place in elements, from 0`) + if (!placed(named, elements.length)) return note(`${at}.dropZones[${i}].correctElements[${j}]`, `names element ${JSON.stringify(named)}, and there ${none(elements.length, 'element')}, counted from 0: name each by its place in elements`) + }) + }) + elements.forEach((/** @type {any} */ element, /** @type {number} */ e) => { + if (!Array.isArray(element?.dropZones)) return + const right = zones.flatMap((/** @type {any} */ zone, /** @type {number} */ i) => (Array.isArray(zone?.correctElements) && zone.correctElements.map(String).includes(String(e)) ? [i] : [])) + const allowed = new Set(element.dropZones.map(String)) + if (right.length && !right.some((/** @type {number} */ i) => allowed.has(String(i)))) note(`${at}.elements[${e}].dropZones`, `lets the element be dropped in ${element.dropZones.length ? `zone ${element.dropZones.join(', ')}` : 'no zone'}, and it is right only in zone ${right.join(', ')}, so no learner can put it right: name ${right.length === 1 ? 'that zone' : 'one of those zones'} in its dropZones`) + }) + elements.forEach((/** @type {any} */ element, /** @type {number} */ i) => { + if (!Array.isArray(element?.dropZones)) return + element.dropZones.forEach((/** @type {any} */ named, /** @type {number} */ j) => { + if (!placed(named, zones.length)) note(`${at}.elements[${i}].dropZones[${j}]`, `names drop zone ${JSON.stringify(named)}, and there ${none(zones.length, 'drop zone')}, counted from 0: name each by its place in dropZones`) }) }) }, + // Held to the images there are (h5p-agamotto.js constrains it), so nothing breaks: it starts elsewhere than written. 'H5P.Agamotto'(params, path, note) { const start = params.behaviour?.startImage const items = count(params.items) - if (typeof start === 'number' && items && (!Number.isInteger(start) || start < 1 || start > items)) note(`${path}.behaviour.startImage`, `starts at image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}: name one by its number, from 1, or leave it out`) + if (typeof start === 'number' && items && (!Number.isInteger(start) || start < 1 || start > items)) note(`${path}.behaviour.startImage`, `is image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}, so it starts at ${start < 1 ? 'the first' : 'the last'}: name one by its number, from 1, or leave it out`) }, // A tour's scenes are named by their ids: where it starts, and where a "go to scene" leads. 'H5P.ThreeImage'(params, path, note) { @@ -182,28 +207,29 @@ const CHECKS = { if (!Array.isArray(tour?.scenes)) return const ids = new Set(tour.scenes.map((/** @type {any} */ scene) => scene?.sceneId).filter((/** @type {any} */ id) => id !== undefined)) const listed = [...ids].join(', ') - if (tour.startSceneId !== undefined && !ids.has(tour.startSceneId)) note(`${path}.threeImage.startSceneId`, `is ${tour.startSceneId}, which no scene has; the scenes' ids are ${listed}: the tour has no scene to start on`) + if (tour.startSceneId !== undefined && !ids.has(tour.startSceneId)) note(`${path}.threeImage.startSceneId`, `is ${tour.startSceneId}, which no scene has; the scenes' ids are ${listed}: name the scene the tour starts on by its sceneId`) tour.scenes.forEach((/** @type {any} */ scene, /** @type {number} */ i) => { if (!Array.isArray(scene?.interactions)) return scene.interactions.forEach((/** @type {any} */ interaction, /** @type {number} */ j) => { const action = interaction?.action const to = action?.params?.nextSceneId if (!/^H5P\.GoToScene\b/.test(String(action?.library ?? '')) || to === undefined || ids.has(to)) return - note(`${path}.threeImage.scenes[${i}].interactions[${j}].action.params.nextSceneId`, `is ${to}, which no scene has; the scenes' ids are ${listed}: it leads nowhere`) + note(`${path}.threeImage.scenes[${i}].interactions[${j}].action.params.nextSceneId`, `is ${to}, which no scene has; the scenes' ids are ${listed}: name the scene it goes to by its sceneId`) }) }) }, - // An answer names its personalities by name, a comma between them: a name that is no - // personality's counts for none, as after a personality is renamed. + // An answer names its personalities by name. The library splits the text at ", " and takes a + // name only where it is a personality's exactly (personalityQuiz.js: `split(', ')`, `===`), so + // another capital, a comma with no space after it, or a personality renamed counts for none. 'H5P.PersonalityQuiz'(params, path, note) { if (!Array.isArray(params.personalities) || !Array.isArray(params.questions)) return - const names = new Set(params.personalities.map((/** @type {any} */ one) => plain(one?.name)).filter(Boolean)) + const names = new Set(params.personalities.map((/** @type {any} */ one) => one?.name).filter((/** @type {any} */ name) => typeof name === 'string' && name)) params.questions.forEach((/** @type {any} */ question, /** @type {number} */ i) => { if (!Array.isArray(question?.answers)) return question.answers.forEach((/** @type {any} */ answer, /** @type {number} */ j) => { - if (typeof answer?.personality !== 'string') return - const unknown = answer.personality.split(',').map((/** @type {any} */ name) => name.trim()).filter((/** @type {any} */ name) => name && !names.has(plain(name))) - if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called, so the answer counts for none: name the personalities as they are called`) + if (typeof answer?.personality !== 'string' || !answer.personality) return + const unknown = answer.personality.split(', ').filter((/** @type {any} */ name) => !names.has(name)) + if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called exactly, so it counts for none: write each name as its personality has it, capitals too, with a comma and a space between two`) }) }) }, diff --git a/packages/author/lib/outline.mjs b/packages/author/lib/outline.mjs index 5023bef8..ae3cb30a 100644 --- a/packages/author/lib/outline.mjs +++ b/packages/author/lib/outline.mjs @@ -55,7 +55,7 @@ const TYPES = { 'H5P.SingleChoiceSet': { right: ['choices[].answers'] }, 'H5P.Summary': { right: ['summaries[].summary'] }, 'H5P.QuestionSet': { items: { questions: 'Question' }, titles: { questions: questionTitle }, draws: { setting: 'poolSize', list: 'questions', what: 'questions' } }, - 'H5P.MemoryGame': { draws: { setting: 'behaviour.numCardsToUse', list: 'cards', what: 'cards' } }, + 'H5P.MemoryGame': { draws: { setting: 'behaviour.numCardsToUse', list: 'cards', what: 'pairs' } }, 'H5P.Crossword': { draws: { setting: 'behaviour.poolSize', list: 'words', what: 'words' } }, 'H5P.InteractiveBook': { items: { chapters: 'Chapter' } }, 'H5P.CoursePresentation': { items: { 'presentation.slides': 'Slide' }, labels: { 'presentation.slides[].keywords[].main': 'Keyword' } }, diff --git a/packages/author/tests/build.test.ts b/packages/author/tests/build.test.ts index 256ed3e3..7807c944 100644 --- a/packages/author/tests/build.test.ts +++ b/packages/author/tests/build.test.ts @@ -660,7 +660,7 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { const at = await mkdtemp(join(dir, 'cards-')) await writeFile(join(at, 'river.png'), png(64, 48)) expect(await notesOf({ ...META, type: 'H5P.MemoryGame', params: { cards: [card('A river'), card('A lake'), card('A sea')], behaviour: { numCardsToUse: 2 } } }, at)).toEqual([ - { path: 'params.behaviour.numCardsToUse', message: 'shows 2 of the 3 cards each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + { path: 'params.behaviour.numCardsToUse', message: 'shows 2 of the 3 pairs each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } ]) const word = (clue: string, answer: string) => ({ clue, answer }) expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: [word('A long river', 'Danube'), word('Through Paris', 'Seine')], behaviour: { poolSize: 2 } } })).toEqual([ @@ -675,15 +675,28 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { { elements: [text('

Rivers

'), { goToSlideType: 'specified', goToSlide: 3, x: 10, y: 10, width: 20, height: 10 }] }, { elements: [text('

Lakes

')] } ] } } })).toEqual([ - { path: 'params.presentation.slides[0].elements[1].goToSlide', message: 'goes to slide 3, and there are 2 slides, so the button goes nowhere: name a slide by its number, from 1' } + { path: 'params.presentation.slides[0].elements[1].goToSlide', message: 'goes to slide 3, and there are 2 slides, so the button has no slide to go to: name a slide by its number, from 1' } ]) - // A Personality Quiz answer naming a personality renamed since. + // Drag and Drop: a right element and a zone that are not there, and an element that can be + // dropped in none of the zones it is right in. + const element = (text: string, zones: string[]) => ({ type: { library: 'H5P.AdvancedText', params: { text: `

${text}

` } }, x: 5, y: 5, width: 10, height: 3, dropZones: zones }) + const zone = (label: string, right: string[]) => ({ label, x: 40, y: 10, width: 20, height: 10, correctElements: right }) + expect(await notesOf({ ...META, type: 'H5P.DragQuestion', params: { question: { settings: { size: { width: 620, height: 310 } }, task: { + elements: [element('Danube', ['0']), element('Garda', ['0']), element('Seine', ['0', '3'])], + dropZones: [zone('Rivers', ['0', '2', '5']), zone('Lakes', ['1'])] + } } } })).toEqual([ + { path: 'params.question.task.dropZones[0].correctElements[2]', message: 'names element "5", and there are 3 elements, counted from 0: name each by its place in elements' }, + { path: 'params.question.task.elements[1].dropZones', message: 'lets the element be dropped in zone 0, and it is right only in zone 1, so no learner can put it right: name that zone in its dropZones' }, + { path: 'params.question.task.elements[2].dropZones[1]', message: 'names drop zone "3", and there are 2 drop zones, counted from 0: name each by its place in dropZones' } + ]) + // A Personality Quiz answer naming a personality renamed since, and one in another case: the + // library takes a name only as its personality has it, and parts two at a comma and a space. expect(await notesOf({ ...META, type: 'H5P.PersonalityQuiz', params: { titleScreen: { title: { text: 'Which traveller are you?' } }, personalities: [{ name: 'Explorer', description: 'Goes far.' }, { name: 'Builder', description: 'Makes things.' }], - questions: [{ text: 'On a free day you…', answers: [{ text: 'walk somewhere new', personality: 'Explorer' }, { text: 'fix something', personality: 'Maker, builder' }] }] + questions: [{ text: 'On a free day you…', answers: [{ text: 'walk somewhere new', personality: 'Explorer' }, { text: 'fix something', personality: 'Maker, builder' }, { text: 'do both', personality: 'Explorer, Builder' }] }] } })).toEqual([ - { path: 'params.questions[0].answers[1].personality', message: 'names "Maker", which no personality is called, so the answer counts for none: name the personalities as they are called' } + { path: 'params.questions[0].answers[1].personality', message: 'names "Maker", "builder", which no personality is called exactly, so it counts for none: write each name as its personality has it, capitals too, with a comma and a space between two' } ]) }) From 167f5d2302c6fdfc3194fcc5bc3854aeafe76f83 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 22:37:47 +0200 Subject: [PATCH 4/6] fix(author): a crossword's fixed words, and Question Set's shuffle, are counted as their libraries draw, and the outline test covers a memory game (#268) One function, drawOf, works out what each draw shows, read in its library's script, for the notes and the outline's first line both: - Crossword keeps the words fixed on the grid and draws only among the rest, so with fixed words it shows them and some of the others, or the fixed words alone where they reach poolSize; a word without an answer or a clue is not counted; - Question Set shuffles the questions whenever poolSize is set, so at or above the number of questions the note says they show in a random order; - Memory Game draws at least 2 pairs. The outline test now builds a memory game, as its title says. --- design/author.md | 5 +- packages/author/lib/mistakes.mjs | 82 +++++++++++++++++++++------ packages/author/lib/outline.mjs | 27 ++++----- packages/author/tests/build.test.ts | 18 ++++-- packages/author/tests/confine.test.ts | 7 +++ 5 files changed, 101 insertions(+), 38 deletions(-) diff --git a/design/author.md b/design/author.md index ba9e5115..6a704bc6 100644 --- a/design/author.md +++ b/design/author.md @@ -469,7 +469,10 @@ text to the content check's rules, and `apps/skills` plays every example untrust are, and Personality Quiz takes a name only as its personality has it, parted at ", ". In ChatGPT a quiz of six questions came with `poolSize` 3 after the chat was asked to add questions, and showed three (2026-11-23); whether its first source had it is not known. The - outline's first line says a draw's how many of how many. Not looked for: a select tied to the + outline's first line says a draw's how many of how many. One function, `drawOf`, works + out what each draw shows, for the notes and the outline: Question Set shuffles whenever + `poolSize` is set, Memory Game draws pairs, at least 2, and Crossword keeps the words fixed on + the grid and draws only among the rest. Not looked for: a select tied to the content, as Multiple Choice's single or multiple answers; Advanced Blanks' gaps against its list and its snippets by name; a Game Map restriction's stage id; video times (#260). Each says what to write. `lib/mistakes.mjs` runs in `checkContent`, so a build says them and so diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index 5af74a08..8c60536a 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -30,20 +30,68 @@ function plain(value) { const count = (value) => (Array.isArray(value) ? value.length : 0) /** - * A number of items drawn at random from a list, against how many the list holds. Below it, which - * may be meant, both numbers are said; at or above it, it draws nothing now, and leaves items out - * at random once more are added: what a chat that adds items and keeps the setting gets (#268). - * @param {unknown} drawn - * @param {number} total - * @param {string} what the items, as "questions" - * @param {string} at the setting's path - * @param {Note} note + * What a draw shows, where a setting shows some of a list's items picked at random each time, as + * each library works it out (#268): + * - Question Set (questionset.js): `poolSize` above 0 shuffles the questions and keeps that many, + * so it also shows them in a random order where it keeps them all. + * - Memory Game (memory-game.js): `numCardsToUse` pairs, at least 2. + * - Crossword (h5p-crossword.js): `poolSize` 0 is all, else at least 2; the words fixed on the + * grid are always kept, and the others drawn to make up the rest; a word without an answer or + * a clue is left out first. + * @param {string} library + * @param {unknown} params as H5P stores them + * @returns {{ at: string, what: string, used: number, total: number, shown: number, fixed: number, shuffles: boolean } | null} + * `at`, the setting's path in the parameters; `used`, the number the library draws; null where + * nothing is drawn + * @internal */ -function draws(drawn, total, what, at, note) { - if (!total || typeof drawn !== 'number' || drawn < 1) return - if (drawn < total) note(at, `shows ${drawn} of the ${total} ${what} each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) - else if (drawn === total) note(at, `is the number of ${what}, ${total}, so it draws nothing, and one added later would leave one out at random: leave it out`) - else note(at, `is above the number of ${what}, ${total}, so it draws nothing until more than ${drawn} are, and then leaves some out at random: leave it out`) +export function drawOf(library, params) { + if (!isObject(params)) return null + if (library === 'H5P.QuestionSet') { + const total = count(params.questions) + if (typeof params.poolSize !== 'number' || !(params.poolSize > 0) || !total) return null + const used = Math.ceil(params.poolSize) + return { at: 'poolSize', what: 'questions', used, total, shown: Math.min(used, total), fixed: 0, shuffles: true } + } + if (library === 'H5P.MemoryGame') { + const total = count(params.cards) + const setting = params.behaviour?.numCardsToUse + if (typeof setting !== 'number' || !(setting >= 1) || !total) return null + const used = Math.max(2, Math.trunc(setting)) + return { at: 'behaviour.numCardsToUse', what: 'pairs', used, total, shown: Math.min(used, total), fixed: 0, shuffles: false } + } + if (library === 'H5P.Crossword') { + const setting = params.behaviour?.poolSize + const words = Array.isArray(params.words) ? params.words.filter((/** @type {any} */ word) => word?.answer && word?.clue) : [] + if (typeof setting !== 'number' || !setting || !words.length) return null + const used = Math.max(2, setting) + const fixed = words.filter((/** @type {any} */ word) => word.fixWord && word.row !== undefined && word.column !== undefined && word.orientation !== undefined).length + const shown = fixed + Math.min(Math.max(0, used - fixed), words.length - fixed) + return { at: 'behaviour.poolSize', what: 'words', used, total: words.length, shown, fixed, shuffles: false } + } + return null +} + +/** + * A draw's note: below the list's length, what it shows, since it may be meant; at or above it, + * that it leaves none out now and would once items are added, what a chat that adds items and + * keeps the setting gets. + * @param {string} library @param {Record} params @param {string} path @param {Note} note + */ +function noteDraw(library, params, path, note) { + const draw = drawOf(library, params) + if (!draw) return + const { what, used, total, shown, fixed } = draw + const at = `${path}.${draw.at}` + const order = draw.shuffles ? ' but shows them in a random order' : '' + const random = draw.shuffles ? ', and set randomQuestions for a random order' : '' + if (shown < total) { + if (!fixed) note(at, `shows ${shown} of the ${total} ${what} each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) + else if (shown === fixed) note(at, `shows only the ${fixed} ${what} fixed on the grid, and never the other ${total - fixed}: leave it out to show them all`) + else note(at, `shows ${shown} of the ${total} ${what} each time, the ${fixed} fixed on the grid and ${shown - fixed} of the other ${total - fixed} drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws`) + } + else if (used === total) note(at, `is the number of ${what}, ${total}, so it leaves none out${order}, and one added later would leave one out at random: leave it out${random}`) + else note(at, `is above the number of ${what}, ${total}, so it leaves none out${order} until more than ${used} are, and then leaves some out at random: leave it out${random}`) } /** @@ -126,15 +174,13 @@ const CHECKS = { // `poolSize`, labelled "Number of questions to be shown", is how many are drawn at random: in // ChatGPT a quiz of six came with it at 3 after the chat was asked to add questions (#268). 'H5P.QuestionSet'(params, path, note) { - draws(params.poolSize, count(params.questions), 'questions', `${path}.poolSize`, note) + noteDraw('H5P.QuestionSet', params, path, note) }, - // An item of `cards` is a pair, and the number is of pairs (memory-game.js: the pool is cut to 2 × it). 'H5P.MemoryGame'(params, path, note) { - draws(params.behaviour?.numCardsToUse, count(params.cards), 'pairs', `${path}.behaviour.numCardsToUse`, note) + noteDraw('H5P.MemoryGame', params, path, note) }, - // Words fixed on the grid are always among those drawn; 0 means all. 'H5P.Crossword'(params, path, note) { - draws(params.behaviour?.poolSize, count(params.words), 'words', `${path}.behaviour.poolSize`, note) + noteDraw('H5P.Crossword', params, path, note) }, // The task ends at this many found. Above the number of hotspots, right or not, the library // does not use it (image-multiple-hotspot-question.js). diff --git a/packages/author/lib/outline.mjs b/packages/author/lib/outline.mjs index ae3cb30a..1233b29f 100644 --- a/packages/author/lib/outline.mjs +++ b/packages/author/lib/outline.mjs @@ -1,5 +1,6 @@ import { isInterfaceText } from './schema.mjs' import { decodeEntities, editorWidget, tagsIn, takesMarkup } from './text.mjs' +import { drawOf } from './mistakes.mjs' import { questionTitle } from './types.mjs' /** @@ -42,21 +43,15 @@ const UNLABELLED = new Set(['text', 'question']) * - `links`: a scenario's `nextContentId`, the index of the content a choice or a content leads * to, negative for the end; and `endScreenScore`, the score an end gives. * - `labels`: a label for a field whose semantics give none. - * - `draws`: a setting that shows only some of a list's items, drawn at random each time, a - * number a chat that adds items may leave as it was (#268): the type's first line says how many - * of how many, where it is below the list's length. * @type {Record, titles?: Record string>, - * times?: Record, links?: boolean, labels?: Record, - * draws?: { setting: string, list: string, what: string } + * times?: Record, links?: boolean, labels?: Record * }>} */ const TYPES = { 'H5P.SingleChoiceSet': { right: ['choices[].answers'] }, 'H5P.Summary': { right: ['summaries[].summary'] }, - 'H5P.QuestionSet': { items: { questions: 'Question' }, titles: { questions: questionTitle }, draws: { setting: 'poolSize', list: 'questions', what: 'questions' } }, - 'H5P.MemoryGame': { draws: { setting: 'behaviour.numCardsToUse', list: 'cards', what: 'pairs' } }, - 'H5P.Crossword': { draws: { setting: 'behaviour.poolSize', list: 'words', what: 'words' } }, + 'H5P.QuestionSet': { items: { questions: 'Question' }, titles: { questions: questionTitle } }, 'H5P.InteractiveBook': { items: { chapters: 'Chapter' } }, 'H5P.CoursePresentation': { items: { 'presentation.slides': 'Slide' }, labels: { 'presentation.slides[].keywords[].main': 'Keyword' } }, 'H5P.BranchingScenario': { items: { 'branchingScenario.content': 'Content', 'branchingScenario.endScreens': 'End screen' }, links: true }, @@ -67,9 +62,6 @@ const TYPES = { } } -/** A value at a dotted path in parameters. @param {Record} params @param {string} path */ -const valueAt = (params, path) => path.split('.').reduce((/** @type {any} */ value, name) => (isObject(value) ? value[name] : undefined), params) - /** The kinds of file field, as a line names them. */ const MEDIA = /** @type {Record} */ ({ image: 'Image', video: 'Video', audio: 'Audio', file: 'File' }) @@ -179,10 +171,15 @@ export function outlineOf(libraries, content, { limit = Infinity } = {}) { if (!isObject(params)) return if (!path) { semanticsOf.set(type, fields) - const draws = TYPES[type]?.draws - const drawn = draws && valueAt(params, draws.setting) - const items = draws && valueAt(params, draws.list) - if (draws && typeof drawn === 'number' && drawn >= 1 && Array.isArray(items) && drawn < items.length) emit(depth, `Shows ${drawn} of the ${items.length} ${draws.what} each time, drawn at random`) + // A setting that shows only some of a list's items, which a chat that adds items may keep + // as it was (#268): the type's first line says how many of how many, as its library draws. + const draw = drawOf(type, params) + if (draw && draw.shown < draw.total) { + const { shown, total, fixed, what } = draw + emit(depth, !fixed ? `Shows ${shown} of the ${total} ${what} each time, drawn at random` + : shown === fixed ? `Shows only the ${fixed} ${what} fixed on the grid, of ${total}` + : `Shows ${shown} of the ${total} ${what} each time: the ${fixed} fixed on the grid, and ${shown - fixed} drawn at random`) + } } for (const field of fields) walk(field, params[field.name], depth, type, path ? `${path}.${field.name}` : field.name, bare, params) } diff --git a/packages/author/tests/build.test.ts b/packages/author/tests/build.test.ts index 7807c944..245a9933 100644 --- a/packages/author/tests/build.test.ts +++ b/packages/author/tests/build.test.ts @@ -645,12 +645,13 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { expect(await quiz(2)).toEqual([ { path: 'params.poolSize', message: 'shows 2 of the 3 questions each time, drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } ]) - // As many as there are draws nothing, and is what hides a question added later; more, once there are more still. + // As many as there are leaves none out, though Question Set still shuffles them, and is what + // hides a question added later; more, once there are more still. expect(await quiz(3)).toEqual([ - { path: 'params.poolSize', message: 'is the number of questions, 3, so it draws nothing, and one added later would leave one out at random: leave it out' } + { path: 'params.poolSize', message: 'is the number of questions, 3, so it leaves none out but shows them in a random order, and one added later would leave one out at random: leave it out, and set randomQuestions for a random order' } ]) expect(await quiz(5)).toEqual([ - { path: 'params.poolSize', message: 'is above the number of questions, 3, so it draws nothing until more than 5 are, and then leaves some out at random: leave it out' } + { path: 'params.poolSize', message: 'is above the number of questions, 3, so it leaves none out but shows them in a random order until more than 5 are, and then leaves some out at random: leave it out, and set randomQuestions for a random order' } ]) expect(await quiz()).toEqual([]) }) @@ -664,7 +665,16 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { ]) const word = (clue: string, answer: string) => ({ clue, answer }) expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: [word('A long river', 'Danube'), word('Through Paris', 'Seine')], behaviour: { poolSize: 2 } } })).toEqual([ - { path: 'params.behaviour.poolSize', message: 'is the number of words, 2, so it draws nothing, and one added later would leave one out at random: leave it out' } + { path: 'params.behaviour.poolSize', message: 'is the number of words, 2, so it leaves none out, and one added later would leave one out at random: leave it out' } + ]) + // Words fixed on the grid are always kept, and the others drawn to make up the rest. + const fixed = (clue: string, answer: string, row: number) => ({ clue, answer, fixWord: true, row, column: 1, orientation: 'across' }) + const fourWords = [fixed('A long river', 'Danube', 1), fixed('Through Paris', 'Seine', 3), word('Through Rome', 'Tiber'), word('Through London', 'Thames')] + expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: fourWords, behaviour: { poolSize: 3 } } })).toEqual([ + { path: 'params.behaviour.poolSize', message: 'shows 3 of the 4 words each time, the 2 fixed on the grid and 1 of the other 2 drawn at random, and leaves the rest out: leave it out to show them all, or tell the user that it draws' } + ]) + expect(await notesOf({ ...META, type: 'H5P.Crossword', params: { words: fourWords, behaviour: { poolSize: 2 } } })).toEqual([ + { path: 'params.behaviour.poolSize', message: 'shows only the 2 words fixed on the grid, and never the other 2: leave it out to show them all' } ]) }) diff --git a/packages/author/tests/confine.test.ts b/packages/author/tests/confine.test.ts index ed70ac58..db78e132 100644 --- a/packages/author/tests/confine.test.ts +++ b/packages/author/tests/confine.test.ts @@ -293,6 +293,13 @@ describe('outline', () => { expect((await outline({ type: 'H5P.QuestionSet', params: { questions, poolSize: 3 } })).split('\n')[0]).toBe(' Question 1') const words = [{ clue: 'A long river', answer: 'Danube' }, { clue: 'Through Paris', answer: 'Seine' }, { clue: 'Through Rome', answer: 'Tiber' }] expect((await outline({ type: 'H5P.Crossword', params: { words, behaviour: { poolSize: 2 } } })).split('\n')[0]).toBe('Shows 2 of the 3 words each time, drawn at random') + // A crossword's words fixed on the grid are always among them. + const fixedWords = [{ ...words[0], fixWord: true, row: 1, column: 1, orientation: 'across' }, ...words.slice(1)] + expect((await outline({ type: 'H5P.Crossword', params: { words: fixedWords, behaviour: { poolSize: 2 } } })).split('\n')[0]).toBe('Shows 2 of the 3 words each time: the 1 fixed on the grid, and 1 drawn at random') + // A memory game counts pairs. + const pair = (alt: string) => ({ image: { path: 'in.png' }, imageAlt: alt }) + const game = await buildPackage({ ...META, type: 'H5P.MemoryGame', params: { cards: [pair('A river'), pair('A lake'), pair('A sea')], behaviour: { numCardsToUse: 2 } } }, undefined, { check: true, base: allowed }) + expect(game.outline.split('\n')[0]).toBe('Shows 2 of the 3 pairs each time, drawn at random') }) it('keeps a text\'s paragraphs, lines and list items apart, and numbers slides, with each slide\'s keyword', async () => { From 2f8bbf1ba9aca177b666472613036886a3036ed0 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 22:41:17 +0200 Subject: [PATCH 5/6] fix(author): a Personality Quiz answer's known names still count, and Agamotto's note leaves out a fraction the build refuses (#268) - Personality Quiz counts each name of an answer on its own, so an answer that names one personality wrongly still counts for the others: the note says that name, or those names, count for none, not the answer. An empty part, after a comma at the end, names nothing and is not said. - Agamotto's startImage takes a whole number, which the build holds it to, so a fraction never reaches the note: the note no longer reads one, and a test shows the build refuses it. --- packages/author/lib/mistakes.mjs | 16 ++++++++++------ packages/author/tests/build.test.ts | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index 8c60536a..6cc15c02 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -241,11 +241,13 @@ const CHECKS = { }) }) }, - // Held to the images there are (h5p-agamotto.js constrains it), so nothing breaks: it starts elsewhere than written. + // Held to the images there are (h5p-agamotto.js constrains it), so nothing breaks: it starts + // elsewhere than written. A fraction never gets here: its field takes a whole number, which + // the build holds it to. 'H5P.Agamotto'(params, path, note) { const start = params.behaviour?.startImage const items = count(params.items) - if (typeof start === 'number' && items && (!Number.isInteger(start) || start < 1 || start > items)) note(`${path}.behaviour.startImage`, `is image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}, so it starts at ${start < 1 ? 'the first' : 'the last'}: name one by its number, from 1, or leave it out`) + if (typeof start === 'number' && items && (start < 1 || start > items)) note(`${path}.behaviour.startImage`, `is image ${start}, and there ${items === 1 ? 'is 1 image' : `are ${items} images`}, so it starts at the ${start < 1 ? 'first' : 'last'}: name one by its number, from 1, or leave it out`) }, // A tour's scenes are named by their ids: where it starts, and where a "go to scene" leads. 'H5P.ThreeImage'(params, path, note) { @@ -264,9 +266,10 @@ const CHECKS = { }) }) }, - // An answer names its personalities by name. The library splits the text at ", " and takes a + // An answer names its personalities by name. The library splits the text at ", " and counts a // name only where it is a personality's exactly (personalityQuiz.js: `split(', ')`, `===`), so - // another capital, a comma with no space after it, or a personality renamed counts for none. + // another capital, a comma with no space after it, or a personality renamed counts for none; + // the answer's other names still count. 'H5P.PersonalityQuiz'(params, path, note) { if (!Array.isArray(params.personalities) || !Array.isArray(params.questions)) return const names = new Set(params.personalities.map((/** @type {any} */ one) => one?.name).filter((/** @type {any} */ name) => typeof name === 'string' && name)) @@ -274,8 +277,9 @@ const CHECKS = { if (!Array.isArray(question?.answers)) return question.answers.forEach((/** @type {any} */ answer, /** @type {number} */ j) => { if (typeof answer?.personality !== 'string' || !answer.personality) return - const unknown = answer.personality.split(', ').filter((/** @type {any} */ name) => !names.has(name)) - if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called exactly, so it counts for none: write each name as its personality has it, capitals too, with a comma and a space between two`) + // An empty part, after a comma at the end, names nothing and is not said. + const unknown = answer.personality.split(', ').filter((/** @type {any} */ name) => name && !names.has(name)) + if (unknown.length) note(`${path}.questions[${i}].answers[${j}].personality`, `names ${unknown.map((/** @type {any} */ name) => JSON.stringify(name)).join(', ')}, which no personality is called exactly, so ${unknown.length === 1 ? 'that name counts' : 'those names count'} for none: write each name as its personality has it, capitals too, with a comma and a space between two`) }) }) }, diff --git a/packages/author/tests/build.test.ts b/packages/author/tests/build.test.ts index 245a9933..45a3d79b 100644 --- a/packages/author/tests/build.test.ts +++ b/packages/author/tests/build.test.ts @@ -687,6 +687,16 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { ] } } })).toEqual([ { path: 'params.presentation.slides[0].elements[1].goToSlide', message: 'goes to slide 3, and there are 2 slides, so the button has no slide to go to: name a slide by its number, from 1' } ]) + // Agamotto: a start image past the last is held to the last; a fraction is refused already. + const at = await mkdtemp(join(dir, 'agamotto-')) + await writeFile(join(at, 'river.png'), png(64, 48)) + const image = (alt: string) => ({ image: { library: 'H5P.Image', params: { file: { path: 'river.png' }, alt } }, labelText: alt }) + const agamotto = (startImage: number) => notesOf({ ...META, type: 'H5P.Agamotto', params: { items: [image('Spring'), image('Summer')], behaviour: { startImage } } }, at) + expect(await agamotto(3)).toEqual([ + { path: 'params.behaviour.startImage', message: 'is image 3, and there are 2 images, so it starts at the last: name one by its number, from 1, or leave it out' } + ]) + await expect(agamotto(1.5)).rejects.toThrow('params.behaviour.startImage: takes a whole number') + expect(await agamotto(2)).toEqual([]) // Drag and Drop: a right element and a zone that are not there, and an element that can be // dropped in none of the zones it is right in. const element = (text: string, zones: string[]) => ({ type: { library: 'H5P.AdvancedText', params: { text: `

${text}

` } }, x: 5, y: 5, width: 10, height: 3, dropZones: zones }) @@ -704,9 +714,11 @@ describe('notes for what builds and is almost surely a mistake (#241)', () => { expect(await notesOf({ ...META, type: 'H5P.PersonalityQuiz', params: { titleScreen: { title: { text: 'Which traveller are you?' } }, personalities: [{ name: 'Explorer', description: 'Goes far.' }, { name: 'Builder', description: 'Makes things.' }], - questions: [{ text: 'On a free day you…', answers: [{ text: 'walk somewhere new', personality: 'Explorer' }, { text: 'fix something', personality: 'Maker, builder' }, { text: 'do both', personality: 'Explorer, Builder' }] }] + questions: [{ text: 'On a free day you…', answers: [{ text: 'walk somewhere new', personality: 'Explorer' }, { text: 'fix something', personality: 'Maker, builder' }, { text: 'do both', personality: 'Explorer, Builder, ' }, { text: 'roam', personality: 'Explorer, Wanderer' }] }] } })).toEqual([ - { path: 'params.questions[0].answers[1].personality', message: 'names "Maker", "builder", which no personality is called exactly, so it counts for none: write each name as its personality has it, capitals too, with a comma and a space between two' } + { path: 'params.questions[0].answers[1].personality', message: 'names "Maker", "builder", which no personality is called exactly, so those names count for none: write each name as its personality has it, capitals too, with a comma and a space between two' }, + // A comma at the end names nothing; a known name beside an unknown one still counts. + { path: 'params.questions[0].answers[3].personality', message: 'names "Wanderer", which no personality is called exactly, so that name counts for none: write each name as its personality has it, capitals too, with a comma and a space between two' } ]) }) From 0ba385b070c6cf89870d7f3aacf327e50c13b9b0 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 22:47:10 +0200 Subject: [PATCH 6/6] fix(author): drawOf drops a fraction as Question Set and Crossword do (#268) Question Set keeps slice(0, poolSize) questions, and Crossword splices to its number, both of which drop a fraction: drawOf rounded Question Set's up. A build holds both fields to whole numbers, so this reaches only a check of saved content. --- packages/author/lib/mistakes.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/author/lib/mistakes.mjs b/packages/author/lib/mistakes.mjs index 6cc15c02..da5a4491 100644 --- a/packages/author/lib/mistakes.mjs +++ b/packages/author/lib/mistakes.mjs @@ -50,7 +50,8 @@ export function drawOf(library, params) { if (library === 'H5P.QuestionSet') { const total = count(params.questions) if (typeof params.poolSize !== 'number' || !(params.poolSize > 0) || !total) return null - const used = Math.ceil(params.poolSize) + // `slice(0, poolSize)`, which drops a fraction. + const used = Math.trunc(params.poolSize) return { at: 'poolSize', what: 'questions', used, total, shown: Math.min(used, total), fixed: 0, shuffles: true } } if (library === 'H5P.MemoryGame') { @@ -64,7 +65,8 @@ export function drawOf(library, params) { const setting = params.behaviour?.poolSize const words = Array.isArray(params.words) ? params.words.filter((/** @type {any} */ word) => word?.answer && word?.clue) : [] if (typeof setting !== 'number' || !setting || !words.length) return null - const used = Math.max(2, setting) + // `Math.max(2, poolSize)`, then a `splice` that drops a fraction. + const used = Math.trunc(Math.max(2, setting)) const fixed = words.filter((/** @type {any} */ word) => word.fixWord && word.row !== undefined && word.column !== undefined && word.orientation !== undefined).length const shown = fixed + Math.min(Math.max(0, used - fixed), words.length - fixed) return { at: 'behaviour.poolSize', what: 'words', used, total: words.length, shown, fixed, shuffles: false }