char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
a6040c925
char/aliceai-t5-moe
1import { REASONING_TAGS } from '$lib/constants' ; 2import { AgenticSectionType } from '$lib/enums' ; 3import type { AgenticSection } from '$lib/types/agentic' ; 4import { buildAssistantRawOutput } from '$lib/utils/agentic' ; 5import { describe , expect , it } from 'vitest' ; 6 7function makeSection ( 8overrides :Partial < AgenticSection > & { type :AgenticSectionType } 9) :AgenticSection { 10return { 11content :'' , 12 ...overrides 13}; 14} 15 16describe ( 'buildAssistantRawOutput' , () => { 17it ( 'returns empty string for empty sections' , () => { 18expect ( buildAssistantRawOutput ([])). toBe ( '' ); 19}); 20 21it ( 'formats a reasoning section with a single newline between tags and content' , () => { 22const sections = [ makeSection ({ content :'thinking...' , type :AgenticSectionType . REASONING })]; 23 24expect ( buildAssistantRawOutput ( sections )). toBe ( 25` ${ REASONING_TAGS . START } \nthinking... ${ REASONING_TAGS . END } ` 26); 27}); 28 29it ( 'formats a text section as-is' , () => { 30const sections = [ makeSection ({ content :'Hello' , type :AgenticSectionType . TEXT })]; 31 32expect ( buildAssistantRawOutput ( sections )). toBe ( 'Hello' ); 33}); 34 35it ( 'formats a tool call with JSON args and no result label' , () => { 36const sections = [ 37makeSection ({ 38toolArgs :JSON . stringify ({ path :'/tmp/file.txt' }), 39toolName :'read_file' , 40toolResult :'file contents' , 41type :AgenticSectionType . TOOL_CALL 42}) 43]; 44 45expect ( buildAssistantRawOutput ( sections )). toBe ( 46[ 47'{' , 48' "name": "read_file",' , 49' "arguments": {' , 50' "path": "/tmp/file.txt"' , 51' }' , 52'}' , 53'' , 54'' , 55'file contents' 56]. join ( '\n' ) 57); 58}); 59 60it ( 'joins multiple sections with double newlines' , () => { 61const sections = [ 62makeSection ({ content :'Hello' , type :AgenticSectionType . TEXT }), 63makeSection ({ toolName :'noop' , type :AgenticSectionType . TOOL_CALL }) 64]; 65 66expect ( buildAssistantRawOutput ( sections )). toBe ( 'Hello\n\n{\n "name": "noop"\n}' ); 67}); 68 69it ( 'falls back to raw string args when JSON parsing fails' , () => { 70const sections = [ 71makeSection ({ 72toolArgs :'{not json' , 73toolName :'broken' , 74toolResult :'result' , 75type :AgenticSectionType . TOOL_CALL 76}) 77]; 78 79expect ( buildAssistantRawOutput ( sections )). toBe ( 80[ '{' , ' "name": "broken",' , ' "arguments": "{not json"' , '}' , '' , '' , 'result' ]. join ( '\n' ) 81); 82}); 83});