char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
85d5703a3
char/aliceai-t5-moe
1import { classifyToolResult } from '$lib/utils/agentic' ; 2import { describe , expect , it } from 'vitest' ; 3 4describe ( 'classifyToolResult' , () => { 5describe ( 'text' , () => { 6it ( 'returns text for undefined input' , () => { 7expect ( classifyToolResult ( undefined )). toBe ( 'text' ); 8}); 9 10it ( 'returns text for empty string' , () => { 11expect ( classifyToolResult ( '' )). toBe ( 'text' ); 12}); 13 14it ( 'returns text for whitespace-only input' , () => { 15expect ( classifyToolResult ( ' \n ' )). toBe ( 'text' ); 16}); 17 18it ( 'returns text for plain prose' , () => { 19expect ( classifyToolResult ( 'Hello, this is just some text.' )). toBe ( 'text' ); 20}); 21 22it ( 'returns text for shell-style line listings' , () => { 23expect ( classifyToolResult ( 'file1.java\nfile2.java\nfile3.java\n' )). toBe ( 'text' ); 24}); 25 26it ( 'returns text when a brace-like string is not valid JSON' , () => { 27expect ( classifyToolResult ( '{key: value}' )). toBe ( 'text' ); 28}); 29}); 30 31describe ( 'json' , () => { 32it ( 'classifies a flat JSON object' , () => { 33expect ( classifyToolResult ( '{"key": "value", "n": 42}' )). toBe ( 'json' ); 34}); 35 36it ( 'classifies a JSON array' , () => { 37expect ( classifyToolResult ( '["a", "b", "c"]' )). toBe ( 'json' ); 38}); 39 40it ( 'classifies a nested JSON array' , () => { 41expect ( classifyToolResult ( '[[1, 2], [3, 4]]' )). toBe ( 'json' ); 42}); 43 44it ( 'classifies a pretty-printed JSON object' , () => { 45expect ( classifyToolResult ( '{\n "key": "value"\n}' )). toBe ( 'json' ); 46}); 47 48it ( 'classifies a deeply nested JSON payload' , () => { 49const nested = JSON . stringify ({ items :[{ id :1 , tags :[ 'a' , 'b' ] }] }, null , 2 ); 50 51expect ( classifyToolResult ( nested )). toBe ( 'json' ); 52}); 53 54it ( 'prefers JSON over inner markdown markers when the content starts with a brace' , () => { 55// A JSON object whose inner strings contain link syntax still 56// reads as JSON because the leading `{` parses cleanly - 57// `classifyToolResult` only inspects the top-level shape, not 58// every nested line marker. 59const jsonWithLink = '{"docs": "see [docs](https://example.com) for more"}' ; 60 61expect ( classifyToolResult ( jsonWithLink )). toBe ( 'json' ); 62}); 63}); 64 65describe ( 'markdown' , () => { 66it ( 'classifies an ATX header line' , () => { 67expect ( classifyToolResult ( '# Title\n\nSome text below.' )). toBe ( 'markdown' ); 68}); 69 70it ( 'classifies a fenced code block' , () => { 71expect ( classifyToolResult ( '```json\n{"key": "v"}\n```' )). toBe ( 'markdown' ); 72}); 73 74it ( 'classifies a tilde-fenced code block' , () => { 75expect ( classifyToolResult ( '~~~bash\nls -la\n~~~' )). toBe ( 'markdown' ); 76}); 77 78it ( 'classifies a markdown link' , () => { 79expect ( classifyToolResult ( 'See [docs](https://example.com) for more.' )). toBe ( 'markdown' ); 80}); 81 82it ( 'classifies bold text' , () => { 83expect ( classifyToolResult ( 'This is **very important**.' )). toBe ( 'markdown' ); 84}); 85 86it ( 'classifies a bulleted list' , () => { 87expect ( classifyToolResult ( '- item one\n- item two\n- item three' )). toBe ( 'markdown' ); 88}); 89 90it ( 'classifies an ordered list' , () => { 91expect ( classifyToolResult ( '1. first step\n2. second step\n3. third step' )). toBe ( 'markdown' ); 92}); 93 94it ( 'classifies a blockquote' , () => { 95expect ( classifyToolResult ( '> quoted text\n> second line' )). toBe ( 'markdown' ); 96}); 97 98it ( 'classifies a markdown table' , () => { 99const table = '| a | b |\n| - | - |\n| 1 | 2 |' ; 100 101expect ( classifyToolResult ( table )). toBe ( 'markdown' ); 102}); 103 104it ( 'classifies a markdown table with alignment markers' , () => { 105const table = '| left | center | right |\n| :--- | :---: | ---: |\n| a | b | c |' ; 106 107expect ( classifyToolResult ( table )). toBe ( 'markdown' ); 108}); 109 110it ( 'classifies nested markdown headings' , () => { 111expect ( classifyToolResult ( '## Section\n\n### Subsection\n' )). toBe ( 'markdown' ); 112}); 113 114it ( 'classifies combined markdown markers in one document' , () => { 115const md = [ 116'# Heading' , 117'' , 118'A paragraph with a [link](https://example.com) and **bold text**.' , 119'' , 120'- bullet item' , 121'- another bullet' , 122'' , 123'| col1 | col2 |' , 124'| ----- | ----- |' , 125'| a | b |' 126]. join ( '\n' ); 127 128expect ( classifyToolResult ( md )). toBe ( 'markdown' ); 129}); 130}); 131 132describe ( 'precedence' , () => { 133it ( 'prefers JSON over markdown when both signals are present' , () => { 134// Starts with `[`, parses as JSON - markdown check is skipped. 135const arr = '[1, 2, "# not-a-heading", "**not-bold**"]' ; 136 137expect ( classifyToolResult ( arr )). toBe ( 'json' ); 138}); 139}); 140});