Files
breeze/tests/narration_text_matcher_test.py
waozi 017d3565d3 Build on Ziran 0.5.0 and Kryon's namespaced widgets, with the Tao picture page
Pin only pushed commits, with no local overrides: Ziran v0.5.0
(f9f92b46), Kryon b45cc524 (one lock entry, ref master, shared with the
Css and Plot master edges), Apps 352901e, Entity b30dd4a and practices
893e5b6f, whose sharpened banners and regenerated Lumi guide clips the
narration check now matches.

The Library opens each Tao Te Ching chapter on its own picture page: the
chapter art and its title, centered together; the text pages follow.
The reader keeps the picture page across reflow, and a chapter start or
a Contents pick opens it. The 81 approved chapter pictures are included.

Breeze now uses Kryon's namespaced widgets (Text.Draw/Text.Props,
Button, Image, Modal.ActionModal, Layout, TabBar, LoadingScreen,
LoadingIndicator, Shape.Circle) instead of the removed Kryon/Widgets
facades. Hosted apps import std/text explicitly, since a short "text"
import now names Kryon's widget. AGENTS.md and the Text/Button API checks
describe the namespaced forms; two unused test doubles are removed.

Build fixes for the new toolchain: the bundle runtime carries Ziran's
instruction engine (no BOOTSTRAP=1) and takes the pinned host zi2c for
cross builds; the Apps controller's lock context has the manifest's
module roots; the app codec generator lists Kryon's raw modules only;
the package scripts read ZX revision 28 bundle assets. The Apps
controller digest matches the Apps 352901e build.

Also included: the stopped lanes' work in this tree (Radio download,
Photos install, Lists, Lumi, Habits shop rewards, astral exercise
selection, appearance and download recovery) and the raylib-free desktop
lane's host modules (app_trace, host_input, host_window, host_clock),
inactive unless DESKTOP_HOST is defined.

Not included: the crash-recovery lane's picture-window and storage
crash-safety changes, which that lane commits itself.

Local tests: zi-check (510 modules), native and Android source checks,
hosted app checks, build-laws, clean-text-api-check, button-api-check,
library-reader-test, library-ui-test, storage-crash-zi-test and
native-image-decode-test pass. The bundled Arcade is still ZX revision 26
and waits for an Arcade build on these pins.
2026-11-16 14:20:12 -03:00

86 lines
4.3 KiB
Python

import difflib
import importlib.util
from pathlib import Path
import sys
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
spec = importlib.util.spec_from_file_location(
'matcher_speech', ROOT / 'scripts/generate-lumi-guide-narration.py')
speech = importlib.util.module_from_spec(spec)
spec.loader.exec_module(speech)
EXPECTED = (
"À partir du point devant votre visage, déplacez-vous dans le sens des aiguilles "
"d'une montre. Effleurez le côté droit de la pièce, puis l'espace derrière vous, "
"puis le côté gauche, puis revenez au point devant votre visage. Laissez le circuit "
"inclure plafond ou mur, surfaces latérales, sol ou lit, puis le retour. "
"Déplacez-vous avec fluidité, sans forcer la vitesse.")
TRANSCRIPT = EXPECTED.replace('surfaces latérales', 'surface latérale')
class NarrationTextMatcherTests(unittest.TestCase):
def setUp(self):
self.config = dict(minimum_match=.92, verify_directions=True, verify_numbers=True)
def test_preserved_long_french_witness(self):
expected = speech.normalized(EXPECTED)
heard = speech.normalized(TRANSCRIPT)
self.assertEqual((len(expected), len(heard)), (293, 291))
self.assertAlmostEqual(difflib.SequenceMatcher(None, expected, heard).ratio(),
.7534246575342466)
self.assertAlmostEqual(speech.match(EXPECTED, TRANSCRIPT), .9965753424657534)
score, detail = speech.assessment(
self.config, 'fr', EXPECTED, TRANSCRIPT, 25, local=True)
self.assertGreaterEqual(score, self.config['minimum_match'])
self.assertEqual(detail['reasons'], [])
def test_short_comparisons_retain_existing_scores(self):
for expected, heard in (('Relax.', 'Relax.'), ('Relax.', 'Release.'),
('呼吸を整えて。', '呼吸を整える。'), ('', ''), ('', 'Relax.')):
with self.subTest(expected=expected, heard=heard):
previous = difflib.SequenceMatcher(
None, speech.normalized(expected), speech.normalized(heard)).ratio()
self.assertEqual(speech.match(expected, heard), previous)
def test_missing_short_tail_fails_above_whole_text_threshold(self):
heard = EXPECTED.replace(', sans forcer la vitesse', '')
self.assertGreaterEqual(speech.match(EXPECTED, heard), self.config['minimum_match'])
score, detail = speech.assessment(
self.config, 'fr', EXPECTED, heard, 25, local=True)
self.assertEqual(score, 0)
self.assertIn('ending', detail['reasons'])
def test_wrong_long_text_is_rejected(self):
heard = 'Respirez calmement et reposez chaque muscle du corps. ' * 8
self.assertLess(speech.match(EXPECTED, heard), self.config['minimum_match'])
self.assertLess(speech.complete_match(
self.config, 'fr', EXPECTED, heard, 25, ming=True), self.config['minimum_match'])
def test_repetition_and_insertion_fail_with_matching_ending(self):
insertion = 'Respirez calmement et reposez chaque muscle du corps. ' * 3
for heard in (EXPECTED + ' ' + EXPECTED,
EXPECTED.replace('Laissez le circuit', insertion + 'Laissez le circuit')):
with self.subTest(heard=heard):
score, detail = speech.assessment(
self.config, 'fr', EXPECTED, heard, 40, local=True)
self.assertEqual(detail['ending_scores'], {'64': 1, '24': 1})
self.assertLess(score, self.config['minimum_match'])
self.assertIn('transcript', detail['reasons'])
def test_direction_and_number_gates_are_unchanged(self):
for heard in (EXPECTED.replace('côté droit', 'côté gauche'),
EXPECTED.replace('le retour', 'le retour 2')):
with self.subTest(heard=heard):
self.assertGreaterEqual(speech.match(EXPECTED, heard), self.config['minimum_match'])
self.assertEqual(speech.verified_match(self.config, 'fr', EXPECTED, heard), 0)
def test_normalization_is_unchanged(self):
self.assertEqual(speech.normalized('RELAX — 123!'), 'relax123')
self.assertEqual(speech.match('RELAX — 123!', 'relax 123'), 1)
if __name__ == '__main__':
unittest.main()