refactor(gateway): 重构格式转换候选资格检查并优化测试基础设施

- 将 format_conversion_disabled 的过滤提前到候选遴选阶段,替代原来的 skip_reason 标记机制
- 为测试添加 execution_runtime_sync_override 直接注入支持,避免启动额外 HTTP 服务器
- 将 submit_terminal_event 改为 async record_terminal_event 确保失败用量事件可靠入库
- 新增 test_support 模块封装可重试的 loopback 端口绑定逻辑
- 前端:poolTrace 将 skipped 从隐藏状态移除,新增 buildPoolParticipatedCandidates 统一新旧链路逻辑,并将 skipped 状态色改为 foreground
This commit is contained in:
fawney19
2026-04-20 16:59:18 +08:00
parent 87afe4898e
commit 226a6e58d5
21 changed files with 380 additions and 247 deletions

View File

@@ -20,10 +20,32 @@ use super::{
LocalProviderDeleteTaskState, ProviderTransportSnapshotCacheKey,
};
#[cfg(test)]
type TestExecutionRuntimeSyncOverrideFn = dyn Fn(
&aether_contracts::ExecutionPlan,
) -> Result<aether_contracts::ExecutionResult, crate::GatewayError>
+ Send
+ Sync;
#[cfg(test)]
#[derive(Clone)]
pub(crate) struct TestExecutionRuntimeSyncOverride(
pub(crate) Arc<TestExecutionRuntimeSyncOverrideFn>,
);
#[cfg(test)]
impl std::fmt::Debug for TestExecutionRuntimeSyncOverride {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("TestExecutionRuntimeSyncOverride(..)")
}
}
#[derive(Debug, Clone)]
pub struct AppState {
#[cfg(test)]
pub(crate) execution_runtime_override_base_url: Option<String>,
#[cfg(test)]
pub(crate) execution_runtime_sync_override: Option<TestExecutionRuntimeSyncOverride>,
pub(crate) data: Arc<GatewayDataState>,
pub(crate) usage_runtime: Arc<usage::UsageRuntime>,
pub(crate) video_tasks: Arc<VideoTaskService>,

View File

@@ -130,6 +130,8 @@ impl AppState {
execution_runtime_override_base_url: execution_runtime_override_base_url
.map(|value| value.trim_end_matches('/').to_string())
.filter(|value| !value.is_empty()),
#[cfg(test)]
execution_runtime_sync_override: None,
data: Arc::clone(&data),
usage_runtime: Arc::new(usage::UsageRuntime::disabled()),
video_tasks: Arc::new(VideoTaskService::new(

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::sync::{Arc, Mutex as StdMutex};
use aether_contracts::{ExecutionPlan, ExecutionResult};
use aether_data_contracts::repository::candidates::RequestCandidateReadRepository;
use aether_data_contracts::repository::provider_catalog::ProviderCatalogReadRepository;
use aether_data_contracts::repository::usage::{UsageReadRepository, UsageRepository};
@@ -170,6 +171,22 @@ impl AppState {
self
}
pub(crate) fn with_execution_runtime_sync_override_for_tests<F>(
mut self,
override_fn: F,
) -> Self
where
F: Fn(&ExecutionPlan) -> Result<ExecutionResult, crate::GatewayError>
+ Send
+ Sync
+ 'static,
{
self.execution_runtime_sync_override = Some(super::app::TestExecutionRuntimeSyncOverride(
Arc::new(override_fn),
));
self
}
pub(crate) fn with_oauth_refresh_coordinator_for_tests(
mut self,
coordinator: provider_transport::LocalOAuthRefreshCoordinator,