6Instrumentation Self‑Test (Dash App)
7====================================
11A minimal, deterministic Dash application used exclusively for **manual**
12validation of the instrumentation system:
14- ID rewriting (instrument_ids)
15- Dynamic instrumentation of callback outputs
16- UI event logger integration
17- Dispatcher patching (middleware)
18- Logging behavior under different debug-level modes
20This module is NOT used in production and is intentionally verbose.
23 **This is a manual integration harness, not an automated test.**
24 Running this module launches a Dash development server that blocks
25 indefinitely until interrupted (Ctrl-C). It produces no assertions,
26 no exit code, and no machine-readable result. It cannot be integrated
27 into CI/CD pipelines. Use ``instrumentation_selftest_cli.py`` for
28 headless, non-blocking instrumentation checks.
332. Build static layout (UNINSTRUMENTED — IDs must remain strings)
343. Register UI event logger
365. Enable instrumentation middleware
376. Run the development server (blocks until Ctrl-C)
39Static layout must NOT be instrumented because Dash callback decorators
40match string IDs. Dynamic content *is* instrumented explicitly using:
42 return apply_instrumentation(dynamic_component_tree)
46MODE A — FORCE VERBOSE (default)
47 DEBUG_LEVELS["INSTRUMENTATION"] = 9
48 DEBUG_LEVELS["UI"] = 9
50MODE B — RESPECT GLOBAL LEVELS
51 Use whatever levels are defined in unified_debug.py
54 python -m oc_diagnostics.instrumentation_selftest_app --use-global
58- Build a static Dash layout with string IDs (NOT instrumented at build
59 time, so callback decorators can match by string ID).
60- Register the UI event logger and all callbacks.
61- Enable instrumentation middleware via ``enable_instrumentation_middleware()``
62 after all callbacks are registered.
63- Optionally force maximum verbosity (default) or use global levels.
64- Launch the Dash development server (blocking call).
68Domain: INSTRUMENTATION
76- Must never be used in CI/CD or automated testing.
77- Must not instrument the static layout at build time.
78- Dynamic callback outputs must be instrumented via ``apply_instrumentation()``.
79- Requires Dash (``pip install oc_diagnostics[dash]``).
83from dash
import Dash, html, dcc, Input, Output
86 enable_instrumentation_middleware,
87 apply_instrumentation,
99 Build the test app following the same lifecycle as the main app.
104 If True, override global debug levels and force maximum verbosity.
111 DEBUG_LEVELS[
"INSTRUMENTATION"] = 9
112 DEBUG_LEVELS[
"UI"] = 9
113 _dbg(
"TEST",
"debug_levels",
"FORCING MAX VERBOSITY", override=
True)
115 _dbg(
"TEST",
"debug_levels",
"Using GLOBAL debug levels", override=
True)
125 app.layout = html.Div(
127 html.Button(
"Click me", id=
"btn"),
129 dcc.Store(id=
"debug-settings-data-store"),
142 Output(
"out",
"children"),
143 Input(
"btn",
"n_clicks"),
145 def update_output(n):
147 return "Click the button"
154 enable_instrumentation_middleware(app)
165 CLI entry point for the Dash instrumentation test app.
167 parser = argparse.ArgumentParser(description=
"Instrumentation Self-Test App")
171 help=
"Use global debug levels instead of forcing verbosity",
177 "Enable Dash debug mode (Werkzeug reloader + debugger). "
178 "Off by default to avoid spawning a second process and exposing "
179 "the Werkzeug debug console. See OI-18 in AI_REVIEW_SYNTHESIS V2.md."
182 args = parser.parse_args()
185 app.run_server(debug=args.debug)
188if __name__ ==
"__main__":
create_test_app(bool force_verbose)
NoReturn apply_instrumentation(*Any args, **Any kwargs)