**影响** - `platform::config::Config` 不再持有 `identity_code` / `identity_name` / `identity_secret` / `bootstrap_admin_account` / `bootstrap_admin_password`; 平台层**不认识**「本连接器是谁」。 - 新增业务层 `tdc::config::TdcConfig`(同五项)与 `tdc::constant`(默认值 + 业务 env 名清单)。 - 对外契约**零变化**(env 名、默认值、取值口径逐字不变)。 **改动** - 新增 `src/tdc/config.rs`:`TdcConfig::from_env` / `from_raw`(纯函数,可单测)/ `Default`;`src/tdc/constant.rs`:默认值 + 5 个业务 env 名(+ 撞名自检)。 - `src/platform/config.rs`:删 3 个业务常量与 5 个字段;`env_or_default` 转 `pub` (平台提供**机制**,业务提供**清单**)。 - `identity::bootstrap_identity(state, &tdc_config)`:业务配置改为**显式入参** (平台层不再持有它 ⇒ 装配层递进去)。 - `main.rs` 造 `TdcConfig::from_env()` 并递给引导与账号库; 8 个测试文件同步改用 `TdcConfig`。 - `CLAUDE.md` + `.workbuddy/memory/2026-10-26.md` 同步。 **设计** - `TdcConfig::from_raw(..)` 做成纯函数(不读进程全局 env)⇒ 与平台层同口径, 测试不引入串行/并行竞态。 Co-Authored-By: Claude <[email protected]>
54 lines
2.1 KiB
Rust
54 lines
2.1 KiB
Rust
//! 引导失败的端到端用例:INSERT 失败 ⇒ **不得**回传密钥。
|
||
//!
|
||
//! ⚠️ 本文件是**独立测试二进制** ⇒ 独立进程 ⇒ 独立 PGlite
|
||
//! (pglite-rs 每进程只允许一个实例)。
|
||
|
||
use std::sync::Arc;
|
||
|
||
use pglite::PGlite;
|
||
use tdc_connector::platform::config::Config;
|
||
use tdc_connector::tdc::config::TdcConfig;
|
||
use tdc_connector::tdc::service::identity::bootstrap_identity;
|
||
use tdc_connector::platform::session::SessionStore;
|
||
use tdc_connector::platform::state::{AppState, BootstrapIdentity};
|
||
|
||
#[tokio::test]
|
||
async fn bootstrap_insert_failure_yields_no_secret() {
|
||
let db = Arc::new(PGlite::open_temp().await.expect("打开临时 PGlite 失败"));
|
||
tdc_connector::platform::db::ensure_schema(db.as_ref())
|
||
.await
|
||
.expect("建表失败");
|
||
// 让 INSERT 必然失败:把目标表删掉
|
||
// (`PGlite::exec(&self, sql: &str)` 是无参版本;带参的是 `query(sql, &[&(dyn ToSql + Sync)])`)
|
||
db.exec("DROP TABLE tdc_identity").await.expect("删表失败");
|
||
|
||
let config = Config::from_env(std::env::current_dir().unwrap());
|
||
let state = AppState::new(
|
||
config,
|
||
db,
|
||
Arc::new(SessionStore::new()),
|
||
BootstrapIdentity::default(),
|
||
);
|
||
|
||
// 🔴 业务配置走显式入参(v3 spec §2.3.1 C8)⇒ 身份码不再挂在平台 Config 上。
|
||
let tdc_config = TdcConfig {
|
||
identity_code: "TEST-CONNECTOR".to_string(),
|
||
identity_name: "测试连接器".to_string(),
|
||
identity_secret: Some("test-secret-key".to_string()),
|
||
bootstrap_admin_account: "admin".to_string(),
|
||
bootstrap_admin_password: None,
|
||
};
|
||
let bootstrap = bootstrap_identity(&state, &tdc_config).await;
|
||
// 🔴 失败 ⇒ 不得有密钥、不得有 id
|
||
assert!(
|
||
bootstrap.issued_secret.is_none(),
|
||
"引导失败时不得回传密钥,实际 {:?}",
|
||
bootstrap.issued_secret
|
||
);
|
||
assert!(
|
||
bootstrap.identity_id.is_empty(),
|
||
"引导失败时不得回传没落库的 id,实际 {:?}",
|
||
bootstrap.identity_id
|
||
);
|
||
}
|