Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
test(voice): pin the three cross-layer vocabularies of the voice section
Ruben Lütked83023191b24
diff --git a/tests/unit/dictation/test_outcome_parity.py b/tests/unit/dictation/test_outcome_parity.pynew file mode 100644index 0000000000..7458452805--- /dev/null+++ b/tests/unit/dictation/test_outcome_parity.py@@ -0,0 +1,127 @@+"""Cross-layer parity guard for the dictation outcome vocabulary (AP-4).++``jarvis.dictation.outcomes.DICTATION_OUTCOMES`` is the single source of truth+for "how did this dictation end". The value is written by the speech pipeline,+carried on ``DictationCompleted``, stored in the history sidecar, serialised by+the REST layer and finally turned into a label by the UI — the exact five-layer+shape that has drifted four times in this repo (BUG-008).++The two layers pinned here are the ones nothing else can catch:++* the TypeScript mirror in ``useDictation.ts``. A value missing there is not a+ type error — the UI simply falls through to rendering the raw identifier+ ("clipboard_only") at the user;+* the ``dictation.outcome.<name>`` key in every locale. A missing key renders+ the key itself on screen, in the one place whose whole job is to explain to+ a human what happened to their words.++Every parsed set is asserted NON-EMPTY before comparison, so a regex that stops+matching fails loudly instead of going trivially green against an empty set.+"""++from __future__ import annotations++import json+import re+from pathlib import Path++from jarvis.dictation.outcomes import (+ DICTATION_OUTCOMES,+ RECOVERABLE_OUTCOMES,+ is_recoverable,+)++_REPO_ROOT = Path(__file__).resolve().parents[3]+_FRONTEND = _REPO_ROOT / "jarvis" / "ui" / "web" / "frontend" / "src"+_DICTATION_TS = _FRONTEND / "hooks" / "useDictation.ts"+_HISTORY_GROUP_TSX = _FRONTEND / "views" / "voice" / "DictationHistoryGroup.tsx"+_LOCALES = _FRONTEND / "i18n" / "locales"++SUPPORTED_LOCALES = ("de", "en", "es")+++def _ts_outcomes() -> list[str]:+ """Members of ``export const DICTATION_OUTCOMES = [...] as const``."""+ assert _DICTATION_TS.exists(), f"frontend hook missing: {_DICTATION_TS}"+ source = _DICTATION_TS.read_text(encoding="utf-8")+ match = re.search(+ r"export const DICTATION_OUTCOMES\s*=\s*\[(.*?)\]\s*as const",+ source,+ re.DOTALL,+ )+ assert match is not None, f"DICTATION_OUTCOMES array not found in {_DICTATION_TS.name}"+ return re.findall(r'"([a-z_]+)"', match.group(1))+++def _locale(name: str) -> dict:+ path = _LOCALES / f"{name}.json"+ assert path.exists(), f"locale file missing: {path}"+ return json.loads(path.read_text(encoding="utf-8"))+++def test_the_python_vocabulary_is_a_usable_set() -> None:+ assert DICTATION_OUTCOMES, "DICTATION_OUTCOMES is empty"+ assert len(set(DICTATION_OUTCOMES)) == len(DICTATION_OUTCOMES), DICTATION_OUTCOMES+++def test_ts_outcome_array_mirrors_the_python_vocabulary() -> None:+ members = _ts_outcomes()+ # Guard against a trivially-green empty/partial parse.+ assert members, f"parsed no outcomes from {_DICTATION_TS.name}"+ assert len(members) == len(set(members)), members+ assert len(members) == len(DICTATION_OUTCOMES), members+ assert set(members) == set(DICTATION_OUTCOMES)+++def test_every_outcome_has_a_label_in_every_locale() -> None:+ assert DICTATION_OUTCOMES, "DICTATION_OUTCOMES is empty"+ for name in SUPPORTED_LOCALES:+ table = _locale(name).get("dictation", {}).get("outcome", {})+ assert isinstance(table, dict) and table, f"{name}.json: dictation.outcome missing"+ for outcome in DICTATION_OUTCOMES:+ value = table.get(outcome)+ assert isinstance(value, str) and value.strip(), (+ f"{name}.json: dictation.outcome.{outcome}"+ )+++def test_no_locale_carries_an_outcome_key_the_backend_never_emits() -> None:+ """A stale key is drift in the other direction — dead copy nobody maintains."""+ for name in SUPPORTED_LOCALES:+ table = _locale(name).get("dictation", {}).get("outcome", {})+ assert set(table) == set(DICTATION_OUTCOMES), f"{name}.json: {sorted(table)}"+++def test_the_renderer_derives_its_known_set_from_the_shared_array() -> None:+ """The UI must not keep a second, hand-written copy of the vocabulary.++ ``DictationHistoryGroup`` decides whether to translate an outcome or to+ print it verbatim. If that decision ran off a locally declared list, a new+ outcome would render as a raw identifier even after the shared array was+ updated — a second SSOT is exactly what this whole file exists to prevent.+ """+ assert _HISTORY_GROUP_TSX.exists(), f"missing: {_HISTORY_GROUP_TSX}"+ source = _HISTORY_GROUP_TSX.read_text(encoding="utf-8")+ assert "DICTATION_OUTCOMES" in source, _HISTORY_GROUP_TSX.name+ assert "new Set(DICTATION_OUTCOMES)" in source, (+ f"{_HISTORY_GROUP_TSX.name} no longer derives its known-outcome set "+ "from the shared array"+ )+ # No second literal array of outcomes anywhere in the renderer.+ assert not re.search(r"\[\s*\"inserted\"", source), _HISTORY_GROUP_TSX.name+++def test_recoverable_outcomes_are_a_real_subset_and_discarded_is_not_one() -> None:+ """``discarded`` is a boolean field, never an outcome (AD-6).++ Folding the two into one string would make "inserted, then discarded by the+ user" unrepresentable, which is a state the history genuinely has.+ """+ assert RECOVERABLE_OUTCOMES, "RECOVERABLE_OUTCOMES is empty"+ assert RECOVERABLE_OUTCOMES < set(DICTATION_OUTCOMES)+ assert "discarded" not in DICTATION_OUTCOMES+ for outcome in DICTATION_OUTCOMES:+ assert is_recoverable(outcome) is (outcome in RECOVERABLE_OUTCOMES), outcome+ # Tolerant on unknown input: a newer backend value must not raise.+ assert is_recoverable("something_new_from_a_newer_install") is False+ assert is_recoverable(None) is Falsediff --git a/tests/unit/ui/web/test_keybind_action_ts_parity.py b/tests/unit/ui/web/test_keybind_action_ts_parity.pynew file mode 100644index 0000000000..43a7815c4d--- /dev/null+++ b/tests/unit/ui/web/test_keybind_action_ts_parity.py@@ -0,0 +1,109 @@+"""Cross-layer parity guard for the voice keybind action vocabulary (AP-4).++A keybind action is a value that crosses five layers: the ``TriggerConfig``+field that stores the combo, the ``KEYBIND_ACTIONS`` / ``KEYBIND_TOML_KEY``+tables in ``config_writer``, the ``/api/settings/keybinds`` payload built from+them, the TypeScript ``KeybindAction`` union the frontend is written against,+and the ``settings_view.keybinds.<action>_label`` string every locale has to+carry.++Every one of those layers fails SILENTLY on drift, which is what makes this+the enum-drift class that has recurred four times here (BUG-008):++* an action missing from the TS union is simply never rendered — the row for+ the new shortcut does not appear and nothing errors;+* an action whose ``KEYBIND_TOML_KEY`` value is not a real ``TriggerConfig``+ field makes the derived ``defaults`` map fall back to ``""``, so the UI+ offers "Reset to default" and resets to *unbound*;+* a missing locale key renders the raw key on screen+ ("settings_view.keybinds.dictate_toggle_label").++Every parsed set is asserted NON-EMPTY before it is compared, so a regex that+stops matching (a reformat, a rename, a move to another file) fails loudly+instead of passing against an empty set.+"""++from __future__ import annotations++import json+import re+from pathlib import Path++from jarvis.core.config import TriggerConfig+from jarvis.core.config_writer import KEYBIND_ACTIONS, KEYBIND_TOML_KEY++_REPO_ROOT = Path(__file__).resolve().parents[4]+_FRONTEND = _REPO_ROOT / "jarvis" / "ui" / "web" / "frontend" / "src"+_HOTKEY_TS = _FRONTEND / "hooks" / "useHotkey.ts"+_LOCALES = _FRONTEND / "i18n" / "locales"++#: The locales the product ships. All of them are equal (CLAUDE.md §1) — a key+#: that exists only in English is a bug for every other user, not a nicety.+SUPPORTED_LOCALES = ("de", "en", "es")+++def _ts_keybind_actions() -> set[str]:+ """Members of ``export type KeybindAction = "a" | "b";`` in useHotkey.ts."""+ assert _HOTKEY_TS.exists(), f"frontend hook missing: {_HOTKEY_TS}"+ source = _HOTKEY_TS.read_text(encoding="utf-8")+ match = re.search(r"export type KeybindAction\s*=\s*(.+?);", source, re.DOTALL)+ assert match is not None, f"KeybindAction union not found in {_HOTKEY_TS.name}"+ return set(re.findall(r'"([a-z_]+)"', match.group(1)))+++def _locale(name: str) -> dict:+ path = _LOCALES / f"{name}.json"+ assert path.exists(), f"locale file missing: {path}"+ return json.loads(path.read_text(encoding="utf-8"))+++def _nested(data: dict, dotted: str) -> object | None:+ node: object = data+ for part in dotted.split("."):+ if not isinstance(node, dict):+ return None+ node = node.get(part) # type: ignore[assignment]+ if node is None:+ return None+ return node+++def test_python_keybind_tables_agree_with_each_other() -> None:+ """``KEYBIND_ACTIONS`` and ``KEYBIND_TOML_KEY`` are one vocabulary, not two."""+ assert KEYBIND_ACTIONS, "KEYBIND_ACTIONS is empty"+ assert len(set(KEYBIND_ACTIONS)) == len(KEYBIND_ACTIONS), KEYBIND_ACTIONS+ assert set(KEYBIND_TOML_KEY) == set(KEYBIND_ACTIONS)+++def test_every_action_maps_to_a_real_trigger_config_field() -> None:+ """The derived ``defaults`` map is only honest if every field exists.++ ``settings_routes`` builds the defaults with ``getattr(TriggerConfig(), f,+ "")``. A typo'd or removed field would silently degrade to ``""``, so the+ "reset to default" button would unbind the shortcut instead of restoring+ it — a wrong answer that looks like a working feature.+ """+ defaults = TriggerConfig()+ assert KEYBIND_TOML_KEY, "KEYBIND_TOML_KEY is empty"+ for action, field in KEYBIND_TOML_KEY.items():+ assert hasattr(defaults, field), f"{action} -> TriggerConfig.{field} missing"+ assert isinstance(getattr(defaults, field), str), action+++def test_ts_keybind_action_union_mirrors_the_python_vocabulary() -> None:+ members = _ts_keybind_actions()+ # Guard against a trivially-green empty/partial parse.+ assert members, f"parsed no KeybindAction members from {_HOTKEY_TS.name}"+ assert len(members) == len(KEYBIND_ACTIONS), members+ assert members == set(KEYBIND_ACTIONS)+++def test_every_action_has_a_label_in_every_locale() -> None:+ """A missing label renders the raw i18n key at the user."""+ assert KEYBIND_ACTIONS, "KEYBIND_ACTIONS is empty"+ for name in SUPPORTED_LOCALES:+ data = _locale(name)+ for action in KEYBIND_ACTIONS:+ key = f"settings_view.keybinds.{action}_label"+ value = _nested(data, key)+ assert isinstance(value, str) and value.strip(), f"{name}.json: {key}"diff --git a/tests/unit/ui/web/test_section_id_parity.py b/tests/unit/ui/web/test_section_id_parity.pynew file mode 100644index 0000000000..a4057687b8--- /dev/null+++ b/tests/unit/ui/web/test_section_id_parity.py@@ -0,0 +1,241 @@+"""Cross-layer parity guard for the sidebar section ids (AP-4).++A section id crosses more layers than it looks: the ``SectionId`` union, the+``SECTION_IDS`` array, the ``SECTION_LABELS`` record (all three in+``store/events.ts``), the ``MainView`` switch that decides which view is+mounted, the ``Sidebar`` row that has to stay highlighted for it, the tab bar+of the merged voice section, and a ``nav.*`` string in every locale.++TypeScript catches almost none of that. ``as const satisfies readonly+SectionId[]`` only rejects an array entry that is missing from the union —+never a union member missing from the array (docs/BUGS.md, the recurring+enum-drift class). A tab id that never reaches ``MainView`` renders a blank+pane. An id missing from ``matchIds`` un-highlights the sidebar row while the+user is standing on it. A missing locale key prints "nav.voice_language" at+the user.++The set of ids parsed out of each layer is asserted NON-EMPTY before it is+compared, so a reformat that breaks a regex fails loudly instead of passing+against an empty set.++Not covered here on purpose: ``SECTION_IDS`` <-> ``navigate.KNOWN`` set+equality, which ``tests/unit/plugins/tool/test_navigate.py`` already derives+from both sides.+"""++from __future__ import annotations++import json+import re+from pathlib import Path++_REPO_ROOT = Path(__file__).resolve().parents[4]+_FRONTEND = _REPO_ROOT / "jarvis" / "ui" / "web" / "frontend" / "src"+_EVENTS_TS = _FRONTEND / "store" / "events.ts"+_MAIN_VIEW_TSX = _FRONTEND / "components" / "layout" / "MainView.tsx"+_SIDEBAR_TSX = _FRONTEND / "components" / "layout" / "Sidebar.tsx"+_VOICE_HUB_TSX = _FRONTEND / "views" / "VoiceHubView.tsx"+_LOCALES = _FRONTEND / "i18n" / "locales"++SUPPORTED_LOCALES = ("de", "en", "es")++#: The five tabs behind the merged voice section. "dictation" and "dictionary"+#: keep their original ids on purpose — renaming them would break the+#: Command-Registry ``ui_section`` binding and every existing voice deep-link.+EXPECTED_VOICE_TABS = (+ "dictation",+ "dictionary",+ "voice-shortcuts",+ "voice-language",+ "voice-api-keys",+)+++def _read(path: Path) -> str:+ assert path.exists(), f"frontend file missing: {path}"+ return path.read_text(encoding="utf-8")+++def _strip_comments(source: str) -> str:+ """Drop ``//`` and ``/* */`` comments.++ The union and the label record are heavily commented, and those comments+ quote ids ("dictation", "{name} Voice"). Parsing them as members would make+ the test agree with prose instead of with code.+ """+ source = re.sub(r"/\*.*?\*/", "", source, flags=re.DOTALL)+ return re.sub(r"//[^\n]*", "", source)+++def _union_members() -> set[str]:+ body = re.search(+ r"export type SectionId\s*=\s*(.+?);", _strip_comments(_read(_EVENTS_TS)), re.DOTALL+ )+ assert body is not None, "SectionId union not found in events.ts"+ return set(re.findall(r'"([a-z0-9_-]+)"', body.group(1)))+++def _section_ids() -> list[str]:+ body = re.search(+ r"export const SECTION_IDS\s*=\s*\[(.*?)\]\s*as const",+ _strip_comments(_read(_EVENTS_TS)),+ re.DOTALL,+ )+ assert body is not None, "SECTION_IDS array not found in events.ts"+ return re.findall(r'"([a-z0-9_-]+)"', body.group(1))+++def _section_labels() -> dict[str, str]:+ body = re.search(+ r"export const SECTION_LABELS[^=]*=\s*\{(.*?)\n\};",+ _strip_comments(_read(_EVENTS_TS)),+ re.DOTALL,+ )+ assert body is not None, "SECTION_LABELS record not found in events.ts"+ pairs = re.findall(r'^\s*"?([a-z0-9_-]+)"?\s*:\s*"([^"]*)"', body.group(1), re.M)+ return dict(pairs)+++def _voice_tabs() -> list[tuple[str, str]]:+ """``(section id, i18n label key)`` for every tab of the voice hub."""+ body = re.search(+ r"const TABS\s*=\s*\[(.*?)\]\s*as const", _read(_VOICE_HUB_TSX), re.DOTALL+ )+ assert body is not None, "TABS array not found in VoiceHubView.tsx"+ return re.findall(+ r'id:\s*"([a-z0-9_-]+)"\s*,\s*labelKey:\s*"([a-z0-9_.]+)"', body.group(1)+ )+++def _voice_hub_routed_ids() -> set[str]:+ """Every ``case "…":`` that falls through to ``<VoiceHubView />``."""+ body = re.search(+ r'((?:\s*case\s+"[a-z0-9_-]+":)+)\s*return\s*<VoiceHubView\s*/>;',+ _read(_MAIN_VIEW_TSX),+ )+ assert body is not None, "VoiceHubView switch arm not found in MainView.tsx"+ return set(re.findall(r'case\s+"([a-z0-9_-]+)":', body.group(1)))+++def _sidebar_voice_match_ids() -> set[str]:+ """The ``matchIds`` of the single sidebar row labelled ``nav.voice``."""+ body = re.search(+ r'labelKey:\s*"nav\.voice"\s*,[\s\S]{0,400}?matchIds:\s*\[([^\]]*)\]',+ _read(_SIDEBAR_TSX),+ )+ assert body is not None, "voice NavItem with matchIds not found in Sidebar.tsx"+ return set(re.findall(r'"([a-z0-9_-]+)"', body.group(1)))+++def _locale(name: str) -> dict:+ path = _LOCALES / f"{name}.json"+ assert path.exists(), f"locale file missing: {path}"+ return json.loads(path.read_text(encoding="utf-8"))+++def _nested(data: dict, dotted: str) -> object | None:+ node: object = data+ for part in dotted.split("."):+ if not isinstance(node, dict):+ return None+ node = node.get(part) # type: ignore[assignment]+ if node is None:+ return None+ return node+++def test_the_three_section_id_layers_are_one_set() -> None:+ """`satisfies` only guards one direction; this guards both."""+ union = _union_members()+ array = _section_ids()+ labels = _section_labels()+ # Guard against a trivially-green empty/partial parse of any layer.+ assert union, "parsed no SectionId union members"+ assert array, "parsed no SECTION_IDS entries"+ assert labels, "parsed no SECTION_LABELS entries"+ assert len(array) == len(set(array)), array+ assert set(array) == union, set(array).symmetric_difference(union)+ assert set(labels) == union, set(labels).symmetric_difference(union)+++def test_every_section_label_is_a_readable_non_empty_string() -> None:+ """These labels are read back verbatim by the voice-navigation toast.++ They are deliberately plain English and NOT interpolated, so a ``{name}``+ token here would be spoken and rendered literally.+ """+ labels = _section_labels()+ assert labels, "parsed no SECTION_LABELS entries"+ for section, label in labels.items():+ assert label.strip(), section+ assert "{name}" not in label, f"{section}: {label!r} is never interpolated"+++def test_the_voice_hub_fronts_exactly_the_expected_tabs() -> None:+ tabs = _voice_tabs()+ assert tabs, "parsed no tabs from VoiceHubView.tsx"+ assert [section for section, _ in tabs] == list(EXPECTED_VOICE_TABS)+++def test_every_voice_tab_is_a_real_section_with_a_label() -> None:+ tabs = _voice_tabs()+ assert tabs, "parsed no tabs from VoiceHubView.tsx"+ known = set(_section_ids())+ labels = _section_labels()+ assert known and labels+ for section, _ in tabs:+ assert section in known, f"tab {section} is not a SectionId"+ assert labels.get(section, "").strip(), f"tab {section} has no SECTION_LABELS entry"+++def test_every_voice_tab_is_routed_and_stays_highlighted() -> None:+ """A tab id that never reaches MainView renders a blank pane."""+ tabs = {section for section, _ in _voice_tabs()}+ routed = _voice_hub_routed_ids()+ matched = _sidebar_voice_match_ids()+ assert tabs, "parsed no tabs from VoiceHubView.tsx"+ assert routed, "parsed no case labels from the MainView VoiceHubView arm"+ assert matched, "parsed no matchIds from the Sidebar voice row"+ assert routed == tabs, routed.symmetric_difference(tabs)+ assert matched == tabs, matched.symmetric_difference(tabs)+++def test_every_voice_tab_label_key_resolves_in_every_locale() -> None:+ tabs = _voice_tabs()+ assert tabs, "parsed no tabs from VoiceHubView.tsx"+ for name in SUPPORTED_LOCALES:+ data = _locale(name)+ for section, label_key in tabs:+ value = _nested(data, label_key)+ assert isinstance(value, str) and value.strip(), (+ f"{name}.json: {label_key} (tab {section})"+ )+++def test_every_voice_section_id_has_a_nav_key_in_every_locale() -> None:+ """The naming convention that keeps a new voice tab from shipping unlabelled.++ Section ids are hyphenated ("voice-shortcuts"); the locale keys under+ ``nav`` are the same value with underscores.+ """+ voice_ids = [s for s in _section_ids() if s.startswith("voice-")]+ assert voice_ids, "parsed no voice-* section ids"+ for name in SUPPORTED_LOCALES:+ data = _locale(name)+ for section in voice_ids:+ key = f"nav.{section.replace('-', '_')}"+ value = _nested(data, key)+ assert isinstance(value, str) and value.strip(), f"{name}.json: {key}"+++def test_the_merged_sidebar_row_carries_the_brand_token_not_a_name() -> None:+ """CLAUDE.md §4 — the user-visible brand is derived from the wake word.++ ``nav.voice`` is the one label of this section that reaches the sidebar, so+ a hardcoded product name here would show up for every user regardless of+ the wake word they chose.+ """+ for name in SUPPORTED_LOCALES:+ value = _nested(_locale(name), "nav.voice")+ assert isinstance(value, str) and value.strip(), f"{name}.json: nav.voice"+ assert "{name}" in value, f"{name}.json: nav.voice lost the brand token"