| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // markdownSVGBenchFixtureSource is the SVG the browser bench feeds to the |
| 6 | // preview. It deliberately omits xmlns: that is how a model usually writes an |
| 7 | // SVG, and it is the case that used to fail, because a namespace-free document |
| 8 | // is not SVG and the browser refuses it as an image. The bench cannot call this sanitizer, so it renders |
| 9 | // markdownSVGBenchFixtureOutput instead; this test is what keeps the two |
| 10 | // honest, because it fails the moment the sanitizer stops producing those |
| 11 | // exact bytes. |
| 12 | const markdownSVGBenchFixtureSource = `<svg viewBox="0 0 10 5"> |
| 13 | <defs><linearGradient id="g"><stop offset="0" stop-color="#f60"/></linearGradient></defs> |
| 14 | <rect width="10" height="5" fill="url(#g)"/> |
| 15 | <text x="1" y="4">preview</text> |
| 16 | </svg>` |
| 17 | |
| 18 | const markdownSVGBenchFixtureOutput = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 5"> |
| 19 | <defs><linearGradient id="g"><stop offset="0" stop-color="#f60"></stop></linearGradient></defs> |
| 20 | <rect width="10" height="5" fill="url(#g)"></rect> |
| 21 | <text x="1" y="4">preview</text> |
| 22 | </svg>` |
| 23 | |
| 24 | func TestMarkdownSVGBenchFixtureMatchesTheSanitizer(t *testing.T) { |
| 25 | view := NewApp().SanitizeMarkdownSVG(markdownSVGBenchFixtureSource) |
| 26 | if !view.OK { |
| 27 | t.Fatalf("the bench fixture is no longer sanitizable: %+v", view) |
| 28 | } |
| 29 | if view.SVG != markdownSVGBenchFixtureOutput { |
| 30 | t.Fatalf("the browser bench renders bytes the sanitizer no longer produces.\n got: %q\nwant: %q\n\nUpdate markdownSVGBenchFixtureOutput in desktop/frontend/bench/chat-file-reference-fixture.tsx to match.", view.SVG, markdownSVGBenchFixtureOutput) |
| 31 | } |
| 32 | } |
| 33 |