forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson-coverage.test.mjs
More file actions
61 lines (53 loc) 路 2.4 KB
/
Copy pathlesson-coverage.test.mjs
File metadata and controls
61 lines (53 loc) 路 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Unit tests for the public lesson coverage dashboard (Issue #905).
import assert from 'node:assert/strict';
import test from 'node:test';
import worker, {
buildLessonCoverage,
handleLessonCoverage,
} from './register-proxy-sw.js';
const LESSONS = [
{ id: 'python-pip', title: 'Python pip timeout recovery', domain: 'devops', tags: ['pip', 'venv'], status: 'published' },
{ id: 'github-auth', title: 'GitHub token 401 recovery', domain: 'devops', tags: ['github', 'token'], status: 'published' },
{ id: 'draft-docker', title: 'Docker draft', domain: 'devops', tags: ['docker'], status: 'draft' },
];
const SIGNALS = {
families: [
{ taskFamily: 'python-env', unsolved7d: 2, unsolved30d: 3, lastSeen: '2026-08-13' },
],
staleLessons: [{ lessonId: 'python-pip', notHelpful30d: 2, lastSeen: '2026-08-12' }],
};
test('coverage classifies covered, review, and uncovered families', () => {
const report = buildLessonCoverage(LESSONS, SIGNALS);
assert.equal(report.metrics.totalLessons, 3);
assert.equal(report.metrics.publishedLessons, 2);
assert.equal(report.metrics.coveredFamilies, 2);
assert.equal(report.metrics.coveragePercent, 16.7);
assert.equal(report.metrics.gapCount, 11);
const python = report.families.find((family) => family.taskFamily === 'python-env');
assert.equal(python.coverageStatus, 'needs-review');
assert.equal(python.lessonCount, 1);
assert.equal(python.unsolved30d, 3);
const glama = report.families.find((family) => family.taskFamily === 'glama-release');
assert.equal(glama.coverageStatus, 'uncovered');
assert.ok(report.gaps.some((family) => family.taskFamily === 'glama-release'));
});
test('handler returns valid JSON with explicit privacy metadata', async () => {
const response = await handleLessonCoverage({
LESSON_DATA: LESSONS,
UNSOLVED_DATA: SIGNALS,
});
assert.equal(response.status, 200);
const body = await response.json();
assert.equal(body.success, true);
assert.equal(body.meta.lessonSource, 'data/lessons.json');
assert.equal(body.meta.raw_query, false);
assert.equal(body.meta.pii, false);
assert.equal(body.staleLessons[0].lessonId, 'python-pip');
});
test('public worker route works without REGISTER_TOKEN or KV', async () => {
const response = await worker.fetch(
new Request('https://misakanet.org/api/insights/lesson-coverage'),
{ LESSON_DATA: LESSONS, UNSOLVED_DATA: SIGNALS },
);
assert.equal(response.status, 200);
});