forge
Explore
Log in

Don't you dare go Hollow

the family flyout under the monogram carries the same health dots im's does.

Browse files at this commit

e39e1346fd1762b9d3c4bd0fa320f95b8d7751a6Ahmet Kaan GümüşParent: c6102af
Each sibling mark probes /healthz concurrently; green while it answers ok, muted otherwise. Dots only. Trailing-slash hrefs stay. Local config/in.toml is left unstaged.
Cargo.lockmodified+1 -0
@@ -2041,6 +2041,7 @@ dependencies = [
2041 "im-client",2041 "im-client",
2042 "in-client",2042 "in-client",
2043 "in-core",2043 "in-core",
2044+ "reqwest",
2044 "serde",2045 "serde",
2045 "serde_json",2046 "serde_json",
2046 "sha2 0.11.0",2047 "sha2 0.11.0",
crates/in-web/Cargo.tomlmodified+2 -0
@@ -41,6 +41,8 @@ http-body = "1"
41 # this binary (see `server.rs`'s `stylesheet_guard`).41 # this binary (see `server.rs`'s `stylesheet_guard`).
42 sha2 = "0.11"42 sha2 = "0.11"
43 ulid = { workspace = true }43 ulid = { workspace = true }
44+# The wordmark flyout probes each sibling's `/healthz` where it stands.
45+reqwest = { version = "0.13.5", default-features = false, features = ["rustls"] }
44 46
45 [build-dependencies]47 [build-dependencies]
46 grass = "0.13"48 grass = "0.13"
crates/in-web/src/health.rsadded+39 -0
@@ -0,0 +1,39 @@
1+//! The one family-health probe, shared by the signed-in wordmark's flyout:
2+//! a service is asked `GET {url}/healthz` where it stands — no credentials,
3+//! two seconds to answer — and the callers fan the probes out concurrently,
4+//! so a family member that is down costs its two seconds, not two seconds
5+//! each.
6+
7+/// One `/healthz` reading. `Up` carries the body — the deploy contract's
8+/// `ok <build sha>` — and the answer's latency; everything else, refused
9+/// or wrong status or a body that does not begin ok or the two-second
10+/// ceiling, is `Down`.
11+pub enum Probe {
12+ Up { body: String, ms: u128 },
13+ Down,
14+}
15+
16+pub(crate) async fn probe_healthz(http: &reqwest::Client, url: &str) -> Probe {
17+ let started = std::time::Instant::now();
18+ let Ok(answer) = http
19+ .get(url)
20+ .timeout(std::time::Duration::from_secs(2))
21+ .send()
22+ .await
23+ else {
24+ return Probe::Down;
25+ };
26+ if !answer.status().is_success() {
27+ return Probe::Down;
28+ }
29+ let body = answer.text().await.unwrap_or_default();
30+ let body = body.trim();
31+ if body.starts_with("ok") {
32+ Probe::Up {
33+ body: body.chars().take(64).collect(),
34+ ms: started.elapsed().as_millis(),
35+ }
36+ } else {
37+ Probe::Down
38+ }
39+}
crates/in-web/src/layout.rsmodified+64 -16
@@ -20,6 +20,7 @@ use topcoat::{
20 20
21 use in_core::store::User;21 use in_core::store::User;
22 22
23+use crate::health::{Probe, probe_healthz};
23 use crate::i18n::{Key, Lang, t};24 use crate::i18n::{Key, Lang, t};
24 use crate::server::{app, current_user};25 use crate::server::{app, current_user};
25 26
@@ -248,8 +249,10 @@ async fn family_of(cx: &Cx) -> Vec<in_client::ServiceJson> {
248 /// sibling services' wordmarks in a flyout that opens under it on hover249 /// sibling services' wordmarks in a flyout that opens under it on hover
249 /// and on keyboard focus — the mark is an `<a href="/">`, so it is already250 /// and on keyboard focus — the mark is an `<a href="/">`, so it is already
250 /// focusable and `:focus-within` needs nothing added. Middots between,251 /// focusable and `:focus-within` needs nothing added. Middots between,
251-/// each a plain link to the service's own address, so the cross-origin252+/// each a plain link to the service's own address, carrying its health
252-/// hop navigates the browser natively. No script: the flyout is CSS on253+/// dot — the same `/healthz` reading: green while the sibling answers
254+/// `ok`, muted while it does not. The cross-origin hop navigates the
255+/// browser natively. No script: the flyout is CSS on
253 /// `:hover` / `:focus-within`, and it stays in the DOM at opacity zero so256 /// `:hover` / `:focus-within`, and it stays in the DOM at opacity zero so
254 /// Tab reaches its links. A family that is absent, or holds no one but257 /// Tab reaches its links. A family that is absent, or holds no one but
255 /// this app, renders the bare mark — there is nothing to reveal.258 /// this app, renders the bare mark — there is nothing to reveal.
@@ -262,29 +265,74 @@ async fn family_mark<'a>(cx: &'a Cx) -> Result<impl View + 'a> {
262 if siblings.is_empty() {265 if siblings.is_empty() {
263 return mark(cx).await.map(|v| v.boxed());266 return mark(cx).await.map(|v| v.boxed());
264 }267 }
268+ // Every probe at once: a family member that is down costs its two
269+ // seconds, not two seconds each.
270+ let http = reqwest::Client::new();
271+ let mut probes = Vec::new();
272+ for service in &siblings {
273+ let http = http.clone();
274+ let url = format!("{}/healthz", service.url.trim_end_matches('/'));
275+ probes.push(tokio::spawn(async move { probe_healthz(&http, &url).await }));
276+ }
277+ let mut rows = Vec::new();
278+ for (service, probe) in siblings.iter().zip(probes) {
279+ let probe = probe.await.unwrap_or(Probe::Down);
280+ rows.push((
281+ service.key.as_str(),
282+ service.url.as_str(),
283+ service.name.as_str(),
284+ probe,
285+ ));
286+ }
287+ let marks = switcher_marks(rows);
265 Ok(view! {288 Ok(view! {
266 cx =>289 cx =>
267 <div class="wordmark-family">290 <div class="wordmark-family">
268 (topcoat::view::Child::new(mark(cx).await?))291 (topcoat::view::Child::new(mark(cx).await?))
269- <nav class="app-switcher">292+ <nav class="app-switcher">(Unescaped::new_unchecked(marks))</nav>
270- for (i, service) in siblings.iter().enumerate() {
271- if i > 0 {
272- <span class="app-switcher-sep">"·"</span>
273- }
274- <a
275- class="app-switcher-mark"
276- href=(format!("{}/", service.url))
277- title=(service.name.clone())
278- >
279- (service.key.clone())
280- </a>
281- }
282- </nav>
283 </div>293 </div>
284 }294 }
285 .boxed())295 .boxed())
286 }296 }
287 297
298+/// The flyout's marks as final HTML, pure over resolved probes: in's own
299+/// row filtered out, every sibling a plain link carrying its probe's dot
300+/// — `health-on` while it answers `ok`, `health-off` while it does not —
301+/// middots between. Dots only: the probe's body and latency never reach
302+/// the chrome. Extracted from `family_mark` so the tests pin this exact
303+/// markup without a router or an asset bundle.
304+pub fn switcher_marks<'a>(
305+ rows: impl IntoIterator<Item = (&'a str, &'a str, &'a str, Probe)>,
306+) -> String {
307+ rows.into_iter()
308+ .filter(|(key, _, _, _)| *key != SELF_KEY)
309+ .map(|(key, url, name, probe)| {
310+ let key = escape(key);
311+ let url = escape(url);
312+ let name = escape(name);
313+ let dot = match probe {
314+ Probe::Up { .. } => "health-on",
315+ Probe::Down => "health-off",
316+ };
317+ format!(
318+ r#"<a class="app-switcher-mark" href="{url}/" title="{name}"><span class="health-dot {dot}"></span>{key}</a>"#
319+ )
320+ })
321+ .collect::<Vec<_>>()
322+ .join(r#"<span class="app-switcher-sep">·</span>"#)
323+}
324+
325+/// Everything the flyout's marks interpolate crosses them as raw HTML —
326+/// key, address, title — so each passes through `escape` first: the same
327+/// discipline im's chrome keeps, anything the family list carries is
328+/// escaped before it reaches the markup.
329+fn escape(raw: &str) -> String {
330+ raw.replace('&', "&amp;")
331+ .replace('<', "&lt;")
332+ .replace('>', "&gt;")
333+ .replace('"', "&quot;")
334+}
335+
288 /// The signed-in chrome: the monogram with the family behind it, the page336 /// The signed-in chrome: the monogram with the family behind it, the page
289 /// nav, the identity menu. Wave-2 pages render their content under this.337 /// nav, the identity menu. Wave-2 pages render their content under this.
290 pub async fn topbar<'a>(338 pub async fn topbar<'a>(
crates/in-web/src/lib.rsmodified+1 -0
@@ -7,6 +7,7 @@ pub mod avatar;
7 pub mod drive;7 pub mod drive;
8 pub mod dropdown;8 pub mod dropdown;
9 pub mod files;9 pub mod files;
10+pub mod health;
10 pub mod i18n;11 pub mod i18n;
11 pub mod layout;12 pub mod layout;
12 pub mod live;13 pub mod live;
crates/in-web/tests/http.rsmodified+111 -0
@@ -3267,10 +3267,121 @@ async fn the_family_flyout_holds_the_siblings_when_the_family_is_mirrored() {
3267 assert!(nav.contains("title=\"Account\""), "{nav}");3267 assert!(nav.contains("title=\"Account\""), "{nav}");
3268 assert_eq!(nav.matches("app-switcher-mark").count(), 2, "{nav}");3268 assert_eq!(nav.matches("app-switcher-mark").count(), 2, "{nav}");
3269 assert_eq!(nav.matches("app-switcher-sep").count(), 1, "{nav}");3269 assert_eq!(nav.matches("app-switcher-sep").count(), 1, "{nav}");
3270+ // Both siblings sit at example.com addresses nothing answers — the
3271+ // probes fail inside their two-second ceiling, concurrently — so both
3272+ // read Off. The flyout carries dots only, one per mark.
3273+ assert!(nav.contains("health-dot health-off"), "{nav}");
3274+ assert!(!nav.contains("health-on"), "{nav}");
3275+ assert_eq!(nav.matches("health-dot").count(), 2, "{nav}");
3270 // The flyout hangs off the monogram, not the page nav.3276 // The flyout hangs off the monogram, not the page nav.
3271 assert!(body.contains("wordmark-family"), "{body}");3277 assert!(body.contains("wordmark-family"), "{body}");
3272 }3278 }
3273 3279
3280+/// The flyout marks each sibling with its probe's reading: a sibling
3281+/// answering `ok` renders `health-on`, a dark port `health-off`, dots
3282+/// only — no probe body, no latency — and in's own row stays out. The
3283+/// markup itself is pinned router-free in
3284+/// `the_family_flyout_marks_pure_html` below.
3285+#[tokio::test]
3286+async fn the_family_flyout_marks_siblings_with_health_dots() {
3287+ use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
3288+
3289+ // A live sibling answering the deploy body, and a dark one.
3290+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
3291+ let live_url = format!("http://{}", listener.local_addr().unwrap());
3292+ let dark = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
3293+ let dark_url = format!("http://{}", dark.local_addr().unwrap());
3294+ drop(dark);
3295+ // `in` gets a row too — one the flyout must leave out.
3296+ let app = TestApp::build_with(
3297+ None,
3298+ &[
3299+ ("in", "Files", "https://files.example.com"),
3300+ ("iz", "Board", &live_url),
3301+ ("im", "Account", &dark_url),
3302+ ],
3303+ )
3304+ .await;
3305+ let cookie = app
3306+ .sign_in("sub-switch-dot", "switchdot@in.test", "SwitchDot")
3307+ .await;
3308+ let talker = tokio::spawn(async move {
3309+ let (mut sock, _) = listener.accept().await.unwrap();
3310+ let mut buf = [0u8; 1024];
3311+ let _ = sock.read(&mut buf).await;
3312+ sock.write_all(b"HTTP/1.1 200 OK\r\ncontent-length: 6\r\n\r\nok dev")
3313+ .await
3314+ .unwrap();
3315+ });
3316+ let page = app.get("/drive", Some(&cookie)).await;
3317+ assert_eq!(page.status, StatusCode::OK, "{}", page.text());
3318+ talker.await.unwrap();
3319+ let body = page.text();
3320+ let nav_start = body.find("app-switcher").expect("no switcher");
3321+ let nav_end = body[nav_start..]
3322+ .find("</nav>")
3323+ .expect("switcher never closes");
3324+ let nav = &body[nav_start..nav_start + nav_end];
3325+ assert!(
3326+ nav.contains(r#"<a class="app-switcher-mark" href="http://127.0.0.1:"#),
3327+ "the marks stay links: {nav}"
3328+ );
3329+ assert!(
3330+ nav.contains("health-dot health-on"),
3331+ "the ok sibling reads on: {nav}"
3332+ );
3333+ assert!(nav.contains(">iz</a>"), "the live sibling renders: {nav}");
3334+ assert!(
3335+ nav.contains("health-dot health-off"),
3336+ "the dark sibling reads off: {nav}"
3337+ );
3338+ assert!(nav.contains(">im</a>"), "the dark sibling renders: {nav}");
3339+ assert!(!nav.contains(">in</a>"), "in's own row stays out: {nav}");
3340+ assert!(!body.contains("ok dev"), "the flyout carries dots only: {body}");
3341+ assert!(!nav.contains(" ms"), "the flyout carries no latency: {nav}");
3342+}
3343+
3344+/// The CI gate for the flyout markup: `switcher_marks` is the exact HTML
3345+/// the flyout renders, so the probe-to-dot mapping and in's omission are
3346+/// pinned without a router or an asset bundle — which is where the
3347+/// renders above get skipped. Up reads `health-on`, Down `health-off`,
3348+/// the keys stay links with their titles, and the probe's body and
3349+/// latency never reach the chrome.
3350+#[test]
3351+fn the_family_flyout_marks_pure_html() {
3352+ use in_web::health::Probe;
3353+
3354+ let marks = in_web::layout::switcher_marks([
3355+ ("iz", "http://127.0.0.1:9001", "Board", Probe::Up { body: "ok dev".into(), ms: 12 }),
3356+ ("im", "http://127.0.0.1:9002", "Account", Probe::Down),
3357+ // in's own row goes in; it must not come back out.
3358+ ("in", "http://127.0.0.1:7655", "Files", Probe::Up { body: "ok dev".into(), ms: 1 }),
3359+ ]);
3360+ assert!(
3361+ marks.contains(
3362+ r#"<a class="app-switcher-mark" href="http://127.0.0.1:9001/" title="Board">"#
3363+ ),
3364+ "the marks stay links: {marks}"
3365+ );
3366+ assert!(
3367+ marks.contains("health-dot health-on"),
3368+ "the ok sibling reads on: {marks}"
3369+ );
3370+ assert!(marks.contains(">iz</a>"), "the live sibling renders: {marks}");
3371+ assert!(
3372+ marks.contains("health-dot health-off"),
3373+ "the dark sibling reads off: {marks}"
3374+ );
3375+ assert!(marks.contains(">im</a>"), "the dark sibling renders: {marks}");
3376+ assert!(!marks.contains(">in</a>"), "in's own row stays out: {marks}");
3377+ assert!(!marks.contains("ok dev"), "the flyout carries dots only: {marks}");
3378+ assert!(!marks.contains(" ms"), "the flyout carries no latency: {marks}");
3379+ assert!(
3380+ marks.contains(r#"<span class="app-switcher-sep">·</span>"#),
3381+ "the marks join on middots: {marks}"
3382+ );
3383+}
3384+
3274 /// The `back` the sign-out hands im is read per sign-out: an origin saved3385 /// The `back` the sign-out hands im is read per sign-out: an origin saved
3275 /// on the running install — the `base_url` setting the settings panel3386 /// on the running install — the `base_url` setting the settings panel
3276 /// writes — takes effect on the very next exit, without a restart. Until3387 /// writes — takes effect on the very next exit, without a restart. Until
style/main.scssmodified+20 -2
@@ -503,8 +503,11 @@ a {
503 // from a row the flyout hangs across.503 // from a row the flyout hangs across.
504 z-index: 50;504 z-index: 50;
505 display: flex;505 display: flex;
506- align-items: baseline;506+ align-items: center;
507- gap: 10px;507+ // The flyout shrink-fits to the monogram's width; without this the
508+ // health dot wraps off its key. It grows right instead, over the page
509+ // nav, under the house dropdown's panel.
510+ white-space: nowrap;
508 padding: 6px 12px;511 padding: 6px 12px;
509 background: var(--surface);512 background: var(--surface);
510 border: 1px solid var(--border);513 border: 1px solid var(--border);
@@ -528,6 +531,21 @@ a {
528 531
529 &-sep { color: var(--muted-soft); }532 &-sep { color: var(--muted-soft); }
530 }533 }
534+
535+// The wordmark flyout's per-service state dot: green while the service's
536+// /healthz answers ok, muted when it does not — the same light iz's
537+// connection card and im's flyout carry, one green across the family.
538+.health-dot {
539+ display: inline-block;
540+ width: 0.55rem;
541+ height: 0.55rem;
542+ border-radius: 50%;
543+ margin-right: 0.4rem;
544+ vertical-align: baseline;
545+
546+ &.health-on { background: #2e9e5b; }
547+ &.health-off { background: var(--muted); }
548+}
531 .scaffold-note {549 .scaffold-note {
532 margin: 24px;550 margin: 24px;
533 padding: 20px 24px;551 padding: 20px 24px;