char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1import McpServerFormWrapper from './components/McpServerFormWrapper.svelte' ; 2import { describe , expect , it } from 'vitest' ; 3import { render } from 'vitest-browser-svelte' ; 4 5const AUTHORIZATION_HEADER = 'Authorization' ; 6const BEARER_PREFIX = 'Bearer ' ; 7const BEARER_PLACEHOLDER = 'Paste token here' ; 8 9/** 10* Client-side tests for the McpServerForm bearer UI. 11* 12* The dedicated UI only "owns" Authorization headers that already carry a 13* Bearer scheme (heuristic check on the value). Other Authorization values 14* stay in the KV section so the user can still edit them verbatim. Storage 15* always goes through the same custom-headers slot, so a round-trip via this 16* UI produces exactly one `Authorization: Bearer <token>` entry. 17* 18* Equivalent parser coverage lives in `tests/unit/headers.test.ts`. 19*/ 20describe ( 'McpServerForm - Authorization / bearer UI' , () => { 21function bearerInput ( screen :Awaited < ReturnType < typeof render >>) { 22return screen . locator . getByPlaceholder ( BEARER_PLACEHOLDER ); 23} 24 25function capturedHeaders ( screen :Awaited < ReturnType < typeof render >>) { 26return screen . getByTestId ( 'captured-headers' ); 27} 28 29it ( 'mounts with the bearer input hidden when no auth header is present' , async () => { 30const screen = await render ( McpServerFormWrapper , { headers :'' }); 31 32await expect . element ( screen . getByRole ( 'textbox' , { name :/ server url / i })). toBeVisible (); 33 34await expect . element ( bearerInput ( screen )). not . toBeInTheDocument (); 35}); 36 37it ( 'toggling Authorization shows the bearer input' , async () => { 38const screen = await render ( McpServerFormWrapper , { headers :'' }); 39 40await screen . getByRole ( 'switch' , { name :/ authorization / i }). click (); 41 42await expect . element ( bearerInput ( screen )). toBeVisible (); 43}); 44 45it ( 'typing a token writes the Authorization row with the Bearer prefix prepended' , async () => { 46const screen = await render ( McpServerFormWrapper , { headers :'' }); 47 48await screen . getByRole ( 'switch' , { name :/ authorization / i }). click (); 49 50const token = 'super-secret' ; 51 52await bearerInput ( screen ). fill ( token ); 53 54const expected = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :` ${ BEARER_PREFIX } ${ token } ` }); 55 56await expect 57. element ( capturedHeaders ( screen )) 58. toHaveAttribute ( 'data-captured-headers' , expected ); 59}); 60 61it ( 'pre-existing Bearer header pre-fills the bearer input with the token stripped' , async () => { 62const existing = JSON . stringify ({ 63[ AUTHORIZATION_HEADER ] :` ${ BEARER_PREFIX } preexisting` , 64'X-Trace-Id' :'abc' 65}); 66const screen = await render ( McpServerFormWrapper , { headers :existing }); 67 68await expect . element ( bearerInput ( screen )). toBeVisible (); 69await expect . element ( bearerInput ( screen )). toHaveValue ( 'preexisting' ); 70}); 71 72it ( 'non-Bearer Authorization is ignored by the dedicated UI and stays in the KV section' , async () => { 73const existing = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :'Basic czNjcjpwYXNz' }); 74const screen = await render ( McpServerFormWrapper , { headers :existing }); 75 76await expect . element ( bearerInput ( screen )). not . toBeInTheDocument (); 77 78const headerKeyInput = screen . getByPlaceholder ( 'Header name' ); 79 80await expect . element ( headerKeyInput ). toBeVisible (); 81}); 82 83it ( 'engaging the token UI replaces a non-Bearer Authorization with the Bearer scheme' , async () => { 84const existing = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :'Basic old' }); 85const screen = await render ( McpServerFormWrapper , { headers :existing }); 86 87await screen . getByRole ( 'switch' , { name :/ authorization / i }). click (); 88await bearerInput ( screen ). fill ( 'new' ); 89 90const expected = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :` ${ BEARER_PREFIX } new` }); 91 92await expect 93. element ( capturedHeaders ( screen )) 94. toHaveAttribute ( 'data-captured-headers' , expected ); 95}); 96 97it ( 'toggling Authorization off with no token drops the Bearer row but keeps non-Bearer schemes' , async () => { 98const existing = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :` ${ BEARER_PREFIX } xyz` }); 99const screen = await render ( McpServerFormWrapper , { headers :existing }); 100 101await screen . getByRole ( 'switch' , { name :/ authorization / i }). click (); 102 103await expect . element ( capturedHeaders ( screen )). toHaveAttribute ( 'data-captured-headers' , '' ); 104}); 105 106it ( 'toggling Authorization off when no Bearer row is present leaves headers untouched' , async () => { 107const existing = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :'Basic czNjcjpwYXNz' }); 108const screen = await render ( McpServerFormWrapper , { headers :existing }); 109 110await screen . getByRole ( 'switch' , { name :/ authorization / i }). click (); 111await screen . getByRole ( 'switch' , { name :/ authorization / i }). click (); 112 113await expect 114. element ( capturedHeaders ( screen )) 115. toHaveAttribute ( 'data-captured-headers' , existing ); 116}); 117 118it ( 'clearing the bearer input drops the Authorization row' , async () => { 119const existing = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :` ${ BEARER_PREFIX } xyz` }); 120const screen = await render ( McpServerFormWrapper , { headers :existing }); 121 122await bearerInput ( screen ). fill ( '' ); 123 124await expect . element ( capturedHeaders ( screen )). toHaveAttribute ( 'data-captured-headers' , '' ); 125}); 126 127it ( 'does not surface Bearer Authorization in the KV section even when pre-existing' , async () => { 128const existing = JSON . stringify ({ [ AUTHORIZATION_HEADER ] :` ${ BEARER_PREFIX } xyz` }); 129const screen = await render ( McpServerFormWrapper , { headers :existing }); 130const headerKeyInput = screen . getByPlaceholder ( 'Header name' ); 131 132await expect . element ( headerKeyInput ). not . toBeInTheDocument (); 133}); 134});