|
16 | 16 |
|
17 | 17 | from aai_cli.app.context import AppState |
18 | 18 | from aai_cli.commands.dictate import _exec as dictate_exec |
19 | | -from aai_cli.core import config, sync_stt |
20 | | -from aai_cli.core.errors import CLIError |
| 19 | +from aai_cli.core import choices, config, sync_stt |
| 20 | +from aai_cli.core.errors import CLIError, UsageError |
21 | 21 |
|
22 | 22 | DICTATE_DEFAULTS = dictate_exec.DictateOptions( |
23 | 23 | language=None, |
@@ -145,6 +145,34 @@ def test_json_mode_emits_one_ndjson_object_per_utterance(seams, capsys): |
145 | 145 | assert captured.err == "" |
146 | 146 |
|
147 | 147 |
|
| 148 | +def test_output_json_folds_into_ndjson_without_the_json_flag(seams, capsys): |
| 149 | + # -o json must enable NDJSON on its own (json_mode stays the --json flag, |
| 150 | + # which is False here) — proving the -o/--output resolution runs. |
| 151 | + seams["keys"] = FakeKeys(["\r", "\r"]) |
| 152 | + _run(dataclasses.replace(DICTATE_DEFAULTS, output_field=choices.TextOrJson.json)) |
| 153 | + assert json.loads(capsys.readouterr().out)["text"] == "hello world" |
| 154 | + |
| 155 | + |
| 156 | +def test_output_text_emits_bare_transcript(seams, capsys): |
| 157 | + # -o text is the explicit spelling of the human default: bare text, no JSON. |
| 158 | + seams["keys"] = FakeKeys(["\r", "\r"]) |
| 159 | + _run(dataclasses.replace(DICTATE_DEFAULTS, output_field=choices.TextOrJson.text)) |
| 160 | + out = capsys.readouterr().out |
| 161 | + assert out.strip() == "hello world" |
| 162 | + assert "{" not in out |
| 163 | + |
| 164 | + |
| 165 | +def test_output_text_conflicts_with_json_flag(seams): |
| 166 | + # --json + -o text are contradictory output shapes: a clean usage error, |
| 167 | + # the same as `stream`/`agent`. |
| 168 | + seams["keys"] = FakeKeys(["\r", "\r"]) |
| 169 | + with pytest.raises(UsageError): |
| 170 | + _run( |
| 171 | + dataclasses.replace(DICTATE_DEFAULTS, output_field=choices.TextOrJson.text), |
| 172 | + json_mode=True, |
| 173 | + ) |
| 174 | + |
| 175 | + |
148 | 176 | def test_quiet_suppresses_the_interactive_hints(seams, capsys): |
149 | 177 | seams["keys"] = FakeKeys(["\r", "\r"]) |
150 | 178 | _run(state=AppState(quiet=True)) |
|
0 commit comments