@@ -240,3 +240,54 @@ fn test_predictive_mode_no_auto_commit() {
240240 ) ;
241241 }
242242}
243+
244+ #[ test]
245+ fn test_auto_commit_skips_single_kana_first_segment ( ) {
246+ use lex_core:: candidates:: generate_candidates;
247+
248+ let dict = make_test_dict ( ) ;
249+ let mut session = InputSession :: new ( dict. clone ( ) , None , None ) ;
250+ session. set_defer_candidates ( true ) ;
251+
252+ fn complete_cycle ( session : & mut InputSession , dict : & dyn Dictionary ) -> Option < KeyResponse > {
253+ let reading = session. comp ( ) . kana . clone ( ) ;
254+ if reading. is_empty ( ) {
255+ return None ;
256+ }
257+ let cand = generate_candidates ( dict, None , None , & reading, 20 ) ;
258+ session. receive_candidates ( & reading, cand. surfaces , cand. paths )
259+ }
260+
261+ // Type a reading where Viterbi may produce a single-kana first segment.
262+ // Even if stability threshold is met, auto-commit must NOT fire when the
263+ // committed reading is shorter than 2 kana.
264+ type_string ( & mut session, "ji" ) ;
265+ complete_cycle ( & mut session, & * dict) ;
266+ type_string ( & mut session, "ji" ) ;
267+ complete_cycle ( & mut session, & * dict) ;
268+ type_string ( & mut session, "ji" ) ;
269+ complete_cycle ( & mut session, & * dict) ;
270+ type_string ( & mut session, "ji" ) ;
271+ let r = complete_cycle ( & mut session, & * dict) ;
272+
273+ // Verify auto-commit preconditions are met (stability >= 3),
274+ // so this test is actually exercising the min-length guard.
275+ assert ! (
276+ session. comp( ) . stability. count >= 3 ,
277+ "stability count should reach threshold; got {}" ,
278+ session. comp( ) . stability. count
279+ ) ;
280+
281+ // Even after many cycles, a single-kana first segment must not auto-commit.
282+ if let Some ( ref resp) = r {
283+ assert ! (
284+ resp. commit. is_none( ) ,
285+ "auto-commit should not commit when the first segment would be a single kana"
286+ ) ;
287+ }
288+ assert_eq ! (
289+ session. comp( ) . kana,
290+ "じじじじ" ,
291+ "composing kana should remain unchanged when auto-commit is skipped"
292+ ) ;
293+ }
0 commit comments