@learnosity/lib-qti-converter 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +263 -0
- package/docs/DIAGNOSTICS.md +263 -0
- package/docs/EXAMPLES.md +869 -0
- package/docs/FAQ.md +415 -0
- package/docs/GETTING_STARTED.md +471 -0
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +338 -0
- package/docs/LEARNOSITY_SECTIONS.md +384 -0
- package/docs/QTI_METADATA_TO_TAGS.md +266 -0
- package/docs/QTI_STRUCTURE.md +353 -0
- package/docs/ROADMAP.md +232 -0
- package/docs/SUPPORTED_INTERACTIONS.md +601 -0
- package/docs/_sidebar.md +13 -0
- package/package.json +90 -0
- package/packages/cli/dist/main.js +45610 -0
- package/packages/core/dist/index.d.ts +2658 -0
- package/packages/core/dist/index.js +31706 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Learnosity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# QTI ↔ Learnosity Converter
|
|
2
|
+
|
|
3
|
+
A TypeScript tool for converting between QTI (Question & Test Interoperability) and Learnosity JSON formats. Use it as a **CLI tool** on the command line, or as a **library** imported into your own Node.js project.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
- **[Getting Started](https://learnosity.github.io/lib-qti-converter/#/GETTING_STARTED)** - Installation, quick start (CLI and library), and basic workflow
|
|
8
|
+
- **[QTI Structure](https://learnosity.github.io/lib-qti-converter/#/QTI_STRUCTURE)** - Support for QTI structural elements (assessmentItem, assessmentTest, assessmentSection, testPart)
|
|
9
|
+
- **[Diagnostics](https://learnosity.github.io/lib-qti-converter/#/DIAGNOSTICS)** - Understanding diagnostic messages and the diagnostics file
|
|
10
|
+
- **[Supported Interactions](https://learnosity.github.io/lib-qti-converter/#/SUPPORTED_INTERACTIONS)** - Complete list of QTI ↔ Learnosity mappings
|
|
11
|
+
- **[Learnosity Bundle Format](https://learnosity.github.io/lib-qti-converter/#/LEARNOSITY_BUNDLE_FORMAT)** - Expected input format for Learnosity → QTI conversion
|
|
12
|
+
- **[Learnosity Sections](https://learnosity.github.io/lib-qti-converter/#/LEARNOSITY_SECTIONS)** - How Learnosity activity sections map to QTI assessmentTest structure
|
|
13
|
+
- **[Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES)** - CLI and programmatic usage examples
|
|
14
|
+
- **[FAQ](https://learnosity.github.io/lib-qti-converter/#/FAQ)** - Troubleshooting and common questions
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- Node.js >= 22.0.0
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @learnosity/lib-qti-converter
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This single install gives you both the CLI tool and the importable library. All dependencies are bundled — there's nothing else to install.
|
|
27
|
+
|
|
28
|
+
### For Contributors (from source)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git clone <repository-url>
|
|
32
|
+
cd lib-qti-converter
|
|
33
|
+
pnpm install
|
|
34
|
+
pnpm run build
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### CLI Usage
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Install globally for CLI access
|
|
43
|
+
npm install -g @learnosity/lib-qti-converter
|
|
44
|
+
|
|
45
|
+
# Convert QTI to Learnosity
|
|
46
|
+
lcon qti-to-learnosity --in item.xml --out item.json --pretty
|
|
47
|
+
|
|
48
|
+
# Convert Learnosity to QTI
|
|
49
|
+
lcon learnosity-to-qti --in item.json --out item.xml
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Library Usage
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { convertQtiToLearnosity } from '@learnosity/lib-qti-converter';
|
|
56
|
+
|
|
57
|
+
const result = await convertQtiToLearnosity(qtiXmlString, {
|
|
58
|
+
qtiVersion: '2.2',
|
|
59
|
+
outputFormat: 'dir',
|
|
60
|
+
diagnostics: 'none',
|
|
61
|
+
verbose: false,
|
|
62
|
+
pretty: true,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
console.log(result.output); // Converted Learnosity JSON
|
|
66
|
+
console.log(result.diagnostics); // Array of diagnostic messages
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
See [Getting Started](https://learnosity.github.io/lib-qti-converter/#/GETTING_STARTED) for detailed instructions and [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) for more usage scenarios.
|
|
70
|
+
|
|
71
|
+
## Available Commands (CLI)
|
|
72
|
+
|
|
73
|
+
The CLI provides four main conversion commands:
|
|
74
|
+
|
|
75
|
+
- **`qti-to-learnosity`** - Convert QTI XML to Learnosity JSON
|
|
76
|
+
- **`qti-package-to-learnosity`** - Convert QTI Content Package to Learnosity bundle
|
|
77
|
+
- **`learnosity-to-qti`** - Convert Learnosity JSON to QTI XML
|
|
78
|
+
- **`learnosity-to-qti-package`** - Convert Learnosity bundle to QTI Content Package
|
|
79
|
+
|
|
80
|
+
**Batch Processing:** The package conversion commands (`qti-package-to-learnosity` and `learnosity-to-qti-package`) support a `--recursive` flag to convert multiple packages in subdirectories with a single command. See [Examples - Batch Processing](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES?id=10-batch-processing-with-recursive-flag) for details.
|
|
81
|
+
|
|
82
|
+
Run `lcon <command> --help` for detailed options, or see [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) for usage scenarios.
|
|
83
|
+
|
|
84
|
+
## QTI Validation (not bundled)
|
|
85
|
+
|
|
86
|
+
After converting Learnosity to QTI, you can validate the generated QTI XML against the official IMS XSD schemas:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Validate all QTI XML files in a directory
|
|
90
|
+
npm run validate:qti output/qti/
|
|
91
|
+
|
|
92
|
+
# Validate a specific file
|
|
93
|
+
npm run validate:qti output/qti/item.xml
|
|
94
|
+
|
|
95
|
+
# Debug mode to see schema resolution details
|
|
96
|
+
npm run validate:qti:debug output/qti/
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Note: the validation script requires Python and lxml library to be installed.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm run setup:python
|
|
103
|
+
npm run validate:qti output/qti/
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Features:**
|
|
107
|
+
|
|
108
|
+
- Uses **local XSD schemas** (not remote) via XML catalog
|
|
109
|
+
- Automatically detects file types and uses appropriate schemas:
|
|
110
|
+
- QTI items/tests → **QTI 2.2** schema (`imsqti_v2p2p4.xsd`)
|
|
111
|
+
- Manifest files → **IMS Content Packaging v1.1.4** schema (`imscp_v1p1.xsd`)
|
|
112
|
+
- LOM metadata → **IMS Learning Resource Metadata v1.2.4** schema (`imsmd_v1p2p4.xsd`)
|
|
113
|
+
|
|
114
|
+
**Schema Versions:**
|
|
115
|
+
|
|
116
|
+
When generating QTI Content Packages, we use the following IMS specifications:
|
|
117
|
+
|
|
118
|
+
| Component | Specification | Version | Schema File |
|
|
119
|
+
| ---------------- | ------------------------------------ | ----------- | ------------------- |
|
|
120
|
+
| QTI Items/Tests | IMS Question & Test Interoperability | 2.2 Patch 4 | `imsqti_v2p2p4.xsd` |
|
|
121
|
+
| Package Manifest | IMS Content Packaging | 1.1.4 | `imscp_v1p1.xsd` |
|
|
122
|
+
| LOM Metadata | IMS Learning Resource Metadata | 1.2.4 | `imsmd_v1p2p4.xsd` |
|
|
123
|
+
|
|
124
|
+
All schemas are stored locally in `./schemas/qti/` and resolved via the XML catalog (`./schemas/catalog.xml`).
|
|
125
|
+
|
|
126
|
+
**Requirements:**
|
|
127
|
+
|
|
128
|
+
- Python 3
|
|
129
|
+
- `lxml` library: `pip install lxml`
|
|
130
|
+
|
|
131
|
+
**Example output:**
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
⠋ Validated: 45/100 files...
|
|
135
|
+
---- invalid-item.xml ----
|
|
136
|
+
invalid-item.xml:12: Element 'choiceInteraction': Missing required attribute 'responseIdentifier'.
|
|
137
|
+
invalid-item.xml:15: Element 'simpleChoice': Missing required attribute 'identifier'.
|
|
138
|
+
|
|
139
|
+
Validated: 100/100 files - Complete!
|
|
140
|
+
|
|
141
|
+
Summary:
|
|
142
|
+
Total files: 102
|
|
143
|
+
Valid: 100
|
|
144
|
+
Failed: 2
|
|
145
|
+
|
|
146
|
+
By folder:
|
|
147
|
+
items/ 98/100
|
|
148
|
+
metadata/ 100/100
|
|
149
|
+
tests/ 1/1
|
|
150
|
+
imsmanifest.xml 1/1
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Note:** This is a development/testing tool for validating QTI output. It's not required for normal conversion operations.
|
|
154
|
+
|
|
155
|
+
## Learnosity JSON Validation
|
|
156
|
+
|
|
157
|
+
After converting QTI to Learnosity (or to validate existing Learnosity JSON files), you can validate the Learnosity JSON structure:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Validate all Learnosity JSON files in items/ and activities/ subdirectories
|
|
161
|
+
npm run validate:learnosity output/learnosity/
|
|
162
|
+
|
|
163
|
+
# Validate all JSON files recursively in a directory
|
|
164
|
+
npm run validate:learnosity output/learnosity/ --recursive
|
|
165
|
+
|
|
166
|
+
# Validate a specific file
|
|
167
|
+
npm run validate:learnosity output/learnosity/items/item.json
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Note:** When validating a directory without `--recursive`, the script only looks in `./items` and `./activities` subdirectories. Use `--recursive` to validate all JSON files in the directory tree.
|
|
171
|
+
|
|
172
|
+
**Features:**
|
|
173
|
+
|
|
174
|
+
- Validates **item structure** (required fields, widget references)
|
|
175
|
+
- Validates **question types** (mcq, clozetext, shorttext, longtextV2, etc.)
|
|
176
|
+
- Validates **validation objects** (`valid_response`, `alt_responses`)
|
|
177
|
+
- Checks **data type correctness** for each question type:
|
|
178
|
+
- **MCQ**: `valid_response.value` must be array of strings
|
|
179
|
+
- **Clozetext**: `valid_response.value` must be array (one per gap)
|
|
180
|
+
- **Shorttext**: `valid_response.value` can be string or array (synonyms)
|
|
181
|
+
- Validates **HTML content** in stimulus and template fields
|
|
182
|
+
- Provides **clear error messages** with diagnostic codes
|
|
183
|
+
|
|
184
|
+
**Example output:**
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
Validating Learnosity JSON files in: output/items/
|
|
188
|
+
|
|
189
|
+
packages/core/test/fixtures/learnosity/items/clozetext/no-placeholders.json:
|
|
190
|
+
❌ [ERROR] LRN_CLOZE_NO_PLACEHOLDERS: clozetext template must contain at least one {{response}} placeholder
|
|
191
|
+
|
|
192
|
+
packages/core/test/fixtures/learnosity/items/clozetext/len-mismatch.json:
|
|
193
|
+
❌ [ERROR] LRN_CLOZE_VALID_RESPONSE_LEN_MISMATCH: valid_response.value length (1) does not match placeholder count (2)
|
|
194
|
+
|
|
195
|
+
======================================================================
|
|
196
|
+
Validation Summary:
|
|
197
|
+
Total files validated: 46
|
|
198
|
+
Files with errors: 2
|
|
199
|
+
Files with warnings: 0
|
|
200
|
+
|
|
201
|
+
❌ Validation failed with 2 error(s)
|
|
202
|
+
======================================================================
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Use Cases:**
|
|
206
|
+
|
|
207
|
+
- **Quality assurance** - Validate existing Learnosity JSON files
|
|
208
|
+
- **Post-conversion testing** - Verify converter output after code changes
|
|
209
|
+
- **CI/CD integration** - Automated validation with exit codes (0 = success, 1 = errors)
|
|
210
|
+
|
|
211
|
+
**Note:** This is a development/testing tool. It's not required for normal conversion operations but is useful for ensuring quality after code changes.
|
|
212
|
+
|
|
213
|
+
## Development Scripts
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
pnpm run build # Compile TypeScript to JavaScript
|
|
217
|
+
pnpm run coverage:cli # Run CLI tests with coverage
|
|
218
|
+
pnpm run coverage:core # Run core tests with coverage
|
|
219
|
+
pnpm run lint # Check code quality
|
|
220
|
+
pnpm run lint:fix # Auto-fix linting issues
|
|
221
|
+
pnpm run test # Run all tests (core + cli)
|
|
222
|
+
pnpm run test:cli # Run CLI package tests only
|
|
223
|
+
pnpm run test:core # Run core package tests only
|
|
224
|
+
pnpm run validate:learnosity # Validate Learnosity JSON structure (see Learnosity JSON Validation section)
|
|
225
|
+
pnpm run validate:qti # Validate QTI XML against XSD schema (see QTI Validation section)
|
|
226
|
+
pnpm run validate:qti:debug # Validate QTI XML in debug mode
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Local Development
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Install and build
|
|
233
|
+
pnpm install
|
|
234
|
+
pnpm run build
|
|
235
|
+
|
|
236
|
+
# Run the CLI
|
|
237
|
+
npm run lcon -- --help
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Project Structure
|
|
241
|
+
|
|
242
|
+
This is a TypeScript monorepo using pnpm workspaces. Both packages are bundled into self-contained files using [tsdown](https://tsdown.dev/), so the published package has zero runtime dependencies.
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
lib-qti-converter/
|
|
246
|
+
├── packages/
|
|
247
|
+
│ ├── core/ # @learnosity/converter-core - Conversion logic (the importable library)
|
|
248
|
+
│ └── cli/ # @learnosity/converter-cli - Command-line interface
|
|
249
|
+
├── bin/ # Utility scripts (validation tools)
|
|
250
|
+
│ ├── validateLearnosity.ts # Learnosity JSON validation
|
|
251
|
+
│ └── validateQti.py # QTI XML validation
|
|
252
|
+
├── schemas/ # QTI/CC XSD schemas (2.1 and 2.2)
|
|
253
|
+
├── docs/ # User documentation
|
|
254
|
+
│ ├── GETTING_STARTED.md
|
|
255
|
+
│ ├── EXAMPLES.md
|
|
256
|
+
│ └── FAQ.md
|
|
257
|
+
├── adr/ # Architectural Decision Records
|
|
258
|
+
└── .github/prompts/ # AI-specific context and prompts
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## License
|
|
262
|
+
|
|
263
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Diagnostics
|
|
2
|
+
|
|
3
|
+
This document explains how to use and interpret diagnostics during conversion:
|
|
4
|
+
|
|
5
|
+
1. **Diagnostic messages** - Warnings, errors, and info messages emitted during conversion
|
|
6
|
+
2. **Diagnostics file** (`diagnostics.json`) - Summary report written after conversion (CLI)
|
|
7
|
+
3. **Programmatic diagnostics** - Handling diagnostics when using the library API
|
|
8
|
+
|
|
9
|
+
## Diagnostic Messages vs. Diagnostics File
|
|
10
|
+
|
|
11
|
+
There are **two different things** both called "diagnostics":
|
|
12
|
+
|
|
13
|
+
1. **Diagnostic Messages** - Warnings, errors, and info messages shown during conversion
|
|
14
|
+
2. **Diagnostics File** (`diagnostics.json`) - A summary report written after conversion
|
|
15
|
+
|
|
16
|
+
### Diagnostic Messages
|
|
17
|
+
|
|
18
|
+
During conversion, the converter emits diagnostic messages to help you understand what's happening:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
$ lcon qti-package-to-learnosity --in package.zip --out bundle/
|
|
22
|
+
|
|
23
|
+
[INFO] Converting QTI package: package.zip
|
|
24
|
+
[WARNING] QTI_MISSING_RESPONSE_DECLARATION: Response declaration missing for RESPONSE_1
|
|
25
|
+
[INFO] Conversion complete: 3 items converted
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
You control where these messages go using the `--diagnostics` flag (see [Diagnostic Output Options](#diagnostic-output-options) below).
|
|
29
|
+
|
|
30
|
+
### Diagnostics File (`diagnostics.json`)
|
|
31
|
+
|
|
32
|
+
After conversion, a `diagnostics.json` file **may be written** depending on your output destination and the `--diagnostics` flag.
|
|
33
|
+
|
|
34
|
+
**Default Behavior:**
|
|
35
|
+
|
|
36
|
+
| Output Destination | Default Mode | Diagnostics File Written? |
|
|
37
|
+
| ------------------------------------------ | ------------ | ------------------------------------- |
|
|
38
|
+
| **File/Directory** (e.g., `--out bundle/`) | `file` | ✅ Yes, to `diagnostics.json` |
|
|
39
|
+
| **Stdout** (e.g., `--out -`) | `stderr` | ❌ No, diagnostics go to console only |
|
|
40
|
+
|
|
41
|
+
> **Note:** Package commands (`qti-package-to-learnosity`, `learnosity-to-qti-package`) only support file/directory output and always default to `file` mode. Single-file commands (`qti-to-learnosity`, `learnosity-to-qti`) support both file and stdout output, with defaults as shown above.
|
|
42
|
+
|
|
43
|
+
**What's in the file:**
|
|
44
|
+
|
|
45
|
+
- Summary statistics (items found, converted, failed)
|
|
46
|
+
- All diagnostic messages from the conversion
|
|
47
|
+
- Input/output paths
|
|
48
|
+
- Conversion metadata (version, timestamp, configuration)
|
|
49
|
+
|
|
50
|
+
**Example `diagnostics.json`:**
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"directory_input": "/path/to/input",
|
|
55
|
+
"directory_output": "/path/to/output",
|
|
56
|
+
"total_items_found": 5,
|
|
57
|
+
"total_items_converted": 4,
|
|
58
|
+
"total_items_failed": 1,
|
|
59
|
+
"converted_items": ["item_001.xml", "item_002.xml", "item_003.xml", "item_004.xml"],
|
|
60
|
+
"failed_items": ["item_005.xml"],
|
|
61
|
+
"issues": {
|
|
62
|
+
"errors": [
|
|
63
|
+
{
|
|
64
|
+
"code": "QTI_UNSUPPORTED_INTERACTION",
|
|
65
|
+
"message": "Unsupported interaction type: sliderInteraction",
|
|
66
|
+
"file": "item_005.xml"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"warnings": [],
|
|
70
|
+
"info": []
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Severity Levels
|
|
78
|
+
|
|
79
|
+
| Level | Description | Action Required |
|
|
80
|
+
| ----------- | ------------------------------------------------- | -------------------------- |
|
|
81
|
+
| **Error** | Critical issues that prevent conversion | Fix the issue and retry |
|
|
82
|
+
| **Warning** | Non-critical issues that may affect quality | Review and consider fixing |
|
|
83
|
+
| **Info** | Informational messages about conversion decisions | No action needed |
|
|
84
|
+
|
|
85
|
+
### Common Diagnostic Codes
|
|
86
|
+
|
|
87
|
+
#### QTI → Learnosity
|
|
88
|
+
|
|
89
|
+
| Code | Severity | Description |
|
|
90
|
+
| ---------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
91
|
+
| `QTI_UNSUPPORTED_INTERACTION` | Error | The QTI interaction type is not supported (e.g., `sliderInteraction`) |
|
|
92
|
+
| `QTI_MISSING_RESPONSE_DECLARATION` | Warning | Response declaration is missing for an interaction |
|
|
93
|
+
| `QTI_MISSING_CORRECT_RESPONSE` | Warning | Correct response is missing from response declaration |
|
|
94
|
+
| `QTI_PROMPT_MISSING` | Warning | Interaction is missing a prompt element |
|
|
95
|
+
| `QTI_CHOICE_NO_TEXT` | Warning | A choice element has no text content |
|
|
96
|
+
| `QTI_DTD_NOT_ALLOWED` | Error | QTI XML contains a DTD (Document Type Definition) which is not allowed for security |
|
|
97
|
+
| `QTI_ALT_RESPONSES_TRIMMED` | Warning | Alternate responses were limited to 10 items due to excessive QTI mapping rules or Cartesian product combinations |
|
|
98
|
+
|
|
99
|
+
#### Learnosity → QTI
|
|
100
|
+
|
|
101
|
+
| Code | Severity | Description |
|
|
102
|
+
| ---------------------------------- | -------- | ------------------------------------------------------------------ |
|
|
103
|
+
| `LRN_UNSUPPORTED_QUESTION_TYPE` | Error | The Learnosity question type cannot be converted to QTI |
|
|
104
|
+
| `LRN_SCHEMA_INVALID` | Error | The Learnosity JSON structure is invalid or malformed |
|
|
105
|
+
| `LRN_MISSING_REQUIRED_FIELD` | Error | A required field is missing from the Learnosity item |
|
|
106
|
+
| `LRN_INVALID_VALIDATION` | Warning | Validation structure is invalid or incomplete |
|
|
107
|
+
| `LRN_MISSING_CORRECT_RESPONSE` | Warning | Correct response is missing from validation |
|
|
108
|
+
| `LRN_UNSUPPORTED_FEATURE_TYPE` | Warning | A Learnosity feature type is not supported for conversion |
|
|
109
|
+
| `QTI_NO_CORRECT_RESPONSE` | Warning | No correct response could be generated for QTI |
|
|
110
|
+
| `CONTENT_SIMPLE_FEATURE_CONVERTED` | Info | A simple feature (calculator, ruler) was converted to QTI metadata |
|
|
111
|
+
|
|
112
|
+
### Diagnostic Output Options
|
|
113
|
+
|
|
114
|
+
You can control where diagnostic messages are written using the `--diagnostics` flag.
|
|
115
|
+
|
|
116
|
+
The `--diagnostics` flag accepts either a **mode** or a **file path**:
|
|
117
|
+
|
|
118
|
+
#### Modes
|
|
119
|
+
|
|
120
|
+
| Mode | Description |
|
|
121
|
+
| -------- | --------------------------------------------------------------- |
|
|
122
|
+
| `file` | Write diagnostics to `diagnostics.json` in the output directory |
|
|
123
|
+
| `stderr` | Write diagnostics to stderr/console |
|
|
124
|
+
| `both` | Write diagnostics to both `diagnostics.json` and stderr |
|
|
125
|
+
| `none` | Suppress diagnostic output |
|
|
126
|
+
|
|
127
|
+
**Default Behavior:**
|
|
128
|
+
|
|
129
|
+
| Command | Default Mode |
|
|
130
|
+
| --------------------------- | ------------------------------------------------------- |
|
|
131
|
+
| `qti-package-to-learnosity` | `file` |
|
|
132
|
+
| `learnosity-to-qti-package` | `file` |
|
|
133
|
+
| `qti-to-learnosity` | `file` for file output, `stderr` for stdout (`--out -`) |
|
|
134
|
+
| `learnosity-to-qti` | `file` for file output, `stderr` for stdout (`--out -`) |
|
|
135
|
+
|
|
136
|
+
#### Custom File Path
|
|
137
|
+
|
|
138
|
+
You can also pass a **custom file path** instead of a mode:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
--diagnostics ./my-diagnostics.json
|
|
142
|
+
--diagnostics /tmp/conversion-report.json
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
When you provide a file path, the mode is automatically set to `file` and diagnostics are written to your specified path instead of the default `diagnostics.json`.
|
|
146
|
+
|
|
147
|
+
**Examples:**
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Write diagnostics to file (default when --out is a file)
|
|
151
|
+
$ lcon qti-to-learnosity --in item.xml --out item.json
|
|
152
|
+
|
|
153
|
+
# Write diagnostics to stderr only
|
|
154
|
+
$ lcon qti-to-learnosity --in item.xml --out item.json --diagnostics stderr
|
|
155
|
+
|
|
156
|
+
# Write diagnostics to both file and stderr
|
|
157
|
+
$ lcon qti-package-to-learnosity --in package.zip --out bundle/ --diagnostics both
|
|
158
|
+
|
|
159
|
+
# Suppress diagnostics
|
|
160
|
+
$ lcon qti-to-learnosity --in item.xml --out item.json --diagnostics none
|
|
161
|
+
|
|
162
|
+
# Specify custom diagnostics file path
|
|
163
|
+
$ lcon qti-to-learnosity --in item.xml --out item.json --diagnostics ./my-diagnostics.json
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Console Output Example:**
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
$ lcon qti-to-learnosity --in item.xml --out item.json --diagnostics stderr
|
|
170
|
+
|
|
171
|
+
[INFO] Converting QTI item: item.xml
|
|
172
|
+
[WARNING] QTI_MISSING_RESPONSE_DECLARATION: Response declaration missing for RESPONSE_1
|
|
173
|
+
[INFO] QTI_COORDINATE_CONVERSION: Converted hotspot coordinates from pixels to percentages
|
|
174
|
+
[INFO] Conversion complete: item.json
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Programmatic Diagnostics (Library Usage)
|
|
180
|
+
|
|
181
|
+
When using the library API, every conversion function returns a `diagnostics` array. You can inspect these directly instead of relying on file or console output:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import {
|
|
185
|
+
convertQtiToLearnosity,
|
|
186
|
+
convertQtiPackageToLearnosity,
|
|
187
|
+
hasErrors,
|
|
188
|
+
filterByLevel,
|
|
189
|
+
countByLevel,
|
|
190
|
+
formatDiagnosticsReport,
|
|
191
|
+
type Diagnostic,
|
|
192
|
+
} from '@learnosity/lib-qti-converter';
|
|
193
|
+
|
|
194
|
+
// Single-item conversion
|
|
195
|
+
const result = await convertQtiToLearnosity(qtiXml, {
|
|
196
|
+
qtiVersion: '2.2',
|
|
197
|
+
pretty: true,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Check for errors
|
|
201
|
+
if (hasErrors(result.diagnostics)) {
|
|
202
|
+
const errors = filterByLevel(result.diagnostics, 'error');
|
|
203
|
+
errors.forEach((d: Diagnostic) => console.error(`[${d.code}] ${d.message}`));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Count by level
|
|
207
|
+
const { error, warning, info } = countByLevel(result.diagnostics);
|
|
208
|
+
console.log(`Errors: ${error}, Warnings: ${warning}, Info: ${info}`);
|
|
209
|
+
|
|
210
|
+
// Format a human-readable report
|
|
211
|
+
const report = formatDiagnosticsReport(result.diagnostics);
|
|
212
|
+
console.log(report);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Package Conversion Diagnostics
|
|
216
|
+
|
|
217
|
+
Package conversion functions return additional summary information alongside diagnostics:
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
const result = await convertQtiPackageToLearnosity({
|
|
221
|
+
inputPath: '/path/to/package.zip',
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// Per-item diagnostics are included in the array
|
|
225
|
+
console.log(result.diagnostics);
|
|
226
|
+
|
|
227
|
+
// Summary information
|
|
228
|
+
console.log(result.convertedSourceFiles); // successfully converted items
|
|
229
|
+
console.log(result.failedSourceFiles); // items that failed conversion
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Diagnostic Object Shape
|
|
233
|
+
|
|
234
|
+
Each diagnostic in the array has the following shape:
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
interface Diagnostic {
|
|
238
|
+
level: 'error' | 'warning' | 'info';
|
|
239
|
+
code: string; // e.g. 'QTI_UNSUPPORTED_INTERACTION'
|
|
240
|
+
message: string; // Human-readable description
|
|
241
|
+
file?: string; // Source file (if applicable)
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Available Diagnostic Utilities
|
|
246
|
+
|
|
247
|
+
| Export | Description |
|
|
248
|
+
| -------------------------------------- | ---------------------------------------------------- |
|
|
249
|
+
| `hasErrors(diagnostics)` | Returns `true` if any diagnostic has level `'error'` |
|
|
250
|
+
| `filterByLevel(diagnostics, level)` | Filter diagnostics by severity level |
|
|
251
|
+
| `countByLevel(diagnostics)` | Returns `{ error, warning, info }` counts |
|
|
252
|
+
| `formatDiagnosticsReport(diagnostics)` | Format as a human-readable string |
|
|
253
|
+
| `DiagnosticCode` | Enum of all diagnostic codes for programmatic checks |
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## See Also
|
|
258
|
+
|
|
259
|
+
- [Getting Started](https://learnosity.github.io/lib-qti-converter/#/GETTING_STARTED) - Installation and basic usage
|
|
260
|
+
- [Examples](https://learnosity.github.io/lib-qti-converter/#/EXAMPLES) - CLI and library usage examples
|
|
261
|
+
- [Learnosity Bundle Format](https://learnosity.github.io/lib-qti-converter/#/LEARNOSITY_BUNDLE_FORMAT) - Expected input format for Learnosity → QTI conversion
|
|
262
|
+
- [Supported Interactions](https://learnosity.github.io/lib-qti-converter/#/SUPPORTED_INTERACTIONS) - List of supported QTI and Learnosity question types
|
|
263
|
+
- [FAQ](https://learnosity.github.io/lib-qti-converter/#/FAQ) - Common questions
|