use super::*;
#[test]
fn editing_an_anthropic_backend_round_trips_its_pinned_kind() {
let mut s = PanelState::new(PanelSeed {
options: vec![BackendOption {
name: "claude".to_string(),
selection: BackendSelection::Named("claude".to_string()),
source: BackendSource::UserDropIn,
kind: Some(BackendKind::Anthropic),
endpoint: "https://api.anthropic.com".to_string(),
model: None,
api_key_env: Some("ANTHROPIC_API_KEY".to_string()),
api_key_file: None,
}],
active: Some(0),
default_backend: None,
});
s.begin_edit();
let Mode::Form(form) = &s.mode else {
panic!("edit should open the form");
};
assert_eq!(
kind_label(KIND_LADDER[form.kind_idx]),
"anthropic",
"the kind dial prefills at the drop-in's pinned kind"
);
s.form_nav(1); s.form_nav(1); s.form_nav(1); type_text(&mut s, "claude-opus-4");
let mut seen: Vec<BackendEdit> = Vec::new();
let mut persist = |edit: &BackendEdit| {
seen.push(edit.clone());
BackendSaveResult::Saved {
note: String::new(),
}
};
assert!(s.submit_form(&mut persist));
assert_eq!(
seen[0].kind,
Some(BackendKind::Anthropic),
"an untouched kind dial round-trips the pinned kind"
);
assert!(!seen[0].dirty.kind, "an untouched kind is not written back");
assert!(
!seen[0].dirty.endpoint,
"an untouched url is not written back"
);
assert!(seen[0].dirty.model, "the typed model IS written");
}
#[test]
fn editing_a_kind_the_dial_cannot_represent_is_refused_not_downgraded() {
let mut s = PanelState::new(PanelSeed {
options: vec![BackendOption {
name: "local".to_string(),
selection: BackendSelection::Named("local".to_string()),
source: BackendSource::UserDropIn,
kind: Some(BackendKind::Embedded),
endpoint: String::new(),
model: None,
api_key_env: None,
api_key_file: None,
}],
active: Some(0),
default_backend: None,
});
s.begin_edit();
assert!(matches!(s.mode, Mode::Choose), "no form opens");
let status = s.status.as_deref().unwrap_or_default();
assert!(status.contains("embedded"), "{status}");
assert!(status.contains("http backends only"), "{status}");
}
#[test]
fn edit_is_blocked_for_kind_fallbacks_and_inline_entries() {
let mut s = panel();
s.cycle(1); s.cycle(1); s.begin_edit();
assert!(matches!(s.mode, Mode::Choose), "inline entry: no form");
assert!(s.status.as_deref().unwrap().contains("inline"));
s.cycle(1); s.begin_edit();
assert!(matches!(s.mode, Mode::Choose));
assert!(s.status.as_deref().unwrap().contains("aren't editable"));
}