Initial public release
Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
280
crates/luxe-tui/src/fixture/auth.rs
Normal file
280
crates/luxe-tui/src/fixture/auth.rs
Normal file
@@ -0,0 +1,280 @@
|
||||
//! Auth fixtures — auth doubles with and without providers, their options, and the login wizard
|
||||
//! seeded on a step, all without credentials or network access.
|
||||
|
||||
use crate::app::App;
|
||||
use luxe_core::auth::{AuthMethod, CredentialStatus, ProviderOption};
|
||||
|
||||
fn provider_option(
|
||||
id: &str,
|
||||
name: &str,
|
||||
methods: Vec<AuthMethod>,
|
||||
status: CredentialStatus,
|
||||
note: Option<&str>,
|
||||
) -> ProviderOption {
|
||||
ProviderOption {
|
||||
id: id.to_string(),
|
||||
name: name.to_string(),
|
||||
methods,
|
||||
status,
|
||||
note: note.map(str::to_string),
|
||||
console_url: None,
|
||||
keyless: id == "lmstudio",
|
||||
needs_endpoint: id == "custom",
|
||||
}
|
||||
}
|
||||
|
||||
/// A canned [`luxe_core::auth::AuthService`] for screenshot review.
|
||||
///
|
||||
/// The wizard's provider list is real product content (names, notes, which providers offer a
|
||||
/// subscription), so a fixture has to supply something representative — but it must never touch the
|
||||
/// network or a credential file.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct FixtureAuth;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl luxe_core::auth::AuthService for FixtureAuth {
|
||||
fn providers(&self) -> Vec<luxe_core::auth::ProviderOption> {
|
||||
use luxe_core::auth::{AuthMethod, CredentialKind, CredentialStatus, StoredCredentialInfo};
|
||||
use provider_option as option;
|
||||
vec![
|
||||
option(
|
||||
"openai",
|
||||
"OpenAI",
|
||||
vec![AuthMethod::api_key(Some("sk-… — or set OPENAI_API_KEY".into()))],
|
||||
CredentialStatus::Stored(StoredCredentialInfo {
|
||||
kind: CredentialKind::ApiKey,
|
||||
expires_at_ms: None,
|
||||
account: None,
|
||||
}),
|
||||
None,
|
||||
),
|
||||
option(
|
||||
"openai-codex",
|
||||
"OpenAI Codex (ChatGPT Plus/Pro)",
|
||||
vec![AuthMethod::subscription(
|
||||
"Sign in with ChatGPT",
|
||||
Some("Needs a ChatGPT Plus or Pro plan".into()),
|
||||
)],
|
||||
CredentialStatus::Missing,
|
||||
None,
|
||||
),
|
||||
option(
|
||||
"anthropic",
|
||||
"Anthropic",
|
||||
vec![AuthMethod::api_key(Some("sk-ant-… — or set ANTHROPIC_API_KEY".into()))],
|
||||
CredentialStatus::Env("ANTHROPIC_API_KEY".into()),
|
||||
Some(
|
||||
"API key only. Anthropic's terms forbid using a Claude Pro/Max subscription \
|
||||
from a third-party harness, so Luxe does not offer that sign-in.",
|
||||
),
|
||||
),
|
||||
option(
|
||||
"github-copilot",
|
||||
"GitHub Copilot",
|
||||
vec![AuthMethod::subscription(
|
||||
"Sign in with GitHub",
|
||||
Some("Needs a Copilot subscription; supports GitHub Enterprise".into()),
|
||||
)],
|
||||
CredentialStatus::Missing,
|
||||
None,
|
||||
),
|
||||
option(
|
||||
"openrouter",
|
||||
"OpenRouter",
|
||||
vec![
|
||||
AuthMethod::subscription(
|
||||
"Sign in with OpenRouter",
|
||||
Some("Creates an API key you own, billed from OpenRouter credits".into()),
|
||||
),
|
||||
AuthMethod::api_key(Some("sk-or-… — or set OPENROUTER_API_KEY".into())),
|
||||
],
|
||||
CredentialStatus::Missing,
|
||||
None,
|
||||
),
|
||||
option(
|
||||
"lmstudio",
|
||||
"LM Studio (local)",
|
||||
vec![AuthMethod {
|
||||
id: "local".into(),
|
||||
label: "Connect to the local server".into(),
|
||||
kind: luxe_core::auth::AuthMethodKind::ApiKey,
|
||||
detail: Some("expects http://127.0.0.1:1234/v1".into()),
|
||||
}],
|
||||
CredentialStatus::Missing,
|
||||
None,
|
||||
),
|
||||
option(
|
||||
"custom",
|
||||
"Custom OpenAI-compatible endpoint",
|
||||
vec![AuthMethod::api_key(None)],
|
||||
CredentialStatus::Missing,
|
||||
Some("vLLM, llama.cpp, a proxy, or anything else that speaks /chat/completions"),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
async fn login(
|
||||
&self,
|
||||
provider_id: &str,
|
||||
_method_id: &str,
|
||||
_interaction: std::sync::Arc<dyn luxe_core::auth::AuthInteraction>,
|
||||
) -> Result<luxe_core::auth::LoginOutcome, luxe_core::auth::AuthError> {
|
||||
Err(luxe_core::auth::AuthError::Network(format!(
|
||||
"the fixture never talks to {provider_id}"
|
||||
)))
|
||||
}
|
||||
|
||||
fn logout(&self, _provider_id: &str) -> Result<bool, luxe_core::auth::AuthError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn store_path(&self) -> std::path::PathBuf {
|
||||
std::path::PathBuf::from("~/.config/luxe/auth.json")
|
||||
}
|
||||
}
|
||||
|
||||
/// [`FixtureAuth`] with nothing configured — a first launch, before anything has been set up.
|
||||
///
|
||||
/// A separate service rather than a flag on the other one, because every remaining fixture wants
|
||||
/// the configured list: the status badges are half of what the wizard's provider rows are for.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct UnconfiguredAuth;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl luxe_core::auth::AuthService for UnconfiguredAuth {
|
||||
fn providers(&self) -> Vec<luxe_core::auth::ProviderOption> {
|
||||
FixtureAuth
|
||||
.providers()
|
||||
.into_iter()
|
||||
.map(|option| luxe_core::auth::ProviderOption {
|
||||
status: luxe_core::auth::CredentialStatus::Missing,
|
||||
..option
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn login(
|
||||
&self,
|
||||
provider_id: &str,
|
||||
method_id: &str,
|
||||
interaction: std::sync::Arc<dyn luxe_core::auth::AuthInteraction>,
|
||||
) -> Result<luxe_core::auth::LoginOutcome, luxe_core::auth::AuthError> {
|
||||
FixtureAuth.login(provider_id, method_id, interaction).await
|
||||
}
|
||||
|
||||
fn logout(&self, provider_id: &str) -> Result<bool, luxe_core::auth::AuthError> {
|
||||
FixtureAuth.logout(provider_id)
|
||||
}
|
||||
|
||||
fn store_path(&self) -> std::path::PathBuf {
|
||||
FixtureAuth.store_path()
|
||||
}
|
||||
}
|
||||
|
||||
/// Which login-wizard state a screenshot should capture.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LoginFixture {
|
||||
/// The provider list, as `/login` shows it.
|
||||
Providers,
|
||||
/// The subscription list, as the Configuration surface opens it.
|
||||
Subscription,
|
||||
/// The local-or-custom list, the other end of the same menu.
|
||||
LocalOrCustom,
|
||||
/// A provider that offers more than one way in.
|
||||
Methods,
|
||||
/// An API-key prompt mid-typing.
|
||||
Secret,
|
||||
/// A device-code flow waiting on the user.
|
||||
Device,
|
||||
/// A login that landed, already handed on to the model picker.
|
||||
Done,
|
||||
}
|
||||
|
||||
impl LoginFixture {
|
||||
/// Parse the `LUXE_FIXTURE_OVERLAY` value naming a login state.
|
||||
pub fn parse(raw: &str) -> Option<Self> {
|
||||
match raw {
|
||||
"login" => Some(Self::Providers),
|
||||
"login-subscription" => Some(Self::Subscription),
|
||||
"login-local" => Some(Self::LocalOrCustom),
|
||||
"login-method" => Some(Self::Methods),
|
||||
"login-secret" => Some(Self::Secret),
|
||||
"login-device" => Some(Self::Device),
|
||||
"login-done" => Some(Self::Done),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The list this state opens over.
|
||||
fn scope(self) -> luxe_core::auth::LoginScope {
|
||||
use luxe_core::auth::LoginScope;
|
||||
match self {
|
||||
Self::Subscription => LoginScope::Subscription,
|
||||
Self::LocalOrCustom => LoginScope::LocalOrCustom,
|
||||
_ => LoginScope::Any,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Seed the login wizard into `app` in the requested state.
|
||||
pub fn seed_login_wizard(app: &mut App, which: LoginFixture) {
|
||||
use crate::auth_wizard::{AuthUiMsg, AuthWizardState};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use luxe_core::auth::{AuthEvent, AuthPrompt, AuthService, CredentialKind, LoginOutcome};
|
||||
|
||||
let service = FixtureAuth;
|
||||
let scope = which.scope();
|
||||
let providers = scope.filter(service.providers());
|
||||
let key = |code: KeyCode| KeyEvent::new(code, KeyModifiers::NONE);
|
||||
|
||||
let mut wizard = match which {
|
||||
LoginFixture::Methods => AuthWizardState::open_for(providers, "openrouter", scope),
|
||||
LoginFixture::Secret | LoginFixture::Done => {
|
||||
AuthWizardState::open_for(providers, "openai", scope)
|
||||
}
|
||||
LoginFixture::Device => AuthWizardState::open_for(providers, "github-copilot", scope),
|
||||
LoginFixture::Providers | LoginFixture::Subscription | LoginFixture::LocalOrCustom => {
|
||||
AuthWizardState::open(providers, scope)
|
||||
}
|
||||
};
|
||||
wizard.take_pending_start();
|
||||
|
||||
match which {
|
||||
LoginFixture::Secret => {
|
||||
let (reply, _rx) = tokio::sync::oneshot::channel();
|
||||
wizard.apply(AuthUiMsg::Prompt {
|
||||
prompt: AuthPrompt::secret("OpenAI API key:", Some("sk-…".into())),
|
||||
reply,
|
||||
});
|
||||
for _ in 0..24 {
|
||||
wizard.on_key(&key(KeyCode::Char('x')));
|
||||
}
|
||||
}
|
||||
LoginFixture::Device => {
|
||||
wizard.apply(AuthUiMsg::Event(AuthEvent::DeviceCode {
|
||||
user_code: "WXYZ-9876".into(),
|
||||
verification_uri: "https://github.com/login/device".into(),
|
||||
interval_secs: 5,
|
||||
expires_in_secs: 900,
|
||||
}));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
app.auth_service = Some(std::sync::Arc::new(FixtureAuth));
|
||||
app.overlays.auth_wizard = Some(wizard);
|
||||
|
||||
// Success has no screen of its own: the wizard hands the outcome back and the app walks into
|
||||
// the model picker. Driven through `Msg::Auth` because that is the door the running flow uses
|
||||
// — a fixture that called the wizard directly would not notice the app ignoring the answer.
|
||||
if which == LoginFixture::Done {
|
||||
app.update(crate::app::Msg::Auth(AuthUiMsg::Finished(Ok(LoginOutcome {
|
||||
provider_id: "openai".into(),
|
||||
provider_name: "OpenAI".into(),
|
||||
kind: Some(CredentialKind::ApiKey),
|
||||
account: None,
|
||||
suggested_model: Some("gpt-5.6".into()),
|
||||
notes: vec!["47 models available (gpt-4.1, gpt-5, gpt-5-mini, …)".into()],
|
||||
advice: Vec::new(),
|
||||
}))));
|
||||
}
|
||||
}
|
||||
48
crates/luxe-tui/src/fixture/capture.rs
Normal file
48
crates/luxe-tui/src/fixture/capture.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
//! Fixture capture — the screenshot a tool card shows, drawn rather than loaded.
|
||||
|
||||
/// What the fixture's agent was asked, did, and verified — the brief's raw material.
|
||||
/// The picture the `screenshot` fixture pretends to have captured.
|
||||
///
|
||||
/// Drawn rather than loaded: a fixture that reads a PNG off disk is a fixture that renders
|
||||
/// differently depending on what is in the tree. This is a plausible dev-server page — a header, a
|
||||
/// sidebar, and a column of cards — at a size that exercises real downscaling.
|
||||
pub(super) fn fixture_capture() -> Vec<u8> {
|
||||
const WIDTH: u32 = 1280;
|
||||
const HEIGHT: u32 = 800;
|
||||
let paint = |x: u32, y: u32| -> [u8; 4] {
|
||||
let card = |top: u32, height: u32| y >= top && y < top + height && (300..1200).contains(&x);
|
||||
match () {
|
||||
_ if y < 72 => [24, 28, 44, 255], // header bar
|
||||
_ if y < 80 => [122, 162, 247, 255], // accent underline
|
||||
_ if x < 260 => [30, 34, 52, 255], // sidebar
|
||||
_ if card(140, 180) => [46, 52, 76, 255],
|
||||
_ if card(360, 120) => [46, 52, 76, 255],
|
||||
_ if card(520, 200) => [46, 52, 76, 255],
|
||||
_ => [18, 20, 32, 255], // page background
|
||||
}
|
||||
};
|
||||
let mut pixels = image::RgbaImage::new(WIDTH, HEIGHT);
|
||||
for (x, y, pixel) in pixels.enumerate_pixels_mut() {
|
||||
*pixel = image::Rgba(paint(x, y));
|
||||
}
|
||||
// A few sidebar rows and a title block, so the downscale has edges to resolve.
|
||||
for row in 0..6u32 {
|
||||
let top = 120 + row * 56;
|
||||
for y in top..top + 18 {
|
||||
for x in 40..220 {
|
||||
pixels.put_pixel(x, y, image::Rgba([88, 96, 130, 255]));
|
||||
}
|
||||
}
|
||||
}
|
||||
for y in 140..176 {
|
||||
for x in 330..820 {
|
||||
pixels.put_pixel(x, y, image::Rgba([158, 206, 106, 255]));
|
||||
}
|
||||
}
|
||||
|
||||
let mut png = std::io::Cursor::new(Vec::new());
|
||||
image::DynamicImage::ImageRgba8(pixels)
|
||||
.write_to(&mut png, image::ImageFormat::Png)
|
||||
.expect("the fixture capture encodes");
|
||||
png.into_inner()
|
||||
}
|
||||
41
crates/luxe-tui/src/fixture/chat.rs
Normal file
41
crates/luxe-tui/src/fixture/chat.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
//! Chat fixtures — the transcript surface in each of its states.
|
||||
//!
|
||||
//! Idle, reasoning, streaming, tool cards, questions, images, the two paste/pending states, and
|
||||
//! the guide's pictures.
|
||||
//! Each seeds only what its screenshot is about, so a change to one demo cannot quietly restage
|
||||
//! another.
|
||||
|
||||
mod cards;
|
||||
mod conversation;
|
||||
mod guide;
|
||||
mod tool_run;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Seeds `app` for a chat scenario, reporting whether this family owns it.
|
||||
///
|
||||
/// `Ok(false)` means another family does — the caller tries the next one. An `Err` is a fixture
|
||||
/// that claimed the scenario and then could not build it, which is a bug in the fixture.
|
||||
pub(super) fn seed(app: &mut App, scenario: FixtureScenario) -> Result<bool, String> {
|
||||
match scenario {
|
||||
FixtureScenario::ChatIdle => conversation::seed_idle(app),
|
||||
FixtureScenario::ChatThinking => conversation::seed_thinking(app),
|
||||
FixtureScenario::ChatStreaming => conversation::seed_streaming(app),
|
||||
FixtureScenario::ChatTools => cards::seed_tool_cards(app),
|
||||
FixtureScenario::ChatCardBodies => cards::seed_card_bodies(app)?,
|
||||
FixtureScenario::ChatWideProse => conversation::seed_wide_prose(app),
|
||||
FixtureScenario::ChatToolError => cards::seed_tool_error(app),
|
||||
FixtureScenario::ChatToolRun => tool_run::seed_tool_run(app),
|
||||
FixtureScenario::ChatQuestion => conversation::seed_question(app),
|
||||
FixtureScenario::ChatPlan => conversation::seed_plan(app)?,
|
||||
FixtureScenario::ChatScreenshot => conversation::seed_screenshot(app)?,
|
||||
FixtureScenario::ChatPaste => conversation::seed_paste(app),
|
||||
FixtureScenario::ChatPending => conversation::seed_pending(app),
|
||||
FixtureScenario::ChatTurn => guide::seed_turn(app),
|
||||
FixtureScenario::ChatPermission => guide::seed_permission(app),
|
||||
FixtureScenario::ChatPalette => guide::seed_palette(app),
|
||||
FixtureScenario::ChatPlanReady => guide::seed_plan_ready(app),
|
||||
_ => return Ok(false),
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
325
crates/luxe-tui/src/fixture/chat/cards.rs
Normal file
325
crates/luxe-tui/src/fixture/chat/cards.rs
Normal file
@@ -0,0 +1,325 @@
|
||||
//! Chat card fixtures — tool cards in each of their states, their bodies, and a failed call.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Chat with deterministic structured tool outcomes.
|
||||
pub(super) fn seed_tool_cards(app: &mut App) {
|
||||
let running = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-read",
|
||||
"read",
|
||||
"crates/luxe-tui/src/view.rs",
|
||||
1,
|
||||
);
|
||||
let mut failed =
|
||||
ToolActivity::running("fixture-session", "call-test", "bash", "cargo test -p luxe-tui", 2);
|
||||
failed.revision = 1;
|
||||
failed.state = ToolActivityState::Failed;
|
||||
failed.elapsed_ms = Some(1_240);
|
||||
failed.summary = Some("validation failed".into());
|
||||
failed.input_preview = Some("--workspace --all-targets".into());
|
||||
failed.output_preview = Some("test target failed after compiling luxe-tui".into());
|
||||
app.push_convo(ConvoBlock::Assistant("Checking the focused TUI slice.".into()));
|
||||
for (index, (call_id, path)) in [
|
||||
("call-read-cargo", "Cargo.toml"),
|
||||
("call-read-app", "crates/luxe-tui/src/app.rs"),
|
||||
("call-read-view", "crates/luxe-tui/src/view.rs"),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let mut completed = ToolActivity::running("fixture-session", call_id, "read", path, 1);
|
||||
completed.state = ToolActivityState::Succeeded;
|
||||
completed.summary = Some("Completed".into());
|
||||
// One message asked for all three, which is what folds them into a line.
|
||||
let index = u32::try_from(index).unwrap_or(0) + 1;
|
||||
completed.run = Some(luxe_core::ToolRun { index, total: 3 });
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: completed,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
}
|
||||
// An edit card renders its precise diff inline (colored +/-), independent of expand.
|
||||
let mut edited = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-edit",
|
||||
"edit",
|
||||
"crates/luxe-tui/src/view/dock.rs",
|
||||
1,
|
||||
);
|
||||
edited.state = ToolActivityState::Succeeded;
|
||||
edited.summary = Some("Completed".into());
|
||||
edited.elapsed_ms = Some(6);
|
||||
edited.output_preview = Some(
|
||||
"Applied 1 edit(s) to 'crates/luxe-tui/src/view/dock.rs'\n\n\
|
||||
\u{20} ...\n\
|
||||
\u{20}734 fn section_heading_line(section: DockSection, app: &App) -> Line<'static> {\n\
|
||||
\u{20}735 let styles = &app.theme_styles;\n\
|
||||
-736 let selected = app.dock.focused && app.dock.selected_section == Some(section);\n\
|
||||
+736 let collapsed = section.is_collapsible() && app.dock.collapsed.contains(§ion);\n\
|
||||
\u{20}737 let marker = if collapsed { \"▸\" } else { \"▾\" };\n\
|
||||
\u{20} ..."
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edited,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// A skill card carries the theme's secondary/purple accent as an activation cue.
|
||||
let mut skill =
|
||||
ToolActivity::running("fixture-session", "call-skill", "skill", "frontend-slides", 1);
|
||||
skill.state = ToolActivityState::Succeeded;
|
||||
skill.summary = Some("Completed".into());
|
||||
skill.elapsed_ms = Some(3);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: skill,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: failed,
|
||||
expanded: true,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// The call in flight goes last, because it is the only one there can be: dispatch runs
|
||||
// them one at a time, so every card above a spinner has already landed.
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: running,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// The three reads fold, settled: a finished run is a count and a duration and no meter,
|
||||
// because there is no progress left to report. `chat-tool-run` catches one mid-flight.
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// Chat with the three cards that carry a body: a written file, a side-by-side edit, a heredoc.
|
||||
pub(super) fn seed_card_bodies(app: &mut App) -> Result<(), String> {
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Wiring the card body renderer, then checking it against a real terminal.".into(),
|
||||
));
|
||||
// A body sourced from the call's arguments, exactly as the live projection builds it.
|
||||
let from_arguments = |call_id: &str, tool: &str, arguments: serde_json::Value| {
|
||||
let label = luxe_core::describe_call(tool, &arguments, "/work/luxe");
|
||||
let mut activity = ToolActivity::running("fixture-session", call_id, tool, label, 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
activity.summary = Some("Completed".into());
|
||||
activity.elapsed_ms = Some(4);
|
||||
activity.card_body = luxe_core::tool_card_body(tool, &arguments, "/work/luxe");
|
||||
activity
|
||||
};
|
||||
|
||||
// Long enough that the preview budget bites, so the truncation footer is on screen.
|
||||
let script = "#!/usr/bin/env bash\n\
|
||||
# Renders tool-glyph candidates so they can be eyeballed in a real terminal font.\n\
|
||||
set -euo pipefail\n\
|
||||
\n\
|
||||
row() { printf ' %-14s %s\\n' \"$1\" \"$2\"; }\n\
|
||||
\n\
|
||||
glyph_for() {\n\
|
||||
\u{20} case \"$1\" in\n\
|
||||
\u{20} bash) printf '\\ue760' ;;\n\
|
||||
\u{20} read) printf '\\ue245' ;;\n\
|
||||
\u{20} *) printf '?' ;;\n\
|
||||
\u{20} esac\n\
|
||||
}\n\
|
||||
\n\
|
||||
for name in bash read grep glob git write edit; do\n\
|
||||
\u{20} row \"$name\" \"$(glyph_for \"$name\")\"\n\
|
||||
done\n\
|
||||
echo\n\
|
||||
row \"total\" \"$(wc -l < candidates.txt)\"\n\
|
||||
exit 0\n";
|
||||
let mut write = from_arguments(
|
||||
"call-write",
|
||||
"write",
|
||||
serde_json::json!({"path": "scripts/glyph_sampler.sh", "content": script}),
|
||||
);
|
||||
write.output_preview = Some("Created 'scripts/glyph_sampler.sh' (498 bytes)".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: write,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
// An edit renders its *result*: only the tool knows where the change landed.
|
||||
let mut edited = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-edit",
|
||||
"edit",
|
||||
"crates/luxe-tui/src/view/blocks.rs",
|
||||
1,
|
||||
);
|
||||
edited.state = ToolActivityState::Succeeded;
|
||||
edited.summary = Some("Completed".into());
|
||||
edited.elapsed_ms = Some(6);
|
||||
edited.output_preview = Some(
|
||||
"Applied 1 edit(s) to 'crates/luxe-tui/src/view/blocks.rs'\n\n\
|
||||
\u{20} ...\n\
|
||||
\u{20}128 let summary = activity.summary.as_deref();\n\
|
||||
-129 let is_diff_tool = matches!(activity.name.as_str(), \"edit\" | \"write\");\n\
|
||||
-130 if is_diff_tool && succeeded {\n\
|
||||
+129 let outcome = tool_card::header_summary(activity);\n\
|
||||
+130 if let Some(body) = tool_card::body(item, &ctx.card()) {\n\
|
||||
\u{20}131 lines.extend(body.into_iter().map(indented));\n\
|
||||
\u{20}132 }\n\
|
||||
\u{20} ..."
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edited,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
// A one-line command says everything on its header, so this one has no body.
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: from_arguments(
|
||||
"call-bash-one",
|
||||
"bash",
|
||||
serde_json::json!({"command": "cargo nextest run -p luxe-tui"}),
|
||||
),
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// A search's payload is the angles it covered, not `queries=[6]`.
|
||||
// Six is past the list's own budget, so the fold and its footer are on screen too.
|
||||
let mut searched = from_arguments(
|
||||
"call-web-search",
|
||||
"web_search",
|
||||
serde_json::json!({"queries": [
|
||||
"ratatui paragraph wrapping trailing spans",
|
||||
"terminal cell width unicode east asian",
|
||||
"crossterm mouse capture bracketed paste",
|
||||
"kitty graphics protocol unicode placeholders",
|
||||
"tui scrollback performance large buffers",
|
||||
"ansi truecolor fallback 256 palette",
|
||||
]}),
|
||||
);
|
||||
searched.elapsed_ms = Some(1_512);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: searched,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// A heredoc does not, and must not vanish behind the header's ellipsis.
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: from_arguments(
|
||||
"call-bash-heredoc",
|
||||
"bash",
|
||||
serde_json::json!({"command": "cd /tmp && python3 - <<'PY'\nimport json\nrows = [(\"bash\", \"\\ue760\"), (\"read\", \"\\ue245\")]\nprint(json.dumps(dict(rows), indent=2))\nPY"}),
|
||||
),
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// Described, a chained command is named by what it does, with the command folded to
|
||||
// its first line underneath
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: from_arguments(
|
||||
"call-bash-described",
|
||||
"bash",
|
||||
serde_json::json!({
|
||||
"description": "Check which fixtures still render the old dock",
|
||||
"command": "for f in crates/luxe-tui/examples/*.rs; do\n grep -l 'CHANGES' \"$f\" || true\ndone | sort",
|
||||
}),
|
||||
),
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// A failing suite through the shell reads as its verdict and what failed
|
||||
let mut suite = from_arguments(
|
||||
"call-bash-suite",
|
||||
"bash",
|
||||
serde_json::json!({
|
||||
"description": "Run the forms tests",
|
||||
"command": "cd tests && ../.venv/bin/python runtests.py forms_tests 2>&1",
|
||||
}),
|
||||
);
|
||||
suite.state = ToolActivityState::Failed;
|
||||
suite.output_preview = Some(
|
||||
"unittest: FAILED — 412 passed, 1 failed, 3 skipped\nFailures:\n ✗ test_deepcopy (forms_tests.field_tests.test_base.BasicFieldsTests)"
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: suite,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Chat with an expanded failed tool for error-state review.
|
||||
pub(super) fn seed_tool_error(app: &mut App) {
|
||||
// Two rejections worth recognizing on sight: a guard that fired (nothing was written;
|
||||
// the model has to read first) and an edit whose anchor wasn't unique. Both are
|
||||
// recoverable, and neither may render as a bare glyph plus a duration.
|
||||
let mut guarded = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-edit-guard",
|
||||
"edit",
|
||||
"crates/luxe-core/src/event.rs",
|
||||
1,
|
||||
);
|
||||
guarded.revision = 1;
|
||||
guarded.state = ToolActivityState::Failed;
|
||||
guarded.elapsed_ms = Some(0);
|
||||
guarded.summary = Some("edited before reading the file".into());
|
||||
guarded.input_preview = Some("replace Event::ToolStarted exactly once".into());
|
||||
guarded.output_preview = Some(
|
||||
"Error: read 'crates/luxe-core/src/event.rs' before editing it \
|
||||
(read-before-edit guard). Use the `read` tool first, then retry."
|
||||
.into(),
|
||||
);
|
||||
let mut failed = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-edit-error",
|
||||
"edit",
|
||||
"crates/luxe-core/src/event.rs",
|
||||
1,
|
||||
);
|
||||
failed.revision = 1;
|
||||
failed.state = ToolActivityState::Failed;
|
||||
failed.elapsed_ms = Some(184);
|
||||
// As the projector builds it: the tool's own first line, cut to the card's budget.
|
||||
failed.summary = Some(
|
||||
"edit[0] 'oldText' matched 2 times (must be unique). Add more context to make \
|
||||
it unique."
|
||||
.into(),
|
||||
);
|
||||
failed.input_preview = Some("replace Event::ToolStarted exactly once".into());
|
||||
failed.output_preview = Some(
|
||||
"Error: edit[0] 'oldText' matched 2 times (must be unique). Add more context \
|
||||
to make it unique."
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The focused edit needs a more specific replacement before retrying.".into(),
|
||||
));
|
||||
for activity in [guarded, failed] {
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: true,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
}
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
322
crates/luxe-tui/src/fixture/chat/conversation.rs
Normal file
322
crates/luxe-tui/src/fixture/chat/conversation.rs
Normal file
@@ -0,0 +1,322 @@
|
||||
//! Chat conversation fixtures — idle, reasoning, streaming, wide prose, a question, a plan, a
|
||||
//! screenshot, a paste and pending submissions.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Idle chat with a fixed short exchange.
|
||||
pub(super) fn seed_idle(app: &mut App) {
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Summarize the current project state.".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The project is ready for the next focused increment.".into(),
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
}
|
||||
|
||||
/// Chat showing model reasoning: one expanded and one collapsed thinking block.
|
||||
pub(super) fn seed_thinking(app: &mut App) {
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Refactor the parser to stream tokens instead of buffering.".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
// Shaped like real reasoning: a `**title**` per section, symbols in backticks, and a
|
||||
// bulleted aside — the markdown a GPT model actually emits.
|
||||
app.push_convo(ConvoBlock::Thinking {
|
||||
text: "**Tracing the buffering**\n\nThe buffering happens in `Parser::feed`, \
|
||||
which collects the whole input before yielding.\nI can turn it into an \
|
||||
iterator adapter that emits tokens as bytes arrive, keeping a small carry \
|
||||
buffer for partial tokens.\n\n**Edge cases**\n\n- a multi-byte token split \
|
||||
across two chunks must not be dropped\n- `feed` still has to report a \
|
||||
trailing partial token as an error"
|
||||
.into(),
|
||||
expanded: true,
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"I'll convert `Parser::feed` into a streaming adapter with a carry buffer for \
|
||||
split tokens."
|
||||
.into(),
|
||||
));
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Good. Now add tests for the split-token case.".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Thinking {
|
||||
text: "**Planning the test**\n\nA table-driven test feeding the input one byte at \
|
||||
a time exercises every split boundary in a single case."
|
||||
.into(),
|
||||
expanded: false,
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Added a byte-at-a-time table test covering split-token boundaries.".into(),
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// Chat caught mid-reveal: a streaming answer with its newest characters still fading in.
|
||||
pub(super) fn seed_streaming(app: &mut App) {
|
||||
// Driven through the production reducer so the reveal arms exactly as it does live, then
|
||||
// stepped on a pinned clock: the frame lands mid-sentence, with the fade on the tail.
|
||||
let base = std::time::Instant::now();
|
||||
app.status.frame_clock = Some(base);
|
||||
app.update(Msg::Engine(Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "The provider does not hand text over at the rate it produced it \u{2014} one \
|
||||
measured delivery is a single seventy-five character delta every ~470 ms, \
|
||||
which paints as two visible jumps a second. A reveal cursor paces those \
|
||||
characters back out at the rate the model is actually working at."
|
||||
.into(),
|
||||
}));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.status.state = crate::app::AppState::Streaming;
|
||||
}
|
||||
|
||||
/// Chat with prose, fenced code, and a table for canvas-width review.
|
||||
pub(super) fn seed_wide_prose(app: &mut App) {
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The conversation canvas keeps the implementation discussion readable on a wide terminal, \
|
||||
while preserving a wider surface for code, tables, paths, and other structured details. \
|
||||
This fixture makes both policies visible without relying on a live provider.\n\n\
|
||||
```rust\n\
|
||||
let widths = conversation_canvas_widths(frame.area().width);\n\
|
||||
render_markdown_block(widths.prose_width, widths.wide_width);\n\
|
||||
```\n\n\
|
||||
| Content | Canvas |\n\
|
||||
| --- | --- |\n\
|
||||
| Narrative prose | Readable 100-cell maximum |\n\
|
||||
| Code and details | Wide 140-cell maximum |"
|
||||
.into(),
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// Chat with the interactive question modal open (multi-select + free-text).
|
||||
pub(super) fn seed_question(app: &mut App) {
|
||||
// An earlier decision, as the transcript keeps it: the modal is long gone, so the card
|
||||
// is the only record of what was chosen.
|
||||
let asked = serde_json::json!({
|
||||
"prompt": "Where should the ingest worker live?",
|
||||
"options": [{"label": "its own crate"}, {"label": "inside luxe-core"}],
|
||||
});
|
||||
let mut answered = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-question",
|
||||
"question",
|
||||
luxe_core::describe_call("question", &asked, "/work/luxe"),
|
||||
1,
|
||||
);
|
||||
answered.state = ToolActivityState::Succeeded;
|
||||
answered.summary = Some("Completed".into());
|
||||
answered.elapsed_ms = Some(14_500);
|
||||
answered.input_preview = Some(asked.to_string());
|
||||
answered.output_preview = Some(
|
||||
luxe_core::question::QuestionOutcome::Answered(vec!["its own crate".into()]).result_text(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: answered,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Its own crate it is. Before I scaffold it, which async features do you want?".into(),
|
||||
));
|
||||
app.overlays.question = Some(crate::question_prompt::QuestionPromptState::new(
|
||||
luxe_core::question::QuestionRequestId::new(),
|
||||
"Which async features should I enable?".into(),
|
||||
vec![
|
||||
luxe_core::question::QuestionOption::new("tokio full")
|
||||
.with_description("everything the runtime offers; simplest to start from")
|
||||
.recommended(),
|
||||
luxe_core::question::QuestionOption::new("rustls TLS")
|
||||
.with_description("no OpenSSL to build against"),
|
||||
luxe_core::question::QuestionOption::new("tracing"),
|
||||
],
|
||||
true,
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// Plan mode, mid-interview: the composer and the agent's question in the plan color.
|
||||
pub(super) fn seed_plan(app: &mut App) -> Result<(), String> {
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Add rate limiting to the ingest API.".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The server has no middleware layer yet, so a limiter goes in `router()`. Two \
|
||||
decisions before I write the plan."
|
||||
.into(),
|
||||
));
|
||||
let asked = serde_json::json!({
|
||||
"prompt": "Limit per client, or across the whole service?",
|
||||
"options": [{"label": "per API key"}, {"label": "global"}],
|
||||
});
|
||||
let mut answered = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-question",
|
||||
"question",
|
||||
luxe_core::describe_call("question", &asked, "/work/luxe"),
|
||||
1,
|
||||
);
|
||||
answered.state = ToolActivityState::Succeeded;
|
||||
answered.summary = Some("Completed".into());
|
||||
answered.elapsed_ms = Some(9_000);
|
||||
answered.input_preview = Some(asked.to_string());
|
||||
answered.output_preview = Some(
|
||||
luxe_core::question::QuestionOutcome::Answered(vec!["per API key".into()]).result_text(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: answered,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
app.push_convo(ConvoBlock::Assistant("Per key it is. Last one:".into()));
|
||||
app.overlays.question = Some(crate::question_prompt::QuestionPromptState::new(
|
||||
luxe_core::question::QuestionRequestId::new(),
|
||||
"What should a client over its limit get?".into(),
|
||||
vec![
|
||||
luxe_core::question::QuestionOption::new("429 with Retry-After")
|
||||
.with_description("what clients and proxies already understand")
|
||||
.recommended(),
|
||||
luxe_core::question::QuestionOption::new("Queue the request")
|
||||
.with_description("smoother, but holds memory under load"),
|
||||
],
|
||||
false,
|
||||
));
|
||||
app.status.mode = luxe_core::mode::PLAN.into();
|
||||
app.status.model = "claude-opus-5".into();
|
||||
app.status.provider = "anthropic".into();
|
||||
app.status.thinking = luxe_core::provider::ThinkingLevel::High;
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A `screenshot` card showing its capture inline, at whatever fidelity the terminal has.
|
||||
pub(super) fn seed_screenshot(app: &mut App) -> Result<(), String> {
|
||||
// Prose on both sides of the capture, so the scenario also exercises the thing that is
|
||||
// genuinely hard: scrolling a picture through a viewport that is made of text.
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The header component now reads its spacing from the layout tokens rather than \
|
||||
hard-coded padding, so it should line up with the sidebar at every breakpoint. \
|
||||
Two things worth checking by eye: the accent rule under the bar, and whether the \
|
||||
first card still clears the fold."
|
||||
.into(),
|
||||
));
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Does the dev server render the new header correctly?".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Capturing the page now \u{2014} here is what it looks like.".into(),
|
||||
));
|
||||
let mut captured = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-shot",
|
||||
"screenshot",
|
||||
"mode=url http://localhost:4321",
|
||||
1,
|
||||
);
|
||||
captured.revision = 1;
|
||||
captured.state = ToolActivityState::Succeeded;
|
||||
captured.elapsed_ms = Some(1_820);
|
||||
captured.summary = Some("Completed".into());
|
||||
captured.output_preview = Some(
|
||||
"Captured url via headless browser (1280x800, 143 KB on disk). \
|
||||
Saved: .luxe/screenshots/shot-1762000000000.png"
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: captured,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
let key = crate::graphics::ImageKey::tool_result("fixture-session", "call-shot", 1);
|
||||
app.images.insert(
|
||||
key.clone(),
|
||||
fixture_capture(),
|
||||
crate::graphics::ImageOrigin { label: "screenshot".into(), path: None },
|
||||
);
|
||||
app.tool_images.insert(("fixture-session".into(), "call-shot".into()), vec![key]);
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"That matches the mock: the accent rule sits flush under the bar and the first \
|
||||
card clears the fold with room to spare. The sidebar rows are still using the \
|
||||
old 56px rhythm though \u{2014} they should be 48 to match the cards. Want me to \
|
||||
change that and re-capture?"
|
||||
.into(),
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A submitted message carrying a paste long enough to be previewed.
|
||||
pub(super) fn seed_paste(app: &mut App) {
|
||||
let payload = (1..=32)
|
||||
.map(|line| format!(" log line {line}: connection reset by peer"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: format!("Here is the failing run:\n{payload}"),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"That's the socket dropping mid-IDLE. I'll add a reconnect with backoff.".into(),
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
}
|
||||
|
||||
/// Running turn with mid-turn submissions pinned above the composer.
|
||||
pub(super) fn seed_pending(app: &mut App) {
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Wire the idle watcher into the sync loop.".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Starting with the IMAP IDLE session, then the reconnect path.".into(),
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.status.state = crate::app::AppState::Streaming;
|
||||
app.status.active_tool = Some("read".into());
|
||||
app.status.on_turn_start();
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
app.dock.show();
|
||||
for (delivery, text) in [
|
||||
(MidTurnDelivery::Steer, "also check the reconnect backoff"),
|
||||
(MidTurnDelivery::Queue, "then update the architecture doc"),
|
||||
(MidTurnDelivery::Queue, "and run the full gate"),
|
||||
] {
|
||||
app.hold_submission(crate::app::PendingSubmission {
|
||||
display: text.into(),
|
||||
chips: Vec::new(),
|
||||
attached: Vec::new(),
|
||||
content: text.into(),
|
||||
draft: text.into(),
|
||||
images: Vec::new(),
|
||||
delivery,
|
||||
});
|
||||
}
|
||||
// A review asked for mid-turn waits with them, and says which of the three states it
|
||||
// is in rather than taking the screen.
|
||||
app.review.queued = Some(crate::app::QueuedReview {
|
||||
target: luxe_core::guided_review::ReviewTarget::WorkingTree,
|
||||
state: crate::app::QueuedReviewState::Waiting,
|
||||
});
|
||||
}
|
||||
145
crates/luxe-tui/src/fixture/chat/guide.rs
Normal file
145
crates/luxe-tui/src/fixture/chat/guide.rs
Normal file
@@ -0,0 +1,145 @@
|
||||
//! Guide fixtures — the states the user guide pictures: a finished turn's cards, a permission
|
||||
//! prompt, the Command Palette and the plan handoff.
|
||||
//!
|
||||
//! One small change runs through all four, the `todo overdue` command the site's demos build, so
|
||||
//! the pictures read as one session rather than four unrelated ones.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// What the reader asked for, in every scenario here.
|
||||
const ASK: &str = "add a `todo overdue` command that lists open tasks past their due date, oldest \
|
||||
first, with a test";
|
||||
|
||||
/// A finished turn: the lookups folded, an edit with its diff, the tests, and the reply.
|
||||
pub(super) fn seed_turn(app: &mut App) {
|
||||
push_turn(app);
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Added `todo overdue`. It lists open tasks past their due date, oldest first, through \
|
||||
a new `overdue` in `src/filter.js`, and two tests cover it. All five pass."
|
||||
.into(),
|
||||
));
|
||||
seed_status(app);
|
||||
}
|
||||
|
||||
/// The same turn, stopped on a commit that waits for approval.
|
||||
pub(super) fn seed_permission(app: &mut App) {
|
||||
push_turn(app);
|
||||
app.push_convo(ConvoBlock::Assistant("The suite passes. Committing the change.".into()));
|
||||
app.overlays.permission = Some(
|
||||
crate::permission_prompt::PermissionPromptState::new(
|
||||
luxe_core::permission::PermissionRequestId::new(),
|
||||
"git".into(),
|
||||
"git commit \u{2014} Add a todo overdue command".into(),
|
||||
vec!["git commit*".into()],
|
||||
)
|
||||
.opened(app.frame_now()),
|
||||
);
|
||||
seed_status(app);
|
||||
}
|
||||
|
||||
/// The Command Palette open over the conversation, with the commands used last at the top.
|
||||
pub(super) fn seed_palette(app: &mut App) {
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
push_turn(app);
|
||||
for id in [crate::commands::id::MODEL, crate::commands::id::DIFF, crate::commands::id::COST] {
|
||||
app.recent_commands.record(id);
|
||||
}
|
||||
seed_status(app);
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('k'), KeyModifiers::CONTROL)));
|
||||
}
|
||||
|
||||
/// Plan mode's plan written, and the question of what to do with it.
|
||||
pub(super) fn seed_plan_ready(app: &mut App) {
|
||||
app.status.mode = luxe_core::mode::PLAN.into();
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Plan the `todo overdue` command, then the reminders that use it.".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(item(settled(
|
||||
"call-write-plan",
|
||||
"write",
|
||||
serde_json::json!({"path": "PLAN.md", "content": ""}),
|
||||
"Created 'PLAN.md' (1.4 KB)",
|
||||
)))));
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The plan is in `PLAN.md`, in three phases: the `overdue` filter and its command, a \
|
||||
daily reminder that reads it, and the docs. Each phase ends with `npm test` passing."
|
||||
.into(),
|
||||
));
|
||||
app.update(Msg::Engine(Event::PlanWritten { path: "PLAN.md".into() }));
|
||||
app.update(Msg::Engine(Event::TurnEnded { reason: luxe_core::StopReason::EndTurn }));
|
||||
seed_status(app);
|
||||
app.status.model = "claude-opus-5".into();
|
||||
app.status.provider = "anthropic".into();
|
||||
app.status.thinking = luxe_core::provider::ThinkingLevel::High;
|
||||
}
|
||||
|
||||
/// The ask, three lookups folded into a line, the edit and the test run.
|
||||
fn push_turn(app: &mut App) {
|
||||
app.push_convo(ConvoBlock::User { text: ASK.into(), attached: Vec::new(), chips: Vec::new() });
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Reading the command table and the filters first.".into(),
|
||||
));
|
||||
for (index, (call_id, path)) in [
|
||||
("call-read-cli", "src/cli.js"),
|
||||
("call-read-filter", "src/filter.js"),
|
||||
("call-read-tests", "test/filter.test.js"),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let mut read = settled(call_id, "read", serde_json::json!({ "path": path }), "…");
|
||||
let index = u32::try_from(index).unwrap_or(0) + 1;
|
||||
read.run = Some(luxe_core::ToolRun { index, total: 3 });
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(item(read))));
|
||||
}
|
||||
let mut edit = settled("call-edit", "edit", serde_json::json!({ "path": "src/filter.js" }), "");
|
||||
edit.output_preview = Some(
|
||||
"Applied 1 edit(s) to 'src/filter.js'\n\n\
|
||||
\u{20} ...\n\
|
||||
\u{20}19 return tasks.filter((task) => tags.every((tag) => task.tags.includes(tag)));\n\
|
||||
\u{20}20 }\n\
|
||||
+21 \n\
|
||||
+22 /** Open tasks past their due date as of `today`, oldest first. */\n\
|
||||
+23 export function overdue(tasks, today) {\n\
|
||||
+24 return open(tasks)\n\
|
||||
+25 .filter((task) => task.due && task.due < today)\n\
|
||||
+26 .sort((a, b) => a.due.localeCompare(b.due));\n\
|
||||
+27 }"
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(item(edit))));
|
||||
let mut test = settled(
|
||||
"call-test",
|
||||
"test",
|
||||
serde_json::json!({ "filter": "test/filter.test.js" }),
|
||||
"node: ok — 5 passed, 0 failed, 0 skipped",
|
||||
);
|
||||
test.elapsed_ms = Some(640);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(item(test))));
|
||||
}
|
||||
|
||||
/// A call that finished, labeled the way the live projection labels it.
|
||||
fn settled(call_id: &str, tool: &str, arguments: serde_json::Value, output: &str) -> ToolActivity {
|
||||
let label = luxe_core::describe_call(tool, &arguments, "/work/todo");
|
||||
let mut activity = ToolActivity::running("fixture-session", call_id, tool, label, 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
activity.summary = Some("Completed".into());
|
||||
activity.elapsed_ms = Some(4);
|
||||
activity.input_preview = Some(arguments.to_string());
|
||||
activity.output_preview = Some(output.into());
|
||||
activity
|
||||
}
|
||||
|
||||
fn item(activity: ToolActivity) -> ToolItem {
|
||||
ToolItem { activity, expanded: false, details_toggled: false, waited_on_user_ms: 0 }
|
||||
}
|
||||
|
||||
fn seed_status(app: &mut App) {
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.provider = "anthropic".into();
|
||||
app.status.thinking = luxe_core::provider::ThinkingLevel::Medium;
|
||||
app.status.context_window = 1_000_000;
|
||||
app.status.context_pct = 3.1;
|
||||
}
|
||||
123
crates/luxe-tui/src/fixture/chat/tool_run.rs
Normal file
123
crates/luxe-tui/src/fixture/chat/tool_run.rs
Normal file
@@ -0,0 +1,123 @@
|
||||
//! The folded tool run — a run of lookups drawn as one line, with the calls it stands for.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A run of lookups folded into one live line, mid-batch, beside the cards that never fold.
|
||||
pub(super) fn seed_tool_run(app: &mut App) {
|
||||
// Seven calls in one message — a command, a checklist move, then a run of five lookups
|
||||
// — caught on the sixth. Dispatch is strictly sequential, so exactly one call is ever in
|
||||
// flight and it is always the last card: everything above it has landed, and the run's
|
||||
// own last lookup has not started. Any still showing two spinners is a state the
|
||||
// runtime cannot produce.
|
||||
let batch = |index: u32| Some(luxe_core::ToolBatch { index, total: 7 });
|
||||
let lookup = |call_id: &str, tool: &str, arguments: serde_json::Value, index: u32| {
|
||||
let label = luxe_core::describe_call(tool, &arguments, "/work/luxe");
|
||||
let mut activity = ToolActivity::running("fixture-session", call_id, tool, label, 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
activity.summary = Some("Completed".into());
|
||||
activity.elapsed_ms = Some(3 + u64::from(index));
|
||||
// As the live projector builds it: the arguments travel with every card.
|
||||
activity.input_preview = Some(arguments.to_string());
|
||||
activity.output_preview = Some("…".into());
|
||||
activity.batch = batch(index + 2);
|
||||
// The message asked for five adjacent lookups, so each of them knows it is in a
|
||||
// run — which is what lets the run be one line from its first card rather than
|
||||
// three cards that later collapse. The fifth has not been dispatched yet.
|
||||
activity.run = Some(luxe_core::ToolRun { index, total: 5 });
|
||||
activity
|
||||
};
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Running the focused tests, then reading the card renderer and its callers.".into(),
|
||||
));
|
||||
// A command is never folded away: which command ran is the thing a reader is watching
|
||||
// for, and a count would hide exactly that.
|
||||
let mut command = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-bash",
|
||||
"bash",
|
||||
"cargo nextest run -p luxe-tui",
|
||||
1,
|
||||
);
|
||||
command.state = ToolActivityState::Succeeded;
|
||||
command.summary = Some("Completed".into());
|
||||
command.elapsed_ms = Some(2_100);
|
||||
command.input_preview = Some(r#"{"command":"cargo nextest run -p luxe-tui"}"#.into());
|
||||
command.output_preview = Some("184 passed, 0 failed".into());
|
||||
command.batch = batch(1);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: command,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
// Nor is the checklist: the card names the item it moved, which only the result knows.
|
||||
let moved = serde_json::json!({
|
||||
"action": "update", "activeForm": "", "blockedBy": [], "id": 3,
|
||||
"status": "in_progress", "subject": "", "subjects": []
|
||||
});
|
||||
let mut todo = ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-todo",
|
||||
"todo",
|
||||
luxe_core::describe_call("todo", &moved, "/work/luxe"),
|
||||
1,
|
||||
);
|
||||
todo.state = ToolActivityState::Succeeded;
|
||||
todo.summary = Some("Completed".into());
|
||||
todo.elapsed_ms = Some(1);
|
||||
todo.input_preview = Some(moved.to_string());
|
||||
todo.output_preview =
|
||||
Some("Updated todo #3 → in_progress: fold a run of lookups into one line".into());
|
||||
todo.batch = batch(2);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: todo,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
for (index, (call_id, tool, arguments)) in [
|
||||
(
|
||||
"call-read-blocks",
|
||||
"read",
|
||||
serde_json::json!({"path": "crates/luxe-tui/src/view/blocks.rs"}),
|
||||
),
|
||||
(
|
||||
"call-read-card",
|
||||
"read",
|
||||
serde_json::json!({"path": "crates/luxe-tui/src/view/tool_card/mod.rs"}),
|
||||
),
|
||||
(
|
||||
"call-grep-header",
|
||||
"grep",
|
||||
serde_json::json!({"pattern": "tool_header_line", "path": "crates"}),
|
||||
),
|
||||
(
|
||||
"call-read-convo",
|
||||
"read",
|
||||
serde_json::json!({"path": "crates/luxe-tui/src/app/conversation.rs"}),
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let index = index as u32 + 1;
|
||||
let mut activity = lookup(call_id, tool, arguments, index);
|
||||
// The one in flight, and the last card there is: the run's fifth lookup is still
|
||||
// hypothetical, which is exactly what lets the line say "6 of 7" already.
|
||||
if index == 4 {
|
||||
activity.state = ToolActivityState::Running;
|
||||
activity.summary = None;
|
||||
activity.elapsed_ms = None;
|
||||
}
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
}
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.status.active_tool = Some("read".into());
|
||||
app.status.state = crate::app::AppState::Streaming;
|
||||
}
|
||||
246
crates/luxe-tui/src/fixture/corpus.rs
Normal file
246
crates/luxe-tui/src/fixture/corpus.rs
Normal file
@@ -0,0 +1,246 @@
|
||||
//! The small review corpus — one change, its provenance and its noise, pinned for the assertions
|
||||
//! that read it.
|
||||
|
||||
use luxe_core::guided_review::{
|
||||
ChapterId, ChapterKind, FileId, GuidedReview, HunkId, LineRange, NoiseKind, ReviewBase,
|
||||
ReviewChapter, ReviewContext, ReviewFile, ReviewFileStatus, ReviewHunk, ReviewId,
|
||||
ReviewItemRef, ReviewLine, ReviewLineKind, ReviewRevisionId, ReviewSource, ReviewStats,
|
||||
ReviewTarget,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
/// A clean empty-tree working-tree source pinned to `content_digest`.
|
||||
pub(crate) fn fixture_source(content_digest: ReviewRevisionId) -> ReviewSource {
|
||||
ReviewSource {
|
||||
base: ReviewBase::EmptyTree,
|
||||
content_digest,
|
||||
includes_staged: false,
|
||||
includes_unstaged: false,
|
||||
included_untracked_files: 0,
|
||||
captured_at_ms: 0,
|
||||
uncovered_paths: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn fixture_guided_review() -> GuidedReview {
|
||||
let revision_id = ReviewRevisionId::from_canonical_bytes(b"fixture guided review");
|
||||
let file_id = FileId::from_path_lineage(None, Some(Path::new("src/notification.rs")));
|
||||
let hunk_id = HunkId::from_content(&file_id, "notification model", "pub struct Notification");
|
||||
let hunk = ReviewHunk {
|
||||
id: hunk_id.clone(),
|
||||
old_range: LineRange::new(4, 3),
|
||||
new_range: LineRange::new(4, 4),
|
||||
heading: Some("pub struct Notification".into()),
|
||||
symbol: None,
|
||||
lines: vec![
|
||||
ReviewLine {
|
||||
old_line: Some(4),
|
||||
new_line: Some(4),
|
||||
kind: ReviewLineKind::Context,
|
||||
text: "pub struct Notification {".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: Some(5),
|
||||
new_line: None,
|
||||
kind: ReviewLineKind::Deletion,
|
||||
text: " pub category: String,".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: None,
|
||||
new_line: Some(5),
|
||||
kind: ReviewLineKind::Addition,
|
||||
text: " pub category: NotificationCategory,".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: Some(6),
|
||||
new_line: Some(6),
|
||||
kind: ReviewLineKind::Context,
|
||||
text: " pub title: String,".into(),
|
||||
},
|
||||
],
|
||||
noise: NoiseKind::Semantic,
|
||||
};
|
||||
let second_hunk_id =
|
||||
HunkId::from_content(&file_id, "notification display", "impl Notification");
|
||||
let second_hunk = ReviewHunk {
|
||||
id: second_hunk_id.clone(),
|
||||
old_range: LineRange::new(18, 1),
|
||||
new_range: LineRange::new(18, 2),
|
||||
heading: Some("impl Notification".into()),
|
||||
symbol: None,
|
||||
lines: vec![
|
||||
ReviewLine {
|
||||
old_line: Some(18),
|
||||
new_line: Some(18),
|
||||
kind: ReviewLineKind::Context,
|
||||
text: "impl Notification {".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: None,
|
||||
new_line: Some(19),
|
||||
kind: ReviewLineKind::Addition,
|
||||
text: " fn category_name(&self) -> &str { \"notification\" }".into(),
|
||||
},
|
||||
],
|
||||
noise: NoiseKind::Semantic,
|
||||
};
|
||||
let file = ReviewFile {
|
||||
id: file_id,
|
||||
old_path: None,
|
||||
new_path: Some("src/notification.rs".into()),
|
||||
status: ReviewFileStatus::Modified,
|
||||
language: Some("rust".into()),
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
hunks: vec![hunk, second_hunk],
|
||||
binary: false,
|
||||
generated: false,
|
||||
non_text: None,
|
||||
};
|
||||
GuidedReview {
|
||||
conversation: None,
|
||||
id: ReviewId::new(),
|
||||
revision_id: revision_id.clone(),
|
||||
target: ReviewTarget::WorkingTree,
|
||||
source: fixture_source(revision_id),
|
||||
context: ReviewContext {
|
||||
title: "Refactor notification model".into(),
|
||||
goal: None,
|
||||
phase_index: Some(30),
|
||||
phase_title: Some("Guided Review model".into()),
|
||||
planning_excerpt: None,
|
||||
acceptance_excerpt: None,
|
||||
source_intent: None,
|
||||
source_commits: 0,
|
||||
pull_request: None,
|
||||
},
|
||||
files: vec![file],
|
||||
chapters: vec![ReviewChapter {
|
||||
id: ChapterId::from_items("core", &[hunk_id.clone(), second_hunk_id.clone()]),
|
||||
title: "Shared notification model".into(),
|
||||
rationale: "Separates category concepts so platform clients share one stable shape."
|
||||
.into(),
|
||||
impact: None,
|
||||
kind: ChapterKind::Core,
|
||||
items: vec![
|
||||
ReviewItemRef::Hunk(hunk_id.clone()),
|
||||
ReviewItemRef::Hunk(second_hunk_id.clone()),
|
||||
],
|
||||
// The narration a reviewer actually reads: one sentence per piece of the change.
|
||||
notes: vec![
|
||||
luxe_core::guided_review::ItemNote {
|
||||
item: hunk_id.as_str().to_owned(),
|
||||
note: "Swaps the free-form `category: String` for the shared enum, so an invalid category stops being representable.".into(),
|
||||
},
|
||||
luxe_core::guided_review::ItemNote {
|
||||
item: second_hunk_id.as_str().to_owned(),
|
||||
note: "Adds `category_name` so the dispatcher and the Swift client render the same label from the enum.".into(),
|
||||
},
|
||||
],
|
||||
}],
|
||||
// Real review-gate results only. The harness does not invent checks from the agent's
|
||||
// shell history, so an interactive review has none.
|
||||
checks: luxe_core::guided_review::CheckSummary::default(),
|
||||
stats: ReviewStats {
|
||||
files: 1,
|
||||
hunks: 2,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
..ReviewStats::default()
|
||||
},
|
||||
generated_at_ms: 0,
|
||||
insight: Some(luxe_core::guided_review::ReviewInsight {
|
||||
files: vec![luxe_core::guided_review::FileInsight {
|
||||
file: "src/notification.rs".into(),
|
||||
relevant: vec![
|
||||
luxe_core::guided_review::RelevantFile {
|
||||
file: "src/dispatcher.rs".into(),
|
||||
reason: "dispatch calls category_name".into(),
|
||||
},
|
||||
luxe_core::guided_review::RelevantFile {
|
||||
file: "tests/notification.rs".into(),
|
||||
reason: "renders_category tests category_name".into(),
|
||||
},
|
||||
],
|
||||
}],
|
||||
untested_symbols: vec!["src/notification.rs::category_name".into()],
|
||||
covered_symbols: vec!["src/notification.rs::Notification".into()],
|
||||
}),
|
||||
provenance: Some(fixture_turn_provenance()),
|
||||
seen: None,
|
||||
brief: Some(luxe_core::guided_review::ReviewBrief {
|
||||
intent: "Notification categories were free-form strings, so a typo reached the \
|
||||
dispatcher and rendered as an empty label."
|
||||
.into(),
|
||||
account: vec![
|
||||
"Replaces `category: String` with a `Category` enum, making an invalid category \
|
||||
unrepresentable."
|
||||
.into(),
|
||||
"Adds `category_name` so the dispatcher and the Swift client render one label \
|
||||
from one source."
|
||||
.into(),
|
||||
],
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn fixture_turn_provenance() -> luxe_core::guided_review::TurnProvenance {
|
||||
luxe_core::guided_review::TurnProvenance {
|
||||
requests: vec!["Make notification categories type-safe across both clients".into()],
|
||||
account: Some(
|
||||
"Replaced the free-form String category with a shared NotificationCategory enum and \
|
||||
added category_name so the dispatcher and the Swift client agree on one shape."
|
||||
.into(),
|
||||
),
|
||||
steps: vec![
|
||||
"read src/notification.rs".into(),
|
||||
"edit src/notification.rs".into(),
|
||||
"bash cargo test --workspace".into(),
|
||||
],
|
||||
read_paths: ["src/notification.rs".to_owned()].into_iter().collect(),
|
||||
written_paths: ["src/notification.rs".to_owned(), "src/dispatcher.rs".to_owned()]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
commands: vec![luxe_core::guided_review::CommandRun {
|
||||
command: "cargo test --workspace".into(),
|
||||
failed: false,
|
||||
tool: "bash".into(),
|
||||
after_last_edit: true,
|
||||
}],
|
||||
had_tool_failure: false,
|
||||
verified_after_last_edit: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn fixture_guided_review_with_noise() -> GuidedReview {
|
||||
let mut review = fixture_guided_review();
|
||||
let file = &mut review.files[0];
|
||||
let hunk_id = HunkId::from_content(&file.id, "format imports", "use std::{fmt, io};");
|
||||
file.hunks.push(ReviewHunk {
|
||||
id: hunk_id.clone(),
|
||||
old_range: LineRange::new(1, 1),
|
||||
new_range: LineRange::new(1, 1),
|
||||
heading: Some("imports".into()),
|
||||
symbol: None,
|
||||
lines: vec![
|
||||
ReviewLine {
|
||||
old_line: Some(1),
|
||||
new_line: None,
|
||||
kind: ReviewLineKind::Deletion,
|
||||
text: "use std::{fmt,io};".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: None,
|
||||
new_line: Some(1),
|
||||
kind: ReviewLineKind::Addition,
|
||||
text: "use std::{fmt, io};".into(),
|
||||
},
|
||||
],
|
||||
noise: NoiseKind::FormattingOnly,
|
||||
});
|
||||
review.chapters[0].items.push(ReviewItemRef::Hunk(hunk_id));
|
||||
review.stats.hunks = 3;
|
||||
review.stats.additions = Some(3);
|
||||
review.stats.deletions = Some(2);
|
||||
review
|
||||
}
|
||||
246
crates/luxe-tui/src/fixture/demo.rs
Normal file
246
crates/luxe-tui/src/fixture/demo.rs
Normal file
@@ -0,0 +1,246 @@
|
||||
//! The demo review — built from its literal change, with the counts and provenance it implies.
|
||||
|
||||
use super::corpus::fixture_source;
|
||||
use super::demo_spec::{DemoHunk, DEMO_CHANGE};
|
||||
use luxe_core::guided_review::{
|
||||
ChapterId, FileId, GuidedReview, HunkId, LineRange, ReviewChapter, ReviewContext, ReviewFile,
|
||||
ReviewHunk, ReviewId, ReviewItemRef, ReviewLine, ReviewLineKind, ReviewRevisionId,
|
||||
ReviewSource, ReviewStats, ReviewTarget,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
/// What the demo's agent was asked, did, and verified.
|
||||
///
|
||||
/// Its own rather than [`fixture_turn_provenance`], because an unread edit is checked against the
|
||||
/// paths it names, and the small corpus's paths are not the demo's.
|
||||
fn demo_turn_provenance() -> luxe_core::guided_review::TurnProvenance {
|
||||
// `src/render/badge.rs` is absent: a formatter reordered its imports during the turn, and the
|
||||
// review accounts for that hunk as formatting
|
||||
let paths = [
|
||||
"src/notification.rs",
|
||||
"src/notification/category.rs",
|
||||
"src/dispatch/router.rs",
|
||||
"src/api/webhook.rs",
|
||||
"tests/notification_category.rs",
|
||||
];
|
||||
luxe_core::guided_review::TurnProvenance {
|
||||
requests: vec!["Stop notification categories being free-form strings".into()],
|
||||
account: Some(
|
||||
"Added a Category enum, parsed the inbound string once at the webhook, and made the \
|
||||
router match exhaustively."
|
||||
.into(),
|
||||
),
|
||||
steps: vec![
|
||||
"grep category: String".into(),
|
||||
"write src/notification/category.rs".into(),
|
||||
"edit src/notification.rs".into(),
|
||||
"edit src/dispatch/router.rs".into(),
|
||||
"edit src/api/webhook.rs".into(),
|
||||
"write tests/notification_category.rs".into(),
|
||||
"test cargo nextest run --workspace".into(),
|
||||
],
|
||||
read_paths: paths.iter().map(|path| (*path).to_owned()).collect(),
|
||||
written_paths: paths.iter().map(|path| (*path).to_owned()).collect(),
|
||||
commands: vec![luxe_core::guided_review::CommandRun {
|
||||
command: "cargo nextest run --workspace".into(),
|
||||
failed: false,
|
||||
tool: "test".into(),
|
||||
after_last_edit: true,
|
||||
}],
|
||||
had_tool_failure: false,
|
||||
verified_after_last_edit: true,
|
||||
}
|
||||
}
|
||||
|
||||
/// A demo hunk's added and removed lines, and the lines on each side its header counts, context
|
||||
/// included, as a real header does.
|
||||
fn demo_counts(lines: &[ReviewLine]) -> (u64, u64, u32, u32) {
|
||||
let count = |keep: fn(&ReviewLine) -> bool| lines.iter().filter(|line| keep(line)).count();
|
||||
(
|
||||
count(|line| line.kind == ReviewLineKind::Addition) as u64,
|
||||
count(|line| line.kind == ReviewLineKind::Deletion) as u64,
|
||||
count(|line| line.old_line.is_some()) as u32,
|
||||
count(|line| line.new_line.is_some()) as u32,
|
||||
)
|
||||
}
|
||||
|
||||
/// Turns a diff-shaped line spec into review lines, counting the numbers rather than trusting them.
|
||||
fn demo_lines(hunk: &DemoHunk) -> Vec<ReviewLine> {
|
||||
let (mut old_line, mut new_line) = (hunk.old_start, hunk.new_start);
|
||||
hunk.lines
|
||||
.iter()
|
||||
.map(|raw| {
|
||||
let (kind, text) = match raw.split_at(1) {
|
||||
("-", rest) => (ReviewLineKind::Deletion, rest),
|
||||
("+", rest) => (ReviewLineKind::Addition, rest),
|
||||
(_, _) => (ReviewLineKind::Context, &raw[raw.len().min(1)..]),
|
||||
};
|
||||
match kind {
|
||||
ReviewLineKind::Deletion => {
|
||||
let at = old_line;
|
||||
old_line += 1;
|
||||
ReviewLine { old_line: Some(at), new_line: None, kind, text: text.into() }
|
||||
}
|
||||
ReviewLineKind::Addition => {
|
||||
let at = new_line;
|
||||
new_line += 1;
|
||||
ReviewLine { old_line: None, new_line: Some(at), kind, text: text.into() }
|
||||
}
|
||||
_ => {
|
||||
let (old_at, new_at) = (old_line, new_line);
|
||||
old_line += 1;
|
||||
new_line += 1;
|
||||
ReviewLine {
|
||||
old_line: Some(old_at),
|
||||
new_line: Some(new_at),
|
||||
kind: ReviewLineKind::Context,
|
||||
text: text.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn fixture_demo_guided_review() -> GuidedReview {
|
||||
let revision_id = ReviewRevisionId::from_canonical_bytes(b"fixture demo guided review");
|
||||
let mut files: Vec<ReviewFile> = Vec::new();
|
||||
let mut chapters: Vec<ReviewChapter> = Vec::new();
|
||||
let (mut additions, mut deletions) = (0_u64, 0_u64);
|
||||
|
||||
for chapter in DEMO_CHANGE {
|
||||
let mut items = Vec::new();
|
||||
let mut notes = Vec::new();
|
||||
for spec in chapter.files {
|
||||
let path = Path::new(spec.path);
|
||||
let id = FileId::from_path_lineage(None, Some(path));
|
||||
let mut hunks = Vec::new();
|
||||
let (mut file_additions, mut file_deletions) = (0_u64, 0_u64);
|
||||
for hunk in spec.hunks {
|
||||
let lines = demo_lines(hunk);
|
||||
let (added, removed, old_count, new_count) = demo_counts(&lines);
|
||||
file_additions += added;
|
||||
file_deletions += removed;
|
||||
let hunk_id = HunkId::from_content(&id, hunk.key, hunk.heading);
|
||||
items.push(ReviewItemRef::Hunk(hunk_id.clone()));
|
||||
notes.push(luxe_core::guided_review::ItemNote {
|
||||
item: hunk_id.as_str().to_owned(),
|
||||
note: hunk.note.into(),
|
||||
});
|
||||
hunks.push(ReviewHunk {
|
||||
id: hunk_id,
|
||||
old_range: LineRange::new(hunk.old_start, old_count),
|
||||
new_range: LineRange::new(hunk.new_start, new_count),
|
||||
heading: Some(hunk.heading.into()),
|
||||
symbol: None,
|
||||
lines,
|
||||
noise: spec.noise,
|
||||
});
|
||||
}
|
||||
additions += file_additions;
|
||||
deletions += file_deletions;
|
||||
files.push(ReviewFile {
|
||||
id,
|
||||
old_path: None,
|
||||
new_path: Some(path.to_path_buf()),
|
||||
status: spec.status,
|
||||
language: Some("rust".into()),
|
||||
additions: Some(file_additions),
|
||||
deletions: Some(file_deletions),
|
||||
hunks,
|
||||
binary: false,
|
||||
generated: false,
|
||||
non_text: None,
|
||||
});
|
||||
}
|
||||
chapters.push(ReviewChapter {
|
||||
id: ChapterId::from_item_keys(
|
||||
chapter.title,
|
||||
&items
|
||||
.iter()
|
||||
.map(|item| match item {
|
||||
ReviewItemRef::Hunk(id) => id.as_str(),
|
||||
ReviewItemRef::File(id) => id.as_str(),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
title: chapter.title.into(),
|
||||
rationale: chapter.rationale.into(),
|
||||
impact: None,
|
||||
kind: chapter.kind,
|
||||
notes,
|
||||
items,
|
||||
});
|
||||
}
|
||||
|
||||
let file_count = files.len() as u64;
|
||||
let hunk_count = files.iter().map(|file| file.hunks.len() as u64).sum();
|
||||
GuidedReview {
|
||||
conversation: None,
|
||||
id: ReviewId::new(),
|
||||
revision_id: revision_id.clone(),
|
||||
target: ReviewTarget::WorkingTree,
|
||||
source: ReviewSource {
|
||||
includes_unstaged: true,
|
||||
included_untracked_files: 2,
|
||||
..fixture_source(revision_id)
|
||||
},
|
||||
context: ReviewContext {
|
||||
title: "Type the notification category".into(),
|
||||
goal: None,
|
||||
phase_index: None,
|
||||
phase_title: None,
|
||||
planning_excerpt: None,
|
||||
acceptance_excerpt: None,
|
||||
source_intent: None,
|
||||
source_commits: 0,
|
||||
pull_request: None,
|
||||
},
|
||||
files,
|
||||
chapters,
|
||||
checks: luxe_core::guided_review::CheckSummary::default(),
|
||||
stats: ReviewStats {
|
||||
files: file_count,
|
||||
hunks: hunk_count,
|
||||
additions: Some(additions),
|
||||
deletions: Some(deletions),
|
||||
..ReviewStats::default()
|
||||
},
|
||||
generated_at_ms: 0,
|
||||
insight: Some(luxe_core::guided_review::ReviewInsight {
|
||||
files: vec![luxe_core::guided_review::FileInsight {
|
||||
file: "src/notification/category.rs".into(),
|
||||
relevant: vec![
|
||||
luxe_core::guided_review::RelevantFile {
|
||||
file: "src/dispatch/router.rs".into(),
|
||||
reason: "routes on Category".into(),
|
||||
},
|
||||
luxe_core::guided_review::RelevantFile {
|
||||
file: "src/api/webhook.rs".into(),
|
||||
reason: "parses the inbound string".into(),
|
||||
},
|
||||
],
|
||||
}],
|
||||
untested_symbols: vec!["src/api/webhook.rs::receive".into()],
|
||||
covered_symbols: vec![
|
||||
"src/notification/category.rs::Category".into(),
|
||||
"src/notification.rs::label".into(),
|
||||
],
|
||||
}),
|
||||
provenance: Some(demo_turn_provenance()),
|
||||
seen: None,
|
||||
brief: Some(luxe_core::guided_review::ReviewBrief {
|
||||
intent: "A notification category was a free-form string, so a typo type-checked, \
|
||||
reached the router, and rendered as an empty badge."
|
||||
.into(),
|
||||
account: vec![
|
||||
"Adds a `Category` enum and parses the inbound string once, at the HTTP boundary."
|
||||
.into(),
|
||||
"Replaces the router's string comparison with an exhaustive match, so a new \
|
||||
category fails to compile rather than routing to the digest."
|
||||
.into(),
|
||||
"Covers the typo case, which the old shape could not express.".into(),
|
||||
],
|
||||
}),
|
||||
}
|
||||
}
|
||||
251
crates/luxe-tui/src/fixture/demo_spec.rs
Normal file
251
crates/luxe-tui/src/fixture/demo_spec.rs
Normal file
@@ -0,0 +1,251 @@
|
||||
//! The demo review's change, written as a reviewer would see it: files, hunks and chapters.
|
||||
|
||||
use luxe_core::guided_review::{ChapterKind, NoiseKind, ReviewFileStatus};
|
||||
|
||||
/// One hunk of the demo change, written the way a diff prints.
|
||||
///
|
||||
/// `lines` carries the leading `-`, `+` or space a unified diff uses, and the line numbers are
|
||||
/// counted from them rather than typed — the numbers on screen then cannot disagree with the lines
|
||||
/// beside them, which is the sort of detail a viewer notices without being able to say why.
|
||||
pub(super) struct DemoHunk {
|
||||
/// Distinguishes this hunk from its siblings when its id is derived.
|
||||
pub(super) key: &'static str,
|
||||
pub(super) heading: &'static str,
|
||||
pub(super) old_start: u32,
|
||||
pub(super) new_start: u32,
|
||||
pub(super) lines: &'static [&'static str],
|
||||
/// The guide's sentence about this hunk. What a reviewer reads before the diff.
|
||||
pub(super) note: &'static str,
|
||||
}
|
||||
|
||||
/// One file of the demo change.
|
||||
pub(super) struct DemoFile {
|
||||
pub(super) path: &'static str,
|
||||
pub(super) status: ReviewFileStatus,
|
||||
pub(super) noise: NoiseKind,
|
||||
pub(super) hunks: &'static [DemoHunk],
|
||||
}
|
||||
|
||||
/// One chapter, and the files it gathers.
|
||||
pub(super) struct DemoChapter {
|
||||
pub(super) title: &'static str,
|
||||
pub(super) rationale: &'static str,
|
||||
pub(super) kind: ChapterKind,
|
||||
pub(super) files: &'static [DemoFile],
|
||||
}
|
||||
|
||||
/// The change the demos walk: a free-form string becoming a type, and everything that follows.
|
||||
///
|
||||
/// Separate from [`fixture_guided_review`] on purpose, and not because one of them is wrong. That
|
||||
/// one is deliberately one file and three lines so that two screenshots of different surfaces stay
|
||||
/// comparable, and a pile of pinned assertions depends on it staying that size. A demo needs the
|
||||
/// opposite: a change small enough to read in one screen does not need chapters, so a demo built on
|
||||
/// the small corpus argues against the feature it is demonstrating.
|
||||
///
|
||||
/// Six files across four chapters, one of them formatting the reviewer can fold away. Every path,
|
||||
/// symbol and line is written to be a change someone could plausibly have made — an invalid
|
||||
/// category stops being representable, and the type flows outward from there to the router, the
|
||||
/// HTTP boundary, and the tests.
|
||||
pub(super) const DEMO_CHANGE: &[DemoChapter] = &[
|
||||
DemoChapter {
|
||||
title: "Make an invalid category unrepresentable",
|
||||
rationale:
|
||||
"A category was a string, so a typo type-checked. This is the type that stops it.",
|
||||
kind: ChapterKind::Core,
|
||||
// The short swap leads. It is the line the whole change is about, it fits on one screen,
|
||||
// and it has a deletion beside its addition — opening on a twenty-line pure insertion shows
|
||||
// a reviewer a wall of green and nothing to compare it against.
|
||||
files: &[
|
||||
DemoFile {
|
||||
path: "src/notification.rs",
|
||||
status: ReviewFileStatus::Modified,
|
||||
noise: NoiseKind::Semantic,
|
||||
hunks: &[
|
||||
DemoHunk {
|
||||
key: "notification field",
|
||||
heading: "pub struct Notification",
|
||||
old_start: 12,
|
||||
new_start: 12,
|
||||
lines: &[
|
||||
" pub struct Notification {",
|
||||
"- pub category: String,",
|
||||
"+ pub category: Category,",
|
||||
" pub title: String,",
|
||||
" pub body: String,",
|
||||
],
|
||||
note: "The field the whole change exists for. Everything below is what \
|
||||
this line forced.",
|
||||
},
|
||||
DemoHunk {
|
||||
key: "notification label",
|
||||
heading: "impl Notification",
|
||||
old_start: 34,
|
||||
new_start: 34,
|
||||
lines: &[
|
||||
" impl Notification {",
|
||||
"- pub fn label(&self) -> &str {",
|
||||
"- self.category.as_str()",
|
||||
"- }",
|
||||
"+ pub fn label(&self) -> &'static str {",
|
||||
"+ match self.category {",
|
||||
"+ Category::Build => \"Build\",",
|
||||
"+ Category::Deploy => \"Deploy\",",
|
||||
"+ Category::Incident => \"Incident\",",
|
||||
"+ }",
|
||||
"+ }",
|
||||
],
|
||||
note: "One label per category, from one match. The old version returned \
|
||||
whatever string it was handed, which is how an empty badge got \
|
||||
rendered.",
|
||||
},
|
||||
],
|
||||
},
|
||||
DemoFile {
|
||||
path: "src/notification/category.rs",
|
||||
status: ReviewFileStatus::Added,
|
||||
noise: NoiseKind::Semantic,
|
||||
hunks: &[DemoHunk {
|
||||
key: "category enum",
|
||||
heading: "pub enum Category",
|
||||
old_start: 0,
|
||||
new_start: 1,
|
||||
lines: &[
|
||||
"+/// What a notification is about, as a closed set.",
|
||||
"+#[derive(Debug, Clone, Copy, PartialEq, Eq)]",
|
||||
"+pub enum Category {",
|
||||
"+ Build,",
|
||||
"+ Deploy,",
|
||||
"+ Incident,",
|
||||
"+}",
|
||||
"+",
|
||||
"+impl FromStr for Category {",
|
||||
"+ type Err = UnknownCategory;",
|
||||
"+",
|
||||
"+ fn from_str(raw: &str) -> Result<Self, Self::Err> {",
|
||||
"+ match raw {",
|
||||
"+ \"build\" => Ok(Self::Build),",
|
||||
"+ \"deploy\" => Ok(Self::Deploy),",
|
||||
"+ \"incident\" => Ok(Self::Incident),",
|
||||
"+ other => Err(UnknownCategory(other.to_owned())),",
|
||||
"+ }",
|
||||
"+ }",
|
||||
"+}",
|
||||
],
|
||||
note: "The closed set, and the one place a string is allowed to become one. \
|
||||
`FromStr` returns a typed error rather than a default, so an unknown \
|
||||
category has to be handled somewhere.",
|
||||
}],
|
||||
},
|
||||
],
|
||||
},
|
||||
DemoChapter {
|
||||
title: "Thread it through the callers",
|
||||
rationale: "Both places that compared the old string, now matching on the type instead.",
|
||||
kind: ChapterKind::Consequence,
|
||||
files: &[
|
||||
DemoFile {
|
||||
path: "src/dispatch/router.rs",
|
||||
status: ReviewFileStatus::Modified,
|
||||
noise: NoiseKind::Semantic,
|
||||
hunks: &[DemoHunk {
|
||||
key: "router match",
|
||||
heading: "fn route",
|
||||
old_start: 58,
|
||||
new_start: 58,
|
||||
lines: &[
|
||||
" pub fn route(notification: &Notification) -> Channel {",
|
||||
"- if notification.category == \"incident\" {",
|
||||
"- return Channel::Pager;",
|
||||
"- }",
|
||||
"- Channel::Digest",
|
||||
"+ match notification.category {",
|
||||
"+ Category::Incident => Channel::Pager,",
|
||||
"+ Category::Build | Category::Deploy => Channel::Digest,",
|
||||
"+ }",
|
||||
" }",
|
||||
],
|
||||
note: "The match is exhaustive, so adding a category later fails to compile \
|
||||
here instead of quietly routing to the digest.",
|
||||
}],
|
||||
},
|
||||
DemoFile {
|
||||
path: "src/api/webhook.rs",
|
||||
status: ReviewFileStatus::Modified,
|
||||
noise: NoiseKind::Semantic,
|
||||
hunks: &[DemoHunk {
|
||||
key: "webhook parse",
|
||||
heading: "async fn receive",
|
||||
old_start: 41,
|
||||
new_start: 41,
|
||||
lines: &[
|
||||
" let payload: Payload = serde_json::from_slice(&body)?;",
|
||||
"- let notification = Notification {",
|
||||
"- category: payload.category,",
|
||||
"+ let category = payload.category.parse().map_err(|_| {",
|
||||
"+ Rejection::unprocessable(\"unknown notification category\")",
|
||||
"+ })?;",
|
||||
"+ let notification = Notification {",
|
||||
"+ category,",
|
||||
" title: payload.title,",
|
||||
],
|
||||
note: "The boundary where a string is still a string. Parsing here is what \
|
||||
lets everything inside assume the type.",
|
||||
}],
|
||||
},
|
||||
],
|
||||
},
|
||||
DemoChapter {
|
||||
title: "Cover what the string could not express",
|
||||
rationale: "A parse failure was not a case the old shape had, so it had no test.",
|
||||
kind: ChapterKind::Test,
|
||||
files: &[DemoFile {
|
||||
path: "tests/notification_category.rs",
|
||||
status: ReviewFileStatus::Added,
|
||||
noise: NoiseKind::Semantic,
|
||||
hunks: &[DemoHunk {
|
||||
key: "category tests",
|
||||
heading: "fn an_unknown_category_is_rejected",
|
||||
old_start: 0,
|
||||
new_start: 1,
|
||||
lines: &[
|
||||
"+#[test]",
|
||||
"+fn an_unknown_category_is_rejected() {",
|
||||
"+ assert!(\"stagin\".parse::<Category>().is_err());",
|
||||
"+}",
|
||||
"+",
|
||||
"+#[test]",
|
||||
"+fn every_category_has_a_label() {",
|
||||
"+ for category in Category::ALL {",
|
||||
"+ assert!(!Notification::sample(category).label().is_empty());",
|
||||
"+ }",
|
||||
"+}",
|
||||
],
|
||||
note: "The typo case, spelled as a typo. The second test walks the closed set, so \
|
||||
a category added without a label fails here.",
|
||||
}],
|
||||
}],
|
||||
},
|
||||
DemoChapter {
|
||||
title: "Formatting the tool rewrote",
|
||||
rationale: "Import order the formatter changed while the real work was happening.",
|
||||
kind: ChapterKind::Supporting,
|
||||
files: &[DemoFile {
|
||||
path: "src/render/badge.rs",
|
||||
status: ReviewFileStatus::Modified,
|
||||
noise: NoiseKind::FormattingOnly,
|
||||
hunks: &[DemoHunk {
|
||||
key: "import churn",
|
||||
heading: "use",
|
||||
old_start: 1,
|
||||
new_start: 1,
|
||||
lines: &[
|
||||
"-use std::fmt::{self, Display};",
|
||||
"-use crate::notification::Notification;",
|
||||
"+use crate::notification::Notification;",
|
||||
"+use std::fmt::{self, Display};",
|
||||
],
|
||||
note: "Nothing here changed behavior.",
|
||||
}],
|
||||
}],
|
||||
},
|
||||
];
|
||||
44
crates/luxe-tui/src/fixture/flagged.rs
Normal file
44
crates/luxe-tui/src/fixture/flagged.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! Flagged — a review whose every hunk is flagged and would otherwise fold away, for tests of what
|
||||
//! the reading list and the call-outs do past the cap of two a kind.
|
||||
|
||||
use luxe_core::guided_review::{GuidedReview, NoiseKind, ReviewStats, TurnProvenance};
|
||||
|
||||
/// A change adding a credential-shaped line to each of `secrets` (two, in two hunks, to the first)
|
||||
/// and editing each of `unread` without reading it, every hunk formatting-only so that only its
|
||||
/// flag keeps it on the list.
|
||||
pub(crate) fn flagged_review(secrets: &[&str], unread: &[&str]) -> GuidedReview {
|
||||
let key = "ghp_9fKq2mZv8RtY4bNx7Wc3LpF6hJd5s"; // luxe:allow-secret
|
||||
let change = |path: &str, added: &str| {
|
||||
format!(
|
||||
"diff --git a/{path} b/{path}\n--- a/{path}\n+++ b/{path}\n@@ -1,1 +1,1 @@\n\
|
||||
-let token = \"\";\n+{added}\n"
|
||||
)
|
||||
};
|
||||
let secret = format!("let token = \"{key}\";");
|
||||
let diff: String = secrets
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(at, path)| match at {
|
||||
// two credential lines in two hunks of the first file: two flags, one thing to say
|
||||
0 => {
|
||||
change(path, &secret) + &format!("@@ -9,1 +9,1 @@\n-let spare = \"\";\n+{secret}\n")
|
||||
}
|
||||
_ => change(path, &secret),
|
||||
})
|
||||
.chain(unread.iter().map(|path| change(path, "let token = None;")))
|
||||
.collect();
|
||||
let mut files = luxe_core::guided_review::parse_unified_diff(&diff).expect("parses").files;
|
||||
for hunk in files.iter_mut().flat_map(|file| file.hunks.iter_mut()) {
|
||||
hunk.noise = NoiseKind::FormattingOnly;
|
||||
}
|
||||
let mut review = super::fixture_demo_guided_review();
|
||||
review.chapters = luxe_core::guided_review::fallback_chapters(&files).expect("chapters");
|
||||
review.stats = ReviewStats::from_files(&files);
|
||||
review.files = files;
|
||||
review.provenance = Some(TurnProvenance {
|
||||
written_paths: unread.iter().map(|path| path.to_string()).collect(),
|
||||
..TurnProvenance::default()
|
||||
});
|
||||
(review.insight, review.seen) = (None, None);
|
||||
review
|
||||
}
|
||||
163
crates/luxe-tui/src/fixture/github.rs
Normal file
163
crates/luxe-tui/src/fixture/github.rs
Normal file
@@ -0,0 +1,163 @@
|
||||
//! `/github` and `/pr` seeded for screenshot review, on the `acme/notify` repository the other
|
||||
//! GitHub fixtures use and a fixed clock, so no capture's ages drift between runs.
|
||||
//!
|
||||
//! `LUXE_FIXTURE_OVERLAY` picks the state: `github` (the list, your pull request's Overview
|
||||
//! beside it), `github-detail` (the same, the keys in the detail), `github-conversation`,
|
||||
//! `github-draft` (an agent's reply open to read), `github-issue` (an issue you have a session
|
||||
//! on), `github-pulls` (every open pull request, more than one page of them), `github-search` (a
|
||||
//! search being typed over them), `github-merged` (that tab stepped to merged), `pr` (your pull
|
||||
//! request on its own, with nothing left in the way), and `pr-merge` (its merge confirmation
|
||||
//! open).
|
||||
|
||||
mod conversation;
|
||||
mod overview;
|
||||
mod rows;
|
||||
|
||||
use luxe_core::github::overview::{ConversationEntry, PullRequestOverview, RowFacts};
|
||||
use luxe_core::github::ListItem;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::github_detail::{DetailTab, GithubDetail, Subject};
|
||||
use crate::github_panel::{Focus, GithubPanel};
|
||||
use conversation::{agent_draft, conversation, JON_THREAD};
|
||||
use overview::{issue, own_pull_request, ready_pull_request};
|
||||
#[cfg(test)]
|
||||
use rows::stamp;
|
||||
#[cfg(test)]
|
||||
use rows::HOUR;
|
||||
use rows::{
|
||||
all_issues, facts, issue_url, issues, listed, merged, mine, pull_requests, review_requested,
|
||||
url, DAY, NOW,
|
||||
};
|
||||
|
||||
/// Your own pull request as the fixtures draw it: one check failing, changes requested, two threads
|
||||
/// open. A starting point for a test that needs an overview and cares about a field or two.
|
||||
pub fn pull_request_overview() -> PullRequestOverview {
|
||||
own_pull_request()
|
||||
}
|
||||
|
||||
/// Seeds the state `which` names over whatever scenario is under it.
|
||||
pub fn seed_github(app: &mut App, which: &str) {
|
||||
if which == "pr" || which == "pr-merge" {
|
||||
let ready = ready_pull_request();
|
||||
let mut detail = GithubDetail::new(Subject::PullRequest(Box::new(ready.clone())));
|
||||
detail.clock = Some(NOW);
|
||||
detail.on_branch = true;
|
||||
if which == "pr-merge" {
|
||||
detail.merging = Some(crate::github_detail::MergeDialog::new(&ready));
|
||||
}
|
||||
app.overlays.pull_request_card = Some(crate::github_detail::PullRequestCard {
|
||||
number: ready.number,
|
||||
state: crate::github_detail::CardState::Ready(Box::new(detail)),
|
||||
seen: None,
|
||||
branch: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
let mut panel = panel();
|
||||
match which {
|
||||
"github-detail" => panel.focus = Focus::Detail,
|
||||
"github-conversation" | "github-draft" => {
|
||||
panel.focus = Focus::Detail;
|
||||
if let Some(detail) = panel.details.get_mut(&url(142)) {
|
||||
detail.tab = DetailTab::Conversation;
|
||||
// On jon's open thread, opened, with the agent's draft under it
|
||||
detail.cursor = 4;
|
||||
detail.open.insert(4);
|
||||
}
|
||||
if which == "github-draft" {
|
||||
if let Some(detail) = panel.details.get_mut(&url(142)) {
|
||||
detail.drafts.clear();
|
||||
let mut card = crate::github_detail::DraftCard::reading(
|
||||
agent_draft(),
|
||||
Some(("jon-avery".into(), JON_THREAD.into())),
|
||||
);
|
||||
// What it answers, as an agent's draft always knows: `d` redrafts it
|
||||
card.target = conversation().into_iter().find_map(|entry| match entry {
|
||||
ConversationEntry::Thread(thread) if thread.id == "jon-router" => {
|
||||
Some(luxe_core::engine::DraftTarget::Thread(thread))
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
detail.composing = Some(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
"github-issue" => {
|
||||
panel.section = 2;
|
||||
}
|
||||
"github-pulls" => {
|
||||
panel.section = 3;
|
||||
}
|
||||
"github-search" => {
|
||||
panel.section = 3;
|
||||
let mut editor = crate::editor::Editor::new();
|
||||
editor.insert_text("is:open is:pr sort:updated-desc digest");
|
||||
panel.editing = Some(editor);
|
||||
}
|
||||
"github-merged" => {
|
||||
use luxe_core::github::query;
|
||||
panel.section = 3;
|
||||
let search = &mut panel.searches[3];
|
||||
search.query = query::with_state(&search.query, query::State::Merged);
|
||||
if let Some(section) = panel.sections.as_mut().and_then(|s| s.get_mut(3)) {
|
||||
let facts: std::collections::HashMap<String, RowFacts> =
|
||||
facts().into_iter().collect();
|
||||
section.items = merged()
|
||||
.into_iter()
|
||||
.map(|item| ListItem { facts: facts.get(&item.url).cloned(), ..item })
|
||||
.collect();
|
||||
section.total = Some(212);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
app.overlays.github = Some(panel);
|
||||
}
|
||||
|
||||
fn panel() -> GithubPanel {
|
||||
let mut panel = GithubPanel {
|
||||
repository: Some("acme/notify".into()),
|
||||
sections: Some(vec![
|
||||
listed("Review requested", review_requested(), None),
|
||||
listed("Mine", mine(), None),
|
||||
listed("Assigned issues", issues(), None),
|
||||
listed("Pull requests", pull_requests(), Some(47)),
|
||||
listed("Issues", all_issues(), Some(23)),
|
||||
]),
|
||||
section: 1,
|
||||
clock: Some(NOW),
|
||||
..GithubPanel::new(&luxe_core::config::GithubConfig::default().sections())
|
||||
};
|
||||
// Each row's second line, as the search brings it
|
||||
let facts: std::collections::HashMap<String, RowFacts> = facts().into_iter().collect();
|
||||
for section in panel.sections.iter_mut().flatten() {
|
||||
for item in &mut section.items {
|
||||
item.facts = facts.get(&item.url).cloned();
|
||||
}
|
||||
}
|
||||
let mut mine = GithubDetail::new(Subject::PullRequest(Box::new(own_pull_request())));
|
||||
mine.conversation = Some(conversation());
|
||||
mine.drafts.push(agent_draft());
|
||||
panel.details.insert(url(142), mine);
|
||||
let mut issue = GithubDetail::new(Subject::Issue(Box::new(issue())));
|
||||
issue.local = Some(luxe_core::github::overview::LocalSession {
|
||||
session: "6f1c2e0a-318".into(),
|
||||
branch: Some("318-phantom-category".into()),
|
||||
last_used: NOW - 2 * DAY,
|
||||
});
|
||||
panel.details.insert(issue_url(318), issue);
|
||||
panel
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_stamp_reads_back_as_the_seconds_it_was_made_from() {
|
||||
for seconds in [0, 951_868_800, NOW, NOW - 2 * DAY - 7 * HOUR - 13] {
|
||||
assert_eq!(luxe_core::github::rfc3339_seconds(&stamp(seconds)), Some(seconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
176
crates/luxe-tui/src/fixture/github/conversation.rs
Normal file
176
crates/luxe-tui/src/fixture/github/conversation.rs
Normal file
@@ -0,0 +1,176 @@
|
||||
//! GitHub conversation — a pull request's comments and threads, and the agent's draft reply.
|
||||
|
||||
use super::overview::DESCRIPTION;
|
||||
use super::rows::{stamp, DAY, HOUR, NOW};
|
||||
use crate::github_detail::Draft;
|
||||
use luxe_core::github::overview::{ConversationEntry, Verdict};
|
||||
use luxe_core::github::{Author, ConversationComment, ReviewThread, ThreadComment, ThreadSide};
|
||||
|
||||
const RABBIT: &str = "## Walkthrough
|
||||
|
||||
The change introduces category-based routing for digest delivery. A new `DigestRouter` maps \
|
||||
each `Category` to a send schedule, and the scheduler consults it before enqueueing.
|
||||
|
||||
## Changes
|
||||
|
||||
| File | Summary |
|
||||
| --- | --- |
|
||||
| `src/digest/router.rs` | New router mapping categories to schedules |
|
||||
| `src/digest/scheduler.rs` | Consults the router before enqueueing |
|
||||
| `src/dispatch/router.rs` | Passes the parsed category through |
|
||||
|
||||
## Sequence
|
||||
|
||||
1. Webhook parses the category.
|
||||
2. Dispatcher hands it to the digest scheduler.
|
||||
3. Scheduler asks the router for a schedule.
|
||||
4. The digest is enqueued on that schedule.
|
||||
|
||||
## Estimated review effort
|
||||
|
||||
Medium — touches scheduling on a hot path.";
|
||||
|
||||
const JON_REVIEW: &str = "Two things before this goes in. The fallback for tenants without \
|
||||
rules is right, but it is decided in two places; and on-call-only for incidents needs a test, \
|
||||
since that is the one a mistake here would page the wrong people over.";
|
||||
|
||||
pub(super) const JON_THREAD: &str =
|
||||
"This decides the fallback again — the scheduler already does it. If \
|
||||
the two ever disagree, a tenant without rules gets incidents on the daily send. Can this read the \
|
||||
schedule the scheduler picked instead?";
|
||||
|
||||
fn comment(author: &str, bot: bool, body: &str, ago: u64) -> ConversationComment {
|
||||
ConversationComment {
|
||||
id: format!("{author}-{ago}"),
|
||||
author: author.into(),
|
||||
bot,
|
||||
mine: author == "nora-quinn",
|
||||
body: body.into(),
|
||||
created_at: stamp(NOW - ago),
|
||||
url: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn thread_comment(author: &str, body: &str, ago: u64) -> ThreadComment {
|
||||
ThreadComment {
|
||||
author: author.into(),
|
||||
body: body.into(),
|
||||
created_at: stamp(NOW - ago),
|
||||
url: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn conversation() -> Vec<ConversationEntry> {
|
||||
vec![
|
||||
ConversationEntry::Opening {
|
||||
author: Author { login: "nora-quinn".into(), bot: false },
|
||||
body: DESCRIPTION.into(),
|
||||
at: NOW - 2 * DAY,
|
||||
},
|
||||
ConversationEntry::Review {
|
||||
comment: comment("coderabbitai[bot]", true, RABBIT, DAY + 6 * HOUR),
|
||||
verdict: Verdict::Commented,
|
||||
line_comments: 4,
|
||||
},
|
||||
ConversationEntry::Review {
|
||||
comment: comment(
|
||||
"mara-okafor",
|
||||
false,
|
||||
"Reads well. The tenant fallback is the part I'd have got wrong.",
|
||||
DAY,
|
||||
),
|
||||
verdict: Verdict::Approved,
|
||||
line_comments: 0,
|
||||
},
|
||||
ConversationEntry::Review {
|
||||
comment: comment("jon-avery", false, JON_REVIEW, 3 * HOUR),
|
||||
verdict: Verdict::ChangesRequested,
|
||||
line_comments: 2,
|
||||
},
|
||||
ConversationEntry::Thread(thread(
|
||||
"jon-router",
|
||||
"src/dispatch/router.rs",
|
||||
Some(88),
|
||||
false,
|
||||
vec![thread_comment("jon-avery", JON_THREAD, 3 * HOUR)],
|
||||
)),
|
||||
ConversationEntry::Thread(thread(
|
||||
"jon-test",
|
||||
"src/digest/scheduler.rs",
|
||||
Some(141),
|
||||
false,
|
||||
vec![thread_comment(
|
||||
"jon-avery",
|
||||
"Worth a test that an incident digest reaches on-call and nobody else.",
|
||||
3 * HOUR,
|
||||
)],
|
||||
)),
|
||||
ConversationEntry::Thread(thread(
|
||||
"mara-webhook",
|
||||
"src/api/webhook.rs",
|
||||
Some(42),
|
||||
true,
|
||||
vec![
|
||||
thread_comment("mara-okafor", "Should an unknown category 422 here?", DAY),
|
||||
thread_comment("nora-quinn", "It does now — see the second commit.", 20 * HOUR),
|
||||
],
|
||||
)),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn thread(
|
||||
id: &str,
|
||||
path: &str,
|
||||
line: Option<u32>,
|
||||
resolved: bool,
|
||||
comments: Vec<ThreadComment>,
|
||||
) -> ReviewThread {
|
||||
ReviewThread {
|
||||
id: id.into(),
|
||||
path: path.into(),
|
||||
line,
|
||||
start_line: None,
|
||||
side: ThreadSide::Right,
|
||||
outdated: false,
|
||||
resolved,
|
||||
file_level: false,
|
||||
total_comments: comments.len(),
|
||||
comments,
|
||||
anchor_text: None,
|
||||
can_reply: true,
|
||||
can_resolve: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn agent_draft() -> Draft {
|
||||
Draft {
|
||||
target: "Reply to @jon-avery on `src/dispatch/router.rs:88`".into(),
|
||||
thread: Some("jon-router".into()),
|
||||
body: "Good catch — they could drift, and the failure mode is the one you describe: a \
|
||||
tenant without routing rules would get incidents on the daily send if the router and the \
|
||||
scheduler ever disagreed about the fallback.
|
||||
|
||||
The router no longer decides it. It reads the schedule the scheduler already picked \
|
||||
(`Schedule::for_tenant`), so there is one place that knows a tenant without rules gets the daily \
|
||||
send, and the router only maps categories onto whatever that returns.
|
||||
|
||||
What changed:
|
||||
|
||||
- `DigestRouter::route` takes the tenant's `Schedule` instead of building its own default
|
||||
- the duplicate fallback in `src/dispatch/router.rs` is gone
|
||||
- a new test, `tenant_without_rules_still_pages_on_call`, sends an incident for a tenant with no \
|
||||
rules and checks it goes out at once, to on-call only
|
||||
|
||||
Fixed in `4c1e2a0`. The other thread — the on-call test you asked for on the scheduler — is \
|
||||
covered by the same test; I'll point to it there too."
|
||||
.into(),
|
||||
by_agent: true,
|
||||
sources: vec![
|
||||
"this session".into(),
|
||||
"the thread".into(),
|
||||
"the review comment, verified".into(),
|
||||
"4c1e2a0".into(),
|
||||
],
|
||||
note: None,
|
||||
}
|
||||
}
|
||||
120
crates/luxe-tui/src/fixture/github/overview.rs
Normal file
120
crates/luxe-tui/src/fixture/github/overview.rs
Normal file
@@ -0,0 +1,120 @@
|
||||
//! GitHub overviews — the pull requests and the issue the panel opens on.
|
||||
|
||||
use super::rows::{issue_url, label, url, DAY, HOUR, MINUTE, NOW};
|
||||
use luxe_core::github::overview::{
|
||||
FailingCheckName, IssueOverview, LinkedPullRequest, MergeMethod, MergeStatus,
|
||||
PullRequestOverview, Reviewer, ReviewerKind, Verdict, Viewer,
|
||||
};
|
||||
use luxe_core::github::{Author, CheckRollup, PullRequestState, ReviewDecision};
|
||||
|
||||
pub(super) const DESCRIPTION: &str =
|
||||
"Digests went to every subscriber whatever the category, so an \
|
||||
incident page and a weekly product note landed in the same email.
|
||||
|
||||
This routes each digest by the category the webhook now parses:
|
||||
|
||||
- `Incident` digests go out at once, to on-call only
|
||||
- `Deploy` digests batch hourly
|
||||
- everything else keeps the daily send
|
||||
|
||||
Tenants without routing rules fall back to the daily send, so nobody stops getting mail on \
|
||||
upgrade.
|
||||
|
||||
Closes #301.";
|
||||
|
||||
pub(super) fn own_pull_request() -> PullRequestOverview {
|
||||
PullRequestOverview {
|
||||
node_id: String::new(),
|
||||
number: 142,
|
||||
title: "Route digests by category".into(),
|
||||
body: DESCRIPTION.into(),
|
||||
url: url(142),
|
||||
repository: "acme/notify".into(),
|
||||
author: Author { login: "nora-quinn".into(), bot: false },
|
||||
state: PullRequestState::Open,
|
||||
draft: false,
|
||||
base_ref: "main".into(),
|
||||
head_ref: "digest-routing".into(),
|
||||
head_oid: "4c1e2a0f9b".into(),
|
||||
cross_repository: false,
|
||||
additions: 96,
|
||||
deletions: 31,
|
||||
changed_files: 7,
|
||||
commits: 6,
|
||||
updated_at: NOW - 25 * MINUTE,
|
||||
labels: vec![label("backend", "1d76db"), label("notifications", "5319e7")],
|
||||
merge_status: MergeStatus::Blocked,
|
||||
review_decision: Some(ReviewDecision::ChangesRequested),
|
||||
reviewers: vec![
|
||||
reviewer("jon-avery", ReviewerKind::User, Verdict::ChangesRequested, 3 * HOUR),
|
||||
reviewer("mara-okafor", ReviewerKind::User, Verdict::Approved, DAY),
|
||||
reviewer("coderabbitai", ReviewerKind::Bot, Verdict::Commented, DAY),
|
||||
reviewer("lena-hart", ReviewerKind::User, Verdict::Requested, DAY),
|
||||
reviewer("acme/platform", ReviewerKind::Team, Verdict::Requested, DAY),
|
||||
],
|
||||
checks: CheckRollup { passed: 11, failed: 1, ..CheckRollup::default() },
|
||||
failing: vec![FailingCheckName { name: "test (ubuntu-latest)".into(), required: true }],
|
||||
unresolved_threads: 2,
|
||||
stack: None,
|
||||
viewer: Viewer { author: true, can_push: true, can_merge: true },
|
||||
merge_methods: vec![MergeMethod::Squash, MergeMethod::Merge, MergeMethod::Rebase],
|
||||
merge_settings: Default::default(),
|
||||
conversation_count: 7,
|
||||
}
|
||||
}
|
||||
|
||||
/// The same pull request a day on: fixed, approved, nothing in the way.
|
||||
pub(super) fn ready_pull_request() -> PullRequestOverview {
|
||||
PullRequestOverview {
|
||||
merge_status: MergeStatus::Clean,
|
||||
review_decision: Some(ReviewDecision::Approved),
|
||||
reviewers: vec![
|
||||
reviewer("jon-avery", ReviewerKind::User, Verdict::Approved, 40 * MINUTE),
|
||||
reviewer("mara-okafor", ReviewerKind::User, Verdict::Approved, DAY),
|
||||
reviewer("lena-hart", ReviewerKind::User, Verdict::Approved, 2 * HOUR),
|
||||
],
|
||||
checks: CheckRollup { passed: 12, ..CheckRollup::default() },
|
||||
failing: Vec::new(),
|
||||
unresolved_threads: 0,
|
||||
updated_at: NOW - 40 * MINUTE,
|
||||
conversation_count: 11,
|
||||
..own_pull_request()
|
||||
}
|
||||
}
|
||||
|
||||
fn reviewer(login: &str, kind: ReviewerKind, verdict: Verdict, ago: u64) -> Reviewer {
|
||||
Reviewer { login: login.into(), kind, verdict, at: Some(NOW - ago) }
|
||||
}
|
||||
|
||||
const ISSUE_BODY: &str = "A webhook that sends `categroy: \"deploy\"` — the typo is real, from \
|
||||
the Jenkins plugin — creates a category named after whatever the field held, and the digest \
|
||||
renders it as an empty heading.
|
||||
|
||||
Expected: an unknown category is refused, or at least lands in `Other`.
|
||||
|
||||
Seen on three tenants this week.";
|
||||
|
||||
pub(super) fn issue() -> IssueOverview {
|
||||
IssueOverview {
|
||||
number: 318,
|
||||
title: "A typo in a webhook creates a phantom category".into(),
|
||||
body: ISSUE_BODY.into(),
|
||||
url: issue_url(318),
|
||||
repository: "acme/notify".into(),
|
||||
author: Author { login: "mara-okafor".into(), bot: false },
|
||||
state: PullRequestState::Open,
|
||||
updated_at: NOW - 2 * HOUR,
|
||||
labels: vec![label("bug", "d73a4a"), label("webhooks", "0e8a16")],
|
||||
assignees: vec!["nora-quinn".into()],
|
||||
milestone: Some("v0.9".into()),
|
||||
linked: vec![LinkedPullRequest {
|
||||
number: 182,
|
||||
title: "Parse notification categories into an enum".into(),
|
||||
state: PullRequestState::Open,
|
||||
draft: false,
|
||||
author: "copilot-swe-agent".into(),
|
||||
closes: true,
|
||||
}],
|
||||
conversation_count: 4,
|
||||
}
|
||||
}
|
||||
162
crates/luxe-tui/src/fixture/github/rows.rs
Normal file
162
crates/luxe-tui/src/fixture/github/rows.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
//! GitHub panel rows — the search results each tab lists, their facts, labels and timestamps.
|
||||
|
||||
use luxe_core::github::overview::{Label, RowFacts};
|
||||
use luxe_core::github::{CheckRollup, ListItem, ListedSection, PullRequestState, ReviewDecision};
|
||||
|
||||
/// The fixture's now: 2026-09-24, mid-afternoon.
|
||||
pub(super) const NOW: u64 = 1_790_265_600;
|
||||
|
||||
pub(super) const MINUTE: u64 = 60;
|
||||
|
||||
pub(super) const HOUR: u64 = 60 * MINUTE;
|
||||
|
||||
pub(super) const DAY: u64 = 24 * HOUR;
|
||||
|
||||
pub(super) fn url(number: u64) -> String {
|
||||
format!("https://github.com/acme/notify/pull/{number}")
|
||||
}
|
||||
|
||||
pub(super) fn issue_url(number: u64) -> String {
|
||||
format!("https://github.com/acme/notify/issues/{number}")
|
||||
}
|
||||
|
||||
fn row(pull_request: bool, number: u64, title: &str, author: &str, ago: u64) -> ListItem {
|
||||
ListItem {
|
||||
pull_request,
|
||||
number,
|
||||
title: title.into(),
|
||||
url: if pull_request { url(number) } else { issue_url(number) },
|
||||
repository: "acme/notify".into(),
|
||||
author: author.into(),
|
||||
draft: number == 139,
|
||||
updated_at: stamp(NOW - ago),
|
||||
state: PullRequestState::Open,
|
||||
facts: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A section as a search brings it: whole, or the first page of `total`.
|
||||
pub(super) fn listed(name: &str, items: Vec<ListItem>, total: Option<u64>) -> ListedSection {
|
||||
let total = total.unwrap_or(items.len() as u64);
|
||||
let next = (total > items.len() as u64).then(|| "Y3Vyc29yOjMw".to_string());
|
||||
ListedSection { name: name.into(), items, error: None, total: Some(total), next }
|
||||
}
|
||||
|
||||
pub(super) fn review_requested() -> Vec<ListItem> {
|
||||
vec![
|
||||
row(true, 182, "Parse notification categories into an enum", "copilot-swe-agent", 2 * HOUR),
|
||||
row(true, 176, "Retry webhook deliveries with backoff", "mara-okafor", 5 * HOUR),
|
||||
row(true, 171, "Drop the legacy digest formatter", "jon-avery", DAY),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn mine() -> Vec<ListItem> {
|
||||
vec![
|
||||
row(true, 142, "Route digests by category", "nora-quinn", 25 * MINUTE),
|
||||
row(true, 139, "Batch digest sends per tenant", "nora-quinn", 3 * DAY),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn issues() -> Vec<ListItem> {
|
||||
vec![
|
||||
row(false, 318, "A typo in a webhook creates a phantom category", "mara-okafor", 2 * HOUR),
|
||||
row(false, 305, "Digest emails ignore the reader's time zone", "kai-holm", DAY),
|
||||
row(false, 297, "Document the notification categories", "jon-avery", 4 * DAY),
|
||||
row(false, 290, "Rate-limit outbound webhooks per tenant", "lena-hart", 9 * DAY),
|
||||
]
|
||||
}
|
||||
|
||||
/// Every open pull request, most recently active first: yours, the ones waiting on you, and the
|
||||
/// ones nobody addressed to you, a bot's among them.
|
||||
pub(super) fn pull_requests() -> Vec<ListItem> {
|
||||
let mut rows = review_requested();
|
||||
rows.extend(mine());
|
||||
rows.push(row(true, 185, "Bump tokio from 1.40 to 1.41", "dependabot", 40 * MINUTE));
|
||||
rows.push(row(true, 168, "Expose digest metrics on /metrics", "kai-holm", 2 * DAY));
|
||||
rows.sort_by_key(|row| std::cmp::Reverse(row.updated_at.clone()));
|
||||
rows
|
||||
}
|
||||
|
||||
pub(super) fn all_issues() -> Vec<ListItem> {
|
||||
let mut rows = issues();
|
||||
rows.push(row(false, 312, "Unsubscribe links 404 for SSO tenants", "kai-holm", 6 * HOUR));
|
||||
rows.push(row(false, 284, "Webhook signatures accept stale timestamps", "lena-hart", 12 * DAY));
|
||||
rows.sort_by_key(|row| std::cmp::Reverse(row.updated_at.clone()));
|
||||
rows
|
||||
}
|
||||
|
||||
pub(super) fn merged() -> Vec<ListItem> {
|
||||
let merged = |number, title, author, ago| ListItem {
|
||||
state: PullRequestState::Merged,
|
||||
..row(true, number, title, author, ago)
|
||||
};
|
||||
vec![
|
||||
merged(181, "Parse the category header case-insensitively", "mara-okafor", 3 * HOUR),
|
||||
merged(174, "Split the dispatcher into its own module", "jon-avery", DAY),
|
||||
merged(170, "Bump serde from 1.0.210 to 1.0.214", "dependabot", 2 * DAY),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn label(name: &str, color: &str) -> Label {
|
||||
Label { name: name.into(), color: color.into() }
|
||||
}
|
||||
|
||||
/// What each row says under its title, by address.
|
||||
pub(super) fn facts() -> Vec<(String, RowFacts)> {
|
||||
let checks = |passed, failed, pending| CheckRollup { passed, failed, pending, skipped: 0 };
|
||||
let pr = |additions, deletions, checks, review_decision, bot| RowFacts {
|
||||
author_bot: bot,
|
||||
additions,
|
||||
deletions,
|
||||
checks,
|
||||
review_decision,
|
||||
..RowFacts::default()
|
||||
};
|
||||
let issue = |labels: Vec<Label>, comments, linked_pull_request| RowFacts {
|
||||
labels,
|
||||
comments,
|
||||
linked_pull_request,
|
||||
..RowFacts::default()
|
||||
};
|
||||
let bug = || label("bug", "d73a4a");
|
||||
vec![
|
||||
(url(182), pr(50, 12, checks(11, 1, 0), Some(ReviewDecision::ChangesRequested), true)),
|
||||
(url(176), pr(212, 40, checks(6, 0, 3), Some(ReviewDecision::ReviewRequired), false)),
|
||||
(url(171), pr(8, 164, checks(12, 0, 0), Some(ReviewDecision::Approved), false)),
|
||||
(url(142), pr(96, 31, checks(11, 1, 0), Some(ReviewDecision::ChangesRequested), false)),
|
||||
(url(139), pr(140, 22, checks(4, 0, 8), None, false)),
|
||||
(issue_url(318), issue(vec![bug(), label("webhooks", "0e8a16")], 4, Some(182))),
|
||||
(issue_url(305), issue(vec![bug()], 3, None)),
|
||||
(issue_url(297), issue(vec![label("docs", "0075ca")], 0, None)),
|
||||
(issue_url(290), issue(vec![label("enhancement", "a2eeef")], 1, None)),
|
||||
(url(185), pr(4, 4, checks(12, 0, 0), None, true)),
|
||||
(url(168), pr(88, 6, checks(10, 0, 2), Some(ReviewDecision::ReviewRequired), false)),
|
||||
(url(181), pr(14, 3, checks(12, 0, 0), Some(ReviewDecision::Approved), false)),
|
||||
(url(174), pr(310, 288, checks(12, 0, 0), Some(ReviewDecision::Approved), false)),
|
||||
(url(170), pr(2, 2, checks(12, 0, 0), None, true)),
|
||||
(issue_url(312), issue(vec![bug(), label("sso", "fbca04")], 2, None)),
|
||||
(issue_url(284), issue(vec![label("security", "b60205")], 5, None)),
|
||||
]
|
||||
}
|
||||
|
||||
/// GitHub's `2026-09-24T19:05:02Z` for `seconds` since the Unix epoch.
|
||||
pub(super) fn stamp(seconds: u64) -> String {
|
||||
// Howard Hinnant's `civil_from_days`, the inverse of what `rfc3339_seconds` reads
|
||||
let days = (seconds / DAY) as i64 + 719_468;
|
||||
let era = days.div_euclid(146_097);
|
||||
let day_of_era = days - era * 146_097;
|
||||
let year_of_era =
|
||||
(day_of_era - day_of_era / 1_460 + day_of_era / 36_524 - day_of_era / 146_096) / 365;
|
||||
let day_of_year = day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100);
|
||||
let shifted = (5 * day_of_year + 2) / 153;
|
||||
let day = day_of_year - (153 * shifted + 2) / 5 + 1;
|
||||
let month = if shifted < 10 { shifted + 3 } else { shifted - 9 };
|
||||
let year = year_of_era + era * 400 + i64::from(month <= 2);
|
||||
let rest = seconds % DAY;
|
||||
format!(
|
||||
"{year:04}-{month:02}-{day:02}T{:02}:{:02}:{:02}Z",
|
||||
rest / HOUR,
|
||||
rest % HOUR / MINUTE,
|
||||
rest % MINUTE
|
||||
)
|
||||
}
|
||||
284
crates/luxe-tui/src/fixture/large.rs
Normal file
284
crates/luxe-tui/src/fixture/large.rs
Normal file
@@ -0,0 +1,284 @@
|
||||
//! The large review — a generated change big enough to exercise scrolling, folding and scale.
|
||||
|
||||
use super::corpus::{fixture_source, fixture_turn_provenance};
|
||||
use luxe_core::guided_review::{
|
||||
ChapterId, FileId, GuidedReview, HunkId, LineRange, NoiseKind, ReviewBase, ReviewFile,
|
||||
ReviewFileStatus, ReviewHunk, ReviewId, ReviewLine, ReviewLineKind, ReviewRevisionId,
|
||||
ReviewSource, ReviewTarget,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
/// A review at the scale the feature exists for: a change too large to read unaided.
|
||||
///
|
||||
/// Forty-four files and three hundred-odd hunks across seven chapters, with the awkward cases a
|
||||
/// real review contains — folded formatting churn, a lockfile, a generated file, a rename, and a
|
||||
/// binary asset. Claims about behaving at scale should be measured against something this size,
|
||||
/// not against a two-hunk sample.
|
||||
pub fn fixture_large_guided_review() -> GuidedReview {
|
||||
use luxe_core::guided_review::{
|
||||
ChapterKind, NonTextChange, NonTextChangeKind, ReviewChapter, ReviewItemRef, ReviewStats,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// One themed group of files, and the chapter it becomes.
|
||||
struct Section {
|
||||
title: &'static str,
|
||||
rationale: &'static str,
|
||||
kind: ChapterKind,
|
||||
directory: &'static str,
|
||||
files: usize,
|
||||
hunks: usize,
|
||||
noise: NoiseKind,
|
||||
}
|
||||
|
||||
const SECTIONS: [Section; 7] = [
|
||||
Section {
|
||||
title: "Shared notification model",
|
||||
rationale: "Separates category, route, and parse-failure concepts so both platform clients share one shape.",
|
||||
kind: ChapterKind::Core,
|
||||
directory: "crates/luxe-core/src/notification",
|
||||
files: 9,
|
||||
hunks: 10,
|
||||
noise: NoiseKind::Semantic,
|
||||
},
|
||||
Section {
|
||||
title: "Dispatcher integration",
|
||||
rationale: "Threads the new category through every dispatch path that used the old string.",
|
||||
kind: ChapterKind::Consequence,
|
||||
directory: "crates/luxe-core/src/dispatch",
|
||||
files: 8,
|
||||
hunks: 9,
|
||||
noise: NoiseKind::Semantic,
|
||||
},
|
||||
Section {
|
||||
title: "Front-end rendering",
|
||||
rationale: "Renders the category badge where the raw string used to be interpolated.",
|
||||
kind: ChapterKind::Consequence,
|
||||
directory: "crates/luxe-tui/src/view",
|
||||
files: 7,
|
||||
hunks: 8,
|
||||
noise: NoiseKind::Semantic,
|
||||
},
|
||||
Section {
|
||||
title: "Coverage for the new shape",
|
||||
rationale: "Adds parse-failure and round-trip cases the old string type could not express.",
|
||||
kind: ChapterKind::Test,
|
||||
directory: "crates/luxe-core/tests",
|
||||
files: 9,
|
||||
hunks: 6,
|
||||
noise: NoiseKind::Semantic,
|
||||
},
|
||||
Section {
|
||||
title: "Docs and configuration",
|
||||
rationale: "Documents the category contract and its configuration surface.",
|
||||
kind: ChapterKind::Supporting,
|
||||
directory: "docs/notifications",
|
||||
files: 5,
|
||||
hunks: 3,
|
||||
noise: NoiseKind::Semantic,
|
||||
},
|
||||
Section {
|
||||
title: "Formatter churn",
|
||||
rationale: "Whitespace the formatter rewrote while the real change was being made.",
|
||||
kind: ChapterKind::Supporting,
|
||||
directory: "crates/luxe-providers/src",
|
||||
files: 5,
|
||||
hunks: 4,
|
||||
noise: NoiseKind::FormattingOnly,
|
||||
},
|
||||
Section {
|
||||
title: "Generated and mechanical",
|
||||
rationale: "Regenerated schema output and lockfile movement.",
|
||||
kind: ChapterKind::Generated,
|
||||
directory: "generated",
|
||||
files: 4,
|
||||
hunks: 3,
|
||||
noise: NoiseKind::Generated,
|
||||
},
|
||||
];
|
||||
|
||||
let mut files: Vec<ReviewFile> = Vec::new();
|
||||
let mut chapters: Vec<ReviewChapter> = Vec::new();
|
||||
|
||||
for section in &SECTIONS {
|
||||
let mut items = Vec::new();
|
||||
for index in 0..section.files {
|
||||
let path = PathBuf::from(format!("{}/module_{index}.rs", section.directory));
|
||||
let id = FileId::from_path_lineage(None, Some(&path));
|
||||
let hunks: Vec<ReviewHunk> = (0..section.hunks)
|
||||
.map(|hunk_index| {
|
||||
let start = 12 + hunk_index as u32 * 40;
|
||||
ReviewHunk {
|
||||
id: HunkId::from_content(
|
||||
&id,
|
||||
&format!("{}-{index}-{hunk_index}", section.directory),
|
||||
"changed",
|
||||
),
|
||||
old_range: LineRange::new(start, 4),
|
||||
new_range: LineRange::new(start, 5),
|
||||
heading: Some(format!("fn handle_{hunk_index}")),
|
||||
symbol: None,
|
||||
lines: large_hunk_lines(start),
|
||||
noise: section.noise,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
items.extend(hunks.iter().map(|hunk| ReviewItemRef::Hunk(hunk.id.clone())));
|
||||
files.push(ReviewFile {
|
||||
id,
|
||||
old_path: None,
|
||||
new_path: Some(path),
|
||||
status: ReviewFileStatus::Modified,
|
||||
language: Some("rust".into()),
|
||||
additions: Some(section.hunks as u64 * 2),
|
||||
deletions: Some(section.hunks as u64),
|
||||
hunks,
|
||||
binary: false,
|
||||
generated: section.noise == NoiseKind::Generated,
|
||||
non_text: None,
|
||||
});
|
||||
}
|
||||
chapters.push(ReviewChapter {
|
||||
id: ChapterId::from_item_keys(
|
||||
section.title,
|
||||
&items
|
||||
.iter()
|
||||
.map(|item| match item {
|
||||
ReviewItemRef::Hunk(id) => id.as_str(),
|
||||
ReviewItemRef::File(id) => id.as_str(),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
title: section.title.into(),
|
||||
rationale: section.rationale.into(),
|
||||
impact: None,
|
||||
kind: section.kind,
|
||||
// One sentence per item, as a real guide writes them.
|
||||
notes: items
|
||||
.iter()
|
||||
.map(|item| luxe_core::guided_review::ItemNote {
|
||||
item: match item {
|
||||
ReviewItemRef::Hunk(id) => id.as_str().to_owned(),
|
||||
ReviewItemRef::File(id) => id.as_str().to_owned(),
|
||||
},
|
||||
note: format!("Part of {}: {}", section.title, section.rationale),
|
||||
})
|
||||
.collect(),
|
||||
items,
|
||||
});
|
||||
}
|
||||
|
||||
// The awkward cases: a rename with no text change, and a binary asset.
|
||||
let renamed_path = PathBuf::from("crates/luxe-tui/src/themes/rose-pine.json");
|
||||
let renamed = ReviewFile {
|
||||
id: FileId::from_path_lineage(
|
||||
Some(Path::new("crates/luxe-tui/themes/rose-pine.json")),
|
||||
Some(&renamed_path),
|
||||
),
|
||||
old_path: Some("crates/luxe-tui/themes/rose-pine.json".into()),
|
||||
new_path: Some(renamed_path),
|
||||
status: ReviewFileStatus::Renamed,
|
||||
language: Some("json".into()),
|
||||
additions: Some(0),
|
||||
deletions: Some(0),
|
||||
hunks: Vec::new(),
|
||||
binary: false,
|
||||
generated: false,
|
||||
non_text: Some(NonTextChange {
|
||||
kind: NonTextChangeKind::Rename,
|
||||
summary: "Renamed with no content change".into(),
|
||||
}),
|
||||
};
|
||||
let binary_path = PathBuf::from("assets/notification.png");
|
||||
let binary = ReviewFile {
|
||||
id: FileId::from_path_lineage(None, Some(&binary_path)),
|
||||
old_path: None,
|
||||
new_path: Some(binary_path),
|
||||
status: ReviewFileStatus::Added,
|
||||
language: None,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
hunks: Vec::new(),
|
||||
binary: true,
|
||||
generated: false,
|
||||
non_text: Some(NonTextChange {
|
||||
kind: NonTextChangeKind::Binary,
|
||||
summary: "Binary files differ".into(),
|
||||
}),
|
||||
};
|
||||
if let Some(chapter) = chapters.last_mut() {
|
||||
chapter.items.push(ReviewItemRef::File(renamed.id.clone()));
|
||||
chapter.items.push(ReviewItemRef::File(binary.id.clone()));
|
||||
}
|
||||
files.push(renamed);
|
||||
files.push(binary);
|
||||
|
||||
let revision_id = ReviewRevisionId::from_canonical_bytes(b"fixture large guided review");
|
||||
GuidedReview {
|
||||
conversation: None,
|
||||
id: ReviewId::new(),
|
||||
revision_id: revision_id.clone(),
|
||||
target: ReviewTarget::WorkingTree,
|
||||
source: ReviewSource {
|
||||
base: ReviewBase::Head { oid: "0".repeat(40) },
|
||||
includes_staged: true,
|
||||
includes_unstaged: true,
|
||||
included_untracked_files: 1,
|
||||
captured_at_ms: 1,
|
||||
..fixture_source(revision_id)
|
||||
},
|
||||
context: luxe_core::guided_review::ReviewContext::bounded(
|
||||
"Type-safe notification categories",
|
||||
Some("Make notification categories type-safe across both clients"),
|
||||
None,
|
||||
None::<&str>,
|
||||
None::<&str>,
|
||||
None::<&str>,
|
||||
),
|
||||
stats: ReviewStats::from_files(&files),
|
||||
files,
|
||||
chapters,
|
||||
checks: luxe_core::guided_review::CheckSummary::default(),
|
||||
generated_at_ms: 2,
|
||||
insight: None,
|
||||
provenance: Some(fixture_turn_provenance()),
|
||||
seen: None,
|
||||
brief: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A short realistic hunk body: context, a replacement, and an addition.
|
||||
fn large_hunk_lines(start: u32) -> Vec<ReviewLine> {
|
||||
vec![
|
||||
ReviewLine {
|
||||
old_line: Some(start),
|
||||
new_line: Some(start),
|
||||
kind: ReviewLineKind::Context,
|
||||
text: " let category = notification.category();".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: Some(start + 1),
|
||||
new_line: None,
|
||||
kind: ReviewLineKind::Deletion,
|
||||
text: " let label: String = category.to_string();".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: None,
|
||||
new_line: Some(start + 1),
|
||||
kind: ReviewLineKind::Addition,
|
||||
text: " let label = category.display_name();".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: None,
|
||||
new_line: Some(start + 2),
|
||||
kind: ReviewLineKind::Addition,
|
||||
text: " debug_assert!(!label.is_empty());".into(),
|
||||
},
|
||||
ReviewLine {
|
||||
old_line: Some(start + 2),
|
||||
new_line: Some(start + 3),
|
||||
kind: ReviewLineKind::Context,
|
||||
text: " emit(label);".into(),
|
||||
},
|
||||
]
|
||||
}
|
||||
57
crates/luxe-tui/src/fixture/light-theme.json
Normal file
57
crates/luxe-tui/src/fixture/light-theme.json
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "light-fixture",
|
||||
"vars": {
|
||||
"bg": "#eff1f5",
|
||||
"fg": "#4c4f69",
|
||||
"muted": "#6c6f85",
|
||||
"dim": "#acb0be",
|
||||
"accent": "#1e66f5",
|
||||
"accentSecondary": "#8839ef",
|
||||
"magenta": "#ea76cb",
|
||||
"info": "#209fb5",
|
||||
"success": "#40a02b",
|
||||
"error": "#d20f39",
|
||||
"warning": "#df8e1d",
|
||||
"border": "#ccd0da",
|
||||
"bgRaised": "#dce0e8"
|
||||
},
|
||||
"colors": {
|
||||
"accent": "accent",
|
||||
"accentSecondary": "accentSecondary",
|
||||
"info": "info",
|
||||
"border": "border",
|
||||
"borderAccent": "accent",
|
||||
"borderMuted": "dim",
|
||||
"success": "success",
|
||||
"error": "error",
|
||||
"warning": "warning",
|
||||
"muted": "muted",
|
||||
"dim": "dim",
|
||||
"text": "fg",
|
||||
"thinkingText": "muted",
|
||||
"thinkingOff": "muted",
|
||||
"thinkingMinimal": "fg",
|
||||
"thinkingLow": "warning",
|
||||
"thinkingMedium": "success",
|
||||
"thinkingHigh": "accent",
|
||||
"thinkingXHigh": "accentSecondary",
|
||||
"thinkingUltra": "magenta",
|
||||
"pasteIndicatorBg": "dim",
|
||||
"selectedBg": "dim",
|
||||
"background": "bg",
|
||||
"userMsgBg": "bgRaised",
|
||||
"toolCallBg": "bgRaised",
|
||||
"toolBg": "bg",
|
||||
"toolTitle": "accent",
|
||||
"toolOutput": "fg",
|
||||
"mdHeading": "accent",
|
||||
"mdLink": "accent",
|
||||
"mdLinkUrl": "muted",
|
||||
"mdCode": "warning",
|
||||
"mdCodeBlock": "bg",
|
||||
"mdCodeBlockBorder": "border",
|
||||
"mdQuote": "muted",
|
||||
"diffAddBg": "#c9dfc9",
|
||||
"diffDelBg": "#e9bfcc"
|
||||
}
|
||||
}
|
||||
223
crates/luxe-tui/src/fixture/mention.rs
Normal file
223
crates/luxe-tui/src/fixture/mention.rs
Normal file
@@ -0,0 +1,223 @@
|
||||
//! Fixture mentions — the `@` picker seeded on a tab, with project files and MCP servers.
|
||||
|
||||
use crate::app::App;
|
||||
use luxe_core::WorkspaceSnapshot;
|
||||
|
||||
/// A snapshot naming four MCP servers: signed in, signed out, never discovered, and a local one.
|
||||
fn seed_mcp_servers(app: &mut App) {
|
||||
use luxe_core::workspace::{ProjectIdentity, WorkspaceScopeId};
|
||||
let server = |id: &str, transport: &str, tools: Option<usize>, signed_in: Option<bool>| {
|
||||
luxe_core::McpServerStatus {
|
||||
id: id.into(),
|
||||
transport: transport.into(),
|
||||
auth: if signed_in.is_some() { "oauth" } else { "none" }.into(),
|
||||
tool_count: tools,
|
||||
enabled: true,
|
||||
tools: (0..tools.unwrap_or(0)).map(|n| format!("tool_{n}")).collect(),
|
||||
signed_in,
|
||||
}
|
||||
};
|
||||
let mut snapshot = WorkspaceSnapshot::empty(
|
||||
WorkspaceScopeId::new("fixture"),
|
||||
ProjectIdentity::non_git("/project".into(), "project", "/project"),
|
||||
);
|
||||
snapshot.tooling.mcp_servers = vec![
|
||||
server("asana", "http", Some(22), Some(true)),
|
||||
server("linear", "http", Some(31), Some(false)),
|
||||
server("sentry", "http", None, None),
|
||||
server("chrome-devtools", "stdio", Some(26), None),
|
||||
];
|
||||
app.workspace = Some(snapshot);
|
||||
}
|
||||
|
||||
/// A fixed project for the Files tab: luxe-shaped paths, a few dotfiles, and three changed files.
|
||||
fn seed_project_files(app: &mut App) {
|
||||
use luxe_core::workspace::{
|
||||
FileChangeStatus, FileChangeSummary, ProjectIdentity, WorkspaceScopeId,
|
||||
};
|
||||
let files = [
|
||||
".cargo/mutants.toml",
|
||||
".config/nextest.toml",
|
||||
".github/workflows/ci.yml",
|
||||
".gitignore",
|
||||
"CONTRIBUTING.md",
|
||||
"Cargo.toml",
|
||||
"README.md",
|
||||
"crates/luxe-core/src/mcp_client.rs",
|
||||
"crates/luxe-core/src/output_limit.rs",
|
||||
"crates/luxe-mcp/src/oauth.rs",
|
||||
"crates/luxe-tui/src/mention_flyout.rs",
|
||||
"crates/luxe-tui/src/picker.rs",
|
||||
"crates/luxe-tui/src/ref_provider.rs",
|
||||
"crates/luxe-tui/src/slash_flyout.rs",
|
||||
"crates/luxe-tui/tests/mention_flyout_render.rs",
|
||||
"docs/guide/interface.md",
|
||||
"docs/guide/mcp.md",
|
||||
];
|
||||
app.file_provider =
|
||||
crate::ref_provider::FileRefProvider::with_files(files.iter().map(|f| (*f).to_string()));
|
||||
let changed = |path: &str, status| FileChangeSummary {
|
||||
path: path.into(),
|
||||
status,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
binary: false,
|
||||
};
|
||||
let mut snapshot = WorkspaceSnapshot::empty(
|
||||
WorkspaceScopeId::new("fixture"),
|
||||
ProjectIdentity::non_git("/project".into(), "project", "/project"),
|
||||
);
|
||||
snapshot.changes.files = vec![
|
||||
changed("crates/luxe-tui/src/picker.rs", FileChangeStatus::Modified),
|
||||
changed("crates/luxe-tui/src/ref_provider.rs", FileChangeStatus::Modified),
|
||||
changed("crates/luxe-tui/tests/mention_flyout_render.rs", FileChangeStatus::Untracked),
|
||||
];
|
||||
snapshot.changes.total_files = 3;
|
||||
app.workspace = Some(snapshot);
|
||||
}
|
||||
|
||||
/// Opens the `@` picker for screenshot review: `files`, `skills`, `github` with a few rows,
|
||||
/// `github-signed-out` as `gh` answers before `gh auth login`, `mcp` with a server in each state
|
||||
/// its row can report, or `jira`, a source of the reader's own.
|
||||
///
|
||||
/// `files-working`, `files-status` and `files-query` are the Files tab over a fixed project with
|
||||
/// three files in progress: as it opens, the same with each changed file's Git status beside it,
|
||||
/// and a search for `flyout` lighting what matched and trimming long paths from the folder.
|
||||
pub fn seed_mention_picker(app: &mut App, tab: &str) {
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use luxe_core::github::{ListItem, PullRequestState};
|
||||
let key = |code| crate::app::Msg::Key(KeyEvent::new(code, KeyModifiers::NONE));
|
||||
// A fixture app has no project indexed; the working directory stands in for one
|
||||
app.file_provider =
|
||||
crate::ref_provider::FileRefProvider::new(&std::env::current_dir().unwrap_or_default());
|
||||
// A source of the reader's own, so the tabs show a third
|
||||
app.config.mentions = vec![luxe_core::config::MentionSource {
|
||||
name: "Jira".into(),
|
||||
kind: None,
|
||||
command: "jira-mentions".into(),
|
||||
args: Vec::new(),
|
||||
icon: Some("\u{f0303}".into()),
|
||||
}];
|
||||
if tab == "mcp" {
|
||||
seed_mcp_servers(app);
|
||||
}
|
||||
let fixed_files = tab.starts_with("files-");
|
||||
if fixed_files {
|
||||
seed_project_files(app);
|
||||
}
|
||||
app.update(key(KeyCode::Char('@')));
|
||||
if tab == "files-status" {
|
||||
if let Some(mention) = app.overlays.mention.as_mut() {
|
||||
mention.show_status();
|
||||
}
|
||||
}
|
||||
if tab == "files-query" {
|
||||
for character in "flyout".chars() {
|
||||
app.update(key(KeyCode::Char(character)));
|
||||
}
|
||||
}
|
||||
if tab == "files" || fixed_files {
|
||||
return;
|
||||
}
|
||||
if tab == "mcp" {
|
||||
// Back past Jira, which asks for its rows, to MCP, which never does
|
||||
app.update(key(KeyCode::BackTab));
|
||||
app.outbox.mention_source = None;
|
||||
app.update(key(KeyCode::BackTab));
|
||||
return;
|
||||
}
|
||||
if tab == "jira" {
|
||||
app.update(key(KeyCode::BackTab));
|
||||
app.outbox.mention_source = None;
|
||||
let row = |id: &str, label: &str, status: &str| luxe_core::mention_source::MentionRow {
|
||||
id: id.into(),
|
||||
label: format!("{id} {label}"),
|
||||
detail: Some(status.into()),
|
||||
text: format!("Jira issue {id} \"{label}\" ({status})"),
|
||||
};
|
||||
if let Some(mention) = app.overlays.mention.as_mut() {
|
||||
mention.set_source(
|
||||
"jira",
|
||||
Ok(vec![
|
||||
row("NOTIFY-41", "Webhook categories arrive as free text", "In progress"),
|
||||
row("NOTIFY-38", "Digest drops the deploy category", "To do"),
|
||||
row(
|
||||
"NOTIFY-35",
|
||||
"Document the category enum for the Swift client",
|
||||
"In review",
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if tab == "skills" {
|
||||
// Skills fixed for review, rather than whatever this machine has installed
|
||||
let skill = |name: &str, description: &str| luxe_core::skills::SkillDoc {
|
||||
name: name.into(),
|
||||
description: description.into(),
|
||||
path: std::path::PathBuf::from(format!("~/.config/luxe/skills/{name}/SKILL.md")),
|
||||
};
|
||||
let cwd = std::env::current_dir().unwrap_or_default();
|
||||
app.overlays.mention = Some(crate::mention_flyout::MentionFlyoutState::new(
|
||||
app.file_provider.clone(),
|
||||
cwd,
|
||||
&app.config.mentions,
|
||||
vec![
|
||||
skill("gh-stack", "Manage stacked branches and pull requests with gh stack"),
|
||||
skill("webapp-testing", "Test a local web app with Playwright: screenshots, logs"),
|
||||
skill("release-notes", "Write the release notes for a tag from its merged PRs"),
|
||||
],
|
||||
&[],
|
||||
));
|
||||
app.update(key(KeyCode::Tab));
|
||||
return;
|
||||
}
|
||||
// Past Skills to GitHub
|
||||
app.update(key(KeyCode::Tab));
|
||||
app.update(key(KeyCode::Tab));
|
||||
let row = |pull_request: bool, number: u64, title: &str, state| ListItem {
|
||||
pull_request,
|
||||
number,
|
||||
title: title.into(),
|
||||
url: format!("https://github.com/acme/notify/pull/{number}"),
|
||||
repository: "acme/notify".into(),
|
||||
author: "mara-okafor".into(),
|
||||
draft: number == 181,
|
||||
updated_at: String::new(),
|
||||
state,
|
||||
facts: None,
|
||||
};
|
||||
let (rows, error) = match tab {
|
||||
"github-signed-out" => (
|
||||
Vec::new(),
|
||||
Some(
|
||||
"The GitHub CLI is not signed in. Run `gh auth login` in a terminal, then try \
|
||||
again."
|
||||
.to_string(),
|
||||
),
|
||||
),
|
||||
_ => (
|
||||
vec![
|
||||
row(
|
||||
true,
|
||||
182,
|
||||
"Parse notification categories into an enum",
|
||||
PullRequestState::Open,
|
||||
),
|
||||
row(true, 181, "Route digests by category", PullRequestState::Open),
|
||||
row(true, 176, "Drop the legacy formatter", PullRequestState::Merged),
|
||||
row(
|
||||
false,
|
||||
318,
|
||||
"A typo in a webhook creates a phantom category",
|
||||
PullRequestState::Open,
|
||||
),
|
||||
],
|
||||
None,
|
||||
),
|
||||
};
|
||||
if let Some(mention) = app.overlays.mention.as_mut() {
|
||||
mention.set_github(rows, error);
|
||||
}
|
||||
}
|
||||
47
crates/luxe-tui/src/fixture/models.rs
Normal file
47
crates/luxe-tui/src/fixture/models.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
//! Fixture models — the catalog a seeded app picks from, without a provider behind it.
|
||||
|
||||
/// The fixture's active model: reasons, tops out at High — the shape of an extended-thinking Claude.
|
||||
/// A few models for the picker the Configuration surface hands a finished login to.
|
||||
pub(super) fn configurable_models() -> Vec<crate::model_picker::ModelEntry> {
|
||||
[
|
||||
("openai", "gpt-5.6", "GPT-5.6"),
|
||||
("openai", "gpt-5.6-mini", "GPT-5.6 mini"),
|
||||
("anthropic", "claude-sonnet-5", "Claude Sonnet 5"),
|
||||
("lmstudio", "qwen3-coder-30b", "Qwen3 Coder 30B"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(provider, id, label)| crate::model_picker::ModelEntry {
|
||||
info: luxe_core::provider::ModelInfo {
|
||||
r#ref: luxe_core::provider::ModelRef::new(provider, id),
|
||||
display_name: Some(label.into()),
|
||||
context_window: 200_000,
|
||||
..Default::default()
|
||||
},
|
||||
label: label.into(),
|
||||
configured: true,
|
||||
unverified: false,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(super) fn fixture_model() -> luxe_core::provider::ModelInfo {
|
||||
luxe_core::provider::ModelInfo {
|
||||
r#ref: luxe_core::provider::ModelRef::new("lmstudio", "qwen3.8-27b"),
|
||||
display_name: Some("Qwen3.8 27B".into()),
|
||||
reasoning: true,
|
||||
context_window: 262_144,
|
||||
thinking_level_map: std::collections::HashMap::from([
|
||||
("minimal".into(), Some("minimal".into())),
|
||||
("low".into(), Some("low".into())),
|
||||
("medium".into(), Some("medium".into())),
|
||||
("high".into(), Some("high".into())),
|
||||
("xhigh".into(), None),
|
||||
("ultra".into(), None),
|
||||
]),
|
||||
thinking_controls: luxe_core::provider::ThinkingControls {
|
||||
effort: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
58
crates/luxe-tui/src/fixture/peek.rs
Normal file
58
crates/luxe-tui/src/fixture/peek.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
//! Fixture peek — the changes pane on a file's text, filtered and focused.
|
||||
|
||||
use crate::app::App;
|
||||
|
||||
/// Seed a subscription's remaining allowance, so the statusline's plan meter can be reviewed.
|
||||
///
|
||||
/// Real values, copied from a live ChatGPT Plus response: a weekly window with a reset days out.
|
||||
/// Opens `path` in the Changes pane's File view with `text` as its content, and `pick` as the
|
||||
/// lines picked in it, for reviewing the File view without an engine to read the file.
|
||||
pub fn seed_file_view(app: &mut App, path: &str, text: &str, pick: Option<(u32, u32)>) {
|
||||
let files = crate::app::messages::changes::changed_files(app);
|
||||
let mut view = crate::changes::ChangesView::new(path.to_string(), files);
|
||||
view.view = crate::changes::PeekView::File;
|
||||
view.text = crate::changes::TextLoad::Ready(Box::new(luxe_core::project_files::ProjectFile {
|
||||
path: path.to_string(),
|
||||
text: text.to_string(),
|
||||
bytes: text.len() as u64,
|
||||
truncated: false,
|
||||
binary: false,
|
||||
}));
|
||||
view.selection = pick;
|
||||
view.scroll = pick.map_or(0, |(first, _)| first.saturating_sub(8) as usize);
|
||||
view.scroll_max.set(usize::MAX);
|
||||
app.changes = Some(view);
|
||||
app.files.reveal(path);
|
||||
app.files.cursor = Some(path.to_string());
|
||||
}
|
||||
|
||||
/// Puts the preview in visual-line mode from `from` to `to`, keyboard and all.
|
||||
pub fn preview_visual(app: &mut App, from: u32, to: u32) {
|
||||
focus_preview(app, Some(from));
|
||||
if let Some(view) = app.changes.as_mut() {
|
||||
// What a first frame would have measured, so the move scrolls as it would on screen
|
||||
view.viewport_rows.set(30);
|
||||
view.toggle_visual();
|
||||
view.move_cursor(i64::from(to) - i64::from(from), false);
|
||||
}
|
||||
}
|
||||
|
||||
/// Filters the tree by `query` over `files`, keyboard in it and still typing.
|
||||
pub fn filter_tree(app: &mut App, files: &[String], query: &str) {
|
||||
app.update(crate::app::Msg::FocusFiles);
|
||||
app.files.set_project_files(files);
|
||||
app.files.open_filter();
|
||||
for character in query.chars() {
|
||||
app.files.edit_filter(Some(character));
|
||||
}
|
||||
let changes = crate::app::messages::files::changed(app);
|
||||
app.files.cursor = app.files.hits(&changes).best.clone();
|
||||
}
|
||||
|
||||
/// Puts the keyboard in the preview, its cursor on `line` when given.
|
||||
pub fn focus_preview(app: &mut App, line: Option<u32>) {
|
||||
app.update(crate::app::Msg::FocusPeek);
|
||||
if let (Some(view), Some(line)) = (app.changes.as_mut(), line) {
|
||||
view.cursor = Some(line);
|
||||
}
|
||||
}
|
||||
135
crates/luxe-tui/src/fixture/pull_request.rs
Normal file
135
crates/luxe-tui/src/fixture/pull_request.rs
Normal file
@@ -0,0 +1,135 @@
|
||||
//! The pull request review — someone else's change, with its context and the threads on it.
|
||||
|
||||
use super::demo::fixture_demo_guided_review;
|
||||
use luxe_core::guided_review::{GuidedReview, ReviewTarget};
|
||||
|
||||
/// The review the demos walk. See [`DEMO_CHANGE`] for why it is not the small one.
|
||||
/// The demos' change as a pull request: opened by a bot, one check failing, changes requested, and
|
||||
/// an issue it closes. No session provenance, because a pull request was not this session's work.
|
||||
pub fn fixture_pull_request_review() -> GuidedReview {
|
||||
use luxe_core::guided_review::{
|
||||
LinkedIssue, PullRequestChecks, PullRequestContext, PullRequestStatus, PullRequestVerdict,
|
||||
};
|
||||
let mut review = fixture_demo_guided_review();
|
||||
review.target = ReviewTarget::PullRequest { number: 42, repository: None };
|
||||
review.source.base = luxe_core::guided_review::ReviewBase::PullRequest {
|
||||
number: 42,
|
||||
repository: "acme/notify".into(),
|
||||
base_ref: "main".into(),
|
||||
head_ref: "copilot/category-enum".into(),
|
||||
merge_base: "4f1c2d9a7e6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d".into(),
|
||||
head_oid: "a9d9d84ee3e848f0e1ea97eaef837126d3a7d983".into(),
|
||||
};
|
||||
review.provenance = None;
|
||||
review.context.goal = None;
|
||||
review.context.title = "Parse notification categories into an enum".into();
|
||||
review.context.pull_request = Some(PullRequestContext {
|
||||
number: 42,
|
||||
repository: "acme/notify".into(),
|
||||
url: "https://github.com/acme/notify/pull/42".into(),
|
||||
title: "Parse notification categories into an enum".into(),
|
||||
body: "Categories arrived as free-form strings, so a typo in a webhook became a new \
|
||||
category nobody routed. This parses them once at the edge and makes the router \
|
||||
match exhaustively.\n\n- `Category` replaces `String` in the model\n- unknown \
|
||||
categories are rejected with a 422"
|
||||
.into(),
|
||||
author: "app/copilot-swe-agent".into(),
|
||||
author_is_bot: true,
|
||||
draft: false,
|
||||
status: PullRequestStatus::Open,
|
||||
verdict: Some(PullRequestVerdict::ChangesRequested),
|
||||
checks: PullRequestChecks { passed: 11, failed: 1, pending: 0, skipped: 2 },
|
||||
base_ref: "main".into(),
|
||||
head_ref: "copilot/category-enum".into(),
|
||||
closing_issues: vec![LinkedIssue {
|
||||
repository: "acme/notify".into(),
|
||||
number: 318,
|
||||
title: Some("A typo in a webhook creates a phantom category".into()),
|
||||
excerpt: String::new(),
|
||||
}],
|
||||
more_closing_issues: 0,
|
||||
});
|
||||
// Through the same placement the engine uses, so the fixture draws what a real one would
|
||||
let comment = |author: &str, body: &str| luxe_core::github::ThreadComment {
|
||||
author: author.into(),
|
||||
body: body.into(),
|
||||
created_at: String::new(),
|
||||
url: String::new(),
|
||||
};
|
||||
let thread = |path: &str, line, outdated, resolved, file_level, comments: Vec<_>| {
|
||||
luxe_core::github::ReviewThread {
|
||||
path: path.into(),
|
||||
line,
|
||||
start_line: None,
|
||||
side: luxe_core::github::ThreadSide::Right,
|
||||
outdated,
|
||||
resolved,
|
||||
file_level,
|
||||
id: format!("thread-{path}-{line:?}"),
|
||||
anchor_text: None,
|
||||
can_reply: true,
|
||||
can_resolve: true,
|
||||
total_comments: comments.len(),
|
||||
comments,
|
||||
}
|
||||
};
|
||||
review.conversation = Some(luxe_core::guided_review::earlier_conversation(
|
||||
&review.files,
|
||||
luxe_core::github::ReviewThreads {
|
||||
threads: vec![
|
||||
thread(
|
||||
"src/notification.rs",
|
||||
Some(13),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
vec![
|
||||
comment(
|
||||
"mara-okafor",
|
||||
"Does anything still construct this from a raw string?",
|
||||
),
|
||||
comment("app/copilot-swe-agent", "Only the webhook, and it parses first."),
|
||||
],
|
||||
),
|
||||
thread(
|
||||
"src/dispatch/router.rs",
|
||||
None,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
vec![comment("mara-okafor", "This match used to fall through to the digest.")],
|
||||
),
|
||||
thread(
|
||||
"src/api/webhook.rs",
|
||||
None,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
vec![comment("jon-avery", "Worth a 422 test for an empty category.")],
|
||||
),
|
||||
],
|
||||
total: 3,
|
||||
conversation: vec![
|
||||
luxe_core::github::ConversationComment {
|
||||
id: "IC_kwDOA1".into(),
|
||||
author: "codecov".into(),
|
||||
bot: true,
|
||||
mine: false,
|
||||
body: "Coverage 91.2% (+0.4%)".into(),
|
||||
created_at: "2026-05-02T09:00:00Z".into(),
|
||||
url: "https://github.com/acme/notify/pull/42#issuecomment-1".into(),
|
||||
},
|
||||
luxe_core::github::ConversationComment {
|
||||
id: "IC_kwDOA2".into(),
|
||||
author: "jon-avery".into(),
|
||||
bot: false,
|
||||
mine: false,
|
||||
body: "Could the changelog mention the new 422?".into(),
|
||||
created_at: "2026-05-02T10:00:00Z".into(),
|
||||
url: "https://github.com/acme/notify/pull/42#issuecomment-2".into(),
|
||||
},
|
||||
],
|
||||
},
|
||||
));
|
||||
review
|
||||
}
|
||||
134
crates/luxe-tui/src/fixture/review.rs
Normal file
134
crates/luxe-tui/src/fixture/review.rs
Normal file
@@ -0,0 +1,134 @@
|
||||
//! Guided Review fixtures — the review surface at each width and stage.
|
||||
//!
|
||||
//! Every scenario here builds on the same pinned review source and then varies one thing: the
|
||||
//! width, the mode, which findings exist, or whether a refresh is in flight. Sharing the source is
|
||||
//! what makes two review screenshots comparable.
|
||||
|
||||
mod findings;
|
||||
mod stages;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Seeds `app` for a review scenario, reporting whether this family owns it.
|
||||
///
|
||||
/// `Ok(false)` means another family does — the caller tries the next one. An `Err` is a fixture
|
||||
/// that claimed the scenario and then could not build it, which is a bug in the fixture.
|
||||
pub(super) fn seed(app: &mut App, scenario: FixtureScenario) -> Result<bool, String> {
|
||||
match scenario {
|
||||
FixtureScenario::GuidedReviewError => seed_error(app),
|
||||
FixtureScenario::GuidedReviewReady
|
||||
| FixtureScenario::GuidedReviewBrief
|
||||
| FixtureScenario::GuidedReviewSend
|
||||
| FixtureScenario::GuidedReviewCommit
|
||||
| FixtureScenario::GuidedReviewOpenPullRequest
|
||||
| FixtureScenario::GuidedReviewOpenStack
|
||||
| FixtureScenario::GuidedReviewThread
|
||||
| FixtureScenario::GuidedReviewWide
|
||||
| FixtureScenario::GuidedReviewFindingsEmpty
|
||||
| FixtureScenario::GuidedReviewFindings
|
||||
| FixtureScenario::GuidedReviewNeedsVerification
|
||||
| FixtureScenario::GuidedReviewFinish
|
||||
| FixtureScenario::GuidedReviewMedium
|
||||
| FixtureScenario::GuidedReviewNarrow
|
||||
| FixtureScenario::GuidedReviewSplit => findings::seed_working_tree_review(app, scenario)?,
|
||||
FixtureScenario::GuidedReviewDemo | FixtureScenario::GuidedReviewGuideHidden => {
|
||||
seed_demo(app, scenario)
|
||||
}
|
||||
FixtureScenario::GuidedReviewPullRequest
|
||||
| FixtureScenario::GuidedReviewPullRequestPost
|
||||
| FixtureScenario::GuidedReviewFixPullRequest => stages::seed_pull_request(app, scenario)?,
|
||||
FixtureScenario::GuidedReviewOwnPullRequest => stages::seed_own_pull_request(app)?,
|
||||
FixtureScenario::GuidedReviewLarge => seed_large(app),
|
||||
FixtureScenario::GuidedReviewNoise => seed_noise(app),
|
||||
FixtureScenario::GuidedReviewRefreshing => seed_refreshing(app),
|
||||
_ => return Ok(false),
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Guided Review source failure rendered through the production event reducer.
|
||||
fn seed_error(app: &mut App) {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Capturing the current working tree for Guided Review.".into(),
|
||||
));
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewFailed {
|
||||
request_id,
|
||||
target: ReviewTarget::WorkingTree,
|
||||
error: GuidedReviewFailure {
|
||||
kind: GuidedReviewFailureKind::Capture,
|
||||
message: "Could not capture a complete immutable working-tree source.".into(),
|
||||
},
|
||||
}));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// The `GuidedReviewDemo` and `GuidedReviewGuideHidden` scenarios.
|
||||
fn seed_demo(app: &mut App, scenario: FixtureScenario) {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id,
|
||||
review: Box::new(super::fixture_demo_guided_review()),
|
||||
}));
|
||||
app.guided_review_workspace.guide_visible =
|
||||
scenario != FixtureScenario::GuidedReviewGuideHidden;
|
||||
// The demo's chapter prose and brief are model-shaped, so the surface has to say the
|
||||
// model wrote them. Left unset it would claim to still be writing, over prose that is
|
||||
// already there.
|
||||
app.review.provenance = Some(luxe_core::guided_review::GuideProvenance::Model { batches: 1 });
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
fn seed_large(app: &mut App) {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id,
|
||||
review: Box::new(fixture_large_guided_review()),
|
||||
}));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// Guided Review with an initially folded formatting hunk.
|
||||
fn seed_noise(app: &mut App) {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id,
|
||||
review: Box::new(fixture_guided_review_with_noise()),
|
||||
}));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
|
||||
/// In-flight Guided Review refresh rendered through the production event reducer.
|
||||
fn seed_refreshing(app: &mut App) {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Captured the current working tree for Guided Review.".into(),
|
||||
));
|
||||
let ready_request = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(ready_request.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id: ready_request,
|
||||
review: Box::new(fixture_guided_review()),
|
||||
}));
|
||||
let refresh_request = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(refresh_request.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoading {
|
||||
request_id: refresh_request,
|
||||
target: ReviewTarget::WorkingTree,
|
||||
}));
|
||||
// The refresh fixture is about the diff staying visible, so it opens on it.
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
}
|
||||
172
crates/luxe-tui/src/fixture/review/findings.rs
Normal file
172
crates/luxe-tui/src/fixture/review/findings.rs
Normal file
@@ -0,0 +1,172 @@
|
||||
//! Review triage fixtures — comments in each of their states, a thread, and a line comment on the
|
||||
//! working-tree review.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The working-tree review the triage and stage scenarios share: loaded, laid out, with its
|
||||
/// feedback window open where the scenario is about feedback, then each scenario's own layer.
|
||||
pub(super) fn seed_working_tree_review(
|
||||
app: &mut App,
|
||||
scenario: FixtureScenario,
|
||||
) -> Result<(), String> {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Captured the current working tree for Guided Review.".into(),
|
||||
));
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id,
|
||||
review: Box::new(fixture_guided_review()),
|
||||
}));
|
||||
if scenario == FixtureScenario::GuidedReviewSplit {
|
||||
app.guided_review_workspace.layout = luxe_core::config::DiffLayout::Split;
|
||||
}
|
||||
if matches!(
|
||||
scenario,
|
||||
FixtureScenario::GuidedReviewFindingsEmpty
|
||||
| FixtureScenario::GuidedReviewFindings
|
||||
| FixtureScenario::GuidedReviewNeedsVerification
|
||||
) {
|
||||
app.guided_review_workspace.findings_visible = true;
|
||||
}
|
||||
seed_review_findings(app, scenario)?;
|
||||
if scenario == FixtureScenario::GuidedReviewThread {
|
||||
seed_review_thread(app)?;
|
||||
}
|
||||
super::stages::seed_review_stage(app, scenario)?;
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Comments in each state for the triage scenarios, the one in need of verification selected
|
||||
/// where that is the point, and a line comment under the wide review's code.
|
||||
fn seed_review_findings(app: &mut App, scenario: FixtureScenario) -> Result<(), String> {
|
||||
if matches!(
|
||||
scenario,
|
||||
FixtureScenario::GuidedReviewFindings
|
||||
| FixtureScenario::GuidedReviewNeedsVerification
|
||||
| FixtureScenario::GuidedReviewSend
|
||||
| FixtureScenario::GuidedReviewCommit
|
||||
| FixtureScenario::GuidedReviewThread
|
||||
| FixtureScenario::GuidedReviewFinish
|
||||
) {
|
||||
let session = app.review.session_mut().ok_or("missing fixture review session")?;
|
||||
for (title, state, severity) in [
|
||||
("Retry path omits a bounded error", FindingState::Open, FindingSeverity::Blocking),
|
||||
(
|
||||
"Confirm the migration handles old data",
|
||||
FindingState::NeedsVerification,
|
||||
FindingSeverity::Issue,
|
||||
),
|
||||
("Clarify the cancellation behavior", FindingState::Draft, FindingSeverity::Suggestion),
|
||||
("Legacy formatter note", FindingState::Resolved, FindingSeverity::Note),
|
||||
("Original context no longer maps", FindingState::Stale, FindingSeverity::Note),
|
||||
] {
|
||||
session
|
||||
.add_finding(ReviewFinding {
|
||||
posted: None,
|
||||
github_thread: None,
|
||||
id: FindingId::new(),
|
||||
label: String::new(),
|
||||
anchor: FindingAnchor::Review,
|
||||
severity,
|
||||
title: title.into(),
|
||||
body: "Fixture feedback retained for visual triage.".into(),
|
||||
proposed_fix: None,
|
||||
state,
|
||||
thread: Vec::new(),
|
||||
})
|
||||
.map_err(|error| error.to_string())?;
|
||||
}
|
||||
let findings =
|
||||
app.review.session().ok_or("missing fixture review session")?.findings.clone();
|
||||
app.guided_review_workspace.move_finding_selection(&findings, true);
|
||||
if scenario == FixtureScenario::GuidedReviewNeedsVerification {
|
||||
let finding_id = findings
|
||||
.iter()
|
||||
.find(|finding| finding.state == FindingState::NeedsVerification)
|
||||
.map(|finding| finding.id.clone())
|
||||
.ok_or("missing verification fixture finding")?;
|
||||
app.guided_review_workspace.selected_finding_id = Some(finding_id);
|
||||
}
|
||||
}
|
||||
if scenario == FixtureScenario::GuidedReviewWide {
|
||||
// Anchored to a line that is on screen, because that is where a comment renders
|
||||
// now: under the code it is about.
|
||||
if let Some(anchor) = review_line_anchor(app.guided_review.as_deref()) {
|
||||
app.review
|
||||
.session_mut()
|
||||
.ok_or("missing fixture review session")?
|
||||
.add_finding(ReviewFinding {
|
||||
posted: None,
|
||||
github_thread: None,
|
||||
id: FindingId::new(),
|
||||
label: String::new(),
|
||||
anchor,
|
||||
severity: FindingSeverity::Issue,
|
||||
title: "The borrow buys nothing here".into(),
|
||||
body: "Category is Copy and label() returns 'static, so &self is \
|
||||
doing no work \u{2014} take self by value?"
|
||||
.into(),
|
||||
proposed_fix: None,
|
||||
state: FindingState::Draft,
|
||||
thread: Vec::new(),
|
||||
})
|
||||
.map_err(|error| error.to_string())?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A comment the agent claims to have fixed, and the reviewer's answer to it, open in its
|
||||
/// details.
|
||||
fn seed_review_thread(app: &mut App) -> Result<(), String> {
|
||||
let session = app.review.session_mut().ok_or("missing fixture review session")?;
|
||||
let finding_id = session
|
||||
.findings
|
||||
.iter()
|
||||
.find(|finding| finding.state == FindingState::NeedsVerification)
|
||||
.map(|finding| finding.id.clone())
|
||||
.ok_or("missing verification fixture finding")?;
|
||||
if let Some(finding) = session.findings.iter_mut().find(|finding| finding.id == finding_id) {
|
||||
finding.thread.push(luxe_core::guided_review::FindingMessage {
|
||||
author: luxe_core::guided_review::FindingMessageAuthor::Agent,
|
||||
body: "Fixed by bounding the retry loop and returning a typed timeout.".into(),
|
||||
created_at_ms: 1,
|
||||
});
|
||||
}
|
||||
session
|
||||
.append_reviewer_message(
|
||||
&finding_id,
|
||||
"The timeout is bounded now, but the caller still ignores it.".into(),
|
||||
2,
|
||||
)
|
||||
.map_err(|error| error.to_string())?;
|
||||
app.guided_review_workspace.selected_finding_id = Some(finding_id);
|
||||
app.guided_review_workspace.findings_visible = true;
|
||||
app.guided_review_workspace.toggle_finding_details();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A line anchor on the first source line of the first hunk, so a fixture comment lands where the
|
||||
/// reviewer is already looking.
|
||||
pub(super) fn review_line_anchor(
|
||||
review: Option<&luxe_core::guided_review::GuidedReview>,
|
||||
) -> Option<FindingAnchor> {
|
||||
let file = review?.files.first()?;
|
||||
let hunk = file.hunks.first()?;
|
||||
// An addition, so the comment sits under a line the change actually made.
|
||||
let line = hunk
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.kind == luxe_core::guided_review::ReviewLineKind::Addition)?;
|
||||
Some(FindingAnchor::Line {
|
||||
file_id: file.id.clone(),
|
||||
hunk_id: hunk.id.clone(),
|
||||
side: luxe_core::guided_review::DiffSide::New,
|
||||
line: line.new_line?,
|
||||
context_hash: line.context_hash(),
|
||||
})
|
||||
}
|
||||
267
crates/luxe-tui/src/fixture/review/stages.rs
Normal file
267
crates/luxe-tui/src/fixture/review/stages.rs
Normal file
@@ -0,0 +1,267 @@
|
||||
//! Review stage fixtures — the post, opening, stack, fix and answers dialogs, and the pull requests
|
||||
//! they act on.
|
||||
|
||||
use super::findings::review_line_anchor;
|
||||
use super::*;
|
||||
|
||||
/// The dialog a stage scenario is about: the commit, the opening, the stack, the send, or the
|
||||
/// finish with its blocking confirmation armed.
|
||||
pub(super) fn seed_review_stage(app: &mut App, scenario: FixtureScenario) -> Result<(), String> {
|
||||
if scenario == FixtureScenario::GuidedReviewCommit {
|
||||
app.guided_review_workspace.open_commit_preview();
|
||||
}
|
||||
if scenario == FixtureScenario::GuidedReviewOpenPullRequest {
|
||||
open_pull_request(app)?;
|
||||
}
|
||||
if scenario == FixtureScenario::GuidedReviewOpenStack {
|
||||
let layer = |head: &str, base: &str, title: &str| luxe_core::github::NewPullRequest {
|
||||
head: head.into(),
|
||||
base: base.into(),
|
||||
title: title.into(),
|
||||
body: String::new(),
|
||||
draft: false,
|
||||
};
|
||||
app.guided_review_workspace.stack_opening = Some(crate::guided_review::StackOpening {
|
||||
request_id: luxe_core::guided_review::PullRequestOpenId::new(),
|
||||
layers: Some(vec![
|
||||
layer("123-category-enum-part-1", "main", "Shared notification model"),
|
||||
layer("123-category-enum-part-2", "123-category-enum-part-1", "Route by category"),
|
||||
layer("123-category-enum", "123-category-enum-part-2", "Reject unknown categories"),
|
||||
]),
|
||||
draft: false,
|
||||
opening: false,
|
||||
error: None,
|
||||
});
|
||||
}
|
||||
if scenario == FixtureScenario::GuidedReviewSend {
|
||||
app.guided_review_workspace.open_send_preview(None, None);
|
||||
}
|
||||
if scenario == FixtureScenario::GuidedReviewFinish {
|
||||
app.guided_review_workspace.open_finish_review(true);
|
||||
// Land on Accept (Request fixes → Accept and commit → Accept) with the blocking
|
||||
// confirmation armed, which is the state worth screenshotting.
|
||||
app.guided_review_workspace.move_finish_review_choice(false);
|
||||
app.guided_review_workspace.move_finish_review_choice(false);
|
||||
app.guided_review_workspace.confirm_finish_review_accept();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The `GuidedReviewPullRequest`, `GuidedReviewPullRequestPost` and `GuidedReviewFixPullRequest`
|
||||
/// scenarios.
|
||||
pub(super) fn seed_pull_request(app: &mut App, scenario: FixtureScenario) -> Result<(), String> {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id,
|
||||
review: Box::new(super::fixture_pull_request_review()),
|
||||
}));
|
||||
app.review.provenance = Some(luxe_core::guided_review::GuideProvenance::Model { batches: 1 });
|
||||
if scenario == FixtureScenario::GuidedReviewPullRequestPost {
|
||||
pull_request_post(app)?;
|
||||
}
|
||||
if scenario == FixtureScenario::GuidedReviewFixPullRequest {
|
||||
// The comments of the post scenario, offered to the agent in a worktree instead
|
||||
pull_request_post(app)?;
|
||||
app.guided_review_workspace.github_post = None;
|
||||
let comments = app.review.session().map_or(0, |s| s.findings.len());
|
||||
app.guided_review_workspace.pull_request_fix = Some(crate::guided_review::PullRequestFix {
|
||||
number: 42,
|
||||
branch: Some("fix-redirects".into()),
|
||||
refusal: None,
|
||||
comments,
|
||||
});
|
||||
}
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Your own pull request's review, answering its threads on GitHub.
|
||||
pub(super) fn seed_own_pull_request(app: &mut App) -> Result<(), String> {
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
let mut review = super::fixture_pull_request_review();
|
||||
// Your own: the same pull request, compared to the working tree it is fixed in
|
||||
review.target = ReviewTarget::OwnPullRequest { number: 42 };
|
||||
review.source.base = luxe_core::guided_review::ReviewBase::MergeBase {
|
||||
reference: "main".into(),
|
||||
oid: "4f1c2d9a7e6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d".into(),
|
||||
};
|
||||
let request_id = ReviewLoadRequestId::new();
|
||||
app.active_guided_review_request = Some(request_id.clone());
|
||||
app.update(Msg::Engine(Event::GuidedReviewLoaded {
|
||||
request_id,
|
||||
review: Box::new(review.clone()),
|
||||
}));
|
||||
bind_session(app, &review);
|
||||
app.review.provenance = Some(luxe_core::guided_review::GuideProvenance::Model { batches: 1 });
|
||||
let session = app.review.session_mut().ok_or("missing fixture review session")?;
|
||||
if let Some(first) = session.findings.iter_mut().find(|f| f.github_thread.is_some()) {
|
||||
first.state = FindingState::Resolved;
|
||||
}
|
||||
let findings = session.findings.clone();
|
||||
let mut answers = crate::guided_review::ThreadAnswers::new(
|
||||
luxe_core::guided_review::ThreadAnswersId::new(),
|
||||
&findings,
|
||||
);
|
||||
answers.prepared = Some((false, false));
|
||||
if let Some(row) = answers.rows.first_mut() {
|
||||
row.reply = "Only the webhook built it from a string, and it parses first now.".into();
|
||||
}
|
||||
app.guided_review_workspace.thread_answers = Some(answers);
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Three comments on the pull request and the post preview GitHub's answer opens: one on the review
|
||||
/// as a whole, one on the line that carries the new type, and a question the agent has already
|
||||
/// answered, which is why it is not in the preview.
|
||||
///
|
||||
/// Titles are the bodies' first lines, which is all a title ever is: there is no field for one.
|
||||
fn pull_request_post(app: &mut App) -> Result<(), String> {
|
||||
let review = app.guided_review.as_deref().ok_or("missing fixture review")?.clone();
|
||||
let line = review_line_anchor(Some(&review)).ok_or("missing fixture line")?;
|
||||
let session = app.review.session_mut().ok_or("missing fixture review session")?;
|
||||
let answer = luxe_core::guided_review::FindingMessage {
|
||||
author: luxe_core::guided_review::FindingMessageAuthor::Agent,
|
||||
body: "So the webhook can answer an unknown category with a 422 that names it. A serde \
|
||||
failure would reject the whole payload with a generic error."
|
||||
.into(),
|
||||
created_at_ms: 1,
|
||||
};
|
||||
for (anchor, severity, body, state, thread) in [
|
||||
(
|
||||
FindingAnchor::Review,
|
||||
FindingSeverity::Issue,
|
||||
"An unknown category now fails the whole webhook with a `422`, and older senders still \
|
||||
post `alert`.\n\nCan we log and drop those for one release before rejecting them \
|
||||
outright?",
|
||||
FindingState::Draft,
|
||||
Vec::new(),
|
||||
),
|
||||
(
|
||||
line,
|
||||
FindingSeverity::Suggestion,
|
||||
"Worth a doc comment here: this is parsed once, in the webhook, so nothing downstream \
|
||||
should build a category from a raw string again.",
|
||||
FindingState::Draft,
|
||||
Vec::new(),
|
||||
),
|
||||
(
|
||||
FindingAnchor::Review,
|
||||
FindingSeverity::Question,
|
||||
"Why `FromStr` here rather than serde's `rename_all` on the enum?",
|
||||
FindingState::Open,
|
||||
vec![answer],
|
||||
),
|
||||
] {
|
||||
let first = body.lines().next().unwrap_or(body);
|
||||
let title = if first.chars().count() <= 80 {
|
||||
first.to_owned()
|
||||
} else {
|
||||
format!("{}…", first.chars().take(79).collect::<String>().trim_end())
|
||||
};
|
||||
session
|
||||
.add_finding(ReviewFinding {
|
||||
posted: None,
|
||||
github_thread: None,
|
||||
id: FindingId::new(),
|
||||
label: String::new(),
|
||||
anchor,
|
||||
severity,
|
||||
title,
|
||||
body: body.into(),
|
||||
proposed_fix: None,
|
||||
state,
|
||||
thread,
|
||||
})
|
||||
.map_err(|error| error.to_string())?;
|
||||
}
|
||||
// GitHub's patch shows every line the capture does, which is the common case
|
||||
let patches = review
|
||||
.files
|
||||
.iter()
|
||||
.filter_map(|file| {
|
||||
let path = file.new_path.as_ref().or(file.old_path.as_ref())?;
|
||||
let mut commentable = luxe_core::github::CommentableLines::default();
|
||||
for line in file.hunks.iter().flat_map(|hunk| &hunk.lines) {
|
||||
commentable.left.extend(line.old_line);
|
||||
commentable.right.extend(line.new_line);
|
||||
}
|
||||
Some(luxe_core::github::FilePatch {
|
||||
path: luxe_core::paths::display(path),
|
||||
previous_path: None,
|
||||
commentable,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
app.guided_review_workspace.github_post = Some(crate::guided_review::GithubPost {
|
||||
request_id: luxe_core::guided_review::PullRequestPostId::new(),
|
||||
verdict: luxe_core::github::ReviewEvent::RequestChanges,
|
||||
prepared: Some(crate::guided_review::PreparedPost {
|
||||
patches,
|
||||
head_moved: false,
|
||||
own_pull_request: false,
|
||||
}),
|
||||
posting: false,
|
||||
error: None,
|
||||
selected: 0,
|
||||
scroll: 0,
|
||||
drafting: None,
|
||||
drafting_since: None,
|
||||
draft_note: None,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The preview of a branch's pull request, drafted from its review for issue #123: its work not
|
||||
/// committed yet, and the branch never pushed.
|
||||
fn open_pull_request(app: &mut App) -> Result<(), String> {
|
||||
let review = app.guided_review.as_ref().ok_or("missing fixture review")?;
|
||||
let issue = luxe_core::guided_review::ClosedIssue { number: 123, title: None };
|
||||
let draft = luxe_core::guided_review::pull_request_draft(review, Some(&issue));
|
||||
let commits = luxe_core::guided_review::chapter_commits(review, &[])
|
||||
.map_err(|error| error.to_string())?
|
||||
.into_iter()
|
||||
.map(|commit| commit.subject)
|
||||
.collect();
|
||||
app.guided_review_workspace.pull_request_opening =
|
||||
Some(crate::guided_review::PullRequestOpening {
|
||||
request_id: luxe_core::guided_review::PullRequestOpenId::new(),
|
||||
prepared: Some(crate::guided_review::PreparedOpening {
|
||||
pull_request: luxe_core::github::NewPullRequest {
|
||||
head: "123-category-enum".into(),
|
||||
base: "main".into(),
|
||||
title: draft.title,
|
||||
body: draft.body,
|
||||
draft: false,
|
||||
},
|
||||
publication: luxe_core::github::Publication::Unpublished,
|
||||
uncommitted: 4,
|
||||
commits,
|
||||
}),
|
||||
editing: None,
|
||||
body_scroll: 0,
|
||||
body_room: std::cell::Cell::new(0),
|
||||
opening: false,
|
||||
error: None,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Answers a loaded review with the session the engine's review desk would bind to it: new, with
|
||||
/// the open threads of your own pull request already adopted as findings.
|
||||
fn bind_session(app: &mut App, review: &luxe_core::guided_review::GuidedReview) {
|
||||
let mut session = luxe_core::guided_review::ReviewSession::new(
|
||||
review.id.clone(),
|
||||
review.target.clone(),
|
||||
review.source.clone(),
|
||||
review.generated_at_ms,
|
||||
);
|
||||
if matches!(review.target, ReviewTarget::OwnPullRequest { .. }) {
|
||||
session.adopt_github_threads(luxe_core::guided_review::thread_findings(review));
|
||||
}
|
||||
app.update(Msg::Engine(Event::ReviewSessionRestored { session: Box::new(session) }));
|
||||
}
|
||||
77
crates/luxe-tui/src/fixture/scaled.rs
Normal file
77
crates/luxe-tui/src/fixture/scaled.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
//! Scaled — the large review repeated, for measuring against review size.
|
||||
|
||||
use super::fixture_large_guided_review;
|
||||
use luxe_core::guided_review::{GuidedReview, ReviewStats};
|
||||
|
||||
/// [`fixture_large_guided_review`] repeated `times` over, for measuring against review size.
|
||||
///
|
||||
/// Whole copies rather than a bigger generator, so the shape stays the one real reviews have — the
|
||||
/// same mix of chapter kinds, folded churn and non-text entries at every scale. Ids are rewritten
|
||||
/// per copy, which is what makes the copies distinct items rather than duplicates that a lookup
|
||||
/// would collapse, and each copy's notes follow its own items. Paths repeat on purpose: a stress
|
||||
/// case of the same tree many times over. `times` of 1 is the fixture itself.
|
||||
pub fn fixture_guided_review_scaled(times: usize) -> GuidedReview {
|
||||
scale(fixture_large_guided_review(), times)
|
||||
}
|
||||
|
||||
/// `base` repeated `times` over, the way [`fixture_guided_review_scaled`] describes.
|
||||
pub(crate) fn scale(base: GuidedReview, times: usize) -> GuidedReview {
|
||||
use luxe_core::guided_review::{ChapterId, FileId, HunkId, ReviewItemRef};
|
||||
use std::collections::HashMap;
|
||||
|
||||
let mut scaled = base.clone();
|
||||
for round in 1..times.max(1) {
|
||||
let mut files = base.files.clone();
|
||||
let mut chapters = base.chapters.clone();
|
||||
// A chapter references its items by id, so every rename has to travel into the chapters of
|
||||
// the same copy — otherwise the copy's sections point at the original's files.
|
||||
let mut renamed_files: HashMap<FileId, FileId> = HashMap::new();
|
||||
let mut renamed_hunks: HashMap<HunkId, HunkId> = HashMap::new();
|
||||
for file in &mut files {
|
||||
let previous = file.id.clone();
|
||||
file.id = FileId::from_path_lineage(
|
||||
None,
|
||||
Some(&std::path::PathBuf::from(format!("copy-{round}/{}", previous.as_str()))),
|
||||
);
|
||||
renamed_files.insert(previous, file.id.clone());
|
||||
for hunk in &mut file.hunks {
|
||||
let previous = hunk.id.clone();
|
||||
hunk.id =
|
||||
HunkId::from_content(&file.id, &format!("copy-{round}"), previous.as_str());
|
||||
renamed_hunks.insert(previous, hunk.id.clone());
|
||||
}
|
||||
}
|
||||
// notes name items by their id's text, so they look up through one map of both kinds
|
||||
let renamed_notes: HashMap<String, String> = renamed_hunks
|
||||
.iter()
|
||||
.map(|(old, new)| (old.as_str(), new.as_str()))
|
||||
.chain(renamed_files.iter().map(|(old, new)| (old.as_str(), new.as_str())))
|
||||
.map(|(old, new)| (old.to_owned(), new.to_owned()))
|
||||
.collect();
|
||||
for chapter in &mut chapters {
|
||||
chapter.id =
|
||||
ChapterId::from_item_keys(&format!("copy-{round}"), &[chapter.id.as_str()]);
|
||||
for item in &mut chapter.items {
|
||||
*item = match item {
|
||||
ReviewItemRef::File(id) => ReviewItemRef::File(
|
||||
renamed_files.get(id).cloned().unwrap_or_else(|| id.clone()),
|
||||
),
|
||||
ReviewItemRef::Hunk(id) => ReviewItemRef::Hunk(
|
||||
renamed_hunks.get(id).cloned().unwrap_or_else(|| id.clone()),
|
||||
),
|
||||
};
|
||||
}
|
||||
for note in &mut chapter.notes {
|
||||
if let Some(new) = renamed_notes.get(¬e.item) {
|
||||
note.item.clone_from(new);
|
||||
}
|
||||
}
|
||||
}
|
||||
scaled.files.extend(files);
|
||||
scaled.chapters.extend(chapters);
|
||||
}
|
||||
// every copy excludes what the original did
|
||||
let excluded_files = base.stats.excluded_files * times.max(1) as u64;
|
||||
scaled.stats = ReviewStats { excluded_files, ..ReviewStats::from_files(&scaled.files) };
|
||||
scaled
|
||||
}
|
||||
164
crates/luxe-tui/src/fixture/scenario.rs
Normal file
164
crates/luxe-tui/src/fixture/scenario.rs
Normal file
@@ -0,0 +1,164 @@
|
||||
//! Fixture scenarios — the stable names screenshots, recordings and checks ask for.
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Declares the scenarios once: the enum, [`FixtureScenario::ALL`] and each one's name come out of
|
||||
/// one list, so a scenario cannot be added to one of them and left out of another.
|
||||
macro_rules! scenarios {
|
||||
($($(#[doc = $doc:literal])* $variant:ident => $name:literal,)+) => {
|
||||
/// Stable screenshot scenario names supported by the fixture runner.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FixtureScenario {
|
||||
$($(#[doc = $doc])* $variant,)+
|
||||
}
|
||||
|
||||
impl FixtureScenario {
|
||||
/// Every scenario, so a check can walk all of them rather than the ones it
|
||||
/// remembers.
|
||||
pub const ALL: &'static [FixtureScenario] = &[$(Self::$variant,)+];
|
||||
|
||||
/// The name the capture scripts, the runner's title and its usage line all spell it
|
||||
/// with.
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
$(Self::$variant => $name,)+
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
scenarios! {
|
||||
/// Startup dashboard with fixed sessions and model metadata.
|
||||
Dashboard => "dashboard",
|
||||
/// The context-file list, open over the dashboard.
|
||||
DashboardContextFiles => "dashboard-context-files",
|
||||
/// The dashboard with a draft typed, listing what it matches.
|
||||
DashboardTyping => "dashboard-typing",
|
||||
/// The dashboard's minimal style: the prompt, the list folded away.
|
||||
DashboardMinimal => "dashboard-minimal",
|
||||
/// The Configuration surface, as a machine with nothing configured opens it.
|
||||
Configuration => "configuration",
|
||||
/// The first run's setup, on its theme step.
|
||||
Setup => "setup",
|
||||
/// The first run's setup, on its tools step.
|
||||
SetupTools => "setup-tools",
|
||||
/// The settings pages, on Appearance, over a config with a few keys set.
|
||||
Settings => "settings",
|
||||
/// The settings pages, on Tools, with one tool turned off here and one by the project.
|
||||
SettingsTools => "settings-tools",
|
||||
/// Idle chat with a fixed short exchange.
|
||||
ChatIdle => "chat-idle",
|
||||
/// Chat showing model reasoning: one expanded and one collapsed thinking block.
|
||||
ChatThinking => "chat-thinking",
|
||||
/// Chat caught mid-reveal: a streaming answer with its newest characters still fading in.
|
||||
ChatStreaming => "chat-streaming",
|
||||
/// Chat with deterministic structured tool outcomes.
|
||||
ChatTools => "chat-tools",
|
||||
/// Chat with the three cards that carry a body: a written file, a side-by-side edit, a heredoc.
|
||||
ChatCardBodies => "chat-card-bodies",
|
||||
/// Chat with prose, fenced code, and a table for canvas-width review.
|
||||
ChatWideProse => "chat-wide-prose",
|
||||
/// Chat with an expanded failed tool for error-state review.
|
||||
ChatToolError => "chat-tool-error",
|
||||
/// A run of lookups folded into one live line, mid-batch, beside the cards that never fold.
|
||||
ChatToolRun => "chat-tool-run",
|
||||
/// Chat with the interactive question modal open (multi-select + free-text).
|
||||
ChatQuestion => "chat-question",
|
||||
/// Plan mode, mid-interview: the composer and the agent's question in the plan color.
|
||||
ChatPlan => "chat-plan",
|
||||
/// Plan mode's plan written, and the question of what to do with it.
|
||||
ChatPlanReady => "chat-plan-ready",
|
||||
/// A finished turn: lookups folded into a line, an edit with its diff, a test run, the reply.
|
||||
ChatTurn => "chat-turn",
|
||||
/// The same turn, stopped on a commit that waits for approval.
|
||||
ChatPermission => "chat-permission",
|
||||
/// The Command Palette over the conversation, the commands used last on top.
|
||||
ChatPalette => "chat-palette",
|
||||
/// A `screenshot` card showing its capture inline, at whatever fidelity the terminal has.
|
||||
ChatScreenshot => "chat-screenshot",
|
||||
/// Guided Review source failure rendered through the production event reducer.
|
||||
GuidedReviewError => "guided-review-error",
|
||||
/// Accepted Guided Review rendered through the production event reducer.
|
||||
GuidedReviewReady => "guided-review-ready",
|
||||
/// Responsive wide Guided Review capture using the standard review corpus.
|
||||
GuidedReviewWide => "guided-review-wide",
|
||||
/// The demos' review: a change large enough to need the chapters it is shown in.
|
||||
GuidedReviewDemo => "guided-review-demo",
|
||||
/// The demos' review with the guide pane put away, so the diff has the screen.
|
||||
GuidedReviewGuideHidden => "guided-review-guide-hidden",
|
||||
/// The working-tree review, open on its brief.
|
||||
GuidedReviewBrief => "guided-review-brief",
|
||||
/// The working-tree review with its send preview open on the seeded comments.
|
||||
GuidedReviewSend => "guided-review-send",
|
||||
/// The working-tree review with its commit preview open.
|
||||
GuidedReviewCommit => "guided-review-commit",
|
||||
/// A generated review large enough to exercise scrolling, folding and scale.
|
||||
GuidedReviewLarge => "guided-review-large",
|
||||
/// The demos' change, arriving as a pull request opened by a bot.
|
||||
GuidedReviewPullRequest => "guided-review-pull-request",
|
||||
/// That pull request's review in the preview before it is posted to GitHub.
|
||||
GuidedReviewPullRequestPost => "guided-review-pull-request-post",
|
||||
/// Your own pull request's review, answering its threads on GitHub.
|
||||
GuidedReviewOwnPullRequest => "guided-review-own-pull-request",
|
||||
/// A branch's review, its pull request drafted in the preview before it opens.
|
||||
GuidedReviewOpenPullRequest => "guided-review-open-pull-request",
|
||||
/// Someone else's pull request, offered to be fixed in a worktree with its comments.
|
||||
GuidedReviewFixPullRequest => "guided-review-fix-pull-request",
|
||||
/// A branch's review, drafted as a stack of pull requests before it opens.
|
||||
GuidedReviewOpenStack => "guided-review-open-stack",
|
||||
/// A comment the agent claims to have fixed and the reviewer's answer, open in its details.
|
||||
GuidedReviewThread => "guided-review-thread",
|
||||
/// Guided Review with the empty Findings drawer open.
|
||||
GuidedReviewFindingsEmpty => "guided-review-findings-empty",
|
||||
/// Guided Review with persisted findings ordered for triage.
|
||||
GuidedReviewFindings => "guided-review-findings",
|
||||
/// Guided Review with a remapped finding awaiting explicit verification.
|
||||
GuidedReviewNeedsVerification => "guided-review-needs-verification",
|
||||
/// Guided Review with the blocking-accept confirmation visible.
|
||||
GuidedReviewFinish => "guided-review-finish",
|
||||
/// Responsive medium Guided Review capture using the standard review corpus.
|
||||
GuidedReviewMedium => "guided-review-medium",
|
||||
/// Responsive narrow Guided Review capture using the standard review corpus.
|
||||
GuidedReviewNarrow => "guided-review-narrow",
|
||||
/// Accepted Guided Review with split presentation preferred for wide captures.
|
||||
GuidedReviewSplit => "guided-review-split",
|
||||
/// Guided Review with an initially folded formatting hunk.
|
||||
GuidedReviewNoise => "guided-review-noise",
|
||||
/// In-flight Guided Review refresh rendered through the production event reducer.
|
||||
GuidedReviewRefreshing => "guided-review-refreshing",
|
||||
/// Find-session picker over the dashboard with a deterministic session catalog.
|
||||
SessionPicker => "session-picker",
|
||||
/// Running turn with mid-turn submissions pinned above the composer.
|
||||
ChatPending => "chat-pending",
|
||||
/// A submitted message carrying a paste long enough to be previewed.
|
||||
ChatPaste => "chat-paste",
|
||||
/// Wide side-by-side Context Dock with deterministic workspace data.
|
||||
DockWide => "dock-wide",
|
||||
/// The wide dock on a branch whose pull request has a failing check and open threads.
|
||||
DockPullRequest => "dock-pull-request",
|
||||
/// Standard-width Context overlay with deterministic workspace data.
|
||||
DockOverlay => "dock-overlay",
|
||||
/// Compact Context replacement with deterministic workspace data.
|
||||
DockCompact => "dock-compact",
|
||||
/// One file's diff beside the dock that opened it.
|
||||
ChangesWide => "changes-wide",
|
||||
/// The same pane with the dock away and the statusline carrying the change instead.
|
||||
ChangesNarrow => "changes-narrow",
|
||||
/// The pane on a file that could not be captured.
|
||||
ChangesFailed => "changes-failed",
|
||||
/// The pane on a file this session changed outside the project, beside the rail that opened it.
|
||||
ChangesExternal => "changes-external",
|
||||
}
|
||||
|
||||
impl FromStr for FixtureScenario {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
Self::ALL
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|scenario| scenario.name() == value)
|
||||
.ok_or_else(|| format!("unknown fixture scenario: {value}"))
|
||||
}
|
||||
}
|
||||
466
crates/luxe-tui/src/fixture/shell.rs
Normal file
466
crates/luxe-tui/src/fixture/shell.rs
Normal file
@@ -0,0 +1,466 @@
|
||||
//! Shell fixtures — the surfaces around the conversation.
|
||||
//!
|
||||
//! The startup dashboard, the Configuration surface, the session picker, and the Context Dock at
|
||||
//! its three widths.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Seeds `app` for a shell scenario, reporting whether this family owns it.
|
||||
///
|
||||
/// `Ok(false)` means another family does — the caller tries the next one. An `Err` is a fixture
|
||||
/// that claimed the scenario and then could not build it, which is a bug in the fixture.
|
||||
pub(super) fn seed(app: &mut App, scenario: FixtureScenario) -> Result<bool, String> {
|
||||
match scenario {
|
||||
FixtureScenario::Dashboard
|
||||
| FixtureScenario::DashboardTyping
|
||||
| FixtureScenario::DashboardMinimal => seed_dashboard(app, scenario),
|
||||
FixtureScenario::DashboardContextFiles => seed_context_files(app)?,
|
||||
FixtureScenario::Configuration => seed_configuration(app),
|
||||
FixtureScenario::Setup | FixtureScenario::SetupTools => seed_setup(app, scenario),
|
||||
FixtureScenario::Settings | FixtureScenario::SettingsTools => seed_settings(app, scenario),
|
||||
FixtureScenario::SessionPicker => seed_sessions(app),
|
||||
FixtureScenario::DockWide
|
||||
| FixtureScenario::DockOverlay
|
||||
| FixtureScenario::DockCompact
|
||||
| FixtureScenario::DockPullRequest => seed_dock(app, scenario),
|
||||
FixtureScenario::ChangesWide
|
||||
| FixtureScenario::ChangesNarrow
|
||||
| FixtureScenario::ChangesFailed
|
||||
| FixtureScenario::ChangesExternal => seed_changes_pane(app, scenario),
|
||||
_ => return Ok(false),
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// The `Dashboard`, `DashboardTyping` and `DashboardMinimal` scenarios.
|
||||
fn seed_dashboard(app: &mut App, scenario: FixtureScenario) {
|
||||
let recent = |id: &str, name: &str, age: &str| SessionSummary {
|
||||
id: id.into(),
|
||||
name: name.into(),
|
||||
age: age.into(),
|
||||
search_text: name.into(),
|
||||
preview: Vec::new(),
|
||||
worktree: None,
|
||||
};
|
||||
// A static render can't show motion, so the shine's frame is nameable: point
|
||||
// `LUXE_FIXTURE_BANNER_TICK` at any tick of the pass to capture that instant.
|
||||
let tick = std::env::var("LUXE_FIXTURE_BANNER_TICK")
|
||||
.ok()
|
||||
.and_then(|value| value.parse().ok())
|
||||
.unwrap_or(0);
|
||||
app.status.thinking = luxe_core::provider::ThinkingLevel::High;
|
||||
// The bar the session will have, which the start screen shows under its prompt
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.status.context_window = 200_000;
|
||||
app.status.project = Some("luxe".into());
|
||||
app.status.git_branch = Some("feature/context-dock".into());
|
||||
app.status.git_dirty = true;
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
app.enter_dashboard(
|
||||
DashboardState::new(vec![
|
||||
recent("fixture-session", "Refine the workspace overview", "12m ago"),
|
||||
recent("fixture-audit", "Audit the current project structure", "1d ago"),
|
||||
recent("fixture-review", "Please explain why this provider stalls", "2d ago"),
|
||||
recent("fixture-alpha", "Trace the stalled provider handshake", "2d ago"),
|
||||
])
|
||||
.with_resume(Some(crate::dashboard::ResumeTarget {
|
||||
id: "fixture-session".into(),
|
||||
title: "Refine the workspace overview".into(),
|
||||
age: "12m ago".into(),
|
||||
}))
|
||||
.with_briefing(crate::dashboard::DashBriefing {
|
||||
changed_files: 12,
|
||||
added: 640,
|
||||
removed: 118,
|
||||
}),
|
||||
);
|
||||
if let Some(dashboard) = app.dashboard.as_mut() {
|
||||
// `enter_dashboard` takes the reader's own style; the fixture names the one it shows
|
||||
dashboard.set_style(match scenario {
|
||||
FixtureScenario::DashboardMinimal => luxe_core::config::DashboardStyle::Minimal,
|
||||
_ => luxe_core::config::DashboardStyle::Launcher,
|
||||
});
|
||||
}
|
||||
if scenario == FixtureScenario::DashboardTyping {
|
||||
app.editor.insert_text("provider");
|
||||
if let Some(dashboard) = app.dashboard.as_mut() {
|
||||
dashboard.sync(&app.editor);
|
||||
}
|
||||
}
|
||||
app.banner = app.banner.with_tick(tick);
|
||||
}
|
||||
|
||||
/// The context-file list, open over the dashboard.
|
||||
fn seed_context_files(app: &mut App) -> Result<(), String> {
|
||||
// The dashboard behind it, then the list over the top — the surface never renders
|
||||
// alone, and the prompt it was searched from should still be readable around it.
|
||||
seed(app, FixtureScenario::Dashboard)?;
|
||||
app.overlays.context_files =
|
||||
Some(crate::context_files::ContextFilesState::from_rows(context_rows()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The Configuration surface, as a machine with nothing configured opens it.
|
||||
fn seed_configuration(app: &mut App) {
|
||||
// Seeded through the production path, so a capture shows what a machine with no
|
||||
// credential really opens — including where this build looks for each file.
|
||||
app.auth_service = Some(std::sync::Arc::new(UnconfiguredAuth));
|
||||
// The step after a login that suggested no model, which the surface hosts in the same
|
||||
// region: without a catalog it would be unreachable here.
|
||||
app.model_catalog = configurable_models();
|
||||
app.open_configuration();
|
||||
}
|
||||
|
||||
/// The `Setup` and `SetupTools` scenarios.
|
||||
fn seed_setup(app: &mut App, scenario: FixtureScenario) {
|
||||
// Built from the shipped themes and no desktop, rather than this machine's, so the
|
||||
// capture is the same everywhere
|
||||
app.auth_service = Some(std::sync::Arc::new(UnconfiguredAuth));
|
||||
app.open_configuration();
|
||||
let setup = crate::configuration::SetupState::open(
|
||||
crate::configuration::SetupMode::FirstRun,
|
||||
&luxe_core::config::Config::default(),
|
||||
luxe_core::theme::builtin_theme_names(),
|
||||
None,
|
||||
"luxe".into(),
|
||||
);
|
||||
if let Some(configuration) = app.overlays.configuration.as_mut() {
|
||||
configuration.show_setup(setup);
|
||||
}
|
||||
if scenario == FixtureScenario::SetupTools {
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
let key = |code| KeyEvent::new(code, KeyModifiers::NONE);
|
||||
let keys = [
|
||||
KeyCode::Enter,
|
||||
KeyCode::Up,
|
||||
KeyCode::Down,
|
||||
KeyCode::Down,
|
||||
KeyCode::Down,
|
||||
KeyCode::Enter,
|
||||
KeyCode::Down,
|
||||
KeyCode::Char(' '),
|
||||
KeyCode::Down,
|
||||
];
|
||||
for code in keys {
|
||||
if let Some(configuration) = app.overlays.configuration.as_mut() {
|
||||
configuration.on_key(&key(code));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The `Settings` and `SettingsTools` scenarios.
|
||||
fn seed_settings(app: &mut App, scenario: FixtureScenario) {
|
||||
// Seeded from fixed documents rather than this machine's files, so a capture is the
|
||||
// same everywhere: a reader who chose a theme and turned the mouse off, in a project
|
||||
// that turns `debug` off for everyone who opens it.
|
||||
app.auth_service = Some(std::sync::Arc::new(UnconfiguredAuth));
|
||||
app.open_configuration();
|
||||
let layers = luxe_core::config::ConfigLayers {
|
||||
global: Some(serde_json::json!({
|
||||
"theme": "luxe",
|
||||
"mouse": false,
|
||||
"conversation": { "growth": "top" },
|
||||
"tools": { "disabled": ["screenshot"] }
|
||||
})),
|
||||
project: Some(serde_json::json!({ "tools": { "disabled": ["debug"] } })),
|
||||
};
|
||||
let page = match scenario {
|
||||
FixtureScenario::SettingsTools => luxe_core::settings::Page::Tools,
|
||||
_ => luxe_core::settings::Page::Appearance,
|
||||
};
|
||||
let settings = crate::configuration::SettingsState::open(
|
||||
layers,
|
||||
"luxe".into(),
|
||||
// Under whoever's home this runs in, so it reads `~/.config/…` on every machine
|
||||
luxe_core::user_dirs::home_dir()
|
||||
.unwrap_or_default()
|
||||
.join(".config")
|
||||
.join("luxe")
|
||||
.join("config.json"),
|
||||
)
|
||||
.open_on(page);
|
||||
if let Some(configuration) = app.overlays.configuration.as_mut() {
|
||||
configuration.show_settings(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/// Find-session picker over the dashboard with a deterministic session catalog.
|
||||
fn seed_sessions(app: &mut App) {
|
||||
let session = |name: &str, age: &str, transcript: &str| SessionEntry {
|
||||
id: name.into(),
|
||||
name: name.into(),
|
||||
age: age.into(),
|
||||
search_text: transcript.into(),
|
||||
preview: Vec::new(),
|
||||
};
|
||||
let turn = |role: PreviewRole, text: &str| PreviewTurn { role, text: text.into() };
|
||||
// The first (selected) row carries a rich, role-tagged preview so the pane shows off
|
||||
// markdown rendering and user/assistant/tool separation for screenshot review.
|
||||
let feature_session = SessionEntry {
|
||||
id: "todo-overdue".into(),
|
||||
name: "Add a todo overdue command that lists open tasks past their due date".into(),
|
||||
age: "2h ago".into(),
|
||||
search_text: "add a todo overdue command that lists open tasks past their due date, \
|
||||
oldest first, with a test"
|
||||
.into(),
|
||||
preview: vec![
|
||||
turn(
|
||||
PreviewRole::User,
|
||||
"add a `todo overdue` command that lists open tasks past their due date, oldest \
|
||||
first, with a test",
|
||||
),
|
||||
turn(PreviewRole::Assistant, "Reading the command table and the filters first."),
|
||||
turn(PreviewRole::Tool, "read(path: \"src/cli.js\")"),
|
||||
turn(
|
||||
PreviewRole::Assistant,
|
||||
"Added `todo overdue`. It lists open tasks past their due date, **oldest \
|
||||
first**.\n\n- `src/filter.js`: a new `overdue` filter\n- `src/cli.js`: the \
|
||||
command\n\nTwo new tests cover it, and all five pass.",
|
||||
),
|
||||
],
|
||||
};
|
||||
let sessions = vec![
|
||||
feature_session,
|
||||
session(
|
||||
"Why does todo import drop tasks with an empty title?",
|
||||
"5h ago",
|
||||
"Why does todo import drop tasks with an empty title? The CSV has 40 rows and only 37 \
|
||||
arrive.",
|
||||
),
|
||||
session(
|
||||
"Fix the flaky reminder test on CI",
|
||||
"yesterday",
|
||||
"Fix the flaky reminder test on CI. It fails about one run in ten with a timezone \
|
||||
off by an hour.",
|
||||
),
|
||||
session(
|
||||
"Review #142: store due dates as UTC",
|
||||
"yesterday",
|
||||
"Review pull request 142, which stores due dates as UTC.",
|
||||
),
|
||||
session(
|
||||
"Plan the move from JSON storage to SQLite",
|
||||
"3d ago",
|
||||
"Plan the move from JSON storage to SQLite, keeping old files readable.",
|
||||
),
|
||||
session(
|
||||
"Add shell completions for bash and zsh",
|
||||
"4d ago",
|
||||
"Add shell completions for bash and zsh, generated from the command table.",
|
||||
),
|
||||
session(
|
||||
"Bump the minimum Python to 3.11",
|
||||
"1w ago",
|
||||
"Bump the minimum Python to 3.11 and drop the tomli fallback.",
|
||||
),
|
||||
];
|
||||
app.status.model = "claude-sonnet-5".into();
|
||||
app.status.provider = "anthropic".into();
|
||||
app.enter_dashboard(DashboardState::new(Vec::new()));
|
||||
app.overlays.session_picker =
|
||||
Some(SessionPickerState::for_kind(sessions, PickerKind::FindSession));
|
||||
app.current_view = ViewMode::SessionPicker;
|
||||
}
|
||||
|
||||
/// The `DockWide`, `DockOverlay`, `DockCompact` and `DockPullRequest` scenarios.
|
||||
fn seed_dock(app: &mut App, scenario: FixtureScenario) {
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Context stays available without displacing the active conversation.".into(),
|
||||
));
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.status.context_window = 200_000;
|
||||
app.status.context_pct = 12.4;
|
||||
app.status.prompt_tokens = 1_240;
|
||||
app.status.completion_tokens = 380;
|
||||
// Session totals are what the dock reports; the per-turn figures reset every turn.
|
||||
app.status.session = dock_session_usage();
|
||||
app.status.thinking = luxe_core::provider::ThinkingLevel::Medium;
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
// One place under ELSEWHERE already looked at, so the rail shows both states it has:
|
||||
// a place still asking for attention, and one folded down to the heading because
|
||||
// everything under it has been read.
|
||||
app.external_seen.insert("/home/dev/.config/luxe/models.json".into(), (4, 1));
|
||||
app.dock.show();
|
||||
if scenario == FixtureScenario::DockPullRequest {
|
||||
if let Some(workspace) = app.workspace.as_mut() {
|
||||
workspace.pull_request = luxe_core::workspace::PullRequestPresence::Found(
|
||||
luxe_core::github::PullRequestStatus {
|
||||
number: 142,
|
||||
title: "Draw the context dock beside the conversation".into(),
|
||||
url: "https://github.com/acme/luxe/pull/142".into(),
|
||||
state: luxe_core::github::PullRequestState::Open,
|
||||
draft: false,
|
||||
review_decision: Some(luxe_core::github::ReviewDecision::ChangesRequested),
|
||||
checks: luxe_core::github::CheckRollup {
|
||||
passed: 4,
|
||||
failed: 1,
|
||||
pending: 0,
|
||||
skipped: 0,
|
||||
},
|
||||
unresolved_threads: 2,
|
||||
head_oid: "3992868".into(),
|
||||
stack: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The `ChangesWide`, `ChangesNarrow`, `ChangesFailed` and `ChangesExternal` scenarios.
|
||||
fn seed_changes_pane(app: &mut App, scenario: FixtureScenario) {
|
||||
// A real exchange, because on a wide terminal the pane keeps the conversation beside
|
||||
// the diff and a one-line transcript would not show what that is worth.
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Why does the dock's change list show directories instead of files?".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"The data was always there \u{2014} `DockChanges.files` carries a path, a status and \
|
||||
both counts per file. Only the renderer withheld them, reducing every file to its \
|
||||
directory before drawing."
|
||||
.into(),
|
||||
));
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"I put the names back under their directory headings, middle-eliding the long ones \
|
||||
so the basename always survives."
|
||||
.into(),
|
||||
));
|
||||
if matches!(scenario, FixtureScenario::ChangesWide | FixtureScenario::ChangesNarrow) {
|
||||
// Still at it: the point of peek is reading the diff while the agent keeps going,
|
||||
// so the turn is live, with its tests running and the clock pinned mid-turn
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Now the dock's tests, to check nothing else leaned on the old grouping.".into(),
|
||||
));
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: luxe_core::ToolActivity::running(
|
||||
"fixture-session",
|
||||
"call-test",
|
||||
"test",
|
||||
"cargo nextest run -p luxe-tui dock",
|
||||
1,
|
||||
),
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
let now = std::time::Instant::now();
|
||||
let ago = |seconds| now.checked_sub(std::time::Duration::from_secs(seconds));
|
||||
app.status.frame_clock = Some(now);
|
||||
app.status.state = crate::app::AppState::Streaming;
|
||||
app.status.active_tool = Some("test".into());
|
||||
app.status.turn_started = ago(38);
|
||||
app.status.tool_started = ago(6);
|
||||
app.status.spinner_frame = 30;
|
||||
}
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.provider = "lmstudio".into();
|
||||
app.status.context_window = 200_000;
|
||||
app.status.context_pct = 12.4;
|
||||
app.status.session = dock_session_usage();
|
||||
app.status.thinking = luxe_core::provider::ThinkingLevel::Medium;
|
||||
app.workspace = Some(dock_workspace_snapshot());
|
||||
if scenario == FixtureScenario::ChangesWide {
|
||||
app.dock.show();
|
||||
} else {
|
||||
// The dock away, so the bar carries the change instead — and, for the failure,
|
||||
// so the message is not sitting under an overlay.
|
||||
app.dock.hide();
|
||||
app.statusline_state.show();
|
||||
}
|
||||
// A file the session changed somewhere else opens in the same pane, from the same
|
||||
// click, against whatever witness that place has — and without the review shortcut,
|
||||
// which is the one thing a review of *this* project could not honor.
|
||||
let path = if scenario == FixtureScenario::ChangesExternal {
|
||||
"/home/dev/.config/luxe/models.json"
|
||||
} else {
|
||||
"crates/luxe-tui/src/view/dock.rs"
|
||||
};
|
||||
app.update(Msg::OpenChanges(path.to_string()));
|
||||
let request = luxe_core::file_diff::FileDiffRequestId::new();
|
||||
if let Some(view) = app.changes.as_mut() {
|
||||
view.request = Some(request.clone());
|
||||
}
|
||||
// Through the production reducer, so the fixture exercises the same path a live
|
||||
// capture takes rather than assigning the state it is supposed to produce.
|
||||
app.update(Msg::Engine(if scenario == FixtureScenario::ChangesFailed {
|
||||
Event::FileDiffFailed {
|
||||
request_id: request,
|
||||
path: path.into(),
|
||||
error: luxe_core::file_diff::FileDiffFailure::TooLarge,
|
||||
}
|
||||
} else {
|
||||
Event::FileDiffLoaded {
|
||||
request_id: request,
|
||||
diff: Box::new(luxe_core::file_diff::FileDiff {
|
||||
path: path.into(),
|
||||
file: Some(Box::new(if scenario == FixtureScenario::ChangesExternal {
|
||||
external_fixture_file(path)
|
||||
} else {
|
||||
changes_fixture_file(path)
|
||||
})),
|
||||
untracked: false,
|
||||
}),
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/// The project context both dashboard scenarios draw from.
|
||||
///
|
||||
/// One list, because the section on the dashboard is the first five of exactly what the full list
|
||||
/// shows — a fixture that seeded them separately could capture a count that disagrees with the rows
|
||||
/// behind it, which is the bug the counts were replaced to stop having.
|
||||
fn context_rows() -> Vec<crate::context_files::ContextFileRow> {
|
||||
use crate::context_files::{ContextFileRow, ContextKind};
|
||||
use luxe_core::instructions::ContextScope;
|
||||
let row = |kind, label: &str, scope: &str, path: &str| ContextFileRow {
|
||||
kind,
|
||||
label: label.into(),
|
||||
scope: scope.into(),
|
||||
path: path.into(),
|
||||
creates: false,
|
||||
reach: None,
|
||||
duplicate: false,
|
||||
};
|
||||
let instructions = |reach, label: &str, scope: &str, path: &str| ContextFileRow {
|
||||
reach: Some(reach),
|
||||
..row(ContextKind::Instructions, label, scope, path)
|
||||
};
|
||||
vec![
|
||||
instructions(
|
||||
ContextScope::Global,
|
||||
"~/.config/luxe/agents.md",
|
||||
"every project",
|
||||
"/home/you/.config/luxe/agents.md",
|
||||
),
|
||||
instructions(ContextScope::Project, "AGENTS.md", "this project", "/repo/AGENTS.md"),
|
||||
row(
|
||||
ContextKind::Skill,
|
||||
"reviewing-diffs",
|
||||
"How this project reads a change",
|
||||
"/repo/.luxe/skills/reviewing-diffs/SKILL.md",
|
||||
),
|
||||
row(
|
||||
ContextKind::Skill,
|
||||
"release-notes",
|
||||
"Turning a milestone into prose",
|
||||
"/repo/.luxe/skills/release-notes/SKILL.md",
|
||||
),
|
||||
row(
|
||||
ContextKind::Skill,
|
||||
"wire-audit",
|
||||
"Reading a capture of what reached the model",
|
||||
"/repo/.luxe/skills/wire-audit/SKILL.md",
|
||||
),
|
||||
row(
|
||||
ContextKind::Skill,
|
||||
"release-checklist",
|
||||
"What ships before a tag does",
|
||||
"/repo/.luxe/skills/release-checklist/SKILL.md",
|
||||
),
|
||||
row(ContextKind::McpServer, "postgres", ".luxe/mcp.json", "/repo/.luxe/mcp.json"),
|
||||
]
|
||||
}
|
||||
260
crates/luxe-tui/src/fixture/tests.rs
Normal file
260
crates/luxe-tui/src/fixture/tests.rs
Normal file
@@ -0,0 +1,260 @@
|
||||
use super::*;
|
||||
use crate::app::ViewMode;
|
||||
|
||||
/// No still may show a state the runtime cannot reach.
|
||||
///
|
||||
/// Dispatch runs a message's calls strictly in order, one at a time, and a card appears when
|
||||
/// its call *starts* — so at any instant exactly one card is in flight and it is the last one
|
||||
/// on screen. Two fixtures had drifted into showing a spinner with finished work below it,
|
||||
/// which is a lifecycle no session produces; one of them is a published site asset, which made
|
||||
/// it a picture of a build nobody can run.
|
||||
#[test]
|
||||
fn a_fixture_never_shows_work_that_could_not_have_happened() {
|
||||
for scenario in FixtureScenario::ALL {
|
||||
let app = seeded_app("luxe", *scenario).expect("every scenario seeds");
|
||||
let in_flight = app
|
||||
.convo
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, item)| {
|
||||
matches!(item.block(), ConvoBlock::Tool(tool)
|
||||
if tool.activity.state == ToolActivityState::Running)
|
||||
})
|
||||
.map(|(index, _)| index)
|
||||
.collect::<Vec<_>>();
|
||||
assert!(
|
||||
in_flight.len() <= 1,
|
||||
"{scenario:?} has {} calls in flight at once, and dispatch runs them one at a time",
|
||||
in_flight.len()
|
||||
);
|
||||
let trailing_cards = app
|
||||
.convo
|
||||
.iter()
|
||||
.skip(in_flight.first().map_or(usize::MAX, |index| index + 1))
|
||||
.filter(|item| matches!(item.block(), ConvoBlock::Tool(_)))
|
||||
.count();
|
||||
assert_eq!(
|
||||
trailing_cards, 0,
|
||||
"{scenario:?} draws a card after the call in flight, which would mean that call \
|
||||
had already finished"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn seeds_stable_dashboard_and_chat_states() {
|
||||
let dashboard = seeded_app("nord", FixtureScenario::Dashboard).unwrap();
|
||||
assert_eq!(dashboard.current_view, ViewMode::Dashboard);
|
||||
let resume = dashboard.dashboard.as_ref().unwrap().resume.as_ref().unwrap();
|
||||
assert_eq!(resume.age, "12m ago");
|
||||
|
||||
let chat = seeded_app("catppuccin", FixtureScenario::ChatIdle).unwrap();
|
||||
assert_eq!(chat.current_view, ViewMode::Chat);
|
||||
assert_eq!(chat.convo.len(), 2);
|
||||
assert_eq!(chat.status.model, "qwen3.8-27b");
|
||||
|
||||
let wide = seeded_app("nord", FixtureScenario::ChatWideProse).unwrap();
|
||||
assert_eq!(wide.convo.len(), 1);
|
||||
assert!(matches!(wide.convo[0].block(), ConvoBlock::Assistant(_)));
|
||||
|
||||
let tool_error = seeded_app("catppuccin", FixtureScenario::ChatToolError).unwrap();
|
||||
assert_eq!(tool_error.convo.len(), 3, "prose plus both rejection cards");
|
||||
assert!(matches!(tool_error.convo[1].block(), ConvoBlock::Tool(_)));
|
||||
assert!(matches!(tool_error.convo[2].block(), ConvoBlock::Tool(_)));
|
||||
|
||||
let guided_review_error = seeded_app("dark", FixtureScenario::GuidedReviewError).unwrap();
|
||||
assert!(guided_review_error.active_guided_review_request.is_none());
|
||||
assert!(matches!(
|
||||
guided_review_error.convo.last().map(|item| item.block()),
|
||||
Some(ConvoBlock::System(message)) if message.starts_with("[review error]")
|
||||
));
|
||||
|
||||
let guided_review_ready = seeded_app("dark", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
assert!(guided_review_ready.active_guided_review_request.is_none());
|
||||
assert!(guided_review_ready.guided_review.is_some());
|
||||
assert_eq!(guided_review_ready.guided_review.as_ref().unwrap().files.len(), 1);
|
||||
assert_eq!(
|
||||
guided_review_ready.review.session().map(|session| &session.id),
|
||||
guided_review_ready.guided_review.as_ref().map(|review| &review.id)
|
||||
);
|
||||
// Nothing about the review reaches the transcript any more: it was a status line for a
|
||||
// surface the reader was already standing on by the time they could read it.
|
||||
assert!(
|
||||
!guided_review_ready
|
||||
.convo
|
||||
.iter()
|
||||
.any(|item| matches!(item.block(), ConvoBlock::System(message)
|
||||
if message.starts_with("[review "))),
|
||||
"the review leaves the transcript alone"
|
||||
);
|
||||
|
||||
for (name, scenario) in [
|
||||
("guided-review-wide", FixtureScenario::GuidedReviewWide),
|
||||
("guided-review-brief", FixtureScenario::GuidedReviewBrief),
|
||||
("guided-review-send", FixtureScenario::GuidedReviewSend),
|
||||
("guided-review-commit", FixtureScenario::GuidedReviewCommit),
|
||||
("guided-review-large", FixtureScenario::GuidedReviewLarge),
|
||||
("guided-review-pull-request", FixtureScenario::GuidedReviewPullRequest),
|
||||
("guided-review-pull-request-post", FixtureScenario::GuidedReviewPullRequestPost),
|
||||
("guided-review-own-pull-request", FixtureScenario::GuidedReviewOwnPullRequest),
|
||||
("guided-review-open-pull-request", FixtureScenario::GuidedReviewOpenPullRequest),
|
||||
("guided-review-fix-pull-request", FixtureScenario::GuidedReviewFixPullRequest),
|
||||
("guided-review-open-stack", FixtureScenario::GuidedReviewOpenStack),
|
||||
("guided-review-guide-hidden", FixtureScenario::GuidedReviewGuideHidden),
|
||||
("guided-review-thread", FixtureScenario::GuidedReviewThread),
|
||||
("guided-review-findings-empty", FixtureScenario::GuidedReviewFindingsEmpty),
|
||||
("guided-review-findings", FixtureScenario::GuidedReviewFindings),
|
||||
("guided-review-finish", FixtureScenario::GuidedReviewFinish),
|
||||
("guided-review-medium", FixtureScenario::GuidedReviewMedium),
|
||||
("guided-review-narrow", FixtureScenario::GuidedReviewNarrow),
|
||||
] {
|
||||
assert_eq!(name.parse::<FixtureScenario>().unwrap(), scenario);
|
||||
let responsive_review = seeded_app("dark", scenario).unwrap();
|
||||
assert!(responsive_review.guided_review.is_some());
|
||||
// `auto` is the default layout, so a review opens side by side and falls back to unified
|
||||
// only where the pane is too narrow for two readable columns.
|
||||
assert_eq!(
|
||||
responsive_review.guided_review_workspace.layout,
|
||||
luxe_core::config::DiffLayout::Auto
|
||||
);
|
||||
}
|
||||
|
||||
let guided_review_needs_verification =
|
||||
seeded_app("dark", FixtureScenario::GuidedReviewNeedsVerification).unwrap();
|
||||
let selected_id = guided_review_needs_verification
|
||||
.guided_review_workspace
|
||||
.selected_finding_id
|
||||
.as_ref()
|
||||
.expect("selected verification fixture finding");
|
||||
assert_eq!(
|
||||
guided_review_needs_verification
|
||||
.review
|
||||
.session()
|
||||
.and_then(|session| session.findings.iter().find(|finding| &finding.id == selected_id))
|
||||
.map(|finding| finding.state),
|
||||
Some(FindingState::NeedsVerification)
|
||||
);
|
||||
|
||||
let guided_review_finish = seeded_app("dark", FixtureScenario::GuidedReviewFinish).unwrap();
|
||||
assert_eq!(
|
||||
guided_review_finish.guided_review_workspace.finish_review_choice,
|
||||
Some(crate::guided_review::FinishReviewChoice::Accept)
|
||||
);
|
||||
assert!(guided_review_finish.guided_review_workspace.finish_review_accept_confirmed);
|
||||
|
||||
let guided_review_split = seeded_app("dark", FixtureScenario::GuidedReviewSplit).unwrap();
|
||||
assert!(guided_review_split.guided_review.is_some());
|
||||
assert_eq!(
|
||||
guided_review_split.guided_review_workspace.layout,
|
||||
luxe_core::config::DiffLayout::Split
|
||||
);
|
||||
assert_eq!(
|
||||
"guided-review-split".parse::<FixtureScenario>().unwrap(),
|
||||
FixtureScenario::GuidedReviewSplit
|
||||
);
|
||||
|
||||
let guided_review_refreshing =
|
||||
seeded_app("dark", FixtureScenario::GuidedReviewRefreshing).unwrap();
|
||||
assert!(guided_review_refreshing.active_guided_review_request.is_some());
|
||||
assert!(guided_review_refreshing.guided_review.is_some());
|
||||
assert_eq!(
|
||||
guided_review_refreshing.guided_review_workspace.load_state,
|
||||
crate::guided_review::GuidedReviewLoadState::Loading {
|
||||
target: luxe_core::guided_review::ReviewTarget::WorkingTree
|
||||
},
|
||||
"a refresh in flight is state on the surface, not a line in the transcript"
|
||||
);
|
||||
|
||||
for scenario in
|
||||
[FixtureScenario::DockWide, FixtureScenario::DockOverlay, FixtureScenario::DockCompact]
|
||||
{
|
||||
let dock = seeded_app("nord", scenario).unwrap();
|
||||
assert!(dock.workspace.is_some());
|
||||
assert_eq!(dock.convo.len(), 1);
|
||||
assert_eq!(dock.dock.runtime_override, crate::workspace_dock::DockRuntimeOverride::Shown);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_unknown_theme_and_scenario() {
|
||||
assert!(seeded_app("missing", FixtureScenario::Dashboard).is_err());
|
||||
assert!("missing".parse::<FixtureScenario>().is_err());
|
||||
}
|
||||
|
||||
/// What the capture scripts and the site pass, in [`FixtureScenario::ALL`]'s order. A literal, so
|
||||
/// renaming a scenario has to change it here as well as in the scripts that would stop working.
|
||||
const SCRIPT_NAMES: [&str; 60] = [
|
||||
"dashboard",
|
||||
"dashboard-context-files",
|
||||
"dashboard-typing",
|
||||
"dashboard-minimal",
|
||||
"configuration",
|
||||
"setup",
|
||||
"setup-tools",
|
||||
"settings",
|
||||
"settings-tools",
|
||||
"chat-idle",
|
||||
"chat-thinking",
|
||||
"chat-streaming",
|
||||
"chat-tools",
|
||||
"chat-card-bodies",
|
||||
"chat-wide-prose",
|
||||
"chat-tool-error",
|
||||
"chat-tool-run",
|
||||
"chat-question",
|
||||
"chat-plan",
|
||||
"chat-plan-ready",
|
||||
"chat-turn",
|
||||
"chat-permission",
|
||||
"chat-palette",
|
||||
"chat-screenshot",
|
||||
"guided-review-error",
|
||||
"guided-review-ready",
|
||||
"guided-review-wide",
|
||||
"guided-review-demo",
|
||||
"guided-review-guide-hidden",
|
||||
"guided-review-brief",
|
||||
"guided-review-send",
|
||||
"guided-review-commit",
|
||||
"guided-review-large",
|
||||
"guided-review-pull-request",
|
||||
"guided-review-pull-request-post",
|
||||
"guided-review-own-pull-request",
|
||||
"guided-review-open-pull-request",
|
||||
"guided-review-fix-pull-request",
|
||||
"guided-review-open-stack",
|
||||
"guided-review-thread",
|
||||
"guided-review-findings-empty",
|
||||
"guided-review-findings",
|
||||
"guided-review-needs-verification",
|
||||
"guided-review-finish",
|
||||
"guided-review-medium",
|
||||
"guided-review-narrow",
|
||||
"guided-review-split",
|
||||
"guided-review-noise",
|
||||
"guided-review-refreshing",
|
||||
"session-picker",
|
||||
"chat-pending",
|
||||
"chat-paste",
|
||||
"dock-wide",
|
||||
"dock-pull-request",
|
||||
"dock-overlay",
|
||||
"dock-compact",
|
||||
"changes-wide",
|
||||
"changes-narrow",
|
||||
"changes-failed",
|
||||
"changes-external",
|
||||
];
|
||||
|
||||
/// Every scenario parses from the name the scripts use, and that name is the one it reports.
|
||||
///
|
||||
/// The break this catches: a scenario renamed or added in one of the places a name is spelled and
|
||||
/// not the others, which used to be three: the parser, the runner's title, and its usage line.
|
||||
#[test]
|
||||
fn every_scenario_round_trips_through_its_script_name() {
|
||||
assert_eq!(FixtureScenario::ALL.len(), SCRIPT_NAMES.len());
|
||||
for (scenario, name) in FixtureScenario::ALL.iter().zip(SCRIPT_NAMES) {
|
||||
assert_eq!(name.parse::<FixtureScenario>(), Ok(*scenario), "{name}");
|
||||
assert_eq!(scenario.name(), name);
|
||||
}
|
||||
}
|
||||
402
crates/luxe-tui/src/fixture/workspace.rs
Normal file
402
crates/luxe-tui/src/fixture/workspace.rs
Normal file
@@ -0,0 +1,402 @@
|
||||
//! Fixture workspace — the snapshot the dock reads, its files in and outside the project, and the
|
||||
//! session's usage.
|
||||
|
||||
use crate::app::App;
|
||||
use luxe_core::guided_review::{
|
||||
FileId, HunkId, LineRange, NoiseKind, ReviewFile, ReviewFileStatus, ReviewHunk, ReviewLine,
|
||||
ReviewLineKind,
|
||||
};
|
||||
use luxe_core::{
|
||||
FileChangeStatus, FileChangeSummary, ProjectIdentity, ReviewSummary, TodoSummary,
|
||||
TodoSummaryItem, TodoSummaryStatus, WorkspaceChangesSummary, WorkspaceScopeId,
|
||||
WorkspaceSnapshot,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
/// One file's change for the Changes pane: two hunks, a replaced line, an addition, a deletion.
|
||||
///
|
||||
/// Built through the review's own content types, which is the point of the pane sharing them —
|
||||
/// a fixture that assembled its own shape would prove nothing about what a real capture renders as.
|
||||
pub(super) fn changes_fixture_file(path: &str) -> ReviewFile {
|
||||
let source = |old: Option<u32>, new: Option<u32>, kind: ReviewLineKind, text: &str| {
|
||||
ReviewLine { old_line: old, new_line: new, kind, text: text.into() }
|
||||
};
|
||||
let id = FileId::from_path_lineage(Some(Path::new(path)), Some(Path::new(path)));
|
||||
let hunk =
|
||||
|label: &str, old: LineRange, new: LineRange, heading: &str, lines: Vec<ReviewLine>| {
|
||||
ReviewHunk {
|
||||
id: HunkId::from_content(&id, label, label),
|
||||
old_range: old,
|
||||
new_range: new,
|
||||
heading: Some(heading.into()),
|
||||
symbol: None,
|
||||
lines,
|
||||
noise: NoiseKind::Semantic,
|
||||
}
|
||||
};
|
||||
ReviewFile {
|
||||
id: id.clone(),
|
||||
old_path: Some(path.into()),
|
||||
new_path: Some(path.into()),
|
||||
status: ReviewFileStatus::Modified,
|
||||
language: Some("rs".into()),
|
||||
additions: Some(48),
|
||||
deletions: Some(9),
|
||||
hunks: vec![
|
||||
hunk(
|
||||
"changes-a",
|
||||
LineRange::new(140, 6),
|
||||
LineRange::new(140, 8),
|
||||
"fn change_lines",
|
||||
vec![
|
||||
source(Some(140), Some(140), ReviewLineKind::Context, " let seen = app.review.seen.as_ref();"),
|
||||
source(Some(141), None, ReviewLineKind::Deletion, " let rows = changes.rows(seen, row_cap);"),
|
||||
source(None, Some(141), ReviewLineKind::Addition, " let all = changes.rows(seen, usize::MAX);"),
|
||||
source(None, Some(142), ReviewLineKind::Addition, " let offset = app.dock.changes_scroll.min(all.len());"),
|
||||
source(Some(142), Some(143), ReviewLineKind::Context, " let shared = shared_row_prefix(&all);"),
|
||||
source(Some(143), Some(144), ReviewLineKind::Context, " if !shared.is_empty() {"),
|
||||
source(Some(144), Some(145), ReviewLineKind::Context, " lines.push(muted_line(format!(\"under {shared}\"), app));"),
|
||||
source(Some(145), Some(146), ReviewLineKind::Context, " }"),
|
||||
],
|
||||
),
|
||||
hunk(
|
||||
"changes-b",
|
||||
LineRange::new(212, 5),
|
||||
LineRange::new(214, 6),
|
||||
"fn change_file_line",
|
||||
vec![
|
||||
source(Some(212), Some(214), ReviewLineKind::Context, " let styles = &app.theme_styles;"),
|
||||
source(Some(213), None, ReviewLineKind::Deletion, " let ink = if reviewed { styles.dim } else { styles.text };"),
|
||||
source(None, Some(215), ReviewLineKind::Addition, " let open = app.changes.as_ref().is_some_and(|view| view.path == path);"),
|
||||
source(None, Some(216), ReviewLineKind::Addition, " let ink = if open { styles.selected_bg } else { styles.text };"),
|
||||
source(Some(214), Some(217), ReviewLineKind::Context, " Line::from(spans)"),
|
||||
source(Some(215), Some(218), ReviewLineKind::Context, "}"),
|
||||
],
|
||||
),
|
||||
],
|
||||
binary: false,
|
||||
generated: false,
|
||||
non_text: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// One file this session changed outside the project, as a peek at it renders.
|
||||
///
|
||||
/// A configuration file in no repository, so its change is measured against the copy retained
|
||||
/// before the first write rather than against any `HEAD` — which is what a peek at one of these
|
||||
/// actually shows.
|
||||
pub(super) fn external_fixture_file(path: &str) -> ReviewFile {
|
||||
let source = |old: Option<u32>, new: Option<u32>, kind: ReviewLineKind, text: &str| {
|
||||
ReviewLine { old_line: old, new_line: new, kind, text: text.into() }
|
||||
};
|
||||
let name = Path::new(path).file_name().map(Path::new).unwrap_or(Path::new(path));
|
||||
let id = FileId::from_path_lineage(Some(name), Some(name));
|
||||
ReviewFile {
|
||||
id: id.clone(),
|
||||
old_path: Some(name.into()),
|
||||
new_path: Some(name.into()),
|
||||
status: ReviewFileStatus::Modified,
|
||||
language: Some("json".into()),
|
||||
additions: Some(4),
|
||||
deletions: Some(1),
|
||||
hunks: vec![ReviewHunk {
|
||||
id: HunkId::from_content(&id, "external-a", "external-a"),
|
||||
old_range: LineRange::new(12, 5),
|
||||
new_range: LineRange::new(12, 8),
|
||||
heading: None,
|
||||
symbol: None,
|
||||
lines: vec![
|
||||
source(Some(12), Some(12), ReviewLineKind::Context, " \"models\": {"),
|
||||
source(
|
||||
Some(13),
|
||||
None,
|
||||
ReviewLineKind::Deletion,
|
||||
" \"default\": \"qwen3.8-14b\",",
|
||||
),
|
||||
source(
|
||||
None,
|
||||
Some(13),
|
||||
ReviewLineKind::Addition,
|
||||
" \"default\": \"qwen3.8-27b\",",
|
||||
),
|
||||
source(
|
||||
None,
|
||||
Some(14),
|
||||
ReviewLineKind::Addition,
|
||||
" \"summarizer\": \"qwen3.8-4b\",",
|
||||
),
|
||||
source(Some(14), Some(15), ReviewLineKind::Context, " \"thinking\": \"medium\""),
|
||||
source(Some(15), Some(16), ReviewLineKind::Context, " }"),
|
||||
],
|
||||
noise: NoiseKind::Semantic,
|
||||
}],
|
||||
binary: false,
|
||||
generated: false,
|
||||
non_text: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A session that has spent on the turn *and* on a review, so the dock's per-source breakdown has
|
||||
/// something to show.
|
||||
pub(super) fn dock_session_usage() -> luxe_core::usage::SessionUsage {
|
||||
use luxe_core::usage::{SessionUsage, SourceUsage, UsageSource, UsageTotals};
|
||||
let agent = UsageTotals {
|
||||
calls: 9,
|
||||
prompt_tokens: 12_400,
|
||||
completion_tokens: 3_800,
|
||||
cache_read_tokens: 21_000,
|
||||
cost_usd: 0.42,
|
||||
..Default::default()
|
||||
};
|
||||
let review = UsageTotals {
|
||||
calls: 2,
|
||||
prompt_tokens: 9_100,
|
||||
completion_tokens: 1_400,
|
||||
cost_usd: 0.031,
|
||||
..Default::default()
|
||||
};
|
||||
let mut total = agent;
|
||||
total.merge(&review);
|
||||
SessionUsage {
|
||||
total,
|
||||
by_source: vec![
|
||||
SourceUsage { source: UsageSource::Agent, totals: agent },
|
||||
SourceUsage { source: UsageSource::Review, totals: review },
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dock_workspace_snapshot() -> WorkspaceSnapshot {
|
||||
let mut snapshot = WorkspaceSnapshot::empty(
|
||||
WorkspaceScopeId::new("fixture-dock"),
|
||||
ProjectIdentity {
|
||||
root: "/work/luxe".into(),
|
||||
display_name: "luxe".into(),
|
||||
display_path: "~/work/luxe".into(),
|
||||
git_branch: Some("feature/context-dock".into()),
|
||||
git_dirty: true,
|
||||
git_head: None,
|
||||
},
|
||||
);
|
||||
// In the order they were written, which is the order the rail draws them: the finished ones
|
||||
// stay where they were rather than sinking to the bottom, so the checklist reads top to bottom
|
||||
// and the ticks descend through it. Longer than the rail's budget on purpose, so the capture
|
||||
// shows the checklist's own scrollbar parked around the work in hand rather than at the top.
|
||||
// The counts add up — 6 pending + 1 active + 4 done + 1 blocked — with the two rows past the
|
||||
// snapshot's bound all still pending.
|
||||
snapshot.todos = TodoSummary {
|
||||
current: Some(TodoSummaryItem {
|
||||
id: "30".into(),
|
||||
subject: "Render the Context Plan".into(),
|
||||
status: TodoSummaryStatus::InProgress,
|
||||
blocked_by: Vec::new(),
|
||||
}),
|
||||
items: vec![
|
||||
TodoSummaryItem {
|
||||
id: "26".into(),
|
||||
subject: "Read the workspace snapshot".into(),
|
||||
status: TodoSummaryStatus::Completed,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "27".into(),
|
||||
subject: "Name the sections".into(),
|
||||
status: TodoSummaryStatus::Completed,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "28".into(),
|
||||
subject: "Model the snapshot".into(),
|
||||
status: TodoSummaryStatus::Completed,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "29".into(),
|
||||
subject: "Reduce it for the rail".into(),
|
||||
status: TodoSummaryStatus::Completed,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "30".into(),
|
||||
subject: "Render the Context Plan".into(),
|
||||
status: TodoSummaryStatus::InProgress,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "31".into(),
|
||||
subject: "Capture responsive fixtures".into(),
|
||||
status: TodoSummaryStatus::Blocked,
|
||||
blocked_by: vec!["30".into()],
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "32".into(),
|
||||
subject: "Wire the dock hit regions".into(),
|
||||
status: TodoSummaryStatus::Pending,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "33".into(),
|
||||
subject: "Document the sections".into(),
|
||||
status: TodoSummaryStatus::Pending,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "34".into(),
|
||||
subject: "Capture the responsive docks".into(),
|
||||
status: TodoSummaryStatus::Pending,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "35".into(),
|
||||
subject: "Check it under a bare font".into(),
|
||||
status: TodoSummaryStatus::Pending,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
],
|
||||
pending: 6,
|
||||
in_progress: 1,
|
||||
completed: 4,
|
||||
blocked: 1,
|
||||
total: 12,
|
||||
truncated: true,
|
||||
};
|
||||
let change = |path: &str, status, additions, deletions, binary| FileChangeSummary {
|
||||
path: path.into(),
|
||||
status,
|
||||
additions,
|
||||
deletions,
|
||||
binary,
|
||||
};
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![
|
||||
// A root-level file: common in practice, and the only way a screenshot shows the
|
||||
// `/ (root)` heading.
|
||||
change("PLAN.md", FileChangeStatus::Modified, Some(64), Some(18), false),
|
||||
change(
|
||||
"crates/luxe-tui/src/view/dock.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(48),
|
||||
Some(9),
|
||||
false,
|
||||
),
|
||||
change(
|
||||
"crates/luxe-tui/src/statusline.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(21),
|
||||
Some(4),
|
||||
false,
|
||||
),
|
||||
change(
|
||||
"crates/luxe-tui/src/dashboard.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(6),
|
||||
Some(2),
|
||||
false,
|
||||
),
|
||||
change(
|
||||
"crates/luxe-core/src/workspace.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(13),
|
||||
Some(0),
|
||||
false,
|
||||
),
|
||||
change(
|
||||
"crates/luxe-tui/src/fixture.rs",
|
||||
FileChangeStatus::Added,
|
||||
Some(31),
|
||||
Some(0),
|
||||
false,
|
||||
),
|
||||
change("assets/context-preview.png", FileChangeStatus::Added, None, None, true),
|
||||
change(
|
||||
"docs/architecture/context-dock.md",
|
||||
FileChangeStatus::Renamed,
|
||||
Some(2),
|
||||
Some(2),
|
||||
false,
|
||||
),
|
||||
change(".luxe/agent-loop/state.json", FileChangeStatus::Untracked, None, None, false),
|
||||
],
|
||||
total_files: 12,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
truncated: true,
|
||||
};
|
||||
// Both kinds of place, because they promise different things: a checkout Git reports in full,
|
||||
// and loose files measured only against what the session found. Three of them, so the section
|
||||
// outgrows its budget and the capture shows the scrollbar that makes the rest reachable.
|
||||
snapshot.external = luxe_core::ExternalChangesSummary {
|
||||
roots: vec![
|
||||
luxe_core::ExternalRootSummary {
|
||||
root: "/home/dev/work/luxe-sdk".into(),
|
||||
display_path: "~/work/luxe-sdk".into(),
|
||||
git_branch: Some("main".into()),
|
||||
git: true,
|
||||
files: vec![
|
||||
change("src/client.ts", FileChangeStatus::Modified, Some(18), Some(3), false),
|
||||
change("src/events.ts", FileChangeStatus::Added, Some(64), Some(0), false),
|
||||
],
|
||||
total_files: 2,
|
||||
truncated: false,
|
||||
},
|
||||
luxe_core::ExternalRootSummary {
|
||||
root: "/home/dev/work/luxe-docs".into(),
|
||||
display_path: "~/work/luxe-docs".into(),
|
||||
git_branch: Some("guide".into()),
|
||||
git: true,
|
||||
files: vec![
|
||||
change(
|
||||
"guide/interface.md",
|
||||
FileChangeStatus::Modified,
|
||||
Some(31),
|
||||
Some(6),
|
||||
false,
|
||||
),
|
||||
change("README.md", FileChangeStatus::Modified, Some(2), Some(2), false),
|
||||
],
|
||||
total_files: 2,
|
||||
truncated: false,
|
||||
},
|
||||
luxe_core::ExternalRootSummary {
|
||||
root: "/home/dev/.config/luxe".into(),
|
||||
display_path: "~/.config/luxe".into(),
|
||||
git_branch: None,
|
||||
git: false,
|
||||
files: vec![change(
|
||||
"models.json",
|
||||
FileChangeStatus::Modified,
|
||||
Some(4),
|
||||
Some(1),
|
||||
false,
|
||||
)],
|
||||
total_files: 1,
|
||||
truncated: false,
|
||||
},
|
||||
],
|
||||
total_files: 5,
|
||||
additions: Some(119),
|
||||
deletions: Some(12),
|
||||
truncated: false,
|
||||
};
|
||||
snapshot.review = Some(ReviewSummary {
|
||||
id: "fixture-review".into(),
|
||||
title: "Fix the stale reference".into(),
|
||||
source: "working tree".into(),
|
||||
unresolved_findings: 1,
|
||||
completed_at_ms: 2,
|
||||
});
|
||||
snapshot
|
||||
}
|
||||
|
||||
pub fn seed_plan_usage(app: &mut App) {
|
||||
app.status.plan_usage = Some(luxe_core::provider::PlanUsage {
|
||||
plan: Some("plus".into()),
|
||||
primary: Some(luxe_core::provider::PlanWindow {
|
||||
used_percent: 12.0,
|
||||
window_minutes: 10_080,
|
||||
resets_in_secs: Some(603_553),
|
||||
}),
|
||||
secondary: None,
|
||||
credits_balance: None,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user