@native-sdk/cli 0.0.0 → 0.4.1

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.
Files changed (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
package/build.zig ADDED
@@ -0,0 +1,2593 @@
1
+ const std = @import("std");
2
+ const web_engine_tool = @import("src/tooling/web_engine.zig");
3
+
4
+ const PlatformOption = enum {
5
+ auto,
6
+ null,
7
+ macos,
8
+ linux,
9
+ windows,
10
+ };
11
+
12
+ const TraceOption = enum {
13
+ off,
14
+ events,
15
+ runtime,
16
+ all,
17
+ };
18
+
19
+ const WebEngineOption = enum {
20
+ system,
21
+ chromium,
22
+ };
23
+
24
+ const PackageTarget = enum {
25
+ macos,
26
+ windows,
27
+ linux,
28
+ ios,
29
+ android,
30
+ };
31
+
32
+ const SigningMode = enum {
33
+ none,
34
+ adhoc,
35
+ identity,
36
+ };
37
+
38
+ pub const AppOptions = @import("build/app.zig").AppOptions;
39
+ pub const addApp = @import("build/app.zig").addApp;
40
+ pub const AppArtifacts = @import("build/app.zig").AppArtifacts;
41
+ pub const addAppArtifacts = @import("build/app.zig").addAppArtifacts;
42
+ pub const MobileLibOptions = @import("build/app.zig").MobileLibOptions;
43
+ pub const addMobileLib = @import("build/app.zig").addMobileLib;
44
+ const mobile_export_symbol_names = @import("build/app.zig").mobile_export_symbol_names;
45
+
46
+ pub fn build(b: *std.Build) void {
47
+ const target = b.standardTargetOptions(.{});
48
+ const host_target = b.graph.host;
49
+ const optimize = b.standardOptimizeOption(.{});
50
+ const platform_option = b.option(PlatformOption, "platform", "Desktop backend: auto, null, macos, linux, windows") orelse .auto;
51
+ const trace_option = b.option(TraceOption, "trace", "Trace output: off, events, runtime, all") orelse .events;
52
+ _ = b.option(bool, "debug-overlay", "Enable debug overlay output") orelse false;
53
+ _ = b.option(bool, "automation", "Enable Native SDK automation artifacts") orelse false;
54
+ _ = b.option(bool, "webview", "Deprecated compatibility flag; native surfaces are always enabled") orelse true;
55
+ const web_engine_override = b.option(WebEngineOption, "web-engine", "Override app.zon web engine: system, chromium");
56
+ const cef_dir_override = b.option([]const u8, "cef-dir", "Override CEF root directory for Chromium builds");
57
+ const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
58
+ _ = b.option(bool, "js-bridge", "Enable optional JavaScript bridge stubs") orelse false;
59
+ const package_target = b.option(PackageTarget, "package-target", "Package target: macos, windows, linux, ios, android") orelse .macos;
60
+ const signing_mode = b.option(SigningMode, "signing", "Signing mode: none, adhoc, identity") orelse .none;
61
+ const package_version = packageVersion(b);
62
+ const optimize_name = @tagName(optimize);
63
+ // Resolve against THIS build's root: as a dependency of a user app the
64
+ // build runner's cwd is the app project, and a cwd-relative "app.zon"
65
+ // would read (and panic on) the user's manifest instead of ours.
66
+ const app_web_engine = web_engine_tool.readManifestConfig(b.allocator, b.graph.io, b.pathFromRoot("app.zon")) catch |err| {
67
+ std.debug.panic("failed to read the framework's own app.zon web engine config: {s}", .{@errorName(err)});
68
+ };
69
+ const resolved_web_engine = web_engine_tool.resolve(app_web_engine, .{
70
+ .web_engine = if (web_engine_override) |value| webEngineFromBuildOption(value) else null,
71
+ .cef_dir = cef_dir_override,
72
+ .cef_auto_install = cef_auto_install_override,
73
+ }) catch |err| {
74
+ std.debug.panic("invalid app.zon web engine config: {s}", .{@errorName(err)});
75
+ };
76
+ const web_engine = buildWebEngineFromResolved(resolved_web_engine.engine);
77
+ const browser_web_engine: WebEngineOption = web_engine_override orelse .system;
78
+ const cef_auto_install = resolved_web_engine.cef_auto_install;
79
+ const selected_platform: PlatformOption = switch (platform_option) {
80
+ .auto => if (target.result.os.tag == .macos) .macos else if (target.result.os.tag == .linux) .linux else if (target.result.os.tag == .windows) .windows else .null,
81
+ else => platform_option,
82
+ };
83
+ const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, resolved_web_engine.cef_dir);
84
+ if (selected_platform == .macos and target.result.os.tag != .macos) {
85
+ @panic("-Dplatform=macos requires a macOS target");
86
+ }
87
+ if (selected_platform == .linux and target.result.os.tag != .linux) {
88
+ @panic("-Dplatform=linux requires a Linux target");
89
+ }
90
+ if (selected_platform == .windows and target.result.os.tag != .windows) {
91
+ @panic("-Dplatform=windows requires a Windows target");
92
+ }
93
+ if (web_engine == .chromium and selected_platform != .macos) {
94
+ @panic("-Dweb-engine=chromium currently requires -Dplatform=macos");
95
+ }
96
+
97
+ const geometry_mod = module(b, target, optimize, "src/primitives/geometry/root.zig");
98
+ const assets_mod = module(b, target, optimize, "src/primitives/assets/root.zig");
99
+ const app_dirs_mod = module(b, target, optimize, "src/primitives/app_dirs/root.zig");
100
+ const trace_mod = module(b, target, optimize, "src/primitives/trace/root.zig");
101
+ const app_manifest_mod = module(b, target, optimize, "src/primitives/app_manifest/root.zig");
102
+ const diagnostics_mod = module(b, target, optimize, "src/primitives/diagnostics/root.zig");
103
+ const platform_info_mod = module(b, target, optimize, "src/primitives/platform_info/root.zig");
104
+ const json_mod = module(b, target, optimize, "src/primitives/json/root.zig");
105
+ const canvas_mod = module(b, target, optimize, "src/primitives/canvas/root.zig");
106
+ canvas_mod.addImport("geometry", geometry_mod);
107
+ canvas_mod.addImport("json", json_mod);
108
+ if (target.result.os.tag == .macos) {
109
+ // The estimator-vs-CoreText agreement test (text_metrics_tests.zig)
110
+ // shapes the bundled face through CoreText; apps already link these
111
+ // transitively via AppKit.
112
+ canvas_mod.linkFramework("CoreFoundation", .{});
113
+ canvas_mod.linkFramework("CoreGraphics", .{});
114
+ canvas_mod.linkFramework("CoreText", .{});
115
+ canvas_mod.linkSystemLibrary("c", .{});
116
+ }
117
+ const debug_mod = module(b, target, optimize, "src/debug/root.zig");
118
+ debug_mod.addImport("app_dirs", app_dirs_mod);
119
+ debug_mod.addImport("trace", trace_mod);
120
+
121
+ const geometry_tests = testArtifact(b, geometry_mod);
122
+ const assets_tests = testArtifact(b, assets_mod);
123
+ const app_dirs_tests = testArtifact(b, app_dirs_mod);
124
+ const trace_tests = testArtifact(b, trace_mod);
125
+ const app_manifest_tests = testArtifact(b, app_manifest_mod);
126
+ const diagnostics_tests = testArtifact(b, diagnostics_mod);
127
+ const platform_info_tests = testArtifact(b, platform_info_mod);
128
+ const json_tests = testArtifact(b, json_mod);
129
+ const canvas_tests = testArtifact(b, canvas_mod);
130
+
131
+ const desktop_mod = module(b, target, optimize, "src/root.zig");
132
+ desktop_mod.addImport("geometry", geometry_mod);
133
+ desktop_mod.addImport("app_dirs", app_dirs_mod);
134
+ desktop_mod.addImport("assets", assets_mod);
135
+ desktop_mod.addImport("trace", trace_mod);
136
+ desktop_mod.addImport("app_manifest", app_manifest_mod);
137
+ desktop_mod.addImport("diagnostics", diagnostics_mod);
138
+ desktop_mod.addImport("platform_info", platform_info_mod);
139
+ desktop_mod.addImport("json", json_mod);
140
+ desktop_mod.addImport("canvas", canvas_mod);
141
+ const desktop_tests = testArtifact(b, desktop_mod);
142
+ const desktop_test_shards = desktopTestShardArtifacts(b, desktop_mod);
143
+
144
+ // The embeddable static library's root module carries only the C ABI
145
+ // exports (fixed WebView shell host); user-app canvas libraries are
146
+ // produced by `addMobileLib` from src/embed/app_exports.zig instead.
147
+ const embed_exports_mod = module(b, target, optimize, "src/embed/c_exports.zig");
148
+ embed_exports_mod.addImport("native_sdk", desktop_mod);
149
+ embed_exports_mod.export_symbol_names = &mobile_export_symbol_names;
150
+ const embed_lib = b.addLibrary(.{
151
+ .linkage = .static,
152
+ .name = "native-sdk",
153
+ .root_module = embed_exports_mod,
154
+ // The embed C ABI (`native_sdk_app_viewport`) is exactly the
155
+ // f32-heavy SysV signature Zig 0.16.0's self-hosted x86_64 backend
156
+ // miscompiles (see useLlvmWorkaround in build/app.zig): without
157
+ // this, Debug x86_64 libs (Android emulators, Intel simulators)
158
+ // hand clang hosts corrupted inset/keyboard floats. addMobileLib
159
+ // already forces LLVM there; the fixed-shell lib must match.
160
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
161
+ });
162
+ b.installArtifact(embed_lib);
163
+
164
+ const automation_protocol_mod = module(b, target, optimize, "src/automation/protocol.zig");
165
+ const automation_protocol_tests = testArtifact(b, automation_protocol_mod);
166
+ // The app-icon pipeline as a standalone module: tooling needs only
167
+ // the vector core + PNG codec slice of canvas, not the full canvas
168
+ // module (which links platform frameworks on macOS and would weigh
169
+ // down the cross-compiled CLI).
170
+ const app_icon_mod = module(b, target, optimize, "src/primitives/canvas/app_icon.zig");
171
+ app_icon_mod.addImport("geometry", geometry_mod);
172
+ // The iOS and Android host sources as embedded bytes: the tooling
173
+ // module writes and compiles them for `native dev|package --target
174
+ // ios|android`.
175
+ const ios_host_mod = module(b, target, optimize, "src/platform/ios/files.zig");
176
+ const android_host_mod = module(b, target, optimize, "src/platform/android/files.zig");
177
+ const tooling_mod = module(b, target, optimize, "src/tooling/root.zig");
178
+ tooling_mod.addImport("assets", assets_mod);
179
+ tooling_mod.addImport("app_dirs", app_dirs_mod);
180
+ tooling_mod.addImport("app_manifest", app_manifest_mod);
181
+ tooling_mod.addImport("diagnostics", diagnostics_mod);
182
+ tooling_mod.addImport("debug", debug_mod);
183
+ tooling_mod.addImport("platform_info", platform_info_mod);
184
+ tooling_mod.addImport("trace", trace_mod);
185
+ tooling_mod.addImport("app_icon", app_icon_mod);
186
+ tooling_mod.addImport("ios_host", ios_host_mod);
187
+ tooling_mod.addImport("android_host", android_host_mod);
188
+ const tooling_tests = testArtifact(b, tooling_mod);
189
+
190
+ // Ejected-component identity proofs: a separate test module because
191
+ // the canonical component sources under src/tooling/components/
192
+ // import `native_sdk` exactly as they will inside an app after
193
+ // `native eject component <name>` copies them there.
194
+ const eject_components_mod = module(b, target, optimize, "src/tooling/components/identity_tests.zig");
195
+ eject_components_mod.addImport("native_sdk", desktop_mod);
196
+ const eject_components_tests = testArtifact(b, eject_components_mod);
197
+
198
+ const ui_markup_mod = module(b, target, optimize, "src/primitives/canvas/ui_markup.zig");
199
+ const markup_lsp_mod = module(b, target, optimize, "tools/native-sdk/markup_lsp.zig");
200
+ markup_lsp_mod.addImport("ui_markup", ui_markup_mod);
201
+ const markup_lsp_tests = testArtifact(b, markup_lsp_mod);
202
+
203
+ const automation_cli_mod = module(b, target, optimize, "tools/native-sdk/automation.zig");
204
+ automation_cli_mod.addImport("automation_protocol", automation_protocol_mod);
205
+ automation_cli_mod.addImport("ui_markup", ui_markup_mod);
206
+ const automation_cli_tests = testArtifact(b, automation_cli_mod);
207
+
208
+ // `native version` names the commit the binary was built from, so
209
+ // binary/framework skew ("your native binary may be stale") is a
210
+ // one-command check. Falls back to "unknown" outside a git checkout.
211
+ const cli_build_info = b.addOptions();
212
+ cli_build_info.addOption([]const u8, "build_commit", cliBuildCommit(b));
213
+
214
+ const cli_mod = module(b, target, optimize, "tools/native-sdk/main.zig");
215
+ cli_mod.addImport("tooling", tooling_mod);
216
+ cli_mod.addImport("automation_protocol", automation_protocol_mod);
217
+ cli_mod.addImport("ui_markup", ui_markup_mod);
218
+ cli_mod.addImport("markup_lsp", markup_lsp_mod);
219
+ cli_mod.addOptions("cli_build_info", cli_build_info);
220
+ const cli_exe = b.addExecutable(.{
221
+ .name = "native",
222
+ .root_module = cli_mod,
223
+ });
224
+ b.installArtifact(cli_exe);
225
+
226
+ // `zig build cli` builds and installs ONLY the CLI executable. The
227
+ // release pipeline cross-compiles it for every supported platform
228
+ // (packages/native-sdk/scripts/build-binaries.sh), and skipping the
229
+ // framework libraries, examples, and docs artifacts keeps that
230
+ // eight-target loop fast.
231
+ const cli_step = b.step("cli", "Build only the native CLI executable (cross-compile friendly)");
232
+ cli_step.dependOn(&b.addInstallArtifact(cli_exe, .{}).step);
233
+
234
+ const host_assets_mod = module(b, host_target, optimize, "src/primitives/assets/root.zig");
235
+ const host_app_dirs_mod = module(b, host_target, optimize, "src/primitives/app_dirs/root.zig");
236
+ const host_app_manifest_mod = module(b, host_target, optimize, "src/primitives/app_manifest/root.zig");
237
+ const host_diagnostics_mod = module(b, host_target, optimize, "src/primitives/diagnostics/root.zig");
238
+ const host_platform_info_mod = module(b, host_target, optimize, "src/primitives/platform_info/root.zig");
239
+ const host_trace_mod = module(b, host_target, optimize, "src/primitives/trace/root.zig");
240
+ const host_debug_mod = module(b, host_target, optimize, "src/debug/root.zig");
241
+ host_debug_mod.addImport("app_dirs", host_app_dirs_mod);
242
+ host_debug_mod.addImport("trace", host_trace_mod);
243
+ const host_automation_protocol_mod = module(b, host_target, optimize, "src/automation/protocol.zig");
244
+ const host_geometry_mod = module(b, host_target, optimize, "src/primitives/geometry/root.zig");
245
+ const host_app_icon_mod = module(b, host_target, optimize, "src/primitives/canvas/app_icon.zig");
246
+ host_app_icon_mod.addImport("geometry", host_geometry_mod);
247
+ const host_ios_host_mod = module(b, host_target, optimize, "src/platform/ios/files.zig");
248
+ const host_android_host_mod = module(b, host_target, optimize, "src/platform/android/files.zig");
249
+ const host_tooling_mod = module(b, host_target, optimize, "src/tooling/root.zig");
250
+ host_tooling_mod.addImport("assets", host_assets_mod);
251
+ host_tooling_mod.addImport("app_dirs", host_app_dirs_mod);
252
+ host_tooling_mod.addImport("app_manifest", host_app_manifest_mod);
253
+ host_tooling_mod.addImport("diagnostics", host_diagnostics_mod);
254
+ host_tooling_mod.addImport("debug", host_debug_mod);
255
+ host_tooling_mod.addImport("platform_info", host_platform_info_mod);
256
+ host_tooling_mod.addImport("trace", host_trace_mod);
257
+ host_tooling_mod.addImport("app_icon", host_app_icon_mod);
258
+ host_tooling_mod.addImport("ios_host", host_ios_host_mod);
259
+ host_tooling_mod.addImport("android_host", host_android_host_mod);
260
+ const host_ui_markup_mod = module(b, host_target, optimize, "src/primitives/canvas/ui_markup.zig");
261
+ const host_markup_lsp_mod = module(b, host_target, optimize, "tools/native-sdk/markup_lsp.zig");
262
+ host_markup_lsp_mod.addImport("ui_markup", host_ui_markup_mod);
263
+ const host_cli_mod = module(b, host_target, optimize, "tools/native-sdk/main.zig");
264
+ host_cli_mod.addImport("tooling", host_tooling_mod);
265
+ host_cli_mod.addImport("automation_protocol", host_automation_protocol_mod);
266
+ host_cli_mod.addImport("ui_markup", host_ui_markup_mod);
267
+ host_cli_mod.addImport("markup_lsp", host_markup_lsp_mod);
268
+ host_cli_mod.addOptions("cli_build_info", cli_build_info);
269
+ const host_cli_exe = b.addExecutable(.{
270
+ .name = "native",
271
+ .root_module = host_cli_mod,
272
+ });
273
+ // Docs component-preview generator: renders the built-in component
274
+ // catalog offscreen through the deterministic reference renderer and
275
+ // writes theme-aware webp pairs plus the markup vocabulary JSON into
276
+ // docs/. Regenerate with `zig build docs-component-previews`.
277
+ const docs_previews_mod = module(b, target, optimize, "tools/docs_component_previews.zig");
278
+ docs_previews_mod.addImport("native_sdk", desktop_mod);
279
+ // The eject registry as its own lean module (its imports stay inside
280
+ // src/tooling/), so the vocab JSON's `ejectable` table is written from
281
+ // the same rows `native eject component` dispatches on — the docs'
282
+ // <EjectSection> resolves from that JSON and can never drift.
283
+ docs_previews_mod.addImport("eject_components", module(b, target, optimize, "src/tooling/eject_components.zig"));
284
+ const docs_previews_exe = b.addExecutable(.{
285
+ .name = "docs-component-previews",
286
+ .root_module = docs_previews_mod,
287
+ });
288
+ const run_docs_previews = b.addRunArtifact(docs_previews_exe);
289
+ run_docs_previews.addArg(b.pathFromRoot("docs/public/components"));
290
+ run_docs_previews.addArg(b.pathFromRoot("docs/src/lib/component-vocab.json"));
291
+ run_docs_previews.has_side_effects = true;
292
+ const docs_previews_step = b.step("docs-component-previews", "Render built-in component previews and vocab JSON into docs/");
293
+ docs_previews_step.dependOn(&run_docs_previews.step);
294
+
295
+ // Render macro-benchmark: deterministic scenarios through the REAL
296
+ // engine pipeline (UiApp + Runtime + null-platform binary packet
297
+ // presents), reporting end-to-end and per-stage p50/p90 per
298
+ // interaction. Baselines should come from
299
+ // `zig build bench-render -Doptimize=ReleaseFast`.
300
+ const bench_render_mod = module(b, target, optimize, "tools/bench_render.zig");
301
+ bench_render_mod.addImport("native_sdk", desktop_mod);
302
+ const bench_render_exe = b.addExecutable(.{
303
+ .name = "bench-render",
304
+ .root_module = bench_render_mod,
305
+ });
306
+ const run_bench_render = b.addRunArtifact(bench_render_exe);
307
+ run_bench_render.has_side_effects = true;
308
+ // Repo root as cwd so the relative budgets path in the docs/gate
309
+ // invocation resolves regardless of where `zig build` ran from.
310
+ run_bench_render.setCwd(b.path("."));
311
+ // Ratchet mode: `zig build bench-render -Doptimize=ReleaseFast --
312
+ // --check tools/bench-render-budgets.txt` compares the median e2e
313
+ // p50 of three suite passes against the committed budgets (the
314
+ // benchmark refuses --check outside ReleaseFast).
315
+ if (b.args) |bench_args| run_bench_render.addArgs(bench_args);
316
+ const bench_render_step = b.step("bench-render", "Run the render macro-benchmark (deterministic scenarios; pass -Doptimize=ReleaseFast for baselines, `-- --check tools/bench-render-budgets.txt` for the budget ratchet)");
317
+ bench_render_step.dependOn(&run_bench_render.step);
318
+
319
+ // Live docs previews: the same scene catalog compiled to
320
+ // wasm32-freestanding (tools/docs_wasm_preview.zig) so the docs
321
+ // upgrade the static webp tiles to interactive engine instances.
322
+ // ReleaseSmall + strip keep the module small enough to lazy-load.
323
+ const wasm_target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
324
+ const wasm_optimize: std.builtin.OptimizeMode = .ReleaseSmall;
325
+ const wasm_geometry_mod = module(b, wasm_target, wasm_optimize, "src/primitives/geometry/root.zig");
326
+ const wasm_json_mod = module(b, wasm_target, wasm_optimize, "src/primitives/json/root.zig");
327
+ const wasm_canvas_mod = module(b, wasm_target, wasm_optimize, "src/primitives/canvas/root.zig");
328
+ wasm_canvas_mod.addImport("geometry", wasm_geometry_mod);
329
+ wasm_canvas_mod.addImport("json", wasm_json_mod);
330
+ const wasm_native_mod = module(b, wasm_target, wasm_optimize, "src/root.zig");
331
+ wasm_native_mod.addImport("geometry", wasm_geometry_mod);
332
+ wasm_native_mod.addImport("json", wasm_json_mod);
333
+ wasm_native_mod.addImport("canvas", wasm_canvas_mod);
334
+ wasm_native_mod.addImport("app_dirs", module(b, wasm_target, wasm_optimize, "src/primitives/app_dirs/root.zig"));
335
+ wasm_native_mod.addImport("assets", module(b, wasm_target, wasm_optimize, "src/primitives/assets/root.zig"));
336
+ wasm_native_mod.addImport("trace", module(b, wasm_target, wasm_optimize, "src/primitives/trace/root.zig"));
337
+ wasm_native_mod.addImport("app_manifest", module(b, wasm_target, wasm_optimize, "src/primitives/app_manifest/root.zig"));
338
+ wasm_native_mod.addImport("diagnostics", module(b, wasm_target, wasm_optimize, "src/primitives/diagnostics/root.zig"));
339
+ wasm_native_mod.addImport("platform_info", module(b, wasm_target, wasm_optimize, "src/primitives/platform_info/root.zig"));
340
+ const docs_wasm_preview_mod = module(b, wasm_target, wasm_optimize, "tools/docs_wasm_preview.zig");
341
+ docs_wasm_preview_mod.addImport("native_sdk", wasm_native_mod);
342
+ docs_wasm_preview_mod.strip = true;
343
+ const docs_wasm_preview_exe = b.addExecutable(.{
344
+ .name = "component-preview",
345
+ .root_module = docs_wasm_preview_mod,
346
+ });
347
+ docs_wasm_preview_exe.entry = .disabled;
348
+ docs_wasm_preview_exe.rdynamic = true;
349
+ // The engine trades heap for fixed capacity but still builds some
350
+ // sizable stack temporaries (NullPlatform alone is ~800 KB); the
351
+ // 1 MB wasm default overflows into linear memory silently.
352
+ docs_wasm_preview_exe.stack_size = 16 * 1024 * 1024;
353
+ const copy_docs_wasm_preview = b.addUpdateSourceFiles();
354
+ copy_docs_wasm_preview.addCopyFileToSource(docs_wasm_preview_exe.getEmittedBin(), "docs/public/wasm/component-preview.wasm");
355
+ const docs_wasm_preview_step = b.step("docs-wasm-preview", "Compile the live component-preview wasm module into docs/public/wasm/");
356
+ docs_wasm_preview_step.dependOn(&copy_docs_wasm_preview.step);
357
+
358
+ const file_contains_checker_mod = module(b, host_target, optimize, "tools/check_file_contains.zig");
359
+ const file_contains_checker = b.addExecutable(.{
360
+ .name = "check-file-contains",
361
+ .root_module = file_contains_checker_mod,
362
+ });
363
+
364
+ // Registry pin printer: emits the ui_schema table counts and
365
+ // fingerprints in the exact form ui_schema_tests.zig pins, plus the
366
+ // next free code per table for reserving codes ahead of parallel
367
+ // work. `zig build print-pins` after registry additions.
368
+ const print_pins_mod = module(b, host_target, optimize, "tools/print_pins.zig");
369
+ print_pins_mod.addImport("ui_schema", module(b, host_target, optimize, "src/primitives/canvas/ui_schema.zig"));
370
+ const print_pins_exe = b.addExecutable(.{
371
+ .name = "print-pins",
372
+ .root_module = print_pins_mod,
373
+ });
374
+ const run_print_pins = b.addRunArtifact(print_pins_exe);
375
+ run_print_pins.has_side_effects = true;
376
+ const print_pins_step = b.step("print-pins", "Print registry counts and fingerprints in pin-ready form");
377
+ print_pins_step.dependOn(&run_print_pins.step);
378
+
379
+ const platform_arg = switch (selected_platform) {
380
+ .auto => unreachable,
381
+ .null => "null",
382
+ .macos => "macos",
383
+ .linux => "linux",
384
+ .windows => "windows",
385
+ };
386
+
387
+ const test_step = b.step("test", "Run package and framework tests");
388
+ test_step.dependOn(&b.addRunArtifact(geometry_tests).step);
389
+ test_step.dependOn(&b.addRunArtifact(assets_tests).step);
390
+ test_step.dependOn(&b.addRunArtifact(app_dirs_tests).step);
391
+ test_step.dependOn(&b.addRunArtifact(trace_tests).step);
392
+ test_step.dependOn(&b.addRunArtifact(app_manifest_tests).step);
393
+ test_step.dependOn(&b.addRunArtifact(diagnostics_tests).step);
394
+ test_step.dependOn(&b.addRunArtifact(platform_info_tests).step);
395
+ test_step.dependOn(&b.addRunArtifact(json_tests).step);
396
+ test_step.dependOn(&b.addRunArtifact(canvas_tests).step);
397
+ for (desktop_test_shards) |shard_tests| {
398
+ test_step.dependOn(&b.addRunArtifact(shard_tests).step);
399
+ }
400
+ test_step.dependOn(&b.addRunArtifact(automation_protocol_tests).step);
401
+ test_step.dependOn(&b.addRunArtifact(tooling_tests).step);
402
+ test_step.dependOn(&b.addRunArtifact(eject_components_tests).step);
403
+ test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
404
+ test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
405
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-package-types", "Verify package TypeScript platform feature names", &.{
406
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCommandInfo" },
407
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "list(): Promise<NativeSdkCommandInfo[]>" },
408
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCreateWebViewViewOptions" },
409
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "Stable runtime view id" },
410
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "update(label: string" },
411
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "focus(options: string | NativeSdkViewSelector)" },
412
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "close(options: string | NativeSdkViewSelector)" },
413
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "kind: \"webview\"" },
414
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "url: string" },
415
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkPlatformFeatureSelector" },
416
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "supports(value: NativeSdkPlatformFeature | NativeSdkPlatformFeatureSelector)" },
417
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"native_control_commands\"" },
418
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"nativeControlCommands\"" },
419
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"recent_documents\"" },
420
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"recentDocuments\"" },
421
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"file_drops\"" },
422
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"fileDrops\"" },
423
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"app_activation_events\"" },
424
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"appActivationEvents\"" },
425
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpu_surfaces\"" },
426
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpuSurfaces\"" },
427
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuFirstFrameLatencyNs: number" },
428
+ });
429
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-bridge-view-selector-helpers", "Verify injected view helpers accept string selectors", &.{
430
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "viewSelectorPayload(options)" },
431
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "viewSelectorPayload(options)" },
432
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "viewSelectorPayload(options)" },
433
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "viewSelectorPayload(options)" },
434
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
435
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
436
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
437
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "focus:function(options){return invoke('native-sdk.view.focus',viewSelectorPayload(options))" },
438
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
439
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
440
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
441
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
442
+ });
443
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-command-contracts", "Verify command docs match native view update contracts", &.{
444
+ .{ .path = "docs/src/app/commands/page.mdx", .pattern = ".text = \"Refreshed\"" },
445
+ .{ .path = "docs/src/app/commands/page.mdx", .pattern = "const commands = await window.zero.commands.list();" },
446
+ });
447
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-native-view-contracts", "Verify native surface docs describe view identity", &.{
448
+ .{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "ViewInfo.id" },
449
+ .{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "window.zero.views.update(\"status\"" },
450
+ .{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "first-frame latency budget" },
451
+ });
452
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-shell-manifest-contracts", "Verify app.zon docs describe shell compatibility window labels", &.{
453
+ .{ .path = "docs/src/app/app-zon/page.mdx", .pattern = "labels must stay unique across both lists" },
454
+ });
455
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-js-view-helper-contracts", "Verify injected view helpers support label-first updates", &.{
456
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "update:function(options,patch)" },
457
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "update:function(options,patch)" },
458
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "update:function(options,patch)" },
459
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "update:function(options,patch)" },
460
+ });
461
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-gpu-frame-emission-below-paint", "Verify the Linux GPU frame emission is scheduled below layout and paint priorities", &.{
462
+ // A saturated demand-driven frame loop (cycle cost > frame
463
+ // interval => every present re-arms at delay 0) scheduled at
464
+ // G_PRIORITY_DEFAULT would be ready on every main-loop
465
+ // iteration and starve GTK's layout/paint sources: presents
466
+ // land and queue_draw keeps inviting a repaint, but the glass
467
+ // freezes on stale pixels for as long as the loop stays armed.
468
+ // The emission must stay below GDK_PRIORITY_REDRAW so every
469
+ // presented frame paints before the next frame event.
470
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "view->gpu_emit_source = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE," },
471
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "paint (GDK_PRIORITY_REDRAW," },
472
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "static void native_sdk_gpu_surface_schedule_frame_emission" },
473
+ });
474
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-audio-buffering-clears-on-noop-resume", "Verify the Linux audio buffering flag drops when the 100% resume completes synchronously", &.{
475
+ // The buffering flag normally drops at the PLAYING
476
+ // state-changed message. When the refill's earlier PAUSED
477
+ // request never completed, the 100% resume is a no-op that
478
+ // posts no message; a non-ASYNC set_state result is the only
479
+ // signal, and the flag must drop on it or it rides every
480
+ // position tick for the rest of the track.
481
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "const int change = gst->element_set_state(audio->playbin, NATIVE_SDK_GST_STATE_PLAYING);" },
482
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "change != NATIVE_SDK_GST_STATE_CHANGE_ASYNC" },
483
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#define NATIVE_SDK_GST_STATE_CHANGE_ASYNC 2" },
484
+ });
485
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-packaged-assets-webview2", "Verify Windows packaged assets are served through WebView2 request interception", &.{
486
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "constexpr const char *kAssetVirtualOrigin = \"https://native-sdk-app.localhost\";" },
487
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "return virtualAssetEntryUrl(webview.asset_entry);" },
488
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "AddWebResourceRequestedFilter(L\"https://native-sdk-app.localhost/*\"" },
489
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "assetWebResourceResponse(environment_ref.Get(), found->second, uri)" },
490
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "bridgeOriginForWebViewUrl(source_webview->second, source_url)" },
491
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "webview.spa_fallback = spa_fallback != 0;" },
492
+ });
493
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-cef-packaged-assets-webviews", "Verify macOS CEF child WebViews resolve packaged asset URLs before loading", &.{
494
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "self.assetRoots = [[NSMutableDictionary alloc] init];" },
495
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "resolvedWebViewURLString:(NSString *)url windowId:(uint64_t)windowId" },
496
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "CefBrowserHost::CreateBrowser(windowInfo, client.get(), std::string(resolvedURL.UTF8String)" },
497
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "self.webviewPendingURLs[[self webViewKeyForWindow:windowId label:label]] = resolvedURL;" },
498
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "bridgeOriginForWindowId:window_id_ webViewLabel:labelString sourceURL:sourceURLString" },
499
+ });
500
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-native-accessibility-roles", "Verify AppKit native views publish accessibility roles", &.{
501
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkAccessibilityRoleForNativeViewKind" },
502
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSAccessibilityToolbarRole" },
503
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSAccessibilityProgressIndicatorRole" },
504
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "view.accessibilityRole = NativeSdkAccessibilityRoleForNativeViewKind(kind)" },
505
+ });
506
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-input-repaints-retained-canvas", "Verify GPU input wakes retained canvas frames", &.{
507
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)requestRetainedCanvasFrame" },
508
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self requestRetainedCanvasFrame];" },
509
+ });
510
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-input-paces-retained-canvas", "Verify GPU input frame requests are paced to the display interval", &.{
511
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRetainedFrameIntervalNanoseconds" },
512
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "retainedFrameLastEmitNs" },
513
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "queuePointerMotionInputEvent:(NSEvent *)event" },
514
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "pendingPointerMotionKind = kind" },
515
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitQueuedPointerMotionInputEvent" },
516
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "queueScrollInputEvent:(NSEvent *)event" },
517
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "pendingScrollDeltaY += deltaY" },
518
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitQueuedScrollInputEvent" },
519
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "dispatch_after(dispatch_time(DISPATCH_TIME_NOW" },
520
+ // The single per-surface frame-event scheduler: every producer
521
+ // (requests, completions, occluded completions) coalesces into
522
+ // one paced emission per display interval.
523
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)scheduleFrameEventEmission" },
524
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)emitScheduledFrameEvent" },
525
+ });
526
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gpu-occluded-frame-heartbeat", "Verify occluded windows throttle frame completions to a heartbeat and restore full cadence on reveal", &.{
527
+ // macOS: occluded surfaces pace logical completions on the ~1 Hz
528
+ // heartbeat (never stopping — on_frame-driven models stay gently
529
+ // current), de-occlusion supersedes the parked emission for an
530
+ // immediate return to the display grid, and heartbeat completions
531
+ // are flagged so the runtime never stamps input latency from them.
532
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkOccludedFrameHeartbeatNs = 1000000000ull" },
533
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (BOOL)occludedFramePacingActive" },
534
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "heartbeatPaced ? NativeSdkOccludedFrameHeartbeatNs" },
535
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "self.frameEventEmissionGeneration += 1" },
536
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "occluded:[self occludedFramePacingActive]" },
537
+ // Exempt producers (a real present's completion, an input's
538
+ // responding frame) fire at grid promptness — neither can
539
+ // sustain a spin.
540
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "scheduleFrameEventEmissionForPresentCompletion:YES" },
541
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)noteGpuSurfaceInputActivity" },
542
+ // Windows: the same throttle keyed on the one reliable Win32
543
+ // occlusion signal (minimize); restore re-arms the pending
544
+ // one-shot timer at the frame-grid delay, and the input /
545
+ // first-present exemptions ride one prompt-frame flag.
546
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuOccludedHeartbeatNs = 1000000000ull" },
547
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpuSurfaceOccludedPacingActive" },
548
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "IsIconic(root)" },
549
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpu_prompt_frame_pending" },
550
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "native_sdk_windows_note_gpu_surface_input" },
551
+ // The runtime side of the measurement honesty: occluded logical
552
+ // completions resolve pending inputs without a latency stamp,
553
+ // and every dispatched input notes the host for a prompt
554
+ // responding frame.
555
+ .{ .path = "src/runtime/gpu_surface_events.zig", .pattern = "resolveGpuSurfaceInputForOccludedFrame" },
556
+ .{ .path = "src/runtime/gpu_surface_events.zig", .pattern = "noteGpuSurfaceInput" },
557
+ // GTK: no reliable cross-backend occlusion signal — the decision
558
+ // to leave full cadence is documented at the scheduler, not
559
+ // implicit.
560
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "No occluded/minimized throttle here, DELIBERATELY" },
561
+ });
562
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-drawable-integral-pixels", "Verify AppKit GPU surfaces use integral drawable pixels", &.{
563
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "ceil(size.width * scale)" },
564
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "ceil(size.height * scale)" },
565
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "self.metalLayer.drawableSize = drawableSize" },
566
+ });
567
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-resize-repaints-retained-canvas", "Verify AppKit GPU resize requests a correctly sized retained frame", &.{
568
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "_metalLayer.contentsGravity = kCAGravityTopLeft" },
569
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (changed) {" },
570
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self requestRetainedCanvasFrame];" },
571
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "canvasTextureMatchesDrawable" },
572
+ });
573
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-transforms", "Verify AppKit GPU packet presenter applies command transforms", &.{
574
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketApplyTransform(command[@\"transform\"])" },
575
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[affine setTransformStruct:transform]" },
576
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[affine concat]" },
577
+ });
578
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-paths", "Verify AppKit GPU packet presenter draws path commands", &.{
579
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[kind isEqualToString:@\"path\"]" },
580
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[verb isEqualToString:@\"quad_to\"]" },
581
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[kind isEqualToString:@\"fill_path\"]" },
582
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[kind isEqualToString:@\"stroke_path\"]" },
583
+ });
584
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-corner-radii", "Verify AppKit GPU packet presenter honors per-corner radii", &.{
585
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketRoundedRectPath" },
586
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "CGFloat topRight = NativeSdkPacketRadiusAt(radiusValue, 1, maxRadius)" },
587
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "CGFloat bottomLeft = NativeSdkPacketRadiusAt(radiusValue, 3, maxRadius)" },
588
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "return NativeSdkPacketRoundedRectPath(rect, shape[@\"radius\"])" },
589
+ });
590
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-load-frames", "Verify AppKit GPU packet presenter handles retained load frames", &.{
591
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "canvasPacketPixels" },
592
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[loadAction isEqualToString:@\"load\"]" },
593
+ // Retained-backing discipline: dirty updates require the validity
594
+ // flag, and every present that mutates the backing clears it until
595
+ // the draw succeeds — a failed draw can never leak stale pixels
596
+ // around a later scissor.
597
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "!self.canvasPacketPixelsValid" },
598
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "self.canvasPacketPixelsValid = YES" },
599
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "hasDirtyRect:uploadDirtyRect" },
600
+ });
601
+ // Version prose is machine-checked: the wire-format v2/v3 drift (spec
602
+ // comments and changelog naming a version the constant had moved past)
603
+ // shipped once, so the constant and every prose site that names the
604
+ // version are pinned together. Bumping `binary_packet_version` fails
605
+ // this step until the encoder comment, the host decoder comment, and
606
+ // the patterns below move with it.
607
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-wire-format-version-prose", "Verify wire-format version prose matches the packet version constant", &.{
608
+ .{ .path = "src/primitives/canvas/serialization.zig", .pattern = "pub const binary_packet_version: u8 = 3;" },
609
+ .{ .path = "src/primitives/canvas/serialization.zig", .pattern = "Compact binary gpu-surface packet encoding (wire format v3)." },
610
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "Compact binary gpu-surface packet decoding (wire format v3)." },
611
+ });
612
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-blur-effects", "Verify AppKit GPU packet presenter applies blur effects", &.{
613
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketApplyBlur" },
614
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "CGBitmapContextGetData(context)" },
615
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSIntersectionRect(rect, clipRect)" },
616
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketTransformRect(transformValue, NativeSdkPacketRect(effect[@\"rect\"]))" },
617
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "return NativeSdkPacketApplyBlur(effect, opacity, context, scale, transformValue, hasClip, clipRect)" },
618
+ });
619
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-text-layout", "Verify AppKit GPU packet presenter honors text layout metadata", &.{
620
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSMutableParagraphStyle" },
621
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketTextLineBreakMode" },
622
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketTextAlignment" },
623
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketNumber(layout[@\"maxWidth\"], 0)" },
624
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[value drawWithRect:NSMakeRect(origin.x, origin.y - size, textWidth, textHeight)" },
625
+ });
626
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-font-assets", "Verify AppKit GPU packet text registers bundled font assets", &.{
627
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "#import <CoreText/CoreText.h>" },
628
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "CTFontManagerRegisterFontsForURL" },
629
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@[ @\"fonts\", @\"Fonts\", @\"assets/fonts\" ]" },
630
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRegisterBundledFonts();" },
631
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketPreferredFont(text, size)" },
632
+ .{ .path = "src/tooling/templates.zig", .pattern = "app_mod.linkFramework(\"CoreText\", .{});" },
633
+ });
634
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-span-fonts", "Verify AppKit packet text resolves reserved span font ids to real weighted and italic faces", &.{
635
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkItalicSansFont(NSFont *font)" },
636
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkWeightedSansFont(" },
637
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkWeightedSansFont(@[ @\"Geist-Medium\", @\"Geist Medium\" ], base, NSFontWeightMedium, NO, size)" },
638
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], base, NSFontWeightBold, YES, size)" },
639
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(base)" },
640
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], base, NSFontWeightBold, YES, size))" },
641
+ });
642
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-cursor-bridge", "Verify AppKit GPU widgets apply retained cursor intent", &.{
643
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "native_sdk_appkit_set_view_cursor" },
644
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "resetCursorRects" },
645
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSTrackingMouseMoved" },
646
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NATIVE_SDK_APPKIT_GPU_INPUT_POINTER_CANCEL" },
647
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "_surfaceCursor = cursor ?: [NSCursor arrowCursor]" },
648
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSCursor pointingHandCursor" },
649
+ });
650
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-actions", "Verify AppKit GPU widget accessibility actions route to the runtime", &.{
651
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityPerformPress" },
652
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitWidgetAccessibilityActionWithId" },
653
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NATIVE_SDK_APPKIT_EVENT_WIDGET_ACCESSIBILITY_ACTION" },
654
+ // The per-element action gate: without it AppKit derives the
655
+ // advertised action list from the CLASS's selectors, so every
656
+ // widget element (a static label included) offers
657
+ // press/increment/decrement/cancel and performing an
658
+ // unsupported one reports success while actuating nothing.
659
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "isAccessibilitySelectorAllowed" },
660
+ // An assistive client's AXFocused WRITE must move the app's
661
+ // real focus, not just flip a flag on the snapshot element.
662
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "setAccessibilityFocused" },
663
+ });
664
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-text-ranges", "Verify AppKit GPU widget accessibility publishes text selection ranges", &.{
665
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilitySelectedTextRange" },
666
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilitySelectedTextRanges" },
667
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityVisibleCharacterRange" },
668
+ });
669
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-accessibility-grid-metrics", "Verify AppKit GPU widget accessibility publishes grid and scroll metrics", &.{
670
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityRowIndexRange" },
671
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityColumnIndexRange" },
672
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityRowCount" },
673
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityMaxValue" },
674
+ });
675
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-ime-bridge", "Verify AppKit GPU widgets route native text input and IME composition", &.{
676
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSTextInputClient" },
677
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "insertText:(id)string replacementRange" },
678
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "setMarkedText:(id)string selectedRange" },
679
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NATIVE_SDK_APPKIT_GPU_INPUT_IME_SET_COMPOSITION" },
680
+ });
681
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-gpu-widget-ime-bridge", "Verify the Windows GPU host routes WM_IME composition onto the shared IME event kinds", &.{
682
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "case WM_IME_STARTCOMPOSITION:" },
683
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "case WM_IME_COMPOSITION:" },
684
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "case WM_IME_ENDCOMPOSITION:" },
685
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuInputImeSetComposition = 8" },
686
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuInputImeCommitComposition = 9" },
687
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuInputImeCancelComposition = 10" },
688
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpuImeCommitAction(pending, result)" },
689
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "ISC_SHOWUICOMPOSITIONWINDOW" },
690
+ });
691
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-text-command-bridge", "Verify AppKit GPU text widgets route native text commands", &.{
692
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
693
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
694
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
695
+ });
696
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-appearance-bridge", "Verify AppKit reports system light and dark appearance changes", &.{
697
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "effectiveAppearance" },
698
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityDisplayShouldReduceMotion" },
699
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "accessibilityDisplayShouldIncreaseContrast" },
700
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NATIVE_SDK_APPKIT_EVENT_APPEARANCE_CHANGED" },
701
+ .{ .path = "src/platform/macos/root.zig", .pattern = ".reduce_motion = event.reduce_motion != 0" },
702
+ .{ .path = "src/platform/macos/root.zig", .pattern = ".high_contrast = event.high_contrast != 0" },
703
+ .{ .path = "src/platform/macos/root.zig", .pattern = ".appearance_changed => state.emit" },
704
+ });
705
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-builtin-bridge-policy", "Verify bridge policy docs include guarded dialog commands", &.{
706
+ .{ .path = "docs/src/app/security/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
707
+ .{ .path = "docs/src/app/bridge/builtin-commands/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
708
+ });
709
+
710
+ addTestStep(b, "test-geometry", "Run geometry module tests", geometry_tests);
711
+ addTestStep(b, "test-assets", "Run assets module tests", assets_tests);
712
+ addTestStep(b, "test-app-dirs", "Run app directory module tests", app_dirs_tests);
713
+ addTestStep(b, "test-trace", "Run trace module tests", trace_tests);
714
+ addTestStep(b, "test-app-manifest", "Run app manifest module tests", app_manifest_tests);
715
+ addTestStep(b, "test-diagnostics", "Run diagnostics module tests", diagnostics_tests);
716
+ addTestStep(b, "test-platform-info", "Run platform info module tests", platform_info_tests);
717
+ addTestStep(b, "test-json", "Run JSON primitive tests", json_tests);
718
+ addTestStep(b, "test-canvas", "Run canvas display list tests", canvas_tests);
719
+ addTestStep(b, "test-desktop", "Run Native SDK framework tests", desktop_tests);
720
+ for (desktop_test_shard_specs, desktop_test_shards) |spec, shard_tests| {
721
+ addTestStep(b, b.fmt("test-desktop-{s}", .{spec.name}), spec.description, shard_tests);
722
+ }
723
+ addTestStep(b, "test-automation-protocol", "Run automation protocol tests", automation_protocol_tests);
724
+ addTestStep(b, "test-automation-cli", "Run native automate CLI tests", automation_cli_tests);
725
+ addTestStep(b, "test-tooling", "Run Native SDK tooling tests", tooling_tests);
726
+ addTestStep(b, "test-eject-components", "Run ejected-component widget-identity tests", eject_components_tests);
727
+
728
+ const run_hello = b.addSystemCommand(&.{ "zig", "build", "run", b.fmt("-Dplatform={s}", .{platform_arg}), b.fmt("-Dtrace={s}", .{@tagName(trace_option)}) });
729
+ run_hello.setCwd(b.path("examples/hello"));
730
+ const run_hello_step = b.step("run-hello", "Run the native-sdk hello WebView example");
731
+ run_hello_step.dependOn(&run_hello.step);
732
+
733
+ const run_webview = b.addSystemCommand(&.{ "zig", "build", "run", b.fmt("-Dplatform={s}", .{platform_arg}), b.fmt("-Dtrace={s}", .{@tagName(trace_option)}), b.fmt("-Dweb-engine={s}", .{@tagName(web_engine)}), b.fmt("-Dcef-dir={s}", .{exampleCefDir(b, cef_dir)}) });
734
+ run_webview.setCwd(b.path("examples/webview"));
735
+ const run_webview_step = b.step("run-webview", "Run the native-sdk WebView example");
736
+ run_webview_step.dependOn(&run_webview.step);
737
+
738
+ const browser_cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, "third_party/cef/macos");
739
+ const run_browser = b.addSystemCommand(&.{ "zig", "build", "run", b.fmt("-Dplatform={s}", .{platform_arg}), b.fmt("-Dtrace={s}", .{@tagName(trace_option)}), b.fmt("-Dweb-engine={s}", .{@tagName(browser_web_engine)}), b.fmt("-Dcef-dir={s}", .{exampleCefDir(b, browser_cef_dir)}) });
740
+ run_browser.setCwd(b.path("examples/browser"));
741
+ const run_browser_step = b.step("run-browser", "Run the native-sdk browser example");
742
+ run_browser_step.dependOn(&run_browser.step);
743
+
744
+ const build_webview_system = b.addSystemCommand(&.{ "zig", "build", b.fmt("-Dplatform={s}", .{platform_arg}), "-Dweb-engine=system" });
745
+ build_webview_system.setCwd(b.path("examples/webview"));
746
+ const webview_system_link_step = b.step("test-webview-system-link", "Build the WebView example with the system engine");
747
+ webview_system_link_step.dependOn(&build_webview_system.step);
748
+
749
+ const build_browser_system = b.addSystemCommand(&.{ "zig", "build", b.fmt("-Dplatform={s}", .{platform_arg}), "-Dweb-engine=system" });
750
+ build_browser_system.setCwd(b.path("examples/browser"));
751
+ const browser_system_link_step = b.step("test-browser-system-link", "Build the browser example with the system engine");
752
+ browser_system_link_step.dependOn(&build_browser_system.step);
753
+
754
+ const frontend_examples_step = b.step("test-examples-frontends", "Run frontend example tests");
755
+ addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-next", "Run Next example tests", "examples/next", .owned);
756
+ addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-react", "Run React example tests", "examples/react", .owned);
757
+ addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-svelte", "Run Svelte example tests", "examples/svelte", .owned);
758
+ addExampleTestStep(b, host_cli_exe, frontend_examples_step, "test-example-vue", "Run Vue example tests", "examples/vue", .owned);
759
+ addFileContainsCheckStep(b, file_contains_checker, frontend_examples_step, "test-example-frontend-positioning", "Verify frontend example native shell positioning", &.{
760
+ .{ .path = "examples/next/README.md", .pattern = "opens the native app shell with WebView content." },
761
+ .{ .path = "examples/react/README.md", .pattern = "opens the native app shell with WebView content." },
762
+ .{ .path = "examples/svelte/README.md", .pattern = "opens the native app shell with WebView content." },
763
+ .{ .path = "examples/vue/README.md", .pattern = "opens the native app shell with WebView content." },
764
+ });
765
+
766
+ const native_examples_step = b.step("test-examples-native", "Run native-first example tests");
767
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-command-app", "Run command app example tests", "examples/command-app", .owned);
768
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-native-shell", "Run native shell example tests", "examples/native-shell", .owned);
769
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-native-panels", "Run native panels example tests", "examples/native-panels", .owned);
770
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-surface", "Run GPU surface example tests", "examples/gpu-surface", .managed);
771
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-dashboard", "Run GPU dashboard example tests", "examples/gpu-dashboard", .managed);
772
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-components", "Run GPU components example tests", "examples/gpu-components", .managed);
773
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-ui-inbox", "Run ui builder inbox example tests", "examples/ui-inbox", .owned);
774
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed);
775
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed);
776
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed);
777
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed);
778
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed);
779
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed);
780
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed);
781
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed);
782
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
783
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
784
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
785
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
786
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-capabilities", "Run capabilities example tests", "examples/capabilities", .owned);
787
+ addFileContainsCheckStep(b, file_contains_checker, native_examples_step, "test-example-capabilities-events", "Verify capabilities example event bridge names", &.{
788
+ .{ .path = "examples/capabilities/src/main.zig", .pattern = "native-sdk:drop:files" },
789
+ });
790
+
791
+ const mobile_examples_step = b.step("test-examples-mobile", "Verify mobile example project layouts");
792
+ addLayoutCheckStep(b, mobile_examples_step, "test-example-ios-layout", "Verify iOS example layout", &.{
793
+ "examples/ios/README.md",
794
+ "examples/ios/app.zon",
795
+ "examples/ios/NativeSdkIOSExample.xcodeproj/project.pbxproj",
796
+ "examples/ios/NativeSdkIOSExample/AppDelegate.swift",
797
+ "examples/ios/NativeSdkIOSExample/SceneDelegate.swift",
798
+ "examples/ios/NativeSdkIOSExample/NativeSdkHostViewController.swift",
799
+ "examples/ios/NativeSdkIOSExample/native_sdk.h",
800
+ "examples/ios/NativeSdkIOSExample/NativeSdkDyldShim.c",
801
+ });
802
+ addLayoutCheckStep(b, mobile_examples_step, "test-example-android-layout", "Verify Android example layout", &.{
803
+ "examples/android/README.md",
804
+ "examples/android/app.zon",
805
+ "examples/android/settings.gradle",
806
+ "examples/android/build.gradle",
807
+ "examples/android/app/build.gradle",
808
+ "examples/android/app/src/main/AndroidManifest.xml",
809
+ "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt",
810
+ "examples/android/app/src/main/cpp/CMakeLists.txt",
811
+ "examples/android/app/src/main/cpp/native_sdk_jni.c",
812
+ "examples/android/app/src/main/cpp/native_sdk.h",
813
+ });
814
+ addLayoutCheckStep(b, mobile_examples_step, "test-example-mobile-shell-layout", "Verify shared mobile-shell metadata", &.{
815
+ "examples/mobile-shell/README.md",
816
+ "examples/mobile-shell/app.zon",
817
+ });
818
+
819
+ // Host-tier packaged project pin: `native package --target ios` must
820
+ // keep emitting the complete, deterministic Xcode project (toolkit
821
+ // host sources, Info.plist, asset catalog, scheme) — drift is caught
822
+ // here. --binary stubs the embed library with the fixed-shell lib so
823
+ // the check needs no iOS cross-compile.
824
+ const package_ios_layout_run = b.addRunArtifact(host_cli_exe);
825
+ package_ios_layout_run.setCwd(b.path("examples/calculator"));
826
+ package_ios_layout_run.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot("."));
827
+ package_ios_layout_run.addArgs(&.{ "package", "--target", "ios", "--output", "zig-out/package/test-ios-layout", "--binary" });
828
+ package_ios_layout_run.addFileArg(embed_lib.getEmittedBin());
829
+ package_ios_layout_run.has_side_effects = true;
830
+ const package_ios_layout_step = b.step("test-package-ios-layout", "Verify the generated iOS host project layout");
831
+ const package_ios_layout_paths = [_][]const u8{
832
+ "examples/calculator/zig-out/package/test-ios-layout/calculator.xcodeproj/project.pbxproj",
833
+ "examples/calculator/zig-out/package/test-ios-layout/calculator.xcodeproj/xcshareddata/xcschemes/calculator.xcscheme",
834
+ "examples/calculator/zig-out/package/test-ios-layout/Host/uikit_host.m",
835
+ "examples/calculator/zig-out/package/test-ios-layout/Host/native_sdk_app.h",
836
+ "examples/calculator/zig-out/package/test-ios-layout/Host/Info.plist",
837
+ "examples/calculator/zig-out/package/test-ios-layout/Assets.xcassets/AppIcon.appiconset/AppIcon.png",
838
+ "examples/calculator/zig-out/package/test-ios-layout/Assets.xcassets/AppIcon.appiconset/Contents.json",
839
+ "examples/calculator/zig-out/package/test-ios-layout/Libraries/libnative-sdk.a",
840
+ "examples/calculator/zig-out/package/test-ios-layout/README.md",
841
+ "examples/calculator/zig-out/package/test-ios-layout/package-manifest.zon",
842
+ };
843
+ for (package_ios_layout_paths) |path| {
844
+ const check = b.addSystemCommand(&.{ "test", "-f", path });
845
+ check.step.dependOn(&package_ios_layout_run.step);
846
+ package_ios_layout_step.dependOn(&check.step);
847
+ mobile_examples_step.dependOn(&check.step);
848
+ }
849
+ const package_ios_layout_contents = [_]FileContainsCheck{
850
+ .{ .path = "examples/calculator/zig-out/package/test-ios-layout/calculator.xcodeproj/project.pbxproj", .pattern = "PRODUCT_BUNDLE_IDENTIFIER = \"dev.native-sdk.calculator\";" },
851
+ .{ .path = "examples/calculator/zig-out/package/test-ios-layout/Host/Info.plist", .pattern = "UILaunchScreen" },
852
+ .{ .path = "examples/calculator/zig-out/package/test-ios-layout/Host/uikit_host.m", .pattern = "native_sdk_app_render_pixels" },
853
+ };
854
+ for (package_ios_layout_contents) |check_value| {
855
+ const check = b.addRunArtifact(file_contains_checker);
856
+ check.setCwd(b.path("."));
857
+ check.addArg(check_value.path);
858
+ check.addArg(check_value.pattern);
859
+ check.step.dependOn(&package_ios_layout_run.step);
860
+ package_ios_layout_step.dependOn(&check.step);
861
+ mobile_examples_step.dependOn(&check.step);
862
+ }
863
+ // Host-tier packaged project pin, Android: `native package --target
864
+ // android` must keep emitting the complete generated host project
865
+ // (toolkit host sources, app.zon-derived manifest, launcher icons) —
866
+ // drift is caught here. --binary stubs the embed library with the
867
+ // fixed-shell lib so the check needs no Android cross-compile, and
868
+ // ANDROID_HOME points at a nonexistent SDK so the deterministic
869
+ // project-only path runs everywhere (the APK assembly is exercised
870
+ // by the live loops, not CI).
871
+ const package_android_layout_run = b.addRunArtifact(host_cli_exe);
872
+ package_android_layout_run.setCwd(b.path("examples/calculator"));
873
+ package_android_layout_run.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot("."));
874
+ package_android_layout_run.setEnvironmentVariable("ANDROID_HOME", b.pathFromRoot("zig-out/no-android-sdk"));
875
+ package_android_layout_run.addArgs(&.{ "package", "--target", "android", "--output", "zig-out/package/test-android-layout", "--binary" });
876
+ package_android_layout_run.addFileArg(embed_lib.getEmittedBin());
877
+ package_android_layout_run.has_side_effects = true;
878
+ const package_android_layout_step = b.step("test-package-android-layout", "Verify the generated Android host project layout");
879
+ const package_android_layout_paths = [_][]const u8{
880
+ "examples/calculator/zig-out/package/test-android-layout/AndroidManifest.xml",
881
+ "examples/calculator/zig-out/package/test-android-layout/Host/NativeSdkActivity.java",
882
+ "examples/calculator/zig-out/package/test-android-layout/Host/android_host.c",
883
+ "examples/calculator/zig-out/package/test-android-layout/Host/native_sdk_app.h",
884
+ "examples/calculator/zig-out/package/test-android-layout/res/mipmap-mdpi/ic_launcher.png",
885
+ "examples/calculator/zig-out/package/test-android-layout/res/mipmap-xxxhdpi/ic_launcher.png",
886
+ "examples/calculator/zig-out/package/test-android-layout/Libraries/libnative-sdk.a",
887
+ "examples/calculator/zig-out/package/test-android-layout/README.md",
888
+ "examples/calculator/zig-out/package/test-android-layout/package-manifest.zon",
889
+ };
890
+ for (package_android_layout_paths) |path| {
891
+ const check = b.addSystemCommand(&.{ "test", "-f", path });
892
+ check.step.dependOn(&package_android_layout_run.step);
893
+ package_android_layout_step.dependOn(&check.step);
894
+ mobile_examples_step.dependOn(&check.step);
895
+ }
896
+ const package_android_layout_contents = [_]FileContainsCheck{
897
+ .{ .path = "examples/calculator/zig-out/package/test-android-layout/AndroidManifest.xml", .pattern = "package=\"dev.native_sdk.calculator\"" },
898
+ .{ .path = "examples/calculator/zig-out/package/test-android-layout/AndroidManifest.xml", .pattern = "dev.native_sdk.host.NativeSdkActivity" },
899
+ .{ .path = "examples/calculator/zig-out/package/test-android-layout/Host/NativeSdkActivity.java", .pattern = "InputMethodManager" },
900
+ .{ .path = "examples/calculator/zig-out/package/test-android-layout/Host/android_host.c", .pattern = "native_sdk_app_render_pixels" },
901
+ };
902
+ for (package_android_layout_contents) |check_value| {
903
+ const check = b.addRunArtifact(file_contains_checker);
904
+ check.setCwd(b.path("."));
905
+ check.addArg(check_value.path);
906
+ check.addArg(check_value.pattern);
907
+ check.step.dependOn(&package_android_layout_run.step);
908
+ package_android_layout_step.dependOn(&check.step);
909
+ mobile_examples_step.dependOn(&check.step);
910
+ }
911
+ addFileContainsCheckStep(b, file_contains_checker, mobile_examples_step, "test-example-mobile-shell-metadata", "Verify shared mobile-shell metadata values", &.{
912
+ .{ .path = "examples/mobile-shell/app.zon", .pattern = ".platforms = .{ \"ios\", \"android\" }" },
913
+ .{ .path = "examples/mobile-shell/app.zon", .pattern = ".capabilities = .{ \"webview\", \"native_views\", \"native_module\" }" },
914
+ .{ .path = "examples/mobile-shell/app.zon", .pattern = ".id = \"mobile.back\"" },
915
+ .{ .path = "examples/mobile-shell/app.zon", .pattern = ".id = \"mobile.refresh\"" },
916
+ .{ .path = "examples/mobile-shell/app.zon", .pattern = ".label = \"mobile-header\"" },
917
+ .{ .path = "examples/mobile-shell/app.zon", .pattern = ".label = \"workspace\", .kind = \"webview\"" },
918
+ });
919
+ addFileContainsCheckStep(b, file_contains_checker, mobile_examples_step, "test-example-mobile-host-commands", "Verify mobile host command metadata values", &.{
920
+ .{ .path = "examples/ios/app.zon", .pattern = ".id = \"mobile.back\"" },
921
+ .{ .path = "examples/ios/app.zon", .pattern = ".id = \"mobile.refresh\"" },
922
+ .{ .path = "examples/ios/app.zon", .pattern = ".label = \"mobile-header\"" },
923
+ .{ .path = "examples/android/app.zon", .pattern = ".id = \"mobile.back\"" },
924
+ .{ .path = "examples/android/app.zon", .pattern = ".id = \"mobile.refresh\"" },
925
+ .{ .path = "examples/android/app.zon", .pattern = ".label = \"mobile-header\"" },
926
+ });
927
+ addFileContainsCheckStep(b, file_contains_checker, mobile_examples_step, "test-example-android-widget-ime", "Verify Android retained widget IME and action bridge", &.{
928
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "override fun onCreateInputConnection" },
929
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "nativeIme(nativeApp, kind, text, cursor)" },
930
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "WIDGET_ACTION_KIND_SET_COMPOSITION = 7" },
931
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "WIDGET_ACTION_DRAG = 1 shl 8" },
932
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "WIDGET_ACTION_DROP_FILES = 1 shl 9" },
933
+ });
934
+ addFileContainsCheckStep(b, file_contains_checker, mobile_examples_step, "test-example-mobile-widget-abi", "Verify mobile examples use stable widget ABI lookups", &.{
935
+ .{ .path = "examples/ios/NativeSdkIOSExample/native_sdk.h", .pattern = "native_sdk_viewport_state_t" },
936
+ .{ .path = "examples/ios/NativeSdkIOSExample/native_sdk.h", .pattern = "native_sdk_app_scroll" },
937
+ .{ .path = "examples/ios/NativeSdkIOSExample/native_sdk.h", .pattern = "native_sdk_app_set_text_measure" },
938
+ .{ .path = "examples/android/app/src/main/cpp/native_sdk.h", .pattern = "native_sdk_app_set_text_measure" },
939
+ .{ .path = "examples/mobile-canvas/ios/native_sdk_app.h", .pattern = "native_sdk_app_set_text_measure" },
940
+ .{ .path = "examples/ios/NativeSdkIOSExample/NativeSdkHostViewController.swift", .pattern = "native_sdk_app_widget_semantics_by_id" },
941
+ .{ .path = "examples/android/app/src/main/cpp/native_sdk.h", .pattern = "native_sdk_app_widget_semantics_by_id" },
942
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "nativeScroll(nativeApp" },
943
+ .{ .path = "examples/android/app/src/main/java/dev/native_sdk/examples/android/MainActivity.kt", .pattern = "nativeWidgetSemanticsByIdFields" },
944
+ .{ .path = "examples/android/app/src/main/cpp/native_sdk_jni.c", .pattern = "native_sdk_app_widget_semantics_by_id" },
945
+ .{ .path = "examples/android/app/src/main/cpp/native_sdk_jni.c", .pattern = "native_sdk_app_scroll" },
946
+ });
947
+ addFileContainsCheckStep(b, file_contains_checker, mobile_examples_step, "test-example-mobile-canvas-span-fonts", "Verify the iOS embed shim measures reserved span font ids with the macOS face mapping", &.{
948
+ .{ .path = "examples/mobile-canvas/ios/main.m", .pattern = "static UIFont *NativeSdkItalicSansFont(UIFont *font)" },
949
+ .{ .path = "examples/mobile-canvas/ios/main.m", .pattern = "static UIFont *NativeSdkWeightedSansFont(" },
950
+ .{ .path = "examples/mobile-canvas/ios/main.m", .pattern = "NativeSdkWeightedSansFont(@[ @\"Geist-Medium\", @\"Geist Medium\" ], UIFontWeightMedium, size)" },
951
+ .{ .path = "examples/mobile-canvas/ios/main.m", .pattern = "NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], UIFontWeightBold, size)" },
952
+ .{ .path = "examples/mobile-canvas/ios/main.m", .pattern = "NativeSdkItalicSansFont(NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], UIFontWeightBold, size))" },
953
+ });
954
+
955
+ const build_mobile_canvas_lib = b.addSystemCommand(&.{ "zig", "build", "lib" });
956
+ build_mobile_canvas_lib.setCwd(b.path("examples/mobile-canvas"));
957
+ const mobile_canvas_lib_step = b.step("test-example-mobile-canvas-lib", "Build the mobile-canvas embed static library through addMobileLib");
958
+ mobile_canvas_lib_step.dependOn(&build_mobile_canvas_lib.step);
959
+ mobile_examples_step.dependOn(&build_mobile_canvas_lib.step);
960
+
961
+ // Android cross-compile proof: pure Zig (no NDK sysroot — the static
962
+ // lib links no libc), PIC so the objects can land in the shim's .so.
963
+ const build_mobile_canvas_lib_android = b.addSystemCommand(&.{ "zig", "build", "lib", "-Dtarget=aarch64-linux-android" });
964
+ build_mobile_canvas_lib_android.setCwd(b.path("examples/mobile-canvas"));
965
+ const mobile_canvas_lib_android_step = b.step("test-example-mobile-canvas-lib-android", "Cross-compile the mobile-canvas embed static library for aarch64-linux-android");
966
+ mobile_canvas_lib_android_step.dependOn(&build_mobile_canvas_lib_android.step);
967
+ mobile_examples_step.dependOn(&build_mobile_canvas_lib_android.step);
968
+
969
+ const examples_step = b.step("test-examples", "Run all example tests and layout checks");
970
+ examples_step.dependOn(frontend_examples_step);
971
+ examples_step.dependOn(native_examples_step);
972
+ examples_step.dependOn(mobile_examples_step);
973
+
974
+ const build_webview_cef = b.addSystemCommand(&.{ "zig", "build", "-Dplatform=macos", "-Dweb-engine=chromium", b.fmt("-Dcef-dir={s}", .{exampleCefDir(b, cef_dir)}) });
975
+ build_webview_cef.setCwd(b.path("examples/webview"));
976
+ const webview_cef_link_step = b.step("test-webview-cef-link", "Build the WebView example with Chromium/CEF");
977
+ webview_cef_link_step.dependOn(&build_webview_cef.step);
978
+
979
+ const webview_smoke_step = b.step("test-webview-smoke", "Run macOS WebView automation smoke test");
980
+ const webview_smoke_build = b.addSystemCommand(&.{ "zig", "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Djs-bridge=true" });
981
+ webview_smoke_build.setCwd(b.path("examples/webview"));
982
+ const webview_smoke_run = b.addSystemCommand(&.{
983
+ "sh", "-c",
984
+ \\set -eu
985
+ \\cd examples/webview
986
+ \\app="zig-out/bin/webview"
987
+ \\cli="$1"
988
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
989
+ \\request='{"id":"smoke","command":"native.ping","payload":{"source":"smoke"}}'
990
+ \\response_file=".zig-cache/native-sdk-automation/bridge-response.txt"
991
+ \\mkdir -p .zig-cache/native-sdk-automation
992
+ \\rm -f .zig-cache/native-sdk-automation/snapshot.txt .zig-cache/native-sdk-automation/windows.txt .zig-cache/native-sdk-automation/command*.txt "$response_file"
993
+ \\printf 'bridge %s\n' "$request" > .zig-cache/native-sdk-automation/command-1.txt
994
+ \\"$app" > .zig-cache/native-sdk-webview-smoke.log 2>&1 &
995
+ \\pid=$!
996
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-webview-smoke.log) ----" >&2; cat .zig-cache/native-sdk-webview-smoke.log >&2 2>/dev/null || true; fi' EXIT
997
+ \\snapshot="$("$cli" automate wait 2>&1)"
998
+ \\case "$snapshot" in *"ready=true"*) ;; *) echo "automation snapshot was not ready" >&2; exit 1 ;; esac
999
+ \\attempts=0
1000
+ \\while [ "$attempts" -lt 50 ] && ! grep -q 'name="webview.load"' .zig-cache/native-sdk-webview-smoke.log; do attempts=$((attempts + 1)); sleep 0.1; done
1001
+ \\grep -q 'name="webview.load"' .zig-cache/native-sdk-webview-smoke.log || { echo "main window never loaded its webview source (blank window)" >&2; exit 1; }
1002
+ \\if grep -q 'name="dispatch.error"' .zig-cache/native-sdk-webview-smoke.log; then echo "runtime recorded a dispatch error during startup" >&2; exit 1; fi
1003
+ \\attempts=0
1004
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
1005
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
1006
+ \\case "$response" in *'"ok":true'*) ;; *) echo "native.ping did not succeed: $response" >&2; exit 1 ;; esac
1007
+ \\case "$response" in *'pong from Zig'*) ;; *) echo "native.ping response was unexpected: $response" >&2; exit 1 ;; esac
1008
+ \\rm -f "$response_file"
1009
+ \\printf 'bridge %s\n' '{"id":"webview-create","command":"native-sdk.webview.create","payload":{"label":"smoke","url":"https://example.com","frame":{"x":24,"y":24,"width":320,"height":220}}}' > .zig-cache/native-sdk-automation/command-1.txt
1010
+ \\attempts=0
1011
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
1012
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
1013
+ \\case "$response" in *'"ok":true'*) ;; *) echo "webview create did not succeed: $response" >&2; exit 1 ;; esac
1014
+ \\rm -f "$response_file"
1015
+ \\printf 'bridge %s\n' '{"id":"webview-resize","command":"native-sdk.webview.setFrame","payload":{"label":"smoke","frame":{"x":36,"y":36,"width":420,"height":260}}}' > .zig-cache/native-sdk-automation/command-1.txt
1016
+ \\attempts=0
1017
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
1018
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
1019
+ \\case "$response" in *'"ok":true'*) ;; *) echo "webview resize did not succeed: $response" >&2; exit 1 ;; esac
1020
+ \\rm -f "$response_file"
1021
+ \\printf 'bridge %s\n' '{"id":"webview-navigate","command":"native-sdk.webview.navigate","payload":{"label":"smoke","url":"https://example.com/?smoke=1"}}' > .zig-cache/native-sdk-automation/command-1.txt
1022
+ \\attempts=0
1023
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
1024
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
1025
+ \\case "$response" in *'"ok":true'*) ;; *) echo "webview navigate did not succeed: $response" >&2; exit 1 ;; esac
1026
+ \\rm -f "$response_file"
1027
+ \\printf 'bridge %s\n' '{"id":"webview-close","command":"native-sdk.webview.close","payload":{"label":"smoke"}}' > .zig-cache/native-sdk-automation/command-1.txt
1028
+ \\attempts=0
1029
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
1030
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
1031
+ \\case "$response" in *'"ok":true'*) ;; *) echo "webview close did not succeed: $response" >&2; exit 1 ;; esac
1032
+ \\echo "webview smoke ok"
1033
+ ,
1034
+ "sh",
1035
+ });
1036
+ webview_smoke_run.addFileArg(cli_exe.getEmittedBin());
1037
+ webview_smoke_run.step.dependOn(&webview_smoke_build.step);
1038
+ webview_smoke_run.step.dependOn(&cli_exe.step);
1039
+ webview_smoke_step.dependOn(&webview_smoke_run.step);
1040
+
1041
+ const native_shell_smoke_step = b.step("test-native-shell-smoke", "Run macOS native-shell automation smoke test");
1042
+ const native_shell_smoke_build = b.addSystemCommand(&.{ "zig", "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Djs-bridge=true" });
1043
+ native_shell_smoke_build.setCwd(b.path("examples/native-shell"));
1044
+ const native_shell_smoke_run = b.addSystemCommand(&.{
1045
+ "sh", "-c",
1046
+ \\set -eu
1047
+ \\cd examples/native-shell
1048
+ \\app="zig-out/bin/native-shell"
1049
+ \\cli="$1"
1050
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1051
+ \\automation_dir=".zig-cache/native-sdk-automation"
1052
+ \\response_file="$automation_dir/bridge-response.txt"
1053
+ \\mkdir -p "$automation_dir"
1054
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir/accessibility.txt" "$automation_dir/windows.txt" "$automation_dir"/command*.txt "$response_file"
1055
+ \\"$app" > .zig-cache/native-sdk-native-shell-smoke.log 2>&1 &
1056
+ \\pid=$!
1057
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-native-shell-smoke.log) ----" >&2; cat .zig-cache/native-sdk-native-shell-smoke.log >&2 2>/dev/null || true; fi' EXIT
1058
+ \\ready="$("$cli" automate wait 2>&1)"
1059
+ \\case "$ready" in *"ready=true"*) ;; *) echo "native-shell automation snapshot was not ready" >&2; exit 1 ;; esac
1060
+ \\snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1061
+ \\case "$snapshot" in *'window @w1 "Native SDK Native Shell"'*) ;; *) echo "native-shell window was missing from snapshot" >&2; exit 1 ;; esac
1062
+ \\case "$snapshot" in *'view @w1/toolbar kind=toolbar'*) ;; *) echo "toolbar view was missing from snapshot" >&2; exit 1 ;; esac
1063
+ \\case "$snapshot" in *'view @w1/sidebar kind=sidebar'*) ;; *) echo "sidebar view was missing from snapshot" >&2; exit 1 ;; esac
1064
+ \\case "$snapshot" in *'view @w1/main kind=webview'*) ;; *) echo "main WebView was missing from snapshot" >&2; exit 1 ;; esac
1065
+ \\case "$snapshot" in *'view @w1/statusbar kind=statusbar'*) ;; *) echo "statusbar view was missing from snapshot" >&2; exit 1 ;; esac
1066
+ \\case "$snapshot" in *'view @w1/refresh-icon kind=icon_button'*'accessibility_label="Refresh workspace"'*) ;; *) echo "refresh icon accessibility metadata was missing from snapshot" >&2; exit 1 ;; esac
1067
+ \\"$cli" automate focus refresh-button >/dev/null 2>&1
1068
+ \\attempts=0
1069
+ \\while [ "$attempts" -lt 50 ]; do
1070
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1071
+ \\ focus_line="$(printf '%s\n' "$snapshot" | grep -F 'view @w1/refresh-button kind=button' || true)"
1072
+ \\ case "$focus_line" in *'focused=true'*) break ;; esac
1073
+ \\ attempts=$((attempts + 1))
1074
+ \\ sleep 0.1
1075
+ \\done
1076
+ \\case "$focus_line" in *'focused=true'*) ;; *) echo "native-shell refresh button did not receive focus" >&2; exit 1 ;; esac
1077
+ \\"$cli" automate focus-next >/dev/null 2>&1
1078
+ \\attempts=0
1079
+ \\while [ "$attempts" -lt 50 ]; do
1080
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1081
+ \\ focus_line="$(printf '%s\n' "$snapshot" | grep -F 'view @w1/palette-button kind=button' || true)"
1082
+ \\ case "$focus_line" in *'focused=true'*) break ;; esac
1083
+ \\ attempts=$((attempts + 1))
1084
+ \\ sleep 0.1
1085
+ \\done
1086
+ \\case "$focus_line" in *'focused=true'*) ;; *) echo "native-shell focus-next did not move focus to palette button" >&2; exit 1 ;; esac
1087
+ \\"$cli" automate focus-previous >/dev/null 2>&1
1088
+ \\attempts=0
1089
+ \\while [ "$attempts" -lt 50 ]; do
1090
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1091
+ \\ focus_line="$(printf '%s\n' "$snapshot" | grep -F 'view @w1/refresh-button kind=button' || true)"
1092
+ \\ case "$focus_line" in *'focused=true'*) break ;; esac
1093
+ \\ attempts=$((attempts + 1))
1094
+ \\ sleep 0.1
1095
+ \\done
1096
+ \\case "$focus_line" in *'focused=true'*) ;; *) echo "native-shell focus-previous did not return focus to refresh button" >&2; exit 1 ;; esac
1097
+ \\"$cli" automate resize 900 640 >/dev/null 2>&1
1098
+ \\attempts=0
1099
+ \\while [ "$attempts" -lt 50 ]; do
1100
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1101
+ \\ case "$snapshot" in *'window @w1 "Native SDK Native Shell" bounds=('*' 900x640)'*) break ;; esac
1102
+ \\ attempts=$((attempts + 1))
1103
+ \\ sleep 0.1
1104
+ \\done
1105
+ \\case "$snapshot" in *'window @w1 "Native SDK Native Shell" bounds=('*' 900x640)'*) ;; *) echo "native-shell window resize was not reflected in snapshot" >&2; exit 1 ;; esac
1106
+ \\case "$snapshot" in *'view @w1/toolbar kind=toolbar'*'bounds=(0,0 900x52)'*) ;; *) echo "native-shell toolbar did not relayout after resize" >&2; exit 1 ;; esac
1107
+ \\case "$snapshot" in *'view @w1/main kind=webview'*'bounds=(240,52 660x548)'*) ;; *) echo "native-shell main WebView did not relayout after resize" >&2; exit 1 ;; esac
1108
+ \\case "$snapshot" in *'view @w1/statusbar kind=statusbar'*'bounds=(240,600 660x40)'*) ;; *) echo "native-shell statusbar did not relayout after resize" >&2; exit 1 ;; esac
1109
+ \\rm -f "$response_file"
1110
+ \\printf 'bridge %s\n' '{"id":"native-shell-refresh","command":"native-sdk.command.invoke","payload":{"name":"app.refresh"}}' > "$automation_dir/command-1.txt"
1111
+ \\attempts=0
1112
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
1113
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
1114
+ \\case "$response" in *'"ok":true'*'"name":"app.refresh"'*'"source":"bridge"'*) ;; *) echo "native-shell command bridge did not succeed: $response" >&2; exit 1 ;; esac
1115
+ \\attempts=0
1116
+ \\while [ "$attempts" -lt 50 ]; do
1117
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1118
+ \\ case "$snapshot" in *'Refreshed from bridge. Count 1.'*) break ;; esac
1119
+ \\ attempts=$((attempts + 1))
1120
+ \\ sleep 0.1
1121
+ \\done
1122
+ \\case "$snapshot" in *'view @w1/status-label kind=label'*'Refreshed from bridge. Count 1.'*) ;; *) echo "native-shell status view did not reflect bridge refresh" >&2; exit 1 ;; esac
1123
+ \\"$cli" automate menu-command app.refresh >/dev/null 2>&1
1124
+ \\attempts=0
1125
+ \\while [ "$attempts" -lt 50 ]; do
1126
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1127
+ \\ case "$snapshot" in *'Refreshed from menu. Count 2.'*) break ;; esac
1128
+ \\ attempts=$((attempts + 1))
1129
+ \\ sleep 0.1
1130
+ \\done
1131
+ \\case "$snapshot" in *'view @w1/status-label kind=label'*'Refreshed from menu. Count 2.'*) ;; *) echo "native-shell menu command did not update status" >&2; exit 1 ;; esac
1132
+ \\"$cli" automate native-command app.refresh refresh-button >/dev/null 2>&1
1133
+ \\attempts=0
1134
+ \\while [ "$attempts" -lt 50 ]; do
1135
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1136
+ \\ case "$snapshot" in *'Refreshed from toolbar. Count 3.'*) break ;; esac
1137
+ \\ attempts=$((attempts + 1))
1138
+ \\ sleep 0.1
1139
+ \\done
1140
+ \\case "$snapshot" in *'view @w1/status-label kind=label'*'Refreshed from toolbar. Count 3.'*) ;; *) echo "native-shell toolbar command did not update status" >&2; exit 1 ;; esac
1141
+ \\"$cli" automate shortcut app.refresh >/dev/null 2>&1
1142
+ \\attempts=0
1143
+ \\while [ "$attempts" -lt 50 ]; do
1144
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1145
+ \\ case "$snapshot" in *'Refreshed from shortcut. Count 4.'*) break ;; esac
1146
+ \\ attempts=$((attempts + 1))
1147
+ \\ sleep 0.1
1148
+ \\done
1149
+ \\case "$snapshot" in *'view @w1/status-label kind=label'*'Refreshed from shortcut. Count 4.'*) ;; *) echo "native-shell shortcut command did not update status" >&2; exit 1 ;; esac
1150
+ \\"$cli" automate menu-command app.preview.open >/dev/null 2>&1
1151
+ \\attempts=0
1152
+ \\while [ "$attempts" -lt 50 ]; do
1153
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1154
+ \\ case "$snapshot" in *'view @w1/preview kind=webview'*'bounds=(520,96 320x220)'*) break ;; esac
1155
+ \\ attempts=$((attempts + 1))
1156
+ \\ sleep 0.1
1157
+ \\done
1158
+ \\case "$snapshot" in *'view @w1/preview kind=webview'*'bounds=(520,96 320x220)'*) ;; *) echo "native-shell preview WebView was not created" >&2; exit 1 ;; esac
1159
+ \\"$cli" automate menu-command app.preview.close >/dev/null 2>&1
1160
+ \\attempts=0
1161
+ \\while [ "$attempts" -lt 50 ]; do
1162
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1163
+ \\ case "$snapshot" in *'view @w1/preview kind=webview'*) ;; *) break ;; esac
1164
+ \\ attempts=$((attempts + 1))
1165
+ \\ sleep 0.1
1166
+ \\done
1167
+ \\case "$snapshot" in *'view @w1/preview kind=webview'*) echo "native-shell preview WebView was not closed" >&2; exit 1 ;; *) ;; esac
1168
+ \\echo "native-shell smoke ok"
1169
+ ,
1170
+ "sh",
1171
+ });
1172
+ native_shell_smoke_run.addFileArg(cli_exe.getEmittedBin());
1173
+ native_shell_smoke_run.step.dependOn(&native_shell_smoke_build.step);
1174
+ native_shell_smoke_run.step.dependOn(&cli_exe.step);
1175
+ native_shell_smoke_step.dependOn(&native_shell_smoke_run.step);
1176
+
1177
+ const gpu_surface_smoke_step = b.step("test-gpu-surface-smoke", "Run macOS GPU surface automation smoke test");
1178
+ // The GPU smoke apps are managed examples (no build.zig of their own),
1179
+ // so their binaries come from the CLI verb. -Doptimize=Debug keeps the
1180
+ // smoke binary at the debug shape the in-dir builds used (`native
1181
+ // build` injects ReleaseFast when no optimize flag is passed).
1182
+ const gpu_surface_smoke_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
1183
+ gpu_surface_smoke_build.setCwd(b.path("examples/gpu-surface"));
1184
+ const gpu_surface_smoke_run = b.addSystemCommand(&.{
1185
+ "sh", "-c",
1186
+ \\set -eu
1187
+ \\cd examples/gpu-surface
1188
+ \\app="zig-out/bin/gpu-surface"
1189
+ \\cli="$1"
1190
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1191
+ \\automation_dir=".zig-cache/native-sdk-automation"
1192
+ \\mkdir -p "$automation_dir"
1193
+ \\# Startup latencies are load-sensitive on shared CI/agent machines.
1194
+ \\# NATIVE_SDK_SMOKE_BUDGET_MS raises the first-frame latency budget (default
1195
+ \\# stays 150 ms) and the automation-ready ceiling (default stays
1196
+ \\# 500 ms; the ceiling never drops below it) without weakening the
1197
+ \\# local defaults; every correctness assertion stays strict.
1198
+ \\smoke_budget_ms="${NATIVE_SDK_SMOKE_BUDGET_MS:-150}"
1199
+ \\case "$smoke_budget_ms" in ''|*[!0-9]*) echo "NATIVE_SDK_SMOKE_BUDGET_MS must be a positive integer of milliseconds: $smoke_budget_ms" >&2; exit 1 ;; esac
1200
+ \\if [ "$smoke_budget_ms" -le 0 ]; then echo "NATIVE_SDK_SMOKE_BUDGET_MS must be a positive integer of milliseconds: $smoke_budget_ms" >&2; exit 1; fi
1201
+ \\smoke_budget_ns=$((smoke_budget_ms * 1000000))
1202
+ \\ready_budget_ms="$smoke_budget_ms"
1203
+ \\if [ "$ready_budget_ms" -lt 500 ]; then ready_budget_ms=500; fi
1204
+ \\ready_budget_ns=$((ready_budget_ms * 1000000))
1205
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir/accessibility.txt" "$automation_dir/windows.txt" "$automation_dir"/command*.txt
1206
+ \\"$app" > .zig-cache/native-sdk-gpu-surface-smoke.log 2>&1 &
1207
+ \\pid=$!
1208
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-gpu-surface-smoke.log) ----" >&2; cat .zig-cache/native-sdk-gpu-surface-smoke.log >&2 2>/dev/null || true; fi' EXIT
1209
+ \\ready="$("$cli" automate wait 2>&1)"
1210
+ \\case "$ready" in *"ready=true"*) ;; *) echo "gpu-surface automation snapshot was not ready" >&2; exit 1 ;; esac
1211
+ \\ready_uptime="$(printf '%s\n' "$ready" | sed -n 's/.*runtime_uptime_ns=\([0-9][0-9]*\).*/\1/p')"
1212
+ \\case "$ready_uptime" in ''|*[!0-9]*) echo "gpu-surface automation ready uptime was missing" >&2; exit 1 ;; esac
1213
+ \\if [ "$ready_uptime" -le 0 ] || [ "$ready_uptime" -gt "$ready_budget_ns" ]; then echo "gpu-surface automation ready exceeded $ready_budget_ms ms: $ready_uptime ns" >&2; exit 1; fi
1214
+ \\snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1215
+ \\case "$snapshot" in *'window @w1 "Native SDK GPU Surface"'*) ;; *) echo "gpu-surface window was missing from snapshot" >&2; exit 1 ;; esac
1216
+ \\case "$snapshot" in *'view @w1/canvas kind=gpu_surface'*'accessibility_label="Animated GPU surface"'*) ;; *) echo "gpu_surface view was missing from snapshot" >&2; exit 1 ;; esac
1217
+ \\case "$snapshot" in *'view @w1/inspector kind=webview'*) ;; *) echo "inspector WebView was missing from snapshot" >&2; exit 1 ;; esac
1218
+ \\case "$snapshot" in *'view @w1/toolbar kind=toolbar'*) ;; *) echo "toolbar view was missing from snapshot" >&2; exit 1 ;; esac
1219
+ \\attempts=0
1220
+ \\while [ "$attempts" -lt 50 ]; do
1221
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1222
+ \\ case "$snapshot" in *'GPU frame 1 from canvas.'*) break ;; esac
1223
+ \\ attempts=$((attempts + 1))
1224
+ \\ sleep 0.1
1225
+ \\done
1226
+ \\case "$snapshot" in *'view @w1/status-label kind=label'*'GPU frame 1 from canvas.'*) ;; *) echo "gpu-surface frame event did not reach the runtime" >&2; exit 1 ;; esac
1227
+ \\case "$snapshot" in *'view @w1/canvas kind=gpu_surface'*'gpu_nonblank=true'*) ;; *) echo "gpu-surface frame was not verified as nonblank" >&2; exit 1 ;; esac
1228
+ \\first_frame_latency="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/canvas kind=gpu_surface.* gpu_first_frame_latency_ns=\([0-9][0-9]*\).*/\1/p')"
1229
+ \\case "$first_frame_latency" in ''|*[!0-9]*) echo "gpu-surface first frame latency was missing" >&2; exit 1 ;; esac
1230
+ \\if [ "$first_frame_latency" -le 0 ] || [ "$first_frame_latency" -gt "$smoke_budget_ns" ]; then echo "gpu-surface first frame exceeded $smoke_budget_ms ms: $first_frame_latency ns" >&2; exit 1; fi
1231
+ \\# The runtime publishes its own fixed 150 ms budget verdict. Within that
1232
+ \\# budget the verdict must agree exactly; beyond it (reachable only when
1233
+ \\# NATIVE_SDK_SMOKE_BUDGET_MS > 150) the runtime must report the overrun honestly.
1234
+ \\if [ "$first_frame_latency" -le 150000000 ]; then
1235
+ \\ case "$snapshot" in *'view @w1/canvas kind=gpu_surface'*'gpu_first_frame_latency_budget_ns=150000000'*'gpu_first_frame_latency_budget_exceeded=0'*'gpu_first_frame_latency_budget_ok=true'*) ;; *) echo "gpu-surface first frame exceeded the latency budget" >&2; exit 1 ;; esac
1236
+ \\else
1237
+ \\ case "$snapshot" in *'view @w1/canvas kind=gpu_surface'*'gpu_first_frame_latency_budget_ns=150000000'*'gpu_first_frame_latency_budget_ok=false'*) ;; *) echo "gpu-surface runtime did not report the first-frame budget overrun" >&2; exit 1 ;; esac
1238
+ \\fi
1239
+ \\"$cli" automate native-command gpu.refresh refresh >/dev/null 2>&1
1240
+ \\attempts=0
1241
+ \\while [ "$attempts" -lt 50 ]; do
1242
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1243
+ \\ case "$snapshot" in *'GPU surface refreshed from toolbar. Count 1.'*) break ;; esac
1244
+ \\ attempts=$((attempts + 1))
1245
+ \\ sleep 0.1
1246
+ \\done
1247
+ \\case "$snapshot" in *'view @w1/status-label kind=label'*'GPU surface refreshed from toolbar. Count 1.'*) ;; *) echo "gpu-surface refresh command did not update status" >&2; exit 1 ;; esac
1248
+ \\"$cli" automate resize 960 620 >/dev/null 2>&1
1249
+ \\attempts=0
1250
+ \\while [ "$attempts" -lt 50 ]; do
1251
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1252
+ \\ case "$snapshot" in *'window @w1 "Native SDK GPU Surface" bounds=('*' 960x620)'*) break ;; esac
1253
+ \\ attempts=$((attempts + 1))
1254
+ \\ sleep 0.1
1255
+ \\done
1256
+ \\case "$snapshot" in *'window @w1 "Native SDK GPU Surface" bounds=('*' 960x620)'*) ;; *) echo "gpu-surface window resize was not reflected in snapshot" >&2; exit 1 ;; esac
1257
+ \\case "$snapshot" in *'view @w1/canvas kind=gpu_surface'*'bounds=(0,0 680x534)'*) ;; *) echo "gpu_surface view did not relayout after resize" >&2; exit 1 ;; esac
1258
+ \\case "$snapshot" in *'view @w1/inspector kind=webview'*'bounds=(680,52 280x534)'*) ;; *) echo "inspector WebView did not relayout after resize" >&2; exit 1 ;; esac
1259
+ \\echo "gpu-surface smoke ok"
1260
+ ,
1261
+ "sh",
1262
+ });
1263
+ gpu_surface_smoke_run.addFileArg(cli_exe.getEmittedBin());
1264
+ gpu_surface_smoke_run.step.dependOn(&gpu_surface_smoke_build.step);
1265
+ gpu_surface_smoke_run.step.dependOn(&cli_exe.step);
1266
+ gpu_surface_smoke_step.dependOn(&gpu_surface_smoke_run.step);
1267
+
1268
+ const writeback_smoke_step = b.step("test-writeback-smoke", "Run macOS provenance + write-back automation smoke test");
1269
+ // Debug on purpose: the write-back loop lives on the markup
1270
+ // interpreter + hot-reload watch, which apps enable in Debug
1271
+ // (kanban's dev_markup_reload) - the release engine is compiled and
1272
+ // watchless by design.
1273
+ const writeback_smoke_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
1274
+ writeback_smoke_build.setCwd(b.path("examples/kanban"));
1275
+ const writeback_smoke_run = b.addSystemCommand(&.{
1276
+ "sh", "-c",
1277
+ \\set -eu
1278
+ \\cd examples/kanban
1279
+ \\app="zig-out/bin/kanban"
1280
+ \\cli="$1"
1281
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1282
+ \\automation_dir=".zig-cache/native-sdk-automation"
1283
+ \\mkdir -p "$automation_dir"
1284
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir"/command*.txt "$automation_dir/provenance.txt"
1285
+ \\# The smoke edits src/board.native through the write-back verb and restores
1286
+ \\# it through the same verb; the trap restores from the backup on ANY
1287
+ \\# failure so an aborted run never leaves the example dirty.
1288
+ \\cp src/board.native .zig-cache/board.native.smoke-backup
1289
+ \\"$app" > .zig-cache/native-sdk-writeback-smoke.log 2>&1 &
1290
+ \\pid=$!
1291
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; cp .zig-cache/board.native.smoke-backup src/board.native; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-writeback-smoke.log) ----" >&2; cat .zig-cache/native-sdk-writeback-smoke.log >&2 2>/dev/null || true; fi' EXIT
1292
+ \\"$cli" automate assert --timeout-ms 30000 'ready=true' >/dev/null
1293
+ \\snapshot="$(cat "$automation_dir/snapshot.txt")"
1294
+ \\button_id="$(printf '%s\n' "$snapshot" | sed -n 's/.*widget @w1\/kanban-canvas#\([0-9][0-9]*\) role=button name="Add card".*/\1/p' | head -n 1)"
1295
+ \\case "$button_id" in ''|*[!0-9]*) echo "writeback smoke: Add card button id was missing from the snapshot" >&2; exit 1 ;; esac
1296
+ \\# 1. Provenance: the button reports its authored span in the root file.
1297
+ \\provenance="$("$cli" automate provenance kanban-canvas "$button_id" 2>/dev/null)"
1298
+ \\case "$provenance" in *"authored=markup"*"root=src/board.native"*) ;; *) echo "writeback smoke: button provenance was not markup-authored: $provenance" >&2; exit 1 ;; esac
1299
+ \\case "$provenance" in *"node file=src/board.native"*) ;; *) echo "writeback smoke: button provenance named the wrong file: $provenance" >&2; exit 1 ;; esac
1300
+ \\# 2. Template + import chain: a card title reports its definition site in
1301
+ \\# the component file plus the <use> site in the root file, with the
1302
+ \\# for-loop iteration key.
1303
+ \\card_id="$(printf '%s\n' "$snapshot" | sed -n 's/.*widget @w1\/kanban-canvas#\([0-9][0-9]*\) role=text name="Sketch the board layout".*/\1/p' | head -n 1)"
1304
+ \\case "$card_id" in ''|*[!0-9]*) echo "writeback smoke: card text id was missing from the snapshot" >&2; exit 1 ;; esac
1305
+ \\card_provenance="$("$cli" automate provenance kanban-canvas "$card_id" 2>/dev/null)"
1306
+ \\case "$card_provenance" in *"node file=src/components/board-column.native"*) ;; *) echo "writeback smoke: card provenance missed the component file: $card_provenance" >&2; exit 1 ;; esac
1307
+ \\case "$card_provenance" in *"use file=src/board.native"*) ;; *) echo "writeback smoke: card provenance missed the use-site chain: $card_provenance" >&2; exit 1 ;; esac
1308
+ \\case "$card_provenance" in *"keys="*) ;; *) echo "writeback smoke: card provenance missed the iteration key: $card_provenance" >&2; exit 1 ;; esac
1309
+ \\# 3. Write-back: flip the button label through the verb; the app's own
1310
+ \\# hot-reload watch picks the file change up and repaints.
1311
+ \\"$cli" automate edit kanban-canvas "$button_id" set-text "Add task" >/dev/null 2>&1
1312
+ \\"$cli" automate assert --timeout-ms 15000 'role=button name="Add task"' >/dev/null
1313
+ \\# The file diff is byte-exact: exactly the label bytes changed.
1314
+ \\sed 's/>Add card</>Add task</' .zig-cache/board.native.smoke-backup > .zig-cache/board.native.smoke-expected
1315
+ \\cmp -s .zig-cache/board.native.smoke-expected src/board.native || { echo "writeback smoke: the edit was not minimal-diff" >&2; exit 1; }
1316
+ \\# 4. Flip it back through the same verb: the structural id survived the
1317
+ \\# reload (text is not identity), and the file restores byte-identical.
1318
+ \\"$cli" automate edit kanban-canvas "$button_id" set-text "Add card" >/dev/null 2>&1
1319
+ \\"$cli" automate assert --timeout-ms 15000 'role=button name="Add card"' >/dev/null
1320
+ \\cmp -s .zig-cache/board.native.smoke-backup src/board.native || { echo "writeback smoke: the flip-back did not restore the file byte-identically" >&2; exit 1; }
1321
+ \\# 5. Refusal: an edit that fails validation leaves the file untouched.
1322
+ \\if "$cli" automate edit kanban-canvas "$button_id" set-attr bogus 1 >/dev/null 2>&1; then echo "writeback smoke: an invalid edit was not refused" >&2; exit 1; fi
1323
+ \\cmp -s .zig-cache/board.native.smoke-backup src/board.native || { echo "writeback smoke: a refused edit touched the file" >&2; exit 1; }
1324
+ \\echo "writeback smoke ok"
1325
+ ,
1326
+ "sh",
1327
+ });
1328
+ writeback_smoke_run.addFileArg(cli_exe.getEmittedBin());
1329
+ writeback_smoke_run.step.dependOn(&writeback_smoke_build.step);
1330
+ writeback_smoke_run.step.dependOn(&cli_exe.step);
1331
+ writeback_smoke_step.dependOn(&writeback_smoke_run.step);
1332
+
1333
+ const gpu_dashboard_smoke_step = b.step("test-gpu-dashboard-smoke", "Run macOS GPU dashboard automation smoke test");
1334
+ const gpu_dashboard_smoke_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
1335
+ gpu_dashboard_smoke_build.setCwd(b.path("examples/gpu-dashboard"));
1336
+ const gpu_dashboard_smoke_run = b.addSystemCommand(&.{
1337
+ "sh", "-c",
1338
+ \\set -eu
1339
+ \\cd examples/gpu-dashboard
1340
+ \\app="zig-out/bin/gpu-dashboard"
1341
+ \\cli="$1"
1342
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1343
+ \\automation_dir=".zig-cache/native-sdk-automation"
1344
+ \\mkdir -p "$automation_dir"
1345
+ \\# First-frame latency is load-sensitive: a cold file cache or CI/agent
1346
+ \\# machine contention can blow the 150 ms budget while the frame itself
1347
+ \\# is presented and correct. Load tolerance without weakening the proof:
1348
+ \\# (a) NATIVE_SDK_SMOKE_BUDGET_MS raises the smoke's latency budget (default
1349
+ \\# stays 150 ms) and the automation-ready ceiling (default stays
1350
+ \\# 500 ms; the ceiling never drops below it), and
1351
+ \\# (b) a budget-only overrun relaunches the app once and re-measures.
1352
+ \\# Every correctness assertion (frame presented, packet-representable,
1353
+ \\# retained content, widget semantics) stays strict on whichever launch
1354
+ \\# survives, and the runtime's own fixed 150 ms budget verdict is still
1355
+ \\# asserted verbatim whenever the measured latency is within 150 ms.
1356
+ \\smoke_budget_ms="${NATIVE_SDK_SMOKE_BUDGET_MS:-150}"
1357
+ \\case "$smoke_budget_ms" in ''|*[!0-9]*) echo "NATIVE_SDK_SMOKE_BUDGET_MS must be a positive integer of milliseconds: $smoke_budget_ms" >&2; exit 1 ;; esac
1358
+ \\if [ "$smoke_budget_ms" -le 0 ]; then echo "NATIVE_SDK_SMOKE_BUDGET_MS must be a positive integer of milliseconds: $smoke_budget_ms" >&2; exit 1; fi
1359
+ \\smoke_budget_ns=$((smoke_budget_ms * 1000000))
1360
+ \\ready_budget_ms="$smoke_budget_ms"
1361
+ \\if [ "$ready_budget_ms" -lt 500 ]; then ready_budget_ms=500; fi
1362
+ \\ready_budget_ns=$((ready_budget_ms * 1000000))
1363
+ \\pid=""
1364
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-gpu-dashboard-smoke.log) ----" >&2; cat .zig-cache/native-sdk-gpu-dashboard-smoke.log >&2 2>/dev/null || true; fi' EXIT
1365
+ \\stop_app() {
1366
+ \\ kill "$pid" >/dev/null 2>&1 || true
1367
+ \\ wait "$pid" >/dev/null 2>&1 || true
1368
+ \\ pid=""
1369
+ \\}
1370
+ \\launch_and_measure_first_frame() {
1371
+ \\ rm -f "$automation_dir/snapshot.txt" "$automation_dir/accessibility.txt" "$automation_dir/windows.txt" "$automation_dir"/command*.txt
1372
+ \\ "$app" > .zig-cache/native-sdk-gpu-dashboard-smoke.log 2>&1 &
1373
+ \\ pid=$!
1374
+ \\ ready="$("$cli" automate wait 2>&1)"
1375
+ \\ case "$ready" in *"ready=true"*) ;; *) echo "gpu-dashboard automation snapshot was not ready" >&2; exit 1 ;; esac
1376
+ \\ ready_uptime="$(printf '%s\n' "$ready" | sed -n 's/.*runtime_uptime_ns=\([0-9][0-9]*\).*/\1/p')"
1377
+ \\ case "$ready_uptime" in ''|*[!0-9]*) echo "gpu-dashboard automation ready uptime was missing" >&2; exit 1 ;; esac
1378
+ \\ if [ "$ready_uptime" -le 0 ] || [ "$ready_uptime" -gt "$ready_budget_ns" ]; then echo "gpu-dashboard automation ready exceeded $ready_budget_ms ms: $ready_uptime ns" >&2; exit 1; fi
1379
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1380
+ \\ case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard"'*) ;; *) echo "gpu-dashboard window was missing from snapshot" >&2; exit 1 ;; esac
1381
+ \\ case "$snapshot" in *'view @w1/main kind=webview'*) echo "dashboard should not create an implicit main WebView" >&2; exit 1 ;; *) ;; esac
1382
+ \\ case "$snapshot" in *'source kind=html bytes=0'*) echo "dashboard should not publish an empty default WebView source" >&2; exit 1 ;; *) ;; esac
1383
+ \\ case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'accessibility_label="Native-rendered product dashboard canvas"'*) ;; *) echo "dashboard GPU canvas was missing from snapshot" >&2; exit 1 ;; esac
1384
+ \\ attempts=0
1385
+ \\ while [ "$attempts" -lt 50 ]; do
1386
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1387
+ \\ case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'gpu_nonblank=true'*'canvas_commands=68'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1388
+ \\ attempts=$((attempts + 1))
1389
+ \\ sleep 0.1
1390
+ \\ done
1391
+ \\ case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'gpu_nonblank=true'*'canvas_commands=68'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "dashboard GPU canvas did not present the retained display list as a packet" >&2; exit 1 ;; esac
1392
+ \\ case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'canvas_commands=68'*'widget_semantics=48'*) ;; *) echo "dashboard GPU canvas was missing retained commands or widget semantics" >&2; exit 1 ;; esac
1393
+ \\ first_frame_latency="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/dashboard-canvas kind=gpu_surface.* gpu_first_frame_latency_ns=\([0-9][0-9]*\).*/\1/p')"
1394
+ \\ case "$first_frame_latency" in ''|*[!0-9]*) echo "dashboard GPU first frame latency was missing" >&2; exit 1 ;; esac
1395
+ \\ if [ "$first_frame_latency" -le 0 ]; then echo "dashboard GPU first frame latency was not recorded" >&2; exit 1; fi
1396
+ \\}
1397
+ \\launch_and_measure_first_frame
1398
+ \\if [ "$first_frame_latency" -gt "$smoke_budget_ns" ]; then
1399
+ \\ echo "dashboard GPU first frame exceeded $smoke_budget_ms ms ($first_frame_latency ns); relaunching once to rule out machine load" >&2
1400
+ \\ stop_app
1401
+ \\ launch_and_measure_first_frame
1402
+ \\fi
1403
+ \\if [ "$first_frame_latency" -gt "$smoke_budget_ns" ]; then echo "dashboard GPU first frame exceeded $smoke_budget_ms ms on both launches: $first_frame_latency ns" >&2; exit 1; fi
1404
+ \\# The runtime publishes its own fixed 150 ms budget verdict. Within that
1405
+ \\# budget the verdict must agree exactly; beyond it (reachable only when
1406
+ \\# NATIVE_SDK_SMOKE_BUDGET_MS > 150) the runtime must report the overrun honestly.
1407
+ \\if [ "$first_frame_latency" -le 150000000 ]; then
1408
+ \\ case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'gpu_first_frame_latency_budget_ns=150000000'*'gpu_first_frame_latency_budget_exceeded=0'*'gpu_first_frame_latency_budget_ok=true'*) ;; *) echo "dashboard GPU first frame exceeded the latency budget" >&2; exit 1 ;; esac
1409
+ \\else
1410
+ \\ case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'gpu_first_frame_latency_budget_ns=150000000'*'gpu_first_frame_latency_budget_ok=false'*) ;; *) echo "dashboard runtime did not report the first-frame budget overrun" >&2; exit 1 ;; esac
1411
+ \\fi
1412
+ \\attempts=0
1413
+ \\while [ "$attempts" -lt 50 ]; do
1414
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1415
+ \\ case "$snapshot" in *'role=text name="Canvas frame:'*) break ;; esac
1416
+ \\ attempts=$((attempts + 1))
1417
+ \\ sleep 0.1
1418
+ \\done
1419
+ \\widget_line() {
1420
+ \\ printf '%s\n' "$snapshot" | grep -F "$1" | head -1
1421
+ \\}
1422
+ \\line="$(widget_line 'role=tab name="Dashboard mode"')"
1423
+ \\case "$line" in *'actions=[focus,press,select]'*) ;; *) echo "dashboard toolbar mode semantics were missing" >&2; exit 1 ;; esac
1424
+ \\line="$(widget_line 'role=button name="Refresh dashboard"')"
1425
+ \\case "$line" in *'actions=[focus,press]'*) ;; *) echo "dashboard toolbar refresh semantics were missing" >&2; exit 1 ;; esac
1426
+ \\# CoreText-backed layout metrics: the refresh button must be sized by the
1427
+ \\# platform text measure provider, not the deterministic estimator
1428
+ \\# (estimateTextWidthForFont sizes "Refresh" at 14px to 51.842 -> 75.841995 wide).
1429
+ \\case "$line" in *'75.841995x34'*) echo "dashboard refresh button was sized by the estimator; platform text measurement is inactive" >&2; exit 1 ;; esac
1430
+ \\refresh_width="$(printf '%s\n' "$line" | sed -n 's/.*bounds=([0-9.,-]* \([0-9.]*\)x[0-9.]*).*/\1/p')"
1431
+ \\case "$refresh_width" in ''|*[!0-9.]*) echo "dashboard refresh button width was missing" >&2; exit 1 ;; esac
1432
+ \\if [ "$(printf '%s\n' "$refresh_width < 50 || $refresh_width > 110" | bc)" -eq 1 ]; then echo "dashboard refresh button width was implausible: $refresh_width" >&2; exit 1; fi
1433
+ \\line="$(widget_line 'role=button name="Live render status"')"
1434
+ \\case "$line" in *'actions=[focus,press]'*) ;; *) echo "dashboard live render button semantics were missing" >&2; exit 1 ;; esac
1435
+ \\line="$(widget_line 'role=textbox name="Forecast amount"')"
1436
+ \\case "$line" in *'text="$13.4M"'*) ;; *) echo "dashboard forecast textbox semantics were missing" >&2; exit 1 ;; esac
1437
+ \\line="$(widget_line 'role=dialog name="Revenue filter popover"')"
1438
+ \\case "$line" in '') echo "dashboard popover semantics were missing" >&2; exit 1 ;; esac
1439
+ \\line="$(widget_line 'role=text name="Canvas frame:')"
1440
+ \\case "$line" in *'packet ok'*) ;; *) echo "dashboard canvas status semantics were missing" >&2; exit 1 ;; esac
1441
+ \\gpu_frame_from_snapshot() {
1442
+ \\ printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/dashboard-canvas kind=gpu_surface.* gpu_frame=\([0-9][0-9]*\).*/\1/p'
1443
+ \\}
1444
+ \\canvas_revision_from_snapshot() {
1445
+ \\ printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/dashboard-canvas kind=gpu_surface.* canvas_revision=\([0-9][0-9]*\).*/\1/p'
1446
+ \\}
1447
+ \\snapshot_contains() {
1448
+ \\ case "$snapshot" in *"$1"*) return 0 ;; *) return 1 ;; esac
1449
+ \\}
1450
+ \\canvas_revision_before_resize="$(canvas_revision_from_snapshot)"
1451
+ \\case "$canvas_revision_before_resize" in ''|*[!0-9]*) echo "dashboard canvas revision was missing before resize" >&2; exit 1 ;; esac
1452
+ \\"$cli" automate resize 1120 700 >/dev/null 2>&1
1453
+ \\attempts=0
1454
+ \\while [ "$attempts" -lt 50 ]; do
1455
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1456
+ \\ case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard" bounds=('*' 1120x700)'*'view @w1/dashboard-canvas kind=gpu_surface'*'bounds=(0,0 1120x700)'*'gpu_nonblank=true'*'canvas_commands=68'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1457
+ \\ attempts=$((attempts + 1))
1458
+ \\ sleep 0.1
1459
+ \\done
1460
+ \\case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard" bounds=('*' 1120x700)'*) ;; *) echo "dashboard window resize was not reflected in snapshot" >&2; exit 1 ;; esac
1461
+ \\case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'bounds=(0,0 1120x700)'*) ;; *) echo "dashboard GPU canvas did not relayout after resize" >&2; exit 1 ;; esac
1462
+ \\case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'gpu_nonblank=true'*'canvas_commands=68'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "dashboard GPU canvas did not remain packet-renderable after resize" >&2; exit 1 ;; esac
1463
+ \\canvas_revision_after_resize="$(canvas_revision_from_snapshot)"
1464
+ \\case "$canvas_revision_after_resize" in ''|*[!0-9]*) echo "dashboard canvas revision was missing after resize" >&2; exit 1 ;; esac
1465
+ \\if [ "$canvas_revision_after_resize" -lt "$canvas_revision_before_resize" ]; then echo "dashboard canvas revision went backwards after resize: $canvas_revision_before_resize -> $canvas_revision_after_resize" >&2; exit 1; fi
1466
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1467
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1468
+ \\gpu_frame_after="$gpu_frame_before"
1469
+ \\switch_id="$(printf '%s\n' "$snapshot" | sed -n 's/.*widget @w1\/dashboard-canvas#\([0-9][0-9]*\) role=switch name="Auto refresh".*/\1/p' | head -1)"
1470
+ \\case "$switch_id" in ''|*[!0-9]*) echo "dashboard auto refresh switch id was missing from snapshot" >&2; exit 1 ;; esac
1471
+ \\"$cli" automate widget-click dashboard-canvas "$switch_id" >/dev/null 2>&1
1472
+ \\attempts=0
1473
+ \\while [ "$attempts" -lt 50 ]; do
1474
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1475
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1476
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1477
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ]; then
1478
+ \\ if snapshot_contains 'Auto refresh off.' && snapshot_contains 'view @w1/dashboard-canvas kind=gpu_surface' && snapshot_contains 'canvas_frame_full_repaint=false' && snapshot_contains 'canvas_frame_pipeline_uploads=0' && snapshot_contains 'canvas_frame_glyph_uploads=0' && snapshot_contains 'canvas_frame_text_uploads=0' && snapshot_contains 'canvas_frame_gpu_packet_unsupported=0' && snapshot_contains 'canvas_frame_gpu_packet_representable=true'; then
1479
+ \\ switch_line="$(printf '%s\n' "$snapshot" | grep -F 'role=switch name="Auto refresh"' | head -1)"
1480
+ \\ case "$switch_line" in *'value=0'*) break ;; esac
1481
+ \\ fi
1482
+ \\ fi
1483
+ \\ attempts=$((attempts + 1))
1484
+ \\ sleep 0.1
1485
+ \\done
1486
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ]; then echo "dashboard switch click did not request a GPU frame" >&2; exit 1; fi
1487
+ \\case "$snapshot" in *'Auto refresh off.'*) ;; *) echo "dashboard switch click did not update status" >&2; exit 1 ;; esac
1488
+ \\switch_line="$(printf '%s\n' "$snapshot" | grep -F 'role=switch name="Auto refresh"' | head -1)"
1489
+ \\case "$switch_line" in *'value=0'*) ;; *) echo "dashboard switch click did not route through pointer input" >&2; exit 1 ;; esac
1490
+ \\case "$snapshot" in *'view @w1/dashboard-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "dashboard switch click did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1491
+ \\input_timestamp="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/dashboard-canvas kind=gpu_surface.* gpu_input_timestamp_ns=\([0-9][0-9]*\).*/\1/p')"
1492
+ \\case "$input_timestamp" in ''|*[!0-9]*) echo "dashboard GPU input timestamp was missing after widget interaction" >&2; exit 1 ;; esac
1493
+ \\if [ "$input_timestamp" -le 0 ]; then echo "dashboard GPU input timestamp was not recorded" >&2; exit 1; fi
1494
+ \\input_latency="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/dashboard-canvas kind=gpu_surface.* gpu_input_latency_ns=\([0-9][0-9]*\).*/\1/p')"
1495
+ \\case "$input_latency" in ''|*[!0-9]*) echo "dashboard GPU input latency was missing after widget interaction" >&2; exit 1 ;; esac
1496
+ \\# --- Incremental pixel equivalence: relaunch under the host's verify
1497
+ \\# mode, where every scissored dirty update is byte-compared against a
1498
+ \\# from-scratch full redraw of the retained command list. Clicks, the
1499
+ \\# live-pulse animation, and a mid-animation resize drive scissored
1500
+ \\# patches; the verify counters must show checks with zero mismatches.
1501
+ \\stop_app
1502
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir"/command*.txt
1503
+ \\verify_log=".zig-cache/native-sdk-gpu-dashboard-verify.log"
1504
+ \\NATIVE_SDK_GPU_VERIFY_INCREMENTAL=1 "$app" > "$verify_log" 2>&1 &
1505
+ \\pid=$!
1506
+ \\ready="$("$cli" automate wait 2>&1)"
1507
+ \\case "$ready" in *"ready=true"*) ;; *) echo "gpu-dashboard verify relaunch was not ready" >&2; exit 1 ;; esac
1508
+ \\snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1509
+ \\switch_id="$(printf '%s\n' "$snapshot" | sed -n 's/.*widget @w1\/dashboard-canvas#\([0-9][0-9]*\) role=switch name="Auto refresh".*/\1/p' | head -1)"
1510
+ \\live_id="$(printf '%s\n' "$snapshot" | sed -n 's/.*widget @w1\/dashboard-canvas#\([0-9][0-9]*\) role=button name="Live render status".*/\1/p' | head -1)"
1511
+ \\case "$switch_id" in ''|*[!0-9]*) echo "dashboard verify switch id was missing" >&2; exit 1 ;; esac
1512
+ \\case "$live_id" in ''|*[!0-9]*) echo "dashboard verify live button id was missing" >&2; exit 1 ;; esac
1513
+ \\"$cli" automate widget-click dashboard-canvas "$switch_id" >/dev/null 2>&1
1514
+ \\sleep 0.4
1515
+ \\"$cli" automate widget-click dashboard-canvas "$live_id" >/dev/null 2>&1
1516
+ \\sleep 0.3
1517
+ \\"$cli" automate resize 1120 700 >/dev/null 2>&1
1518
+ \\sleep 0.5
1519
+ \\"$cli" automate widget-click dashboard-canvas "$live_id" >/dev/null 2>&1
1520
+ \\attempts=0
1521
+ \\while [ "$attempts" -lt 50 ]; do
1522
+ \\ if grep -q "gpu incremental verify view=dashboard-canvas checks=" "$verify_log" 2>/dev/null; then break; fi
1523
+ \\ attempts=$((attempts + 1))
1524
+ \\ sleep 0.1
1525
+ \\done
1526
+ \\if ! grep -q "gpu incremental verify view=dashboard-canvas checks=" "$verify_log" 2>/dev/null; then echo "dashboard verify mode recorded no incremental checks" >&2; exit 1; fi
1527
+ \\if grep -q "verify MISMATCH" "$verify_log" 2>/dev/null; then echo "dashboard incremental present diverged from a full redraw:" >&2; grep "verify MISMATCH" "$verify_log" >&2; exit 1; fi
1528
+ \\if grep "gpu incremental verify view=dashboard-canvas checks=" "$verify_log" | grep -qv "mismatches=0"; then echo "dashboard incremental verify reported mismatches" >&2; exit 1; fi
1529
+ \\echo "gpu-dashboard smoke ok"
1530
+ ,
1531
+ "sh",
1532
+ });
1533
+ gpu_dashboard_smoke_run.addFileArg(cli_exe.getEmittedBin());
1534
+ gpu_dashboard_smoke_run.step.dependOn(&gpu_dashboard_smoke_build.step);
1535
+ gpu_dashboard_smoke_run.step.dependOn(&cli_exe.step);
1536
+ gpu_dashboard_smoke_step.dependOn(&gpu_dashboard_smoke_run.step);
1537
+
1538
+ // Percentile performance check — a single-sample gate was noise-dominated,
1539
+ // so this asserts p90 over N launches. Deliberately NOT part of
1540
+ // `zig build test` or the fast gate tier: N launches are slow and the
1541
+ // numbers only mean something on a controlled machine. Runs via
1542
+ // `scripts/gate.sh full --perf` locally and a dedicated macos-14 CI job.
1543
+ // Knobs: NATIVE_SDK_PERF_LAUNCHES, NATIVE_SDK_PERF_INTERACTIONS, NATIVE_SDK_PERF_BUDGET_MS,
1544
+ // NATIVE_SDK_PERF_INPUT_BUDGET_MS — see scripts/perf-gpu-dashboard.sh.
1545
+ const gpu_dashboard_perf_step = b.step("test-gpu-dashboard-perf", "Run macOS GPU dashboard percentile performance check (N launches; slow)");
1546
+ const gpu_dashboard_perf_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
1547
+ gpu_dashboard_perf_build.setCwd(b.path("examples/gpu-dashboard"));
1548
+ const gpu_dashboard_perf_run = b.addSystemCommand(&.{ "sh", "scripts/perf-gpu-dashboard.sh" });
1549
+ gpu_dashboard_perf_run.addFileArg(cli_exe.getEmittedBin());
1550
+ gpu_dashboard_perf_run.step.dependOn(&gpu_dashboard_perf_build.step);
1551
+ gpu_dashboard_perf_run.step.dependOn(&cli_exe.step);
1552
+ gpu_dashboard_perf_step.dependOn(&gpu_dashboard_perf_run.step);
1553
+
1554
+ const canvas_preview_smoke_step = b.step("test-canvas-preview-smoke", "Run macOS canvas + webview (both-in-one-window) automation smoke test");
1555
+ const canvas_preview_smoke_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
1556
+ canvas_preview_smoke_build.setCwd(b.path("examples/canvas-preview"));
1557
+ const canvas_preview_smoke_run = b.addSystemCommand(&.{
1558
+ "sh", "-c",
1559
+ \\set -eu
1560
+ \\cd examples/canvas-preview
1561
+ \\app="zig-out/bin/canvas-preview"
1562
+ \\cli="$1"
1563
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1564
+ \\automation_dir=".zig-cache/native-sdk-automation"
1565
+ \\mkdir -p "$automation_dir"
1566
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir/accessibility.txt" "$automation_dir/windows.txt" "$automation_dir"/command*.txt "$automation_dir/screenshot-preview-canvas.png"
1567
+ \\"$app" > .zig-cache/native-sdk-canvas-preview-smoke.log 2>&1 &
1568
+ \\pid=$!
1569
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-canvas-preview-smoke.log) ----" >&2; cat .zig-cache/native-sdk-canvas-preview-smoke.log >&2 2>/dev/null || true; fi' EXIT
1570
+ \\ready="$("$cli" automate wait 2>&1)"
1571
+ \\case "$ready" in *"ready=true"*) ;; *) echo "canvas-preview automation snapshot was not ready" >&2; exit 1 ;; esac
1572
+ \\# Both architectures live in window 1: a presenting Metal canvas and
1573
+ \\# a live WKWebView on a real https URL — with no implicit main webview.
1574
+ \\"$cli" automate assert 'view @w1/preview-canvas kind=gpu_surface.*gpu_nonblank=true' 'view @w1/preview kind=webview.*url="https://example.com/"'
1575
+ \\"$cli" automate assert --absent 'view @w1/main kind=webview' 'source kind=html bytes=0'
1576
+ \\# The webview pane is snapped to the canvas anchor widget: right of
1577
+ \\# the 224pt sidebar, below the 56pt toolbar.
1578
+ \\preview_line="$(grep 'view @w1/preview kind=webview' "$automation_dir/snapshot.txt" | head -1)"
1579
+ \\preview_x="$(printf '%s\n' "$preview_line" | sed -n 's/.*bounds=(\([0-9.]*\),.*/\1/p')"
1580
+ \\case "$preview_x" in ''|*[!0-9.]*) echo "canvas-preview webview x was missing" >&2; exit 1 ;; esac
1581
+ \\if [ "$(printf '%s\n' "$preview_x < 224" | bc)" -eq 1 ]; then echo "canvas-preview webview was not snapped right of the sidebar: x=$preview_x" >&2; exit 1; fi
1582
+ \\# Navigation from a Msg: the app command switches the model URL and
1583
+ \\# the runtime navigates the platform webview.
1584
+ \\"$cli" automate native-command app.docs >/dev/null 2>&1
1585
+ \\"$cli" automate assert 'view @w1/preview kind=webview.*url="https://native-sdk.dev/"' 'name="URL: https://native-sdk.dev/"'
1586
+ \\# Resize keeps the pane snapped to the anchor widget's new frame:
1587
+ \\# the panel right of the 224pt sidebar and below the 56pt toolbar.
1588
+ \\"$cli" automate resize 1200 800 >/dev/null 2>&1
1589
+ \\"$cli" automate assert 'window @w1 "Native SDK Canvas Preview" bounds=.*1200x800' 'view @w1/preview kind=webview.*bounds=.224,56 976x744'
1590
+ \\# Canvas screenshot evidence (reference-rendered PNG of the chrome).
1591
+ \\"$cli" automate screenshot preview-canvas >/dev/null 2>&1
1592
+ \\test -s "$automation_dir/screenshot-preview-canvas.png" || { echo "canvas-preview screenshot was empty" >&2; exit 1; }
1593
+ \\echo "canvas-preview smoke ok"
1594
+ ,
1595
+ "sh",
1596
+ });
1597
+ canvas_preview_smoke_run.addFileArg(cli_exe.getEmittedBin());
1598
+ canvas_preview_smoke_run.step.dependOn(&canvas_preview_smoke_build.step);
1599
+ canvas_preview_smoke_run.step.dependOn(&cli_exe.step);
1600
+ canvas_preview_smoke_step.dependOn(&canvas_preview_smoke_run.step);
1601
+
1602
+ const gpu_components_smoke_step = b.step("test-gpu-components-smoke", "Run macOS GPU components automation smoke test");
1603
+ const gpu_components_smoke_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
1604
+ gpu_components_smoke_build.setCwd(b.path("examples/gpu-components"));
1605
+ const gpu_components_smoke_run = b.addSystemCommand(&.{
1606
+ "sh", "-c",
1607
+ \\set -eu
1608
+ \\cd examples/gpu-components
1609
+ \\app="zig-out/bin/gpu-components"
1610
+ \\cli="$1"
1611
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1612
+ \\automation_dir=".zig-cache/native-sdk-automation"
1613
+ \\mkdir -p "$automation_dir"
1614
+ \\# Startup latencies are load-sensitive on shared CI/agent machines.
1615
+ \\# NATIVE_SDK_SMOKE_BUDGET_MS raises the first-frame latency budget (default
1616
+ \\# stays 150 ms) and the automation-ready ceiling (default stays
1617
+ \\# 500 ms; the ceiling never drops below it) without weakening the
1618
+ \\# local defaults; every correctness assertion stays strict.
1619
+ \\smoke_budget_ms="${NATIVE_SDK_SMOKE_BUDGET_MS:-150}"
1620
+ \\case "$smoke_budget_ms" in ''|*[!0-9]*) echo "NATIVE_SDK_SMOKE_BUDGET_MS must be a positive integer of milliseconds: $smoke_budget_ms" >&2; exit 1 ;; esac
1621
+ \\if [ "$smoke_budget_ms" -le 0 ]; then echo "NATIVE_SDK_SMOKE_BUDGET_MS must be a positive integer of milliseconds: $smoke_budget_ms" >&2; exit 1; fi
1622
+ \\smoke_budget_ns=$((smoke_budget_ms * 1000000))
1623
+ \\ready_budget_ms="$smoke_budget_ms"
1624
+ \\if [ "$ready_budget_ms" -lt 500 ]; then ready_budget_ms=500; fi
1625
+ \\ready_budget_ns=$((ready_budget_ms * 1000000))
1626
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir/accessibility.txt" "$automation_dir/windows.txt" "$automation_dir"/command*.txt
1627
+ \\"$app" > .zig-cache/native-sdk-gpu-components-smoke.log 2>&1 &
1628
+ \\pid=$!
1629
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-gpu-components-smoke.log) ----" >&2; cat .zig-cache/native-sdk-gpu-components-smoke.log >&2 2>/dev/null || true; fi' EXIT
1630
+ \\ready="$("$cli" automate wait 2>&1)"
1631
+ \\case "$ready" in *"ready=true"*) ;; *) echo "gpu-components automation snapshot was not ready" >&2; exit 1 ;; esac
1632
+ \\ready_uptime="$(printf '%s\n' "$ready" | sed -n 's/.*runtime_uptime_ns=\([0-9][0-9]*\).*/\1/p')"
1633
+ \\case "$ready_uptime" in ''|*[!0-9]*) echo "gpu-components automation ready uptime was missing" >&2; exit 1 ;; esac
1634
+ \\if [ "$ready_uptime" -le 0 ] || [ "$ready_uptime" -gt "$ready_budget_ns" ]; then echo "gpu-components automation ready exceeded $ready_budget_ms ms: $ready_uptime ns" >&2; exit 1; fi
1635
+ \\snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1636
+ \\case "$snapshot" in *'window @w1 "Native SDK GPU Components"'*) ;; *) echo "gpu-components window was missing from snapshot" >&2; exit 1 ;; esac
1637
+ \\case "$snapshot" in *'view @w1/main kind=webview'*) echo "components should not create an implicit main WebView" >&2; exit 1 ;; *) ;; esac
1638
+ \\case "$snapshot" in *'source kind=html bytes=0'*) echo "components should not publish an empty default WebView source" >&2; exit 1 ;; *) ;; esac
1639
+ \\attempts=0
1640
+ \\while [ "$attempts" -lt 50 ]; do
1641
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1642
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'gpu_nonblank=true'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1643
+ \\ attempts=$((attempts + 1))
1644
+ \\ sleep 0.1
1645
+ \\done
1646
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'gpu_nonblank=true'*) ;; *) echo "components GPU surface was not ready and nonblank" >&2; exit 1 ;; esac
1647
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "components GPU frame was not packet-representable" >&2; exit 1 ;; esac
1648
+ \\first_frame_latency="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/components-canvas kind=gpu_surface.* gpu_first_frame_latency_ns=\([0-9][0-9]*\).*/\1/p')"
1649
+ \\case "$first_frame_latency" in ''|*[!0-9]*) echo "components GPU first frame latency was missing" >&2; exit 1 ;; esac
1650
+ \\if [ "$first_frame_latency" -le 0 ] || [ "$first_frame_latency" -gt "$smoke_budget_ns" ]; then echo "components GPU first frame exceeded $smoke_budget_ms ms: $first_frame_latency ns" >&2; exit 1; fi
1651
+ \\# The runtime publishes its own fixed 150 ms budget verdict. Within that
1652
+ \\# budget the verdict must agree exactly; beyond it (reachable only when
1653
+ \\# NATIVE_SDK_SMOKE_BUDGET_MS > 150) the runtime must report the overrun honestly.
1654
+ \\if [ "$first_frame_latency" -le 150000000 ]; then
1655
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'gpu_first_frame_latency_budget_ns=150000000'*'gpu_first_frame_latency_budget_exceeded=0'*'gpu_first_frame_latency_budget_ok=true'*) ;; *) echo "components GPU first frame exceeded the latency budget" >&2; exit 1 ;; esac
1656
+ \\else
1657
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'gpu_first_frame_latency_budget_ns=150000000'*'gpu_first_frame_latency_budget_ok=false'*) ;; *) echo "components runtime did not report the first-frame budget overrun" >&2; exit 1 ;; esac
1658
+ \\fi
1659
+ \\gpu_frame_from_snapshot() {
1660
+ \\ printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/components-canvas kind=gpu_surface.* gpu_frame=\([0-9][0-9]*\).*/\1/p'
1661
+ \\}
1662
+ \\canvas_revision_from_snapshot() {
1663
+ \\ printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/components-canvas kind=gpu_surface.* canvas_revision=\([0-9][0-9]*\).*/\1/p'
1664
+ \\}
1665
+ \\snapshot_contains() {
1666
+ \\ case "$snapshot" in *"$1"*) return 0 ;; *) return 1 ;; esac
1667
+ \\}
1668
+ \\case "$snapshot" in *'widget @w1/components-canvas#113 role=checkbox'*'value=1'*'actions=[focus,toggle]'*) ;; *) echo "checkbox widget was not initially selected" >&2; exit 1 ;; esac
1669
+ \\case "$snapshot" in *'widget @w1/components-canvas#114 role=switch'*'value=1'*'actions=[focus,toggle]'*) ;; *) echo "switch widget was not initially selected" >&2; exit 1 ;; esac
1670
+ \\case "$snapshot" in *'widget @w1/components-canvas#116 role=progressbar'*'value=1'*) ;; *) echo "progress widget was missing from the initial snapshot" >&2; exit 1 ;; esac
1671
+ \\case "$snapshot" in *'widget @w1/components-canvas#117 role=tab'*'value=1'*'actions=[focus,select]'*) ;; *) echo "small segmented control was not initially selected" >&2; exit 1 ;; esac
1672
+ \\case "$snapshot" in *'widget @w1/components-canvas#119 role=tab'*'value=0'*'actions=[focus,select]'*) ;; *) echo "large segmented control was not initially available" >&2; exit 1 ;; esac
1673
+ \\case "$snapshot" in *'widget @w1/components-canvas#142 role=menuitem'*'actions=[focus,press,select]'*) ;; *) echo "menu item widget was not initially actionable" >&2; exit 1 ;; esac
1674
+ \\case "$snapshot" in *'widget @w1/components-canvas#86 role=tab'*'actions=[focus,press,select]'*) ;; *) echo "theme toolbar trigger was not initially actionable" >&2; exit 1 ;; esac
1675
+ \\case "$snapshot" in *'widget @w1/components-canvas#83 role=button'*'actions=[focus,press]'*) ;; *) echo "refresh toolbar widget was not initially actionable" >&2; exit 1 ;; esac
1676
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1677
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1678
+ \\gpu_frame_after="$gpu_frame_before"
1679
+ \\canvas_revision_before="$(canvas_revision_from_snapshot)"
1680
+ \\case "$canvas_revision_before" in ''|*[!0-9]*) canvas_revision_before=0 ;; esac
1681
+ \\canvas_revision_after="$canvas_revision_before"
1682
+ \\"$cli" automate widget-click components-canvas 86 >/dev/null 2>&1
1683
+ \\attempts=0
1684
+ \\while [ "$attempts" -lt 50 ]; do
1685
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1686
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1687
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1688
+ \\ canvas_revision_after="$(canvas_revision_from_snapshot)"
1689
+ \\ case "$canvas_revision_after" in ''|*[!0-9]*) canvas_revision_after=0 ;; esac
1690
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ] || [ "$canvas_revision_after" -gt "$canvas_revision_before" ]; then
1691
+ \\ if snapshot_contains 'GPU component theme: ' && snapshot_contains ' from native_view. Count 1.' && snapshot_contains 'view @w1/components-canvas kind=gpu_surface' && snapshot_contains 'canvas_frame_gpu_packet_unsupported=0' && snapshot_contains 'canvas_frame_gpu_packet_representable=true'; then break; fi
1692
+ \\ fi
1693
+ \\ attempts=$((attempts + 1))
1694
+ \\ sleep 0.1
1695
+ \\done
1696
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ] && [ "$canvas_revision_after" -le "$canvas_revision_before" ]; then echo "theme automation command did not update the retained GPU canvas" >&2; exit 1; fi
1697
+ \\case "$snapshot" in *'GPU component theme: '*' from native_view. Count 1.'*) ;; *) echo "theme automation command did not update status" >&2; exit 1 ;; esac
1698
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "theme automation command did not present a packet-renderable GPU frame" >&2; exit 1 ;; esac
1699
+ \\"$cli" automate widget-action components-canvas 111 focus >/dev/null 2>&1
1700
+ \\attempts=0
1701
+ \\while [ "$attempts" -lt 50 ]; do
1702
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1703
+ \\ case "$snapshot" in *'widget @w1/components-canvas#111 role=textbox'*'focused=true'*'text="native-sdk"'*) break ;; esac
1704
+ \\ attempts=$((attempts + 1))
1705
+ \\ sleep 0.1
1706
+ \\done
1707
+ \\case "$snapshot" in *'widget @w1/components-canvas#111 role=textbox'*'focused=true'*'text="native-sdk"'*) ;; *) echo "widget focus automation did not focus retained text" >&2; exit 1 ;; esac
1708
+ \\"$cli" automate widget-key components-canvas z z >/dev/null 2>&1
1709
+ \\attempts=0
1710
+ \\while [ "$attempts" -lt 50 ]; do
1711
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1712
+ \\ case "$snapshot" in *'widget @w1/components-canvas#111 role=textbox'*'focused=true'*'text="native-sdkz"'*) break ;; esac
1713
+ \\ attempts=$((attempts + 1))
1714
+ \\ sleep 0.1
1715
+ \\done
1716
+ \\case "$snapshot" in *'widget @w1/components-canvas#111 role=textbox'*'focused=true'*'text="native-sdkz"'*) ;; *) echo "widget keyboard automation did not update retained text" >&2; exit 1 ;; esac
1717
+ \\"$cli" automate widget-key components-canvas tab >/dev/null 2>&1
1718
+ \\attempts=0
1719
+ \\while [ "$attempts" -lt 50 ]; do
1720
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1721
+ \\ case "$snapshot" in *'widget @w1/components-canvas#112 role=textbox'*'focused=true'*) break ;; esac
1722
+ \\ attempts=$((attempts + 1))
1723
+ \\ sleep 0.1
1724
+ \\done
1725
+ \\case "$snapshot" in *'widget @w1/components-canvas#112 role=textbox'*'focused=true'*) ;; *) echo "widget keyboard automation did not move focus" >&2; exit 1 ;; esac
1726
+ \\"$cli" automate widget-action components-canvas 105 press >/dev/null 2>&1
1727
+ \\attempts=0
1728
+ \\while [ "$attempts" -lt 50 ]; do
1729
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1730
+ \\ if snapshot_contains 'Keyed icon_button #105.' && snapshot_contains 'widget @w1/components-canvas#105 role=button' && snapshot_contains 'actions=[focus,press]'; then break; fi
1731
+ \\ attempts=$((attempts + 1))
1732
+ \\ sleep 0.1
1733
+ \\done
1734
+ \\if ! snapshot_contains 'Keyed icon_button #105.' || ! snapshot_contains 'widget @w1/components-canvas#105 role=button' || ! snapshot_contains 'actions=[focus,press]'; then echo "icon button automation press did not update status" >&2; exit 1; fi
1735
+ \\"$cli" automate widget-action components-canvas 111 set-text native-engine >/dev/null 2>&1
1736
+ \\attempts=0
1737
+ \\while [ "$attempts" -lt 50 ]; do
1738
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1739
+ \\ case "$snapshot" in *'widget @w1/components-canvas#111 role=textbox'*'text="native-engine"'*) break ;; esac
1740
+ \\ attempts=$((attempts + 1))
1741
+ \\ sleep 0.1
1742
+ \\done
1743
+ \\case "$snapshot" in *'widget @w1/components-canvas#111 role=textbox'*'text="native-engine"'*) ;; *) echo "text field automation did not update retained text" >&2; exit 1 ;; esac
1744
+ \\"$cli" automate widget-action components-canvas 115 increment >/dev/null 2>&1
1745
+ \\attempts=0
1746
+ \\while [ "$attempts" -lt 50 ]; do
1747
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1748
+ \\ case "$snapshot" in *'Keyed slider #115: value '*)
1749
+ \\ case "$snapshot" in *'widget @w1/components-canvas#115 role=slider'*'value=0.62'*) ;; *'widget @w1/components-canvas#115 role=slider'*) break ;; esac
1750
+ \\ ;;
1751
+ \\ esac
1752
+ \\ attempts=$((attempts + 1))
1753
+ \\ sleep 0.1
1754
+ \\done
1755
+ \\case "$snapshot" in *'Keyed slider #115: value '*) ;; *) echo "slider automation increment did not update status" >&2; exit 1 ;; esac
1756
+ \\case "$snapshot" in *'widget @w1/components-canvas#115 role=slider'*'value=0.62'*) echo "slider automation increment did not change value" >&2; exit 1 ;; *'widget @w1/components-canvas#115 role=slider'*) ;; *) echo "slider widget was missing after increment" >&2; exit 1 ;; esac
1757
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1758
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1759
+ \\gpu_frame_after="$gpu_frame_before"
1760
+ \\"$cli" automate widget-drag components-canvas 115 0.25 0.82 >/dev/null 2>&1
1761
+ \\attempts=0
1762
+ \\while [ "$attempts" -lt 50 ]; do
1763
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1764
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1765
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1766
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ]; then
1767
+ \\ if snapshot_contains 'Clicked slider #115: value 0.82.' && snapshot_contains 'widget @w1/components-canvas#115 role=slider' && { snapshot_contains 'value=0.82' || snapshot_contains 'value=0.819'; }; then
1768
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1769
+ \\ fi
1770
+ \\ fi
1771
+ \\ attempts=$((attempts + 1))
1772
+ \\ sleep 0.1
1773
+ \\done
1774
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ]; then echo "slider automation drag did not request a GPU frame" >&2; exit 1; fi
1775
+ \\if ! snapshot_contains 'Clicked slider #115: value 0.82.' || ! snapshot_contains 'widget @w1/components-canvas#115 role=slider' || { ! snapshot_contains 'value=0.82' && ! snapshot_contains 'value=0.819'; }; then echo "slider automation drag did not update retained slider state" >&2; exit 1; fi
1776
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "slider automation drag did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1777
+ \\"$cli" automate widget-action components-canvas 156 press >/dev/null 2>&1
1778
+ \\attempts=0
1779
+ \\while [ "$attempts" -lt 50 ]; do
1780
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1781
+ \\ if snapshot_contains 'Keyed data_cell #156: selected.' && snapshot_contains 'widget @w1/components-canvas#156 role=gridcell' && snapshot_contains 'focused=true' && snapshot_contains 'value=1'; then break; fi
1782
+ \\ attempts=$((attempts + 1))
1783
+ \\ sleep 0.1
1784
+ \\done
1785
+ \\if ! snapshot_contains 'Keyed data_cell #156: selected.' || ! snapshot_contains 'widget @w1/components-canvas#156 role=gridcell' || ! snapshot_contains 'focused=true' || ! snapshot_contains 'value=1'; then echo "grid cell automation press did not focus and report status" >&2; exit 1; fi
1786
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1787
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1788
+ \\gpu_frame_after="$gpu_frame_before"
1789
+ \\"$cli" automate widget-click components-canvas 119 >/dev/null 2>&1
1790
+ \\attempts=0
1791
+ \\while [ "$attempts" -lt 50 ]; do
1792
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1793
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1794
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1795
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ]; then
1796
+ \\ if snapshot_contains 'Clicked segmented_control #119: selected.' && snapshot_contains 'widget @w1/components-canvas#117 role=tab' && snapshot_contains 'value=0' && snapshot_contains 'widget @w1/components-canvas#119 role=tab' && snapshot_contains 'focused=true' && snapshot_contains 'value=1'; then
1797
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1798
+ \\ fi
1799
+ \\ fi
1800
+ \\ attempts=$((attempts + 1))
1801
+ \\ sleep 0.1
1802
+ \\done
1803
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ]; then echo "segmented control automation click did not request a GPU frame" >&2; exit 1; fi
1804
+ \\if ! snapshot_contains 'Clicked segmented_control #119: selected.' || ! snapshot_contains 'widget @w1/components-canvas#117 role=tab' || ! snapshot_contains 'value=0' || ! snapshot_contains 'widget @w1/components-canvas#119 role=tab' || ! snapshot_contains 'focused=true' || ! snapshot_contains 'value=1'; then echo "segmented control automation click did not update retained selection state" >&2; exit 1; fi
1805
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "segmented control automation click did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1806
+ \\# The catalog's project menu is an ACTIONS menu (no sibling declares a
1807
+ \\# committed row), so automation select mints NO selection: value
1808
+ \\# stays 0. Automation focus follows the pointer contract (rows take
1809
+ \\# focus QUIETLY, no visible affordance), so nothing repaints and no
1810
+ \\# frame is requested — the republished snapshot alone carries the
1811
+ \\# focus move. A picker menu would mint value=1 and repaint; the
1812
+ \\# select specimen's committed-row tests cover that register.
1813
+ \\"$cli" automate widget-action components-canvas 142 select >/dev/null 2>&1
1814
+ \\attempts=0
1815
+ \\while [ "$attempts" -lt 50 ]; do
1816
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1817
+ \\ case "$(printf '%s\\n' "$snapshot" | grep -F 'components-canvas#142 role=menuitem' | head -1)" in *'focused=true'*'value=0'*) break ;; esac
1818
+ \\ attempts=$((attempts + 1))
1819
+ \\ sleep 0.1
1820
+ \\done
1821
+ \\menu_item_line="$(printf '%s\\n' "$snapshot" | grep -F 'components-canvas#142 role=menuitem' | head -1)"
1822
+ \\case "$menu_item_line" in *'focused=true'*'value=0'*) ;; *) echo "menu item automation select did not move quiet focus without minting a selection" >&2; exit 1 ;; esac
1823
+ \\"$cli" automate widget-action components-canvas 113 toggle >/dev/null 2>&1
1824
+ \\attempts=0
1825
+ \\while [ "$attempts" -lt 50 ]; do
1826
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1827
+ \\ if snapshot_contains 'Keyed checkbox #113: off.' && snapshot_contains 'widget @w1/components-canvas#113 role=checkbox' && snapshot_contains 'value=0'; then break; fi
1828
+ \\ attempts=$((attempts + 1))
1829
+ \\ sleep 0.1
1830
+ \\done
1831
+ \\if ! snapshot_contains 'Keyed checkbox #113: off.' || ! snapshot_contains 'widget @w1/components-canvas#113 role=checkbox' || ! snapshot_contains 'value=0'; then echo "checkbox automation toggle did not update the retained widget snapshot" >&2; exit 1; fi
1832
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1833
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1834
+ \\gpu_frame_after="$gpu_frame_before"
1835
+ \\"$cli" automate widget-click components-canvas 113 >/dev/null 2>&1
1836
+ \\attempts=0
1837
+ \\while [ "$attempts" -lt 50 ]; do
1838
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1839
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1840
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1841
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ]; then
1842
+ \\ if snapshot_contains 'Clicked checkbox #113: on.' && snapshot_contains 'widget @w1/components-canvas#113 role=checkbox' && snapshot_contains 'value=1'; then
1843
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1844
+ \\ fi
1845
+ \\ fi
1846
+ \\ attempts=$((attempts + 1))
1847
+ \\ sleep 0.1
1848
+ \\done
1849
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ]; then echo "checkbox automation click did not request a GPU frame" >&2; exit 1; fi
1850
+ \\if ! snapshot_contains 'Clicked checkbox #113: on.' || ! snapshot_contains 'widget @w1/components-canvas#113 role=checkbox' || ! snapshot_contains 'value=1'; then echo "checkbox automation click did not route through pointer input" >&2; exit 1; fi
1851
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "checkbox automation click did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1852
+ \\"$cli" automate widget-action components-canvas 114 toggle >/dev/null 2>&1
1853
+ \\attempts=0
1854
+ \\while [ "$attempts" -lt 50 ]; do
1855
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1856
+ \\ if snapshot_contains 'Keyed switch_control #114: off.' && snapshot_contains 'widget @w1/components-canvas#114 role=switch' && snapshot_contains 'value=0'; then break; fi
1857
+ \\ attempts=$((attempts + 1))
1858
+ \\ sleep 0.1
1859
+ \\done
1860
+ \\if ! snapshot_contains 'Keyed switch_control #114: off.' || ! snapshot_contains 'widget @w1/components-canvas#114 role=switch' || ! snapshot_contains 'value=0'; then echo "switch automation toggle did not wake the idle app" >&2; exit 1; fi
1861
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1862
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1863
+ \\gpu_frame_after="$gpu_frame_before"
1864
+ \\"$cli" automate widget-click components-canvas 114 >/dev/null 2>&1
1865
+ \\attempts=0
1866
+ \\while [ "$attempts" -lt 50 ]; do
1867
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1868
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1869
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1870
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ]; then
1871
+ \\ if snapshot_contains 'Clicked switch_control #114: on.' && snapshot_contains 'widget @w1/components-canvas#114 role=switch' && snapshot_contains 'value=1'; then
1872
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1873
+ \\ fi
1874
+ \\ fi
1875
+ \\ attempts=$((attempts + 1))
1876
+ \\ sleep 0.1
1877
+ \\done
1878
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ]; then echo "switch automation click did not request a GPU frame" >&2; exit 1; fi
1879
+ \\if ! snapshot_contains 'Clicked switch_control #114: on.' || ! snapshot_contains 'widget @w1/components-canvas#114 role=switch' || ! snapshot_contains 'value=1'; then echo "switch automation click did not route through pointer input" >&2; exit 1; fi
1880
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "switch automation click did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1881
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1882
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1883
+ \\gpu_frame_after="$gpu_frame_before"
1884
+ \\canvas_revision_before="$(canvas_revision_from_snapshot)"
1885
+ \\case "$canvas_revision_before" in ''|*[!0-9]*) canvas_revision_before=0 ;; esac
1886
+ \\canvas_revision_after="$canvas_revision_before"
1887
+ \\"$cli" automate widget-action components-canvas 120 increment >/dev/null 2>&1
1888
+ \\attempts=0
1889
+ \\while [ "$attempts" -lt 50 ]; do
1890
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1891
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1892
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1893
+ \\ canvas_revision_after="$(canvas_revision_from_snapshot)"
1894
+ \\ case "$canvas_revision_after" in ''|*[!0-9]*) canvas_revision_after=0 ;; esac
1895
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ] || [ "$canvas_revision_after" -gt "$canvas_revision_before" ]; then
1896
+ \\ if snapshot_contains 'Keyed list #120: offset 56.' && snapshot_contains 'widget @w1/components-canvas#120 role=list' && snapshot_contains 'scroll=[offset=56,viewport=56,content=168]'; then
1897
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1898
+ \\ fi
1899
+ \\ fi
1900
+ \\ attempts=$((attempts + 1))
1901
+ \\ sleep 0.1
1902
+ \\done
1903
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ] && [ "$canvas_revision_after" -le "$canvas_revision_before" ]; then echo "list automation increment did not update the retained GPU canvas" >&2; exit 1; fi
1904
+ \\if ! snapshot_contains 'Keyed list #120: offset 56.' || ! snapshot_contains 'widget @w1/components-canvas#120 role=list' || ! snapshot_contains 'scroll=[offset=56,viewport=56,content=168]'; then echo "list automation increment did not update retained scroll semantics" >&2; exit 1; fi
1905
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "list automation increment did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1906
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1907
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1908
+ \\gpu_frame_after="$gpu_frame_before"
1909
+ \\canvas_revision_before="$(canvas_revision_from_snapshot)"
1910
+ \\case "$canvas_revision_before" in ''|*[!0-9]*) canvas_revision_before=0 ;; esac
1911
+ \\canvas_revision_after="$canvas_revision_before"
1912
+ \\"$cli" automate widget-action components-canvas 150 increment >/dev/null 2>&1
1913
+ \\attempts=0
1914
+ \\while [ "$attempts" -lt 50 ]; do
1915
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1916
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1917
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1918
+ \\ canvas_revision_after="$(canvas_revision_from_snapshot)"
1919
+ \\ case "$canvas_revision_after" in ''|*[!0-9]*) canvas_revision_after=0 ;; esac
1920
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ] || [ "$canvas_revision_after" -gt "$canvas_revision_before" ]; then
1921
+ \\ if snapshot_contains 'Keyed table #150: offset 56.' && snapshot_contains 'widget @w1/components-canvas#150 role=grid' && snapshot_contains 'scroll=[offset=56,viewport=28,content=140]'; then
1922
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1923
+ \\ fi
1924
+ \\ fi
1925
+ \\ attempts=$((attempts + 1))
1926
+ \\ sleep 0.1
1927
+ \\done
1928
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ] && [ "$canvas_revision_after" -le "$canvas_revision_before" ]; then echo "data grid automation increment did not update the retained GPU canvas" >&2; exit 1; fi
1929
+ \\if ! snapshot_contains 'Keyed table #150: offset 56.' || ! snapshot_contains 'widget @w1/components-canvas#150 role=grid' || ! snapshot_contains 'scroll=[offset=56,viewport=28,content=140]'; then echo "data grid automation increment did not update retained scroll semantics" >&2; exit 1; fi
1930
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "data grid automation increment did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1931
+ \\gpu_frame_before="$(gpu_frame_from_snapshot)"
1932
+ \\case "$gpu_frame_before" in ''|*[!0-9]*) gpu_frame_before=0 ;; esac
1933
+ \\gpu_frame_after="$gpu_frame_before"
1934
+ \\canvas_revision_before="$(canvas_revision_from_snapshot)"
1935
+ \\case "$canvas_revision_before" in ''|*[!0-9]*) canvas_revision_before=0 ;; esac
1936
+ \\canvas_revision_after="$canvas_revision_before"
1937
+ \\"$cli" automate widget-wheel components-canvas 130 20 >/dev/null 2>&1
1938
+ \\attempts=0
1939
+ \\while [ "$attempts" -lt 50 ]; do
1940
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
1941
+ \\ gpu_frame_after="$(gpu_frame_from_snapshot)"
1942
+ \\ case "$gpu_frame_after" in ''|*[!0-9]*) gpu_frame_after=0 ;; esac
1943
+ \\ canvas_revision_after="$(canvas_revision_from_snapshot)"
1944
+ \\ case "$canvas_revision_after" in ''|*[!0-9]*) canvas_revision_after=0 ;; esac
1945
+ \\ if [ "$gpu_frame_after" -gt "$gpu_frame_before" ] || [ "$canvas_revision_after" -gt "$canvas_revision_before" ]; then
1946
+ \\ case "$snapshot" in *'widget @w1/components-canvas#130 role=group'*'scroll=[offset=84,viewport=56,content=140]'*)
1947
+ \\ case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) break ;; esac
1948
+ \\ ;;
1949
+ \\ esac
1950
+ \\ fi
1951
+ \\ attempts=$((attempts + 1))
1952
+ \\ sleep 0.1
1953
+ \\done
1954
+ \\if [ "$gpu_frame_after" -le "$gpu_frame_before" ] && [ "$canvas_revision_after" -le "$canvas_revision_before" ]; then echo "scroll automation wheel did not update the retained GPU canvas" >&2; exit 1; fi
1955
+ \\case "$snapshot" in *'widget @w1/components-canvas#130 role=group'*'scroll=[offset=84,viewport=56,content=140]'*) ;; *) echo "scroll automation wheel did not update retained scroll semantics" >&2; exit 1 ;; esac
1956
+ \\case "$snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'canvas_frame_full_repaint=false'*'canvas_frame_pipeline_uploads=0'*'canvas_frame_image_uploads=0'*'canvas_frame_glyph_uploads=0'*'canvas_frame_text_uploads=0'*'canvas_frame_gpu_packet_unsupported=0'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "scroll automation wheel did not present an incremental GPU packet without interaction-time uploads" >&2; exit 1 ;; esac
1957
+ \\input_timestamp="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/components-canvas kind=gpu_surface.* gpu_input_timestamp_ns=\([0-9][0-9]*\).*/\1/p')"
1958
+ \\case "$input_timestamp" in ''|*[!0-9]*) echo "components GPU input timestamp was missing after widget interaction" >&2; exit 1 ;; esac
1959
+ \\if [ "$input_timestamp" -le 0 ]; then echo "components GPU input timestamp was not recorded" >&2; exit 1; fi
1960
+ \\input_latency="$(printf '%s\n' "$snapshot" | sed -n 's/.*view @w1\/components-canvas kind=gpu_surface.* gpu_input_latency_ns=\([0-9][0-9]*\).*/\1/p')"
1961
+ \\case "$input_latency" in ''|*[!0-9]*) echo "components GPU input latency was missing after widget interaction" >&2; exit 1 ;; esac
1962
+ \\# gpu_input_latency now stamps at the RESPONDING present's completion
1963
+ \\# (input to glass), which legitimately spans the paced render wait —
1964
+ \\# up to a couple of display intervals while animations hold the paced
1965
+ \\# loop. Assert an explicit input-to-glass bound (the perf harness
1966
+ \\# budgets the same channel at 100 ms) instead of the one-interval
1967
+ \\# budget flag the old completion-channel stamp happened to satisfy.
1968
+ \\if [ "$input_latency" -le 0 ] || [ "$input_latency" -gt 100000000 ]; then echo "components GPU input-to-glass latency was implausible: $input_latency ns" >&2; exit 1; fi
1969
+ \\echo "gpu-components smoke ok"
1970
+ ,
1971
+ "sh",
1972
+ });
1973
+ gpu_components_smoke_run.addFileArg(cli_exe.getEmittedBin());
1974
+ gpu_components_smoke_run.step.dependOn(&gpu_components_smoke_build.step);
1975
+ gpu_components_smoke_run.step.dependOn(&cli_exe.step);
1976
+ gpu_components_smoke_step.dependOn(&gpu_components_smoke_run.step);
1977
+
1978
+ const webview_cef_smoke_step = b.step("test-webview-cef-smoke", "Run macOS Chromium WebView automation smoke test");
1979
+ const webview_cef_smoke_build = b.addSystemCommand(&.{ "zig", "build", "-Dplatform=macos", "-Dweb-engine=chromium", b.fmt("-Dcef-dir={s}", .{exampleCefDir(b, cef_dir)}), "-Dautomation=true", "-Djs-bridge=true" });
1980
+ webview_cef_smoke_build.setCwd(b.path("examples/webview"));
1981
+ const webview_cef_smoke_run = b.addSystemCommand(&.{
1982
+ "sh", "-c",
1983
+ \\set -eu
1984
+ \\cd examples/webview
1985
+ \\app="zig-out/bin/webview"
1986
+ \\cli="$1"
1987
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
1988
+ \\request='{"id":"ping","command":"native.ping","payload":{"source":"cef-smoke"}}'
1989
+ \\response_file=".zig-cache/native-sdk-automation/bridge-response.txt"
1990
+ \\mkdir -p .zig-cache/native-sdk-automation
1991
+ \\rm -f .zig-cache/native-sdk-automation/snapshot.txt .zig-cache/native-sdk-automation/windows.txt .zig-cache/native-sdk-automation/command*.txt "$response_file"
1992
+ \\printf 'bridge %s\n' "$request" > .zig-cache/native-sdk-automation/command-1.txt
1993
+ \\"$app" > .zig-cache/native-sdk-webview-cef-smoke.log 2>&1 &
1994
+ \\pid=$!
1995
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-webview-cef-smoke.log) ----" >&2; cat .zig-cache/native-sdk-webview-cef-smoke.log >&2 2>/dev/null || true; fi' EXIT
1996
+ \\snapshot="$("$cli" automate wait 2>&1)"
1997
+ \\case "$snapshot" in *"ready=true"*) ;; *) echo "automation snapshot was not ready" >&2; exit 1 ;; esac
1998
+ \\attempts=0
1999
+ \\while [ "$attempts" -lt 50 ] && ! grep -q 'name="webview.load"' .zig-cache/native-sdk-webview-cef-smoke.log; do attempts=$((attempts + 1)); sleep 0.1; done
2000
+ \\grep -q 'name="webview.load"' .zig-cache/native-sdk-webview-cef-smoke.log || { echo "main window never loaded its webview source (blank window)" >&2; exit 1; }
2001
+ \\if grep -q 'name="dispatch.error"' .zig-cache/native-sdk-webview-cef-smoke.log; then echo "runtime recorded a dispatch error during startup" >&2; exit 1; fi
2002
+ \\attempts=0
2003
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
2004
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
2005
+ \\case "$response" in *'"ok":true'*'pong from Zig'*) ;; *) echo "native.ping response was unexpected: $response" >&2; exit 1 ;; esac
2006
+ \\rm -f "$response_file"
2007
+ \\printf 'bridge %s\n' '{"id":"webview-create","command":"native-sdk.webview.create","payload":{"label":"smoke","url":"https://example.com","frame":{"x":24,"y":24,"width":320,"height":220}}}' > .zig-cache/native-sdk-automation/command-1.txt
2008
+ \\attempts=0
2009
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
2010
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
2011
+ \\case "$response" in *'"ok":true'*) ;; *) echo "cef webview create did not succeed: $response" >&2; exit 1 ;; esac
2012
+ \\rm -f "$response_file"
2013
+ \\printf 'bridge %s\n' '{"id":"webview-resize","command":"native-sdk.webview.setFrame","payload":{"label":"smoke","frame":{"x":36,"y":36,"width":420,"height":260}}}' > .zig-cache/native-sdk-automation/command-1.txt
2014
+ \\attempts=0
2015
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
2016
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
2017
+ \\case "$response" in *'"ok":true'*) ;; *) echo "cef webview resize did not succeed: $response" >&2; exit 1 ;; esac
2018
+ \\rm -f "$response_file"
2019
+ \\printf 'bridge %s\n' '{"id":"webview-navigate","command":"native-sdk.webview.navigate","payload":{"label":"smoke","url":"https://example.com/?smoke=1"}}' > .zig-cache/native-sdk-automation/command-1.txt
2020
+ \\attempts=0
2021
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
2022
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
2023
+ \\case "$response" in *'"ok":true'*) ;; *) echo "cef webview navigate did not succeed: $response" >&2; exit 1 ;; esac
2024
+ \\rm -f "$response_file"
2025
+ \\printf 'bridge %s\n' '{"id":"webview-close","command":"native-sdk.webview.close","payload":{"label":"smoke"}}' > .zig-cache/native-sdk-automation/command-1.txt
2026
+ \\attempts=0
2027
+ \\while [ "$attempts" -lt 50 ] && [ ! -s "$response_file" ]; do attempts=$((attempts + 1)); sleep 0.1; done
2028
+ \\response="$(cat "$response_file" 2>/dev/null || true)"
2029
+ \\case "$response" in *'"ok":true'*) ;; *) echo "cef webview close did not succeed: $response" >&2; exit 1 ;; esac
2030
+ \\echo "cef webview smoke ok"
2031
+ ,
2032
+ "sh",
2033
+ });
2034
+ webview_cef_smoke_run.addFileArg(cli_exe.getEmittedBin());
2035
+ webview_cef_smoke_run.step.dependOn(&webview_cef_smoke_build.step);
2036
+ webview_cef_smoke_run.step.dependOn(&cli_exe.step);
2037
+ webview_cef_smoke_step.dependOn(&webview_cef_smoke_run.step);
2038
+
2039
+ const dev_run = b.addSystemCommand(&.{ "zig", "build", "run", b.fmt("-Dplatform={s}", .{platform_arg}) });
2040
+ dev_run.setCwd(b.path("examples/webview"));
2041
+ const dev_step = b.step("dev", "Run managed frontend dev server and native shell");
2042
+ dev_step.dependOn(&dev_run.step);
2043
+
2044
+ const lib_step = b.step("lib", "Build native-sdk embeddable static library");
2045
+ lib_step.dependOn(&b.addInstallArtifact(embed_lib, .{}).step);
2046
+
2047
+ const doctor_run = b.addRunArtifact(host_cli_exe);
2048
+ doctor_run.addArg("doctor");
2049
+ const doctor_step = b.step("doctor", "Print native-sdk platform diagnostics");
2050
+ doctor_step.dependOn(&doctor_run.step);
2051
+
2052
+ const validate_run = b.addRunArtifact(host_cli_exe);
2053
+ validate_run.addArgs(&.{ "validate", "app.zon" });
2054
+ const validate_step = b.step("validate", "Validate app.zon");
2055
+ validate_step.dependOn(&validate_run.step);
2056
+
2057
+ const bundle_run = b.addRunArtifact(host_cli_exe);
2058
+ bundle_run.addArgs(&.{ "bundle-assets", "app.zon", "assets", "zig-out/assets" });
2059
+ const bundle_step = b.step("bundle-assets", "Bundle app assets");
2060
+ bundle_step.dependOn(&bundle_run.step);
2061
+
2062
+ const package_run = b.addRunArtifact(host_cli_exe);
2063
+ package_run.addArgs(&.{
2064
+ "package",
2065
+ "--target",
2066
+ @tagName(package_target),
2067
+ "--output",
2068
+ b.fmt("zig-out/package/native-sdk-{s}-{s}-{s}{s}", .{ package_version, @tagName(package_target), optimize_name, packageSuffix(package_target) }),
2069
+ "--binary",
2070
+ });
2071
+ package_run.addFileArg(embed_lib.getEmittedBin());
2072
+ package_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", @tagName(signing_mode), "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
2073
+ if (cef_auto_install) package_run.addArg("--cef-auto-install");
2074
+ package_run.step.dependOn(&embed_lib.step);
2075
+ package_run.step.dependOn(&bundle_run.step);
2076
+ const package_step = b.step("package", "Create local package artifact");
2077
+ package_step.dependOn(&package_run.step);
2078
+
2079
+ const package_cef_run = b.addRunArtifact(host_cli_exe);
2080
+ package_cef_run.addArgs(&.{
2081
+ "package",
2082
+ "--target",
2083
+ "macos",
2084
+ "--output",
2085
+ b.fmt("zig-out/package/native-sdk-cef-smoke-{s}.app", .{optimize_name}),
2086
+ "--binary",
2087
+ });
2088
+ package_cef_run.addFileArg(embed_lib.getEmittedBin());
2089
+ package_cef_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--web-engine", "chromium", "--cef-dir", cef_dir });
2090
+ if (cef_auto_install) package_cef_run.addArg("--cef-auto-install");
2091
+ package_cef_run.step.dependOn(&embed_lib.step);
2092
+ package_cef_run.step.dependOn(&bundle_run.step);
2093
+
2094
+ const package_cef_check = b.addSystemCommand(&.{
2095
+ "sh", "-c",
2096
+ b.fmt(
2097
+ \\set -e
2098
+ \\app="zig-out/package/native-sdk-cef-smoke-{s}.app"
2099
+ \\test -d "$app/Contents/Frameworks/Chromium Embedded Framework.framework"
2100
+ \\test -f "$app/Contents/Frameworks/Chromium Embedded Framework.framework/Resources/icudtl.dat"
2101
+ \\test -f "$app/Contents/Frameworks/Chromium Embedded Framework.framework/Libraries/libGLESv2.dylib"
2102
+ \\test -f "$app/Contents/Resources/package-manifest.zon"
2103
+ \\echo "cef package layout ok"
2104
+ , .{optimize_name}),
2105
+ });
2106
+ package_cef_check.step.dependOn(&package_cef_run.step);
2107
+ const package_cef_smoke_step = b.step("test-package-cef-layout", "Verify macOS Chromium package layout");
2108
+ package_cef_smoke_step.dependOn(&package_cef_check.step);
2109
+
2110
+ // Signed-package seal pin: package an ad-hoc signed bundle and prove
2111
+ // the signature survives packaging intact with codesign's own strict
2112
+ // verifier. This is the regression gate for the ordering bug where a
2113
+ // file written into Contents/Resources AFTER signing invalidated the
2114
+ // resource seal ("file added"), turning every quarantined install
2115
+ // into Gatekeeper's "damaged — move to Trash" dialog. The bundle
2116
+ // carries the CLI as its executable (packaging only needs a real
2117
+ // Mach-O to sign); the check skips loudly on hosts without codesign
2118
+ // (any non-macOS machine) instead of pretending to have verified.
2119
+ const package_signing_run = b.addRunArtifact(host_cli_exe);
2120
+ package_signing_run.addArgs(&.{ "package", "--target", "macos", "--output", "zig-out/package/native-sdk-signing-verify.app", "--binary" });
2121
+ package_signing_run.addFileArg(host_cli_exe.getEmittedBin());
2122
+ package_signing_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", "adhoc" });
2123
+ package_signing_run.has_side_effects = true;
2124
+ const package_signing_check = b.addSystemCommand(&.{
2125
+ "sh", "-c",
2126
+ \\set -e
2127
+ \\app="zig-out/package/native-sdk-signing-verify.app"
2128
+ \\if ! command -v codesign >/dev/null 2>&1; then
2129
+ \\ echo "codesign unavailable on this host; skipping signed-package verification"
2130
+ \\ exit 0
2131
+ \\fi
2132
+ \\codesign --verify --strict --deep "$app"
2133
+ \\grep -q "ad-hoc signed" "$app/Contents/Resources/signing-plan.txt"
2134
+ \\echo "signed package verify ok"
2135
+ ,
2136
+ });
2137
+ package_signing_check.step.dependOn(&package_signing_run.step);
2138
+ const package_signing_step = b.step("test-package-signing", "Verify an ad-hoc signed macOS package passes codesign --verify --strict");
2139
+ package_signing_step.dependOn(&package_signing_check.step);
2140
+
2141
+ const package_windows_run = b.addRunArtifact(host_cli_exe);
2142
+ package_windows_run.addArgs(&.{ "package-windows", "--output", b.fmt("zig-out/package/native-sdk-{s}-windows-Debug", .{package_version}), "--manifest", "app.zon", "--assets", "assets" });
2143
+ const package_windows_step = b.step("package-windows", "Create local Windows artifact directory");
2144
+ package_windows_step.dependOn(&package_windows_run.step);
2145
+
2146
+ const package_linux_run = b.addRunArtifact(host_cli_exe);
2147
+ package_linux_run.addArgs(&.{ "package-linux", "--output", b.fmt("zig-out/package/native-sdk-{s}-linux-Debug", .{package_version}), "--manifest", "app.zon", "--assets", "assets" });
2148
+ const package_linux_step = b.step("package-linux", "Create local Linux artifact directory");
2149
+ package_linux_step.dependOn(&package_linux_run.step);
2150
+
2151
+ const package_ios_run = b.addRunArtifact(host_cli_exe);
2152
+ package_ios_run.addArgs(&.{ "package-ios", "--output", b.fmt("zig-out/mobile/native-sdk-{s}-ios-Debug", .{package_version}), "--manifest", "app.zon", "--assets", "assets" });
2153
+ const package_ios_step = b.step("package-ios", "Create local iOS host skeleton");
2154
+ package_ios_step.dependOn(&package_ios_run.step);
2155
+
2156
+ const package_android_run = b.addRunArtifact(host_cli_exe);
2157
+ package_android_run.addArgs(&.{ "package-android", "--output", b.fmt("zig-out/mobile/native-sdk-{s}-android-Debug", .{package_version}), "--manifest", "app.zon", "--assets", "assets" });
2158
+ const package_android_step = b.step("package-android", "Create local Android host project");
2159
+ package_android_step.dependOn(&package_android_run.step);
2160
+
2161
+ // Default app icon: rendered from vector geometry (tools/
2162
+ // generate_app_icon.zig) through the SDK's own path rasterizer, so
2163
+ // the checked-in .icns/.ico/.png/.svg all regenerate from source.
2164
+ // The built-in app-icon pipeline assembles and round-trip-validates
2165
+ // the containers itself (no external tools, any host OS), and the
2166
+ // CLI's embedded scaffold copies are kept in sync.
2167
+ const generate_icon_step = b.step("generate-icon", "Regenerate the default app icon (.icns/.ico/.png/.svg) from vector source");
2168
+ const generate_icon_mod = module(b, target, optimize, "tools/generate_app_icon.zig");
2169
+ generate_icon_mod.addImport("native_sdk", desktop_mod);
2170
+ const generate_icon_exe = b.addExecutable(.{
2171
+ .name = "generate-app-icon",
2172
+ .root_module = generate_icon_mod,
2173
+ });
2174
+ const generate_icon_run = b.addRunArtifact(generate_icon_exe);
2175
+ generate_icon_run.addArgs(&.{
2176
+ "assets/icon.icns",
2177
+ "assets/icon.png",
2178
+ "assets/icon.ico",
2179
+ "assets/icon.svg",
2180
+ "src/tooling/default_icon.icns",
2181
+ "src/tooling/default_icon.png",
2182
+ "zig-out/icon-full-bleed.png",
2183
+ // The one committed full-bleed copy: the notes example's raw
2184
+ // one-image icon source (it demos the packaging mask + inset),
2185
+ // regenerated here so it can never drift from the default.
2186
+ "examples/notes/assets/icon.png",
2187
+ });
2188
+ generate_icon_run.has_side_effects = true;
2189
+ generate_icon_step.dependOn(&generate_icon_run.step);
2190
+
2191
+ const notarize_run = b.addRunArtifact(host_cli_exe);
2192
+ notarize_run.addArgs(&.{
2193
+ "package",
2194
+ "--target",
2195
+ "macos",
2196
+ "--output",
2197
+ b.fmt("zig-out/package/native-sdk-{s}-macos-{s}.app", .{ package_version, optimize_name }),
2198
+ "--binary",
2199
+ });
2200
+ notarize_run.addFileArg(embed_lib.getEmittedBin());
2201
+ notarize_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", "identity", "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
2202
+ if (cef_auto_install) notarize_run.addArg("--cef-auto-install");
2203
+ notarize_run.step.dependOn(&embed_lib.step);
2204
+ notarize_run.step.dependOn(&bundle_run.step);
2205
+ const notarize_step = b.step("notarize", "Package, sign with identity, and notarize for macOS distribution");
2206
+ notarize_step.dependOn(&notarize_run.step);
2207
+
2208
+ const dmg_script = b.addSystemCommand(&.{
2209
+ "sh", "-c",
2210
+ b.fmt(
2211
+ \\APP="zig-out/package/native-sdk-{s}-macos-{s}.app"
2212
+ \\DMG="zig-out/package/native-sdk-{s}-macos-{s}.dmg"
2213
+ \\test -d "$APP" || {{ echo "run 'zig build package' first" >&2; exit 1; }}
2214
+ \\hdiutil create -volname "native-sdk" -srcfolder "$APP" -ov -format UDZO "$DMG"
2215
+ \\echo "created $DMG"
2216
+ , .{ package_version, optimize_name, package_version, optimize_name }),
2217
+ });
2218
+ dmg_script.step.dependOn(&package_run.step);
2219
+ const dmg_step = b.step("dmg", "Create macOS .dmg disk image from the packaged .app");
2220
+ dmg_step.dependOn(&dmg_script.step);
2221
+
2222
+ const cef_bundle_script = b.addSystemCommand(&.{
2223
+ "sh", "-c",
2224
+ b.fmt(
2225
+ \\set -e
2226
+ \\rm -rf "zig-out/Frameworks/Chromium Embedded Framework.framework" "zig-out/bin/Frameworks/Chromium Embedded Framework.framework" ".zig-cache/o/Frameworks/Chromium Embedded Framework.framework"
2227
+ \\mkdir -p "zig-out/Frameworks" "zig-out/bin/Frameworks" ".zig-cache/o/Frameworks"
2228
+ \\cp -R "{s}/Release/Chromium Embedded Framework.framework" "zig-out/Frameworks/"
2229
+ \\cp -R "{s}/Release/Chromium Embedded Framework.framework" "zig-out/bin/Frameworks/"
2230
+ \\cp -R "{s}/Release/Chromium Embedded Framework.framework" ".zig-cache/o/Frameworks/"
2231
+ \\if [ -d "{s}/Resources" ]; then
2232
+ \\ mkdir -p "zig-out/bin/Resources/cef"
2233
+ \\ cp -R "{s}/Resources/"* "zig-out/bin/Resources/cef/"
2234
+ \\fi
2235
+ \\echo "CEF framework copied for local dev runs"
2236
+ , .{ cef_dir, cef_dir, cef_dir, cef_dir, cef_dir }),
2237
+ });
2238
+ const cef_bundle_step = b.step("cef-bundle", "Copy CEF framework and resources into zig-out/bin/ for local dev runs");
2239
+ if (cef_auto_install) {
2240
+ const cef_bundle_auto = b.addRunArtifact(host_cli_exe);
2241
+ cef_bundle_auto.addArgs(&.{ "cef", "install", "--dir", cef_dir });
2242
+ cef_bundle_script.step.dependOn(&cef_bundle_auto.step);
2243
+ }
2244
+ cef_bundle_step.dependOn(&cef_bundle_script.step);
2245
+ }
2246
+
2247
+ fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, path: []const u8) *std.Build.Module {
2248
+ return b.createModule(.{
2249
+ .root_source_file = b.path(path),
2250
+ .target = target,
2251
+ .optimize = optimize,
2252
+ });
2253
+ }
2254
+
2255
+ /// The short commit hash of the framework checkout the CLI is built
2256
+ /// from, for `native version` staleness checks. "unknown" when
2257
+ /// git is unavailable (e.g. building from a package tarball).
2258
+ fn cliBuildCommit(b: *std.Build) []const u8 {
2259
+ var code: u8 = undefined;
2260
+ const output = b.runAllowFail(&.{ "git", "rev-parse", "--short", "HEAD" }, &code, .ignore) catch return "unknown";
2261
+ const trimmed = std.mem.trim(u8, output, " \n\r\t");
2262
+ if (trimmed.len == 0) return "unknown";
2263
+ return trimmed;
2264
+ }
2265
+
2266
+ fn testArtifact(b: *std.Build, mod: *std.Build.Module) *std.Build.Step.Compile {
2267
+ return filteredTestArtifact(b, mod, "test", &.{});
2268
+ }
2269
+
2270
+ fn filteredTestArtifact(b: *std.Build, mod: *std.Build.Module, name: []const u8, filters: []const []const u8) *std.Build.Step.Compile {
2271
+ // use_llvm: Zig 0.16.0's self-hosted x86_64 backend miscompiles the
2272
+ // SysV C ABI for f32-heavy signatures (native_sdk_app_viewport); see
2273
+ // useLlvmWorkaround in build/app.zig for the full story and repro.
2274
+ const use_llvm = if (mod.resolved_target) |target| @import("build/app.zig").useLlvmWorkaround(target) else null;
2275
+ return b.addTest(.{ .name = name, .root_module = mod, .filters = filters, .use_llvm = use_llvm });
2276
+ }
2277
+
2278
+ /// One slice of the framework test suite, selected by test-name filters.
2279
+ /// The framework module compiles into a single test binary whose ~580
2280
+ /// tests run serially in one process, which made that binary the longest
2281
+ /// step in `zig build test` by a wide margin — the rest of the suite is
2282
+ /// dozens of binaries that each finish in well under a second. The
2283
+ /// aggregate `test` step therefore runs the framework module as one
2284
+ /// filtered binary per family below, so the build runner executes the
2285
+ /// families concurrently and the suite finishes with the slowest family
2286
+ /// instead of the sum of all of them. `zig build test-desktop` still runs
2287
+ /// the unfiltered binary when a single process is easier to debug, and
2288
+ /// each family has its own `test-desktop-<name>` step.
2289
+ const DesktopTestShard = struct {
2290
+ /// Suffix for the artifact name and the `test-desktop-<name>` step.
2291
+ name: []const u8,
2292
+ description: []const u8,
2293
+ /// A test file's namespace is routed to the first shard in
2294
+ /// `desktop_test_shard_specs` with a matching prefix, so earlier
2295
+ /// entries carve their family out of the later, broader ones and
2296
+ /// the final empty prefix collects every namespace left over.
2297
+ prefixes: []const []const u8,
2298
+ };
2299
+
2300
+ const desktop_test_shard_specs = [_]DesktopTestShard{
2301
+ .{
2302
+ .name = "canvas-widget",
2303
+ .description = "Run framework canvas widget tests",
2304
+ .prefixes = &.{"runtime.canvas_widget"},
2305
+ },
2306
+ .{
2307
+ .name = "canvas-frame",
2308
+ .description = "Run framework canvas frame, budget, image, and font tests",
2309
+ .prefixes = &.{"runtime.canvas"},
2310
+ },
2311
+ .{
2312
+ .name = "ui-shell",
2313
+ .description = "Run framework UI app and shell layout tests",
2314
+ .prefixes = &.{ "runtime.ui_app", "runtime.shell" },
2315
+ },
2316
+ .{
2317
+ .name = "runtime-core",
2318
+ .description = "Run framework runtime core, effects, session, and bridge tests",
2319
+ .prefixes = &.{"runtime."},
2320
+ },
2321
+ .{
2322
+ .name = "platform",
2323
+ .description = "Run framework platform, automation, embed, and remaining tests",
2324
+ .prefixes = &.{""},
2325
+ },
2326
+ };
2327
+
2328
+ /// A framework source file that declares top-level tests, described by
2329
+ /// the dotted namespace the test runner uses in fully-qualified test
2330
+ /// names: tests in src/runtime/effects_tests.zig are named
2331
+ /// "runtime.effects_tests.test.<name>".
2332
+ const DesktopTestFile = struct {
2333
+ namespace: []const u8,
2334
+ /// Names of the file's `test "<name>"` declarations, in source order.
2335
+ /// Unnamed `test { ... }` blocks are not listed: the test runner
2336
+ /// exempts them from filtering, so they run in every shard. That is
2337
+ /// deliberate — those blocks are the aggregators whose references
2338
+ /// make the compiler discover the named tests in the first place,
2339
+ /// and their bodies are empty at run time.
2340
+ named_tests: []const []const u8,
2341
+ };
2342
+
2343
+ /// Test binaries for the framework module, one per shard spec. Filters
2344
+ /// are derived from the source tree at configure time: every framework
2345
+ /// file with a top-level `test` declaration contributes its namespace as
2346
+ /// a filter ("runtime.effects_tests.test") to exactly one shard, so a
2347
+ /// new test file is picked up — and routed to a shard by prefix — the
2348
+ /// moment it exists, and a file can never silently fall out of
2349
+ /// `zig build test` because a hand-kept list went stale.
2350
+ fn desktopTestShardArtifacts(b: *std.Build, mod: *std.Build.Module) [desktop_test_shard_specs.len]*std.Build.Step.Compile {
2351
+ const files = desktopTestFiles(b);
2352
+ var filters: [desktop_test_shard_specs.len]std.ArrayList([]const u8) = @splat(.empty);
2353
+ for (files) |file| {
2354
+ const shard = desktopTestShardIndex(file.namespace);
2355
+ if (std.mem.eql(u8, file.namespace, "root")) {
2356
+ // Filters match anywhere in a fully-qualified name, and the
2357
+ // module root's namespace ("root") is a dotted suffix of
2358
+ // every other root.zig namespace ("runtime.root",
2359
+ // "platform.root", ...), so a bare "root.test" filter would
2360
+ // pull those files' tests into this shard as well. Filter
2361
+ // the module root by exact test name instead.
2362
+ for (file.named_tests) |test_name| {
2363
+ filters[shard].append(b.allocator, b.fmt("root.test.{s}", .{test_name})) catch @panic("OOM");
2364
+ }
2365
+ continue;
2366
+ }
2367
+ filters[shard].append(b.allocator, b.fmt("{s}.test", .{file.namespace})) catch @panic("OOM");
2368
+ // The same suffix hazard across two shards would run the longer
2369
+ // file's tests twice per `zig build test`. Refuse the layout up
2370
+ // front so the collision is resolved when the file is added, not
2371
+ // when a duplicated test starts flaking.
2372
+ for (files) |other| {
2373
+ if (desktopTestShardIndex(other.namespace) == shard) continue;
2374
+ if (std.mem.endsWith(u8, other.namespace, b.fmt(".{s}", .{file.namespace}))) {
2375
+ std.debug.panic(
2376
+ "framework test shards: namespace {s} is a dotted suffix of {s} in another shard; their name filters would overlap. Adjust desktop_test_shard_specs so both land in one shard.",
2377
+ .{ file.namespace, other.namespace },
2378
+ );
2379
+ }
2380
+ }
2381
+ }
2382
+ var artifacts: [desktop_test_shard_specs.len]*std.Build.Step.Compile = undefined;
2383
+ for (&artifacts, desktop_test_shard_specs, filters) |*artifact, spec, shard_filters| {
2384
+ artifact.* = filteredTestArtifact(b, mod, b.fmt("desktop-{s}-tests", .{spec.name}), shard_filters.items);
2385
+ }
2386
+ return artifacts;
2387
+ }
2388
+
2389
+ fn desktopTestShardIndex(namespace: []const u8) usize {
2390
+ for (desktop_test_shard_specs, 0..) |spec, index| {
2391
+ for (spec.prefixes) |prefix| {
2392
+ if (std.mem.startsWith(u8, namespace, prefix)) return index;
2393
+ }
2394
+ }
2395
+ unreachable; // the final shard's empty prefix matches every namespace
2396
+ }
2397
+
2398
+ /// Scans the framework source tree for files declaring top-level tests,
2399
+ /// sorted by namespace so the generated filters — and therefore the
2400
+ /// shard binaries' cache manifests — do not churn with directory
2401
+ /// iteration order. src/primitives and src/tooling are separate modules
2402
+ /// with their own test binaries; everything else under src/ belongs to
2403
+ /// the framework module rooted at src/root.zig.
2404
+ fn desktopTestFiles(b: *std.Build) []const DesktopTestFile {
2405
+ const gpa = b.allocator;
2406
+ const io = b.graph.io;
2407
+ var files: std.ArrayList(DesktopTestFile) = .empty;
2408
+ var src_dir = b.build_root.handle.openDir(io, "src", .{ .iterate = true }) catch |err|
2409
+ std.debug.panic("framework test shards: unable to open src/: {s}", .{@errorName(err)});
2410
+ defer src_dir.close(io);
2411
+ var walker = src_dir.walk(gpa) catch @panic("OOM");
2412
+ defer walker.deinit();
2413
+ while (walker.next(io) catch |err|
2414
+ std.debug.panic("framework test shards: unable to walk src/: {s}", .{@errorName(err)})) |entry|
2415
+ {
2416
+ if (entry.kind == .directory) {
2417
+ if (entry.depth() == 1 and
2418
+ (std.mem.eql(u8, entry.basename, "primitives") or std.mem.eql(u8, entry.basename, "tooling")))
2419
+ {
2420
+ walker.leave(io);
2421
+ }
2422
+ continue;
2423
+ }
2424
+ if (entry.kind != .file or !std.mem.endsWith(u8, entry.basename, ".zig")) continue;
2425
+ const source = entry.dir.readFileAlloc(io, entry.basename, gpa, .limited(16 * 1024 * 1024)) catch |err|
2426
+ std.debug.panic("framework test shards: unable to read src/{s}: {s}", .{ entry.path, @errorName(err) });
2427
+ var named_tests: std.ArrayList([]const u8) = .empty;
2428
+ var has_tests = false;
2429
+ var lines = std.mem.splitScalar(u8, source, '\n');
2430
+ while (lines.next()) |line| {
2431
+ // Only column-zero declarations: a test nested inside a
2432
+ // container would carry that container's namespace, which
2433
+ // these filters would not match.
2434
+ if (!std.mem.startsWith(u8, line, "test ")) continue;
2435
+ has_tests = true;
2436
+ const rest = line["test ".len..];
2437
+ if (rest.len > 0 and rest[0] == '"') {
2438
+ if (std.mem.indexOfScalar(u8, rest[1..], '"')) |end| {
2439
+ named_tests.append(gpa, rest[1 .. 1 + end]) catch @panic("OOM");
2440
+ }
2441
+ }
2442
+ }
2443
+ if (!has_tests) continue;
2444
+ const namespace = gpa.dupe(u8, entry.path[0 .. entry.path.len - ".zig".len]) catch @panic("OOM");
2445
+ std.mem.replaceScalar(u8, namespace, std.fs.path.sep, '.');
2446
+ files.append(gpa, .{ .namespace = namespace, .named_tests = named_tests.items }) catch @panic("OOM");
2447
+ }
2448
+ const sorted = files.items;
2449
+ std.mem.sort(DesktopTestFile, sorted, {}, struct {
2450
+ fn lessThan(_: void, lhs: DesktopTestFile, rhs: DesktopTestFile) bool {
2451
+ return std.mem.lessThan(u8, lhs.namespace, rhs.namespace);
2452
+ }
2453
+ }.lessThan);
2454
+ return sorted;
2455
+ }
2456
+
2457
+ fn addTestStep(b: *std.Build, name: []const u8, description: []const u8, artifact: *std.Build.Step.Compile) void {
2458
+ const step = b.step(name, description);
2459
+ step.dependOn(&b.addRunArtifact(artifact).step);
2460
+ }
2461
+
2462
+ /// How an example's build is driven. `managed` examples carry only
2463
+ /// app.zon + src (+ assets): the `native` CLI synthesizes their build
2464
+ /// graph, so their suites run through the CLI verbs — exactly what a user
2465
+ /// gets from `native init`. `owned` examples keep a build.zig of their own
2466
+ /// (extra steps or flags the generated graph does not provide) and are
2467
+ /// driven through plain in-dir `zig build`.
2468
+ const ExampleBuildShape = enum { managed, owned };
2469
+
2470
+ fn addExampleTestStep(b: *std.Build, cli_exe: *std.Build.Step.Compile, group: *std.Build.Step, name: []const u8, description: []const u8, example_path: []const u8, shape: ExampleBuildShape) void {
2471
+ const run = switch (shape) {
2472
+ .owned => b.addSystemCommand(&.{ "zig", "build", "test", "-Dplatform=null" }),
2473
+ .managed => managedExampleRun(b, cli_exe, &.{ "test", "-Dplatform=null" }),
2474
+ };
2475
+ run.setCwd(b.path(example_path));
2476
+ // Every example suite must actually run every time: the child build owns
2477
+ // its own caching, and this outer step's argv never changes when example
2478
+ // or framework sources do, so letting the step cache would skip real
2479
+ // tests. But a side-effect run that also inherits stdio holds the build
2480
+ // runner's global stderr lock for the child's entire lifetime, which
2481
+ // executes the example suites strictly one at a time. Capturing both
2482
+ // streams keeps the always-run semantics while releasing that lock, so
2483
+ // independent examples run concurrently (bounded by the runner's job
2484
+ // pool, one worker per CPU — cold child builds peak well under 1 GB
2485
+ // each, so a machine-wide pool of them fits in memory). On failure the
2486
+ // captured stderr is reported under this step's name, so a failing
2487
+ // example still names itself.
2488
+ run.has_side_effects = true;
2489
+ _ = run.captureStdOut(.{});
2490
+ _ = run.captureStdErr(.{});
2491
+ // Concurrent children all spawn the same binary, so carry the step name
2492
+ // into the run: a failure line then reads "test-example-<name> failure"
2493
+ // instead of nineteen indistinguishable "run exe native" entries.
2494
+ run.setName(name);
2495
+ const step = b.step(name, description);
2496
+ step.dependOn(&run.step);
2497
+ group.dependOn(&run.step);
2498
+ }
2499
+
2500
+ /// Run a `native` CLI verb (argv tail) against a managed example. The CLI
2501
+ /// artifact runs from the build cache, where its executable location does
2502
+ /// not reveal the framework checkout, so NATIVE_SDK_PATH pins the generated
2503
+ /// graph's framework dependency to this repository.
2504
+ fn managedExampleRun(b: *std.Build, cli_exe: *std.Build.Step.Compile, argv_tail: []const []const u8) *std.Build.Step.Run {
2505
+ const run = b.addRunArtifact(cli_exe);
2506
+ run.addArgs(argv_tail);
2507
+ run.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot("."));
2508
+ return run;
2509
+ }
2510
+
2511
+ fn addLayoutCheckStep(b: *std.Build, group: *std.Build.Step, name: []const u8, description: []const u8, paths: []const []const u8) void {
2512
+ const step = b.step(name, description);
2513
+ for (paths) |path| {
2514
+ const check = b.addSystemCommand(&.{ "test", "-f", path });
2515
+ step.dependOn(&check.step);
2516
+ group.dependOn(&check.step);
2517
+ }
2518
+ }
2519
+
2520
+ const FileContainsCheck = struct {
2521
+ path: []const u8,
2522
+ pattern: []const u8,
2523
+ };
2524
+
2525
+ fn addFileContainsCheckStep(b: *std.Build, checker: *std.Build.Step.Compile, group: *std.Build.Step, name: []const u8, description: []const u8, checks: []const FileContainsCheck) void {
2526
+ const step = b.step(name, description);
2527
+ for (checks) |check_value| {
2528
+ const check = b.addRunArtifact(checker);
2529
+ // The checked paths are relative to this build script. Run steps
2530
+ // otherwise inherit the invoking process's cwd, and `zig build test`
2531
+ // is also invoked from zero-config app directories that resolve up
2532
+ // to this build.zig (scaffolded workspaces, examples) — from there
2533
+ // the relative paths would point into the app, not the repo.
2534
+ check.setCwd(b.path("."));
2535
+ check.addArg(check_value.path);
2536
+ check.addArg(check_value.pattern);
2537
+ step.dependOn(&check.step);
2538
+ group.dependOn(&check.step);
2539
+ }
2540
+ }
2541
+
2542
+ fn packageSuffix(target: PackageTarget) []const u8 {
2543
+ return switch (target) {
2544
+ .macos => ".app",
2545
+ .windows, .linux, .ios, .android => "",
2546
+ };
2547
+ }
2548
+
2549
+ fn packageVersion(b: *std.Build) []const u8 {
2550
+ var file = std.Io.Dir.cwd().openFile(b.graph.io, "build.zig.zon", .{}) catch return "0.1.0";
2551
+ defer file.close(b.graph.io);
2552
+ var buffer: [4096]u8 = undefined;
2553
+ const len = file.readPositionalAll(b.graph.io, &buffer, 0) catch return "0.1.0";
2554
+ const bytes = buffer[0..len];
2555
+ const marker = ".version = \"";
2556
+ const start = std.mem.indexOf(u8, bytes, marker) orelse return "0.1.0";
2557
+ const value_start = start + marker.len;
2558
+ const value_end = std.mem.indexOfScalarPos(u8, bytes, value_start, '"') orelse return "0.1.0";
2559
+ return b.allocator.dupe(u8, bytes[value_start..value_end]) catch return "0.1.0";
2560
+ }
2561
+
2562
+ fn defaultCefDir(platform: PlatformOption, configured: []const u8) []const u8 {
2563
+ if (!std.mem.eql(u8, configured, web_engine_tool.default_cef_dir)) return configured;
2564
+ return switch (platform) {
2565
+ .linux => "third_party/cef/linux",
2566
+ .windows => "third_party/cef/windows",
2567
+ else => configured,
2568
+ };
2569
+ }
2570
+
2571
+ /// CEF dir for a sub-build whose cwd is an example directory (two levels
2572
+ /// below the repo root). Relative paths are resolved by the example's
2573
+ /// build against its own root, so the repo-root-relative default must be
2574
+ /// rebased; absolute overrides pass through, but the example build.zigs
2575
+ /// reject them (b.path panics), so callers should prefer relative paths.
2576
+ fn exampleCefDir(b: *std.Build, cef_dir: []const u8) []const u8 {
2577
+ if (std.fs.path.isAbsolute(cef_dir)) return cef_dir;
2578
+ return b.fmt("../../{s}", .{cef_dir});
2579
+ }
2580
+
2581
+ fn webEngineFromBuildOption(option: WebEngineOption) web_engine_tool.Engine {
2582
+ return switch (option) {
2583
+ .system => .system,
2584
+ .chromium => .chromium,
2585
+ };
2586
+ }
2587
+
2588
+ fn buildWebEngineFromResolved(engine: web_engine_tool.Engine) WebEngineOption {
2589
+ return switch (engine) {
2590
+ .system => .system,
2591
+ .chromium => .chromium,
2592
+ };
2593
+ }