char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
5.3 KiB134 linesraw
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', () => {
21	function bearerInput(screen: Awaited<ReturnType<typeof render>>) {
22		return screen.locator.getByPlaceholder(BEARER_PLACEHOLDER);
23	}
24
25	function capturedHeaders(screen: Awaited<ReturnType<typeof render>>) {
26		return screen.getByTestId('captured-headers');
27	}
28
29	it('mounts with the bearer input hidden when no auth header is present', async () => {
30		const screen = await render(McpServerFormWrapper, { headers: '' });
31
32		await expect.element(screen.getByRole('textbox', { name: /server url/i })).toBeVisible();
33
34		await expect.element(bearerInput(screen)).not.toBeInTheDocument();
35	});
36
37	it('toggling Authorization shows the bearer input', async () => {
38		const screen = await render(McpServerFormWrapper, { headers: '' });
39
40		await screen.getByRole('switch', { name: /authorization/i }).click();
41
42		await expect.element(bearerInput(screen)).toBeVisible();
43	});
44
45	it('typing a token writes the Authorization row with the Bearer prefix prepended', async () => {
46		const screen = await render(McpServerFormWrapper, { headers: '' });
47
48		await screen.getByRole('switch', { name: /authorization/i }).click();
49
50		const token = 'super-secret';
51
52		await bearerInput(screen).fill(token);
53
54		const expected = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}${token}` });
55
56		await expect
57			.element(capturedHeaders(screen))
58			.toHaveAttribute('data-captured-headers', expected);
59	});
60
61	it('pre-existing Bearer header pre-fills the bearer input with the token stripped', async () => {
62		const existing = JSON.stringify({
63			[AUTHORIZATION_HEADER]: `${BEARER_PREFIX}preexisting`,
64			'X-Trace-Id': 'abc'
65		});
66		const screen = await render(McpServerFormWrapper, { headers: existing });
67
68		await expect.element(bearerInput(screen)).toBeVisible();
69		await expect.element(bearerInput(screen)).toHaveValue('preexisting');
70	});
71
72	it('non-Bearer Authorization is ignored by the dedicated UI and stays in the KV section', async () => {
73		const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: 'Basic czNjcjpwYXNz' });
74		const screen = await render(McpServerFormWrapper, { headers: existing });
75
76		await expect.element(bearerInput(screen)).not.toBeInTheDocument();
77
78		const headerKeyInput = screen.getByPlaceholder('Header name');
79
80		await expect.element(headerKeyInput).toBeVisible();
81	});
82
83	it('engaging the token UI replaces a non-Bearer Authorization with the Bearer scheme', async () => {
84		const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: 'Basic old' });
85		const screen = await render(McpServerFormWrapper, { headers: existing });
86
87		await screen.getByRole('switch', { name: /authorization/i }).click();
88		await bearerInput(screen).fill('new');
89
90		const expected = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}new` });
91
92		await expect
93			.element(capturedHeaders(screen))
94			.toHaveAttribute('data-captured-headers', expected);
95	});
96
97	it('toggling Authorization off with no token drops the Bearer row but keeps non-Bearer schemes', async () => {
98		const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}xyz` });
99		const screen = await render(McpServerFormWrapper, { headers: existing });
100
101		await screen.getByRole('switch', { name: /authorization/i }).click();
102
103		await expect.element(capturedHeaders(screen)).toHaveAttribute('data-captured-headers', '');
104	});
105
106	it('toggling Authorization off when no Bearer row is present leaves headers untouched', async () => {
107		const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: 'Basic czNjcjpwYXNz' });
108		const screen = await render(McpServerFormWrapper, { headers: existing });
109
110		await screen.getByRole('switch', { name: /authorization/i }).click();
111		await screen.getByRole('switch', { name: /authorization/i }).click();
112
113		await expect
114			.element(capturedHeaders(screen))
115			.toHaveAttribute('data-captured-headers', existing);
116	});
117
118	it('clearing the bearer input drops the Authorization row', async () => {
119		const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}xyz` });
120		const screen = await render(McpServerFormWrapper, { headers: existing });
121
122		await bearerInput(screen).fill('');
123
124		await expect.element(capturedHeaders(screen)).toHaveAttribute('data-captured-headers', '');
125	});
126
127	it('does not surface Bearer Authorization in the KV section even when pre-existing', async () => {
128		const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}xyz` });
129		const screen = await render(McpServerFormWrapper, { headers: existing });
130		const headerKeyInput = screen.getByPlaceholder('Header name');
131
132		await expect.element(headerKeyInput).not.toBeInTheDocument();
133	});
134});