kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

QTI contains operator ignores order for ordered containers

Open Rishika-dev opened this issue 3 weeks ago • 3 comments

🙂 Looking for an issue? Welcome! This issue is open for contribution. If this is the first time you’re requesting an issue, please:

  • Read Contributing guidelines carefully. Pay extra attention to Using generative AI. Pull requests and comments that don’t follow the guidelines won’t be answered.
  • Confirm that you’ve read the guidelines in your comment.

Target branch: develop

Observed behavior

For ordered containers, qti-contains ignores order. [A,B,C] is reported to contain both [C,A] and [A,C].

The evaluator works out that the second operand is ordered (subCardinality), but then always uses multiset containment, which counts values without regard to order:

https://github.com/learningequality/kolibri/blob/07e85c89ef/kolibri/plugins/qti_viewer/frontend/utils/qti/evaluator.js#L641-L684

The comment at the top of the case already describes the rule, "strict sub-sequence (ordered)":

https://github.com/learningequality/kolibri/blob/07e85c89ef/kolibri/plugins/qti_viewer/frontend/utils/qti/evaluator.js#L625-L628

The spec (2.11.3.17 Contains Expression): "For ordered containers the second sub-expression must be a strict sub-sequence within the first. In other words, [A,B,C] does not contain [C,A] but it does contain [B,C]."

No test covers contains with ordered containers.

Expected behavior

When both operands are ordered, qti-contains is true only if the second appears as a run of consecutive values, in the same order, within the first:

  • [A,B,C] contains [B,C]: true
  • [A,B,C] contains [C,A]: false
  • [A,B,C] contains [A,C]: false

Unordered (multiple) containers keep the current multiset behavior.

User-facing consequences

contains on ordered responses is how an author gives credit for part of a sequence, for example "B directly followed by C" in an order interaction. Because order is ignored, a learner who puts those choices in the wrong order or apart still gets that credit, and the item scores a wrong answer as right.

Steps to reproduce

const xml = '<qti-contains><qti-variable identifier="R"/><qti-variable identifier="S"/></qti-contains>';
const doc = new DOMParser().parseFromString(xml, 'text/xml');
const ordered = { cardinality: 'ordered', baseType: 'identifier' };
evaluateNode(doc.documentElement, { R: ['A', 'B', 'C'], S: ['C', 'A'] }, { R: ordered, S: ordered });
// returns true; the spec gives false
evaluateNode(doc.documentElement, { R: ['A', 'B', 'C'], S: ['A', 'C'] }, { R: ordered, S: ordered });
// returns true; the spec gives false

Context

  • Kolibri develop at 07e85c89ef

Possible fix, which I'd be glad to work on: when subCardinality is ordered, check for a contiguous sub-sequence using qtiValuesEqual for each element, so pairs still compare correctly. Add tests for the spec's examples.

AI usage

I found this while comparing the QTI evaluator's operators with the QTI 3.0 spec, and confirmed the results above with a Jest test. I used an AI coding assistant to help with the comparison and the write-up.

Rishika-dev avatar Nov 08 '26 19:11 Rishika-dev

🔍 Thanks for opening this issue! @rtibblesbot will check it against the code and comment with its findings.

What happens next:

  • The community-issue-review label stays on until the review comment is posted.
  • The comment identifies the files, lines, or commits examined so you can follow the reasoning and respond if you disagree.
  • If the check confirms the issue, @rtibblesbot may also correct the title and description. GitHub preserves the edit history, so the original text remains available.
  • @rtibblesbot's comments are LLM-generated, so please evaluate them critically.

A maintainer decides what happens next. This check does not close the issue.

learning-equality-bot avatar Nov 08 '26 19:11 learning-equality-bot

Verdict: claim holds Evidence: kolibri/plugins/qti_viewer/frontend/utils/qti/evaluator.js:621-684 at 07e85c89ef (develop HEAD)

  • case 'contains' sets subCardinality to ORDERED for an ordered variable declaration or a qti-ordered/qti-repeat sub-expression (lines 641-658), but uses it only to decide whether sub is a single value (lines 664-666).
  • Every sub-container then takes the multiset count at lines 670-683, so [A,B,C] contains [C,A] and [A,C] → true, as the report states.
  • The comment at lines 625-628 names "strict sub-sequence (ordered)", which the code never implements.
  • evaluator.spec.js has no contains test with ordered cardinality; its contains suites (lines 675, 2489, 2829, 3107) declare or build only multiple containers or single values.
  • The qti-ordered positional test at line 2884 covers match, not contains.
  • Related but separate: #15803 (qti-delete operand order).

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 09 '26 00:11 rtibblesbot

Opened the fix: https://github.com/learningequality/kolibri/pull/15960

Rishika-dev avatar Nov 19 '26 17:11 Rishika-dev