"""Reviewed thematic links between immutable tasks; never changes task content.""" import hashlib import json import pathlib BASE = pathlib.Path(__file__).resolve().parent DEST = BASE.parents[1] / 'apps/api/internal/store/coursebank' def compile_sequences(): review_bytes = (BASE / 'sequence_review.json').read_bytes() review = json.loads(review_bytes) assert review['reviewed'] for name, digest in review['sources'].items(): assert hashlib.sha256((BASE / name).read_bytes()).hexdigest() == digest, f'Sequence review is stale: {name}' source = json.loads((BASE / 'sequence_sources.json').read_text()) entries = {} for path in (DEST / 'en-US/a1-v2').glob('*.json'): if path.name != 'manifest.json': entries[path.name] = json.loads(path.read_text()) sequences = [] for module, rows in source['modules'].items(): for scene, vocab, repeats, grammar, writing, de, ru in rows: steps = [] for phase, skill, numbers in [('listen', 'listening', [scene]), ('vocabulary', 'vocabulary', vocab), ('read', 'reading', [scene]), ('repeat', 'speaking', repeats), ('grammar', 'grammar', grammar), ('write', 'writing', writing), ('compose', 'writing', [scene]), ('speak', 'speaking', [scene])]: for number in numbers: entry = entries[f'{module}.{skill}.json'][number - 1] expected = {'listen':'choice','vocabulary':'choice','read':'choice','repeat':'repeat_sentence','grammar':'choice','write':'short_text','compose':'free_text','speak':'free_speech'}[phase] assert entry['task']['kind'] == expected steps.append(dict(phase=phase, bank_entry_id=entry['id'])) sequences.append(dict(id=f'{module}_scene_{scene:02d}', module_id=f'a1_{module}_v1', titles={'de-DE':de,'ru-RU':ru}, steps=steps)) assert len(sequences) == review['sequence_count'] == 60 return dict(revision=source['revision'], editorial_review_sha256=hashlib.sha256(review_bytes).hexdigest(), sequences=sequences) def build(): data = (json.dumps(compile_sequences(),ensure_ascii=False,indent=2)+'\n').encode() (DEST/'sequences.json').write_bytes(data) (DEST/'sequence_manifest.json').write_text(json.dumps({'sha256':hashlib.sha256(data).hexdigest()},indent=2)+'\n') print('Wrote 60 thematic learning sequences in six modules; no task content changed.') def audit(): data = (DEST/'sequences.json').read_bytes() assert hashlib.sha256(data).hexdigest() == json.loads((DEST/'sequence_manifest.json').read_text())['sha256'] assert json.loads(data) == compile_sequences() for seq in json.loads(data)['sequences']: assert seq['steps'][0]['phase']=='listen' and seq['steps'][-1]['phase']=='speak' assert all(seq['titles'][lang] for lang in ('de-DE','ru-RU')) assert seq['steps'][-2]['phase']=='compose' assert seq['steps'][-2]['bank_entry_id'].replace('_writing_','_speaking_') == seq['steps'][-1]['bank_entry_id'] print('PASS: 60 reviewed thematic sequences, listening first and free speaking after related recognition, repeat, grammar and writing; immutable task links.') if __name__ == '__main__': build() audit()