Files
Aether/apps/aether-gateway/tests/architecture/admin_system.rs
T
AAEE86 3394a51278 ci(gateway): slim Test (Gateway) batch 1 — split architecture guards, pin build fingerprint
第一批减负(对应 docs/operations/gateway-ci-timeout-reduction-plan.md):

A1 架构守卫迁出
- 将 src/tests/architecture/**(208 项 / 约 1.5 万行字符串断言)迁至
  tests/architecture/,入口 tests/architecture_guard.rs
- 从 lib cfg(test) 巨型编译单元移除,压低 rustc 峰值与 OOM 风险
- 断言逻辑不变;helper 可见性改为 pub(crate)

A2 构建指纹统一
- test_gateway 的 mold RUSTFLAGS / RUST_MIN_STACK / sccache 上移至 job 级 env
- rust-ci.yml 全部 toolchain 钉住 1.95.0(与 rust-toolchain.toml、fmt/clippy 一致)
- Gateway 独立 cache key,避免 mold 指纹与无 mold job 互相污染

A4 补安全集成测试
- 新增 Test integration targets:cargo nextest run -p aether-gateway --tests
- 覆盖 architecture_guard + 此前未执行的 admin_unsigned_identity_headers

验证:architecture_guard + admin_unsigned 209 passed;
cargo check -p aether-gateway --lib --tests 通过;cargo fmt --check 通过。

不创建 PR,仅本地分支提交。
2026-09-23 17:51:45 +08:00

616 lines
24 KiB
Rust

use super::*;
#[test]
fn admin_system_build_version_contract_uses_explicit_local_build_arg() {
let build_rs = read_workspace_file("apps/aether-gateway/build.rs");
for pattern in [
"cargo:rerun-if-env-changed=AETHER_BUILD_VERSION",
"env::var(\"AETHER_BUILD_VERSION\")",
] {
assert!(
build_rs.contains(pattern),
"apps/aether-gateway/build.rs should consume explicit build version pattern {pattern}"
);
}
let dockerfile = read_workspace_file("Dockerfile.app.local");
for pattern in [
"ARG AETHER_BUILD_VERSION",
"ENV AETHER_BUILD_VERSION=${AETHER_BUILD_VERSION}",
"AETHER_VERSION=${AETHER_BUILD_VERSION}",
] {
assert!(
dockerfile.contains(pattern),
"Dockerfile.app.local should pass explicit build version pattern {pattern}"
);
}
let deploy = read_workspace_file("deploy.sh");
for pattern in [
"detect_build_version()",
"git describe --tags --match 'v[0-9]*' --always --dirty",
"AETHER_BUILD_VERSION=\"${AETHER_BUILD_VERSION:-$(detect_build_version)}\"",
"--build-arg \"AETHER_BUILD_VERSION=$AETHER_BUILD_VERSION\"",
">>> AETHER_BUILD_VERSION",
] {
assert!(
deploy.contains(pattern),
"deploy.sh should pass deterministic local build version pattern {pattern}"
);
}
let vite_config = read_workspace_file("frontend/vite.config.ts");
for pattern in [
"process.env.AETHER_BUILD_VERSION",
"process.env.AETHER_VERSION",
"git describe --tags --match \"v[0-9]*\" --always --dirty",
"trimmed.startsWith('tunnel-v')",
] {
assert!(
vite_config.contains(pattern),
"frontend/vite.config.ts should consume local build version pattern {pattern}"
);
}
let core_api = read_workspace_file("apps/aether-gateway/src/api/core.rs");
for pattern in [
"option_env!(\"AETHER_BUILD_VERSION\")",
"\"version\": current_gateway_version()",
] {
assert!(
core_api.contains(pattern),
"api/core.rs should expose build version pattern {pattern}"
);
}
let build_rs = read_workspace_file("apps/aether-gateway/build.rs");
for pattern in [
"\"--match\"",
"\"v[0-9]*\"",
"trimmed.starts_with(\"tunnel-v\")",
] {
assert!(
build_rs.contains(pattern),
"apps/aether-gateway/build.rs should ignore tunnel release tags for gateway version pattern {pattern}"
);
}
}
#[test]
fn admin_system_and_endpoint_roots_stay_thin() {
let system_mod = read_workspace_file("apps/aether-gateway/src/handlers/admin/system/mod.rs");
for pattern in [
"pub(super) use super::auth::{",
"pub(super) use super::model::{",
"pub(super) use super::provider::{",
] {
assert!(
!system_mod.contains(pattern),
"handlers/admin/system/mod.rs should not act as a cross-domain re-export layer for {pattern}"
);
}
for pattern in [
"mod routes;",
"pub(super) use self::routes::maybe_build_local_admin_system_response;",
] {
assert!(
system_mod.contains(pattern),
"handlers/admin/system/mod.rs should stay as a thin system subdomain router for {pattern}"
);
}
for forbidden in [
"pub(crate) use self::adaptive::maybe_build_local_admin_adaptive_response;",
"pub(crate) use self::core::maybe_build_local_admin_core_response;",
"pub(crate) use self::management_tokens::maybe_build_local_admin_management_tokens_response;",
"pub(crate) use self::modules::maybe_build_local_admin_modules_response;",
"pub(crate) use self::proxy_nodes::maybe_build_local_admin_proxy_nodes_response;",
"pub(crate) use crate::handlers::admin::provider::pool_admin::maybe_build_local_admin_pool_response;",
] {
assert!(
!system_mod.contains(forbidden),
"handlers/admin/system/mod.rs should not remain a public owner export hub for {forbidden}"
);
}
assert!(
!workspace_file_exists("apps/aether-gateway/src/handlers/admin/system/pool/mod.rs"),
"handlers/admin/system/pool/mod.rs should be deleted once system root delegates pool admin directly to provider::pool_admin"
);
let endpoint_mod =
read_workspace_file("apps/aether-gateway/src/handlers/admin/endpoint/mod.rs");
for pattern in [
"mod routes;",
"pub(super) use self::routes::maybe_build_local_admin_endpoints_response;",
] {
assert!(
endpoint_mod.contains(pattern),
"handlers/admin/endpoint/mod.rs should stay as a thin endpoint router for {pattern}"
);
}
for pattern in [
"use self::extractors::{",
"use self::health_builders::{",
"use self::payloads::{",
] {
assert!(
!endpoint_mod.contains(pattern),
"handlers/admin/endpoint/mod.rs should not re-export local helper seam {pattern}"
);
}
assert!(
endpoint_mod.contains(
"pub(crate) use self::health_builders::build_admin_endpoint_health_status_payload;"
),
"handlers/admin/endpoint/mod.rs should keep only the crate-facing health status payload seam"
);
let system_core_mod =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/core/mod.rs");
for pattern in [
"super::management_tokens::maybe_build_local_admin_management_tokens_response",
"maybe_build_local_admin_oauth_response",
"super::modules::maybe_build_local_admin_modules_response",
"maybe_build_local_admin_model_catalog_response",
] {
assert!(
system_core_mod.contains(pattern),
"handlers/admin/system/core/mod.rs should call the real owner {pattern}"
);
}
let system_routes =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/routes.rs");
for pattern in [
"core::maybe_build_local_admin_core_response(",
"adaptive::maybe_build_local_admin_adaptive_response(",
"pool_admin::maybe_build_local_admin_pool_response(",
"proxy_nodes::maybe_build_local_admin_proxy_nodes_response(",
] {
assert!(
system_routes.contains(pattern),
"handlers/admin/system/routes.rs should dispatch through specific system owner {pattern}"
);
}
for path in [
"apps/aether-gateway/src/handlers/admin/system/core/management_tokens_routes.rs",
"apps/aether-gateway/src/handlers/admin/system/core/model_routes.rs",
"apps/aether-gateway/src/handlers/admin/system/core/modules_routes.rs",
"apps/aether-gateway/src/handlers/admin/system/core/oauth_routes.rs",
] {
assert!(
!workspace_file_exists(path),
"{path} should be deleted once system/core/mod.rs dispatches directly to real owners"
);
}
let system_routes =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/core/system_routes.rs");
assert!(
!system_routes.contains("use crate::handlers::public::{"),
"handlers/admin/system/core/system_routes.rs should not borrow system-owned route helpers from handlers/public"
);
assert!(
!system_routes.contains("crate::handlers::admin::auth::build_proxy_error_response")
&& !system_routes.contains("use crate::handlers::admin::auth::build_proxy_error_response;"),
"handlers/admin/system/core/system_routes.rs should not borrow proxy error builder from auth"
);
for pattern in [
"build_admin_email_template_payload",
"build_admin_email_templates_payload",
"preview_admin_email_template",
"reset_admin_email_template",
] {
assert!(
system_routes.contains(pattern),
"handlers/admin/system/core/system_routes.rs should keep delegating through admin system shared helper {pattern}"
);
}
let endpoint_routes =
read_workspace_file("apps/aether-gateway/src/handlers/admin/endpoint/routes.rs");
assert!(
endpoint_routes.contains(
"endpoint_keys::maybe_build_local_admin_endpoints_keys_response"
),
"handlers/admin/endpoint/routes.rs should dispatch provider key management directly to provider::endpoint_keys"
);
assert!(
endpoint_routes.contains(
"endpoints_admin::maybe_build_local_admin_endpoints_routes_response"
),
"handlers/admin/endpoint/routes.rs should dispatch provider endpoint CRUD directly to provider::endpoints_admin"
);
{
let path = "apps/aether-gateway/src/handlers/admin/endpoint/keys.rs";
assert!(
!workspace_file_exists(path),
"{path} should be deleted once endpoint root dispatches directly to provider-owned handlers"
);
}
}
#[test]
fn admin_model_root_owns_model_catalog_routes() {
let model_mod = read_workspace_file("apps/aether-gateway/src/handlers/admin/model/mod.rs");
assert!(
model_mod.contains("mod catalog_routes;"),
"handlers/admin/model/mod.rs should register catalog_routes owner"
);
assert!(
model_mod.contains(
"pub(super) use self::catalog_routes::maybe_build_local_admin_model_catalog_response;"
),
"handlers/admin/model/mod.rs should expose model catalog route seam"
);
let model_catalog_routes =
read_workspace_file("apps/aether-gateway/src/handlers/admin/model/catalog_routes.rs");
for pattern in [
"build_admin_model_catalog_payload",
"read_admin_external_models_cache",
"clear_admin_external_models_cache",
"ADMIN_MODEL_CATALOG_DATA_UNAVAILABLE_DETAIL",
] {
assert!(
model_catalog_routes.contains(pattern),
"handlers/admin/model/catalog_routes.rs should own {pattern}"
);
}
}
#[test]
fn admin_system_owns_admin_module_helpers() {
let public_modules_helpers =
read_workspace_file("apps/aether-gateway/src/handlers/public/system_modules_helpers.rs");
for pattern in [
"admin_module_by_name",
"admin_module_name_from_enabled_path",
"admin_module_name_from_status_path",
"build_admin_module_runtime_state",
"build_admin_module_status_payload",
"build_admin_module_validation_result",
"build_admin_modules_status_payload",
"AdminSetModuleEnabledRequest",
] {
assert!(
!public_modules_helpers.contains(pattern),
"handlers/public/system_modules_helpers.rs should not re-export admin module helper {pattern}"
);
}
let public_modules = read_workspace_file(
"apps/aether-gateway/src/handlers/public/system_modules_helpers/modules.rs",
);
for pattern in [
"pub(crate) struct AdminModuleDefinition",
"pub(crate) struct AdminSetModuleEnabledRequest",
"pub(crate) struct AdminModuleRuntimeState",
"pub(crate) fn admin_module_by_name",
"pub(crate) async fn build_admin_module_runtime_state",
"pub(crate) fn build_admin_module_validation_result",
"pub(crate) async fn build_admin_module_status_payload",
"pub(crate) async fn build_admin_modules_status_payload",
"pub(crate) fn admin_module_name_from_status_path",
"pub(crate) fn admin_module_name_from_enabled_path",
] {
assert!(
!public_modules.contains(pattern),
"handlers/public/system_modules_helpers/modules.rs should not own admin module helper {pattern}"
);
}
let system_shared_modules =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/modules.rs");
for pattern in [
"pub(crate) struct AdminModuleDefinition",
"pub(crate) struct AdminSetModuleEnabledRequest",
"pub(crate) struct AdminModuleRuntimeState",
"pub(crate) fn admin_module_by_name",
"pub(crate) async fn build_admin_module_runtime_state",
"pub(crate) fn build_admin_module_validation_result",
"pub(crate) async fn build_admin_module_status_payload",
"pub(crate) async fn build_admin_modules_status_payload",
"pub(crate) fn admin_module_name_from_status_path",
"pub(crate) fn admin_module_name_from_enabled_path",
] {
assert!(
system_shared_modules.contains(pattern),
"handlers/admin/system/shared/modules.rs should own {pattern}"
);
}
}
#[test]
fn admin_system_owns_system_route_helpers() {
let public_system_helpers =
read_workspace_file("apps/aether-gateway/src/handlers/public/system_modules_helpers.rs");
for pattern in [
"current_aether_version",
"build_admin_system_check_update_payload",
"build_admin_system_stats_payload",
"build_admin_system_settings_payload",
"apply_admin_system_settings_update",
"build_admin_api_formats_payload",
"build_admin_system_config_export_payload",
"build_admin_system_users_export_payload",
"build_admin_system_data_export_payload",
"build_admin_system_configs_payload",
"build_admin_system_config_detail_payload",
"apply_admin_system_config_update",
"delete_admin_system_config",
"serialize_admin_system_users_export_wallet",
"module_available_from_env",
"system_config_bool",
"system_config_string",
"read_admin_email_template_payload",
"escape_admin_email_template_html",
"render_admin_email_template_html",
] {
assert!(
!public_system_helpers.contains(pattern),
"handlers/public/system_modules_helpers.rs should not re-export admin system helper {pattern}"
);
}
let public_mod = read_workspace_file("apps/aether-gateway/src/handlers/public/mod.rs");
for pattern in [
"current_aether_version",
"build_admin_system_check_update_payload",
"build_admin_system_stats_payload",
"build_admin_system_settings_payload",
"apply_admin_system_settings_update",
"build_admin_api_formats_payload",
"build_admin_system_config_export_payload",
"build_admin_system_users_export_payload",
"build_admin_system_data_export_payload",
"build_admin_system_configs_payload",
"build_admin_system_config_detail_payload",
"apply_admin_system_config_update",
"delete_admin_system_config",
"serialize_admin_system_users_export_wallet",
"module_available_from_env",
"system_config_bool",
"system_config_string",
"read_admin_email_template_payload",
"escape_admin_email_template_html",
"render_admin_email_template_html",
] {
assert!(
!public_mod.contains(pattern),
"handlers/public/mod.rs should not re-export admin system helper {pattern}"
);
}
let public_system_file = read_workspace_file(
"apps/aether-gateway/src/handlers/public/system_modules_helpers/system.rs",
);
for pattern in [
"pub(crate) fn current_aether_version",
"pub(crate) fn build_admin_system_check_update_payload",
"pub(crate) async fn build_admin_system_stats_payload",
"pub(crate) async fn build_admin_system_settings_payload",
"pub(crate) async fn build_admin_system_config_export_payload",
"pub(crate) async fn build_admin_system_users_export_payload",
"pub(crate) async fn build_admin_system_data_export_payload",
"pub(crate) fn build_admin_system_configs_payload",
"pub(crate) async fn build_admin_system_config_detail_payload",
"pub(crate) async fn apply_admin_system_config_update",
"pub(crate) async fn delete_admin_system_config",
"pub(crate) fn serialize_admin_system_users_export_wallet",
"pub(crate) fn module_available_from_env",
"pub(crate) fn system_config_bool",
"pub(crate) fn system_config_string",
"pub(crate) async fn read_admin_email_template_payload",
"pub(crate) fn escape_admin_email_template_html",
"pub(crate) fn render_admin_email_template_html",
] {
assert!(
!public_system_file.contains(pattern),
"handlers/public/system_modules_helpers/system.rs should not own shared/admin system helper {pattern}"
);
}
let shared_mod = read_workspace_file("apps/aether-gateway/src/handlers/shared/mod.rs");
for pattern in [
"mod email_templates;",
"mod system_config_values;",
"pub(crate) use self::email_templates::{",
"pub(crate) use self::system_config_values::{",
] {
assert!(
shared_mod.contains(pattern),
"handlers/shared/mod.rs should wire shared system helper owner {pattern}"
);
}
let shared_system_config_values =
read_workspace_file("apps/aether-gateway/src/handlers/shared/system_config_values.rs");
for pattern in [
"pub(crate) fn module_available_from_env",
"pub(crate) fn system_config_bool",
"pub(crate) fn system_config_string",
] {
assert!(
shared_system_config_values.contains(pattern),
"handlers/shared/system_config_values.rs should own {pattern}"
);
}
let shared_email_templates =
read_workspace_file("apps/aether-gateway/src/handlers/shared/email_templates.rs");
for pattern in [
"pub(crate) fn admin_email_template_definition",
"pub(crate) fn admin_email_template_subject_key",
"pub(crate) fn admin_email_template_html_key",
"pub(crate) async fn read_admin_email_template_payload",
"pub(crate) fn escape_admin_email_template_html",
"pub(crate) fn render_admin_email_template_html",
] {
assert!(
shared_email_templates.contains(pattern),
"handlers/shared/email_templates.rs should own {pattern}"
);
}
let system_shared_mod =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/mod.rs");
for pattern in [
"pub(crate) mod configs;",
"pub(crate) mod export;",
"pub(crate) mod modules;",
"pub(crate) mod paths;",
"pub(crate) mod settings;",
] {
assert!(
system_shared_mod.contains(pattern),
"handlers/admin/system/shared/mod.rs should wire system helper owner {pattern}"
);
}
for forbidden in [
"pub(crate) use self::configs::*;",
"pub(crate) use self::email_templates::{",
"pub(crate) use self::modules::*;",
"pub(crate) use self::paths::*;",
"pub(crate) use self::settings::*;",
] {
assert!(
!system_shared_mod.contains(forbidden),
"handlers/admin/system/shared/mod.rs should not remain a re-export hub for {forbidden}"
);
}
assert!(
!workspace_file_exists("apps/aether-gateway/src/handlers/admin/system/shared/system.rs"),
"handlers/admin/system/shared/system.rs should be replaced by email_templates.rs"
);
let system_shared_settings =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/settings.rs");
for pattern in [
"pub(crate) fn current_aether_version",
"pub(crate) fn build_admin_system_check_update_payload",
"pub(crate) async fn build_admin_system_stats_payload",
"pub(crate) async fn build_admin_system_settings_payload",
"pub(crate) async fn apply_admin_system_settings_update",
"pub(crate) fn build_admin_api_formats_payload",
] {
assert!(
system_shared_settings.contains(pattern),
"handlers/admin/system/shared/settings.rs should own {pattern}"
);
}
let system_shared_configs =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/configs.rs");
for pattern in [
"pub(crate) fn build_admin_system_configs_payload",
"pub(crate) async fn build_admin_system_config_detail_payload",
"pub(crate) async fn apply_admin_system_config_update",
"pub(crate) async fn delete_admin_system_config",
] {
assert!(
system_shared_configs.contains(pattern),
"handlers/admin/system/shared/configs.rs should own {pattern}"
);
}
let request_system =
read_workspace_module_tree("apps/aether-gateway/src/handlers/admin/request/system/mod.rs");
for pattern in [
"pub(crate) async fn build_admin_email_templates_payload",
"pub(crate) async fn build_admin_email_template_payload",
"pub(crate) async fn apply_admin_email_template_update",
"pub(crate) async fn preview_admin_email_template",
"pub(crate) async fn reset_admin_email_template",
"pub(crate) async fn build_admin_system_config_export_payload",
"pub(crate) async fn build_admin_system_users_export_payload",
"pub(crate) async fn build_admin_system_data_export_payload",
] {
assert!(
request_system.contains(pattern),
"handlers/admin/request/system/mod.rs should own {pattern}"
);
}
for path in [
"apps/aether-gateway/src/handlers/admin/system/shared/email_templates.rs",
"apps/aether-gateway/src/handlers/admin/system/shared/users_export.rs",
] {
assert!(
!workspace_file_exists(path),
"{path} should be deleted once request/system/mod.rs owns system email/export route wrappers"
);
}
}
#[test]
fn admin_system_shared_configs_split_export_owners() {
let system_shared_mod =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/mod.rs");
for pattern in ["pub(crate) mod configs;", "pub(crate) mod export;"] {
assert!(
system_shared_mod.contains(pattern),
"handlers/admin/system/shared/mod.rs should register explicit system shared owner {pattern}"
);
}
let system_shared_configs =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/configs.rs");
for forbidden in [
"build_admin_system_config_export_payload(",
"build_admin_system_users_export_payload(",
"serialize_admin_system_users_export_wallet(",
] {
assert!(
!system_shared_configs.contains(forbidden),
"handlers/admin/system/shared/configs.rs should stay focused on config CRUD, not export owner {forbidden}"
);
}
assert!(
!workspace_file_exists("apps/aether-gateway/src/handlers/admin/system/shared/export.rs"),
"handlers/admin/system/shared/export.rs should be replaced by export/ directory owners"
);
let system_shared_export =
read_workspace_file("apps/aether-gateway/src/handlers/admin/system/shared/export/mod.rs");
for pattern in [
"pub(crate) use self::providers::build_admin_system_export_providers_payload;",
"decrypt_admin_system_export_secret",
"ADMIN_SYSTEM_CONFIG_EXPORT_VERSION",
"ADMIN_SYSTEM_EXPORT_PAGE_LIMIT",
] {
assert!(
system_shared_export.contains(pattern),
"handlers/admin/system/shared/export/mod.rs should own {pattern}"
);
}
let request_system =
read_workspace_module_tree("apps/aether-gateway/src/handlers/admin/request/system/mod.rs");
for pattern in [
"pub(crate) async fn build_admin_system_config_export_payload(",
"pub(crate) async fn build_admin_system_users_export_payload(",
"pub(crate) async fn build_admin_system_data_export_payload(",
] {
assert!(
request_system.contains(pattern),
"handlers/admin/request/system/mod.rs should own {pattern}"
);
}
for path in [
"apps/aether-gateway/src/handlers/admin/system/shared/export/support.rs",
"apps/aether-gateway/src/handlers/admin/system/shared/export/providers.rs",
] {
assert!(
workspace_file_exists(path),
"{path} should exist once system export owner is split into specific modules"
);
}
assert!(
!workspace_file_exists("apps/aether-gateway/src/handlers/admin/system/shared/users_export.rs"),
"handlers/admin/system/shared/users_export.rs should be deleted once request/system/mod.rs owns users export wrapper"
);
}