From 3b4420c05b8d63d94e3451579b8c19e269f7ad9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nordstr=C3=B6m?= <13300531+n0rpan@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:15:31 +0000 Subject: [PATCH 1/8] Add bounded lead fact cards over typed runner snapshots --- oxa/oxa-cli/src/lead/cards.rs | 157 ++++++++++++++++++++++++++++++++ oxa/oxa-cli/src/lead/mod.rs | 2 + oxa/oxa-cli/src/lib.rs | 1 + oxa/oxa-cli/tests/lead_cards.rs | 91 ++++++++++++++++++ 4 files changed, 251 insertions(+) create mode 100644 oxa/oxa-cli/src/lead/cards.rs create mode 100644 oxa/oxa-cli/src/lead/mod.rs create mode 100644 oxa/oxa-cli/tests/lead_cards.rs diff --git a/oxa/oxa-cli/src/lead/cards.rs b/oxa/oxa-cli/src/lead/cards.rs new file mode 100644 index 000000000..28edfbb1b --- /dev/null +++ b/oxa/oxa-cli/src/lead/cards.rs @@ -0,0 +1,157 @@ +//! Bounded, deterministic cards for the lead commands. Callers fetch the situation +//! through the runner API; this module never reads files or reconstructs logs. +use oxa_proto::work::{Snapshot, Subject}; + +/// A successfully decoded snapshot is still an observation at its sequence, not a +/// fresh assertion about the machine. The caller supplies its freshness policy. +pub struct Cards { + snapshot: Snapshot, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Unavailable { + Invalid, + Stale, + Future, +} + +impl Cards { + /// Command routing is deterministic and consumes no model turn. Mutations + /// are deliberately absent until the standing API is wired. + pub fn command(&self, command: &str) -> Option { + match command.trim() { + "/status" => Some(self.status()), + "/asks" => Some(self.asks()), + _ => None, + } + } + + pub fn decode(bytes: &[u8], now_ms: u64, max_age_ms: u64) -> Result { + let snapshot = Snapshot::from_json(bytes).map_err(|_| Unavailable::Invalid)?; + let age = now_ms.checked_sub(snapshot.at_ms).ok_or(Unavailable::Future)?; + if age > max_age_ms { + return Err(Unavailable::Stale); + } + Ok(Self { snapshot }) + } + + fn source(&self) -> String { + let s = &self.snapshot; + format!( + "Runner observation: seq {} · standing {} · at {} ms", + s.as_of_seq, s.standing_revision, s.at_ms + ) + } + + /// At most 12 physical lines, source included. No queue or hold fact exists in + /// the current Snapshot type, so neither is inferred from blocks or chat. + pub fn status(&self) -> String { + let s = &self.snapshot; + let mut lines = vec![ + self.source(), + format!( + "Goal: {}", + s.goal + .as_deref() + .map(field) + .unwrap_or_else(|| "unavailable".into()) + ), + format!( + "Running: {} · locally accepted: {} · published: {} · merged: {}", + s.running.len(), + s.local_accepted.len(), + s.published.len(), + s.landed.len() + ), + format!( + "Blocked: {} · asks: {} · incidents: {}", + s.blocked.len(), + s.asks.len(), + s.incidents.len() + ), + "Queue / holds / external validation: unavailable in this snapshot".into(), + ]; + for task in s.running.iter().take(2) { + lines.push(format!( + "Running {} on {} · {}", + field(&task.task), + field(&task.host), + field(&task.branch) + )); + } + if s.running.len() > 2 { + lines.push(format!("{} more running tasks", s.running.len() - 2)); + } + if let Some(block) = s.blocked.first() { + lines.push(format!( + "Block: {} · {}", + subject(&block.subject), + field(&block.code) + )); + } + if let Some(ask) = s.asks.first() { + lines.push(format!("Ask {}: {}", field(&ask.id), field(&ask.question))); + } + if s.history_truncated { + lines.push("Terminal / incident history shortened by runner".into()); + } + lines.join("\n") + } + + /// One item at a time. Missing decision metadata is explicit, never invented + /// from the question. This renderer grants no permission to resolve an ask. + pub fn asks(&self) -> String { + let s = &self.snapshot; + let mut lines = vec![self.source()]; + if let Some(ask) = s.asks.first() { + lines.extend([ + format!("Ask {} · {}", field(&ask.id), subject(&ask.subject)), + format!("Question: {}", field(&ask.question)), + "Options / recommendation / meanwhile: unavailable in current facts".into(), + "Ask revision: unavailable; decision write disabled".into(), + format!("{} other open asks", s.asks.len() - 1), + ]); + } else { + lines.push("No open asks in this runner observation".into()); + } + lines.join("\n") + } +} + +/// No raw error or rejected input is reflected into the terminal. +pub fn unavailable(reason: Unavailable) -> &'static str { + match reason { + Unavailable::Invalid => "Runner facts unavailable: missing or invalid situation; status unknown", + Unavailable::Stale => "Runner facts unavailable: stale situation; status unknown", + Unavailable::Future => "Runner facts unavailable: observation clock is ahead; status unknown", + } +} + +fn subject(value: &Subject) -> String { + match value { + Subject::Repository => "repository".into(), + Subject::Task(id) => format!("task {}", field(id)), + Subject::PullRequest(number) => format!("PR #{number}"), + Subject::Host(id) => format!("host {}", field(id)), + Subject::Inbox(id) => format!("inbox {}", field(id)), + } +} + +// Bounded single-line terminal text even when typed fixtures bypass the decoder. +// Escape controls and bidi formatting; truncate by characters, not UTF-8 bytes. +fn field(value: &str) -> String { + let mut out = String::new(); + for ch in value.chars().take(160) { + if ch.is_control() + || matches!(ch, '\u{2028}' | '\u{2029}' | '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}') + { + out.extend(ch.escape_unicode()); + } else { + out.push(ch); + } + } + if value.chars().count() > 160 { + out.push('…'); + } + out +} diff --git a/oxa/oxa-cli/src/lead/mod.rs b/oxa/oxa-cli/src/lead/mod.rs new file mode 100644 index 000000000..8ea5fe155 --- /dev/null +++ b/oxa/oxa-cli/src/lead/mod.rs @@ -0,0 +1,2 @@ +//! Lead presentation over runner-independent typed facts. No state reads or writes. +pub mod cards; diff --git a/oxa/oxa-cli/src/lib.rs b/oxa/oxa-cli/src/lib.rs index b41be1ee3..cbcbc3bcf 100644 --- a/oxa/oxa-cli/src/lib.rs +++ b/oxa/oxa-cli/src/lib.rs @@ -25,6 +25,7 @@ mod home_cwd; mod hooks; mod identity_cmd; mod in_process; +pub mod lead; mod limits; mod mcp_cmd; mod netguard; diff --git a/oxa/oxa-cli/tests/lead_cards.rs b/oxa/oxa-cli/tests/lead_cards.rs new file mode 100644 index 000000000..250b28ebd --- /dev/null +++ b/oxa/oxa-cli/tests/lead_cards.rs @@ -0,0 +1,91 @@ +use oxa_cli::lead::cards::{unavailable, Cards, Unavailable}; +use oxa_proto::work::{Ask, Blocked, Running, Snapshot, Subject}; + +fn snapshot() -> Snapshot { + Snapshot { + as_of_seq: 18, + at_ms: 1000, + standing_revision: 4, + goal: Some("Ship a tested change".into()), + running: Vec::new(), + local_accepted: Vec::new(), + published: Vec::new(), + landed: Vec::new(), + blocked: Vec::new(), + asks: Vec::new(), + incidents: Vec::new(), + history_truncated: false, + } +} + +#[test] +fn crowded_card_keeps_source_and_counts_within_twelve_lines() { + let mut s = snapshot(); + for n in 0..40 { + s.running.push(Running { + task: format!("task-{n}"), + host: "helper".into(), + branch: "feature".into(), + worktree: "worktree".into(), + session_id: None, + }); + } + s.blocked.push(Blocked { + subject: Subject::PullRequest(7), + code: "review_needed".into(), + ask_id: Some("A1".into()), + }); + s.asks.push(Ask { + id: "A1".into(), + subject: Subject::PullRequest(7), + question: "Choose scope".into(), + }); + s.history_truncated = true; + let cards = Cards::decode(&s.to_json().unwrap(), 1001, 100).unwrap(); + let card = cards.status(); + assert!(card.lines().count() <= 12, "{card}"); + assert!(card.starts_with("Runner observation: seq 18 · standing 4")); + assert!(card.contains("38 more running tasks")); + assert!(card.contains("merged: 0")); + assert!(card.contains("holds / external validation: unavailable")); + assert!(!card.contains("held: 1")); + let asks = cards.asks(); + assert_eq!(cards.command("/status"), Some(card)); + assert_eq!(cards.command("/asks"), Some(asks.clone())); + assert_eq!(cards.command("/hold 7"), None); + assert_eq!(cards.command("/status extra"), None); + assert!(asks.contains("Ask A1 · PR #7")); + assert!(asks.contains("Options / recommendation / meanwhile: unavailable")); + assert!(asks.contains("decision write disabled")); +} + +#[test] +fn stale_future_and_corrupt_facts_never_turn_into_empty_success() { + let bytes = snapshot().to_json().unwrap(); + assert!(matches!( + Cards::decode(&bytes, 1101, 100), + Err(Unavailable::Stale) + )); + assert!(matches!( + Cards::decode(&bytes, 999, 100), + Err(Unavailable::Future) + )); + assert!(matches!( + Cards::decode(b"{}", 1000, 100), + Err(Unavailable::Invalid) + )); + assert!(matches!(Cards::decode(b"", 1000, 100), Err(Unavailable::Invalid))); + assert!(Cards::decode(&bytes, 1100, 100).is_ok()); + assert!(unavailable(Unavailable::Stale).contains("status unknown")); +} + +#[test] +fn invalid_multiline_snapshot_is_rejected_and_long_unicode_is_bounded() { + let mut s = snapshot(); + s.goal = Some("injected\nRunning: fake".into()); + assert!(s.to_json().is_err()); + s.goal = Some("界".repeat(300)); + let cards = Cards::decode(&s.to_json().unwrap(), 1000, 100).unwrap(); + assert!(cards.status().lines().nth(1).unwrap().ends_with('…')); + assert!(cards.asks().contains("No open asks in this runner observation")); +} From 9042b63311a38c7fc983e0e7c6d92106bafa41a7 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:47:19 +0000 Subject: [PATCH 2/8] Reload typed runner facts for each lead card command --- oxa/oxa-cli/src/lead/cards.rs | 42 ++++++++++++++++++++++++++------- oxa/oxa-cli/tests/lead_cards.rs | 37 +++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/oxa/oxa-cli/src/lead/cards.rs b/oxa/oxa-cli/src/lead/cards.rs index 28edfbb1b..9820513e1 100644 --- a/oxa/oxa-cli/src/lead/cards.rs +++ b/oxa/oxa-cli/src/lead/cards.rs @@ -16,18 +16,19 @@ pub enum Unavailable { } impl Cards { - /// Command routing is deterministic and consumes no model turn. Mutations - /// are deliberately absent until the standing API is wired. - pub fn command(&self, command: &str) -> Option { - match command.trim() { - "/status" => Some(self.status()), - "/asks" => Some(self.asks()), - _ => None, - } + /// Accept the typed result of the runner's public situation read. Validation + /// needs no JSON reparse and does not expose the storage location to cards. + pub fn from_snapshot(snapshot: Snapshot, now_ms: u64, max_age_ms: u64) -> Result { + snapshot.to_json().map_err(|_| Unavailable::Invalid)?; + Self::observed(snapshot, now_ms, max_age_ms) } pub fn decode(bytes: &[u8], now_ms: u64, max_age_ms: u64) -> Result { let snapshot = Snapshot::from_json(bytes).map_err(|_| Unavailable::Invalid)?; + Self::observed(snapshot, now_ms, max_age_ms) + } + + fn observed(snapshot: Snapshot, now_ms: u64, max_age_ms: u64) -> Result { let age = now_ms.checked_sub(snapshot.at_ms).ok_or(Unavailable::Future)?; if age > max_age_ms { return Err(Unavailable::Stale); @@ -118,6 +119,31 @@ impl Cards { } } +/// Fetch a fresh typed observation for each supported command. The lead adapter +/// supplies `|| facts.situation()`; no model, private file or log read is involved. +/// Unknown commands never invoke the reader. Storage errors stay opaque. +pub fn command( + command: &str, + now_ms: u64, + max_age_ms: u64, + read: impl FnOnce() -> Result, +) -> Option { + let render = match command.trim() { + "/status" => Cards::status, + "/asks" => Cards::asks, + _ => return None, + }; + Some( + match read() + .map_err(|_| Unavailable::Invalid) + .and_then(|s| Cards::from_snapshot(s, now_ms, max_age_ms)) + { + Ok(cards) => render(&cards), + Err(reason) => unavailable(reason).to_owned(), + }, + ) +} + /// No raw error or rejected input is reflected into the terminal. pub fn unavailable(reason: Unavailable) -> &'static str { match reason { diff --git a/oxa/oxa-cli/tests/lead_cards.rs b/oxa/oxa-cli/tests/lead_cards.rs index 250b28ebd..f20c2c040 100644 --- a/oxa/oxa-cli/tests/lead_cards.rs +++ b/oxa/oxa-cli/tests/lead_cards.rs @@ -1,4 +1,4 @@ -use oxa_cli::lead::cards::{unavailable, Cards, Unavailable}; +use oxa_cli::lead::cards::{command, unavailable, Cards, Unavailable}; use oxa_proto::work::{Ask, Blocked, Running, Snapshot, Subject}; fn snapshot() -> Snapshot { @@ -50,15 +50,42 @@ fn crowded_card_keeps_source_and_counts_within_twelve_lines() { assert!(card.contains("holds / external validation: unavailable")); assert!(!card.contains("held: 1")); let asks = cards.asks(); - assert_eq!(cards.command("/status"), Some(card)); - assert_eq!(cards.command("/asks"), Some(asks.clone())); - assert_eq!(cards.command("/hold 7"), None); - assert_eq!(cards.command("/status extra"), None); assert!(asks.contains("Ask A1 · PR #7")); assert!(asks.contains("Options / recommendation / meanwhile: unavailable")); assert!(asks.contains("decision write disabled")); } +#[test] +fn commands_fetch_current_typed_facts_and_never_route_mutations() { + let reads = std::cell::Cell::new(0); + let read = || { + reads.set(reads.get() + 1); + let mut s = snapshot(); + s.as_of_seq = reads.get(); + Ok::<_, ()>(s) + }; + assert!(command("/status", 1000, 100, read).unwrap().contains("seq 1 ·")); + assert!(command("/asks", 1000, 100, read).unwrap().contains("seq 2 ·")); + assert_eq!(reads.get(), 2); + for unknown in ["/hold 7", "/status extra", "/approve 7", "/decide A1 yes"] { + assert_eq!(command(unknown, 1000, 100, read), None); + } + assert_eq!(reads.get(), 2); + let missing = command("/status", 1000, 100, || Err::("private diagnostic")); + assert_eq!(missing.as_deref(), Some(unavailable(Unavailable::Invalid))); + assert!(!missing.unwrap().contains("private diagnostic")); + assert_eq!( + command("/asks", 1101, 100, || Ok::<_, ()>(snapshot())).as_deref(), + Some(unavailable(Unavailable::Stale)) + ); + let mut invalid = snapshot(); + invalid.goal = Some("injected\nstatus".into()); + assert!(matches!( + Cards::from_snapshot(invalid, 1000, 100), + Err(Unavailable::Invalid) + )); +} + #[test] fn stale_future_and_corrupt_facts_never_turn_into_empty_success() { let bytes = snapshot().to_json().unwrap(); From bb367eb8cda08a4ea9644d45f641614dd3372cf0 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:01:24 +0100 Subject: [PATCH 3/8] Keep unavailable standing revisions explicit in lead cards --- oxa/oxa-cli/src/lead/cards.rs | 9 +++++++-- oxa/oxa-cli/tests/lead_cards.rs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/oxa/oxa-cli/src/lead/cards.rs b/oxa/oxa-cli/src/lead/cards.rs index 9820513e1..c44741690 100644 --- a/oxa/oxa-cli/src/lead/cards.rs +++ b/oxa/oxa-cli/src/lead/cards.rs @@ -38,9 +38,14 @@ impl Cards { fn source(&self) -> String { let s = &self.snapshot; + let standing = if s.standing_revision == 0 { + "unavailable".to_owned() + } else { + s.standing_revision.to_string() + }; format!( - "Runner observation: seq {} · standing {} · at {} ms", - s.as_of_seq, s.standing_revision, s.at_ms + "Runner observation: seq {} · standing {standing} · at {} ms", + s.as_of_seq, s.at_ms ) } diff --git a/oxa/oxa-cli/tests/lead_cards.rs b/oxa/oxa-cli/tests/lead_cards.rs index f20c2c040..45dd544d3 100644 --- a/oxa/oxa-cli/tests/lead_cards.rs +++ b/oxa/oxa-cli/tests/lead_cards.rs @@ -18,6 +18,20 @@ fn snapshot() -> Snapshot { } } +#[test] +fn absent_standing_revision_stays_unavailable() { + let mut observation = snapshot(); + observation.standing_revision = 0; + let cards = Cards::from_snapshot(observation, 1000, 100).unwrap(); + for card in [cards.status(), cards.asks()] { + assert!( + card.lines().next().unwrap().contains("standing unavailable"), + "{card}" + ); + assert!(!card.contains("standing 0")); + } +} + #[test] fn crowded_card_keeps_source_and_counts_within_twelve_lines() { let mut s = snapshot(); From c5170cbd33c45f3930c0cd6f210bab32b8a55236 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:06:52 +0100 Subject: [PATCH 4/8] test(lead): cover directional marks in typed cards --- oxa/oxa-cli/tests/lead_cards.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/oxa/oxa-cli/tests/lead_cards.rs b/oxa/oxa-cli/tests/lead_cards.rs index 45dd544d3..dbb3c2ba2 100644 --- a/oxa/oxa-cli/tests/lead_cards.rs +++ b/oxa/oxa-cli/tests/lead_cards.rs @@ -130,3 +130,22 @@ fn invalid_multiline_snapshot_is_rejected_and_long_unicode_is_bounded() { assert!(cards.status().lines().nth(1).unwrap().ends_with('…')); assert!(cards.asks().contains("No open asks in this runner observation")); } + +#[test] +fn accepted_directional_marks_are_escaped_in_goal_and_ask_cards() { + let mut observation = snapshot(); + let text = "before\u{061c}\u{200e}\u{200f}after"; + observation.goal = Some(text.into()); + observation.asks.push(Ask { + id: "A1".into(), + subject: Subject::Repository, + question: text.into(), + }); + let cards = Cards::decode(&observation.to_json().unwrap(), 1000, 100).unwrap(); + for output in [cards.status(), cards.asks()] { + assert!(output.contains(r"before\u{61c}\u{200e}\u{200f}after")); + assert!(!output + .chars() + .any(|ch| matches!(ch, '\u{061c}' | '\u{200e}' | '\u{200f}'))); + } +} From 3f193e9b435bb76fac4ee60371eb5976de8cdab7 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:16:55 +0100 Subject: [PATCH 5/8] fix(lead): escape all directional marks in typed cards --- oxa/oxa-cli/src/lead/cards.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oxa/oxa-cli/src/lead/cards.rs b/oxa/oxa-cli/src/lead/cards.rs index c44741690..422d46312 100644 --- a/oxa/oxa-cli/src/lead/cards.rs +++ b/oxa/oxa-cli/src/lead/cards.rs @@ -174,7 +174,7 @@ fn field(value: &str) -> String { let mut out = String::new(); for ch in value.chars().take(160) { if ch.is_control() - || matches!(ch, '\u{2028}' | '\u{2029}' | '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}') + || matches!(ch, '\u{061c}' | '\u{200e}' | '\u{200f}' | '\u{2028}' | '\u{2029}' | '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}') { out.extend(ch.escape_unicode()); } else { From 96a6af35bb6dc4c0f2a48eef5741c00917dec98f Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:05:03 +0100 Subject: [PATCH 6/8] test(lead): follow the Running step field in lead card fixtures Main's typed situation fact now carries `Running::step`, so the lead card fixtures no longer compiled: `Running` was still built with the previous field set, which broke the oxa-cli test target and the all-targets clippy job. Add the field with an in-progress step; no assertion changes. Fold the control/bidi glyph check into one helper as well, so every line stays inside the workspace rustfmt width. The escaped set is unchanged. --- oxa/oxa-cli/src/lead/cards.rs | 12 +++++++++--- oxa/oxa-cli/tests/lead_cards.rs | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/oxa/oxa-cli/src/lead/cards.rs b/oxa/oxa-cli/src/lead/cards.rs index 422d46312..f297d14b1 100644 --- a/oxa/oxa-cli/src/lead/cards.rs +++ b/oxa/oxa-cli/src/lead/cards.rs @@ -173,9 +173,7 @@ fn subject(value: &Subject) -> String { fn field(value: &str) -> String { let mut out = String::new(); for ch in value.chars().take(160) { - if ch.is_control() - || matches!(ch, '\u{061c}' | '\u{200e}' | '\u{200f}' | '\u{2028}' | '\u{2029}' | '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}') - { + if unsafe_glyph(ch) { out.extend(ch.escape_unicode()); } else { out.push(ch); @@ -186,3 +184,11 @@ fn field(value: &str) -> String { } out } + +// Controls and bidi formatting change how one terminal line is displayed. +fn unsafe_glyph(ch: char) -> bool { + let marks = matches!(ch, '\u{061c}' | '\u{200e}' | '\u{200f}'); + let overrides = ('\u{202a}'..='\u{202e}').contains(&ch); + let isolates = ('\u{2066}'..='\u{2069}').contains(&ch); + ch.is_control() || marks || overrides || isolates || matches!(ch, '\u{2028}' | '\u{2029}') +} diff --git a/oxa/oxa-cli/tests/lead_cards.rs b/oxa/oxa-cli/tests/lead_cards.rs index dbb3c2ba2..faaaece98 100644 --- a/oxa/oxa-cli/tests/lead_cards.rs +++ b/oxa/oxa-cli/tests/lead_cards.rs @@ -1,5 +1,5 @@ use oxa_cli::lead::cards::{command, unavailable, Cards, Unavailable}; -use oxa_proto::work::{Ask, Blocked, Running, Snapshot, Subject}; +use oxa_proto::work::{Ask, Blocked, Running, Snapshot, Subject, TaskStep}; fn snapshot() -> Snapshot { Snapshot { @@ -42,6 +42,7 @@ fn crowded_card_keeps_source_and_counts_within_twelve_lines() { branch: "feature".into(), worktree: "worktree".into(), session_id: None, + step: TaskStep::Preparing, }); } s.blocked.push(Blocked { From 244ca4a84d6cd4ca44b5008903a4670097b44e89 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:19:21 +0100 Subject: [PATCH 7/8] test(lead): supply the current typed running step --- oxa/oxa-cli/tests/lead_cards.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/oxa/oxa-cli/tests/lead_cards.rs b/oxa/oxa-cli/tests/lead_cards.rs index dbb3c2ba2..a13664d23 100644 --- a/oxa/oxa-cli/tests/lead_cards.rs +++ b/oxa/oxa-cli/tests/lead_cards.rs @@ -42,6 +42,7 @@ fn crowded_card_keeps_source_and_counts_within_twelve_lines() { branch: "feature".into(), worktree: "worktree".into(), session_id: None, + step: oxa_proto::work::TaskStep::Worker, }); } s.blocked.push(Blocked { From b877b8a942971e02b88eec4aa7f10cf313225f48 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:19:37 +0100 Subject: [PATCH 8/8] test(lead): compose status and asks with the public facts store --- oxa/oxa-cli/tests/lead_storage.rs | 125 ++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 oxa/oxa-cli/tests/lead_storage.rs diff --git a/oxa/oxa-cli/tests/lead_storage.rs b/oxa/oxa-cli/tests/lead_storage.rs new file mode 100644 index 000000000..d4e909f62 --- /dev/null +++ b/oxa/oxa-cli/tests/lead_storage.rs @@ -0,0 +1,125 @@ +//! Compose the lead cards with the runner's public facts store. +use oxa_cli::lead::cards::command; +use oxa_fake::TestEnv; +use oxa_proto::work::{ + Ask, AskClosed, Blocked, Checkpoint, Evidence, EvidenceKind, Fact, Landed, LocalAcceptance, Publication, + PullRequest, Running, Subject, TaskStep, +}; +use oxa_work::events::Facts; + +#[test] +fn missing_public_store_stays_unknown_without_initialization() { + let env = TestEnv::new(); + let root = env.root().join("absent-facts"); + for name in ["/status", "/asks"] { + let card = command(name, 1000, 100, || Facts::open(&root)?.situation()).unwrap(); + assert!(card.contains("status unknown")); + assert!(!root.exists()); + } +} + +#[test] +fn commands_read_fresh_public_storage_and_keep_acceptance_distinct_from_landing() { + let env = TestEnv::new(); + let facts = Facts::initialize(&env.root().join("facts")).unwrap(); + let head = "1".repeat(40); + let observations = [ + Fact::TaskStarted(Running { + task: "task-1".into(), + host: "helper".into(), + branch: "agent/task-1".into(), + worktree: "~/project/task-1".into(), + session_id: None, + step: TaskStep::Preparing, + }), + Fact::LocalAcceptance(LocalAcceptance { + task: "task-1".into(), + commit: head.clone(), + evidence: Evidence { + kind: EvidenceKind::LocalCheck, + id: "checks-1".into(), + }, + }), + Fact::Blocked(Blocked { + subject: Subject::PullRequest(7), + code: "needs_review".into(), + ask_id: Some("ask-1".into()), + }), + Fact::AskOpened(Ask { + id: "ask-1".into(), + subject: Subject::PullRequest(7), + question: "Choose scope".into(), + }), + ]; + for (index, fact) in observations.into_iter().enumerate() { + facts + .append( + Checkpoint { + source: "fixture".into(), + revision: index as u64 + 1, + }, + 1000, + fact, + ) + .unwrap(); + } + let status = command("/status", 1000, 100, || facts.situation()).unwrap(); + assert!(status.contains("seq 4 ·")); + assert!(status.contains("standing unavailable")); + assert!(status.contains("Running: 1 · locally accepted: 1 · published: 0 · merged: 0")); + assert!(status.contains("Queue / holds / external validation: unavailable")); + assert!(status.contains("Block: PR #7 · needs_review")); + assert!(status.lines().count() <= 12); + let asks = command("/asks", 1000, 100, || facts.situation()).unwrap(); + assert!(asks.contains("Ask ask-1 · PR #7")); + facts + .append( + Checkpoint { + source: "fixture".into(), + revision: 5, + }, + 1001, + Fact::AskClosed(AskClosed { id: "ask-1".into() }), + ) + .unwrap(); + let next = command("/asks", 1001, 100, || facts.situation()).unwrap(); + assert!(next.contains("seq 5 ·")); + assert!(next.contains("No open asks")); + let pr = PullRequest { + number: 7, + head: head.clone(), + }; + facts + .append( + Checkpoint { + source: "fixture".into(), + revision: 6, + }, + 1002, + Fact::Published(Publication { + task: "task-1".into(), + pr: pr.clone(), + }), + ) + .unwrap(); + let published = command("/status", 1002, 100, || facts.situation()).unwrap(); + assert!(published.contains("seq 6 ·")); + assert!(published.contains("locally accepted: 1 · published: 1 · merged: 0")); + facts + .append( + Checkpoint { + source: "fixture".into(), + revision: 7, + }, + 1003, + Fact::PrMerged(Landed { + pr, + merge_commit: head, + merged_at_ms: 1003, + }), + ) + .unwrap(); + let landed = command("/status", 1003, 100, || facts.situation()).unwrap(); + assert!(landed.contains("seq 7 ·")); + assert!(landed.contains("locally accepted: 0 · published: 0 · merged: 1")); +}