fix: 三端联调测试 2 P0 + 6 P1 + 2 P2 修复
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

P0-1: SaaS relay 模型别名解析 — "glm-4-flash" → "glm-4-flash-250414" (resolve_model)
P0-2: config.rs interpolate_env_vars UTF-8 修复 (chars 迭代器替代 bytes as char)
      + DB 启动编码检查 + docker-compose UTF-8 编码参数

P1-3: UI 模型选择器覆盖 Agent 默认模型 (model_override 全链路: TS→Tauri→Rust kernel)
P1-6: 知识搜索管道修复 — seed_knowledge 创建 chunks + 默认分类 (seed/uploaded/distillation)
P1-7: 用量限额从当前 Plan 读取 (非 stale usage 表)
P1-8: relay 双维度配额检查 (relay_requests + input_tokens)

P2-9: SSE 路径 token 计数修复 — 流结束检测替代固定 500ms sleep + billing increment
This commit is contained in:
iven
2026-04-14 00:17:08 +08:00
parent 0903a0d652
commit 4c3136890b
13 changed files with 234 additions and 49 deletions

View File

@@ -38,10 +38,25 @@ pub async fn init_db(config: &DatabaseConfig) -> SaasResult<PgPool> {
.connect(&database_url)
.await?;
// 验证数据库编码为 UTF8 — 中文 Windows (GBK/代码页936) 可能导致默认非 UTF8
let encoding: (String,) = sqlx::query_as("SHOW server_encoding")
.fetch_one(&pool)
.await
.unwrap_or(("UNKNOWN".to_string(),));
if encoding.0.to_uppercase() != "UTF8" {
tracing::error!(
"⚠ 数据库编码为 '{}',非 UTF8中文数据将损坏。请使用 CREATE DATABASE ... WITH ENCODING='UTF8' 重建数据库。",
encoding.0
);
} else {
tracing::info!("Database encoding: {}", encoding.0);
}
run_migrations(&pool).await?;
ensure_security_columns(&pool).await?;
seed_admin_account(&pool).await?;
seed_builtin_prompts(&pool).await?;
seed_knowledge_categories(&pool).await?;
seed_builtin_industries(&pool).await?;
seed_demo_data(&pool).await?;
fix_seed_data(&pool).await?;
@@ -1004,6 +1019,31 @@ async fn seed_builtin_industries(pool: &PgPool) -> SaasResult<()> {
crate::industry::service::seed_builtin_industries(pool).await
}
/// 种子化知识库默认分类(幂等)
async fn seed_knowledge_categories(pool: &PgPool) -> SaasResult<()> {
let now = chrono::Utc::now();
let categories = [
("seed", "种子知识", "系统内置的行业基础知识"),
("uploaded", "上传文档", "用户上传的文档知识"),
("distillation", "蒸馏知识", "API 蒸馏生成的知识"),
];
for (id, name, desc) in &categories {
sqlx::query(
"INSERT INTO knowledge_categories (id, name, description, created_at, updated_at) \
VALUES ($1, $2, $3, $4, $4) \
ON CONFLICT (id) DO NOTHING"
)
.bind(id)
.bind(name)
.bind(desc)
.bind(&now)
.execute(pool)
.await?;
}
tracing::debug!("Seeded knowledge categories");
Ok(())
}
#[cfg(test)]
mod tests {
// PostgreSQL 单元测试需要真实数据库连接,此处保留接口兼容