aKode setup: scelta di dove salvare la chiave API (portachiavi o file protetto)
- nuovo passo «Dove salvo la chiave?» dopo il campo Chiave API (solo se inserita), preselezionato secondo provider_api_key_store; senza portachiavi solo il file - la scelta scrive provider_api_key_store (impostazione globale: file oppure auto), salva la chiave solo nel backend scelto, rimuove la copia nell'altro e sposta le chiavi degli altri provider - akode-login: save_provider_api_key_to(_with_keyring), sonda del portachiavi - test: file 0600 e nessuna chiave in config.toml, portachiavi senza file, cambio con rimozione della vecchia copia; snapshot 60/80/120 senza la chiave Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,8 @@ const SECRET: &str = "sk-akode-test-secret-0123456789";
|
||||
fn wizard() -> SetupWizard {
|
||||
let mut ctx = SetupContext {
|
||||
include_theme: true,
|
||||
key_store_mode: AuthCredentialsStoreMode::Auto,
|
||||
keyring_available: true,
|
||||
..Default::default()
|
||||
};
|
||||
ctx.existing_provider_ids
|
||||
@@ -146,6 +148,9 @@ fn model_list_screen() {
|
||||
let mut wizard = endpoint_wizard();
|
||||
wizard.form_focus = 3;
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
// A key was entered: choose where to store it first.
|
||||
assert_eq!(wizard.page, Page::KeyStore);
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.page, Page::Model);
|
||||
assert!(wizard.pending.is_some());
|
||||
insta::assert_snapshot!("setup_model_loading_80", render(&wizard, 80, 12));
|
||||
@@ -370,3 +375,87 @@ fn long_model_list_filters_by_text_and_free_toggle() {
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.model, "m-1");
|
||||
}
|
||||
|
||||
/// The endpoint form with a key, confirmed: the key storage choice follows.
|
||||
fn key_store_wizard(configure: impl FnOnce(&mut SetupContext)) -> SetupWizard {
|
||||
let mut ctx = wizard().ctx.clone();
|
||||
configure(&mut ctx);
|
||||
let mut wizard = SetupWizard::new(FrameRequester::test_dummy(), ctx);
|
||||
wizard.go(Page::Endpoint);
|
||||
type_text(&mut wizard, "imeAI");
|
||||
wizard.handle_key_event(key(KeyCode::Tab));
|
||||
type_text(&mut wizard, "http://192.168.40.25:8080/v1");
|
||||
wizard.handle_key_event(key(KeyCode::Tab));
|
||||
type_text(&mut wizard, SECRET);
|
||||
wizard.handle_key_event(key(KeyCode::Tab));
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.page, Page::KeyStore);
|
||||
wizard
|
||||
}
|
||||
|
||||
fn key_store_edit(wizard: &SetupWizard) -> Option<serde_json::Value> {
|
||||
let edits = wizard.config_edits("imeai", "imeAI", /*has_key*/ true);
|
||||
let rendered = serde_json::to_string(
|
||||
&edits
|
||||
.iter()
|
||||
.map(|edit| (edit.key_path.clone(), edit.value.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.expect("json");
|
||||
assert!(!rendered.contains(SECRET));
|
||||
edits
|
||||
.into_iter()
|
||||
.find(|edit| edit.key_path == "provider_api_key_store")
|
||||
.map(|edit| edit.value)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_store_choice_defaults_to_the_keyring() {
|
||||
let mut wizard = key_store_wizard(|_| {});
|
||||
snapshot_all_widths("setup_key_store", &wizard, 12);
|
||||
assert!(!wizard.key_in_file);
|
||||
assert_eq!(key_store_edit(&wizard), None);
|
||||
wizard.handle_key_event(key(KeyCode::Down));
|
||||
assert!(wizard.key_in_file);
|
||||
snapshot_all_widths("setup_key_store_file", &wizard, 14);
|
||||
assert_eq!(key_store_edit(&wizard), Some(serde_json::json!("file")));
|
||||
for width in [40u16, 60, 80, 120] {
|
||||
assert!(!render(&wizard, width, 14).contains("sk-akode"));
|
||||
}
|
||||
wizard.handle_key_event(key(KeyCode::Esc));
|
||||
assert_eq!(wizard.page, Page::Endpoint);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_store_choice_preselects_the_configured_file() {
|
||||
let mut wizard = key_store_wizard(|ctx| ctx.key_store_mode = AuthCredentialsStoreMode::File);
|
||||
assert!(wizard.key_in_file);
|
||||
assert_eq!(key_store_edit(&wizard), None);
|
||||
wizard.handle_key_event(key(KeyCode::Char('1')));
|
||||
assert!(!wizard.key_in_file);
|
||||
assert_eq!(key_store_edit(&wizard), Some(serde_json::json!("auto")));
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.page, Page::Model);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_store_choice_offers_only_the_file_without_a_keyring() {
|
||||
let mut wizard = key_store_wizard(|ctx| ctx.keyring_available = false);
|
||||
assert!(wizard.key_in_file);
|
||||
wizard.handle_key_event(key(KeyCode::Up));
|
||||
assert!(wizard.key_in_file);
|
||||
snapshot_all_widths("setup_key_store_no_keyring", &wizard, 14);
|
||||
assert_eq!(key_store_edit(&wizard), Some(serde_json::json!("file")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn endpoint_without_a_key_skips_the_storage_choice() {
|
||||
let mut wizard = wizard();
|
||||
wizard.go(Page::Endpoint);
|
||||
type_text(&mut wizard, "imeAI");
|
||||
wizard.handle_key_event(key(KeyCode::Tab));
|
||||
type_text(&mut wizard, "http://192.168.40.25:8080/v1");
|
||||
wizard.form_focus = 3;
|
||||
wizard.handle_key_event(key(KeyCode::Enter));
|
||||
assert_eq!(wizard.page, Page::Model);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user