Files
solvecraft/tests/tools/test_icon_export.py
jyviko 312454f899 Look: SolidCraft's icons, glyphs, UI fonts and themes as the shared crate solidcraft-look (follows #14251) (#14578)
* UI kit: an icon set can extend another host's masters with a host's own

IconSet::extended(data, extension) draws another host's IconData (the same
static tables, not a copy) with an IconExtension of the host's own masters,
aliases and default accents, in the data's colour roles and accents. For a
name both have the extension's master, alias or default accent wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

* Look: SolidCraft's icons, glyphs, UI fonts and built-in themes are the shared crate solidcraft-look

The icon masters and their build step, the code-drawn glyph painters, the UI fonts and the
built-in themes move into crates/look with history. SolidCraft's app installs its look from
the crate, as another app can. The workspace tab table stays the app's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

* Look: the end-cap icons' attribution rows and the style guide's path follow the move

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

* Licence: SolidCraft's brand and interface are under LICENSE-BRAND

The UI kit, the look (interface icons, glyphs, built-in themes), the theme's tokens and palettes,
and the SolidCraft name, logo, app icon and brand kit are SolidCraft's brand. They may be used,
changed and contributed to as part of SolidCraft; using them in another program or product needs
the maintainers' written permission. Geometry and the rest of the code stay MIT OR Apache-2.0,
and third-party fonts keep their own licences.

The three crates declare the licence with `license-file`, which `xtask shared` now accepts when
the file sits inside the crate; the generated licence list names it; ATTRIBUTION rows for the
look's artwork and the branding name it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M2MmcDrkcWhQeHS2K8

---------

Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 09:06:00 -05:00

145 lines
8.0 KiB
Python

