1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! Handler for `trusty-search dashboard` — open the admin panel in a browser.
//!
//! Why: `dashboard` / `dash` / `ui` is a convenience entrypoint: the user
//! should never have to know which port the daemon chose or whether it is
//! running yet. Mirrors the trusty-analyze pattern from PR #685.
//!
//! What: calls `ensure_daemon_running_or_exit` which spawns the daemon in the
//! background if it is not yet running and polls `/health` until ready (60s
//! budget with a braille spinner). Then discovers the bound address via
//! `daemon_base_url()` (which reads `~/.trusty-search/http_addr` with TCP
//! fallbacks) and opens `http://<addr>/ui` in the default browser. On
//! browser-open failure (headless env) degrades gracefully by printing the
//! URL to stderr rather than returning an error.
//!
//! Test: `cargo run -- dashboard` with no daemon running spawns the daemon
//! and opens the browser; with the daemon already running, the probe returns
//! immediately and no spawn occurs; headless (no GUI) prints the URL.
use daemon_base_url;
use Result;
use Colorize;
/// Open the admin panel of the running daemon in the default browser.
///
/// Why: provides a one-command path from "is the daemon up?" to "show me the
/// UI" without the user having to memorise ports or run `trusty-search start`
/// first. Auto-starts the daemon when absent, matching the trusty-analyze
/// dashboard (#685) for a consistent UX across the suite.
/// What: ensures the daemon is running (spawning it in the background if
/// needed), resolves the bound address via `daemon_base_url()`, then opens
/// `http://<addr>/ui`. Browser-open failure degrades to a printed URL.
/// Test: `cargo test -p trusty-search -- dashboard` exercises the
/// already-healthy path. Manual: `cargo run -- dashboard` with no daemon
/// should print the "Starting…" spinner and then open the browser.
pub async
/// Construct the `/ui` URL from `base` and open it in the default browser.
///
/// Why: extracted so tests can exercise the URL-construction + open path
/// independently from the async auto-start flow.
/// What: appends `/ui` to `base`, prints the URL, calls `open::that`, and
/// degrades gracefully (stderr warning + URL) if the browser cannot be
/// launched (headless / CI environments).
/// Test: `dashboard_url_is_constructed_correctly` verifies the URL shape.