Remove legacy compatibility paths

This commit is contained in:
Thales Maciel 2026-02-26 13:30:01 -03:00
parent 5b38cc7dcd
commit b42298b9b5
8 changed files with 23 additions and 323 deletions

View file

@ -26,7 +26,6 @@ class ConfigTests(unittest.TestCase):
self.assertFalse(cfg.injection.remove_transcription_from_clipboard)
self.assertEqual(cfg.vocabulary.replacements, [])
self.assertEqual(cfg.vocabulary.terms, [])
self.assertTrue(cfg.domain_inference.enabled)
self.assertTrue(missing.exists())
written = json.loads(missing.read_text(encoding="utf-8"))
@ -48,7 +47,6 @@ class ConfigTests(unittest.TestCase):
],
"terms": ["Systemd", "Kubernetes"],
},
"domain_inference": {"enabled": True},
}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
@ -66,7 +64,6 @@ class ConfigTests(unittest.TestCase):
self.assertEqual(cfg.vocabulary.replacements[0].source, "Martha")
self.assertEqual(cfg.vocabulary.replacements[0].target, "Marta")
self.assertEqual(cfg.vocabulary.terms, ["Systemd", "Kubernetes"])
self.assertTrue(cfg.domain_inference.enabled)
def test_super_modifier_hotkey_is_valid(self):
payload = {"daemon": {"hotkey": "Super+m"}}
@ -98,28 +95,6 @@ class ConfigTests(unittest.TestCase):
):
load(str(path))
def test_loads_legacy_keys(self):
payload = {
"hotkey": "Alt+m",
"input": "Mic",
"whisper_model": "tiny",
"whisper_device": "cpu",
"injection_backend": "clipboard",
}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
cfg = load(str(path))
self.assertEqual(cfg.daemon.hotkey, "Alt+m")
self.assertEqual(cfg.recording.input, "Mic")
self.assertEqual(cfg.stt.model, "tiny")
self.assertEqual(cfg.stt.device, "cpu")
self.assertEqual(cfg.injection.backend, "clipboard")
self.assertFalse(cfg.injection.remove_transcription_from_clipboard)
self.assertEqual(cfg.vocabulary.replacements, [])
def test_invalid_injection_backend_raises(self):
payload = {"injection": {"backend": "invalid"}}
with tempfile.TemporaryDirectory() as td:
@ -138,41 +113,20 @@ class ConfigTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "injection.remove_transcription_from_clipboard"):
load(str(path))
def test_removed_ai_section_raises(self):
payload = {"ai": {"enabled": True}}
def test_unknown_top_level_fields_are_ignored(self):
payload = {
"custom_a": {"enabled": True},
"custom_b": {"nested": "value"},
"custom_c": 123,
}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "ai section is no longer supported"):
load(str(path))
cfg = load(str(path))
def test_removed_legacy_ai_enabled_raises(self):
payload = {"ai_enabled": True}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "ai_enabled is no longer supported"):
load(str(path))
def test_removed_logging_section_raises(self):
payload = {"logging": {"log_transcript": True}}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "no longer supported"):
load(str(path))
def test_removed_legacy_log_transcript_raises(self):
payload = {"log_transcript": True}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "no longer supported"):
load(str(path))
self.assertEqual(cfg.daemon.hotkey, "Cmd+m")
self.assertEqual(cfg.injection.backend, "clipboard")
def test_conflicting_replacements_raise(self):
payload = {
@ -224,32 +178,15 @@ class ConfigTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "wildcard"):
load(str(path))
def test_removed_domain_mode_raises(self):
payload = {"domain_inference": {"mode": "heuristic"}}
def test_unknown_vocabulary_fields_are_ignored(self):
payload = {"vocabulary": {"custom_limit": 100, "custom_extra": 200, "terms": ["Docker"]}}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "domain_inference.mode is no longer supported"):
load(str(path))
cfg = load(str(path))
def test_removed_vocabulary_max_rules_raises(self):
payload = {"vocabulary": {"max_rules": 100}}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "vocabulary.max_rules is no longer supported"):
load(str(path))
def test_removed_vocabulary_max_terms_raises(self):
payload = {"vocabulary": {"max_terms": 100}}
with tempfile.TemporaryDirectory() as td:
path = Path(td) / "config.json"
path.write_text(json.dumps(payload), encoding="utf-8")
with self.assertRaisesRegex(ValueError, "vocabulary.max_terms is no longer supported"):
load(str(path))
self.assertEqual(cfg.vocabulary.terms, ["Docker"])
if __name__ == "__main__":

View file

@ -7,18 +7,17 @@ SRC = ROOT / "src"
if str(SRC) not in sys.path:
sys.path.insert(0, str(SRC))
from config import DomainInferenceConfig, VocabularyConfig, VocabularyReplacement
from vocabulary import DOMAIN_GENERAL, VocabularyEngine
from config import VocabularyConfig, VocabularyReplacement
from vocabulary import VocabularyEngine
class VocabularyEngineTests(unittest.TestCase):
def _engine(self, replacements=None, terms=None, domain_enabled=True):
def _engine(self, replacements=None, terms=None):
vocab = VocabularyConfig(
replacements=replacements or [],
terms=terms or [],
)
domain = DomainInferenceConfig(enabled=domain_enabled)
return VocabularyEngine(vocab, domain)
return VocabularyEngine(vocab)
def test_boundary_aware_replacement(self):
engine = self._engine(
@ -50,27 +49,6 @@ class VocabularyEngineTests(unittest.TestCase):
self.assertLessEqual(len(hotwords), 1024)
self.assertLessEqual(len(prompt), 600)
def test_domain_inference_general_fallback(self):
engine = self._engine()
result = engine.infer_domain("please call me later")
self.assertEqual(result.name, DOMAIN_GENERAL)
self.assertEqual(result.confidence, 0.0)
def test_domain_inference_for_technical_text(self):
engine = self._engine(terms=["Docker", "Systemd"])
result = engine.infer_domain("restart Docker and systemd service on prod")
self.assertNotEqual(result.name, DOMAIN_GENERAL)
self.assertGreater(result.confidence, 0.0)
def test_domain_inference_can_be_disabled(self):
engine = self._engine(domain_enabled=False)
result = engine.infer_domain("please restart docker")
self.assertEqual(result.name, DOMAIN_GENERAL)
self.assertEqual(result.confidence, 0.0)
if __name__ == "__main__":
unittest.main()