Skip to content

Commit 4f57c65

Browse files
committed
Merge browser math and provenance test fixes into Rust 2024 candidate
2 parents 7777479 + da5f7f7 commit 4f57c65

3 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎docs/website/src/styles/details.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
.typst-detail h3 { margin: 24px 0 10px; font-size: 17px; font-weight: 600; }
44
.typst-detail p { margin: 10px 0; }
55
.typst-detail svg { max-width: 100%; filter: invert(.9); }
6+
/* Direct glyph colors avoid WebKit rasterizing small filtered math into blocks. */
7+
.typst-detail .typst-math > svg { filter: none; }
8+
.typst-detail .typst-math [fill="#000000"] { fill: var(--ink); }
9+
.typst-detail .typst-math [stroke="#000000"] { stroke: var(--ink); }
610
.typst-math > svg { display: inline-block !important; vertical-align: baseline; }
711
div.typst-math { overflow-x: auto; margin: 14px 0; }
812
.typst-detail figure { margin: 20px 0; }

‎scripts/test_website.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,45 @@ def test_graph_growth_labels_are_conservative_for_exact_signed_formulas(self):
190190
expect(self.page.locator('.path')).to_have_count(2)
191191
expect(self.page.get_by_role('button', name='Hide other routes', exact=True)).to_be_visible()
192192

193+
def test_typst_math_keeps_vector_glyphs_and_colors_in_both_themes(self):
194+
self.visit('problem/KSatisfiability?variant=k=K3')
195+
expect(self.page.locator('article.typst-detail')).to_be_visible()
196+
formula = self.page.locator('.typst-math > svg').filter(has=self.page.locator('g + g use')).first
197+
expect(formula).to_be_visible()
198+
self.page.evaluate('document.fonts.ready')
199+
# Include an intentional color and a fraction-like stroke alongside the real Typst glyphs.
200+
formula.locator('use').first.evaluate("node => node.setAttribute('fill', '#e15759')")
201+
formula.evaluate('''svg => {
202+
const line = document.createElementNS('http://www.w3.org/2000/svg', 'path');
203+
line.setAttribute('d', 'M0 .1H4'); line.setAttribute('stroke', '#000000');
204+
line.setAttribute('stroke-width', '.1'); svg.append(line);
205+
}''')
206+
for theme, ink, paper in [('dark', '#eef3e9', '#0b110d'), ('light', '#112011', '#ffffff')]:
207+
with self.subTest(theme=theme):
208+
self.page.evaluate('''({ink, paper}) => {
209+
document.documentElement.style.setProperty('--ink', ink);
210+
document.documentElement.style.setProperty('--paper', paper);
211+
}''', {'ink': ink, 'paper': paper})
212+
expect(formula.locator('use').first).to_have_css('fill', 'rgb(225, 87, 89)')
213+
actual = formula.screenshot()
214+
# Reference the same vectors with explicit theme paint and no rasterizing filter.
215+
saved = formula.evaluate('''(svg, ink) => {
216+
const painted = [...svg.querySelectorAll('[fill="#000000"], [stroke="#000000"]')];
217+
const saved = [svg.getAttribute('style'), painted.map(node => node.getAttribute('style'))];
218+
svg.style.filter = 'none';
219+
for (const node of painted) {
220+
if (node.getAttribute('fill') === '#000000') node.style.fill = ink;
221+
if (node.getAttribute('stroke') === '#000000') node.style.stroke = ink;
222+
}
223+
return saved;
224+
}''', ink)
225+
self.assertEqual(actual, formula.screenshot(), 'Theme styling changed the rendered math vectors')
226+
formula.evaluate('''(svg, [style, paints]) => {
227+
const restore = (node, value) => value === null ? node.removeAttribute('style') : node.setAttribute('style', value);
228+
restore(svg, style);
229+
[...svg.querySelectorAll('[fill="#000000"], [stroke="#000000"]')].forEach((node, i) => restore(node, paints[i]));
230+
}''', saved)
231+
193232
def test_accessibility_atlas(self):
194233
self.visit('atlas')
195234
expect(self.page.locator('.atlas-row').first).to_be_visible()

‎scripts/test_website_verification.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import tempfile
1414
import unittest
15+
from unittest.mock import patch
1516
from urllib.request import build_opener, ProxyHandler
1617
from urllib.parse import urlsplit
1718

@@ -74,7 +75,13 @@ def test_canceled_asset_request_does_not_print_a_server_traceback(self):
7475
def test_verification_only_report_does_not_claim_the_artifact_build_source(self):
7576
with tempfile.TemporaryDirectory() as directory:
7677
site = Path(directory)
77-
with self.assertRaises(FileNotFoundError):
78+
# This case checks failed-artifact provenance; the full verifier exercises these tools.
79+
run = subprocess.run
80+
def skip_tool_checks(command, **kwargs):
81+
if command[:2] in [["cargo", "test"], ["npm", "run"]]:
82+
return subprocess.CompletedProcess(command, 0)
83+
return run(command, **kwargs)
84+
with patch("check_website.subprocess.run", side_effect=skip_tool_checks), self.assertRaises(FileNotFoundError):
7885
check_website.check(site, build=False, open_questions=None)
7986
report = json.loads((site / "verification.json").read_text())
8087
self.assertEqual(report["verification"]["status"], "failed")

0 commit comments

Comments
 (0)