The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
test(M7): CodeBlock-Tests auf die registrierten Grammatiken erweitert
David705102c66a39
diff --git a/src/components/chat/__tests__/CodeBlock.test.ts b/src/components/chat/__tests__/CodeBlock.test.tsindex 1d88e652..e3f9229c 100644--- a/src/components/chat/__tests__/CodeBlock.test.ts+++ b/src/components/chat/__tests__/CodeBlock.test.ts@@ -9,7 +9,12 @@* Run: npx vitest run src/components/chat/__tests__/CodeBlock.test.ts*/import { describe, it, expect } from 'vitest'-import { isHtmlSnippet } from '../CodeBlock'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { refractor } from 'refractor/core'+import { isHtmlSnippet, highlightLanguageFor, PRISM_LANGUAGES } from '../CodeBlock'++const source = readFileSync(resolve(__dirname, '..', 'CodeBlock.tsx'), 'utf8')describe('isHtmlSnippet', () => {describe('by language tag (fenced code block lang)', () => {@@ -90,3 +95,118 @@ describe('isHtmlSnippet', () => {})})})++// ── M7 · the boot chunk is not 22 % syntax highlighting ─────────────────────++describe('only the grammars this app can actually show are bundled', () => {+ it('imports the PrismLight engine, never the full-Prism barrel', () => {+ // `react-syntax-highlighter`'s `Prism` export drags refractor's ~300+ // grammars into the boot chunk. This is the whole finding.+ expect(source).toContain("react-syntax-highlighter/dist/esm/prism-light")+ expect(source).not.toMatch(/from 'react-syntax-highlighter'/)+ expect(source).not.toMatch(/dist\/esm\/prism'/)+ })++ it('takes the one theme by its deep path, not the 46-theme barrel', () => {+ expect(source).toContain('styles/prism/one-dark')+ expect(source).not.toMatch(/styles\/prism'/)+ })++ it('registers what an LLM chat and the file preview actually emit', () => {+ // The audit's list, plus everything lib/file-preview.ts's LANGUAGE map can+ // hand us — a preview that quietly lost its colours would be a regression+ // dressed up as a saving.+ for (const lang of [+ 'typescript', 'tsx', 'javascript', 'jsx', 'python', 'rust', 'bash',+ 'json', 'yaml', 'sql', 'go', 'java', 'c', 'cpp', 'csharp', 'php',+ 'ruby', 'markup', 'css', 'markdown', 'diff', 'toml', 'docker',+ 'scss', 'less', 'ini', 'kotlin', 'swift', 'powershell', 'batch',+ 'graphql', 'lua', 'r', 'dart', 'hcl', 'groovy', 'makefile',+ ]) {+ expect(highlightLanguageFor(lang), lang).toBe(lang)+ }+ })++ it('the declared language set is exactly what refractor really knows', () => {+ // Drift guard. PRISM_LANGUAGES is hand-written so production code does not+ // have to import refractor; importing CodeBlock above ran the+ // registrations, so refractor can be asked what actually happened.+ const real = refractor.listLanguages()+ // Nothing claimed that is not registered…+ expect([...PRISM_LANGUAGES].filter((n) => !real.includes(n))).toEqual([])+ // …and nothing registered that is not claimed, except refractor's built-in+ // plain-text family, which is left out on purpose so it normalises to the+ // highlighter's no-grammar branch.+ expect(real.filter((n) => !PRISM_LANGUAGES.has(n)).sort())+ .toEqual(['plain', 'plaintext', 'text', 'txt'])+ })++ it('stays far below the full-Prism grammar count', () => {+ // The full build answers to ~300 names. If this ever climbs back there,+ // somebody re-imported the barrel.+ expect(refractor.listLanguages().length).toBeLessThan(100)+ })+})++describe('an unknown fence renders as plain text instead of throwing', () => {+ it('a language nobody registered falls back to text', () => {+ // refractor throws "Unknown language" for anything unregistered. The+ // highlighter does catch that, but a chat that renders is not something to+ // leave to a library's catch block.+ expect(highlightLanguageFor('brainfuck')).toBe('text')+ expect(highlightLanguageFor('cobol')).toBe('text')+ expect(() => refractor.highlight('x', 'brainfuck')).toThrow()+ })++ it('no fence tag at all is text', () => {+ expect(highlightLanguageFor(undefined)).toBe('text')+ expect(highlightLanguageFor('')).toBe('text')+ expect(highlightLanguageFor(' ')).toBe('text')+ })++ it('every spelling of "no language" collapses to text', () => {+ expect(highlightLanguageFor('text')).toBe('text')+ expect(highlightLanguageFor('txt')).toBe('text')+ expect(highlightLanguageFor('plain')).toBe('text')+ expect(highlightLanguageFor('plaintext')).toBe('text')+ })++ it('the tags models really write map onto a registered grammar', () => {+ expect(highlightLanguageFor('sh')).toBe('sh')+ expect(highlightLanguageFor('shell')).toBe('shell')+ expect(highlightLanguageFor('zsh')).toBe('bash')+ expect(highlightLanguageFor('console')).toBe('bash')+ expect(highlightLanguageFor('py')).toBe('py')+ expect(highlightLanguageFor('ts')).toBe('ts')+ expect(highlightLanguageFor('rs')).toBe('rust')+ expect(highlightLanguageFor('golang')).toBe('go')+ expect(highlightLanguageFor('c++')).toBe('cpp')+ expect(highlightLanguageFor('c#')).toBe('csharp')+ expect(highlightLanguageFor('html')).toBe('html')+ expect(highlightLanguageFor('htm')).toBe('markup')+ expect(highlightLanguageFor('terraform')).toBe('hcl')+ expect(highlightLanguageFor('jsonc')).toBe('json')+ })++ it('is case- and whitespace-insensitive, the way fences are written', () => {+ expect(highlightLanguageFor('Python')).toBe('python')+ expect(highlightLanguageFor(' TSX ')).toBe('tsx')+ expect(highlightLanguageFor('Dockerfile')).toBe('dockerfile')+ })++ it('every registered name really highlights', () => {+ // The point of the fallback is that highlightLanguageFor never hands the+ // highlighter something refractor will reject.+ for (const name of PRISM_LANGUAGES) {+ if (name === 'text') continue+ expect(() => refractor.highlight('x = 1', name), name).not.toThrow()+ }+ })++ it('the header still shows the RAW tag, only the highlighter is normalised', () => {+ // `{language || 'code'}` in the header, highlightLanguageFor on the+ // highlighter — otherwise an unknown fence would silently be relabelled.+ expect(source).toContain("{language || 'code'}")+ expect(source).toContain('language={highlightLanguageFor(language)}')+ })+})