luxe 0.1.5: a provider picker, model ids, and a guided review that says less
The dock's provider row opens a list of providers, and the model picker opens on the provider in use, with tab to widen it; signing in opens it on the provider just signed in to. Models go by their id unless config names them, and the model row wears its maker's mark. The guided review's guide prompt is shorter, the pull request brief shows the start of the description with the rest behind p, its commits drop the Luxe-review and Luxe-revision lines, and the weakened-gates signal is gone. luxe update reruns the installer it was installed with, in place of luxe-cli-update. The preview's FILE tab reads files the session changed outside the project, and only those. Smaller fixes: bash headers are highlighted, the preview loses a blank row, the launcher divider sits inside its frame, and the phone app's top bar is clear of iOS's blur. rustls-webpki 0.103.16 and webpki-roots 1.0.10 fix RUSTSEC-2026-0381 and RUSTSEC-2026-0382, and vite 8.3.4 fixes GHSA-587h-7wmj-h5pm, GHSA-698v-4r3x-3vcv and GHSA-r825-w8mm-5pxw.
This commit is contained in:
54
crates/luxe-tui/src/model_picker/providers.rs
Normal file
54
crates/luxe-tui/src/model_picker/providers.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
//! Provider step — the list of providers the model picker opens on from the dock's provider row.
|
||||
//!
|
||||
//! Choosing a provider keeps the model in use when that provider serves it too, and otherwise moves
|
||||
//! on to that provider's models. [`super::ModelPickerState`] makes that call; this holds the list
|
||||
//! and its cursor.
|
||||
|
||||
use super::ModelEntry;
|
||||
use crate::picker::PickerNav;
|
||||
|
||||
/// One provider row: its id and how many of the catalog's models it serves.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(super) struct ProviderRow {
|
||||
pub(super) id: String,
|
||||
pub(super) models: usize,
|
||||
}
|
||||
|
||||
/// The provider list and its cursor.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(super) struct ProviderStep {
|
||||
pub(super) rows: Vec<ProviderRow>,
|
||||
pub(super) nav: PickerNav,
|
||||
}
|
||||
|
||||
impl ProviderStep {
|
||||
/// Every provider serving one of `models`, with the cursor on `current` when it is among them.
|
||||
pub(super) fn new(models: &[ModelEntry], current: Option<&str>) -> Self {
|
||||
let rows = provider_rows(models);
|
||||
let mut nav = PickerNav::new(rows.len());
|
||||
if let Some(row) = current.and_then(|id| rows.iter().position(|row| row.id == id)) {
|
||||
nav.select(row);
|
||||
}
|
||||
Self { rows, nav }
|
||||
}
|
||||
|
||||
/// The provider under the cursor, if any row matches the query.
|
||||
pub(super) fn selected(&self) -> Option<&ProviderRow> {
|
||||
self.rows.get(self.nav.selected_item_index()?)
|
||||
}
|
||||
|
||||
/// What a reader can type at a provider row: its id.
|
||||
pub(super) fn searchable(&self) -> Vec<String> {
|
||||
self.rows.iter().map(|row| row.id.clone()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// One row per provider, by id. The catalog lists providers in a hash set's order, which means
|
||||
/// nothing, so a reader finds one where the alphabet says it is.
|
||||
fn provider_rows(models: &[ModelEntry]) -> Vec<ProviderRow> {
|
||||
let mut counts = std::collections::BTreeMap::<&str, usize>::new();
|
||||
for entry in models {
|
||||
*counts.entry(entry.info.r#ref.provider.as_str()).or_default() += 1;
|
||||
}
|
||||
counts.into_iter().map(|(id, models)| ProviderRow { id: id.to_owned(), models }).collect()
|
||||
}
|
||||
364
crates/luxe-tui/src/model_picker/render.rs
Normal file
364
crates/luxe-tui/src/model_picker/render.rs
Normal file
@@ -0,0 +1,364 @@
|
||||
//! Model picker drawing — the panel, its search line, the rows of whichever step is showing, and
|
||||
//! the footer that says what `tab` and `←` do from here.
|
||||
|
||||
use super::meta::meta_suffix;
|
||||
use super::providers::ProviderRow;
|
||||
use super::{ModelEntry, ModelPickerState};
|
||||
use crate::glyphs::{icon_label, Icon};
|
||||
use crate::theme::styles::ThemeStyles;
|
||||
use crate::widgets::truncate_end as truncate;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Clear, List, ListItem, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
/// Panel label for the model step, and the start of its title when scoped to a provider.
|
||||
const MODEL_TITLE: &str = "Select model";
|
||||
|
||||
/// Panel label for the provider step.
|
||||
const PROVIDER_TITLE: &str = "Select provider";
|
||||
|
||||
impl ModelPickerState {
|
||||
/// The panel's glyph and title: the step showing, and which provider a scoped list is from.
|
||||
fn title(&self) -> (&'static str, String) {
|
||||
if self.providers.is_some() {
|
||||
return (Icon::Provider.glyph(), PROVIDER_TITLE.to_owned());
|
||||
}
|
||||
match self.scoped_provider() {
|
||||
Some(provider) => (Icon::Model.glyph(), format!("{MODEL_TITLE} \u{b7} {provider}")),
|
||||
None => (Icon::Model.glyph(), MODEL_TITLE.to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The keys along the bottom edge, for the step showing.
|
||||
fn hint(&self) -> String {
|
||||
if self.providers.is_some() {
|
||||
return "enter choose \u{b7} \u{2191}/\u{2193} move \u{b7} esc close".to_owned();
|
||||
}
|
||||
let widen = match (self.served_scope(), self.widened) {
|
||||
(Some(provider), true) => format!("tab only {provider} \u{b7} "),
|
||||
(Some(_), false) => "tab every provider \u{b7} ".to_owned(),
|
||||
(None, _) => String::new(),
|
||||
};
|
||||
let esc = if self.from_providers { "esc back" } else { "esc close" };
|
||||
format!("enter switch \u{b7} {widen}\u{2190} providers \u{b7} {esc}")
|
||||
}
|
||||
|
||||
/// What a model row says after its label: who serves it while the list mixes providers, and
|
||||
/// its id when a configured name stands in for it.
|
||||
fn subtitle(&self, entry: &ModelEntry) -> String {
|
||||
let id = &entry.info.r#ref.id;
|
||||
let named = entry.label != *id;
|
||||
match (self.scoped_provider().is_none(), named) {
|
||||
(true, true) => format!(" {}", entry.qualified_id()),
|
||||
(true, false) => format!(" {}", entry.info.r#ref.provider),
|
||||
(false, true) => format!(" {id}"),
|
||||
(false, false) => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Terminal-cell width for the picker modal: fit the widest row of either step, the footer,
|
||||
/// the title and the note, then add borders and one right-pad cell. Measured over every row so
|
||||
/// the width holds still while a query narrows the list or the reader changes step.
|
||||
///
|
||||
/// The row's own frame is part of the fit rather than a constant beside it: a modal sized to
|
||||
/// the words alone clips the closing cap off its widest row the moment the frame changes.
|
||||
pub(super) fn content_modal_width(&self, available: u16) -> u16 {
|
||||
let chrome = crate::widgets::SELECTION_FRAME + 2 + 2;
|
||||
let model_rows = self.all.iter().map(|entry| {
|
||||
let words = entry.label.width() + entry.qualified_id().width() + 2;
|
||||
chrome + words + meta_suffix(entry).width()
|
||||
});
|
||||
let provider_rows = self.provider_step_rows().into_iter().map(|row| chrome + row.width());
|
||||
let row_width = model_rows.chain(provider_rows).max().unwrap_or(0);
|
||||
let total = self.all.len();
|
||||
let footer_width = format!(" {total}/{total} \u{b7} {} ", self.hint()).width();
|
||||
let (glyph, title) = self.title();
|
||||
let title_width = crate::widgets::panel_title_width(glyph, &title);
|
||||
// The lead space each note line is drawn with comes out of the same three cells the
|
||||
// borders take below, so the text's own width is the whole of what it asks for.
|
||||
let note_width = self.note.iter().map(|line| line.width()).max().unwrap_or(0);
|
||||
let natural = row_width.max(footer_width).max(title_width).max(note_width) as u16;
|
||||
let max_width = available.saturating_sub(4).max(30);
|
||||
natural.saturating_add(3).clamp(30, max_width)
|
||||
}
|
||||
|
||||
/// Every provider row as drawn, for measuring; the step need not be showing.
|
||||
fn provider_step_rows(&self) -> Vec<String> {
|
||||
let step = super::providers::ProviderStep::new(&self.all, None);
|
||||
step.rows.iter().map(provider_text).collect()
|
||||
}
|
||||
|
||||
/// Rows the picker wants in `area`: its list, its chrome, and a floor so it never reads as a
|
||||
/// scrap of a list.
|
||||
pub(crate) fn desired_height(&self, area: Rect) -> u16 {
|
||||
// Borders, the search field and its rule, the rows, the footer
|
||||
let desired =
|
||||
self.match_count().min(14) as u16 + 4 + crate::widgets::FOOTER_ROWS + self.note_rows();
|
||||
desired.max(10 + self.note_rows()).min(area.height.saturating_sub(2))
|
||||
}
|
||||
|
||||
/// Renders the picker as a centered modal over the conversation.
|
||||
pub fn view(
|
||||
&self,
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &ThemeStyles,
|
||||
hit: &std::cell::RefCell<crate::mouse::HitRegions>,
|
||||
) {
|
||||
if area.width < 30 || area.height < 8 {
|
||||
return;
|
||||
}
|
||||
// Fit the widest row (stable across queries) + one right-pad cell, rather than a
|
||||
// fixed-width box with trailing dead space.
|
||||
let width = self.content_modal_width(area.width);
|
||||
let height = self.desired_height(area);
|
||||
self.view_in(frame, crate::widgets::centered_rect(width, height, area), theme, hit);
|
||||
}
|
||||
|
||||
/// Renders the picker's panel at exactly `panel`, for a surface that has already placed it.
|
||||
///
|
||||
/// The Configuration surface hands a finished login straight to this, in the region the wizard
|
||||
/// was just in: "now pick a model" is the last step of setting one up, not a new screen.
|
||||
pub(crate) fn view_in(
|
||||
&self,
|
||||
frame: &mut Frame,
|
||||
panel: Rect,
|
||||
theme: &ThemeStyles,
|
||||
hit: &std::cell::RefCell<crate::mouse::HitRegions>,
|
||||
) {
|
||||
frame.render_widget(Clear, panel);
|
||||
let (glyph, title) = self.title();
|
||||
let block = crate::widgets::titled_panel(glyph, &title, theme);
|
||||
let chunks = self.sections(block.inner(panel));
|
||||
frame.render_widget(block, panel);
|
||||
self.render_note(frame, chunks[0], theme);
|
||||
self.render_search(frame, chunks[1], theme);
|
||||
self.render_list(frame, chunks[2], theme, hit);
|
||||
let count = self.position_label();
|
||||
crate::widgets::render_footer(frame, chunks[3], &self.hint(), Some(&count), theme);
|
||||
}
|
||||
|
||||
/// The panel's inside, top to bottom: the note, the search line, the list and the footer.
|
||||
fn sections(&self, inner: Rect) -> std::rc::Rc<[Rect]> {
|
||||
Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(self.note_rows()),
|
||||
Constraint::Length(2),
|
||||
Constraint::Min(2),
|
||||
Constraint::Length(crate::widgets::FOOTER_ROWS),
|
||||
])
|
||||
.split(inner)
|
||||
}
|
||||
|
||||
/// `3/12`: the cursor's row among the matches, for the footer.
|
||||
fn position_label(&self) -> String {
|
||||
let total = self.match_count();
|
||||
format!("{}/{total}", self.cursor().saturating_add(1).min(total))
|
||||
}
|
||||
|
||||
/// What a login landed, above the list, when there is something to say.
|
||||
fn render_note(&self, frame: &mut Frame, area: Rect, theme: &ThemeStyles) {
|
||||
if self.note.is_empty() {
|
||||
return;
|
||||
}
|
||||
let room = usize::from(area.width).saturating_sub(1);
|
||||
let lines: Vec<Line> = self
|
||||
.note
|
||||
.iter()
|
||||
.map(|line| Line::from(Span::styled(format!(" {}", truncate(line, room)), theme.muted)))
|
||||
.collect();
|
||||
frame.render_widget(Paragraph::new(lines), area);
|
||||
}
|
||||
|
||||
/// The search line, with the terminal's cursor at the end of the query.
|
||||
fn render_search(&self, frame: &mut Frame, area: Rect, theme: &ThemeStyles) {
|
||||
let search = Paragraph::new(Line::from(vec![
|
||||
Span::styled(" Search: ", theme.accent.add_modifier(Modifier::BOLD)),
|
||||
Span::styled(self.query().to_string(), theme.text),
|
||||
]))
|
||||
.block(Block::default().borders(Borders::BOTTOM).border_style(theme.border_muted));
|
||||
frame.render_widget(search, area);
|
||||
let cursor_x = area
|
||||
.x
|
||||
.saturating_add(9)
|
||||
.saturating_add(self.query().width() as u16)
|
||||
.min(area.right().saturating_sub(1));
|
||||
frame.set_cursor_position((cursor_x, area.y));
|
||||
}
|
||||
|
||||
/// The rows of the step showing, or a line saying nothing matches.
|
||||
fn render_list(
|
||||
&self,
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &ThemeStyles,
|
||||
hit: &std::cell::RefCell<crate::mouse::HitRegions>,
|
||||
) {
|
||||
if self.match_count() == 0 {
|
||||
return self.render_empty(frame, area, theme);
|
||||
}
|
||||
let window = self.window(area.height as usize);
|
||||
let width = crate::widgets::list_rows_width(area.width, self.match_count(), area.height);
|
||||
self.register_rows(area, width, window, theme, frame, hit);
|
||||
let available = width.saturating_sub(2 + crate::widgets::SELECTION_FRAME as u16) as usize;
|
||||
let items: Vec<ListItem> = (window.0..window.1)
|
||||
.map(|row| {
|
||||
let selected = row == self.cursor();
|
||||
let spans = self.row_spans(row, selected, available, theme);
|
||||
let line = crate::widgets::selection_row(spans, width.into(), selected, theme);
|
||||
ListItem::new(line)
|
||||
})
|
||||
.collect();
|
||||
frame.render_widget(List::new(items), Rect { width, ..area });
|
||||
}
|
||||
|
||||
/// The line in place of the list when the query matches nothing.
|
||||
fn render_empty(&self, frame: &mut Frame, area: Rect, theme: &ThemeStyles) {
|
||||
let empty = if self.providers.is_some() { "providers" } else { "models" };
|
||||
let message = Paragraph::new(format!(" No matching {empty}")).style(theme.muted);
|
||||
frame.render_widget(message, area);
|
||||
}
|
||||
|
||||
/// Row `row` of the step showing, as spans.
|
||||
fn row_spans(
|
||||
&self,
|
||||
row: usize,
|
||||
selected: bool,
|
||||
available: usize,
|
||||
theme: &ThemeStyles,
|
||||
) -> Vec<Span<'static>> {
|
||||
match &self.providers {
|
||||
Some(step) => self.provider_spans(step, row, selected, available, theme),
|
||||
None => self.model_spans(row, selected, available, theme),
|
||||
}
|
||||
}
|
||||
|
||||
/// The `(first, end)` rows of the filtered list that fit `capacity`, around the cursor.
|
||||
fn window(&self, capacity: usize) -> (usize, usize) {
|
||||
let total = self.match_count();
|
||||
let start =
|
||||
(self.cursor() + 1).saturating_sub(capacity).min(total.saturating_sub(capacity));
|
||||
(start, (start + capacity).min(total))
|
||||
}
|
||||
|
||||
/// Publishes a click target per visible row, and the scrollbar beside them.
|
||||
fn register_rows(
|
||||
&self,
|
||||
area: Rect,
|
||||
width: u16,
|
||||
(start, end): (usize, usize),
|
||||
theme: &ThemeStyles,
|
||||
frame: &mut Frame,
|
||||
hit: &std::cell::RefCell<crate::mouse::HitRegions>,
|
||||
) {
|
||||
let mut regions = hit.borrow_mut();
|
||||
for row in start..end {
|
||||
let row_rect = Rect::new(area.x, area.y.saturating_add((row - start) as u16), width, 1);
|
||||
regions.push(row_rect, crate::mouse::MouseTarget::ModelRow(row));
|
||||
}
|
||||
let (list, position) = (crate::mouse::OverlayList::Models, (start, self.match_count()));
|
||||
crate::widgets::list_scrollbar(frame, &mut regions, area, list, position, theme);
|
||||
}
|
||||
|
||||
/// One model row: cursor, the in-use dot, label, who serves it or its id, and what it is.
|
||||
fn model_spans(
|
||||
&self,
|
||||
row: usize,
|
||||
selected: bool,
|
||||
available: usize,
|
||||
theme: &ThemeStyles,
|
||||
) -> Vec<Span<'static>> {
|
||||
let Some(entry) = self.nav.item_index_at(row).and_then(|index| self.items.get(index))
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let is_active = self.active.as_ref() == Some(&entry.info.r#ref);
|
||||
let label = truncate(&entry.label, available.saturating_sub(MARKER_WIDTH + 3));
|
||||
// The subtitle, then what it is, in whatever the label leaves: a row that ran past the
|
||||
// frame was cut by it mid-word, and took the selection's closing cap with it
|
||||
let room = available.saturating_sub(MARKER_WIDTH).saturating_sub(label.width());
|
||||
let subtitle = truncate(&self.subtitle(entry), room);
|
||||
let meta = truncate(&meta_suffix(entry), room.saturating_sub(subtitle.width()));
|
||||
let mut spans = lead_spans(selected, is_active, theme);
|
||||
spans.push(Span::styled(label, theme.label_on(selected)));
|
||||
spans.push(Span::styled(subtitle, theme.muted.patch(row_background(selected, theme))));
|
||||
if !meta.is_empty() {
|
||||
spans.push(Span::styled(meta, theme.secondary_on(selected)));
|
||||
}
|
||||
spans
|
||||
}
|
||||
|
||||
/// One provider row: cursor, the in-use dot, its mark and id, and how many models it serves.
|
||||
fn provider_spans(
|
||||
&self,
|
||||
step: &super::providers::ProviderStep,
|
||||
row: usize,
|
||||
selected: bool,
|
||||
available: usize,
|
||||
theme: &ThemeStyles,
|
||||
) -> Vec<Span<'static>> {
|
||||
let Some(provider) = step.nav.item_index_at(row).and_then(|index| step.rows.get(index))
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let is_active = self.active.as_ref().is_some_and(|active| active.provider == provider.id);
|
||||
let name = icon_label(crate::widgets::provider_icon(&provider.id).glyph(), &provider.id);
|
||||
let name = truncate(&name, available.saturating_sub(MARKER_WIDTH));
|
||||
let count = truncate(&model_count(provider), available.saturating_sub(name.width() + 2));
|
||||
let mut spans = lead_spans(selected, is_active, theme);
|
||||
spans.push(Span::styled(name, theme.label_on(selected)));
|
||||
spans.push(Span::styled(count, theme.muted.patch(row_background(selected, theme))));
|
||||
spans
|
||||
}
|
||||
}
|
||||
|
||||
/// Cells the in-use dot takes, with its gap, whether or not it is drawn.
|
||||
const MARKER_WIDTH: usize = 2;
|
||||
|
||||
/// What every row starts with: the cursor's gutter, then the in-use dot or its blank.
|
||||
fn lead_spans(selected: bool, is_active: bool, theme: &ThemeStyles) -> Vec<Span<'static>> {
|
||||
let marker = if is_active { "\u{25cf} " } else { " " };
|
||||
let marker_style = active_style(is_active, theme).patch(row_background(selected, theme));
|
||||
vec![
|
||||
Span::styled(crate::glyphs::Mark::Cursor.gutter(selected), theme.accent_on(selected)),
|
||||
Span::styled(marker, marker_style),
|
||||
]
|
||||
}
|
||||
|
||||
/// The cursor row's background, for spans that would otherwise leave a gap in it.
|
||||
fn row_background(selected: bool, theme: &ThemeStyles) -> Style {
|
||||
if selected {
|
||||
theme.selected_bg
|
||||
} else {
|
||||
Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// The in-use dot's ink: success on the row in use, muted (and blank) elsewhere.
|
||||
fn active_style(is_active: bool, theme: &ThemeStyles) -> Style {
|
||||
if is_active {
|
||||
theme.success
|
||||
} else {
|
||||
theme.muted
|
||||
}
|
||||
}
|
||||
|
||||
/// ` 12 models`, after a provider's name.
|
||||
fn model_count(provider: &ProviderRow) -> String {
|
||||
match provider.models {
|
||||
1 => " 1 model".to_owned(),
|
||||
count => format!(" {count} models"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A provider row's words as drawn, for measuring the panel.
|
||||
fn provider_text(provider: &ProviderRow) -> String {
|
||||
let name = icon_label(crate::widgets::provider_icon(&provider.id).glyph(), &provider.id);
|
||||
format!(" {name}{}", model_count(provider))
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
use super::meta::meta_suffix;
|
||||
use super::*;
|
||||
use ratatui::layout::Rect;
|
||||
|
||||
fn entry(provider: &str, id: &str, configured: bool) -> ModelEntry {
|
||||
ModelEntry {
|
||||
@@ -111,6 +113,153 @@ fn a_refreshed_catalog_keeps_the_query_and_the_row_under_the_cursor() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The catalog as served by two providers that both offer `claude-sonnet-4-6`.
|
||||
fn shared_catalog() -> Vec<ModelEntry> {
|
||||
let mut models = catalog();
|
||||
models.push(entry("github-copilot", "claude-sonnet-4-6", false));
|
||||
models
|
||||
}
|
||||
|
||||
/// The picker on Anthropic's `claude-sonnet-4-6`, opened on `start`.
|
||||
fn on_sonnet(start: PickerStart) -> ModelPickerState {
|
||||
let active = Some(ModelRef::new("anthropic", "claude-sonnet-4-6"));
|
||||
ModelPickerState::open(shared_catalog(), active).starting_on(start)
|
||||
}
|
||||
|
||||
fn press(picker: &mut ModelPickerState, codes: &[KeyCode]) -> ModelPickerOutcome {
|
||||
codes.iter().map(|code| picker.on_key(&key(*code))).last().expect("a key")
|
||||
}
|
||||
|
||||
/// The model step is about the provider in use, and `tab` widens it to every provider and back,
|
||||
/// keeping the cursor on the model it was on.
|
||||
#[test]
|
||||
fn the_model_step_shows_the_provider_in_use_until_tab_widens_it() {
|
||||
let mut picker = on_sonnet(PickerStart::Models);
|
||||
assert_eq!(picker.match_count(), 2, "anthropic's two");
|
||||
let chosen = || Some("anthropic/claude-sonnet-4-6".to_owned());
|
||||
assert_eq!(picker.selected_entry().map(ModelEntry::qualified_id), chosen());
|
||||
press(&mut picker, &[KeyCode::Tab]);
|
||||
assert_eq!(picker.match_count(), 5, "every provider's");
|
||||
assert_eq!(picker.selected_entry().map(ModelEntry::qualified_id), chosen());
|
||||
press(&mut picker, &[KeyCode::Tab]);
|
||||
assert_eq!(picker.match_count(), 2, "and back");
|
||||
|
||||
// With no model in use there is no provider to be about
|
||||
let unset = ModelPickerState::open(catalog(), None).starting_on(PickerStart::Models);
|
||||
assert_eq!(unset.match_count(), 4);
|
||||
}
|
||||
|
||||
/// A login opens on the provider it signed in to, at the top with nothing chosen, even when the
|
||||
/// model in use is another provider's. `tab` still reaches everything else.
|
||||
#[test]
|
||||
fn a_login_opens_on_the_provider_it_signed_in_to() {
|
||||
let active = Some(ModelRef::new("anthropic", "claude-sonnet-4-6"));
|
||||
let mut picker = ModelPickerState::open(shared_catalog(), active).about_provider("openai");
|
||||
assert_eq!(picker.match_count(), 1, "openai's own");
|
||||
let shown = picker.selected_entry().map(ModelEntry::qualified_id);
|
||||
assert_eq!(shown.as_deref(), Some("openai/gpt-5-codex"));
|
||||
assert_eq!(picker.cursor(), 0);
|
||||
press(&mut picker, &[KeyCode::Tab]);
|
||||
assert_eq!(picker.match_count(), 5, "and tab widens it");
|
||||
}
|
||||
|
||||
/// A local server's models land a moment after the picker opens, so a provider that serves nothing
|
||||
/// yet shows every model until they arrive, then narrows to them.
|
||||
#[test]
|
||||
fn a_provider_whose_models_arrive_late_is_scoped_when_they_do() {
|
||||
let mut picker = ModelPickerState::open(catalog(), None).about_provider("ollama");
|
||||
assert_eq!(picker.match_count(), 4, "nothing of ollama's yet, so everything");
|
||||
let mut arrived = catalog();
|
||||
arrived.push(entry("ollama", "qwen3-coder", false));
|
||||
picker.refresh(arrived);
|
||||
assert_eq!(picker.match_count(), 1, "narrowed once they land");
|
||||
}
|
||||
|
||||
/// The provider step lists each provider once, by name, with the cursor on the one in use.
|
||||
#[test]
|
||||
fn the_provider_step_lists_each_provider_once() {
|
||||
let picker = on_sonnet(PickerStart::Providers);
|
||||
assert!(picker.choosing_provider());
|
||||
assert_eq!(picker.match_count(), 4, "anthropic, github-copilot, lmstudio, openai");
|
||||
assert_eq!(picker.cursor(), 0, "on anthropic, the one in use");
|
||||
let screen = drawn(&picker, Rect::new(0, 0, 120, 30));
|
||||
assert!(screen.contains("Select provider"), "{screen}");
|
||||
assert!(screen.contains("anthropic 2 models"), "{screen}");
|
||||
assert!(screen.contains("lmstudio 1 model "), "{screen}");
|
||||
}
|
||||
|
||||
/// Another provider serving the model in use switches to it there at once: the model was never
|
||||
/// the question, so nothing asks it again.
|
||||
#[test]
|
||||
fn a_provider_serving_the_same_model_switches_to_it_there() {
|
||||
let mut picker = on_sonnet(PickerStart::Providers);
|
||||
match press(&mut picker, &[KeyCode::Down, KeyCode::Enter]) {
|
||||
ModelPickerOutcome::Select(info) => {
|
||||
assert_eq!(info.r#ref, ModelRef::new("github-copilot", "claude-sonnet-4-6"));
|
||||
}
|
||||
other => panic!("expected the same model from copilot, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A provider without the model in use opens on its own models, and `esc` goes back to the
|
||||
/// providers it came from before it closes anything.
|
||||
#[test]
|
||||
fn a_provider_without_the_model_opens_on_its_models() {
|
||||
let mut picker = on_sonnet(PickerStart::Providers);
|
||||
let outcome =
|
||||
press(&mut picker, &[KeyCode::Down, KeyCode::Down, KeyCode::Down, KeyCode::Enter]);
|
||||
assert_eq!(outcome, ModelPickerOutcome::Consumed);
|
||||
assert!(!picker.choosing_provider());
|
||||
let shown = picker.selected_entry().map(ModelEntry::qualified_id);
|
||||
assert_eq!(shown.as_deref(), Some("openai/gpt-5-codex"), "openai's, and only those");
|
||||
assert_eq!(picker.match_count(), 1);
|
||||
|
||||
assert_eq!(press(&mut picker, &[KeyCode::Esc]), ModelPickerOutcome::Consumed);
|
||||
assert!(picker.choosing_provider(), "back to the providers");
|
||||
assert_eq!(press(&mut picker, &[KeyCode::Esc]), ModelPickerOutcome::Close);
|
||||
}
|
||||
|
||||
/// Choosing the provider already in use is asking to see its models, not a switch to nothing new.
|
||||
#[test]
|
||||
fn the_provider_in_use_opens_on_its_models() {
|
||||
let mut picker = on_sonnet(PickerStart::Providers);
|
||||
assert_eq!(press(&mut picker, &[KeyCode::Enter]), ModelPickerOutcome::Consumed);
|
||||
assert!(!picker.choosing_provider());
|
||||
assert_eq!(picker.match_count(), 2);
|
||||
}
|
||||
|
||||
/// `←` reaches the providers from a model step opened anywhere; `esc` there closes, since
|
||||
/// nothing led to it.
|
||||
#[test]
|
||||
fn left_reaches_the_providers_from_the_model_step() {
|
||||
let mut picker = on_sonnet(PickerStart::Models);
|
||||
press(&mut picker, &[KeyCode::Left]);
|
||||
assert!(picker.choosing_provider());
|
||||
assert_eq!(picker.cursor(), 0, "on the provider the models were from");
|
||||
assert_eq!(press(&mut picker, &[KeyCode::Esc]), ModelPickerOutcome::Close);
|
||||
}
|
||||
|
||||
/// A row names its provider only while the list mixes them, and its id only when a configured
|
||||
/// name stands in for it: a model is never written out twice.
|
||||
#[test]
|
||||
fn a_row_says_only_what_its_label_does_not() {
|
||||
let mut picker = on_sonnet(PickerStart::Models);
|
||||
let area = Rect::new(0, 0, 120, 30);
|
||||
let scoped = drawn(&picker, area);
|
||||
assert!(scoped.contains("Select model · anthropic"), "{scoped}");
|
||||
assert!(!scoped.contains("anthropic/"), "{scoped}");
|
||||
assert!(scoped.contains("tab every provider"), "{scoped}");
|
||||
press(&mut picker, &[KeyCode::Tab]);
|
||||
let every = drawn(&picker, area);
|
||||
assert!(every.contains("gpt-5-codex openai"), "{every}");
|
||||
assert!(every.contains("tab only anthropic"), "{every}");
|
||||
|
||||
let named =
|
||||
ModelEntry { label: "sonnet".into(), ..entry("anthropic", "claude-sonnet-4-6", true) };
|
||||
let picker = ModelPickerState::open(vec![named], None);
|
||||
assert!(drawn(&picker, area).contains("sonnet anthropic/claude-sonnet-4-6"));
|
||||
}
|
||||
|
||||
/// The opening line is measured, not guessed at: a panel sized without it clips its own
|
||||
/// hint row out through the bottom border, and one sized to the rows alone truncates it.
|
||||
#[test]
|
||||
@@ -164,7 +313,8 @@ fn a_row_too_long_for_the_frame_is_shortened_inside_it() {
|
||||
assert_eq!(rows.len(), 2, "{screen}");
|
||||
for row in &rows {
|
||||
let inside = row.trim_end().strip_suffix('│').expect("the frame's edge");
|
||||
assert!(inside.trim_end_matches(['▌', ' ']).ends_with('…'), "{screen}");
|
||||
// The label is what gives way; a provider short enough to fit after it still shows
|
||||
assert!(inside.contains("fit-in-s…"), "{screen}");
|
||||
}
|
||||
assert!(rows[0].trim_end().ends_with("▌│"), "the cursor's row keeps its cap: {screen}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user