@snap/valdi 1.0.8 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
- package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
- package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
- package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
- package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
- package/.bootstrap/apps/ui_application/package.json +24 -0
- package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
- package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
- package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
- package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
- package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
- package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
- package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
- package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
- package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
- package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
- package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
- package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
- package/.metadata/.bazelrc.template +92 -0
- package/.metadata/.bazelversion.template +1 -0
- package/.metadata/.editorconfig.template +37 -0
- package/.metadata/.eslintrc.js.template +27 -0
- package/.metadata/.gitignore.template +4 -0
- package/.metadata/.prettierrc.json.template +7 -0
- package/.metadata/.watchmanconfig.template +8 -0
- package/.metadata/AGENTS.md.template +16 -0
- package/.metadata/MODULE.bazel.template +62 -0
- package/.metadata/README.md.template +31 -0
- package/.metadata/config.yaml.template +1 -0
- package/.metadata/package.json.template +23 -0
- package/.metadata/skill-reference.tsx.template +8 -0
- package/.metadata/skill-tests-BUILD.bazel.template +21 -0
- package/.metadata/skill-tests-README.md.template +17 -0
- package/.metadata/skill.md.template +27 -0
- package/bundled-skills/registry.json +14 -2
- package/bundled-skills/skills/valdi-animations/skill.md +197 -0
- package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
- package/bundled-skills/skills/valdi-bazel/skill.md +21 -2
- package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
- package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
- package/bundled-skills/skills/valdi-custom-view/skill.md +49 -5
- package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
- package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
- package/bundled-skills/skills/valdi-inspect/skill.md +217 -0
- package/bundled-skills/skills/valdi-localization/skill.md +142 -0
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
- package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
- package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
- package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
- package/bundled-skills/skills/valdi-overview/skill.md +7 -4
- package/bundled-skills/skills/valdi-perf/skill.md +223 -0
- package/bundled-skills/skills/valdi-polyglot-module/skill.md +131 -12
- package/bundled-skills/skills/valdi-preview/skill.md +303 -0
- package/bundled-skills/skills/valdi-profile/skill.md +126 -0
- package/bundled-skills/skills/valdi-setup/skill.md +55 -5
- package/bundled-skills/skills/valdi-testing/skill.md +23 -7
- package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
- package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
- package/dist/commands/agentCheck.js +184 -0
- package/dist/commands/analyze.js +16 -0
- package/dist/commands/analyze_commands/duplicates.js +134 -0
- package/dist/commands/bootstrap.js +57 -73
- package/dist/commands/doctor.js +40 -203
- package/dist/commands/hotreload.js +15 -0
- package/dist/commands/inspect.js +16 -0
- package/dist/commands/inspect_commands/contexts.js +55 -0
- package/dist/commands/inspect_commands/devices.js +53 -0
- package/dist/commands/inspect_commands/heap.js +59 -0
- package/dist/commands/inspect_commands/select.js +43 -0
- package/dist/commands/inspect_commands/snapshot.js +129 -0
- package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
- package/dist/commands/inspect_commands/status.js +68 -0
- package/dist/commands/inspect_commands/tree.js +86 -0
- package/dist/commands/preview.js +81 -0
- package/dist/commands/profile.js +16 -0
- package/dist/commands/profile_commands/capture.js +106 -0
- package/dist/commands/projectsync.js +9 -7
- package/dist/commands/skills_commands/install.js +6 -1
- package/dist/commands/skills_commands/update.js +2 -1
- package/dist/core/analyze/clusterer.js +150 -0
- package/dist/core/analyze/fingerprint.js +2 -0
- package/dist/core/analyze/knownPatterns.js +76 -0
- package/dist/core/analyze/parser.js +177 -0
- package/dist/core/analyze/reporter.js +83 -0
- package/dist/core/analyze/scanner.js +172 -0
- package/dist/core/analyze/similarity.js +56 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/packageFiles.spec.js +29 -0
- package/dist/preview/previewGenerator.js +240 -0
- package/dist/preview/previewGenerator.spec.js +203 -0
- package/dist/preview/viewModelParser.js +86 -0
- package/dist/preview/viewModelParser.spec.js +171 -0
- package/dist/setup/DevSetupHelper.js +0 -51
- package/dist/setup/linuxSetup.js +0 -2
- package/dist/setup/macOSSetup.js +1 -4
- package/dist/utils/BazelClient.js +15 -0
- package/dist/utils/daemonClient.js +344 -0
- package/dist/utils/hermesClient.js +252 -0
- package/dist/utils/skillsAdapters.js +86 -5
- package/dist/utils/skillsAdapters.spec.js +60 -0
- package/dist/utils/skillsRegistry.js +8 -0
- package/dist/utils/stringUtils.spec.js +1 -1
- package/package.json +30 -12
- package/dist/setup/versions.js +0 -8
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Tests for extract_colors.py — color extraction logic."""
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
|
|
9
|
+
# Add the script directory to path
|
|
10
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
11
|
+
from extract_colors import (
|
|
12
|
+
dominant_color_kmeans,
|
|
13
|
+
sample_point,
|
|
14
|
+
extract_region,
|
|
15
|
+
auto_detect_thumbnails,
|
|
16
|
+
auto_detect_colored_regions,
|
|
17
|
+
_resolve_macos_path,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from PIL import Image
|
|
22
|
+
except ImportError:
|
|
23
|
+
print("Pillow required for tests: pip3 install Pillow", file=sys.stderr)
|
|
24
|
+
sys.exit(1)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TestDominantColorKmeans(unittest.TestCase):
|
|
28
|
+
def test_empty_pixels(self):
|
|
29
|
+
self.assertEqual(dominant_color_kmeans([]), '#000000')
|
|
30
|
+
|
|
31
|
+
def test_single_pixel(self):
|
|
32
|
+
result = dominant_color_kmeans([(255, 0, 0)])
|
|
33
|
+
self.assertEqual(result, '#FF0000')
|
|
34
|
+
|
|
35
|
+
def test_two_pixels(self):
|
|
36
|
+
# With < k pixels, averages them
|
|
37
|
+
result = dominant_color_kmeans([(255, 0, 0), (255, 0, 0)])
|
|
38
|
+
self.assertEqual(result, '#FF0000')
|
|
39
|
+
|
|
40
|
+
def test_uniform_color(self):
|
|
41
|
+
pixels = [(100, 50, 200)] * 100
|
|
42
|
+
result = dominant_color_kmeans(pixels)
|
|
43
|
+
self.assertEqual(result, '#6432C8')
|
|
44
|
+
|
|
45
|
+
def test_prefers_saturated_over_white(self):
|
|
46
|
+
# Mix of white (background) and red (content)
|
|
47
|
+
pixels = [(255, 255, 255)] * 80 + [(200, 30, 30)] * 20
|
|
48
|
+
result = dominant_color_kmeans(pixels)
|
|
49
|
+
# Should pick the red cluster, not white (which gets penalized)
|
|
50
|
+
r = int(result[1:3], 16)
|
|
51
|
+
g = int(result[3:5], 16)
|
|
52
|
+
b = int(result[5:7], 16)
|
|
53
|
+
self.assertGreater(r, g) # Red-ish
|
|
54
|
+
self.assertGreater(r, b)
|
|
55
|
+
|
|
56
|
+
def test_prefers_larger_cluster(self):
|
|
57
|
+
# Large blue cluster vs small green cluster
|
|
58
|
+
pixels = [(30, 30, 200)] * 90 + [(30, 200, 30)] * 10
|
|
59
|
+
result = dominant_color_kmeans(pixels)
|
|
60
|
+
b = int(result[5:7], 16)
|
|
61
|
+
g = int(result[3:5], 16)
|
|
62
|
+
self.assertGreater(b, g) # Should be blue-ish
|
|
63
|
+
|
|
64
|
+
def test_penalizes_near_black(self):
|
|
65
|
+
pixels = [(5, 5, 5)] * 80 + [(100, 50, 200)] * 20
|
|
66
|
+
result = dominant_color_kmeans(pixels)
|
|
67
|
+
# The purple should win despite fewer pixels
|
|
68
|
+
r = int(result[1:3], 16)
|
|
69
|
+
self.assertGreater(r, 20) # Not near-black
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class TestSamplePoint(unittest.TestCase):
|
|
73
|
+
def test_center_pixel_of_solid_image(self):
|
|
74
|
+
img = Image.new('RGB', (20, 20), (128, 64, 32))
|
|
75
|
+
result = sample_point(img, 10, 10)
|
|
76
|
+
self.assertEqual(result, '#804020')
|
|
77
|
+
|
|
78
|
+
def test_edge_pixel_clamped(self):
|
|
79
|
+
img = Image.new('RGB', (10, 10), (255, 0, 0))
|
|
80
|
+
# Sampling at (0, 0) with radius=3 should clamp and not crash
|
|
81
|
+
result = sample_point(img, 0, 0, radius=3)
|
|
82
|
+
self.assertEqual(result, '#FF0000')
|
|
83
|
+
|
|
84
|
+
def test_sample_returns_median(self):
|
|
85
|
+
# Create an image with a gradient-like pattern
|
|
86
|
+
img = Image.new('RGB', (20, 20), (100, 100, 100))
|
|
87
|
+
# Put a bright pixel in the center
|
|
88
|
+
img.putpixel((10, 10), (255, 255, 255))
|
|
89
|
+
result = sample_point(img, 10, 10, radius=3)
|
|
90
|
+
# Median of mostly gray + one white should still be gray
|
|
91
|
+
r = int(result[1:3], 16)
|
|
92
|
+
self.assertLess(r, 200) # Not the outlier white
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class TestExtractRegion(unittest.TestCase):
|
|
96
|
+
def test_solid_region(self):
|
|
97
|
+
img = Image.new('RGB', (100, 100), (0, 128, 255))
|
|
98
|
+
result = extract_region(img, 10, 10, 20, 20)
|
|
99
|
+
self.assertEqual(result, '#0080FF')
|
|
100
|
+
|
|
101
|
+
def test_region_clamps_to_image_bounds(self):
|
|
102
|
+
img = Image.new('RGB', (50, 50), (255, 0, 0))
|
|
103
|
+
# Region extends beyond image — should not crash
|
|
104
|
+
result = extract_region(img, 40, 40, 20, 20)
|
|
105
|
+
self.assertEqual(result, '#FF0000')
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class TestAutoDetectThumbnails(unittest.TestCase):
|
|
109
|
+
def test_detects_dark_block_in_left_column(self):
|
|
110
|
+
# White image with a dark square in the left column
|
|
111
|
+
img = Image.new('RGB', (400, 400), (255, 255, 255))
|
|
112
|
+
# Draw a dark block at x=30-70, y=50-100 (in the left 11% scan zone)
|
|
113
|
+
for y in range(50, 100):
|
|
114
|
+
for x in range(30, 70):
|
|
115
|
+
img.putpixel((x, y), (50, 50, 50))
|
|
116
|
+
results = auto_detect_thumbnails(img)
|
|
117
|
+
self.assertGreater(len(results), 0)
|
|
118
|
+
name, x, y, w, h = results[0]
|
|
119
|
+
self.assertGreaterEqual(y, 40)
|
|
120
|
+
self.assertLessEqual(y + h, 110)
|
|
121
|
+
|
|
122
|
+
def test_no_thumbnails_on_white_image(self):
|
|
123
|
+
img = Image.new('RGB', (400, 400), (255, 255, 255))
|
|
124
|
+
results = auto_detect_thumbnails(img)
|
|
125
|
+
self.assertEqual(len(results), 0)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class TestAutoDetectColoredRegions(unittest.TestCase):
|
|
129
|
+
def test_detects_saturated_region(self):
|
|
130
|
+
# White image with a small bright blue rectangle
|
|
131
|
+
img = Image.new('RGB', (200, 200), (255, 255, 255))
|
|
132
|
+
for y in range(50, 70):
|
|
133
|
+
for x in range(100, 140):
|
|
134
|
+
img.putpixel((x, y), (0, 100, 255))
|
|
135
|
+
results = auto_detect_colored_regions(img)
|
|
136
|
+
self.assertGreater(len(results), 0)
|
|
137
|
+
|
|
138
|
+
def test_no_colored_regions_on_white_image(self):
|
|
139
|
+
img = Image.new('RGB', (200, 200), (255, 255, 255))
|
|
140
|
+
results = auto_detect_colored_regions(img)
|
|
141
|
+
self.assertEqual(len(results), 0)
|
|
142
|
+
|
|
143
|
+
def test_ignores_near_white_and_near_black(self):
|
|
144
|
+
# Image with only near-white and near-black — no saturated pixels
|
|
145
|
+
img = Image.new('RGB', (200, 200), (250, 250, 250))
|
|
146
|
+
for y in range(50, 100):
|
|
147
|
+
for x in range(50, 100):
|
|
148
|
+
img.putpixel((x, y), (10, 10, 10))
|
|
149
|
+
results = auto_detect_colored_regions(img)
|
|
150
|
+
self.assertEqual(len(results), 0)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class TestResolveMacosPath(unittest.TestCase):
|
|
154
|
+
def test_existing_path_unchanged(self):
|
|
155
|
+
with tempfile.NamedTemporaryFile(delete=False) as f:
|
|
156
|
+
result = _resolve_macos_path(f.name)
|
|
157
|
+
self.assertEqual(result, f.name)
|
|
158
|
+
os.unlink(f.name)
|
|
159
|
+
|
|
160
|
+
def test_nonexistent_path_returned_as_is(self):
|
|
161
|
+
path = '/tmp/nonexistent_test_file_12345.png'
|
|
162
|
+
result = _resolve_macos_path(path)
|
|
163
|
+
self.assertEqual(result, path)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
if __name__ == '__main__':
|
|
167
|
+
unittest.main()
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Tests for find_icon.py — fuzzy icon matching logic."""
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
|
|
9
|
+
# Add the script directory to path
|
|
10
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
11
|
+
from find_icon import split_camel_case, expand_query, score_icon, parse_icons, find_icons
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestSplitCamelCase(unittest.TestCase):
|
|
15
|
+
def test_simple_camel_case(self):
|
|
16
|
+
self.assertEqual(split_camel_case('chatBubbleFill'), ['chat', 'bubble', 'fill'])
|
|
17
|
+
|
|
18
|
+
def test_multi_word(self):
|
|
19
|
+
self.assertEqual(split_camel_case('arrowRightShareFill'), ['arrow', 'right', 'share', 'fill'])
|
|
20
|
+
|
|
21
|
+
def test_single_word(self):
|
|
22
|
+
self.assertEqual(split_camel_case('camera'), ['camera'])
|
|
23
|
+
|
|
24
|
+
def test_consecutive_capitals(self):
|
|
25
|
+
# 'SC' treated as one segment
|
|
26
|
+
parts = split_camel_case('SCMyModule')
|
|
27
|
+
self.assertEqual(parts[0], 'sc')
|
|
28
|
+
|
|
29
|
+
def test_fill_suffix(self):
|
|
30
|
+
parts = split_camel_case('gearFill')
|
|
31
|
+
self.assertEqual(parts, ['gear', 'fill'])
|
|
32
|
+
|
|
33
|
+
def test_xmark(self):
|
|
34
|
+
parts = split_camel_case('xmarkFill')
|
|
35
|
+
self.assertEqual(parts, ['xmark', 'fill'])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TestExpandQuery(unittest.TestCase):
|
|
39
|
+
def test_known_synonym(self):
|
|
40
|
+
result = expand_query(['settings'])
|
|
41
|
+
self.assertIn('gear', result)
|
|
42
|
+
self.assertIn('settings', result)
|
|
43
|
+
|
|
44
|
+
def test_no_synonym(self):
|
|
45
|
+
result = expand_query(['chat'])
|
|
46
|
+
self.assertEqual(result, ['chat'])
|
|
47
|
+
|
|
48
|
+
def test_multiple_synonyms(self):
|
|
49
|
+
result = expand_query(['search'])
|
|
50
|
+
self.assertIn('magnifying', result)
|
|
51
|
+
self.assertIn('glass', result)
|
|
52
|
+
|
|
53
|
+
def test_mixed_known_unknown(self):
|
|
54
|
+
result = expand_query(['send', 'big'])
|
|
55
|
+
self.assertIn('send', result)
|
|
56
|
+
self.assertIn('big', result)
|
|
57
|
+
self.assertIn('arrow', result)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class TestScoreIcon(unittest.TestCase):
|
|
61
|
+
def test_exact_match_scores_high(self):
|
|
62
|
+
icon_words = ['chat', 'bubble', 'fill']
|
|
63
|
+
query_words = ['chat', 'bubble']
|
|
64
|
+
expanded = expand_query(query_words)
|
|
65
|
+
score = score_icon(icon_words, query_words, expanded)
|
|
66
|
+
self.assertGreater(score, 0)
|
|
67
|
+
|
|
68
|
+
def test_no_match_scores_zero(self):
|
|
69
|
+
icon_words = ['gear', 'fill']
|
|
70
|
+
query_words = ['chat', 'bubble']
|
|
71
|
+
expanded = expand_query(query_words)
|
|
72
|
+
score = score_icon(icon_words, query_words, expanded)
|
|
73
|
+
self.assertEqual(score, 0.0)
|
|
74
|
+
|
|
75
|
+
def test_synonym_match(self):
|
|
76
|
+
icon_words = ['gear', 'fill']
|
|
77
|
+
query_words = ['settings']
|
|
78
|
+
expanded = expand_query(query_words)
|
|
79
|
+
score = score_icon(icon_words, query_words, expanded)
|
|
80
|
+
self.assertGreater(score, 0)
|
|
81
|
+
|
|
82
|
+
def test_fill_variant_boosted(self):
|
|
83
|
+
fill_words = ['chat', 'bubble', 'fill']
|
|
84
|
+
stroke_words = ['chat', 'bubble', 'stroke']
|
|
85
|
+
query_words = ['chat', 'bubble']
|
|
86
|
+
expanded = expand_query(query_words)
|
|
87
|
+
fill_score = score_icon(fill_words, query_words, expanded)
|
|
88
|
+
stroke_score = score_icon(stroke_words, query_words, expanded)
|
|
89
|
+
self.assertGreater(fill_score, stroke_score)
|
|
90
|
+
|
|
91
|
+
def test_empty_query_scores_zero(self):
|
|
92
|
+
icon_words = ['chat', 'bubble']
|
|
93
|
+
score = score_icon(icon_words, [], [])
|
|
94
|
+
self.assertEqual(score, 0.0)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class TestParseIcons(unittest.TestCase):
|
|
98
|
+
def test_parses_static_getters(self):
|
|
99
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.tsx', delete=False) as f:
|
|
100
|
+
f.write("""
|
|
101
|
+
export class SIGIcon {
|
|
102
|
+
static get chatBubbleFill(): Asset { return Asset.fromModule('sig_chat_bubble_fill'); }
|
|
103
|
+
static get gearFill(): Asset { return Asset.fromModule('sig_gear_fill'); }
|
|
104
|
+
static get bellStroke(): Asset { return Asset.fromModule('sig_bell_stroke'); }
|
|
105
|
+
}
|
|
106
|
+
""")
|
|
107
|
+
f.flush()
|
|
108
|
+
icons = parse_icons(f.name)
|
|
109
|
+
os.unlink(f.name)
|
|
110
|
+
self.assertEqual(icons, ['chatBubbleFill', 'gearFill', 'bellStroke'])
|
|
111
|
+
|
|
112
|
+
def test_empty_file(self):
|
|
113
|
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.tsx', delete=False) as f:
|
|
114
|
+
f.write("// empty\n")
|
|
115
|
+
f.flush()
|
|
116
|
+
icons = parse_icons(f.name)
|
|
117
|
+
os.unlink(f.name)
|
|
118
|
+
self.assertEqual(icons, [])
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class TestFindIcons(unittest.TestCase):
|
|
122
|
+
def setUp(self):
|
|
123
|
+
self.icons_file = tempfile.NamedTemporaryFile(mode='w', suffix='.tsx', delete=False)
|
|
124
|
+
self.icons_file.write("""
|
|
125
|
+
export class SIGIcon {
|
|
126
|
+
static get chatBubbleFill(): Asset { return Asset.fromModule('a'); }
|
|
127
|
+
static get chatBubbleStroke(): Asset { return Asset.fromModule('b'); }
|
|
128
|
+
static get gearFill(): Asset { return Asset.fromModule('c'); }
|
|
129
|
+
static get gearStroke(): Asset { return Asset.fromModule('d'); }
|
|
130
|
+
static get bellFill(): Asset { return Asset.fromModule('e'); }
|
|
131
|
+
static get arrowRightFill(): Asset { return Asset.fromModule('f'); }
|
|
132
|
+
static get mapPinFill(): Asset { return Asset.fromModule('g'); }
|
|
133
|
+
static get personFill(): Asset { return Asset.fromModule('h'); }
|
|
134
|
+
static get magnifyingGlassFill(): Asset { return Asset.fromModule('i'); }
|
|
135
|
+
static get threeDotHorizontalFill(): Asset { return Asset.fromModule('j'); }
|
|
136
|
+
}
|
|
137
|
+
""")
|
|
138
|
+
self.icons_file.flush()
|
|
139
|
+
|
|
140
|
+
def tearDown(self):
|
|
141
|
+
os.unlink(self.icons_file.name)
|
|
142
|
+
|
|
143
|
+
def test_direct_match(self):
|
|
144
|
+
results = find_icons('chat bubble', self.icons_file.name)
|
|
145
|
+
self.assertTrue(len(results) > 0)
|
|
146
|
+
# chatBubbleFill should be the top result
|
|
147
|
+
self.assertEqual(results[0][0], 'chatBubbleFill')
|
|
148
|
+
|
|
149
|
+
def test_synonym_match(self):
|
|
150
|
+
results = find_icons('settings', self.icons_file.name)
|
|
151
|
+
self.assertTrue(len(results) > 0)
|
|
152
|
+
top_names = [r[0] for r in results]
|
|
153
|
+
self.assertTrue(any('gear' in name.lower() for name in top_names))
|
|
154
|
+
|
|
155
|
+
def test_notification_synonym(self):
|
|
156
|
+
results = find_icons('notification', self.icons_file.name)
|
|
157
|
+
self.assertTrue(len(results) > 0)
|
|
158
|
+
top_names = [r[0] for r in results]
|
|
159
|
+
self.assertIn('bellFill', top_names)
|
|
160
|
+
|
|
161
|
+
def test_search_synonym(self):
|
|
162
|
+
results = find_icons('search', self.icons_file.name)
|
|
163
|
+
self.assertTrue(len(results) > 0)
|
|
164
|
+
self.assertEqual(results[0][0], 'magnifyingGlassFill')
|
|
165
|
+
|
|
166
|
+
def test_no_match(self):
|
|
167
|
+
results = find_icons('xyznonexistent', self.icons_file.name)
|
|
168
|
+
self.assertEqual(len(results), 0)
|
|
169
|
+
|
|
170
|
+
def test_top_n_limiting(self):
|
|
171
|
+
results = find_icons('fill', self.icons_file.name, top_n=3)
|
|
172
|
+
self.assertTrue(len(results) <= 3)
|
|
173
|
+
|
|
174
|
+
def test_profile_synonym(self):
|
|
175
|
+
results = find_icons('profile', self.icons_file.name)
|
|
176
|
+
self.assertTrue(len(results) > 0)
|
|
177
|
+
top_names = [r[0] for r in results]
|
|
178
|
+
self.assertIn('personFill', top_names)
|
|
179
|
+
|
|
180
|
+
def test_menu_synonym(self):
|
|
181
|
+
results = find_icons('menu', self.icons_file.name)
|
|
182
|
+
self.assertTrue(len(results) > 0)
|
|
183
|
+
top_names = [r[0] for r in results]
|
|
184
|
+
self.assertIn('threeDotHorizontalFill', top_names)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if __name__ == '__main__':
|
|
188
|
+
unittest.main()
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Auto-snapshot-and-diff loop: watches for hot-reload completions and
|
|
3
|
+
# automatically captures a snapshot + generates a pixel diff against a mock.
|
|
4
|
+
#
|
|
5
|
+
# This script monitors /tmp/hotreload.log for "Recompilation pass finished"
|
|
6
|
+
# lines, waits for the app to re-render, then runs snapshot + diff. It writes
|
|
7
|
+
# the latest result to /tmp/watch-diff-latest.txt so an AI agent can poll it.
|
|
8
|
+
#
|
|
9
|
+
# The script does NOT kill any running processes -- it only observes and snapshots.
|
|
10
|
+
#
|
|
11
|
+
# Usage:
|
|
12
|
+
# # Watch and auto-diff after each hot-reload
|
|
13
|
+
# bash watch-and-diff.sh /tmp/mock.png --key CommunitiesFeed --port 13592
|
|
14
|
+
#
|
|
15
|
+
# # With context for in-app Playground
|
|
16
|
+
# bash watch-and-diff.sh /tmp/mock.png --key CommunitiesFeed --port 13592 --context "0 8"
|
|
17
|
+
#
|
|
18
|
+
# Arguments:
|
|
19
|
+
# $1 - Mock image path (required)
|
|
20
|
+
# --key - Component key for snapshot (default: "PreviewRoot")
|
|
21
|
+
# --port - App port (default: 13591)
|
|
22
|
+
# --context - Context args for in-app snapshots, e.g. "0 8"
|
|
23
|
+
# --output - Diff output path (default: /tmp/mock-vs-render-diff.png)
|
|
24
|
+
|
|
25
|
+
set -euo pipefail
|
|
26
|
+
|
|
27
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
28
|
+
|
|
29
|
+
# --- Argument parsing ---
|
|
30
|
+
MOCK_PATH="${1:?Usage: watch-and-diff.sh <mock_path> [--key KEY] [--port PORT] [--context \"IDX IDX\"] [--output PATH]}"
|
|
31
|
+
shift
|
|
32
|
+
|
|
33
|
+
KEY="PreviewRoot"
|
|
34
|
+
PORT="13591"
|
|
35
|
+
CONTEXT_ARGS=""
|
|
36
|
+
OUTPUT="/tmp/mock-vs-render-diff.png"
|
|
37
|
+
|
|
38
|
+
while [[ $# -gt 0 ]]; do
|
|
39
|
+
case "$1" in
|
|
40
|
+
--key) KEY="$2"; shift 2 ;;
|
|
41
|
+
--port) PORT="$2"; shift 2 ;;
|
|
42
|
+
--context) CONTEXT_ARGS="$2"; shift 2 ;;
|
|
43
|
+
--output) OUTPUT="$2"; shift 2 ;;
|
|
44
|
+
*) echo "Unknown arg: $1" >&2; exit 1 ;;
|
|
45
|
+
esac
|
|
46
|
+
done
|
|
47
|
+
|
|
48
|
+
# Validate mock image exists
|
|
49
|
+
if [[ ! -f "$MOCK_PATH" ]]; then
|
|
50
|
+
echo "ERROR: Mock image not found: $MOCK_PATH" >&2
|
|
51
|
+
exit 1
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
HOTRELOAD_LOG="/tmp/hotreload.log"
|
|
55
|
+
LATEST_FILE="/tmp/watch-diff-latest.txt"
|
|
56
|
+
|
|
57
|
+
# We use a FIFO so tail runs as a separate process we can kill on cleanup,
|
|
58
|
+
# while the read loop runs in the main shell (preserving function access).
|
|
59
|
+
FIFO="/tmp/watch-diff-fifo.$$"
|
|
60
|
+
mkfifo "$FIFO"
|
|
61
|
+
|
|
62
|
+
TAIL_PID=""
|
|
63
|
+
|
|
64
|
+
# --- Graceful shutdown ---
|
|
65
|
+
cleanup() {
|
|
66
|
+
echo ""
|
|
67
|
+
echo "[$(date '+%H:%M:%S')] Stopping watch-and-diff..."
|
|
68
|
+
if [[ -n "$TAIL_PID" ]] && kill -0 "$TAIL_PID" 2>/dev/null; then
|
|
69
|
+
kill "$TAIL_PID" 2>/dev/null || true
|
|
70
|
+
wait "$TAIL_PID" 2>/dev/null || true
|
|
71
|
+
fi
|
|
72
|
+
rm -f "$FIFO"
|
|
73
|
+
echo "[$(date '+%H:%M:%S')] Stopped."
|
|
74
|
+
exit 0
|
|
75
|
+
}
|
|
76
|
+
trap cleanup SIGINT SIGTERM EXIT
|
|
77
|
+
|
|
78
|
+
# --- Resolve snapshot command ---
|
|
79
|
+
SNAPSHOT_CMD=""
|
|
80
|
+
if command -v valdi-sc &>/dev/null; then
|
|
81
|
+
SNAPSHOT_CMD="valdi-sc inspect snapshot"
|
|
82
|
+
elif command -v valdi &>/dev/null; then
|
|
83
|
+
SNAPSHOT_CMD="valdi inspect snapshot"
|
|
84
|
+
else
|
|
85
|
+
echo "ERROR: Neither valdi-sc nor valdi found in PATH" >&2
|
|
86
|
+
exit 1
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
# --- Snapshot + diff function ---
|
|
90
|
+
do_snapshot_and_diff() {
|
|
91
|
+
local ts
|
|
92
|
+
ts="$(date '+%Y-%m-%d %H:%M:%S')"
|
|
93
|
+
echo ""
|
|
94
|
+
echo "[$ts] Hot-reload detected. Waiting 4s for re-render..."
|
|
95
|
+
sleep 4
|
|
96
|
+
|
|
97
|
+
echo "[$ts] Capturing snapshot (key=$KEY, port=$PORT)..."
|
|
98
|
+
|
|
99
|
+
local snapshot_output snapshot_path
|
|
100
|
+
# shellcheck disable=SC2086
|
|
101
|
+
snapshot_output=$($SNAPSHOT_CMD $CONTEXT_ARGS --key "$KEY" --port "$PORT" 2>&1) || true
|
|
102
|
+
snapshot_path=$(echo "$snapshot_output" | grep -o '"path":"[^"]*"' | head -1 | sed 's/"path":"//;s/"//')
|
|
103
|
+
|
|
104
|
+
if [[ -z "$snapshot_path" || ! -f "$snapshot_path" ]]; then
|
|
105
|
+
echo "[$ts] ERROR: Could not capture snapshot. Output:" >&2
|
|
106
|
+
echo "$snapshot_output" >&2
|
|
107
|
+
{
|
|
108
|
+
echo "timestamp=$ts"
|
|
109
|
+
echo "status=error"
|
|
110
|
+
echo "error=snapshot_failed"
|
|
111
|
+
} > "$LATEST_FILE"
|
|
112
|
+
return 1
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
echo "[$ts] Snapshot: $snapshot_path"
|
|
116
|
+
echo "[$ts] Generating diff..."
|
|
117
|
+
|
|
118
|
+
local diff_output match_pct
|
|
119
|
+
diff_output=$(python3 "$SCRIPT_DIR/diff.py" "$MOCK_PATH" "$snapshot_path" --output "$OUTPUT" 2>&1) || true
|
|
120
|
+
echo "$diff_output"
|
|
121
|
+
|
|
122
|
+
# Extract match percentage from diff.py output
|
|
123
|
+
match_pct=$(echo "$diff_output" | grep -o 'Match: [0-9.]*%' | head -1 | grep -o '[0-9.]*')
|
|
124
|
+
if [[ -z "$match_pct" ]]; then
|
|
125
|
+
match_pct="unknown"
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
# Write result to latest file for AI agent polling
|
|
129
|
+
{
|
|
130
|
+
echo "timestamp=$ts"
|
|
131
|
+
echo "status=ok"
|
|
132
|
+
echo "match_pct=$match_pct"
|
|
133
|
+
echo "snapshot=$snapshot_path"
|
|
134
|
+
echo "diff=$OUTPUT"
|
|
135
|
+
echo "mock=$MOCK_PATH"
|
|
136
|
+
} > "$LATEST_FILE"
|
|
137
|
+
|
|
138
|
+
echo ""
|
|
139
|
+
echo "[$ts] Result: ${match_pct}% match"
|
|
140
|
+
echo "[$ts] Diff image: $OUTPUT"
|
|
141
|
+
echo "[$ts] Latest result written to: $LATEST_FILE"
|
|
142
|
+
echo "---"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# --- Main loop ---
|
|
146
|
+
echo "============================================"
|
|
147
|
+
echo " watch-and-diff"
|
|
148
|
+
echo "============================================"
|
|
149
|
+
echo "Mock: $MOCK_PATH"
|
|
150
|
+
echo "Key: $KEY"
|
|
151
|
+
echo "Port: $PORT"
|
|
152
|
+
echo "Context: ${CONTEXT_ARGS:-<none>}"
|
|
153
|
+
echo "Output: $OUTPUT"
|
|
154
|
+
echo "Log: $HOTRELOAD_LOG"
|
|
155
|
+
echo "Latest: $LATEST_FILE"
|
|
156
|
+
echo "============================================"
|
|
157
|
+
echo ""
|
|
158
|
+
|
|
159
|
+
# Ensure the hotreload log exists
|
|
160
|
+
if [[ ! -f "$HOTRELOAD_LOG" ]]; then
|
|
161
|
+
echo "Waiting for $HOTRELOAD_LOG to appear..."
|
|
162
|
+
while [[ ! -f "$HOTRELOAD_LOG" ]]; do
|
|
163
|
+
sleep 1
|
|
164
|
+
done
|
|
165
|
+
echo "Log file appeared."
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
echo "[$(date '+%H:%M:%S')] Monitoring for hot-reload completions (Ctrl+C to stop)..."
|
|
169
|
+
echo ""
|
|
170
|
+
|
|
171
|
+
# Start tail writing to the FIFO in the background.
|
|
172
|
+
# -n 0 means start from the current end of the file (ignore old lines).
|
|
173
|
+
tail -n 0 -f "$HOTRELOAD_LOG" > "$FIFO" &
|
|
174
|
+
TAIL_PID=$!
|
|
175
|
+
|
|
176
|
+
# Read from the FIFO in the main shell so functions and variables are accessible.
|
|
177
|
+
while IFS= read -r line; do
|
|
178
|
+
if [[ "$line" == *"Recompilation pass finished"* ]]; then
|
|
179
|
+
do_snapshot_and_diff || true
|
|
180
|
+
fi
|
|
181
|
+
done < "$FIFO"
|