tessera-learn 0.2.1 → 0.2.2

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.
@@ -3,7 +3,7 @@
3
3
  import { SvelteMap } from 'svelte/reactivity';
4
4
  import { useQuestion } from '../runtime/hooks.svelte.js';
5
5
  import { questionId, shuffle } from './util.js';
6
- import LockedBanner from './LockedBanner.svelte';
6
+ import QuestionShell from './QuestionShell.svelte';
7
7
  import ResultIcon from './ResultIcon.svelte';
8
8
  import RetryButton from './RetryButton.svelte';
9
9
 
@@ -85,10 +85,7 @@
85
85
  if (!inQuiz) {
86
86
  initShuffle();
87
87
  } else {
88
- onMount(() => {
89
- initShuffle();
90
- q.setRender(renderQuestion);
91
- });
88
+ onMount(initShuffle);
92
89
  }
93
90
 
94
91
  function handleLeftClick(leftIndex) {
@@ -166,7 +163,7 @@
166
163
  }
167
164
  </script>
168
165
 
169
- {#snippet matchingContent()}
166
+ <QuestionShell {q} class="tessera-matching" aria-label={question}>
170
167
  <p class="tessera-matching-question">{question}</p>
171
168
 
172
169
  <div class="tessera-matching-grid">
@@ -268,28 +265,9 @@
268
265
  {/if}
269
266
  </div>
270
267
  {/if}
271
- {/snippet}
272
-
273
- {#if !inQuiz}
274
- <div class="tessera-matching" aria-label={question}>
275
- {@render matchingContent()}
276
- </div>
277
- {/if}
278
-
279
- {#snippet renderQuestion()}
280
- <div class="tessera-matching" aria-label={question}>
281
- {#if q.isLockedCorrect}
282
- <LockedBanner />
283
- {/if}
284
- {@render matchingContent()}
285
- </div>
286
- {/snippet}
268
+ </QuestionShell>
287
269
 
288
270
  <style>
289
- .tessera-matching {
290
- padding: var(--tessera-spacing-md) 0;
291
- }
292
-
293
271
  .tessera-matching-question {
294
272
  font-size: 1.125rem;
295
273
  font-weight: 600;
@@ -1,8 +1,7 @@
1
1
  <script>
2
- import { onMount } from 'svelte';
3
2
  import { useQuestion } from '../runtime/hooks.svelte.js';
4
3
  import { questionId } from './util.js';
5
- import LockedBanner from './LockedBanner.svelte';
4
+ import QuestionShell from './QuestionShell.svelte';
6
5
  import RetryButton from './RetryButton.svelte';
7
6
 
8
7
  let {
@@ -45,10 +44,6 @@
45
44
  // `q.mode` is fixed for the lifetime of the widget; capture once.
46
45
  const inQuiz = q.mode === 'quiz';
47
46
 
48
- onMount(() => {
49
- if (inQuiz) q.setRender(renderQuestion);
50
- });
51
-
52
47
  function handleSelect(optIndex) {
53
48
  if (q.locked) return;
54
49
  selectedOption = optIndex;
@@ -73,7 +68,12 @@
73
68
  }
74
69
  </script>
75
70
 
76
- {#snippet mcContent()}
71
+ <QuestionShell
72
+ {q}
73
+ class="tessera-mc"
74
+ role="radiogroup"
75
+ aria-labelledby="{groupId}-label"
76
+ >
77
77
  <p class="tessera-mc-question" id="{groupId}-label">{question}</p>
78
78
 
79
79
  <div class="tessera-mc-options">
@@ -127,28 +127,9 @@
127
127
  <RetryButton onclick={() => q.retry()} />
128
128
  {/if}
129
129
  {/if}
130
- {/snippet}
131
-
132
- {#if !inQuiz}
133
- <div class="tessera-mc" role="radiogroup" aria-labelledby="{groupId}-label">
134
- {@render mcContent()}
135
- </div>
136
- {/if}
137
-
138
- {#snippet renderQuestion()}
139
- <div class="tessera-mc" role="radiogroup" aria-labelledby="{groupId}-label">
140
- {#if q.isLockedCorrect}
141
- <LockedBanner />
142
- {/if}
143
- {@render mcContent()}
144
- </div>
145
- {/snippet}
130
+ </QuestionShell>
146
131
 
147
132
  <style>
148
- .tessera-mc {
149
- padding: var(--tessera-spacing-md) 0;
150
- }
151
-
152
133
  .tessera-mc-question {
153
134
  font-size: 1.125rem;
154
135
  font-weight: 600;
@@ -0,0 +1,35 @@
1
+ <script>
2
+ import { onMount } from 'svelte';
3
+ import LockedBanner from './LockedBanner.svelte';
4
+
5
+ // Shared dual-render wrapper for the question widgets: inline when
6
+ // standalone, a snippet the Quiz shell renders when inside a quiz.
7
+ let { q, class: className = '', children, ...rest } = $props();
8
+
9
+ const inQuiz = $derived(q.mode === 'quiz');
10
+
11
+ onMount(() => {
12
+ if (inQuiz) q.setRender(quizContent);
13
+ });
14
+ </script>
15
+
16
+ {#if !inQuiz}
17
+ <div class="tessera-question-shell {className}" {...rest}>
18
+ {@render children?.()}
19
+ </div>
20
+ {/if}
21
+
22
+ {#snippet quizContent()}
23
+ <div class="tessera-question-shell {className}" {...rest}>
24
+ {#if q.isLockedCorrect}
25
+ <LockedBanner />
26
+ {/if}
27
+ {@render children?.()}
28
+ </div>
29
+ {/snippet}
30
+
31
+ <style>
32
+ .tessera-question-shell {
33
+ padding: var(--tessera-spacing-md) 0;
34
+ }
35
+ </style>
@@ -3,7 +3,7 @@
3
3
  import { SvelteMap } from 'svelte/reactivity';
4
4
  import { useQuestion } from '../runtime/hooks.svelte.js';
5
5
  import { questionId, shuffle } from './util.js';
6
- import LockedBanner from './LockedBanner.svelte';
6
+ import QuestionShell from './QuestionShell.svelte';
7
7
  import ResultIcon from './ResultIcon.svelte';
8
8
  import RetryButton from './RetryButton.svelte';
9
9
 
@@ -77,10 +77,7 @@
77
77
  if (!inQuiz) {
78
78
  initQueue();
79
79
  } else {
80
- onMount(() => {
81
- initQueue();
82
- q.setRender(renderQuestion);
83
- });
80
+ onMount(initQueue);
84
81
  }
85
82
 
86
83
  let currentItemIdx = $derived(queue.length > 0 ? queue[0] : null);
@@ -176,7 +173,7 @@
176
173
  }
177
174
  </script>
178
175
 
179
- {#snippet sortingContent()}
176
+ <QuestionShell {q} class="tessera-sorting" aria-label={question}>
180
177
  <p class="tessera-sorting-question">{question}</p>
181
178
 
182
179
  <!-- Card deck: shows the current card to be placed -->
@@ -321,28 +318,9 @@
321
318
  </button>
322
319
  </div>
323
320
  {/if}
324
- {/snippet}
325
-
326
- {#if !inQuiz}
327
- <div class="tessera-sorting" aria-label={question}>
328
- {@render sortingContent()}
329
- </div>
330
- {/if}
331
-
332
- {#snippet renderQuestion()}
333
- <div class="tessera-sorting" aria-label={question}>
334
- {#if q.isLockedCorrect}
335
- <LockedBanner />
336
- {/if}
337
- {@render sortingContent()}
338
- </div>
339
- {/snippet}
321
+ </QuestionShell>
340
322
 
341
323
  <style>
342
- .tessera-sorting {
343
- padding: var(--tessera-spacing-md) 0;
344
- }
345
-
346
324
  .tessera-sorting-question {
347
325
  font-size: 1.125rem;
348
326
  font-weight: 600;
@@ -1,5 +1,7 @@
1
- import { existsSync, writeFileSync } from 'node:fs';
2
- import { resolve } from 'node:path';
1
+ import { spawn, type SpawnOptions } from 'node:child_process';
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import { dirname, resolve } from 'node:path';
3
5
  import { generateManifest, readCourseConfig } from '../manifest.js';
4
6
  import { normalizeA11y, type A11ySettings } from '../validation.js';
5
7
 
@@ -23,12 +25,19 @@ const IMPACT_RANK: Record<ImpactLevel, number> = {
23
25
  // skips export packaging, and stubs xAPI while it's set. See plugin/index.ts.
24
26
  export const AUDIT_ENV_FLAG = 'TESSERA_A11Y_AUDIT';
25
27
 
28
+ export interface AxeNodeDetail {
29
+ target: string;
30
+ html: string;
31
+ summary: string;
32
+ }
33
+
26
34
  interface AxeViolation {
27
35
  id: string;
28
36
  impact: ImpactLevel | null;
29
37
  help: string;
30
38
  helpUrl: string;
31
39
  nodes: number;
40
+ elements: AxeNodeDetail[];
32
41
  }
33
42
 
34
43
  interface PageAuditResult {
@@ -70,10 +79,210 @@ export function axeIgnoreRules(ignore: string[]): string[] {
70
79
  );
71
80
  }
72
81
 
82
+ const MAX_HTML_LENGTH = 200;
83
+ const MAX_ELEMENTS_SHOWN = 5;
84
+
85
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ export function mapNodeDetail(node: any): AxeNodeDetail {
87
+ const target = Array.isArray(node?.target)
88
+ ? node.target.flat(Infinity).join(' ')
89
+ : String(node?.target ?? '');
90
+ const html = String(node?.html ?? '');
91
+ return {
92
+ target,
93
+ html:
94
+ html.length > MAX_HTML_LENGTH
95
+ ? `${html.slice(0, MAX_HTML_LENGTH - 1)}…`
96
+ : html,
97
+ summary: String(node?.failureSummary ?? '')
98
+ .replace(/\s*\n\s*/g, ' ')
99
+ .trim(),
100
+ };
101
+ }
102
+
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
+ export function mapViolation(v: any): AxeViolation {
105
+ return {
106
+ id: v.id,
107
+ impact: v.impact ?? null,
108
+ help: v.help,
109
+ helpUrl: v.helpUrl,
110
+ nodes: v.nodes.length,
111
+ elements: v.nodes.map(mapNodeDetail),
112
+ };
113
+ }
114
+
73
115
  export function isMissingBrowserError(message: string): boolean {
74
116
  return /Executable doesn't exist|playwright install/i.test(message);
75
117
  }
76
118
 
119
+ // A missing-deps failure also mentions `playwright install-deps`, so it matches
120
+ // isMissingBrowserError; detect it first to route to the `--with-deps` fix.
121
+ export function isMissingDepsError(message: string): boolean {
122
+ return /Host system is missing dependencies|missing dependencies to run browser/i.test(
123
+ message,
124
+ );
125
+ }
126
+
127
+ const INSTALL_CHROMIUM = 'pnpm exec playwright install chromium';
128
+ const PLAYWRIGHT_SPECS = ['playwright', '@playwright/test'] as const;
129
+
130
+ function reportManualInstall(lead: string): void {
131
+ console.error(
132
+ `\x1b[31m[tessera a11y]\x1b[0m ${lead}\n` +
133
+ ` Install it once:\n` +
134
+ ` ${INSTALL_CHROMIUM}`,
135
+ );
136
+ }
137
+
138
+ type SpawnFn = (
139
+ command: string,
140
+ args: string[],
141
+ options: SpawnOptions,
142
+ ) => {
143
+ on(event: 'error', listener: (err: Error) => void): unknown;
144
+ on(event: 'exit', listener: (code: number | null) => void): unknown;
145
+ kill?(signal?: NodeJS.Signals): unknown;
146
+ };
147
+
148
+ function resolvePlaywrightBin():
149
+ | { command: string; args: string[] }
150
+ | undefined {
151
+ const require = createRequire(import.meta.url);
152
+ for (const spec of PLAYWRIGHT_SPECS) {
153
+ try {
154
+ const pkgPath = require.resolve(`${spec}/package.json`);
155
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as {
156
+ bin?: string | Record<string, string>;
157
+ };
158
+ const binRel =
159
+ typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.playwright;
160
+ if (!binRel) continue;
161
+ return {
162
+ command: process.execPath,
163
+ args: [resolve(dirname(pkgPath), binRel), 'install', 'chromium'],
164
+ };
165
+ } catch {
166
+ continue;
167
+ }
168
+ }
169
+ return undefined;
170
+ }
171
+
172
+ const INSTALL_TIMEOUT_MS = 10 * 60_000;
173
+
174
+ // Run the workspace's own `playwright` bin with the current Node binary so the
175
+ // install is package-manager-agnostic. No --with-deps: it needs sudo on Linux.
176
+ export async function installChromium(
177
+ workspaceRoot: string,
178
+ spawnFn: SpawnFn = spawn,
179
+ timeoutMs: number = INSTALL_TIMEOUT_MS,
180
+ ): Promise<boolean> {
181
+ const bin = resolvePlaywrightBin();
182
+ if (!bin) {
183
+ console.error(
184
+ `\x1b[31m[tessera a11y]\x1b[0m Could not locate the Playwright CLI to install Chromium.`,
185
+ );
186
+ return false;
187
+ }
188
+
189
+ return new Promise<boolean>((resolvePromise) => {
190
+ const child = spawnFn(bin.command, bin.args, {
191
+ stdio: 'inherit',
192
+ cwd: workspaceRoot,
193
+ });
194
+ let settled = false;
195
+ const finish = (ok: boolean) => {
196
+ if (settled) return;
197
+ settled = true;
198
+ clearTimeout(timer);
199
+ resolvePromise(ok);
200
+ };
201
+ const timer = setTimeout(() => {
202
+ console.error(
203
+ `\x1b[31m[tessera a11y]\x1b[0m Chromium install timed out after ${Math.round(
204
+ timeoutMs / 60_000,
205
+ )} min; aborting.`,
206
+ );
207
+ child.kill?.('SIGKILL');
208
+ finish(false);
209
+ }, timeoutMs);
210
+ timer.unref?.();
211
+ child.on('error', (err) => {
212
+ console.error(
213
+ `\x1b[31m[tessera a11y]\x1b[0m Failed to start the Chromium install: ${err.message}`,
214
+ );
215
+ finish(false);
216
+ });
217
+ child.on('exit', (code) => finish(code === 0));
218
+ });
219
+ }
220
+
221
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
+ type LaunchResult = { ok: true; browser: any } | { ok: false; code: number };
223
+
224
+ function reportLaunchFailure(message: string, isLinux: boolean): void {
225
+ console.error(
226
+ `\x1b[31m[tessera a11y]\x1b[0m Chromium is installed but failed to launch.\n` +
227
+ (isLinux
228
+ ? ` Install system dependencies:\n pnpm exec playwright install --with-deps chromium\n`
229
+ : ``) +
230
+ ` Original error: ${message}`,
231
+ );
232
+ }
233
+
234
+ // Owns the catch → install → guarded-retry around chromium.launch(). The retry
235
+ // is guarded because a binary-only install can still fail to launch (on Linux,
236
+ // for want of system libs) rather than throw a raw error post-download.
237
+ export async function launchWithInstall({
238
+ launch,
239
+ install,
240
+ isLinux = process.platform === 'linux',
241
+ }: {
242
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
+ launch: () => Promise<any>;
244
+ install: () => Promise<boolean>;
245
+ isLinux?: boolean;
246
+ }): Promise<LaunchResult> {
247
+ try {
248
+ return { ok: true, browser: await launch() };
249
+ } catch (err) {
250
+ const message = err instanceof Error ? err.message : String(err);
251
+ if (isMissingDepsError(message)) {
252
+ reportLaunchFailure(message, isLinux);
253
+ return { ok: false, code: 1 };
254
+ }
255
+ if (!isMissingBrowserError(message)) throw err;
256
+
257
+ console.log(
258
+ "[tessera a11y] Chromium isn't installed for Playwright. Installing it once now…",
259
+ );
260
+ const installed = await install();
261
+ if (!installed) {
262
+ reportManualInstall("Chromium isn't installed for Playwright.");
263
+ return { ok: false, code: 1 };
264
+ }
265
+
266
+ try {
267
+ return { ok: true, browser: await launch() };
268
+ } catch (retryErr) {
269
+ const retryMessage =
270
+ retryErr instanceof Error ? retryErr.message : String(retryErr);
271
+ if (
272
+ isMissingBrowserError(retryMessage) &&
273
+ !isMissingDepsError(retryMessage)
274
+ ) {
275
+ reportManualInstall(
276
+ "Chromium still isn't installed after the install step.",
277
+ );
278
+ } else {
279
+ reportLaunchFailure(retryMessage, isLinux);
280
+ }
281
+ return { ok: false, code: 1 };
282
+ }
283
+ }
284
+ }
285
+
77
286
  // A violation with no impact is treated as failing rather than slipping the
78
287
  // gate at every threshold.
79
288
  function isFailing(v: AxeViolation, thresholdRank: number): boolean {
@@ -98,7 +307,7 @@ async function loadDeps(): Promise<
98
307
  > {
99
308
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
309
  let chromium: any;
101
- for (const spec of ['playwright', '@playwright/test']) {
310
+ for (const spec of PLAYWRIGHT_SPECS) {
102
311
  try {
103
312
  const mod = (await tryImport(spec)) as { chromium?: unknown };
104
313
  if (mod.chromium) {
@@ -140,7 +349,7 @@ export async function runAudit(
140
349
  `\x1b[31m[tessera a11y]\x1b[0m Tier 2 needs Playwright + axe-core, which aren't installed.\n` +
141
350
  ` Install them to run the runtime audit:\n` +
142
351
  ` pnpm add -D playwright @axe-core/playwright\n` +
143
- ` pnpm exec playwright install chromium`,
352
+ ` ${INSTALL_CHROMIUM}`,
144
353
  );
145
354
  return 1;
146
355
  }
@@ -200,21 +409,12 @@ export async function runAudit(
200
409
  return 1;
201
410
  }
202
411
 
203
- let browser;
204
- try {
205
- browser = await chromium.launch();
206
- } catch (err) {
207
- const message = err instanceof Error ? err.message : String(err);
208
- if (isMissingBrowserError(message)) {
209
- console.error(
210
- `\x1b[31m[tessera a11y]\x1b[0m Chromium isn't installed for Playwright.\n` +
211
- ` Install it once:\n` +
212
- ` pnpm exec playwright install chromium`,
213
- );
214
- return 1;
215
- }
216
- throw err;
217
- }
412
+ const launched = await launchWithInstall({
413
+ launch: () => chromium.launch(),
414
+ install: () => installChromium(workspaceRoot),
415
+ });
416
+ if (!launched.ok) return launched.code;
417
+ const browser = launched.browser;
218
418
  const pages: PageAuditResult[] = [];
219
419
  try {
220
420
  // axe-core/playwright requires a page from an explicit context.
@@ -230,14 +430,7 @@ export async function runAudit(
230
430
  const builder = new AxeBuilder({ page }).withTags(tags);
231
431
  if (disableRules.length > 0) builder.disableRules(disableRules);
232
432
  const out = await builder.analyze();
233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
- return out.violations.map((v: any) => ({
235
- id: v.id,
236
- impact: v.impact ?? null,
237
- help: v.help,
238
- helpUrl: v.helpUrl,
239
- nodes: v.nodes.length,
240
- }));
433
+ return out.violations.map(mapViolation);
241
434
  };
242
435
 
243
436
  const recordPage = async (
@@ -351,6 +544,18 @@ function printSummary(report: AuditReport, reportPath: string): void {
351
544
  console.log(
352
545
  ` [${v.impact ?? 'n/a'}] ${v.id} — ${v.help} (${v.nodes} node${v.nodes === 1 ? '' : 's'})`,
353
546
  );
547
+ for (const el of v.elements.slice(0, MAX_ELEMENTS_SHOWN)) {
548
+ console.log(
549
+ `\x1b[90m → ${el.target || '(unknown element)'}\x1b[0m`,
550
+ );
551
+ if (el.summary) console.log(`\x1b[90m ${el.summary}\x1b[0m`);
552
+ }
553
+ const hidden = v.elements.length - MAX_ELEMENTS_SHOWN;
554
+ if (hidden > 0) {
555
+ console.log(
556
+ `\x1b[90m … and ${hidden} more — see a11y-report.json\x1b[0m`,
557
+ );
558
+ }
354
559
  }
355
560
  }
356
561
  console.log(`\n[tessera a11y] Report written to ${reportPath}`);
@@ -32,29 +32,57 @@ export function findWorkspaceRoot(cwd: string): string | null {
32
32
  }
33
33
  }
34
34
 
35
- export function listCourses(workspaceRoot: string): string[] {
35
+ function scanCourses(workspaceRoot: string): {
36
+ courses: string[];
37
+ malformed: string[];
38
+ } {
36
39
  const coursesDir = join(workspaceRoot, 'courses');
40
+ const courses: string[] = [];
41
+ const malformed: string[] = [];
37
42
  try {
38
- return readdirSync(coursesDir, { withFileTypes: true })
39
- .filter((e) => e.isDirectory() && isCourse(join(coursesDir, e.name)))
40
- .map((e) => e.name)
41
- .sort();
43
+ for (const e of readdirSync(coursesDir, { withFileTypes: true })) {
44
+ if (!e.isDirectory()) continue;
45
+ const dir = join(coursesDir, e.name);
46
+ if (isCourse(dir)) courses.push(e.name);
47
+ else if (isDir(join(dir, 'pages'))) malformed.push(e.name);
48
+ }
42
49
  } catch {
43
- return [];
50
+ return { courses, malformed };
44
51
  }
52
+ return { courses: courses.sort(), malformed: malformed.sort() };
53
+ }
54
+
55
+ export function listCourses(workspaceRoot: string): string[] {
56
+ return scanCourses(workspaceRoot).courses;
57
+ }
58
+
59
+ export function listMalformedCourses(workspaceRoot: string): string[] {
60
+ return scanCourses(workspaceRoot).malformed;
45
61
  }
46
62
 
47
63
  const NOT_A_WORKSPACE =
48
64
  'Not inside a Tessera workspace — no `courses/` directory was found at or above the current directory.';
49
65
 
66
+ function malformedHint(malformed: string[]): string {
67
+ if (malformed.length === 0) return '';
68
+ return (
69
+ `\nSkipped (missing course.config.js):\n` +
70
+ malformed.map((c) => ` courses/${c}`).join('\n')
71
+ );
72
+ }
73
+
50
74
  function listHint(workspaceRoot: string): string {
51
- const courses = listCourses(workspaceRoot);
75
+ const { courses, malformed } = scanCourses(workspaceRoot);
52
76
  if (courses.length === 0) {
53
- return '\nNo courses found. Create one with `tessera new <name>`.';
77
+ return (
78
+ '\nNo courses found. Create one with `tessera new <name>`.' +
79
+ malformedHint(malformed)
80
+ );
54
81
  }
55
82
  return (
56
83
  `\nAvailable courses:\n${courses.map((c) => ` ${c}`).join('\n')}` +
57
- '\nName one (`tessera <command> <course>`) or cd into its folder.'
84
+ '\nName one (`tessera <command> <course>`) or cd into its folder.' +
85
+ malformedHint(malformed)
58
86
  );
59
87
  }
60
88
 
@@ -579,10 +579,7 @@ export class CMI5Adapter implements PersistenceAdapter {
579
579
  opts: { moveOn?: boolean; mastery?: boolean } = {},
580
580
  ): Record<string, unknown> {
581
581
  const tmpl = this.#launchData?.contextTemplate ?? {};
582
- const tmplActivities = (tmpl.contextActivities ?? {}) as Record<
583
- string,
584
- unknown
585
- >;
582
+ const tmplActivities = tmpl.contextActivities ?? {};
586
583
 
587
584
  // Concat-dedupe category to preserve any template-supplied entries
588
585
  // (§10.2.1 forbids overwriting them).
@@ -594,14 +591,8 @@ export class CMI5Adapter implements PersistenceAdapter {
594
591
  category.push({ id, objectType: 'Activity' });
595
592
  }
596
593
  };
597
- const templateCategory = Array.isArray(
598
- (tmplActivities as { category?: unknown }).category,
599
- )
600
- ? (
601
- tmplActivities as {
602
- category: Array<{ id: string; objectType?: string }>;
603
- }
604
- ).category
594
+ const templateCategory = Array.isArray(tmplActivities.category)
595
+ ? tmplActivities.category
605
596
  : [];
606
597
  for (const c of templateCategory) {
607
598
  if (c && typeof c.id === 'string') push(c.id);
@@ -615,13 +606,13 @@ export class CMI5Adapter implements PersistenceAdapter {
615
606
  };
616
607
 
617
608
  const ctx: Record<string, unknown> = {
618
- ...(tmpl as Record<string, unknown>),
609
+ ...tmpl,
619
610
  contextActivities,
620
611
  };
621
612
  // cmi5 §9.6.3.2 — masteryScore extension is scoped to Passed/Failed.
622
613
  if (opts.mastery && this.#masteryScore !== null) {
623
614
  ctx.extensions = {
624
- ...((tmpl.extensions ?? {}) as Record<string, unknown>),
615
+ ...(tmpl.extensions ?? {}),
625
616
  [CMI5_MASTERYSCORE_EXT]: this.#masteryScore,
626
617
  };
627
618
  }