Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions oxa/oxa-cli/src/lead_page.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Read-only web projection. Never serialize runner records or arbitrary GitHub payloads.
use oxa_proto::work::{IncidentKind, PullRequest, Snapshot, Subject};
use oxa_work::board::{Action, Board};
use oxa_work::board::{Action, Board, Entry};
use std::fmt::Write;

mod chat;
Expand Down Expand Up @@ -82,7 +82,11 @@ pub fn content(view: &View<'_>, now: u64) -> String {
}

pub fn content_for(page: Page, view: &View<'_>, now: u64) -> String {
let mut html = format!("<main><h1 id=main tabindex=-1>{}</h1>", page.title());
let title = match page {
Page::Item(number) => format!("Item #{number}"),
_ => page.title().into(),
};
let mut html = format!("<main><h1 id=main tabindex=-1>{title}</h1>");
if page == Page::Home {
attention(&mut html, view);
}
Expand All @@ -106,6 +110,7 @@ pub fn content_for(page: Page, view: &View<'_>, now: u64) -> String {
}
Page::Workers => workers(&mut html, view),
Page::Asks => asks(&mut html, view),
Page::Item(number) => item(&mut html, view, number, now),
Page::Chat(prompt) => chat::render(&mut html, view, prompt),
Page::Usage => html
.push_str("<section><h2>Plans and quotas</h2><p>Usage observations unavailable.</p></section>"),
Expand Down Expand Up @@ -186,17 +191,10 @@ fn board(html: &mut String, view: &View<'_>, now: u64, query: Query) {
html.push_str("<div class=scroll><table><thead><tr><th>PR</th><th>Next action</th><th>Priority</th><th>Lease</th><th>Attempts today</th></tr></thead><tbody>");
let offset = query.page.saturating_mul(pages::BOARD_ROWS);
for row in rows.iter().skip(offset).take(pages::BOARD_ROWS) {
let lease = row.lease.as_ref().map_or("Unleased".into(), |l| {
format!(
"{} · expires {}{}",
escape(&l.holder),
l.expires_at,
if l.expires_at <= now { " (expired)" } else { "" }
)
});
let lease = lease(row, now);
let _ = write!(
html,
"<tr><td>#{}</td><td>{}</td><td>{}</td><td>{lease}</td><td>{}</td></tr>",
"<tr><td><a href=/items/{0}>#{0}</a></td><td>{1}</td><td>{2}</td><td>{lease}</td><td>{3}</td></tr>",
row.number,
action(row.action),
if row.release_pinned { "Release" } else { "Normal" },
Expand Down Expand Up @@ -232,6 +230,34 @@ fn board(html: &mut String, view: &View<'_>, now: u64, query: Query) {
html.push_str("</section>");
}

fn lease(row: &Entry, now: u64) -> String {
row.lease.as_ref().map_or("Unleased".into(), |l| {
format!(
"{} · expires {}{}",
escape(&l.holder),
l.expires_at,
if l.expires_at <= now { " (expired)" } else { "" }
)
})
}

fn item(html: &mut String, view: &View<'_>, number: u64, now: u64) {
html.push_str("<p><a href=/board>Back to Board</a></p>");
let Some(board) = view.board else {
html.push_str("<p>Board unavailable.</p>");
return;
};
let Some(row) = board.entries.iter().find(|row| row.number == number) else {
html.push_str("<p>Item unavailable in this snapshot.</p>");
return;
};
let _ = write!(html,
"<section><h2>Next action</h2><p>{}</p></section><section><h2>State</h2><p>{}</p><p>{}</p><p>Attempts today: {}</p><p class=muted>Observed at {} (Unix seconds)</p></section>",
action(row.action), if row.release_pinned { "Release" } else { "Normal priority" },
lease(row, now), row.attempts_today, board.observed_at);
html.push_str("<section><h2>Details and changes</h2><p>Title, checks, findings and diff observations unavailable.</p></section>");
}

fn workers(html: &mut String, view: &View<'_>) {
html.push_str("<section id=lanes><h2>Workers</h2>");
if let Some(s) = view.situation {
Expand Down
10 changes: 8 additions & 2 deletions oxa/oxa-cli/src/lead_page/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Page {
BoardQuery(Query),
Workers,
Usage,
Item(u64),
Chat(Prompt),
}

Expand All @@ -31,6 +32,7 @@ impl Page {
Self::Board | Self::BoardQuery(_) => "Board",
Self::Workers => "Workers",
Self::Usage => "Usage",
Self::Item(_) => "Item",
Self::Chat(_) => "Chat with lead",
}
}
Expand All @@ -39,7 +41,7 @@ impl Page {
match self {
Self::Home => "/",
Self::Asks => "/asks",
Self::Board | Self::BoardQuery(_) => "/board",
Self::Board | Self::BoardQuery(_) | Self::Item(_) => "/board",
Self::Workers => "/workers",
Self::Usage => "/usage",
Self::Chat(_) => "/chat",
Expand All @@ -51,6 +53,10 @@ impl Page {
.strip_suffix("?fragment=1")
.or_else(|| path.strip_suffix("&fragment=1"))
.map_or((path, false), |path| (path, true));
if let Some(number) = path.strip_prefix("/items/") {
let parsed: u64 = number.parse().ok()?;
return (parsed > 0 && parsed.to_string() == number).then_some((Self::Item(parsed), fragment));
}
if let Some(query) = path.strip_prefix("/board?") {
return Some((Self::BoardQuery(Query::parse(query)?), fragment));
}
Expand All @@ -71,7 +77,7 @@ impl Page {

pub(super) fn navigation(self) -> String {
let mut html = String::from("<nav class=tabs aria-label=Main>");
let selected = if matches!(self, Self::BoardQuery(_)) {
let selected = if matches!(self, Self::BoardQuery(_) | Self::Item(_)) {
Self::Board
} else {
self
Expand Down
1 change: 1 addition & 0 deletions oxa/oxa-cli/src/lead_page/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ section{padding:18px 0;scroll-margin-top:88px;border-top:1px solid var(--line)}
#attention{padding:16px;border:0;border-radius:var(--radius);background:var(--warn-soft);margin-bottom:18px}
#attention h2{color:var(--warn)}ul{margin:8px 0;padding-left:22px}li{margin:8px 0;overflow-wrap:anywhere}
li a,summary{display:inline-flex;align-items:center;min-height:44px}
td>a,p>a{display:inline-flex;align-items:center;min-height:44px}
.pages{display:flex;gap:16px}.pages a{display:inline-flex;align-items:center;min-height:44px}
.filters{display:flex;gap:8px;overflow:auto;padding:8px 0}.filters>*{display:inline-flex;align-items:center;min-height:44px;white-space:nowrap;padding:8px;border-radius:8px;background:var(--raised)}
.filters a[aria-current=page]{color:var(--accent);background:var(--accent-soft)}
Expand Down
35 changes: 35 additions & 0 deletions oxa/oxa-cli/tests/lead_serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,41 @@ fn real_server_is_user_enabled_authorized_and_rereads_private_board() {
"{query}"
);
}
let record = serde_json::json!({"schema_version":1,"observed_at":10,"board":{
"observed_at":10,"entries":[{"number":17,"head":"private-head-marker",
"release_pinned":true,"action":"fix_findings","lease":null,
"attempts_today":2,"eligible":false}]}});
std::fs::write(&sample, format!("{record}\n")).unwrap();
assert!(get(port, "/board", &authority, "").contains("href=/items/17"));
for path in ["/items/17", "/items/17?fragment=1"] {
let response = get(port, path, &authority, "");
assert_eq!(response.lines().next(), Some("HTTP/1.1 200 OK"), "{path}");
for text in [
"Item #17",
"Fix findings",
"Release",
"Unleased",
"2",
"aria-current=page>Board",
] {
assert!(response.contains(text), "{text}");
}
assert!(!response.contains("private-head-marker"));
assert!(get(port, path, "attacker.invalid", "").starts_with("HTTP/1.1 403"));
}
assert!(get(port, "/items/18", &authority, "").contains("Item unavailable"));
for path in [
"/items/0",
"/items/01",
"/items/-1",
"/items/18446744073709551616",
"/items/17/x",
] {
assert!(
get(port, path, &authority, "").starts_with("HTTP/1.1 404"),
"{path}"
);
}
assert!(get(port, "/", "attacker.invalid", "").starts_with("HTTP/1.1 403"));
assert!(get(
port,
Expand Down
Loading