forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ask.py
More file actions
47 lines (32 loc) · 2 KB
/
Copy pathtest_ask.py
File metadata and controls
47 lines (32 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Tests for the top-level ``omi ask`` command."""
from __future__ import annotations
import json
from omi_cli.main import app
def test_ask_posts_question_and_prints_answer(authed_profile, respx_mock, cli_runner) -> None:
route = respx_mock.post("/v1/dev/user/ask").respond(
json={
"answer": "You decided to raise prices 10%.",
"sources": [{"id": "c1", "title": "Pricing sync", "created_at": "2026-07-20T00:00:00Z"}],
}
)
result = cli_runner.invoke(app, ["ask", "what did I decide about pricing?"])
assert result.exit_code == 0
assert "You decided to raise prices 10%." in result.stdout
assert "Pricing sync" in result.stdout # source rendered
body = json.loads(route.calls[0].request.content)
assert body["question"] == "what did I decide about pricing?"
assert body["limit"] == 5 # default grounding size
def test_ask_forwards_timezone_verbatim_and_defaults_to_utc(authed_profile, respx_mock, cli_runner) -> None:
"""The CLI is not the validation boundary — the backend's ``DeveloperAskRequest``
validator is, so the option is forwarded as typed rather than pre-screened here.
A CLI-side IANA check would drift from the server's ``ZoneInfo`` database."""
route = respx_mock.post("/v1/dev/user/ask").respond(json={"answer": "ok", "sources": []})
assert cli_runner.invoke(app, ["ask", "when?"]).exit_code == 0
assert json.loads(route.calls[0].request.content)["timezone"] == "UTC"
assert cli_runner.invoke(app, ["ask", "when?", "--timezone", "Asia/Kolkata"]).exit_code == 0
assert json.loads(route.calls[1].request.content)["timezone"] == "Asia/Kolkata"
def test_ask_json_mode_emits_raw_payload(authed_profile, respx_mock, cli_runner) -> None:
respx_mock.post("/v1/dev/user/ask").respond(json={"answer": "42", "sources": []})
result = cli_runner.invoke(app, ["--json", "ask", "meaning of life?", "--limit", "3"])
assert result.exit_code == 0
assert json.loads(result.stdout) == {"answer": "42", "sources": []}