Spaces:
Running
Running
File size: 2,607 Bytes
21ad36a 36a170e b4f163f 21ad36a 897170b 21ad36a 897170b 21ad36a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import { describe, expect, it } from 'vitest';
import { HTML_ARTIFACT_MIN_TOKENS, planClientTools, requestsHtmlArtifact } from './tool-routing';
describe('HTML artifact intent routing', () => {
it.each([
'Create an HTML app for tracking expenses',
'Write HTML and CSS for a compact dashboard',
'Build a web page with a pricing table',
'Напиши HTML-приложение для списка задач',
'Сделай веб-приложение с красивым календарём',
'Сверстай лендинг для кофейни',
])('recognizes an explicit creation request: %s', (prompt) => {
expect(requestsHtmlArtifact(prompt)).toBe(true);
});
it.each([
'Explain what an HTML application is',
'Review this HTML for accessibility',
'Что такое веб-приложение?',
'Напиши кратко о стандарте HTML',
'Сделай вычисление 2 + 2',
])('does not force an artifact for discussion or unrelated work: %s', (prompt) => {
expect(requestsHtmlArtifact(prompt)).toBe(false);
});
it('requires only html_artifact on the first matching round', () => {
const plan = planClientTools('Напиши HTML-приложение для заметок', true, 0);
expect(plan.toolChoice).toBe('required');
expect(plan.tools?.map((tool) => tool.function.name)).toEqual(['html_artifact']);
expect(plan.requiredToolName).toBe('html_artifact');
expect(plan.minimumMaxTokens).toBe(HTML_ARTIFACT_MIN_TOKENS);
expect(plan.minimumMaxTokens).toBe(4_096);
expect(plan.systemInstruction).toContain('compact enough to finish');
expect(plan.systemInstruction).toContain('Do not answer with a Markdown code block');
expect(plan.systemInstruction).toContain('artifact_update');
expect(plan.systemInstruction).toContain('until it passes');
});
it('returns control to the model with repair tools after the artifact result', () => {
const plan = planClientTools('Create an HTML app', true, 1);
expect(plan.toolChoice).toBe('auto');
expect(plan.minimumMaxTokens).toBe(0);
expect(plan.tools?.map((tool) => tool.function.name)).toEqual(expect.arrayContaining([
'artifact_update',
'artifact_test',
'artifact_inspect',
]));
});
it('keeps ordinary tool use on auto and honors the off switch', () => {
expect(planClientTools('Calculate 17 * 9', true, 0).toolChoice).toBe('auto');
expect(planClientTools('Create an HTML app', false, 0)).toEqual({
toolChoice: 'none',
minimumMaxTokens: 0,
});
});
});
|