Spaces:
Running
Running
| 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'); | |
| }); | |
| it('ends the tool loop after the artifact result', () => { | |
| expect(planClientTools('Create an HTML app', true, 1)).toEqual({ | |
| toolChoice: 'none', | |
| minimumMaxTokens: 0, | |
| }); | |
| }); | |
| 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, | |
| }); | |
| }); | |
| }); | |