irimi-sdk 0.2.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- irimi/__init__.py +4 -0
- irimi/_aiohttp_patch.py +371 -0
- irimi/_aiohttp_serving.py +216 -0
- irimi/_atomic_total.py +14 -0
- irimi/_bodies.py +64 -0
- irimi/_credential_headers.py +52 -0
- irimi/_decorators.py +236 -0
- irimi/_delivery.py +70 -0
- irimi/_divergence.py +60 -0
- irimi/_drops.py +24 -0
- irimi/_errors.py +14 -0
- irimi/_exporter.py +193 -0
- irimi/_function_answers.py +87 -0
- irimi/_git.py +37 -0
- irimi/_httpx_patch.py +236 -0
- irimi/_interception.py +174 -0
- irimi/_labeled_calls.py +116 -0
- irimi/_llm_providers.py +57 -0
- irimi/_object_fields.py +32 -0
- irimi/_outbound_calls.py +190 -0
- irimi/_patching.py +58 -0
- irimi/_rebuilding.py +97 -0
- irimi/_recorded_calls.py +231 -0
- irimi/_recording.py +122 -0
- irimi/_recording_loader.py +63 -0
- irimi/_replay_child.py +156 -0
- irimi/_replay_decisions.py +120 -0
- irimi/_replay_fields.py +16 -0
- irimi/_replay_proxy.py +328 -0
- irimi/_replay_refusals.py +5 -0
- irimi/_response_recording.py +74 -0
- irimi/_sdk.py +318 -0
- irimi/_serialisation.py +114 -0
- irimi/_status_reasons.py +10 -0
- irimi/_unpatched_clients.py +105 -0
- irimi/_url_credentials.py +11 -0
- irimi/_urllib3_patch.py +465 -0
- irimi/_urllib3_serving.py +81 -0
- irimi/_wire/__init__.py +56 -0
- irimi/_wire/call_roles.py +32 -0
- irimi/_wire/events.py +209 -0
- irimi/_wire/field_names.py +80 -0
- irimi/_wire/json_value.py +3 -0
- irimi/_wire/markers.py +49 -0
- irimi/py.typed +0 -0
- irimi_sdk-0.2.0.dev0.dist-info/METADATA +81 -0
- irimi_sdk-0.2.0.dev0.dist-info/RECORD +48 -0
- irimi_sdk-0.2.0.dev0.dist-info/WHEEL +4 -0
irimi/_wire/events.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import string
|
|
4
|
+
from collections.abc import Mapping
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from irimi._wire.json_value import JsonValue
|
|
8
|
+
|
|
9
|
+
WIRE_VERSION = "v1"
|
|
10
|
+
EVENTS_PATH = f"/{WIRE_VERSION}/events"
|
|
11
|
+
RUN_EVENTS_PATH = f"/{WIRE_VERSION}/runs/{{trace_id}}/events"
|
|
12
|
+
EVENT_FIELD_NAMES = frozenset({"id", "type", "trace_id", "span_id", "time_unix_nano"})
|
|
13
|
+
START_FIELD_NAMES = frozenset({"parent_span_id", "kind", "name", "seq"})
|
|
14
|
+
ID_CHARACTERS = frozenset(string.ascii_letters + string.digits + "-_")
|
|
15
|
+
LARGEST_ID_LENGTH = 128
|
|
16
|
+
LARGEST_WHOLE_NUMBER = 2**63 - 1
|
|
17
|
+
LARGEST_SEQ = 2**53 - 1
|
|
18
|
+
DIGITS_IN_LARGEST_WHOLE_NUMBER = len(str(LARGEST_WHOLE_NUMBER))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WireFormatError(ValueError):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class Event:
|
|
27
|
+
id: str
|
|
28
|
+
type: str
|
|
29
|
+
trace_id: str
|
|
30
|
+
span_id: str
|
|
31
|
+
time_unix_nano: int
|
|
32
|
+
fields: Mapping[str, JsonValue]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class StartEvent(Event):
|
|
37
|
+
parent_span_id: str | None
|
|
38
|
+
kind: str
|
|
39
|
+
name: str
|
|
40
|
+
seq: int
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True)
|
|
44
|
+
class EndEvent(Event):
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class Batch:
|
|
50
|
+
events: tuple[Event, ...]
|
|
51
|
+
fields: Mapping[str, JsonValue]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class RefusedEvent:
|
|
56
|
+
index: int
|
|
57
|
+
reason: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@dataclass(frozen=True)
|
|
61
|
+
class ParsedBatch:
|
|
62
|
+
batch: Batch
|
|
63
|
+
refused: tuple[RefusedEvent, ...]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def parse_batch(document: JsonValue) -> ParsedBatch:
|
|
67
|
+
if not isinstance(document, dict):
|
|
68
|
+
raise WireFormatError("batch: expected an object")
|
|
69
|
+
events = document.get("events")
|
|
70
|
+
if not isinstance(events, list):
|
|
71
|
+
raise WireFormatError("batch.events: expected a list")
|
|
72
|
+
accepted: list[Event] = []
|
|
73
|
+
refused: list[RefusedEvent] = []
|
|
74
|
+
for index, event in enumerate(events):
|
|
75
|
+
try:
|
|
76
|
+
accepted.append(parse_event(event, f"events[{index}]"))
|
|
77
|
+
except WireFormatError as error:
|
|
78
|
+
refused.append(RefusedEvent(index=index, reason=str(error)))
|
|
79
|
+
return ParsedBatch(
|
|
80
|
+
batch=Batch(events=tuple(accepted), fields=_without(document, frozenset({"events"}))),
|
|
81
|
+
refused=tuple(refused),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def write_batch(batch: Batch) -> dict[str, JsonValue]:
|
|
86
|
+
events: list[JsonValue] = [write_event(event) for event in batch.events]
|
|
87
|
+
return {**batch.fields, "events": events}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def parse_refused_events(document: JsonValue) -> tuple[RefusedEvent, ...]:
|
|
91
|
+
if not isinstance(document, dict):
|
|
92
|
+
raise WireFormatError("answer: expected an object")
|
|
93
|
+
refused = document.get("refused")
|
|
94
|
+
if not isinstance(refused, list):
|
|
95
|
+
raise WireFormatError("answer.refused: expected a list")
|
|
96
|
+
return tuple(
|
|
97
|
+
_parse_refused_event(item, f"refused[{place}]") for place, item in enumerate(refused)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def write_refused_events(refused: tuple[RefusedEvent, ...]) -> dict[str, JsonValue]:
|
|
102
|
+
return {"refused": [{"index": event.index, "reason": event.reason} for event in refused]}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _parse_refused_event(document: JsonValue, place: str) -> RefusedEvent:
|
|
106
|
+
if not isinstance(document, dict):
|
|
107
|
+
raise WireFormatError(f"{place}: expected an object")
|
|
108
|
+
index = document.get("index")
|
|
109
|
+
if isinstance(index, bool) or not isinstance(index, int):
|
|
110
|
+
raise WireFormatError(f"{place}.index: expected a whole number")
|
|
111
|
+
return RefusedEvent(index=index, reason=_read_string(document, "reason", place))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def parse_event(document: JsonValue, place: str = "event") -> Event:
|
|
115
|
+
if not isinstance(document, dict):
|
|
116
|
+
raise WireFormatError(f"{place}: expected an object")
|
|
117
|
+
event_type = _read_string(document, "type", place)
|
|
118
|
+
if event_type == "start":
|
|
119
|
+
return _parse_start_event(document, place)
|
|
120
|
+
event_class = EndEvent if event_type == "end" else Event
|
|
121
|
+
return event_class(
|
|
122
|
+
id=_read_id(document, "id", place),
|
|
123
|
+
type=event_type,
|
|
124
|
+
trace_id=_read_id(document, "trace_id", place),
|
|
125
|
+
span_id=_read_id(document, "span_id", place),
|
|
126
|
+
time_unix_nano=_read_time(document, place),
|
|
127
|
+
fields=_without(document, EVENT_FIELD_NAMES),
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _parse_start_event(document: dict[str, JsonValue], place: str) -> StartEvent:
|
|
132
|
+
return StartEvent(
|
|
133
|
+
id=_read_id(document, "id", place),
|
|
134
|
+
type="start",
|
|
135
|
+
trace_id=_read_id(document, "trace_id", place),
|
|
136
|
+
span_id=_read_id(document, "span_id", place),
|
|
137
|
+
time_unix_nano=_read_time(document, place),
|
|
138
|
+
parent_span_id=_read_parent_span_id(document, place),
|
|
139
|
+
kind=_read_string(document, "kind", place),
|
|
140
|
+
name=_read_string(document, "name", place),
|
|
141
|
+
seq=_read_seq(document, place),
|
|
142
|
+
fields=_without(document, EVENT_FIELD_NAMES | START_FIELD_NAMES),
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def write_event(event: Event) -> dict[str, JsonValue]:
|
|
147
|
+
document: dict[str, JsonValue] = {
|
|
148
|
+
**event.fields,
|
|
149
|
+
"id": event.id,
|
|
150
|
+
"type": event.type,
|
|
151
|
+
"trace_id": event.trace_id,
|
|
152
|
+
"span_id": event.span_id,
|
|
153
|
+
"time_unix_nano": str(event.time_unix_nano),
|
|
154
|
+
}
|
|
155
|
+
if isinstance(event, StartEvent):
|
|
156
|
+
document.update(
|
|
157
|
+
parent_span_id=event.parent_span_id, kind=event.kind, name=event.name, seq=event.seq
|
|
158
|
+
)
|
|
159
|
+
return document
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _read_string(document: dict[str, JsonValue], name: str, place: str) -> str:
|
|
163
|
+
value = document.get(name)
|
|
164
|
+
if not isinstance(value, str) or not value:
|
|
165
|
+
raise WireFormatError(f"{place}.{name}: expected a non-empty string")
|
|
166
|
+
return value
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _read_id(document: dict[str, JsonValue], name: str, place: str) -> str:
|
|
170
|
+
value = document.get(name)
|
|
171
|
+
if (
|
|
172
|
+
not isinstance(value, str)
|
|
173
|
+
or not 1 <= len(value) <= LARGEST_ID_LENGTH
|
|
174
|
+
or not ID_CHARACTERS.issuperset(value)
|
|
175
|
+
):
|
|
176
|
+
raise WireFormatError(
|
|
177
|
+
f"{place}.{name}: expected 1 to {LARGEST_ID_LENGTH} of letters, digits, - and _"
|
|
178
|
+
)
|
|
179
|
+
return value
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _read_time(document: dict[str, JsonValue], place: str) -> int:
|
|
183
|
+
value = document.get("time_unix_nano")
|
|
184
|
+
if not isinstance(value, str) or not (value.isascii() and value.isdigit()):
|
|
185
|
+
raise WireFormatError(f"{place}.time_unix_nano: expected a string of digits")
|
|
186
|
+
if len(value) > DIGITS_IN_LARGEST_WHOLE_NUMBER or int(value) > LARGEST_WHOLE_NUMBER:
|
|
187
|
+
raise WireFormatError(f"{place}.time_unix_nano: expected at most {LARGEST_WHOLE_NUMBER}")
|
|
188
|
+
return int(value)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _read_parent_span_id(document: dict[str, JsonValue], place: str) -> str | None:
|
|
192
|
+
if "parent_span_id" not in document:
|
|
193
|
+
raise WireFormatError(f"{place}.parent_span_id: expected a string or null")
|
|
194
|
+
if document["parent_span_id"] is None:
|
|
195
|
+
return None
|
|
196
|
+
return _read_id(document, "parent_span_id", place)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _read_seq(document: dict[str, JsonValue], place: str) -> int:
|
|
200
|
+
value = document.get("seq")
|
|
201
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
202
|
+
raise WireFormatError(f"{place}.seq: expected a whole number")
|
|
203
|
+
if abs(value) > LARGEST_SEQ:
|
|
204
|
+
raise WireFormatError(f"{place}.seq: expected at most {LARGEST_SEQ}")
|
|
205
|
+
return value
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _without(document: dict[str, JsonValue], names: frozenset[str]) -> dict[str, JsonValue]:
|
|
209
|
+
return {name: value for name, value in document.items() if name not in names}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from irimi._wire.json_value import JsonValue
|
|
6
|
+
|
|
7
|
+
INPUT = "input"
|
|
8
|
+
ARGS = "args"
|
|
9
|
+
KWARGS = "kwargs"
|
|
10
|
+
OUTPUT = "output"
|
|
11
|
+
STATUS = "status"
|
|
12
|
+
ERROR = "error"
|
|
13
|
+
FLAGS = "flags"
|
|
14
|
+
WRITE = "write"
|
|
15
|
+
READ = "read"
|
|
16
|
+
MODE = "mode"
|
|
17
|
+
ENVIRONMENT = "environment"
|
|
18
|
+
DEPLOYMENT = "deployment"
|
|
19
|
+
STARTED_BY = "started_by"
|
|
20
|
+
IMPORT_PATH = "import_path"
|
|
21
|
+
EVENTS_PRODUCED = "events_produced"
|
|
22
|
+
NEXT_CURSOR = "next_cursor"
|
|
23
|
+
REQUEST = "request"
|
|
24
|
+
RESPONSE = "response"
|
|
25
|
+
ANSWERED = "answered"
|
|
26
|
+
KEY = "key"
|
|
27
|
+
REPLAY = "replay"
|
|
28
|
+
SOURCE_RUN = "source_run"
|
|
29
|
+
ALLOWED_UNPATCHED = "allowed_unpatched"
|
|
30
|
+
MATCHED = "matched"
|
|
31
|
+
CHANGED = "changed"
|
|
32
|
+
BODY = "body"
|
|
33
|
+
DATA = "data"
|
|
34
|
+
ENCODING = "encoding"
|
|
35
|
+
CONTENT_ENCODING = "content_encoding"
|
|
36
|
+
CONTENT_TYPE = "content_type"
|
|
37
|
+
METHOD = "method"
|
|
38
|
+
URL = "url"
|
|
39
|
+
HEADERS = "headers"
|
|
40
|
+
SPAN_ID = "span_id"
|
|
41
|
+
RULE = "rule"
|
|
42
|
+
|
|
43
|
+
Flag = Literal[
|
|
44
|
+
"not_replayable",
|
|
45
|
+
"unserialisable_output",
|
|
46
|
+
"unattached",
|
|
47
|
+
"request_body_truncated",
|
|
48
|
+
"response_body_truncated",
|
|
49
|
+
"request_body_not_recorded",
|
|
50
|
+
"response_body_incomplete",
|
|
51
|
+
"new_write",
|
|
52
|
+
"unmatched_read",
|
|
53
|
+
"undescribed_call",
|
|
54
|
+
"recorded_value_unservable",
|
|
55
|
+
"caught_by_proxy",
|
|
56
|
+
"after_divergence",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
NOT_REPLAYABLE: Flag = "not_replayable"
|
|
60
|
+
UNATTACHED: Flag = "unattached"
|
|
61
|
+
REQUEST_BODY_TRUNCATED: Flag = "request_body_truncated"
|
|
62
|
+
REQUEST_BODY_NOT_RECORDED: Flag = "request_body_not_recorded"
|
|
63
|
+
UNSERIALISABLE_OUTPUT: Flag = "unserialisable_output"
|
|
64
|
+
RESPONSE_BODY_TRUNCATED: Flag = "response_body_truncated"
|
|
65
|
+
RESPONSE_BODY_INCOMPLETE: Flag = "response_body_incomplete"
|
|
66
|
+
UNDESCRIBED_CALL: Flag = "undescribed_call"
|
|
67
|
+
UNMATCHED_READ: Flag = "unmatched_read"
|
|
68
|
+
NEW_WRITE: Flag = "new_write"
|
|
69
|
+
RECORDED_VALUE_UNSERVABLE: Flag = "recorded_value_unservable"
|
|
70
|
+
CAUGHT_BY_PROXY: Flag = "caught_by_proxy"
|
|
71
|
+
AFTER_DIVERGENCE: Flag = "after_divergence"
|
|
72
|
+
|
|
73
|
+
BodyEncoding = Literal["text", "base64"]
|
|
74
|
+
|
|
75
|
+
TEXT: BodyEncoding = "text"
|
|
76
|
+
BASE64: BodyEncoding = "base64"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def write_flags(*flags: Flag) -> list[JsonValue]:
|
|
80
|
+
return list(flags)
|
irimi/_wire/markers.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from irimi._wire.json_value import JsonValue
|
|
4
|
+
|
|
5
|
+
RESERVED_KEY = "$irimi"
|
|
6
|
+
LITERAL = "literal"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def escape_reserved_keys(value: JsonValue) -> JsonValue:
|
|
10
|
+
if isinstance(value, list):
|
|
11
|
+
return [escape_reserved_keys(item) for item in value]
|
|
12
|
+
if not isinstance(value, dict):
|
|
13
|
+
return value
|
|
14
|
+
return escape_reserved_key({name: escape_reserved_keys(item) for name, item in value.items()})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def escape_reserved_key(items: dict[str, JsonValue]) -> dict[str, JsonValue]:
|
|
18
|
+
if RESERVED_KEY in items:
|
|
19
|
+
return {RESERVED_KEY: LITERAL, "value": items}
|
|
20
|
+
return items
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def mark_unserialisable(type_name: str) -> dict[str, JsonValue]:
|
|
24
|
+
return {RESERVED_KEY: "unserialisable", "type": type_name}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def mark_redacted(reason: str) -> dict[str, JsonValue]:
|
|
28
|
+
return {RESERVED_KEY: "redacted", "reason": reason}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def mark_object(type_name: str, fields: JsonValue) -> dict[str, JsonValue]:
|
|
32
|
+
return {RESERVED_KEY: "object", "type": type_name, "fields": fields}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def unescape_reserved_keys(value: JsonValue) -> JsonValue:
|
|
36
|
+
if isinstance(value, list):
|
|
37
|
+
return [unescape_reserved_keys(item) for item in value]
|
|
38
|
+
if not isinstance(value, dict):
|
|
39
|
+
return value
|
|
40
|
+
if RESERVED_KEY not in value:
|
|
41
|
+
return _unescape_items(value)
|
|
42
|
+
literal = value.get("value")
|
|
43
|
+
if value[RESERVED_KEY] == LITERAL and isinstance(literal, dict):
|
|
44
|
+
return _unescape_items(literal)
|
|
45
|
+
return value
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _unescape_items(items: dict[str, JsonValue]) -> dict[str, JsonValue]:
|
|
49
|
+
return {name: unescape_reserved_keys(item) for name, item in items.items()}
|
irimi/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: irimi-sdk
|
|
3
|
+
Version: 0.2.0.dev0
|
|
4
|
+
Summary: The irimi SDK alone, for production apps: record workflow runs and send them to an irimi server.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
9
|
+
Classifier: Typing :: Typed
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Project-URL: Homepage, https://github.com/irimi-io/Irimi
|
|
12
|
+
Project-URL: Issues, https://github.com/irimi-io/Irimi/issues
|
|
13
|
+
Project-URL: Source, https://github.com/irimi-io/Irimi
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# irimi-sdk
|
|
17
|
+
|
|
18
|
+
The irimi SDK alone. irimi does shadow runs for AI agents: record a workflow run in production,
|
|
19
|
+
replay it with one change (a model, a prompt, code) with every write faked, and see how the two
|
|
20
|
+
runs differ.
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install irimi-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This is the part that runs inside an app and records it: `import irimi`, no dependencies, Python
|
|
27
|
+
3.10 or newer. `pip install irimi` installs it together with the `irimi` command and the irimi
|
|
28
|
+
server, and needs Python 3.12 or newer.
|
|
29
|
+
|
|
30
|
+
## Replay a run
|
|
31
|
+
|
|
32
|
+
A replay runs a recorded run's workflow as the code is now and records the result as a new run.
|
|
33
|
+
Calls that match the recording are answered from it. Writes sent through the HTTP clients irimi
|
|
34
|
+
intercepts (httpx, httpx2, requests, urllib3 and aiohttp) and calls to functions marked
|
|
35
|
+
`@irimi.function(write=True)` are never performed; a read with no match is sent for real. So is an
|
|
36
|
+
LLM call whose request changed: its new answer is the point of a replay, and it costs money and
|
|
37
|
+
tokens like any other call. Once the replay makes a write that is new or has different arguments, or
|
|
38
|
+
skips a recorded write, every read answered from the recording after that is flagged
|
|
39
|
+
`after_divergence`: its answer shows the world as the recorded run left it, not as the replay's
|
|
40
|
+
writes would have. The workflow must live in a module that can be imported. Run the replay from the
|
|
41
|
+
app's directory, with `IRIMI_SERVER_URL` set:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
irimi replay <run id>
|
|
45
|
+
irimi runs <new run id>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`irimi replay <run id> --diff` ends by printing how the replay differs from the recorded run,
|
|
49
|
+
call by call, as `irimi diff <run id> <new run id>` does.
|
|
50
|
+
|
|
51
|
+
The `irimi` command comes with `pip install irimi`; `pip install irimi-sdk` does not install it.
|
|
52
|
+
|
|
53
|
+
A replay stops when it finds a client irimi cannot intercept, such as a database driver
|
|
54
|
+
(psycopg, SQLAlchemy, redis and others) or an HTTP client irimi could not patch, and only when the
|
|
55
|
+
app loads it: one that is installed but never imported does not stop a replay. It checks once
|
|
56
|
+
the workflow's module has been imported, and again whenever the workflow imports such a client
|
|
57
|
+
later; writes a module makes while it is being imported happen before that first check. Probing
|
|
58
|
+
for an optional driver inside the workflow, as `importlib.util.find_spec("redis")` does, also
|
|
59
|
+
stops the replay. Label every write through a driver `@irimi.function(write=True)`, then allow it
|
|
60
|
+
by name with `irimi replay <run id> --dangerously-allow-unpatched psycopg` or
|
|
61
|
+
`irimi.init(dangerously_allow_unpatched=["psycopg"])`. Upgrade an HTTP client irimi could not
|
|
62
|
+
patch, or allow it the same way if the workflow makes no calls through it.
|
|
63
|
+
|
|
64
|
+
A replay also points every client that honours proxy settings (`HTTP_PROXY`, `HTTPS_PROXY` and
|
|
65
|
+
`ALL_PROXY`), such as `urllib.request` or `curl`, at a proxy of irimi's own. A plain HTTP call it
|
|
66
|
+
catches is answered like any other call in the replay: from the recording, faked, or sent for real
|
|
67
|
+
when it is a read. An HTTPS connection it catches is refused, since irimi cannot see what would be
|
|
68
|
+
sent through it, and is recorded as `CONNECT <host>`. Both are flagged `caught_by_proxy`. During a
|
|
69
|
+
replay your own `NO_PROXY` is ignored and your `HTTP_PROXY`, `HTTPS_PROXY` and `ALL_PROXY` are
|
|
70
|
+
replaced, so where calls out of your network need a company proxy, the replay's live calls fail.
|
|
71
|
+
|
|
72
|
+
Some writes still really happen: those through a client irimi does not know by name, HTTP sent by a
|
|
73
|
+
client that ignores proxy settings, such as `http.client` used directly, a call the proxy catches on
|
|
74
|
+
its way to a host while irimi has a live call of its own open to that same host, and writes a
|
|
75
|
+
process the workflow starts, such as a `multiprocessing` worker, makes other than through a labeled
|
|
76
|
+
function. In such a process functions marked `@irimi.function(write=True)` are still faked and
|
|
77
|
+
nothing is recorded, but irimi intercepts no HTTP client there: HTTP reaches the replay's proxy only
|
|
78
|
+
from a client that honours proxy settings, and a database driver there is not guarded. Code that
|
|
79
|
+
catches the refusal keeps the replay running, without the driver it tried to import.
|
|
80
|
+
|
|
81
|
+
Early development. Source and issues: https://github.com/irimi-io/Irimi
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
irimi/__init__.py,sha256=z-_4SuZOp3llF3lwr6L6UaBlfRqQiJgBdQTJjRPl2jA,163
|
|
2
|
+
irimi/_aiohttp_patch.py,sha256=v32lIKD_WuhX4yQDyBDEfXwmqBOKA3k4MEHnhTqu7ls,13477
|
|
3
|
+
irimi/_aiohttp_serving.py,sha256=tSLDlded0ambjZySf0y1TqewRI082dvESEKOgPdSJC8,6686
|
|
4
|
+
irimi/_atomic_total.py,sha256=KGm0u0o5dmeFfNbwZArryrGwmHdA5Jo3Kvue0Dl6NhU,292
|
|
5
|
+
irimi/_bodies.py,sha256=w8fzDq_-SKEQ53hfP1blV4IXhY0Wd6iQf2okNyLmr0w,1865
|
|
6
|
+
irimi/_credential_headers.py,sha256=zOxR5mR-lwUf8B-okkre9JFnarTLV0-4frAe5vN8zIU,1596
|
|
7
|
+
irimi/_decorators.py,sha256=P4ZTnVDzSzEAOSy7JIw0tzh05mwF5ENxlllPlhcXilM,8747
|
|
8
|
+
irimi/_delivery.py,sha256=ac-7I0i-9OIgT0Y-TggFDLcaF3tjE9iq12V7_n7W6QM,2116
|
|
9
|
+
irimi/_divergence.py,sha256=TyDw_ImHq10yX-UGpWQDd7amJymBplxOWhHtmG5OWaw,2400
|
|
10
|
+
irimi/_drops.py,sha256=NYqiqS6Nq4rJUoeXJCF9v7ih04XuPwZayfu5S8KEZfs,680
|
|
11
|
+
irimi/_errors.py,sha256=KWaPM1DjUHaxf6Zp7Q-tOsEXG4agczPMU5-oIaDzJYU,485
|
|
12
|
+
irimi/_exporter.py,sha256=YenO_LyXz9sWvAPeeEGSQjoR542IntbPdRzP_uDPtMY,6795
|
|
13
|
+
irimi/_function_answers.py,sha256=CyheVFpnAALblP1inoT1Bq7xk6fIl2S2lFEw5Tf_Gi0,2852
|
|
14
|
+
irimi/_git.py,sha256=_NvvdycchEjAF7FEwweC-aLQcmNqOUJU3i9hNKQ4GSo,1171
|
|
15
|
+
irimi/_httpx_patch.py,sha256=Jinva_GlOhQ7NKbjjX807EE3B9yqw_z-P8nix5H8JmE,7821
|
|
16
|
+
irimi/_interception.py,sha256=WGFJgxJ7SA0yYrJ94sFHskLXmhqDzZuRclpjflthNxs,6575
|
|
17
|
+
irimi/_labeled_calls.py,sha256=pwEtJRpfgw1uRPFbDke1RWNDZ2X12jWQA4kxtGy5UjE,4080
|
|
18
|
+
irimi/_llm_providers.py,sha256=22ttkvQ3Hd0pcDYNiukfLpblPmsfMLJSYD2Um2RBG3M,1834
|
|
19
|
+
irimi/_object_fields.py,sha256=krfnmQf4AsX1tzSpco3Q78DZ0pz1BSGPTPiN4QLXhaQ,1214
|
|
20
|
+
irimi/_outbound_calls.py,sha256=QQiFH9PAmYg5HKONjuGDGd5dTW5IrCBj07y-KKsYDA0,6559
|
|
21
|
+
irimi/_patching.py,sha256=Mhm7hQ4FWzS3u4OO7200ymC8BRyMvWhAbIBG-XHRVRg,1832
|
|
22
|
+
irimi/_rebuilding.py,sha256=3WcGlDNEa4pYm_zh7ST57ptgeM4-XYdZjBLjNrA_hX0,3842
|
|
23
|
+
irimi/_recorded_calls.py,sha256=XexuyEPD2h83L007VjG2FqJMtmh3VFEW-mjQQ9DChHQ,7787
|
|
24
|
+
irimi/_recording.py,sha256=JDo0GvotYlGELAAYzwJiGAJ5ojooI4RiCuaXYEstEGU,3767
|
|
25
|
+
irimi/_recording_loader.py,sha256=R2SYT_jnn5Qpn2GLp8sL_1BjRQvH44-eEgTovOxk4wg,2638
|
|
26
|
+
irimi/_replay_child.py,sha256=LeMfL-pW14jagCU17eCJcwlBePvShp1OFdBEPxDOPDU,5942
|
|
27
|
+
irimi/_replay_decisions.py,sha256=nTfAQ5IfkSFUF4Jhks3q2ras37OkVF8NzeWH1m-tIHE,4380
|
|
28
|
+
irimi/_replay_fields.py,sha256=DLc8jUk2WWZTHPPpK-56J8eeM-LdZaoUknKnaryHUnw,552
|
|
29
|
+
irimi/_replay_proxy.py,sha256=_dyErFopxjI1CQ0BZtp9DQ3sttkjDa1lVnM114yB9xE,11039
|
|
30
|
+
irimi/_replay_refusals.py,sha256=90BvC7UyH4ZKYtv39IKxbzyEZKLmRnpYp3Pp2h__9YI,78
|
|
31
|
+
irimi/_response_recording.py,sha256=4bgHxagcqVoQt1OUI_-dinb-B5lZAl24TaCHMtuJeFE,2576
|
|
32
|
+
irimi/_sdk.py,sha256=4sfTTc6iAuepyWBepQxI7qNPs4ax8maYvr9VSAgkt6w,12647
|
|
33
|
+
irimi/_serialisation.py,sha256=XftM63FATjHMHB07Ih_Qjfa9y-KQvzVVMg-l1OlAPf4,3796
|
|
34
|
+
irimi/_status_reasons.py,sha256=gvwGUjD07HwriUErT7ZUqglwNnGErpA8sAYnQYl4pBc,203
|
|
35
|
+
irimi/_unpatched_clients.py,sha256=WmJ33OThC9acREt2RLsygPKPKxpU838TLdE28mm46JM,3691
|
|
36
|
+
irimi/_url_credentials.py,sha256=tai16gemc7U0hTiO-xDApAVPHInrpbkZBErU2_3_8hM,290
|
|
37
|
+
irimi/_urllib3_patch.py,sha256=Mk2TXogf0F-Fv3FFvWpQQx6Ls0gWd6EcjgLECWo1dDQ,17933
|
|
38
|
+
irimi/_urllib3_serving.py,sha256=Lbl2uj1E59MOBYf_0qWYy06WQb-yr-S3yqX6ci3QHW8,2468
|
|
39
|
+
irimi/_wire/__init__.py,sha256=JvRwkFLz5x5hASayQgP9P8M3UYc1vo7Bpjzl30EeYZI,1125
|
|
40
|
+
irimi/_wire/call_roles.py,sha256=VXCx8uwBEt2tRDciYUaK4boKo097SHeshWoXK1C81k4,1137
|
|
41
|
+
irimi/_wire/events.py,sha256=-0l369R1DvDG6nQDFpWETzcxkjhx00yzt9FSkP0pSE8,7130
|
|
42
|
+
irimi/_wire/field_names.py,sha256=6Phj0thdg8vREzda6Is0pdL0TrUZFVRW7ICJzEJZ8Lw,2004
|
|
43
|
+
irimi/_wire/json_value.py,sha256=gXf7ra5TBWOuZdoHnfje8Qyw0gwGCJrVHEAsKf44qNc,125
|
|
44
|
+
irimi/_wire/markers.py,sha256=AtfOUnjjp311TTrPw1Gd9gd7xzhbHmzPoh8jqMSIGY4,1613
|
|
45
|
+
irimi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
|
+
irimi_sdk-0.2.0.dev0.dist-info/WHEEL,sha256=-gI5GRFdiNNn2CFz-ptlExISMINC-k8bFxeojAlHbrM,81
|
|
47
|
+
irimi_sdk-0.2.0.dev0.dist-info/METADATA,sha256=AzYZS3vqFQt9dVuBY_TUCCbN5zrxI0oknFdVoSbkims,4769
|
|
48
|
+
irimi_sdk-0.2.0.dev0.dist-info/RECORD,,
|