* ui: move tools/ui to ui/apps/chat The chat app moves to its own root folder, ui/apps/chat, as the first step of splitting the UI into one library (ui/lib) and the apps built on it (ui/apps). The code is unchanged; every path that pointed at tools/ui now points at ui/apps/chat: CMake adds it from tools/, and the Dockerfiles, the Nix package, the workflows, the labeler, CODEOWNERS, .editorconfig, the git hooks, the dev and demo scripts and the docs follow it. Assisted-by: Claude (Opus 5.5 Medium) * ui: name Llama Chat's package @ggml-org/llama-chat It was still called llama-ui, the name of the library that now sits beside it in ui/lib (@ggml-org/llama-ui). The package stays private; the app's display name and the llama-ui.zip build artifact are unchanged. Assisted-by: Claude (Opus 5.5 Medium) * ui: call the built-in web UI Llama Chat in docs, help text and comments The app in tools/ui is Llama Chat; Llama UI is the component library it is built from. Prose that said "Web UI", "web UI" or "WebUI" for the app now names it: the READMEs, SECURITY.md, the --ui help text, the CMake option description, one server log line, code comments and the Storybook intro. Names that others depend on are unchanged: the deprecated --webui flag aliases, the LLAMA_*_WEBUI CMake and environment names, the webui_settings field, the storage migration keys and the Nix attributes. Assisted-by: Claude (Opus 5.5 Medium) * ui: name tools/ui as a former path of Llama Chat in the code-review skill Changes under the old tools/ui path, as well as tools/server/webui, still get the Llama Chat checklist. Assisted-by: Claude (Opus 5.5 Medium) * ui: name Llama Chat's path in the security policy's exclusions Llama Chat no longer lives under tools/server/, so the exclusion listed under it now names ui/apps/chat. What is covered stays the same. Assisted-by: Claude (Opus 5.5 Medium)
135 lines
5.3 KiB
TypeScript
135 lines
5.3 KiB
TypeScript
import McpServerFormWrapper from './components/McpServerFormWrapper.svelte';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { render } from 'vitest-browser-svelte';
|
|
|
|
const AUTHORIZATION_HEADER = 'Authorization';
|
|
const BEARER_PREFIX = 'Bearer ';
|
|
const BEARER_PLACEHOLDER = 'Paste token here';
|
|
|
|
/**
|
|
* Client-side tests for the McpServerForm bearer UI.
|
|
*
|
|
* The dedicated UI only "owns" Authorization headers that already carry a
|
|
* Bearer scheme (heuristic check on the value). Other Authorization values
|
|
* stay in the KV section so the user can still edit them verbatim. Storage
|
|
* always goes through the same custom-headers slot, so a round-trip via this
|
|
* UI produces exactly one `Authorization: Bearer <token>` entry.
|
|
*
|
|
* Equivalent parser coverage lives in `tests/unit/headers.test.ts`.
|
|
*/
|
|
describe('McpServerForm - Authorization / bearer UI', () => {
|
|
function bearerInput(screen: Awaited<ReturnType<typeof render>>) {
|
|
return screen.locator.getByPlaceholder(BEARER_PLACEHOLDER);
|
|
}
|
|
|
|
function capturedHeaders(screen: Awaited<ReturnType<typeof render>>) {
|
|
return screen.getByTestId('captured-headers');
|
|
}
|
|
|
|
it('mounts with the bearer input hidden when no auth header is present', async () => {
|
|
const screen = await render(McpServerFormWrapper, { headers: '' });
|
|
|
|
await expect.element(screen.getByRole('textbox', { name: /server url/i })).toBeVisible();
|
|
|
|
await expect.element(bearerInput(screen)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('toggling Authorization shows the bearer input', async () => {
|
|
const screen = await render(McpServerFormWrapper, { headers: '' });
|
|
|
|
await screen.getByRole('switch', { name: /authorization/i }).click();
|
|
|
|
await expect.element(bearerInput(screen)).toBeVisible();
|
|
});
|
|
|
|
it('typing a token writes the Authorization row with the Bearer prefix prepended', async () => {
|
|
const screen = await render(McpServerFormWrapper, { headers: '' });
|
|
|
|
await screen.getByRole('switch', { name: /authorization/i }).click();
|
|
|
|
const token = 'super-secret';
|
|
|
|
await bearerInput(screen).fill(token);
|
|
|
|
const expected = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}${token}` });
|
|
|
|
await expect
|
|
.element(capturedHeaders(screen))
|
|
.toHaveAttribute('data-captured-headers', expected);
|
|
});
|
|
|
|
it('pre-existing Bearer header pre-fills the bearer input with the token stripped', async () => {
|
|
const existing = JSON.stringify({
|
|
[AUTHORIZATION_HEADER]: `${BEARER_PREFIX}preexisting`,
|
|
'X-Trace-Id': 'abc'
|
|
});
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
|
|
await expect.element(bearerInput(screen)).toBeVisible();
|
|
await expect.element(bearerInput(screen)).toHaveValue('preexisting');
|
|
});
|
|
|
|
it('non-Bearer Authorization is ignored by the dedicated UI and stays in the KV section', async () => {
|
|
const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: 'Basic czNjcjpwYXNz' });
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
|
|
await expect.element(bearerInput(screen)).not.toBeInTheDocument();
|
|
|
|
const headerKeyInput = screen.getByPlaceholder('Header name');
|
|
|
|
await expect.element(headerKeyInput).toBeVisible();
|
|
});
|
|
|
|
it('engaging the token UI replaces a non-Bearer Authorization with the Bearer scheme', async () => {
|
|
const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: 'Basic old' });
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
|
|
await screen.getByRole('switch', { name: /authorization/i }).click();
|
|
await bearerInput(screen).fill('new');
|
|
|
|
const expected = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}new` });
|
|
|
|
await expect
|
|
.element(capturedHeaders(screen))
|
|
.toHaveAttribute('data-captured-headers', expected);
|
|
});
|
|
|
|
it('toggling Authorization off with no token drops the Bearer row but keeps non-Bearer schemes', async () => {
|
|
const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}xyz` });
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
|
|
await screen.getByRole('switch', { name: /authorization/i }).click();
|
|
|
|
await expect.element(capturedHeaders(screen)).toHaveAttribute('data-captured-headers', '');
|
|
});
|
|
|
|
it('toggling Authorization off when no Bearer row is present leaves headers untouched', async () => {
|
|
const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: 'Basic czNjcjpwYXNz' });
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
|
|
await screen.getByRole('switch', { name: /authorization/i }).click();
|
|
await screen.getByRole('switch', { name: /authorization/i }).click();
|
|
|
|
await expect
|
|
.element(capturedHeaders(screen))
|
|
.toHaveAttribute('data-captured-headers', existing);
|
|
});
|
|
|
|
it('clearing the bearer input drops the Authorization row', async () => {
|
|
const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}xyz` });
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
|
|
await bearerInput(screen).fill('');
|
|
|
|
await expect.element(capturedHeaders(screen)).toHaveAttribute('data-captured-headers', '');
|
|
});
|
|
|
|
it('does not surface Bearer Authorization in the KV section even when pre-existing', async () => {
|
|
const existing = JSON.stringify({ [AUTHORIZATION_HEADER]: `${BEARER_PREFIX}xyz` });
|
|
const screen = await render(McpServerFormWrapper, { headers: existing });
|
|
const headerKeyInput = screen.getByPlaceholder('Header name');
|
|
|
|
await expect.element(headerKeyInput).not.toBeInTheDocument();
|
|
});
|
|
});
|