import { describe, expect, it } from 'vitest'; import { sanitizeLearningRuntimeAnchor } from '@/lib/learning-runtime-anchor'; import { matchesLearningCloudProgress } from '@/pages/Learning/CoursePlayer'; describe('Learning CoursePlayer runtime boundary', () => { it('copies only sceneId and sceneOrder from the untrusted iframe anchor', () => { expect(sanitizeLearningRuntimeAnchor({ sceneId: 'scene-3', sceneOrder: 3, courseId: 'iframe-course', contentHash: 'iframe-hash', moduleId: 'iframe-module', moduleContentHash: 'iframe-module-hash', actionIndex: 8, })).toEqual({ sceneId: 'scene-3', sceneOrder: 3 }); }); it('drops invalid or empty anchors instead of forwarding arbitrary context', () => { expect(sanitizeLearningRuntimeAnchor({ sceneId: '', sceneOrder: -1, arbitrary: true })).toBeUndefined(); expect(sanitizeLearningRuntimeAnchor(['scene-1'])).toBeUndefined(); }); it('restores single-course cloud progress stored under the server main module', () => { expect(matchesLearningCloudProgress( { courseId: 'course-1', contentHash: 'a'.repeat(64), moduleId: 'main' }, 'course-1', { courseContentHash: 'a'.repeat(64), moduleId: null, modules: [{}] }, )).toBe(true); expect(matchesLearningCloudProgress( { courseId: 'course-1', contentHash: 'a'.repeat(64), moduleId: 'other' }, 'course-1', { courseContentHash: 'a'.repeat(64), moduleId: null, modules: [{}] }, )).toBe(false); }); });