02f2a04b37
Implements docs/contracts/issues/1.contract.md. Four entry points
(stream_turn, reconnect_turn, cancel_turn, _parse_sse_id) + nine
typed Event variants + ten domain exceptions. 37 tests covering
every TESTS: entry verbatim, plus the boundary smoke test still
passes.
Tracer-bullet ordering per the contract's per-FN tracer tags:
_parse_sse_id (foundation; happy_simple) → stream_turn
(happy_one_text_done) → reconnect_turn (happy_resume_from_seq_3) →
cancel_turn (happy_cancel). Each FN's tracer went RED then GREEN
before its other tests landed.
Shared SSE-iteration logic (INV-002 sse_id presence + INV-003
turn_id stability + terminal-break) lives in private _iter_events
helper. expected_turn_id=None gives stream_turn's "establish from
first event" semantics; expected_turn_id=N gives reconnect_turn's
"first event is already a flip-candidate" semantics — the
two-entry-point distinction Volva surfaced during the paraphrase
round.
A few implementation choices worth recording:
- _parse_sse_id uses a `^-?\\d+$` regex pre-check to reject any
whitespace before int() is called. Python's `int(" 3 ")` silently
strips, which would have made the trailing_whitespace adversarial
test pass for the wrong reason.
- The connection_drop test uses a custom httpx.AsyncByteStream
subclass (_DropAfter) that yields chunks then raises
RemoteProtocolError mid-stream. respx alone can't simulate
mid-stream HTTP errors.
- ToolResult.result and ToolStart.arguments are typed as Any
because the server's tool wire shape varies per tool; the spec
doesn't pin a generic schema.
- Boundary smoke test (no core.* / worldtree.* imports under
src/ratatoskr/) still GREEN — INV-005 holds.
Also: one E501 line-length fix in test_no_worldtree_imports.py
that ruff flagged once the new tests pulled it into scope.
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""Boundary smoke test: Ratatoskr must not import from a Worldtree checkout.
|
|
|
|
The boundary rule (docs/design-brief.md §2): Ratatoskr depends on the
|
|
*published Conversation API spec* — vendored at `docs/conversation-api-spec.md`
|
|
at a pinned SHA — and NOT on any Worldtree source code. This test fails
|
|
loud if any file under `src/ratatoskr/` imports from `core.*`, `worldtree.*`,
|
|
or any other identifiable Worldtree module path.
|
|
|
|
If you find yourself wanting to import from Worldtree: stop. The right
|
|
move is one of:
|
|
- Re-derive the type from the vendored spec.
|
|
- File a question to worldtree-dev via althing (the spec is unclear).
|
|
- Bump the spec pin (`docs/SPEC-PIN.md`) and re-vendor if the spec moved.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import re
|
|
|
|
_FORBIDDEN_IMPORT_PATTERNS = [
|
|
re.compile(r"^\s*import\s+core(\.|\s|$)", re.MULTILINE),
|
|
re.compile(r"^\s*from\s+core(\.|\s+import)", re.MULTILINE),
|
|
re.compile(r"^\s*import\s+worldtree(\.|\s|$)", re.MULTILINE),
|
|
re.compile(r"^\s*from\s+worldtree(\.|\s+import)", re.MULTILINE),
|
|
]
|
|
|
|
_SRC_ROOT = pathlib.Path(__file__).parent.parent / "src" / "ratatoskr"
|
|
|
|
|
|
def test_no_worldtree_imports() -> None:
|
|
violations: list[tuple[pathlib.Path, str]] = []
|
|
for path in _SRC_ROOT.rglob("*.py"):
|
|
text = path.read_text(encoding="utf-8")
|
|
for pattern in _FORBIDDEN_IMPORT_PATTERNS:
|
|
for match in pattern.finditer(text):
|
|
line = text[: match.start()].count("\n") + 1
|
|
violations.append((path, f"line {line}: {match.group(0).strip()}"))
|
|
if violations:
|
|
report = "\n".join(
|
|
f" {p.relative_to(_SRC_ROOT.parent.parent)}: {v}" for p, v in violations
|
|
)
|
|
raise AssertionError(
|
|
"Ratatoskr must not import from Worldtree source. Violations:\n"
|
|
f"{report}\n\n"
|
|
"See docs/design-brief.md §2 (boundary rule) and "
|
|
"docs/SPEC-PIN.md (spec-pin discipline)."
|
|
)
|