mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 18:37:46 +08:00
feat(models): add external catalog proxy selection
This commit is contained in:
@@ -350,13 +350,22 @@ async fn gateway_imports_admin_system_config_locally_and_persists_data_impl() {
|
||||
let (gateway_url, gateway_handle) = start_server(gateway).await;
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let mut import_payload = sample_system_import_payload();
|
||||
import_payload["system_configs"]
|
||||
.as_array_mut()
|
||||
.expect("system configs should be an array")
|
||||
.push(json!({
|
||||
"key": "external_models_proxy_node_id",
|
||||
"value": null,
|
||||
"description": "External models proxy"
|
||||
}));
|
||||
let response = client
|
||||
.post(format!("{gateway_url}/api/admin/system/config/import"))
|
||||
.header(GATEWAY_HEADER, "rust-phase3b")
|
||||
.header(TRUSTED_ADMIN_USER_ID_HEADER, "admin-user-123")
|
||||
.header(TRUSTED_ADMIN_USER_ROLE_HEADER, "admin")
|
||||
.header(TRUSTED_ADMIN_SESSION_ID_HEADER, "session-123")
|
||||
.json(&sample_system_import_payload())
|
||||
.json(&import_payload)
|
||||
.send()
|
||||
.await
|
||||
.expect("request should succeed");
|
||||
@@ -372,7 +381,7 @@ async fn gateway_imports_admin_system_config_locally_and_persists_data_impl() {
|
||||
assert_eq!(payload["stats"]["models"]["created"], json!(1));
|
||||
assert_eq!(payload["stats"]["ldap"]["created"], json!(1));
|
||||
assert_eq!(payload["stats"]["oauth"]["created"], json!(1));
|
||||
assert_eq!(payload["stats"]["system_configs"]["created"], json!(2));
|
||||
assert_eq!(payload["stats"]["system_configs"]["created"], json!(3));
|
||||
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
|
||||
|
||||
let global_models = global_model_repository
|
||||
@@ -531,8 +540,16 @@ async fn gateway_imports_admin_system_config_locally_and_persists_data_impl() {
|
||||
.iter()
|
||||
.find(|entry| entry["key"] == "smtp_password")
|
||||
.expect("smtp_password should exist");
|
||||
let exported_external_models_proxy = exported_system_configs
|
||||
.iter()
|
||||
.find(|entry| entry["key"] == "external_models_proxy_node_id")
|
||||
.expect("external models proxy should exist");
|
||||
assert_eq!(exported_site_name["value"], "Imported Aether");
|
||||
assert_eq!(exported_smtp_password["value"], "smtp-secret");
|
||||
assert_eq!(
|
||||
exported_external_models_proxy["value"],
|
||||
serde_json::Value::Null
|
||||
);
|
||||
|
||||
gateway_handle.abort();
|
||||
upstream_handle.abort();
|
||||
@@ -2459,10 +2476,11 @@ fn gateway_skips_proxy_nodes_during_admin_system_config_import() {
|
||||
}
|
||||
|
||||
async fn gateway_skips_proxy_nodes_during_admin_system_config_import_impl() {
|
||||
let data_state = build_empty_admin_system_data_state();
|
||||
let gateway = build_router_with_state(
|
||||
AppState::new()
|
||||
.expect("gateway should build")
|
||||
.with_data_state_for_tests(build_empty_admin_system_data_state()),
|
||||
.with_data_state_for_tests(data_state.clone()),
|
||||
);
|
||||
let (gateway_url, gateway_handle) = start_server(gateway).await;
|
||||
|
||||
@@ -2482,6 +2500,11 @@ async fn gateway_skips_proxy_nodes_during_admin_system_config_import_impl() {
|
||||
"name": "Legacy Node",
|
||||
"ip": "127.0.0.1",
|
||||
"port": 8080
|
||||
}],
|
||||
"system_configs": [{
|
||||
"key": "external_models_proxy_node_id",
|
||||
"value": "legacy-node-1",
|
||||
"description": "External models proxy"
|
||||
}]
|
||||
}))
|
||||
.send()
|
||||
@@ -2491,6 +2514,7 @@ async fn gateway_skips_proxy_nodes_during_admin_system_config_import_impl() {
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
let payload: Value = response.json().await.expect("json body should parse");
|
||||
assert_eq!(payload["stats"]["proxy_nodes"]["skipped"], json!(1));
|
||||
assert_eq!(payload["stats"]["system_configs"]["created"], json!(1));
|
||||
assert!(payload["stats"]["errors"]
|
||||
.as_array()
|
||||
.expect("errors should be an array")
|
||||
@@ -2498,6 +2522,20 @@ async fn gateway_skips_proxy_nodes_during_admin_system_config_import_impl() {
|
||||
.any(|item| item
|
||||
.as_str()
|
||||
.is_some_and(|value| value.contains("暂不支持导入代理节点"))));
|
||||
assert!(payload["stats"]["errors"]
|
||||
.as_array()
|
||||
.expect("errors should be an array")
|
||||
.iter()
|
||||
.any(|item| item
|
||||
.as_str()
|
||||
.is_some_and(|value| value.contains("已切换为直连"))));
|
||||
assert_eq!(
|
||||
data_state
|
||||
.find_system_config_value("external_models_proxy_node_id")
|
||||
.await
|
||||
.expect("external models proxy config lookup should succeed"),
|
||||
Some(Value::Null)
|
||||
);
|
||||
|
||||
gateway_handle.abort();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user