|
| 1 | +"""Tests for `get_debug_bridge()` selection matrix. |
| 2 | +
|
| 3 | +Locks in the non-breaking-change contract: absence of `attach` preserves the |
| 4 | +legacy `job_id`-based selection. Explicit `attach` overrides that selection. |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | +from uipath._cli._debug._bridge import ( |
| 12 | + ConsoleDebugBridge, |
| 13 | + SignalRDebugBridge, |
| 14 | + get_debug_bridge, |
| 15 | +) |
| 16 | +from uipath.runtime import UiPathRuntimeContext |
| 17 | +from uipath.runtime.debug import DetachedDebugBridge |
| 18 | + |
| 19 | + |
| 20 | +def _ctx(**overrides) -> UiPathRuntimeContext: |
| 21 | + return UiPathRuntimeContext(**overrides) |
| 22 | + |
| 23 | + |
| 24 | +def test_attach_none_returns_detached_bridge_without_job_id(): |
| 25 | + bridge = get_debug_bridge(_ctx(), attach="none") |
| 26 | + assert isinstance(bridge, DetachedDebugBridge) |
| 27 | + |
| 28 | + |
| 29 | +def test_attach_none_returns_detached_bridge_even_when_job_id_set(monkeypatch): |
| 30 | + """'none' wins over job_id — this is the whole point of the flag.""" |
| 31 | + monkeypatch.setenv("UIPATH_URL", "https://cloud.uipath.com") |
| 32 | + bridge = get_debug_bridge(_ctx(job_id="job-123"), attach="none") |
| 33 | + assert isinstance(bridge, DetachedDebugBridge) |
| 34 | + |
| 35 | + |
| 36 | +def test_attach_signalr_forces_signalr_bridge(monkeypatch): |
| 37 | + monkeypatch.setenv("UIPATH_URL", "https://cloud.uipath.com") |
| 38 | + bridge = get_debug_bridge(_ctx(job_id="job-123"), attach="signalr") |
| 39 | + assert isinstance(bridge, SignalRDebugBridge) |
| 40 | + |
| 41 | + |
| 42 | +def test_attach_console_forces_console_bridge_even_when_job_id_set(monkeypatch): |
| 43 | + monkeypatch.setenv("UIPATH_URL", "https://cloud.uipath.com") |
| 44 | + bridge = get_debug_bridge(_ctx(job_id="job-123"), attach="console") |
| 45 | + assert isinstance(bridge, ConsoleDebugBridge) |
| 46 | + |
| 47 | + |
| 48 | +def test_legacy_selection_signalr_when_job_id_set_and_no_attach(monkeypatch): |
| 49 | + """Non-breaking change assertion: absence of `attach` preserves today's behavior.""" |
| 50 | + monkeypatch.setenv("UIPATH_URL", "https://cloud.uipath.com") |
| 51 | + bridge = get_debug_bridge(_ctx(job_id="job-123")) |
| 52 | + assert isinstance(bridge, SignalRDebugBridge) |
| 53 | + |
| 54 | + |
| 55 | +def test_legacy_selection_console_when_no_job_id_and_no_attach(): |
| 56 | + """Non-breaking change assertion: absence of `attach` preserves today's behavior.""" |
| 57 | + bridge = get_debug_bridge(_ctx()) |
| 58 | + assert isinstance(bridge, ConsoleDebugBridge) |
| 59 | + |
| 60 | + |
| 61 | +def test_attach_signalr_without_job_id_raises(): |
| 62 | + """Explicit signalr without job_id is a user error — surface it loudly.""" |
| 63 | + with pytest.raises(ValueError, match="UIPATH_URL and UIPATH_JOB_KEY"): |
| 64 | + get_debug_bridge(_ctx(), attach="signalr") |
0 commit comments