CoolFace
Apppublic

inductiveML/monarch-webgpu

sourceHugging Faceapache-2.0updated 9d agoView on Hugging Face
1likes
monarch-markdown.test.tsx28 linesDownload Raw Back to tests
1import {describe, test} from 'node:test';2import assert from 'node:assert/strict';3import {createElement} from 'react';4import {renderToStaticMarkup} from 'react-dom/server';5import MonarchMarkdown from '../src/components/MonarchMarkdown';6 7const render = (text: string) => renderToStaticMarkup(createElement(MonarchMarkdown, {text}));8 9describe('generated response Markdown', () => {10  test('renders prose, JSON fences, GFM tables, and checklists, including partial streams', () => {11    const html = render('## Result\n\n**Ada** uses `Python`.\n\n```json\n{"name":"Ada"}\n```\n\n| Name | Age |\n| --- | --- |\n| Ada | 28 |\n\n- [x] Extracted\n- [ ] Review\n\n> A quoted note.');12    for (const tag of ['<h2>', '<strong>', '<code>', '<pre>', '<table>', '<blockquote>', 'type="checkbox"', 'class="language-json"']) assert.ok(html.includes(tag), tag);13    assert.ok(!html.includes('```'));14    assert.ok(render('```json\n{"name":').includes('class="language-json"'));15    assert.ok(render('[Reference](https://example.com)').includes('rel="noopener noreferrer"'));16  });17 18  test('does not execute model HTML, unsafe links, or fetch model-supplied images', () => {19    const html = render('<script>alert(1)</script>\n\n<img src="https://example.com/tracker" onerror="alert(1)">\n\n[bad](javascript:alert%281%29)\n\n![A diagram](https://example.com/tracker)');20    assert.ok(!html.includes('<script'));21    assert.ok(!html.includes('<img'));22    assert.ok(!html.includes('onerror'));23    assert.ok(!html.includes('javascript:'));24    assert.ok(!html.includes('https://example.com/tracker'));25    assert.ok(html.includes('A diagram'));26  });27});28