bitfab-py 0.78.0__tar.gz → 0.78.2__tar.gz
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.
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/PKG-INFO +1 -1
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/client.py +52 -27
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/gmail_sandbox.py +182 -8
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/service_calls.py +19 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/pyproject.toml +1 -1
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/README.md +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/__init__.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/agent_middleware.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/approval.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/assertion_categories.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/baml.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/baml_auto_trace.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/categories.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/claude_agent_sdk.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/client_patching.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/cloudReplay.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/cloud_replay_cli.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/commit_ref.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/compress.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/constants.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/datasets.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/db_snapshot.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/error_chain.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/experiment_id.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/experiments.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/finalizers.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/git_command.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/git_state.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/google_calls.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/graders.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/http.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/integration_fixture.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/jev.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/labels.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/langgraph.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/langgraph_integration.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/langgraph_runs.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/mock_matching.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/mock_override.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/openai_agent_sdk.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/openai_agents_usage.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/organization_members.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/otel.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/payload_budget.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/processor_payload.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/provider_calls.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_branch.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_cli.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_heartbeat.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_interrupt.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_invocation.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_memory.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_processes.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/replay_registry.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/sandbox.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/seed_cli.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/selective_replay.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/serialize.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/simulation_plan.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/span_meta.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/span_origin.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/spans.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/subtree.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/thread_propagation.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/timestamp.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/trace_completion.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/trace_metadata.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/trace_payload.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/traces.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/tracing.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/transport.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/transport_types.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/verdicts.py +0 -0
- {bitfab_py-0.78.0 → bitfab_py-0.78.2}/bitfab/warn_once.py +0 -0
|
@@ -152,6 +152,7 @@ CAPTURE_ENABLED_ENV = "BITFAB_CAPTURE_ENABLED"
|
|
|
152
152
|
MAX_CAPTURED_SUBTREE_SPANS_ENV = "BITFAB_MAX_CAPTURED_SUBTREE_SPANS"
|
|
153
153
|
|
|
154
154
|
DISABLED_INTEGRATIONS_ENV = "BITFAB_DISABLED_INTEGRATIONS"
|
|
155
|
+
ENABLED_INTEGRATIONS_ENV = "BITFAB_ENABLED_INTEGRATIONS"
|
|
155
156
|
CONTENT_WITHHELD_KEY = "content_withheld_while_integration_off"
|
|
156
157
|
OFF_BY_DEFAULT_INTEGRATIONS = frozenset({"gmail"})
|
|
157
158
|
KNOWN_INTEGRATIONS = provider_calls.INTEGRATION_NAMES | OFF_BY_DEFAULT_INTEGRATIONS
|
|
@@ -170,9 +171,23 @@ def read_positive_int_env(name: str) -> int | None:
|
|
|
170
171
|
return value if value > 0 else None
|
|
171
172
|
|
|
172
173
|
|
|
173
|
-
def
|
|
174
|
+
def _integration_names_from_env(name: str, known: frozenset[str]) -> set[str]:
|
|
175
|
+
raw = os.environ.get(name, "")
|
|
176
|
+
names = {part.strip().lower() for part in raw.split(",") if part.strip()}
|
|
177
|
+
unknown = sorted(names - known)
|
|
178
|
+
if unknown:
|
|
179
|
+
warn_once(
|
|
180
|
+
f"unknown-integrations:{name}:{','.join(unknown)}",
|
|
181
|
+
f"{name} names {', '.join(unknown)}, "
|
|
182
|
+
f"which the SDK does not know; ignoring it. Known integrations are "
|
|
183
|
+
f"{', '.join(sorted(known))}.",
|
|
184
|
+
)
|
|
185
|
+
return names & known
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def resolve_integrations(
|
|
174
189
|
integrations: Mapping[str, bool] | None,
|
|
175
|
-
) -> frozenset[str]:
|
|
190
|
+
) -> tuple[frozenset[str], frozenset[str]]:
|
|
176
191
|
known = KNOWN_INTEGRATIONS
|
|
177
192
|
in_code = dict(integrations or {})
|
|
178
193
|
unknown = sorted(set(in_code) - known)
|
|
@@ -181,25 +196,26 @@ def resolve_disabled_integrations(
|
|
|
181
196
|
f"Bitfab(integrations=...) got {', '.join(unknown)}; "
|
|
182
197
|
f"known integrations are {', '.join(sorted(known))}."
|
|
183
198
|
)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
turned_off = _integration_names_from_env(DISABLED_INTEGRATIONS_ENV, known)
|
|
200
|
+
turned_on = _integration_names_from_env(ENABLED_INTEGRATIONS_ENV, known)
|
|
201
|
+
disabled: set[str] = set()
|
|
202
|
+
off_by_default: set[str] = set()
|
|
203
|
+
for name in known:
|
|
204
|
+
if name in in_code:
|
|
205
|
+
if not in_code[name]:
|
|
206
|
+
disabled.add(name)
|
|
207
|
+
elif name in turned_off:
|
|
208
|
+
disabled.add(name)
|
|
209
|
+
elif name in OFF_BY_DEFAULT_INTEGRATIONS and name not in turned_on:
|
|
210
|
+
disabled.add(name)
|
|
211
|
+
off_by_default.add(name)
|
|
212
|
+
return frozenset(disabled), frozenset(off_by_default)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def resolve_disabled_integrations(
|
|
216
|
+
integrations: Mapping[str, bool] | None,
|
|
217
|
+
) -> frozenset[str]:
|
|
218
|
+
return resolve_integrations(integrations)[0]
|
|
203
219
|
|
|
204
220
|
|
|
205
221
|
def read_boolean_env(name: str) -> bool | None:
|
|
@@ -1457,13 +1473,19 @@ class Bitfab:
|
|
|
1457
1473
|
span, and replay cannot mock them, and a model client no
|
|
1458
1474
|
Bitfab client has on is never patched. ``gmail`` (Google's
|
|
1459
1475
|
Python client) is off by default because mail is sensitive;
|
|
1460
|
-
True records each
|
|
1461
|
-
|
|
1476
|
+
True, or ``BITFAB_ENABLED_INTEGRATIONS=gmail``, records each
|
|
1477
|
+
Gmail API call as a span named for its method, which the Gmail
|
|
1478
|
+
sandbox builds its starting mailbox from on replay. While it is
|
|
1479
|
+
off only by default, the first Gmail call inside a trace warns
|
|
1480
|
+
once with how to turn it on; turning it off by name silences
|
|
1481
|
+
that. Whatever this says, a Gmail call made during a replay
|
|
1462
1482
|
never reaches Google: the Gmail sandbox answers it. None
|
|
1463
1483
|
(default) or a name left out: off when
|
|
1464
|
-
``BITFAB_DISABLED_INTEGRATIONS`` lists it
|
|
1465
|
-
|
|
1466
|
-
|
|
1484
|
+
``BITFAB_DISABLED_INTEGRATIONS`` lists it, on when
|
|
1485
|
+
``BITFAB_ENABLED_INTEGRATIONS`` lists it (both comma
|
|
1486
|
+
separated; off wins when both do); a name given here wins
|
|
1487
|
+
over both variables. Raises ValueError for a name the SDK
|
|
1488
|
+
does not know.
|
|
1467
1489
|
enabled: Deprecated alias for ``capture_enabled``. Warns once.
|
|
1468
1490
|
"""
|
|
1469
1491
|
if enabled is not None:
|
|
@@ -1484,7 +1506,10 @@ class Bitfab:
|
|
|
1484
1506
|
self._capture_enabled_in_code = capture_enabled
|
|
1485
1507
|
self._capture_enabled_from_env: bool | None = None
|
|
1486
1508
|
self._strict = strict
|
|
1487
|
-
|
|
1509
|
+
(
|
|
1510
|
+
self._disabled_integrations,
|
|
1511
|
+
self._integrations_off_by_default,
|
|
1512
|
+
) = resolve_integrations(integrations)
|
|
1488
1513
|
self._patched_integrations = (
|
|
1489
1514
|
provider_calls.INTEGRATION_NAMES - self._disabled_integrations
|
|
1490
1515
|
)
|
|
@@ -19,6 +19,9 @@ GMAIL_SANDBOX_NAME = "Gmail"
|
|
|
19
19
|
GET_METHOD = "gmail.users.messages.get"
|
|
20
20
|
LIST_METHOD = "gmail.users.messages.list"
|
|
21
21
|
PROFILE_METHOD = "gmail.users.getProfile"
|
|
22
|
+
LABELS_LIST_METHOD = "gmail.users.labels.list"
|
|
23
|
+
LABEL_GET_METHOD = "gmail.users.labels.get"
|
|
24
|
+
SEND_AS_LIST_METHOD = "gmail.users.settings.sendAs.list"
|
|
22
25
|
SYSTEM_LABELS = (
|
|
23
26
|
"INBOX",
|
|
24
27
|
"SENT",
|
|
@@ -185,7 +188,14 @@ def mailbox_from_recorded_calls(ctx: SandboxStartCtx) -> dict[str, Any]:
|
|
|
185
188
|
if ctx.recorded_state is not None:
|
|
186
189
|
return as_mailboxes(ctx, ctx.recorded_state)
|
|
187
190
|
by_credential: dict[str | None, dict[str, Any]] = {}
|
|
188
|
-
for name in (
|
|
191
|
+
for name in (
|
|
192
|
+
GET_METHOD,
|
|
193
|
+
PROFILE_METHOD,
|
|
194
|
+
LIST_METHOD,
|
|
195
|
+
LABELS_LIST_METHOD,
|
|
196
|
+
LABEL_GET_METHOD,
|
|
197
|
+
SEND_AS_LIST_METHOD,
|
|
198
|
+
):
|
|
189
199
|
for span in ctx.recorded_spans(name):
|
|
190
200
|
output = span.output
|
|
191
201
|
if not isinstance(output, dict) or HTTP_ERROR_KEY in output:
|
|
@@ -199,6 +209,8 @@ def mailbox_from_recorded_calls(ctx: SandboxStartCtx) -> dict[str, Any]:
|
|
|
199
209
|
"emailAddress": None,
|
|
200
210
|
"messages": {},
|
|
201
211
|
"searches": [],
|
|
212
|
+
"labels": {},
|
|
213
|
+
"sendAs": None,
|
|
202
214
|
},
|
|
203
215
|
)
|
|
204
216
|
if name == LIST_METHOD and not given.get("pageToken"):
|
|
@@ -214,13 +226,32 @@ def mailbox_from_recorded_calls(ctx: SandboxStartCtx) -> dict[str, Any]:
|
|
|
214
226
|
)
|
|
215
227
|
if name == PROFILE_METHOD:
|
|
216
228
|
box["emailAddress"] = output.get("emailAddress") or box["emailAddress"]
|
|
229
|
+
if name == LABELS_LIST_METHOD:
|
|
230
|
+
for label in output.get("labels") or []:
|
|
231
|
+
_keep_user_label(box["labels"], label)
|
|
232
|
+
if name == LABEL_GET_METHOD:
|
|
233
|
+
_keep_user_label(box["labels"], output)
|
|
234
|
+
if name == SEND_AS_LIST_METHOD and isinstance(output.get("sendAs"), list):
|
|
235
|
+
box["sendAs"] = output["sendAs"]
|
|
217
236
|
boxes = [
|
|
218
|
-
{
|
|
237
|
+
{
|
|
238
|
+
**box,
|
|
239
|
+
"messages": list(box["messages"].values()),
|
|
240
|
+
"labels": list(box["labels"].values()),
|
|
241
|
+
}
|
|
219
242
|
for box in by_credential.values()
|
|
220
243
|
]
|
|
221
244
|
return as_mailboxes(ctx, {"mailboxes": boxes or [{}]})
|
|
222
245
|
|
|
223
246
|
|
|
247
|
+
def _keep_user_label(into: dict[str, dict[str, Any]], label: Any) -> None:
|
|
248
|
+
if not isinstance(label, dict) or not label.get("id"):
|
|
249
|
+
return
|
|
250
|
+
if label.get("type") == "system" or label["id"] in SYSTEM_LABELS:
|
|
251
|
+
return
|
|
252
|
+
into[str(label["id"])] = label
|
|
253
|
+
|
|
254
|
+
|
|
224
255
|
def as_mailboxes(ctx: SandboxStartCtx, started: Any) -> dict[str, Any]:
|
|
225
256
|
if isinstance(started, dict) and isinstance(started.get("mailboxes"), list):
|
|
226
257
|
boxes = started["mailboxes"]
|
|
@@ -255,6 +286,8 @@ def as_mailboxes(ctx: SandboxStartCtx, started: Any) -> dict[str, Any]:
|
|
|
255
286
|
drafts=box.get("drafts"),
|
|
256
287
|
details=box.get("details"),
|
|
257
288
|
searches=box.get("searches"),
|
|
289
|
+
labels=box.get("labels"),
|
|
290
|
+
send_as=box.get("sendAs"),
|
|
258
291
|
)
|
|
259
292
|
for index, box in enumerate(boxes or [{}])
|
|
260
293
|
]
|
|
@@ -270,6 +303,8 @@ def new_mailbox(
|
|
|
270
303
|
drafts: list[dict[str, Any]] | None = None,
|
|
271
304
|
details: dict[str, Any] | None = None,
|
|
272
305
|
searches: list[dict[str, Any]] | None = None,
|
|
306
|
+
labels: list[dict[str, Any] | str] | None = None,
|
|
307
|
+
send_as: list[dict[str, Any]] | None = None,
|
|
273
308
|
) -> dict[str, Any]:
|
|
274
309
|
normalized = [gmail_message(message) for message in messages or []]
|
|
275
310
|
for message in normalized:
|
|
@@ -296,10 +331,25 @@ def new_mailbox(
|
|
|
296
331
|
"messages": normalized,
|
|
297
332
|
"drafts": list(drafts or []),
|
|
298
333
|
"searches": list(searches or []),
|
|
334
|
+
"labels": [_user_label(label) for label in labels or []],
|
|
335
|
+
"sendAs": None if send_as is None else [dict(entry) for entry in send_as],
|
|
299
336
|
"notes": [],
|
|
300
337
|
}
|
|
301
338
|
|
|
302
339
|
|
|
340
|
+
def _user_label(label: dict[str, Any] | str) -> dict[str, Any]:
|
|
341
|
+
given = {"name": label} if isinstance(label, str) else dict(label)
|
|
342
|
+
name = str(given.get("name") or given.get("id") or "")
|
|
343
|
+
return {
|
|
344
|
+
"id": str(given.get("id") or name),
|
|
345
|
+
"name": name,
|
|
346
|
+
"type": "user",
|
|
347
|
+
"messageListVisibility": "show",
|
|
348
|
+
"labelListVisibility": "labelShow",
|
|
349
|
+
**given,
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
303
353
|
def _note(state: dict[str, Any], text: str) -> None:
|
|
304
354
|
notes = state.setdefault("notes", [])
|
|
305
355
|
if text not in notes:
|
|
@@ -387,6 +437,19 @@ def _relative_millis(value: str) -> int | None:
|
|
|
387
437
|
return days * 86_400_000
|
|
388
438
|
|
|
389
439
|
|
|
440
|
+
def _search_name(name: str) -> str:
|
|
441
|
+
return re.sub(r"[\s/&]+", "-", name.strip().lower())
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def _label_ids_named(state: dict[str, Any], value: str) -> set[str]:
|
|
445
|
+
wanted = _search_name(value)
|
|
446
|
+
return {
|
|
447
|
+
str(label.get("id"))
|
|
448
|
+
for label in state.get("labels") or []
|
|
449
|
+
if _search_name(str(label.get("name") or "")) == wanted
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
390
453
|
def _contains(haystack: str, needle: str) -> bool:
|
|
391
454
|
return needle.lower() in haystack.lower()
|
|
392
455
|
|
|
@@ -422,7 +485,12 @@ def _term_matches(state: dict[str, Any], message: dict[str, Any], term: str) ->
|
|
|
422
485
|
return wanted.upper() in labels
|
|
423
486
|
if operator in {"in", "label"}:
|
|
424
487
|
wanted = value.upper().replace("-", "_")
|
|
425
|
-
return
|
|
488
|
+
return (
|
|
489
|
+
wanted == "ANYWHERE"
|
|
490
|
+
or wanted in labels
|
|
491
|
+
or value in labels
|
|
492
|
+
or bool(_label_ids_named(state, value) & labels)
|
|
493
|
+
)
|
|
426
494
|
if operator == "has":
|
|
427
495
|
return value.lower() != "attachment" or bool(
|
|
428
496
|
_attachments(message.get("payload") or {})
|
|
@@ -782,10 +850,106 @@ def _profile(state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
|
|
|
782
850
|
}
|
|
783
851
|
|
|
784
852
|
|
|
785
|
-
def
|
|
853
|
+
def _all_labels(state: dict[str, Any]) -> list[dict[str, Any]]:
|
|
854
|
+
found = [{"id": label, "name": label, "type": "system"} for label in SYSTEM_LABELS]
|
|
855
|
+
known = set(SYSTEM_LABELS)
|
|
856
|
+
for label in state.setdefault("labels", []):
|
|
857
|
+
if label["id"] not in known:
|
|
858
|
+
known.add(label["id"])
|
|
859
|
+
found.append(label)
|
|
860
|
+
for message in state["messages"]:
|
|
861
|
+
for label_id in message.get("labelIds") or []:
|
|
862
|
+
if label_id in known:
|
|
863
|
+
continue
|
|
864
|
+
known.add(label_id)
|
|
865
|
+
_note(
|
|
866
|
+
state,
|
|
867
|
+
f"label {label_id} was only seen on messages, so its name is its id",
|
|
868
|
+
)
|
|
869
|
+
found.append(_user_label({"id": label_id, "name": label_id}))
|
|
870
|
+
return found
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
def _labels(state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
|
|
874
|
+
return {"labels": _all_labels(state)}
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
def _label_get(state: dict[str, Any], params: dict[str, Any]) -> dict[str, Any]:
|
|
878
|
+
wanted = str(params.get("id"))
|
|
879
|
+
label = next((lb for lb in _all_labels(state) if lb["id"] == wanted), None)
|
|
880
|
+
if label is None:
|
|
881
|
+
return _not_found(f"label {wanted}")
|
|
882
|
+
return copy.deepcopy(label)
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
def _conflict(message: str) -> dict[str, Any]:
|
|
786
886
|
return {
|
|
787
|
-
|
|
788
|
-
|
|
887
|
+
HTTP_ERROR_KEY: {
|
|
888
|
+
"code": 409,
|
|
889
|
+
"message": message,
|
|
890
|
+
"status": "ABORTED",
|
|
891
|
+
"errors": [{"message": message, "domain": "global", "reason": "aborted"}],
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
def _invalid(message: str) -> dict[str, Any]:
|
|
897
|
+
return {
|
|
898
|
+
HTTP_ERROR_KEY: {
|
|
899
|
+
"code": 400,
|
|
900
|
+
"message": message,
|
|
901
|
+
"status": "INVALID_ARGUMENT",
|
|
902
|
+
"errors": [{"message": message, "domain": "global", "reason": "invalid"}],
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
def _label_create(state: dict[str, Any], params: dict[str, Any]) -> dict[str, Any]:
|
|
908
|
+
body = params.get("body") or {}
|
|
909
|
+
name = str(body.get("name") or "").strip()
|
|
910
|
+
if not name:
|
|
911
|
+
return _invalid("Invalid label name")
|
|
912
|
+
if any(lb["name"].lower() == name.lower() for lb in _all_labels(state)):
|
|
913
|
+
return _conflict("Label name exists or conflicts")
|
|
914
|
+
label = _user_label(
|
|
915
|
+
{
|
|
916
|
+
**{k: v for k, v in body.items() if k not in {"id", "type"}},
|
|
917
|
+
"id": _next_id(state, "Label_sandbox"),
|
|
918
|
+
"name": name,
|
|
919
|
+
}
|
|
920
|
+
)
|
|
921
|
+
state["labels"].append(label)
|
|
922
|
+
return copy.deepcopy(label)
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
def _send_as(state: dict[str, Any], _params: dict[str, Any]) -> dict[str, Any]:
|
|
926
|
+
recorded = state.get("sendAs")
|
|
927
|
+
if recorded is not None:
|
|
928
|
+
return {"sendAs": copy.deepcopy(recorded)}
|
|
929
|
+
address = state.get("emailAddress")
|
|
930
|
+
if not address:
|
|
931
|
+
_note(
|
|
932
|
+
state,
|
|
933
|
+
"the account's address was never recorded, so it has no send-as addresses",
|
|
934
|
+
)
|
|
935
|
+
return {"sendAs": []}
|
|
936
|
+
_note(
|
|
937
|
+
state,
|
|
938
|
+
"send-as settings were never recorded, so the account's own address is "
|
|
939
|
+
"listed with no display name or signature",
|
|
940
|
+
)
|
|
941
|
+
return {
|
|
942
|
+
"sendAs": [
|
|
943
|
+
{
|
|
944
|
+
"sendAsEmail": address,
|
|
945
|
+
"displayName": "",
|
|
946
|
+
"replyToAddress": "",
|
|
947
|
+
"signature": "",
|
|
948
|
+
"isPrimary": True,
|
|
949
|
+
"isDefault": True,
|
|
950
|
+
"treatAsAlias": False,
|
|
951
|
+
"verificationStatus": "accepted",
|
|
952
|
+
}
|
|
789
953
|
]
|
|
790
954
|
}
|
|
791
955
|
|
|
@@ -808,7 +972,10 @@ HANDLERS: dict[str, Callable[[dict[str, Any], dict[str, Any]], dict[str, Any]]]
|
|
|
808
972
|
"gmail.users.drafts.list": _drafts_list,
|
|
809
973
|
"gmail.users.threads.get": _thread,
|
|
810
974
|
"gmail.users.history.list": _history,
|
|
811
|
-
|
|
975
|
+
LABELS_LIST_METHOD: _labels,
|
|
976
|
+
LABEL_GET_METHOD: _label_get,
|
|
977
|
+
"gmail.users.labels.create": _label_create,
|
|
978
|
+
SEND_AS_LIST_METHOD: _send_as,
|
|
812
979
|
PROFILE_METHOD: _profile,
|
|
813
980
|
}
|
|
814
981
|
|
|
@@ -880,6 +1047,8 @@ def _empty_mailbox_for(boxes: list[dict[str, Any]], address: str) -> dict[str, A
|
|
|
880
1047
|
"messages": [],
|
|
881
1048
|
"drafts": [],
|
|
882
1049
|
"searches": [],
|
|
1050
|
+
"labels": [],
|
|
1051
|
+
"sendAs": None,
|
|
883
1052
|
"notes": [f"{address} had no mailbox in the original run, so it starts empty"],
|
|
884
1053
|
}
|
|
885
1054
|
|
|
@@ -918,7 +1087,12 @@ def gmail_sandbox(
|
|
|
918
1087
|
Args:
|
|
919
1088
|
start: Builds the mailbox for one replay item from a
|
|
920
1089
|
``SandboxStartCtx``. Return a list of messages, or
|
|
921
|
-
``{"messages": [...], "emailAddress": ..., "drafts": [...]
|
|
1090
|
+
``{"messages": [...], "emailAddress": ..., "drafts": [...],
|
|
1091
|
+
"labels": [...], "sendAs": [...]}``. ``labels`` are the account's
|
|
1092
|
+
own labels, each a Gmail label or a name; ``sendAs`` are Gmail
|
|
1093
|
+
send-as entries (``sendAsEmail``, ``displayName``, ``signature``,
|
|
1094
|
+
...). Without ``sendAs``, the account's address is listed with no
|
|
1095
|
+
signature.
|
|
922
1096
|
Each message is a Gmail API message or plain fields as
|
|
923
1097
|
``gmail_message`` takes them; a plain ``account`` field puts the
|
|
924
1098
|
message in that account's mailbox. For several accounts, return
|
|
@@ -11,6 +11,7 @@ from typing import Any
|
|
|
11
11
|
|
|
12
12
|
from bitfab.constants import _replay_context, replay_item_is_running
|
|
13
13
|
from bitfab.sandbox import SANDBOX_SESSION_KEY
|
|
14
|
+
from bitfab.warn_once import warn_once
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
@dataclass(frozen=True)
|
|
@@ -53,6 +54,22 @@ def _records(client: Any, integration: str) -> bool:
|
|
|
53
54
|
return integration not in getattr(client, "_disabled_integrations", ())
|
|
54
55
|
|
|
55
56
|
|
|
57
|
+
def _warn_recording_off_by_default(integration: str) -> None:
|
|
58
|
+
newest = next(iter(_alive_clients()), None)
|
|
59
|
+
if integration not in getattr(newest, "_integrations_off_by_default", ()):
|
|
60
|
+
return
|
|
61
|
+
warn_once(
|
|
62
|
+
f"integration-off-by-default:{integration}",
|
|
63
|
+
f"a {integration} call ran inside a trace and was not recorded, because "
|
|
64
|
+
f"Bitfab records {integration} calls only once you turn them on (they "
|
|
65
|
+
f"carry your users' data). Without them, replays of this trace start "
|
|
66
|
+
f"the {integration} sandbox with nothing the original run read. Turn "
|
|
67
|
+
f'recording on with Bitfab(integrations={{"{integration}": True}}) or '
|
|
68
|
+
f"BITFAB_ENABLED_INTEGRATIONS={integration}; turn it off by name "
|
|
69
|
+
f'(integrations={{"{integration}": False}}) to stop this warning.',
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
56
73
|
def current_call() -> ServiceCall | None:
|
|
57
74
|
return _current.get()
|
|
58
75
|
|
|
@@ -117,6 +134,8 @@ def run(call: ServiceCall) -> Any:
|
|
|
117
134
|
(c for c in _alive_clients() if _records(c, call.integration)), None
|
|
118
135
|
)
|
|
119
136
|
if client is None or not _inside_trace():
|
|
137
|
+
if client is None and _inside_trace():
|
|
138
|
+
_warn_recording_off_by_default(call.integration)
|
|
120
139
|
return call.send()
|
|
121
140
|
tokens = (
|
|
122
141
|
_current.set(call),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|