"""Exercise the real HTTP export endpoint without touching the working review or queue."""
import json
import csv
import pathlib
import shutil
import socket
import subprocess
import sys
import tempfile
import time
import unittest
import urllib.error
import urllib.request
class IconExportTest(unittest.TestCase):
def test_inventory_includes_nested_and_helper_icon_uses(self):
source = pathlib.Path(__file__).resolve().parents[2] / 'crates/look/icons/design/tools'
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
design = root / 'crates/look/icons/design'
tools = design / 'tools'
tools.mkdir(parents=True)
for name in ('icon_status.py', 'review_state.py', 'icon_palette.py'):
shutil.copy(source / name, tools / name)
shutil.copytree(source / 'review', tools / 'review')
(design / 'palette.toml').write_text('[roles.line]\nlight="#000000"\ndark="#ffffff"\n', encoding='utf-8')
for name in ('aliases.toml',):
(design / name).write_text('', encoding='utf-8')
svg = design / 'svg/model'
svg.mkdir(parents=True)
for name in ('agent_chat', 'pattern_flip', 'normal', 'infinite', 'trace'):
(svg / (name + '.svg')).write_text('<svg viewBox="0 0 64 64"></svg>', encoding='utf-8')
ui = root / 'crates/ui-egui/src'
(ui / 'agent_chat').mkdir(parents=True)
(ui / 'agent_chat/panel.rs').write_text('icons::paint(p, r, "agent_chat", ink, fill, a);', encoding='utf-8')
(ui / 'dialogs.rs').write_text('pattern_toggle(ui, alignment_label, "Flip direction", "pattern_flip", reversed);', encoding='utf-8')
(ui / 'sketch_palette.rs').write_text('''
for (i, (label, icon, tip)) in [
("—", "normal", "Normal"),
("↔", "infinite", "Infinite"),
].iter().enumerate() { icons::paint(p, r, icon, ink, fill, a); }
''', encoding='utf-8')
engine = root / 'crates/engine/src/cmd'
engine.mkdir(parents=True)
# A long builder must not lose its icon after the first fourteen lines.
(engine / 'motion.rs').write_text('CommandSpec::new("motion.trace", "Trace", trace)\n'
+ '\n' * 16 + '.icon("trace").params("doc");', encoding='utf-8')
subprocess.run([sys.executable, '-B', str(tools / 'icon_status.py'), '--csv'],
check=True, capture_output=True, text=True)
with open(root / 'target/icon-inventory.csv', encoding='utf-8') as f:
rows = {r['icon']: r for r in csv.DictReader(f)}
self.assertEqual(set(rows), {'agent_chat', 'pattern_flip', 'normal', 'infinite', 'trace'})
self.assertIn('agent_chat/panel.rs', rows['agent_chat']['used_by_ui'])
self.assertIn('dialogs.rs', rows['pattern_flip']['used_by_ui'])
for name in ('normal', 'infinite'):
self.assertIn('sketch_palette.rs', rows[name]['used_by_ui'])
self.assertEqual(rows['trace']['example_command'], 'motion.trace')
def test_export_snapshots_only_pending_notes_for_codex(self):
source = pathlib.Path(__file__).resolve().parents[2] / 'crates/look/icons/design/tools'
with tempfile.TemporaryDirectory() as tmp:
root = pathlib.Path(tmp)
design = root / 'crates/look/icons/design'
tools = design / 'tools'
tools.mkdir(parents=True)
for name in ('icon_status.py', 'review_state.py', 'icon_palette.py'):
shutil.copy(source / name, tools / name)
shutil.copytree(source / 'review', tools / 'review')
for name in ('palette.toml', 'aliases.toml'):
(design / name).write_text('', encoding='utf-8')
(design / 'palette.toml').write_text('[roles.line]\nlight="#000000"\ndark="#ffffff"\n', encoding='utf-8')
svg = design / 'svg/model'
svg.mkdir(parents=True)
for name in ('box', 'joint'):
(svg / (name + '.svg')).write_text('<svg viewBox="0 0 64 64"></svg>', encoding='utf-8')
# An accepted icon's note must never be exported, even if it still has text.
original = {'final': {'box': ''}, 'notes': {'box': 'Keep it', 'joint': 'Round the corners\nUse related icons'}}
(design / 'review.json').write_text(json.dumps(original), encoding='utf-8')
with socket.socket() as port_socket:
port_socket.bind(('127.0.0.1', 0))
port = port_socket.getsockname()[1]
proc = subprocess.Popen([sys.executable, str(tools / 'icon_status.py'), '--serve', str(port)],
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
try:
url = 'http://127.0.0.1:%d' % port
# Up to a minute: CI machines can be busy enough that the server starts slowly.
deadline = time.monotonic() + 60
while time.monotonic() < deadline:
try:
with urllib.request.urlopen(url + '/api/review', timeout=1) as response:
base = json.load(response)
break
except urllib.error.URLError:
if proc.poll() is not None:
self.fail(proc.stderr.read().decode())
time.sleep(0.02)
else:
self.fail('review server did not start')
def post(endpoint, state):
data = json.dumps({'base': base, **state}).encode()
with urllib.request.urlopen(urllib.request.Request(url + endpoint, data=data), timeout=2) as response:
return json.load(response)
state = {'final': base['final'], 'notes': base['notes']}
inbox = root / 'target/codex-icon-review/inbox'
post('/api/review', state)
self.assertFalse(inbox.exists(), 'autosave must not request redraws')
result = post('/api/export', state)
self.assertTrue(result['ok'])
self.assertEqual(result['sent'], 1)
requests = list(inbox.glob('*.json'))
self.assertEqual(len(requests), 1)
request = json.loads(requests[0].read_text(encoding='utf-8'))
self.assertEqual(request['id'], result['request_id'])
self.assertEqual(request['notes'], {'joint': original['notes']['joint']})
self.assertFalse(list(inbox.glob('*.tmp')))
self.assertFalse((root / 'target/review-requests.log').exists())
with urllib.request.urlopen(url, timeout=2) as response:
page = response.read().decode()
self.assertIn('local review inbox', page)
self.assertNotIn('Claude', page)
self.assertIn('location.reload()', page)
# Existing tabs also reload when the server's page implementation changes.
with open(tools / 'icon_status.py', 'a', encoding='utf-8') as f:
f.write('\n# page update\n')
with urllib.request.urlopen(url + '/api/review', timeout=2) as response:
self.assertNotEqual(json.load(response)['rev'], base['rev'])
# A note resolved on disk cannot be resurrected by an unchanged stale page.
saved = json.loads((design / 'review.json').read_text(encoding='utf-8'))
saved['notes'] = {'box': 'Keep it'}
(design / 'review.json').write_text(json.dumps(saved), encoding='utf-8')
empty = post('/api/export', state)
self.assertEqual(empty['sent'], 0)
self.assertEqual(len(list(inbox.glob('*.json'))), 1)
finally:
proc.terminate()
proc.wait(timeout=5)
proc.stderr.close()
if __name__ == '__main__':
unittest.main()