687 lines
22 KiB
Rust
687 lines
22 KiB
Rust
#![recursion_limit = "256"]
|
|
|
|
mod admin;
|
|
mod admin_accounts;
|
|
mod admin_recharge;
|
|
mod ai_generation_drafts;
|
|
mod ai_tasks;
|
|
mod aliyun_matting;
|
|
mod api_response;
|
|
mod app;
|
|
mod asset_billing;
|
|
mod assets;
|
|
mod auth;
|
|
mod auth_me;
|
|
mod auth_payload;
|
|
mod auth_public_user;
|
|
mod auth_session;
|
|
mod auth_sessions;
|
|
mod backpressure;
|
|
mod bark_battle;
|
|
mod big_fish;
|
|
mod big_fish_agent_turn;
|
|
mod big_fish_draft_compiler;
|
|
mod character_animation_assets;
|
|
mod character_visual_assets;
|
|
mod config;
|
|
mod creation_agent_anchor_templates;
|
|
mod creation_agent_chat;
|
|
mod creation_agent_document_input;
|
|
mod creation_agent_llm_turn;
|
|
mod creation_entry_config;
|
|
mod creative_agent;
|
|
mod creative_agent_sse;
|
|
mod custom_world;
|
|
mod custom_world_agent_entities;
|
|
mod custom_world_agent_turn;
|
|
mod custom_world_ai;
|
|
mod custom_world_asset_prompts;
|
|
mod custom_world_foundation_draft;
|
|
mod custom_world_result_prompts;
|
|
mod custom_world_rpg_draft_prompts;
|
|
mod editor_agent;
|
|
mod editor_generation_config;
|
|
mod editor_generation_queue;
|
|
mod editor_green_screen;
|
|
mod editor_project;
|
|
mod editor_screen_background_decision;
|
|
mod editor_screen_background_filter;
|
|
mod edutainment_baby_drawing;
|
|
mod edutainment_baby_object;
|
|
mod error_middleware;
|
|
mod external_api_audit;
|
|
mod external_api_auth;
|
|
mod external_api_keys;
|
|
mod external_assets_api;
|
|
mod external_editor_api;
|
|
mod external_generation;
|
|
mod external_generation_worker;
|
|
mod external_generation_worker_controller;
|
|
mod frontend_runtime_config;
|
|
pub(crate) mod generated_asset_sheets;
|
|
mod generated_image_assets;
|
|
mod health;
|
|
mod http_error;
|
|
mod hyper3d_generation;
|
|
mod jump_hop;
|
|
mod jump_hop_atlas_slicing;
|
|
mod llm;
|
|
mod llm_model_routing;
|
|
mod login_options;
|
|
mod logout;
|
|
mod logout_all;
|
|
mod match3d;
|
|
mod modules;
|
|
mod openai_image_generation;
|
|
mod password_entry;
|
|
mod password_management;
|
|
mod phone_auth;
|
|
mod platform_errors;
|
|
mod process_metrics;
|
|
mod profile_identity;
|
|
mod profile_recharge_expiration_listener;
|
|
mod profile_recharge_refund_reconciliation;
|
|
mod prompt;
|
|
mod public_work;
|
|
mod puzzle;
|
|
mod puzzle_agent_turn;
|
|
mod puzzle_clear;
|
|
mod puzzle_gallery_cache;
|
|
mod refresh_session;
|
|
mod registration_reward;
|
|
mod request_context;
|
|
mod response_headers;
|
|
mod runtime_browse_history;
|
|
mod runtime_chat;
|
|
mod runtime_chat_plain;
|
|
mod runtime_inventory;
|
|
mod runtime_profile;
|
|
mod runtime_save;
|
|
mod runtime_settings;
|
|
mod session_client;
|
|
mod square_hole;
|
|
mod square_hole_agent_turn;
|
|
mod state;
|
|
mod story_battles;
|
|
mod story_sessions;
|
|
mod telemetry;
|
|
mod tracking;
|
|
mod tracking_outbox;
|
|
mod vector_engine_audio_generation;
|
|
mod visual_novel;
|
|
mod volcengine_speech;
|
|
mod wallet_refund_outbox;
|
|
mod wechat;
|
|
mod wooden_fish;
|
|
mod work_author;
|
|
mod work_play_tracking;
|
|
|
|
use shared_logging::{OtelConfig, init_tracing};
|
|
use socket2::{Domain, Protocol, Socket, Type};
|
|
use std::{
|
|
collections::HashSet,
|
|
env, fs, future, io,
|
|
net::{SocketAddr, TcpListener as StdTcpListener},
|
|
panic,
|
|
sync::Arc,
|
|
thread,
|
|
time::Duration,
|
|
};
|
|
use tokio::net::TcpListener;
|
|
use tokio::runtime::Builder as TokioRuntimeBuilder;
|
|
use tokio::time::timeout;
|
|
use tracing::{error, info, warn};
|
|
|
|
use crate::{
|
|
app::{build_router, build_spacetime_unavailable_router},
|
|
config::{AppConfig, ProcessRole},
|
|
external_generation_worker::run_external_generation_worker,
|
|
external_generation_worker_controller::run_external_generation_worker_controller,
|
|
profile_recharge_expiration_listener::spawn_profile_recharge_expiration_listener,
|
|
profile_recharge_refund_reconciliation::spawn_profile_recharge_refund_reconciliation_worker,
|
|
state::{AppState, AppStateInitError},
|
|
tracking_outbox::TrackingOutbox,
|
|
wallet_refund_outbox::WalletRefundOutbox,
|
|
};
|
|
|
|
const API_SERVER_STARTUP_STACK_SIZE_BYTES: usize = 32 * 1024 * 1024;
|
|
const AUTH_STORE_STARTUP_RESTORE_TIMEOUT: Duration = Duration::from_secs(8);
|
|
const AUTH_STORE_STARTUP_RETRY_INTERVAL: Duration = Duration::from_secs(5);
|
|
|
|
#[derive(Clone)]
|
|
struct ShutdownContext {
|
|
app_state: Option<AppState>,
|
|
tracking_outbox: Option<Arc<TrackingOutbox>>,
|
|
wallet_refund_outbox: Option<Arc<WalletRefundOutbox>>,
|
|
outbox_flush_timeout: Duration,
|
|
}
|
|
|
|
fn main() -> Result<(), io::Error> {
|
|
// Windows 本地调试下 Axum 路由树和启动恢复链较重,显式放大启动线程栈,避免 debug 构建在进入监听前栈溢出。
|
|
let server_thread = thread::Builder::new()
|
|
.name("api-server-bootstrap".to_string())
|
|
.stack_size(API_SERVER_STARTUP_STACK_SIZE_BYTES)
|
|
.spawn(|| {
|
|
load_local_env_files();
|
|
let config = AppConfig::from_env();
|
|
let mut runtime_builder = TokioRuntimeBuilder::new_multi_thread();
|
|
runtime_builder
|
|
.enable_all()
|
|
.thread_name("api-server-worker")
|
|
.thread_stack_size(API_SERVER_STARTUP_STACK_SIZE_BYTES);
|
|
if let Some(worker_threads) = config.worker_threads {
|
|
runtime_builder.worker_threads(worker_threads);
|
|
}
|
|
|
|
runtime_builder.build()?.block_on(run_server(config))
|
|
})?;
|
|
|
|
match server_thread.join() {
|
|
Ok(result) => result,
|
|
Err(payload) => panic::resume_unwind(payload),
|
|
}
|
|
}
|
|
|
|
async fn run_server(config: AppConfig) -> Result<(), io::Error> {
|
|
init_tracing(
|
|
&config.log_filter,
|
|
OtelConfig {
|
|
enabled: config.otel_enabled,
|
|
},
|
|
)?;
|
|
process_metrics::register_process_metrics();
|
|
telemetry::register_http_runtime_metrics();
|
|
|
|
if !config.process_role.runs_http() {
|
|
return run_worker_only(config).await;
|
|
}
|
|
|
|
run_http_role(config).await
|
|
}
|
|
|
|
async fn run_worker_only(config: AppConfig) -> Result<(), io::Error> {
|
|
let process_role = config.process_role;
|
|
let state = build_non_http_app_state_for_startup(config).map_err(|error| {
|
|
io::Error::other(format!(
|
|
"初始化 external generation worker 状态失败:{error}"
|
|
))
|
|
})?;
|
|
state
|
|
.spacetime_client()
|
|
.get_external_generation_queue_stats()
|
|
.await
|
|
.map_err(|error| {
|
|
io::Error::other(format!("验证外部生成队列运行时服务身份失败:{error}"))
|
|
})?;
|
|
spawn_common_app_state_background_workers(&state);
|
|
info!(
|
|
process_role = process_role.as_str(),
|
|
"api-server 以非 HTTP 角色启动"
|
|
);
|
|
if process_role.runs_external_generation_worker() {
|
|
run_external_generation_worker(state).await
|
|
} else if process_role.runs_external_generation_controller() {
|
|
run_external_generation_worker_controller(state).await
|
|
} else {
|
|
Err(io::Error::other(format!(
|
|
"不支持的非 HTTP 进程角色:{}",
|
|
process_role.as_str()
|
|
)))
|
|
}
|
|
}
|
|
|
|
fn build_non_http_app_state_for_startup(
|
|
config: AppConfig,
|
|
) -> Result<AppState, state::AppStateInitError> {
|
|
let process_role = config.process_role;
|
|
debug_assert!(!should_restore_auth_store_for_startup(process_role));
|
|
info!(
|
|
process_role = process_role.as_str(),
|
|
"非 HTTP 进程跳过 SpacetimeDB 认证投影恢复"
|
|
);
|
|
AppState::new_with_empty_auth_store(config)
|
|
}
|
|
|
|
fn should_restore_auth_store_for_startup(process_role: ProcessRole) -> bool {
|
|
process_role.runs_http()
|
|
}
|
|
|
|
fn should_initialize_editor_generation_pricing_for_startup(process_role: ProcessRole) -> bool {
|
|
process_role.runs_http()
|
|
}
|
|
|
|
async fn run_http_role(config: AppConfig) -> Result<(), io::Error> {
|
|
let bind_address = config.bind_socket_addr();
|
|
let listen_backlog = config.listen_backlog;
|
|
let worker_threads = config.worker_threads;
|
|
let otel_enabled = config.otel_enabled;
|
|
let process_role = config.process_role;
|
|
let outbox_flush_timeout = config.shutdown_outbox_flush_timeout;
|
|
let listener = build_tcp_listener(bind_address, listen_backlog)?;
|
|
|
|
let (router, shutdown_context, worker_state) = match restore_app_state_for_startup(config).await
|
|
{
|
|
Ok(state) => {
|
|
spawn_http_app_state_background_workers(&state, process_role);
|
|
let tracking_outbox = state.tracking_outbox();
|
|
let wallet_refund_outbox = state.wallet_refund_outbox();
|
|
let worker_state = process_role
|
|
.runs_external_generation_worker()
|
|
.then(|| state.clone());
|
|
(
|
|
build_router(state.clone()),
|
|
ShutdownContext {
|
|
app_state: Some(state),
|
|
tracking_outbox,
|
|
wallet_refund_outbox,
|
|
outbox_flush_timeout,
|
|
},
|
|
worker_state,
|
|
)
|
|
}
|
|
Err(AppStateInitError::DependencyUnavailable(message)) => (
|
|
build_spacetime_unavailable_router(message),
|
|
ShutdownContext {
|
|
app_state: None,
|
|
tracking_outbox: None,
|
|
wallet_refund_outbox: None,
|
|
outbox_flush_timeout,
|
|
},
|
|
None,
|
|
),
|
|
Err(error) => {
|
|
return Err(std::io::Error::other(format!(
|
|
"初始化应用状态失败:{error}"
|
|
)));
|
|
}
|
|
};
|
|
|
|
info!(
|
|
%bind_address,
|
|
listen_backlog,
|
|
worker_threads = worker_threads.unwrap_or(0),
|
|
otel_enabled,
|
|
process_role = process_role.as_str(),
|
|
"api-server 已完成 tracing 初始化并开始监听"
|
|
);
|
|
|
|
let http_server = axum::serve(listener, router)
|
|
.with_graceful_shutdown(shutdown_signal(shutdown_context.clone()));
|
|
let result = if let Some(worker_state) = worker_state {
|
|
tokio::select! {
|
|
result = http_server => result,
|
|
result = run_external_generation_worker(worker_state) => result,
|
|
}
|
|
} else {
|
|
http_server.await
|
|
};
|
|
finalize_shutdown(shutdown_context).await;
|
|
result
|
|
}
|
|
|
|
async fn shutdown_signal(context: ShutdownContext) {
|
|
let signal = wait_for_shutdown_signal().await;
|
|
if let Some(state) = context.app_state.as_ref() {
|
|
state.mark_not_ready();
|
|
}
|
|
info!(
|
|
signal,
|
|
"api-server 收到退出信号,已标记 readiness 不可用并开始排空 HTTP 请求"
|
|
);
|
|
}
|
|
|
|
async fn wait_for_shutdown_signal() -> &'static str {
|
|
#[cfg(unix)]
|
|
{
|
|
tokio::select! {
|
|
signal = wait_for_ctrl_c_signal() => signal,
|
|
signal = wait_for_sigterm_signal() => signal,
|
|
}
|
|
}
|
|
|
|
#[cfg(not(unix))]
|
|
{
|
|
wait_for_ctrl_c_signal().await
|
|
}
|
|
}
|
|
|
|
async fn wait_for_ctrl_c_signal() -> &'static str {
|
|
if let Err(error) = tokio::signal::ctrl_c().await {
|
|
error!(error = %error, "监听 SIGINT 失败,无法通过 Ctrl-C 触发优雅退出");
|
|
future::pending::<()>().await;
|
|
}
|
|
"sigint"
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
async fn wait_for_sigterm_signal() -> &'static str {
|
|
let mut signal = match tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
|
|
{
|
|
Ok(signal) => signal,
|
|
Err(error) => {
|
|
error!(error = %error, "监听 SIGTERM 失败,无法通过 systemd terminate 触发优雅退出");
|
|
future::pending::<()>().await;
|
|
unreachable!("pending future never returns");
|
|
}
|
|
};
|
|
signal.recv().await;
|
|
"sigterm"
|
|
}
|
|
|
|
async fn finalize_shutdown(context: ShutdownContext) {
|
|
if let Some(state) = context.app_state.as_ref() {
|
|
state.mark_not_ready();
|
|
}
|
|
|
|
if context.outbox_flush_timeout.is_zero() {
|
|
warn!("api-server 退出时 outbox flush timeout 为 0,跳过主动 flush");
|
|
return;
|
|
}
|
|
|
|
let timeout_ms = context
|
|
.outbox_flush_timeout
|
|
.as_millis()
|
|
.min(u128::from(u64::MAX)) as u64;
|
|
if let Some(outbox) = context.tracking_outbox {
|
|
info!(timeout_ms, "api-server 退出前封存并 flush tracking outbox");
|
|
match timeout(context.outbox_flush_timeout, outbox.flush_for_shutdown()).await {
|
|
Ok(Ok(())) => {
|
|
info!("api-server 退出前 tracking outbox flush 完成");
|
|
}
|
|
Ok(Err(error)) => {
|
|
warn!(
|
|
error = %error,
|
|
"api-server 退出前 tracking outbox flush 未完成,已保留本地文件等待下次启动重试"
|
|
);
|
|
}
|
|
Err(_) => {
|
|
warn!(
|
|
timeout_ms,
|
|
"api-server 退出前 tracking outbox flush 超时,已保留本地文件等待下次启动重试"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
if let Some(outbox) = context.wallet_refund_outbox {
|
|
info!(timeout_ms, "api-server 退出前 flush wallet refund outbox");
|
|
match timeout(context.outbox_flush_timeout, outbox.flush_for_shutdown()).await {
|
|
Ok(Ok(())) => {
|
|
info!("api-server 退出前 wallet refund outbox flush 完成");
|
|
}
|
|
Ok(Err(error)) => {
|
|
warn!(
|
|
error = %error,
|
|
"api-server 退出前 wallet refund outbox flush 未完成,已保留本地文件等待下次启动重试"
|
|
);
|
|
}
|
|
Err(_) => {
|
|
warn!(
|
|
timeout_ms,
|
|
"api-server 退出前 wallet refund outbox flush 超时,已保留本地文件等待下次启动重试"
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn spawn_common_app_state_background_workers(state: &AppState) {
|
|
state.puzzle_gallery_cache().spawn_cleanup_task();
|
|
if let Some(outbox) = state.tracking_outbox() {
|
|
outbox.spawn_worker();
|
|
}
|
|
if let Some(outbox) = state.wallet_refund_outbox() {
|
|
outbox.spawn_worker();
|
|
}
|
|
}
|
|
|
|
fn spawn_http_app_state_background_workers(state: &AppState, process_role: ProcessRole) {
|
|
spawn_common_app_state_background_workers(state);
|
|
if should_start_profile_recharge_expiration_listener(process_role) {
|
|
spawn_profile_recharge_expiration_listener(state.clone());
|
|
spawn_profile_recharge_refund_reconciliation_worker(state.clone());
|
|
}
|
|
}
|
|
|
|
fn should_start_profile_recharge_expiration_listener(process_role: ProcessRole) -> bool {
|
|
process_role.runs_http()
|
|
}
|
|
|
|
fn build_tcp_listener(
|
|
bind_address: SocketAddr,
|
|
listen_backlog: i32,
|
|
) -> Result<TcpListener, io::Error> {
|
|
let domain = Domain::for_address(bind_address);
|
|
let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;
|
|
socket.set_reuse_address(true)?;
|
|
socket.set_nonblocking(true)?;
|
|
socket.bind(&bind_address.into())?;
|
|
socket.listen(listen_backlog)?;
|
|
TcpListener::from_std(StdTcpListener::from(socket))
|
|
}
|
|
|
|
async fn restore_app_state_for_startup(
|
|
config: AppConfig,
|
|
) -> Result<AppState, state::AppStateInitError> {
|
|
loop {
|
|
match try_restore_app_state_for_startup(config.clone()).await {
|
|
Ok(state) => return Ok(state),
|
|
Err(state::AppStateInitError::DependencyUnavailable(message)) => {
|
|
warn!(
|
|
retry_after_seconds = AUTH_STORE_STARTUP_RETRY_INTERVAL.as_secs(),
|
|
error = %message,
|
|
"启动恢复 SpacetimeDB 认证投影暂不可用,api-server 将继续重试"
|
|
);
|
|
tokio::time::sleep(AUTH_STORE_STARTUP_RETRY_INTERVAL).await;
|
|
}
|
|
Err(error) => return Err(error),
|
|
}
|
|
}
|
|
}
|
|
|
|
async fn try_restore_app_state_for_startup(
|
|
config: AppConfig,
|
|
) -> Result<AppState, state::AppStateInitError> {
|
|
let process_role = config.process_role;
|
|
let state = match timeout(
|
|
AUTH_STORE_STARTUP_RESTORE_TIMEOUT,
|
|
AppState::try_restore_auth_store_from_spacetime(config),
|
|
)
|
|
.await
|
|
{
|
|
Ok(result) => result?,
|
|
Err(_) => {
|
|
error!(
|
|
timeout_seconds = AUTH_STORE_STARTUP_RESTORE_TIMEOUT.as_secs(),
|
|
"启动等待 SpacetimeDB 恢复认证投影超时"
|
|
);
|
|
return Err(state::AppStateInitError::DependencyUnavailable(
|
|
"SpacetimeDB 启动恢复认证投影超时".to_string(),
|
|
));
|
|
}
|
|
};
|
|
if should_initialize_editor_generation_pricing_for_startup(process_role) {
|
|
state
|
|
.ensure_editor_generation_runtime_service_identity()
|
|
.await
|
|
.map_err(|error| {
|
|
state::AppStateInitError::DependencyUnavailable(format!(
|
|
"初始化模型定价服务身份失败:{error}"
|
|
))
|
|
})?;
|
|
}
|
|
Ok(state)
|
|
}
|
|
|
|
fn load_local_env_files() {
|
|
let shell_env_keys = protected_env_keys_from(env::vars());
|
|
|
|
for path in [".env", ".env.local", ".env.secrets.local"] {
|
|
load_env_file(path, &shell_env_keys);
|
|
}
|
|
}
|
|
|
|
fn protected_env_keys_from(vars: impl IntoIterator<Item = (String, String)>) -> HashSet<String> {
|
|
vars.into_iter()
|
|
.filter_map(|(key, value)| {
|
|
if value.trim().is_empty() {
|
|
None
|
|
} else {
|
|
Some(key)
|
|
}
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn load_env_file(path: &str, shell_env_keys: &HashSet<String>) {
|
|
let Ok(raw_text) = fs::read_to_string(path) else {
|
|
return;
|
|
};
|
|
|
|
let raw_text = raw_text.trim_start_matches('\u{feff}');
|
|
|
|
for raw_line in raw_text.split('\n') {
|
|
let line = raw_line.trim();
|
|
if line.is_empty() || line.starts_with('#') {
|
|
continue;
|
|
}
|
|
|
|
let Some((raw_key, raw_value)) = line.split_once('=') else {
|
|
continue;
|
|
};
|
|
let key = raw_key.trim().trim_start_matches('\u{feff}');
|
|
if !is_valid_env_key(key) || shell_env_keys.contains(key) {
|
|
continue;
|
|
}
|
|
|
|
// 这里只在启动前、Tokio runtime 创建前写入进程环境,避免并发读写 env。
|
|
unsafe {
|
|
env::set_var(key, strip_env_value(raw_value));
|
|
}
|
|
}
|
|
}
|
|
|
|
fn strip_env_value(raw_value: &str) -> String {
|
|
let value = raw_value.trim_end_matches('\r');
|
|
if value.len() >= 2 {
|
|
let bytes = value.as_bytes();
|
|
let first = bytes[0];
|
|
let last = bytes[value.len() - 1];
|
|
if (first == b'"' && last == b'"') || (first == b'\'' && last == b'\'') {
|
|
return value[1..value.len() - 1].to_string();
|
|
}
|
|
}
|
|
|
|
value.to_string()
|
|
}
|
|
|
|
fn is_valid_env_key(key: &str) -> bool {
|
|
let mut chars = key.chars();
|
|
match chars.next() {
|
|
Some(first) if first == '_' || first.is_ascii_alphabetic() => {}
|
|
_ => return false,
|
|
}
|
|
|
|
chars.all(|ch| ch == '_' || ch.is_ascii_alphanumeric())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::{
|
|
AUTH_STORE_STARTUP_RETRY_INTERVAL, is_valid_env_key, protected_env_keys_from,
|
|
should_initialize_editor_generation_pricing_for_startup,
|
|
should_restore_auth_store_for_startup, should_start_profile_recharge_expiration_listener,
|
|
strip_env_value,
|
|
};
|
|
use crate::config::ProcessRole;
|
|
|
|
#[test]
|
|
fn strip_env_value_removes_wrapping_quotes() {
|
|
assert_eq!(strip_env_value("\"true\""), "true");
|
|
assert_eq!(strip_env_value("'aliyun'"), "aliyun");
|
|
assert_eq!(strip_env_value("plain\r"), "plain");
|
|
}
|
|
|
|
#[test]
|
|
fn load_env_key_can_strip_utf8_bom_prefix() {
|
|
let key = "\u{feff}SMS_AUTH_ENABLED"
|
|
.trim()
|
|
.trim_start_matches('\u{feff}');
|
|
|
|
assert_eq!(key, "SMS_AUTH_ENABLED");
|
|
}
|
|
|
|
#[test]
|
|
fn is_valid_env_key_accepts_dotenv_key_subset() {
|
|
assert!(is_valid_env_key("SMS_AUTH_ENABLED"));
|
|
assert!(is_valid_env_key("_LOCAL_KEY_1"));
|
|
assert!(!is_valid_env_key("1_BAD"));
|
|
assert!(!is_valid_env_key("BAD-KEY"));
|
|
}
|
|
|
|
#[test]
|
|
fn empty_shell_env_does_not_protect_dotenv_value() {
|
|
let protected = protected_env_keys_from([
|
|
("ALIYUN_OSS_BUCKET".to_string(), "".to_string()),
|
|
("ALIYUN_OSS_ENDPOINT".to_string(), " ".to_string()),
|
|
(
|
|
"ALIYUN_OSS_ACCESS_KEY_ID".to_string(),
|
|
"configured".to_string(),
|
|
),
|
|
]);
|
|
|
|
assert!(!protected.contains("ALIYUN_OSS_BUCKET"));
|
|
assert!(!protected.contains("ALIYUN_OSS_ENDPOINT"));
|
|
assert!(protected.contains("ALIYUN_OSS_ACCESS_KEY_ID"));
|
|
}
|
|
|
|
#[test]
|
|
fn startup_dependency_retry_interval_is_short_enough_for_service_recovery() {
|
|
assert_eq!(AUTH_STORE_STARTUP_RETRY_INTERVAL.as_secs(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn auth_store_startup_restore_is_limited_to_http_roles() {
|
|
assert!(should_restore_auth_store_for_startup(ProcessRole::Api));
|
|
assert!(should_restore_auth_store_for_startup(ProcessRole::All));
|
|
assert!(!should_restore_auth_store_for_startup(
|
|
ProcessRole::ExternalGenerationWorker
|
|
));
|
|
assert!(!should_restore_auth_store_for_startup(
|
|
ProcessRole::ExternalGenerationController
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn editor_generation_pricing_initialization_is_limited_to_http_roles() {
|
|
assert!(should_initialize_editor_generation_pricing_for_startup(
|
|
ProcessRole::Api
|
|
));
|
|
assert!(should_initialize_editor_generation_pricing_for_startup(
|
|
ProcessRole::All
|
|
));
|
|
assert!(!should_initialize_editor_generation_pricing_for_startup(
|
|
ProcessRole::ExternalGenerationWorker
|
|
));
|
|
assert!(!should_initialize_editor_generation_pricing_for_startup(
|
|
ProcessRole::ExternalGenerationController
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn profile_recharge_expiration_listener_is_limited_to_http_roles() {
|
|
assert!(should_start_profile_recharge_expiration_listener(
|
|
ProcessRole::Api
|
|
));
|
|
assert!(should_start_profile_recharge_expiration_listener(
|
|
ProcessRole::All
|
|
));
|
|
assert!(!should_start_profile_recharge_expiration_listener(
|
|
ProcessRole::ExternalGenerationWorker
|
|
));
|
|
assert!(!should_start_profile_recharge_expiration_listener(
|
|
ProcessRole::ExternalGenerationController
|
|
));
|
|
}
|
|
}
|