-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_process_session_id_callback.py
More file actions
82 lines (63 loc) · 2.35 KB
/
Copy pathtest_process_session_id_callback.py
File metadata and controls
82 lines (63 loc) · 2.35 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Tests for the on_session_id_resolved callback fired from inside the task group."""
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
import pytest
pytestmark = [pytest.mark.layer("execution"), pytest.mark.medium, pytest.mark.feature("execution")]
class TestOnSessionIdResolvedCallback:
"""on_session_id_resolved callback fires during live subprocess execution."""
@pytest.mark.anyio
async def test_callback_fires_with_resolved_session_id(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""When stdout emits a system init record, on_session_id_resolved fires."""
import anyio
from autoskillit.execution.process._process_race import (
RaceAccumulator,
_extract_stdout_session_id,
)
stdout_path = tmp_path / "stdout.jsonl"
session_id = "sess-callback-123"
init_record: dict[str, Any] = {
"type": "system",
"subtype": "init",
"session_id": session_id,
}
stdout_path.write_text(json.dumps(init_record) + "\n")
acc = RaceAccumulator()
ready = anyio.Event()
captured: list[str] = []
def on_sid(sid: str) -> None:
captured.append(sid)
await _extract_stdout_session_id(
stdout_path,
acc,
ready,
on_session_id_resolved=on_sid,
)
assert ready.is_set()
assert acc.stdout_session_id == session_id
assert captured == [session_id]
@pytest.mark.anyio
async def test_callback_not_called_when_no_session_id_found(self, tmp_path: Path) -> None:
"""When no init record is present, callback is never invoked."""
import anyio
from autoskillit.execution.process._process_race import (
RaceAccumulator,
_extract_stdout_session_id,
)
stdout_path = tmp_path / "stdout.jsonl"
stdout_path.write_text("")
acc = RaceAccumulator()
ready = anyio.Event()
captured: list[str] = []
await _extract_stdout_session_id(
stdout_path,
acc,
ready,
on_session_id_resolved=lambda sid: captured.append(sid),
_timeout=0.5,
)
assert not acc.stdout_session_id
assert captured == []