Skip to content

Commit 9e2fc09

Browse files
committed
fix(native): fall back when commit message is pending
1 parent 7244297 commit 9e2fc09

7 files changed

Lines changed: 639 additions & 25 deletions

File tree

apps/native/src-tauri/src/commands/summarize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub async fn finalize_restore(
7979

8080
/// Generates a commit message from the current semantic change map via the pipeline.
8181
#[tauri::command]
82-
pub async fn generate_commit_message(app: AppHandle) -> Result<String, String> {
82+
pub async fn generate_commit_message(app: AppHandle) -> Result<Option<String>, String> {
8383
crate::summarize::pipelines::commit_message::generate(&app)
8484
.await
8585
.map_err(|e| capture_err("generate_commit_message", e))

apps/native/src-tauri/src/summarize/pipelines/commit_message.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
//! Commit message pipeline — returns the stored whole-diff summary when available.
22
3+
use crate::summarize::find_existing::FoundSetForCurrent;
34
use anyhow::Result;
45
use tauri::{AppHandle, Runtime};
56

6-
pub async fn generate<R: Runtime>(app: &AppHandle<R>) -> Result<String> {
7+
pub async fn generate<R: Runtime>(app: &AppHandle<R>) -> Result<Option<String>> {
78
let base_ref = crate::summarize::active_summary_base_ref(app);
89
let change_sets = crate::summarize::found_change_sets_since(app, &base_ref)?;
910

11+
Ok(stored_generated_commit_message(&change_sets))
12+
}
13+
14+
fn stored_generated_commit_message(change_sets: &[FoundSetForCurrent]) -> Option<String> {
1015
change_sets
1116
.iter()
1217
.find_map(|entry| {
@@ -17,5 +22,46 @@ pub async fn generate<R: Runtime>(app: &AppHandle<R>) -> Result<String> {
1722
.filter(|message| !message.trim().is_empty())
1823
})
1924
.map(str::to_string)
20-
.ok_or_else(|| anyhow::anyhow!("no generated commit message found"))
25+
}
26+
27+
#[cfg(test)]
28+
mod tests {
29+
use super::*;
30+
use crate::sqlite_types::ChangeSet;
31+
32+
fn found_with_message(generated_commit_message: Option<&str>) -> FoundSetForCurrent {
33+
FoundSetForCurrent {
34+
change_set: Some(ChangeSet {
35+
id: 1,
36+
commit_id: None,
37+
base_commit_id: 1,
38+
commit_message: None,
39+
generated_commit_message: generated_commit_message.map(str::to_string),
40+
created_at: 0,
41+
evolution_id: None,
42+
}),
43+
changes: vec![],
44+
missed_hashes: vec![],
45+
}
46+
}
47+
48+
#[test]
49+
fn missing_generated_commit_message_is_expected_absence() {
50+
let change_sets = vec![found_with_message(None), found_with_message(Some(" "))];
51+
52+
assert_eq!(stored_generated_commit_message(&change_sets), None);
53+
}
54+
55+
#[test]
56+
fn returns_first_non_empty_generated_commit_message() {
57+
let change_sets = vec![
58+
found_with_message(None),
59+
found_with_message(Some("feat(nix): update shell packages")),
60+
];
61+
62+
assert_eq!(
63+
stored_generated_commit_message(&change_sets).as_deref(),
64+
Some("feat(nix): update shell packages"),
65+
);
66+
}
2167
}

0 commit comments

Comments
 (0)