fix(dbx-cli): 修复空存储下 context 回退
- 在 GUI runtime 不可用且 headless storage 无法打开时返回空上下文 - 增加空 app data 与不可打开 app data 的 dbx-cli 回归测试
This commit is contained in:
parent
37cde903d5
commit
2fd3e533e9
|
|
@ -257,10 +257,7 @@ async fn context(args: &[String]) -> CliEnvelope<serde_json::Value> {
|
|||
match crate::runtime_client::get_json("/context").await {
|
||||
Ok(data) => ok(CliSource::GuiRuntime, data),
|
||||
Err(_) => {
|
||||
let configs = match load_headless_connections().await {
|
||||
Ok(configs) => configs,
|
||||
Err(err) => return err,
|
||||
};
|
||||
let configs = load_headless_connections().await.unwrap_or_default();
|
||||
ok(
|
||||
CliSource::Headless,
|
||||
serde_json::json!({
|
||||
|
|
@ -910,6 +907,37 @@ mod tests {
|
|||
std::env::remove_var("DBX_APP_DATA_DIR");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn context_returns_headless_minimal_context_for_empty_or_unopenable_app_data() {
|
||||
let _guard = ENV_LOCK.lock().unwrap();
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let empty_app_data = dir.path().join("empty-app-data");
|
||||
let unopenable_app_data = dir.path().join("app-data-file");
|
||||
std::fs::write(&unopenable_app_data, "not a directory").unwrap();
|
||||
|
||||
for app_data in [&empty_app_data, &unopenable_app_data] {
|
||||
std::env::set_var("DBX_APP_DATA_DIR", app_data);
|
||||
|
||||
let data = success_data(dispatch(vec!["context".into(), "--format".into(), "json".into()]).await);
|
||||
|
||||
assert_eq!(data["runtime"], "headless");
|
||||
assert!(data["activeConnection"].is_null());
|
||||
assert_eq!(data["configSource"], "headless");
|
||||
}
|
||||
|
||||
std::env::set_var("DBX_APP_DATA_DIR", &unopenable_app_data);
|
||||
assert_failure_code(
|
||||
dispatch(vec!["conn".into(), "list".into(), "--format".into(), "json".into()]).await,
|
||||
CliErrorCode::InternalError,
|
||||
);
|
||||
assert_failure_code(
|
||||
dispatch(vec!["conn".into(), "show".into(), "missing".into(), "--format".into(), "json".into()]).await,
|
||||
CliErrorCode::InternalError,
|
||||
);
|
||||
|
||||
std::env::remove_var("DBX_APP_DATA_DIR");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn runtime_discovery_serves_context_selection_and_current_result_limit() {
|
||||
let _guard = ENV_LOCK.lock().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in New Issue