From e3e32c725d98781b66279b534def4b7b4031d360 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Fri, 7 Aug 2026 08:21:59 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E5=AF=B9=E5=AD=98=E5=82=A8=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=BA=94=E7=94=A8=20rustfmt=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- src/storage/migrations.rs | 13 +++++++++---- src/storage/row_mapping.rs | 6 +----- src/storage/tests.rs | 14 +++----------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08450eb..b31b3bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1635,7 +1635,7 @@ dependencies = [ [[package]] name = "picobot" -version = "0.3.1" +version = "0.3.2" dependencies = [ "anyhow", "async-trait", diff --git a/src/storage/migrations.rs b/src/storage/migrations.rs index 217f04c..971886a 100644 --- a/src/storage/migrations.rs +++ b/src/storage/migrations.rs @@ -53,7 +53,10 @@ pub(super) fn ensure_messages_schema(conn: &Connection) -> Result<(), StorageErr // Token usage 字段(仅 assistant 消息有值,来自 LLM 响应) if !has_column(conn, "messages", "prompt_tokens")? { - add_column_if_missing(conn, "ALTER TABLE messages ADD COLUMN prompt_tokens INTEGER")?; + add_column_if_missing( + conn, + "ALTER TABLE messages ADD COLUMN prompt_tokens INTEGER", + )?; } if !has_column(conn, "messages", "completion_tokens")? { add_column_if_missing( @@ -147,8 +150,7 @@ pub(super) fn ensure_memory_scope_key_migration(conn: &Connection) -> Result<(), // 版本 0:未迁移;版本 1:memory_scope_key 迁移已完成。 const MEMORY_SCOPE_KEY_MIGRATION_VERSION: i64 = 1; - let current_version: i64 = - conn.query_row("PRAGMA user_version", [], |row| row.get(0))?; + let current_version: i64 = conn.query_row("PRAGMA user_version", [], |row| row.get(0))?; if current_version >= MEMORY_SCOPE_KEY_MIGRATION_VERSION { // 已迁移过,跳过 @@ -182,7 +184,10 @@ pub(super) fn ensure_memory_scope_key_migration(conn: &Connection) -> Result<(), // 步骤3:记录迁移版本,后续启动直接跳过 conn.execute( - &format!("PRAGMA user_version = {}", MEMORY_SCOPE_KEY_MIGRATION_VERSION), + &format!( + "PRAGMA user_version = {}", + MEMORY_SCOPE_KEY_MIGRATION_VERSION + ), [], )?; diff --git a/src/storage/row_mapping.rs b/src/storage/row_mapping.rs index 3db8766..0cce0f2 100644 --- a/src/storage/row_mapping.rs +++ b/src/storage/row_mapping.rs @@ -27,11 +27,7 @@ pub(super) fn map_usage_row( let completion: Option = row.get(completion_idx)?; let total: Option = row.get(total_idx)?; let context_window: Option = row.get(context_window_idx)?; - if prompt.is_none() - && completion.is_none() - && total.is_none() - && context_window.is_none() - { + if prompt.is_none() && completion.is_none() && total.is_none() && context_window.is_none() { Ok(None) } else { Ok(Some(MessageUsage { diff --git a/src/storage/tests.rs b/src/storage/tests.rs index ef4553e..586bcd0 100644 --- a/src/storage/tests.rs +++ b/src/storage/tests.rs @@ -692,9 +692,7 @@ fn test_scheduler_job_roundtrip_and_runtime_update() { fn test_get_topic_message_count_uses_count_query() { let store = SessionStore::in_memory().unwrap(); let session = store.create_cli_session(Some("topic-count")).unwrap(); - let topic = store - .create_topic(&session.id, "topic-1", None) - .unwrap(); + let topic = store.create_topic(&session.id, "topic-1", None).unwrap(); // 初始计数为 0 assert_eq!(store.get_topic_message_count(&topic.id).unwrap(), 0); @@ -702,11 +700,7 @@ fn test_get_topic_message_count_uses_count_query() { // 追加 3 条带 topic_id 的消息 for content in ["m1", "m2", "m3"] { store - .append_message_with_topic( - &session.id, - Some(&topic.id), - &ChatMessage::user(content), - ) + .append_message_with_topic(&session.id, Some(&topic.id), &ChatMessage::user(content)) .unwrap(); } @@ -714,9 +708,7 @@ fn test_get_topic_message_count_uses_count_query() { assert_eq!(store.get_topic_message_count(&topic.id).unwrap(), 3); // 另一个 topic 的计数应为 0(隔离验证) - let other_topic = store - .create_topic(&session.id, "topic-2", None) - .unwrap(); + let other_topic = store.create_topic(&session.id, "topic-2", None).unwrap(); assert_eq!(store.get_topic_message_count(&other_topic.id).unwrap(), 0); // 不存在的 topic_id 返回 0