Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/typescript-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: TypeScript SDK CI
on:
pull_request:
paths:
- 'README.md'
- 'typescript/**'
- 'openapi/**'
- 'scripts/**'
Expand All @@ -17,6 +18,7 @@ on:
push:
branches: [main]
paths:
- 'README.md'
- 'typescript/**'
- 'openapi/**'
- 'scripts/**'
Expand Down
403 changes: 60 additions & 343 deletions README.md

Large diffs are not rendered by default.

466 changes: 60 additions & 406 deletions python/README.md

Large diffs are not rendered by default.

384 changes: 384 additions & 0 deletions python/docs/usage.md

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions python/tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Execute the published quickstart with the real SDK and synthetic HTTP replies."""

import copy
import re
from pathlib import Path

import pytest
import zelinqa
from spec_examples import ARRET_SANS_QUESTION, DECISION_NORMALE, SESSION_NEUVE
from test_runtime_client import Recorder, json_response, sync_client

README = Path(__file__).resolve().parents[1] / "README.md"


def quickstart():
examples = re.findall(r"```python\n(.*?)\n```", README.read_text(), re.DOTALL)
assert len(examples) == 1, "Every executable README example must be tested"
return compile(examples[0], str(README), "exec")


def decision_for(kind):
decision = copy.deepcopy(DECISION_NORMALE)
candidate = decision["candidates"][0]
candidate["type"] = kind
candidate["selection_mode"] = None if kind == "open" else "single"
if kind == "multiple_choice":
candidate["selection_mode"] = "multiple"
candidate["choices"] = (
[] if kind == "open" else [{"choice_id": "choice-email", "label": "Email"}]
)
return decision


@pytest.mark.parametrize(
"kind,reply",
[
("open", "I need to qualify inbound requests."),
("single_choice", "Email"),
("multiple_choice", "Email"),
("semi_open", "Email"),
("open", ""),
("open", " "),
("single_choice", ""),
],
)
def test_quickstart_submits_the_real_reply(monkeypatch, kind, reply):
decision = decision_for(kind)
recorder = Recorder(
json_response(201, SESSION_NEUVE),
json_response(200, decision),
json_response(200, ARRET_SANS_QUESTION),
)
monkeypatch.setattr(zelinqa, "ZelinqaClient", lambda: sync_client(recorder))
monkeypatch.setattr("builtins.input", lambda prompt: reply)

exec(quickstart(), {})

assert len(recorder.requests) == 3
assert recorder.body(0)["client_reference"] == "demo-001"
body = recorder.body()
assert body["state_version"] == decision["versions"]["state_version"]
previous = body["previous_turn"]
assert previous["decision_id"] == decision["decision_id"]
assert previous["question_id"] == decision["candidates"][0]["question_id"]
if not reply.strip():
assert previous["outcome"] == "asked_no_answer"
assert previous.get("user_text") is None
assert previous.get("structured_answer") is None
elif kind == "open":
assert previous["user_text"] == reply
assert previous.get("structured_answer") is None
else:
assert previous["structured_answer"]["choice_ids"] == ["choice-email"]
assert previous.get("user_text") is None


def test_quickstart_does_not_ask_after_stop(monkeypatch):
recorder = Recorder(json_response(201, SESSION_NEUVE), json_response(200, ARRET_SANS_QUESTION))
monkeypatch.setattr(zelinqa, "ZelinqaClient", lambda: sync_client(recorder))
monkeypatch.setattr("builtins.input", lambda prompt: pytest.fail("No question is pending"))

exec(quickstart(), {})

assert len(recorder.requests) == 2


def test_quickstart_rejects_an_unknown_label_before_sending(monkeypatch):
recorder = Recorder(
json_response(201, SESSION_NEUVE), json_response(200, decision_for("single_choice"))
)
monkeypatch.setattr(zelinqa, "ZelinqaClient", lambda: sync_client(recorder))
monkeypatch.setattr("builtins.input", lambda prompt: "Not a displayed choice")

with pytest.raises(ValueError, match="Unknown or ambiguous choice label"):
exec(quickstart(), {})

assert len(recorder.requests) == 2
Loading
Loading