Move the vitest tests to the open-webui/tests suite (#29677)

The colocated vitest files (shortcuts, the colon fence marked extension) now
live in open-webui/tests under frontend/, next to the rest of the regression
suite, where they run against the source of any ref through the shared
regression workflow. This removes the copies here; the unit-tests workflow job
and the test:frontend script stay and pass with no tests.

src/lib/utils/_template_old.ts goes as well: it imports vitest but its name
never matched the test glob, so those tests have not run since they were added.
This commit is contained in:
Classic298 2026-09-05 01:43:48 +02:00 committed by GitHub
parent 7bf898f461
commit c2e6766ed8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 0 additions and 178 deletions

View file

@ -1,43 +0,0 @@
import { beforeEach, describe, expect, it } from 'vitest';
import {
eventToChord,
loadKeybindings,
matchKeybinding,
resetKeybindings,
Shortcut
} from './shortcuts';
const key = (
key: string,
modifiers: Partial<Pick<KeyboardEvent, 'ctrlKey' | 'metaKey' | 'altKey' | 'shiftKey'>> = {}
) =>
({
key,
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: false,
...modifiers
}) as KeyboardEvent;
describe('shortcuts', () => {
beforeEach(() => {
resetKeybindings();
});
it('normalizes ctrl to Cmd on non-Mac platforms', () => {
expect(eventToChord(key('k', { ctrlKey: true }))).toBe('Cmd+K');
expect(matchKeybinding(key('k', { ctrlKey: true }))).toBe(Shortcut.SEARCH);
});
it('loads saved bindings, including unassigned shortcuts', () => {
loadKeybindings({
[Shortcut.SEARCH]: 'Cmd+Shift+P',
[Shortcut.NEW_CHAT]: ''
});
expect(matchKeybinding(key('k', { ctrlKey: true }))).toBeNull();
expect(matchKeybinding(key('p', { ctrlKey: true, shiftKey: true }))).toBe(Shortcut.SEARCH);
expect(matchKeybinding(key('o', { ctrlKey: true, shiftKey: true }))).toBeNull();
});
});

View file

@ -1,66 +0,0 @@
import { titleGenerationTemplate } from '$lib/utils/index';
import { expect, test } from 'vitest';
test('titleGenerationTemplate correctly replaces {{prompt}} placeholder', () => {
const template = 'Hello {{prompt}}!';
const prompt = 'world';
const expected = 'Hello world!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate correctly replaces {{prompt:start:<length>}} placeholder', () => {
const template = 'Hello {{prompt:start:3}}!';
const prompt = 'world';
const expected = 'Hello wor!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate correctly replaces {{prompt:end:<length>}} placeholder', () => {
const template = 'Hello {{prompt:end:3}}!';
const prompt = 'world';
const expected = 'Hello rld!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate correctly replaces {{prompt:middletruncate:<length>}} placeholder when prompt length is greater than length', () => {
const template = 'Hello {{prompt:middletruncate:4}}!';
const prompt = 'world';
const expected = 'Hello wo...ld!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate correctly replaces {{prompt:middletruncate:<length>}} placeholder when prompt length is less than or equal to length', () => {
const template = 'Hello {{prompt:middletruncate:5}}!';
const prompt = 'world';
const expected = 'Hello world!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate returns original template when no placeholders are present', () => {
const template = 'Hello world!';
const prompt = 'world';
const expected = 'Hello world!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate does not replace placeholders inside of replaced placeholders', () => {
const template = 'Hello {{prompt}}!';
const prompt = 'World, {{prompt}} injection';
const expected = 'Hello World, {{prompt}} injection!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});
test('titleGenerationTemplate correctly replaces multiple placeholders', () => {
const template = 'Hello {{prompt}}! This is {{prompt:start:3}}!';
const prompt = 'world';
const expected = 'Hello world! This is wor!';
const actual = titleGenerationTemplate(template, prompt);
expect(actual).toBe(expected);
});

View file

@ -1,69 +0,0 @@
import { describe, expect, it } from 'vitest';
import { Marked } from 'marked';
import colonFenceExtension from './colon-fence-extension';
type ColonFenceToken = {
type: string;
fenceType: string;
attributes: Record<string, string>;
text: string;
};
const firstFence = (src: string) => {
const marked = new Marked();
marked.use(colonFenceExtension());
const tokens = marked.lexer(src) as unknown as ColonFenceToken[];
return tokens.find((token) => token.type === 'colonFence') as ColonFenceToken;
};
describe('colon fence extension', () => {
it('tokenizes a block without attributes', () => {
const token = firstFence(':::writing\n\nHello\n:::\n');
expect(token.fenceType).toBe('writing');
expect(token.attributes).toEqual({});
expect(token.text).toBe('Hello');
});
it('parses the attributes on the opening line', () => {
const token = firstFence(
':::writing{variant="email" id="48173" subject="Short question" recipient="mail@example.com"}\n\nHello\n:::\n'
);
expect(token.attributes).toEqual({
variant: 'email',
id: '48173',
subject: 'Short question',
recipient: 'mail@example.com'
});
expect(token.text).toBe('Hello');
});
it('does not read attributes from unbraced trailing text', () => {
const token = firstFence(':::writing{variant="document"} draft subject="junk"\n\nHello\n:::\n');
expect(token.attributes).toEqual({ variant: 'document' });
});
it('ignores an opening line that has no braces at all', () => {
const token = firstFence(
':::note prose mentioning recipient="evil@example.com"\n\nHello\n:::\n'
);
expect(token.fenceType).toBe('note');
expect(token.attributes).toEqual({});
});
it('ignores an unclosed brace', () => {
const token = firstFence(':::writing{subject="Short question"\n\nHello\n:::\n');
expect(token.attributes).toEqual({});
});
it('allows braces inside an attribute value', () => {
const token = firstFence(':::writing{subject="use {x} here"}\n\nHello\n:::\n');
expect(token.attributes.subject).toBe('use {x} here');
});
});