langfun 0.1.2.dev202510230805__py3-none-any.whl → 0.1.2.dev202511270805__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.
Potentially problematic release.
This version of langfun might be problematic. Click here for more details.
- langfun/core/__init__.py +2 -0
- langfun/core/agentic/__init__.py +4 -1
- langfun/core/agentic/action.py +447 -29
- langfun/core/agentic/action_eval.py +9 -2
- langfun/core/agentic/action_test.py +149 -21
- langfun/core/async_support.py +32 -3
- langfun/core/coding/python/correction.py +19 -9
- langfun/core/coding/python/execution.py +14 -12
- langfun/core/coding/python/generation.py +21 -16
- langfun/core/coding/python/sandboxing.py +23 -3
- langfun/core/component.py +42 -3
- langfun/core/concurrent.py +70 -6
- langfun/core/concurrent_test.py +1 -0
- langfun/core/console.py +1 -1
- langfun/core/data/conversion/anthropic.py +12 -3
- langfun/core/data/conversion/anthropic_test.py +8 -6
- langfun/core/data/conversion/gemini.py +9 -2
- langfun/core/data/conversion/gemini_test.py +12 -9
- langfun/core/data/conversion/openai.py +145 -31
- langfun/core/data/conversion/openai_test.py +161 -17
- langfun/core/eval/base.py +47 -43
- langfun/core/eval/base_test.py +5 -5
- langfun/core/eval/matching.py +5 -2
- langfun/core/eval/patching.py +3 -3
- langfun/core/eval/scoring.py +4 -3
- langfun/core/eval/v2/__init__.py +1 -0
- langfun/core/eval/v2/checkpointing.py +64 -6
- langfun/core/eval/v2/checkpointing_test.py +9 -2
- langfun/core/eval/v2/eval_test_helper.py +103 -2
- langfun/core/eval/v2/evaluation.py +91 -16
- langfun/core/eval/v2/evaluation_test.py +9 -3
- langfun/core/eval/v2/example.py +50 -40
- langfun/core/eval/v2/example_test.py +16 -8
- langfun/core/eval/v2/experiment.py +74 -8
- langfun/core/eval/v2/experiment_test.py +19 -0
- langfun/core/eval/v2/metric_values.py +31 -3
- langfun/core/eval/v2/metric_values_test.py +32 -0
- langfun/core/eval/v2/metrics.py +157 -44
- langfun/core/eval/v2/metrics_test.py +39 -18
- langfun/core/eval/v2/progress.py +30 -1
- langfun/core/eval/v2/progress_test.py +27 -0
- langfun/core/eval/v2/progress_tracking.py +12 -3
- langfun/core/eval/v2/progress_tracking_test.py +6 -1
- langfun/core/eval/v2/reporting.py +90 -71
- langfun/core/eval/v2/reporting_test.py +24 -6
- langfun/core/eval/v2/runners/__init__.py +30 -0
- langfun/core/eval/v2/{runners.py → runners/base.py} +59 -142
- langfun/core/eval/v2/runners/beam.py +341 -0
- langfun/core/eval/v2/runners/beam_test.py +131 -0
- langfun/core/eval/v2/runners/ckpt_monitor.py +294 -0
- langfun/core/eval/v2/runners/ckpt_monitor_test.py +162 -0
- langfun/core/eval/v2/runners/debug.py +40 -0
- langfun/core/eval/v2/runners/debug_test.py +76 -0
- langfun/core/eval/v2/runners/parallel.py +100 -0
- langfun/core/eval/v2/runners/parallel_test.py +95 -0
- langfun/core/eval/v2/runners/sequential.py +47 -0
- langfun/core/eval/v2/runners/sequential_test.py +172 -0
- langfun/core/langfunc.py +45 -130
- langfun/core/langfunc_test.py +7 -5
- langfun/core/language_model.py +141 -21
- langfun/core/language_model_test.py +54 -3
- langfun/core/llms/__init__.py +9 -1
- langfun/core/llms/anthropic.py +157 -2
- langfun/core/llms/azure_openai.py +29 -17
- langfun/core/llms/cache/base.py +25 -3
- langfun/core/llms/cache/in_memory.py +48 -7
- langfun/core/llms/cache/in_memory_test.py +14 -4
- langfun/core/llms/compositional.py +25 -1
- langfun/core/llms/deepseek.py +30 -2
- langfun/core/llms/fake.py +32 -1
- langfun/core/llms/gemini.py +55 -17
- langfun/core/llms/gemini_test.py +84 -0
- langfun/core/llms/google_genai.py +34 -1
- langfun/core/llms/groq.py +28 -3
- langfun/core/llms/llama_cpp.py +23 -4
- langfun/core/llms/openai.py +36 -3
- langfun/core/llms/openai_compatible.py +148 -27
- langfun/core/llms/openai_compatible_test.py +207 -20
- langfun/core/llms/openai_test.py +0 -2
- langfun/core/llms/rest.py +12 -1
- langfun/core/llms/vertexai.py +58 -8
- langfun/core/logging.py +1 -1
- langfun/core/mcp/client.py +77 -22
- langfun/core/mcp/client_test.py +8 -35
- langfun/core/mcp/session.py +94 -29
- langfun/core/mcp/session_test.py +54 -0
- langfun/core/mcp/tool.py +151 -22
- langfun/core/mcp/tool_test.py +197 -0
- langfun/core/memory.py +1 -0
- langfun/core/message.py +160 -55
- langfun/core/message_test.py +65 -81
- langfun/core/modalities/__init__.py +8 -0
- langfun/core/modalities/audio.py +21 -1
- langfun/core/modalities/image.py +19 -1
- langfun/core/modalities/mime.py +64 -3
- langfun/core/modalities/mime_test.py +11 -0
- langfun/core/modalities/pdf.py +19 -1
- langfun/core/modalities/video.py +21 -1
- langfun/core/modality.py +167 -29
- langfun/core/modality_test.py +42 -12
- langfun/core/natural_language.py +1 -1
- langfun/core/sampling.py +4 -4
- langfun/core/sampling_test.py +20 -4
- langfun/core/structured/__init__.py +2 -24
- langfun/core/structured/completion.py +34 -44
- langfun/core/structured/completion_test.py +23 -43
- langfun/core/structured/description.py +54 -50
- langfun/core/structured/function_generation.py +29 -12
- langfun/core/structured/mapping.py +81 -37
- langfun/core/structured/parsing.py +95 -79
- langfun/core/structured/parsing_test.py +0 -3
- langfun/core/structured/querying.py +215 -142
- langfun/core/structured/querying_test.py +65 -29
- langfun/core/structured/schema/__init__.py +49 -0
- langfun/core/structured/schema/base.py +664 -0
- langfun/core/structured/schema/base_test.py +531 -0
- langfun/core/structured/schema/json.py +174 -0
- langfun/core/structured/schema/json_test.py +121 -0
- langfun/core/structured/schema/python.py +316 -0
- langfun/core/structured/schema/python_test.py +410 -0
- langfun/core/structured/schema_generation.py +33 -14
- langfun/core/structured/scoring.py +47 -36
- langfun/core/structured/tokenization.py +26 -11
- langfun/core/subscription.py +2 -2
- langfun/core/template.py +174 -49
- langfun/core/template_test.py +123 -17
- langfun/env/__init__.py +8 -2
- langfun/env/base_environment.py +320 -128
- langfun/env/base_environment_test.py +473 -0
- langfun/env/base_feature.py +92 -15
- langfun/env/base_feature_test.py +228 -0
- langfun/env/base_sandbox.py +84 -361
- langfun/env/base_sandbox_test.py +1235 -0
- langfun/env/event_handlers/__init__.py +1 -1
- langfun/env/event_handlers/chain.py +233 -0
- langfun/env/event_handlers/chain_test.py +253 -0
- langfun/env/event_handlers/event_logger.py +95 -98
- langfun/env/event_handlers/event_logger_test.py +21 -21
- langfun/env/event_handlers/metric_writer.py +225 -140
- langfun/env/event_handlers/metric_writer_test.py +23 -6
- langfun/env/interface.py +854 -40
- langfun/env/interface_test.py +112 -2
- langfun/env/load_balancers_test.py +23 -2
- langfun/env/test_utils.py +126 -84
- {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511270805.dist-info}/METADATA +1 -1
- langfun-0.1.2.dev202511270805.dist-info/RECORD +215 -0
- langfun/core/eval/v2/runners_test.py +0 -343
- langfun/core/structured/schema.py +0 -987
- langfun/core/structured/schema_test.py +0 -982
- langfun/env/base_test.py +0 -1481
- langfun/env/event_handlers/base.py +0 -350
- langfun-0.1.2.dev202510230805.dist-info/RECORD +0 -195
- {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511270805.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511270805.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202510230805.dist-info → langfun-0.1.2.dev202511270805.dist-info}/top_level.txt +0 -0
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
import re
|
|
17
17
|
import time
|
|
18
18
|
from typing import Annotated
|
|
19
|
-
from langfun.env
|
|
19
|
+
from langfun.env import interface
|
|
20
20
|
import pyglove as pg
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
class EventLogger(pg.Object,
|
|
23
|
+
class EventLogger(pg.Object, interface.EventHandler):
|
|
24
24
|
"""Event handler for logging debugger."""
|
|
25
25
|
|
|
26
26
|
colored: Annotated[
|
|
@@ -125,7 +125,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
125
125
|
|
|
126
126
|
def on_environment_starting(
|
|
127
127
|
self,
|
|
128
|
-
environment:
|
|
128
|
+
environment: interface.Environment,
|
|
129
129
|
) -> None:
|
|
130
130
|
"""Called when the environment is starting."""
|
|
131
131
|
self._print(
|
|
@@ -137,7 +137,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
137
137
|
|
|
138
138
|
def on_environment_shutting_down(
|
|
139
139
|
self,
|
|
140
|
-
environment:
|
|
140
|
+
environment: interface.Environment,
|
|
141
141
|
offline_duration: float,
|
|
142
142
|
) -> None:
|
|
143
143
|
"""Called when the environment is shutting down."""
|
|
@@ -151,7 +151,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
151
151
|
|
|
152
152
|
def on_environment_start(
|
|
153
153
|
self,
|
|
154
|
-
environment:
|
|
154
|
+
environment: interface.Environment,
|
|
155
155
|
duration: float,
|
|
156
156
|
error: BaseException | None
|
|
157
157
|
) -> None:
|
|
@@ -166,7 +166,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
166
166
|
|
|
167
167
|
def on_environment_housekeep(
|
|
168
168
|
self,
|
|
169
|
-
environment:
|
|
169
|
+
environment: interface.Environment,
|
|
170
170
|
counter: int,
|
|
171
171
|
duration: float,
|
|
172
172
|
error: BaseException | None,
|
|
@@ -194,7 +194,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
194
194
|
|
|
195
195
|
def on_environment_shutdown(
|
|
196
196
|
self,
|
|
197
|
-
environment:
|
|
197
|
+
environment: interface.Environment,
|
|
198
198
|
duration: float,
|
|
199
199
|
lifetime: float,
|
|
200
200
|
error: BaseException | None
|
|
@@ -210,8 +210,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
210
210
|
|
|
211
211
|
def on_sandbox_start(
|
|
212
212
|
self,
|
|
213
|
-
|
|
214
|
-
sandbox: base.Sandbox,
|
|
213
|
+
sandbox: interface.Sandbox,
|
|
215
214
|
duration: float,
|
|
216
215
|
error: BaseException | None
|
|
217
216
|
) -> None:
|
|
@@ -226,10 +225,9 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
226
225
|
|
|
227
226
|
def on_sandbox_status_change(
|
|
228
227
|
self,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
new_status: base.Sandbox.Status,
|
|
228
|
+
sandbox: interface.Sandbox,
|
|
229
|
+
old_status: interface.Sandbox.Status,
|
|
230
|
+
new_status: interface.Sandbox.Status,
|
|
233
231
|
span: float
|
|
234
232
|
) -> None:
|
|
235
233
|
if self.sandbox_status:
|
|
@@ -242,8 +240,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
242
240
|
|
|
243
241
|
def on_sandbox_shutdown(
|
|
244
242
|
self,
|
|
245
|
-
|
|
246
|
-
sandbox: base.Sandbox,
|
|
243
|
+
sandbox: interface.Sandbox,
|
|
247
244
|
duration: float,
|
|
248
245
|
lifetime: float,
|
|
249
246
|
error: BaseException | None
|
|
@@ -258,10 +255,62 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
258
255
|
styles=['bold'],
|
|
259
256
|
)
|
|
260
257
|
|
|
258
|
+
def on_sandbox_session_start(
|
|
259
|
+
self,
|
|
260
|
+
sandbox: interface.Sandbox,
|
|
261
|
+
session_id: str,
|
|
262
|
+
duration: float,
|
|
263
|
+
error: BaseException | None
|
|
264
|
+
) -> None:
|
|
265
|
+
"""Called when a sandbox session starts."""
|
|
266
|
+
if self.session_status:
|
|
267
|
+
self._print(
|
|
268
|
+
f'[{sandbox.id}@{session_id}] sandbox session started '
|
|
269
|
+
f'(duration={duration:.2f} seconds)',
|
|
270
|
+
error=error,
|
|
271
|
+
color='blue',
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
def on_sandbox_session_end(
|
|
275
|
+
self,
|
|
276
|
+
sandbox: interface.Sandbox,
|
|
277
|
+
session_id: str,
|
|
278
|
+
duration: float,
|
|
279
|
+
lifetime: float,
|
|
280
|
+
error: BaseException | None
|
|
281
|
+
) -> None:
|
|
282
|
+
"""Called when a sandbox session ends."""
|
|
283
|
+
if self.session_status:
|
|
284
|
+
self._print(
|
|
285
|
+
f'[{sandbox.id}@{session_id}] sandbox session ended '
|
|
286
|
+
f'(duration={duration:.2f} seconds), '
|
|
287
|
+
f'lifetime={lifetime:.2f} seconds)',
|
|
288
|
+
error=error,
|
|
289
|
+
color='blue',
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
def on_sandbox_activity(
|
|
293
|
+
self,
|
|
294
|
+
name: str,
|
|
295
|
+
sandbox: interface.Sandbox,
|
|
296
|
+
session_id: str | None,
|
|
297
|
+
duration: float,
|
|
298
|
+
error: BaseException | None,
|
|
299
|
+
**kwargs
|
|
300
|
+
) -> None:
|
|
301
|
+
"""Called when a sandbox activity is performed."""
|
|
302
|
+
log_id = f'{sandbox.id}@{session_id or "<idle>"}'
|
|
303
|
+
color = 'yellow' if session_id is None else 'cyan'
|
|
304
|
+
self._print(
|
|
305
|
+
f'[{log_id}] sandbox call {name!r} '
|
|
306
|
+
f'(duration={duration:.2f} seconds, kwargs={kwargs}) ',
|
|
307
|
+
error,
|
|
308
|
+
color=color
|
|
309
|
+
)
|
|
310
|
+
|
|
261
311
|
def on_sandbox_housekeep(
|
|
262
312
|
self,
|
|
263
|
-
|
|
264
|
-
sandbox: base.Sandbox,
|
|
313
|
+
sandbox: interface.Sandbox,
|
|
265
314
|
counter: int,
|
|
266
315
|
duration: float,
|
|
267
316
|
error: BaseException | None,
|
|
@@ -279,16 +328,14 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
279
328
|
|
|
280
329
|
def on_feature_setup(
|
|
281
330
|
self,
|
|
282
|
-
|
|
283
|
-
sandbox: base.Sandbox,
|
|
284
|
-
feature: base.Feature,
|
|
331
|
+
feature: interface.Feature,
|
|
285
332
|
duration: float,
|
|
286
333
|
error: BaseException | None
|
|
287
334
|
) -> None:
|
|
288
335
|
"""Called when a sandbox feature is setup."""
|
|
289
336
|
if self.feature_status:
|
|
290
337
|
self._print(
|
|
291
|
-
f'[{
|
|
338
|
+
f'[{feature.id}] feature setup complete '
|
|
292
339
|
f'(duration={duration:.2f} seconds)',
|
|
293
340
|
error=error,
|
|
294
341
|
color='white',
|
|
@@ -296,16 +343,14 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
296
343
|
|
|
297
344
|
def on_feature_teardown(
|
|
298
345
|
self,
|
|
299
|
-
|
|
300
|
-
sandbox: base.Sandbox,
|
|
301
|
-
feature: base.Feature,
|
|
346
|
+
feature: interface.Feature,
|
|
302
347
|
duration: float,
|
|
303
348
|
error: BaseException | None
|
|
304
349
|
) -> None:
|
|
305
350
|
"""Called when a sandbox feature is teardown."""
|
|
306
351
|
if self.feature_status:
|
|
307
352
|
self._print(
|
|
308
|
-
f'[{
|
|
353
|
+
f'[{feature.id}] feature teardown complete '
|
|
309
354
|
f'(duration={duration:.2f} seconds)',
|
|
310
355
|
error=error,
|
|
311
356
|
color='white',
|
|
@@ -313,9 +358,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
313
358
|
|
|
314
359
|
def on_feature_setup_session(
|
|
315
360
|
self,
|
|
316
|
-
|
|
317
|
-
sandbox: base.Sandbox,
|
|
318
|
-
feature: base.Feature,
|
|
361
|
+
feature: interface.Feature,
|
|
319
362
|
session_id: str | None,
|
|
320
363
|
duration: float,
|
|
321
364
|
error: BaseException | None
|
|
@@ -323,7 +366,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
323
366
|
"""Called when a sandbox feature is setup."""
|
|
324
367
|
if self.feature_status:
|
|
325
368
|
self._print(
|
|
326
|
-
f'[{
|
|
369
|
+
f'[{feature.id}@{session_id or "<idle>"}] '
|
|
327
370
|
f'feature setup complete (duration={duration:.2f} seconds)',
|
|
328
371
|
error=error,
|
|
329
372
|
color='yellow',
|
|
@@ -331,9 +374,7 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
331
374
|
|
|
332
375
|
def on_feature_teardown_session(
|
|
333
376
|
self,
|
|
334
|
-
|
|
335
|
-
sandbox: base.Sandbox,
|
|
336
|
-
feature: base.Feature,
|
|
377
|
+
feature: interface.Feature,
|
|
337
378
|
session_id: str,
|
|
338
379
|
duration: float,
|
|
339
380
|
error: BaseException | None
|
|
@@ -341,17 +382,34 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
341
382
|
"""Called when a sandbox feature is teardown."""
|
|
342
383
|
if self.feature_status:
|
|
343
384
|
self._print(
|
|
344
|
-
f'[{
|
|
385
|
+
f'[{feature.id}@{session_id}] '
|
|
345
386
|
f'feature teardown complete (duration={duration:.2f} seconds)',
|
|
346
387
|
error=error,
|
|
347
388
|
color='yellow',
|
|
348
389
|
)
|
|
349
390
|
|
|
391
|
+
def on_feature_activity(
|
|
392
|
+
self,
|
|
393
|
+
name: str,
|
|
394
|
+
feature: interface.Feature,
|
|
395
|
+
session_id: str | None,
|
|
396
|
+
duration: float,
|
|
397
|
+
error: BaseException | None,
|
|
398
|
+
**kwargs
|
|
399
|
+
) -> None:
|
|
400
|
+
"""Called when a feature activity is performed."""
|
|
401
|
+
log_id = f'{feature.id}@{session_id or "<idle>"}'
|
|
402
|
+
color = 'yellow' if session_id is None else 'cyan'
|
|
403
|
+
self._print(
|
|
404
|
+
f'[{log_id}] feature call {name!r} '
|
|
405
|
+
f'(duration={duration:.2f} seconds, kwargs={kwargs}) ',
|
|
406
|
+
error,
|
|
407
|
+
color=color
|
|
408
|
+
)
|
|
409
|
+
|
|
350
410
|
def on_feature_housekeep(
|
|
351
411
|
self,
|
|
352
|
-
|
|
353
|
-
sandbox: base.Sandbox,
|
|
354
|
-
feature: base.Feature,
|
|
412
|
+
feature: interface.Feature,
|
|
355
413
|
counter: int,
|
|
356
414
|
duration: float,
|
|
357
415
|
error: BaseException | None,
|
|
@@ -360,74 +418,13 @@ class EventLogger(pg.Object, base.EventHandler):
|
|
|
360
418
|
"""Called when a sandbox feature is housekeeping."""
|
|
361
419
|
if self.feature_status and self.housekeep_status:
|
|
362
420
|
self._print(
|
|
363
|
-
f'[{
|
|
421
|
+
f'[{feature.id}] feature housekeeping complete '
|
|
364
422
|
f'(counter={counter}, (duration={duration:.2f} seconds, '
|
|
365
423
|
f'housekeep_info={kwargs})',
|
|
366
424
|
error=error,
|
|
367
425
|
color='white',
|
|
368
426
|
)
|
|
369
427
|
|
|
370
|
-
def on_session_start(
|
|
371
|
-
self,
|
|
372
|
-
environment: base.Environment,
|
|
373
|
-
sandbox: base.Sandbox,
|
|
374
|
-
session_id: str,
|
|
375
|
-
duration: float,
|
|
376
|
-
error: BaseException | None
|
|
377
|
-
) -> None:
|
|
378
|
-
"""Called when a sandbox session starts."""
|
|
379
|
-
if self.session_status:
|
|
380
|
-
self._print(
|
|
381
|
-
f'[{sandbox.id}/{session_id}] session started '
|
|
382
|
-
f'(duration={duration:.2f} seconds)',
|
|
383
|
-
error=error,
|
|
384
|
-
color='blue',
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
def on_session_end(
|
|
388
|
-
self,
|
|
389
|
-
environment: base.Environment,
|
|
390
|
-
sandbox: base.Sandbox,
|
|
391
|
-
session_id: str,
|
|
392
|
-
duration: float,
|
|
393
|
-
lifetime: float,
|
|
394
|
-
error: BaseException | None
|
|
395
|
-
) -> None:
|
|
396
|
-
"""Called when a sandbox session ends."""
|
|
397
|
-
if self.session_status:
|
|
398
|
-
self._print(
|
|
399
|
-
f'[{sandbox.id}/{session_id}] session ended '
|
|
400
|
-
f'(duration={duration:.2f} seconds), '
|
|
401
|
-
f'lifetime={lifetime:.2f} seconds)',
|
|
402
|
-
error=error,
|
|
403
|
-
color='blue',
|
|
404
|
-
)
|
|
405
|
-
|
|
406
|
-
def on_sandbox_activity(
|
|
407
|
-
self,
|
|
408
|
-
name: str,
|
|
409
|
-
environment: base.Environment,
|
|
410
|
-
sandbox: base.Sandbox,
|
|
411
|
-
feature: base.Feature | None,
|
|
412
|
-
session_id: str | None,
|
|
413
|
-
duration: float,
|
|
414
|
-
error: BaseException | None,
|
|
415
|
-
**kwargs
|
|
416
|
-
) -> None:
|
|
417
|
-
"""Called when a sandbox activity is performed."""
|
|
418
|
-
del environment
|
|
419
|
-
log_id = f'{sandbox.id}/{session_id or "<idle>"}'
|
|
420
|
-
if feature is not None:
|
|
421
|
-
log_id = f'{log_id}/{feature.name}'
|
|
422
|
-
|
|
423
|
-
color = 'yellow' if session_id is None else 'cyan'
|
|
424
|
-
self._print(
|
|
425
|
-
f'[{log_id}] call {name!r} '
|
|
426
|
-
f'(duration={duration:.2f} seconds, kwargs={kwargs}) ',
|
|
427
|
-
error,
|
|
428
|
-
color=color
|
|
429
|
-
)
|
|
430
|
-
|
|
431
428
|
def _print(
|
|
432
429
|
self,
|
|
433
430
|
message: str,
|
|
@@ -71,15 +71,15 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
71
71
|
outage_retry_interval=0,
|
|
72
72
|
housekeep_interval=1.0,
|
|
73
73
|
sandbox_keepalive_interval=1.0,
|
|
74
|
-
|
|
74
|
+
event_handler=event_logger,
|
|
75
75
|
)
|
|
76
76
|
with self._capture_logs(test_name) as stream:
|
|
77
77
|
with env:
|
|
78
|
-
with env.sandbox('session1') as sb:
|
|
78
|
+
with env.sandbox(session_id='session1') as sb:
|
|
79
79
|
self.assertEqual(sb.test_feature1.num_shell_calls(), 4)
|
|
80
80
|
|
|
81
81
|
with self.assertRaises(interface.SandboxStateError):
|
|
82
|
-
with env.sandbox('session2') as sb:
|
|
82
|
+
with env.sandbox(session_id='session2') as sb:
|
|
83
83
|
sb.shell('echo "bar"', raise_error=RuntimeError)
|
|
84
84
|
|
|
85
85
|
stdout = stream.getvalue()
|
|
@@ -104,9 +104,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
104
104
|
'feature setup complete',
|
|
105
105
|
'feature teardown complete',
|
|
106
106
|
'/test_feature1] feature housekeeping',
|
|
107
|
-
'session started',
|
|
108
|
-
'session ended',
|
|
109
|
-
'call \'shell\'',
|
|
107
|
+
'sandbox session started',
|
|
108
|
+
'sandbox session ended',
|
|
109
|
+
'sandbox call \'shell\'',
|
|
110
110
|
'RuntimeError',
|
|
111
111
|
],
|
|
112
112
|
unexpected_substrings=[
|
|
@@ -154,9 +154,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
154
154
|
'sandbox shutdown',
|
|
155
155
|
'feature setup complete',
|
|
156
156
|
'feature teardown complete',
|
|
157
|
-
'session started',
|
|
158
|
-
'session ended',
|
|
159
|
-
'call \'shell\'',
|
|
157
|
+
'sandbox session started',
|
|
158
|
+
'sandbox session ended',
|
|
159
|
+
'sandbox call \'shell\'',
|
|
160
160
|
'RuntimeError',
|
|
161
161
|
],
|
|
162
162
|
regex='.*environment.*',
|
|
@@ -174,9 +174,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
174
174
|
'feature setup complete',
|
|
175
175
|
'feature teardown complete',
|
|
176
176
|
'feature housekeeping',
|
|
177
|
-
'session started',
|
|
178
|
-
'session ended',
|
|
179
|
-
'call \'shell\'',
|
|
177
|
+
'sandbox session started',
|
|
178
|
+
'sandbox session ended',
|
|
179
|
+
'sandbox call \'shell\'',
|
|
180
180
|
'RuntimeError',
|
|
181
181
|
],
|
|
182
182
|
unexpected_substrings=[
|
|
@@ -202,9 +202,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
202
202
|
'-> acquired',
|
|
203
203
|
'sandbox shutdown',
|
|
204
204
|
'sandbox housekeeping',
|
|
205
|
-
'session started',
|
|
206
|
-
'session ended',
|
|
207
|
-
'call \'shell\'',
|
|
205
|
+
'sandbox session started',
|
|
206
|
+
'sandbox session ended',
|
|
207
|
+
'sandbox call \'shell\'',
|
|
208
208
|
'RuntimeError',
|
|
209
209
|
],
|
|
210
210
|
unexpected_substrings=[
|
|
@@ -232,12 +232,12 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
232
232
|
'feature setup complete',
|
|
233
233
|
'feature teardown complete',
|
|
234
234
|
'feature housekeeping',
|
|
235
|
-
'call \'shell\'',
|
|
235
|
+
'sandbox call \'shell\'',
|
|
236
236
|
'RuntimeError',
|
|
237
237
|
],
|
|
238
238
|
unexpected_substrings=[
|
|
239
|
-
'session started',
|
|
240
|
-
'session ended',
|
|
239
|
+
'sandbox session started',
|
|
240
|
+
'sandbox session ended',
|
|
241
241
|
],
|
|
242
242
|
session_status=False,
|
|
243
243
|
)
|
|
@@ -256,9 +256,9 @@ class EventLoggerTest(unittest.TestCase):
|
|
|
256
256
|
'sandbox shutdown',
|
|
257
257
|
'feature setup complete',
|
|
258
258
|
'feature teardown complete',
|
|
259
|
-
'session started',
|
|
260
|
-
'session ended',
|
|
261
|
-
'call \'shell\'',
|
|
259
|
+
'sandbox session started',
|
|
260
|
+
'sandbox session ended',
|
|
261
|
+
'sandbox call \'shell\'',
|
|
262
262
|
'RuntimeError',
|
|
263
263
|
],
|
|
264
264
|
unexpected_substrings=[
|