brain backup 2026-09-14

This commit is contained in:
Adolfo Reyna
2026-09-14 22:38:47 -04:00
parent ca346cc6e7
commit f0ead4f6fa
147 changed files with 73451 additions and 8 deletions
@@ -0,0 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { classifyUnit, roleForPdf, isGradeThreeSource } from '../src/catalog.mjs';
test('keeps a Grade 3 unit from the verified source list', () => {
assert.equal(isGradeThreeSource({ title: 'Grade 3 CK Math: Unit 1', filename: 'CKMath_G3U1.zip' }), true);
assert.equal(isGradeThreeSource({ title: 'Grade 2 CK Math: Unit 1', filename: 'CKMath_G2U1.zip' }), false);
});
test('classifies major Grade 3 curriculum families', () => {
assert.equal(classifyUnit('CKMath_G3U1_IntroducingMultiplication.zip'), 'Math');
assert.equal(classifyUnit('CKSci_G3_U1_InvestigatingForces.zip'), 'Science');
assert.equal(classifyUnit('CKLA_G3_Unit-1.zip'), 'Language Arts');
assert.equal(classifyUnit('CKHG_G3_U1_WorldRivers.zip'), 'History & Geography');
});
test('labels teacher guides and student resources without exposing arbitrary paths', () => {
assert.equal(roleForPdf('CKMath_G3U1_IntroducingMultiplication_TG_W2.pdf'), 'Teacher Guide');
assert.equal(roleForPdf('CKMath_G3U1_IntroducingMultiplication_SR_W2.pdf'), 'Student Reader');
assert.equal(roleForPdf('CoreKnowledge_CurriculumSeries_CCL_TermsOfUse_2024_W1.pdf'), 'Reference');
});
@@ -0,0 +1,23 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { filterUnits, subjectsFor, teacherGuidesFor } from '../src/library.mjs';
const units = [
{ subject: 'Math', title: 'Grade 3 Math', materials: [{ role: 'Teacher Guide', id: 'math-guide' }] },
{ subject: 'Science', title: 'Grade 3 Science', materials: [{ role: 'Student Reader', id: 'science-reader' }] },
{ subject: 'Math', title: 'Math Literature', materials: [] },
];
test('lists available subjects with All first', () => {
assert.deepEqual(subjectsFor(units), ['All', 'Math', 'Science']);
});
test('filters units by selected subject', () => {
assert.deepEqual(filterUnits(units, 'Math').map((unit) => unit.title), ['Grade 3 Math', 'Math Literature']);
assert.equal(filterUnits(units, 'All').length, 3);
});
test('selects only a unit’s teacher-plan PDFs', () => {
assert.deepEqual(teacherGuidesFor(units[0]), [{ role: 'Teacher Guide', id: 'math-guide' }]);
assert.deepEqual(teacherGuidesFor(units[1]), []);
});
@@ -0,0 +1,24 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
isCorrectTotal,
isCorrectEquation,
hasReasoningEvidence,
} from '../src/session.mjs';
test('accepts the total for seven groups of two', () => {
assert.equal(isCorrectTotal('14'), true);
});
test('rejects an incorrect total for seven groups of two', () => {
assert.equal(isCorrectTotal('13'), false);
});
test('accepts an equivalent multiplication equation', () => {
assert.equal(isCorrectEquation('2 × 7 = 14'), true);
});
test('requires a learner explanation to name groups or repeated addition and the total', () => {
assert.equal(hasReasoningEvidence('There are 7 groups of 2, so there are 14 shoes.'), true);
assert.equal(hasReasoningEvidence('It is 14.'), false);
});
@@ -0,0 +1,40 @@
import importlib.util
import json
import tempfile
import unittest
import zipfile
from pathlib import Path
MODULE_PATH = Path(__file__).parents[1] / 'scripts' / 'build_grade3_catalog.py'
spec = importlib.util.spec_from_file_location('catalog_builder', MODULE_PATH)
builder = importlib.util.module_from_spec(spec)
spec.loader.exec_module(builder)
class GradeThreeCatalogTest(unittest.TestCase):
def test_build_catalog_keeps_grade_three_archives_and_labels_pdfs(self):
with tempfile.TemporaryDirectory() as temp_dir:
root = Path(temp_dir)
archive = root / 'CKMath_G3U1.zip'
with zipfile.ZipFile(archive, 'w') as zf:
zf.writestr('unit/CKMath_G3U1_TG.pdf', b'not-a-real-pdf')
zf.writestr('unit/CKMath_G3U1_SR.pdf', b'not-a-real-pdf')
zf.writestr('__MACOSX/unit/._ignored.pdf', b'ignored')
manifest = root / 'download-manifest.json'
manifest.write_text(json.dumps([
{'title': 'Grade 3 CKMath: Unit 1', 'filename': archive.name, 'source': 'https://example.test/g3.zip', 'type': 'zip'},
{'title': 'Grade 2 CKMath: Unit 1', 'filename': 'CKMath_G2U1.zip', 'source': 'https://example.test/g2.zip', 'type': 'zip'},
]))
catalog = builder.build_catalog(manifest, root)
self.assertEqual(catalog['unit_count'], 1)
unit = catalog['units'][0]
self.assertEqual(unit['subject'], 'Math')
self.assertEqual([material['role'] for material in unit['materials']], ['Student Reader', 'Teacher Guide'])
self.assertEqual(unit['teacher_guide_count'], 1)
self.assertEqual(unit['student_material_count'], 1)
if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,31 @@
import importlib.util
import unittest
from pathlib import Path
MODULE_PATH = Path(__file__).parents[1] / 'src' / 'server_catalog.py'
spec = importlib.util.spec_from_file_location('server_catalog', MODULE_PATH)
server_catalog = importlib.util.module_from_spec(spec)
spec.loader.exec_module(server_catalog)
class ServerCatalogTest(unittest.TestCase):
def setUp(self):
self.catalog = {
'units': [{
'filename': 'CKMath_G3U1.zip',
'materials': [{'id': 'guide-1', 'internal_path': 'unit/guide.pdf', 'filename': 'guide.pdf'}],
}]
}
def test_known_material_id_resolves_to_its_declared_zip_member(self):
index = server_catalog.material_index(self.catalog)
self.assertEqual(server_catalog.lookup_material(index, 'guide-1'), ('CKMath_G3U1.zip', 'unit/guide.pdf'))
def test_unknown_or_path_like_id_is_not_resolved(self):
index = server_catalog.material_index(self.catalog)
self.assertIsNone(server_catalog.lookup_material(index, '../../etc/passwd'))
self.assertIsNone(server_catalog.lookup_material(index, 'not-in-the-catalog'))
if __name__ == '__main__':
unittest.main()