22// assistant message phases.
33import { describe , expect , it } from "vitest" ;
44import { extractAssistantText as extractChatHistoryAssistantText } from "./chat-history-text.js" ;
5- import { extractAssistantText as extractSessionAssistantText } from "./session-message-text.js" ;
65
76function assistantTextPart ( id : string , phase : string , text : string ) {
87 return {
@@ -19,39 +18,31 @@ function assistantMessage(...content: ReturnType<typeof assistantTextPart>[]) {
1918 } ;
2019}
2120
22- const assistantTextExtractors = [
23- [ "chat history" , extractChatHistoryAssistantText ] ,
24- [ "session message" , extractSessionAssistantText ] ,
25- ] as const ;
26-
2721describe ( "phase-aware assistant text helpers" , ( ) => {
2822 it ( "fails soft for malformed inputs" , ( ) => {
2923 for ( const message of [ null , 42 , "broken history entry" ] ) {
3024 expect ( extractChatHistoryAssistantText ( message ) ) . toBeUndefined ( ) ;
31- expect ( extractSessionAssistantText ( message ) ) . toBeUndefined ( ) ;
3225 }
3326 } ) ;
3427
35- for ( const [ label , extractAssistantText ] of assistantTextExtractors ) {
36- it ( `prefers final_answer text over commentary in ${ label } helpers` , ( ) => {
37- const message = assistantMessage (
38- assistantTextPart ( "commentary" , "commentary" , "Need verify healthy." ) ,
39- assistantTextPart ( "final" , "final_answer" , "Health check completed successfully." ) ,
40- ) ;
28+ it ( "prefers final_answer text over commentary" , ( ) => {
29+ const message = assistantMessage (
30+ assistantTextPart ( "commentary" , "commentary" , "Need verify healthy." ) ,
31+ assistantTextPart ( "final" , "final_answer" , "Health check completed successfully." ) ,
32+ ) ;
4133
42- expect ( extractAssistantText ( message ) ) . toBe ( "Health check completed successfully." ) ;
43- } ) ;
34+ expect ( extractChatHistoryAssistantText ( message ) ) . toBe ( "Health check completed successfully." ) ;
35+ } ) ;
4436
45- it ( ` preserves spaces across split final_answer blocks in ${ label } helpers` , ( ) => {
46- const message = assistantMessage (
47- assistantTextPart ( "commentary" , "commentary" , "Need verify healthy." ) ,
48- assistantTextPart ( "final_1" , "final_answer" , "Hi " ) ,
49- assistantTextPart ( "final_2" , "final_answer" , "<think>secret</think>there" ) ,
50- ) ;
37+ it ( " preserves spaces across split final_answer blocks" , ( ) => {
38+ const message = assistantMessage (
39+ assistantTextPart ( "commentary" , "commentary" , "Need verify healthy." ) ,
40+ assistantTextPart ( "final_1" , "final_answer" , "Hi " ) ,
41+ assistantTextPart ( "final_2" , "final_answer" , "<think>secret</think>there" ) ,
42+ ) ;
5143
52- expect ( extractAssistantText ( message ) ) . toBe ( "Hi there" ) ;
53- } ) ;
54- }
44+ expect ( extractChatHistoryAssistantText ( message ) ) . toBe ( "Hi there" ) ;
45+ } ) ;
5546
5647 it ( "does not fall back to commentary when an explicit final_answer is empty" , ( ) => {
5748 // An explicit empty final answer means there is no publishable response;
0 commit comments