MCPcopy
hub / github.com/reflex-dev/reflex / TelemetryCompileApp

Function TelemetryCompileApp

tests/integration/test_telemetry_compile.py:22–85  ·  view source on GitHub ↗

Reflex app exercising the features collected on the ``compile`` event. Includes a parent + child state hierarchy with Cookie / LocalStorage / SessionStorage to guard against the inherited-field double-count regression, a background event handler, a SharedState user subclass, and a d

(events_log_path: str = "")

Source from the content-addressed store, hash-verified

20
21
22def TelemetryCompileApp(events_log_path: str = ""):
23 """Reflex app exercising the features collected on the ``compile`` event.
24
25 Includes a parent + child state hierarchy with Cookie / LocalStorage /
26 SessionStorage to guard against the inherited-field double-count
27 regression, a background event handler, a SharedState user subclass,
28 and a dynamic route.
29
30 Args:
31 events_log_path: Filesystem path to a JSONL file. Every
32 ``telemetry.send`` invocation during compile is appended as
33 one JSON object per line so the test can read it back.
34 """
35 import json
36 import os
37 from pathlib import Path
38
39 import reflex as rx
40 from reflex.istate.storage import Cookie, LocalStorage, SessionStorage
41 from reflex.utils import telemetry
42
43 # AppHarness force-disables telemetry. Re-enable it on the live config
44 # singleton so the real _compile() path runs record_compile, and
45 # redirect telemetry.send to disk so the test can read the payload.
46 os.environ["REFLEX_TELEMETRY_ENABLED"] = "true"
47 rx.config.get_config().telemetry_enabled = True
48
49 sink = Path(events_log_path)
50 sink.parent.mkdir(parents=True, exist_ok=True)
51
52 def _capture(event, properties=None, **_kwargs):
53 with sink.open("a") as fh:
54 fh.write(
55 json.dumps({"event": event, "properties": properties or {}}) + "\n"
56 )
57 return True
58
59 telemetry.send = _capture
60
61 class StorageRoot(rx.State):
62 token: str = Cookie()
63 local_pref: str = LocalStorage()
64
65 @rx.event(background=True)
66 async def heavy(self):
67 """Background handler used to assert detection."""
68
69 class StorageChild(StorageRoot):
70 # ``token`` and ``local_pref`` are inherited here and must not be
71 # re-counted on the child state.
72 session: str = SessionStorage()
73
74 class SharedThing(rx.SharedState):
75 value: int = 0
76
77 def index():
78 return rx.box(rx.text("home"))
79

Callers

nothing calls this directly

Calls 3

add_pageMethod · 0.95
PathClass · 0.85
get_configMethod · 0.80

Tested by

no test coverage detected