@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
@@ -0,0 +1,1939 @@
1
+ const std = @import("std");
2
+ const app_icon_tool = @import("app_icon");
3
+ const app_manifest = @import("app_manifest");
4
+ const diagnostics = @import("diagnostics");
5
+ const raw_manifest = @import("raw_manifest.zig");
6
+ const web_engine_tool = @import("web_engine.zig");
7
+
8
+ pub const ValidationResult = struct {
9
+ ok: bool,
10
+ message: []const u8,
11
+ };
12
+
13
+ pub const Metadata = struct {
14
+ id: []const u8,
15
+ name: []const u8,
16
+ display_name: ?[]const u8 = null,
17
+ /// One human-facing sentence about the app: the About panel credits
18
+ /// line on macOS. Optional — absent means no credits line.
19
+ description: ?[]const u8 = null,
20
+ version: []const u8,
21
+ icons: []const []const u8 = &.{},
22
+ platforms: []const []const u8 = &.{},
23
+ permissions: []const []const u8 = &.{},
24
+ capabilities: []const []const u8 = &.{},
25
+ bridge_commands: []const BridgeCommandMetadata = &.{},
26
+ web_engine: []const u8 = "system",
27
+ /// The built-in theme pack the app selects (`theme = "geist"`).
28
+ /// Optional — absent keeps the house register. Validated against
29
+ /// the known pack names so a typo is a check error, never a silent
30
+ /// default-theme fallback.
31
+ theme: ?[]const u8 = null,
32
+ cef: web_engine_tool.CefConfig = .{},
33
+ frontend: ?FrontendMetadata = null,
34
+ security: SecurityMetadata = .{},
35
+ windows: []const WindowMetadata = &.{},
36
+ shell: ShellMetadata = .{},
37
+ commands: []const CommandMetadata = &.{},
38
+ menus: []const MenuMetadata = &.{},
39
+ shortcuts: []const ShortcutMetadata = &.{},
40
+ file_associations: []const FileAssociationMetadata = &.{},
41
+ url_schemes: []const UrlSchemeMetadata = &.{},
42
+
43
+ pub fn displayName(self: Metadata) []const u8 {
44
+ return self.display_name orelse self.name;
45
+ }
46
+
47
+ pub fn deinit(self: Metadata, allocator: std.mem.Allocator) void {
48
+ allocator.free(self.id);
49
+ allocator.free(self.name);
50
+ if (self.display_name) |value| allocator.free(value);
51
+ if (self.description) |value| allocator.free(value);
52
+ if (self.theme) |value| allocator.free(value);
53
+ allocator.free(self.version);
54
+ allocator.free(self.web_engine);
55
+ allocator.free(self.cef.dir);
56
+ for (self.icons) |value| allocator.free(value);
57
+ if (self.icons.len > 0) allocator.free(self.icons);
58
+ for (self.platforms) |value| allocator.free(value);
59
+ if (self.platforms.len > 0) allocator.free(self.platforms);
60
+ for (self.permissions) |value| allocator.free(value);
61
+ if (self.permissions.len > 0) allocator.free(self.permissions);
62
+ for (self.capabilities) |value| allocator.free(value);
63
+ if (self.capabilities.len > 0) allocator.free(self.capabilities);
64
+ for (self.bridge_commands) |command| {
65
+ allocator.free(command.name);
66
+ for (command.permissions) |value| allocator.free(value);
67
+ if (command.permissions.len > 0) allocator.free(command.permissions);
68
+ for (command.origins) |value| allocator.free(value);
69
+ if (command.origins.len > 0) allocator.free(command.origins);
70
+ }
71
+ if (self.bridge_commands.len > 0) allocator.free(self.bridge_commands);
72
+ if (self.frontend) |frontend| {
73
+ allocator.free(frontend.dist);
74
+ allocator.free(frontend.entry);
75
+ if (frontend.dev) |dev| {
76
+ allocator.free(dev.url);
77
+ for (dev.command) |value| allocator.free(value);
78
+ if (dev.command.len > 0) allocator.free(dev.command);
79
+ allocator.free(dev.ready_path);
80
+ }
81
+ }
82
+ for (self.security.navigation.allowed_origins) |value| allocator.free(value);
83
+ if (self.security.navigation.allowed_origins.len > 0) allocator.free(self.security.navigation.allowed_origins);
84
+ if (!std.mem.eql(u8, self.security.navigation.external_links.action, "deny") or self.security.navigation.external_links.allowed_urls.len > 0) {
85
+ allocator.free(self.security.navigation.external_links.action);
86
+ }
87
+ for (self.security.navigation.external_links.allowed_urls) |value| allocator.free(value);
88
+ if (self.security.navigation.external_links.allowed_urls.len > 0) allocator.free(self.security.navigation.external_links.allowed_urls);
89
+ for (self.windows) |window| {
90
+ allocator.free(window.label);
91
+ if (window.title) |title| allocator.free(title);
92
+ allocator.free(window.titlebar);
93
+ }
94
+ if (self.windows.len > 0) allocator.free(self.windows);
95
+ for (self.shell.windows) |window| {
96
+ allocator.free(window.label);
97
+ if (window.title) |title| allocator.free(title);
98
+ allocator.free(window.restore_policy);
99
+ allocator.free(window.titlebar);
100
+ for (window.views) |view| {
101
+ allocator.free(view.label);
102
+ allocator.free(view.kind);
103
+ if (view.parent) |parent| allocator.free(parent);
104
+ if (view.edge) |edge| allocator.free(edge);
105
+ if (view.axis) |axis| allocator.free(axis);
106
+ if (view.role) |role| allocator.free(role);
107
+ if (view.accessibility_label) |accessibility_label| allocator.free(accessibility_label);
108
+ if (view.url) |url| allocator.free(url);
109
+ if (view.text) |text| allocator.free(text);
110
+ if (view.command) |command| allocator.free(command);
111
+ if (view.gpu_backend) |gpu_backend| allocator.free(gpu_backend);
112
+ if (view.gpu_pixel_format) |gpu_pixel_format| allocator.free(gpu_pixel_format);
113
+ if (view.gpu_present_mode) |gpu_present_mode| allocator.free(gpu_present_mode);
114
+ if (view.gpu_alpha_mode) |gpu_alpha_mode| allocator.free(gpu_alpha_mode);
115
+ if (view.gpu_color_space) |gpu_color_space| allocator.free(gpu_color_space);
116
+ }
117
+ if (window.views.len > 0) allocator.free(window.views);
118
+ }
119
+ if (self.shell.windows.len > 0) allocator.free(self.shell.windows);
120
+ for (self.shell.chrome.tabs) |tab| {
121
+ allocator.free(tab.id);
122
+ allocator.free(tab.label);
123
+ allocator.free(tab.icon);
124
+ }
125
+ if (self.shell.chrome.tabs.len > 0) allocator.free(self.shell.chrome.tabs);
126
+ if (self.shell.chrome.primary_action) |action| {
127
+ allocator.free(action.id);
128
+ allocator.free(action.label);
129
+ allocator.free(action.icon);
130
+ }
131
+ for (self.commands) |command| {
132
+ allocator.free(command.id);
133
+ allocator.free(command.title);
134
+ }
135
+ if (self.commands.len > 0) allocator.free(self.commands);
136
+ for (self.menus) |menu| {
137
+ allocator.free(menu.title);
138
+ for (menu.items) |item| {
139
+ allocator.free(item.label);
140
+ allocator.free(item.command);
141
+ allocator.free(item.key);
142
+ for (item.modifiers) |value| allocator.free(value);
143
+ if (item.modifiers.len > 0) allocator.free(item.modifiers);
144
+ }
145
+ if (menu.items.len > 0) allocator.free(menu.items);
146
+ }
147
+ if (self.menus.len > 0) allocator.free(self.menus);
148
+ for (self.shortcuts) |shortcut| {
149
+ allocator.free(shortcut.id);
150
+ allocator.free(shortcut.key);
151
+ for (shortcut.modifiers) |value| allocator.free(value);
152
+ if (shortcut.modifiers.len > 0) allocator.free(shortcut.modifiers);
153
+ }
154
+ if (self.shortcuts.len > 0) allocator.free(self.shortcuts);
155
+ for (self.file_associations) |association| {
156
+ allocator.free(association.name);
157
+ allocator.free(association.role);
158
+ for (association.extensions) |value| allocator.free(value);
159
+ if (association.extensions.len > 0) allocator.free(association.extensions);
160
+ for (association.mime_types) |value| allocator.free(value);
161
+ if (association.mime_types.len > 0) allocator.free(association.mime_types);
162
+ if (association.icon) |icon| allocator.free(icon);
163
+ }
164
+ if (self.file_associations.len > 0) allocator.free(self.file_associations);
165
+ for (self.url_schemes) |scheme| {
166
+ allocator.free(scheme.scheme);
167
+ allocator.free(scheme.role);
168
+ }
169
+ if (self.url_schemes.len > 0) allocator.free(self.url_schemes);
170
+ }
171
+ };
172
+
173
+ pub const BridgeCommandMetadata = struct {
174
+ name: []const u8,
175
+ permissions: []const []const u8 = &.{},
176
+ origins: []const []const u8 = &.{},
177
+ };
178
+
179
+ pub const WindowMetadata = struct {
180
+ label: []const u8 = "main",
181
+ title: ?[]const u8 = null,
182
+ width: f32 = 720,
183
+ height: f32 = 480,
184
+ x: ?f32 = null,
185
+ y: ?f32 = null,
186
+ resizable: bool = true,
187
+ restore_state: bool = true,
188
+ titlebar: []const u8 = "standard",
189
+ min_width: f32 = 0,
190
+ min_height: f32 = 0,
191
+ };
192
+
193
+ pub const ShellMetadata = struct {
194
+ windows: []const ShellWindowMetadata = &.{},
195
+ chrome: ShellChromeMetadata = .{},
196
+ };
197
+
198
+ pub const ShellChromeMetadata = struct {
199
+ tabs: []const ShellTabMetadata = &.{},
200
+ primary_action: ?ShellPrimaryActionMetadata = null,
201
+ };
202
+
203
+ pub const ShellTabMetadata = struct {
204
+ id: []const u8,
205
+ label: []const u8,
206
+ icon: []const u8 = "",
207
+ };
208
+
209
+ pub const ShellPrimaryActionMetadata = struct {
210
+ id: []const u8,
211
+ label: []const u8,
212
+ icon: []const u8 = "",
213
+ };
214
+
215
+ pub const ShellWindowMetadata = struct {
216
+ label: []const u8 = "main",
217
+ title: ?[]const u8 = null,
218
+ width: f32 = 720,
219
+ height: f32 = 480,
220
+ x: ?f32 = null,
221
+ y: ?f32 = null,
222
+ resizable: bool = true,
223
+ restore_state: bool = true,
224
+ restore_policy: []const u8 = "clamp_to_visible_screen",
225
+ titlebar: []const u8 = "standard",
226
+ min_width: f32 = 0,
227
+ min_height: f32 = 0,
228
+ views: []const ShellViewMetadata = &.{},
229
+ };
230
+
231
+ pub const ShellViewMetadata = struct {
232
+ label: []const u8,
233
+ kind: []const u8,
234
+ parent: ?[]const u8 = null,
235
+ edge: ?[]const u8 = null,
236
+ axis: ?[]const u8 = null,
237
+ x: ?f32 = null,
238
+ y: ?f32 = null,
239
+ width: ?f32 = null,
240
+ height: ?f32 = null,
241
+ min_width: ?f32 = null,
242
+ min_height: ?f32 = null,
243
+ max_width: ?f32 = null,
244
+ max_height: ?f32 = null,
245
+ fill: bool = false,
246
+ layer: i32 = 0,
247
+ visible: bool = true,
248
+ enabled: bool = true,
249
+ role: ?[]const u8 = null,
250
+ accessibility_label: ?[]const u8 = null,
251
+ url: ?[]const u8 = null,
252
+ text: ?[]const u8 = null,
253
+ command: ?[]const u8 = null,
254
+ gpu_backend: ?[]const u8 = null,
255
+ gpu_pixel_format: ?[]const u8 = null,
256
+ gpu_present_mode: ?[]const u8 = null,
257
+ gpu_alpha_mode: ?[]const u8 = null,
258
+ gpu_color_space: ?[]const u8 = null,
259
+ gpu_vsync: ?bool = null,
260
+ };
261
+
262
+ pub const ShortcutMetadata = struct {
263
+ id: []const u8,
264
+ key: []const u8,
265
+ modifiers: []const []const u8 = &.{},
266
+ };
267
+
268
+ pub const CommandMetadata = struct {
269
+ id: []const u8,
270
+ title: []const u8 = "",
271
+ enabled: bool = true,
272
+ checked: bool = false,
273
+ };
274
+
275
+ pub const MenuMetadata = struct {
276
+ title: []const u8,
277
+ items: []const MenuItemMetadata = &.{},
278
+ };
279
+
280
+ pub const MenuItemMetadata = struct {
281
+ label: []const u8 = "",
282
+ command: []const u8 = "",
283
+ key: []const u8 = "",
284
+ modifiers: []const []const u8 = &.{},
285
+ separator: bool = false,
286
+ enabled: bool = true,
287
+ checked: bool = false,
288
+ };
289
+
290
+ pub const FileAssociationMetadata = struct {
291
+ name: []const u8,
292
+ role: []const u8 = "viewer",
293
+ extensions: []const []const u8 = &.{},
294
+ mime_types: []const []const u8 = &.{},
295
+ icon: ?[]const u8 = null,
296
+ };
297
+
298
+ pub const UrlSchemeMetadata = struct {
299
+ scheme: []const u8,
300
+ role: []const u8 = "viewer",
301
+ };
302
+
303
+ pub const FrontendDevMetadata = struct {
304
+ url: []const u8,
305
+ command: []const []const u8 = &.{},
306
+ ready_path: []const u8 = "/",
307
+ timeout_ms: u32 = 30_000,
308
+ };
309
+
310
+ pub const FrontendMetadata = struct {
311
+ dist: []const u8 = "dist",
312
+ entry: []const u8 = "index.html",
313
+ spa_fallback: bool = true,
314
+ dev: ?FrontendDevMetadata = null,
315
+ };
316
+
317
+ pub const ExternalLinkMetadata = struct {
318
+ action: []const u8 = "deny",
319
+ allowed_urls: []const []const u8 = &.{},
320
+ };
321
+
322
+ pub const NavigationMetadata = struct {
323
+ allowed_origins: []const []const u8 = &.{},
324
+ external_links: ExternalLinkMetadata = .{},
325
+ };
326
+
327
+ pub const SecurityMetadata = struct {
328
+ navigation: NavigationMetadata = .{},
329
+ };
330
+
331
+ const RawManifest = raw_manifest.RawManifest;
332
+ const RawBridge = raw_manifest.RawBridge;
333
+ const RawBridgeCommand = raw_manifest.RawBridgeCommand;
334
+ const RawFrontend = raw_manifest.RawFrontend;
335
+ const RawFrontendDev = raw_manifest.RawFrontendDev;
336
+ const RawSecurity = raw_manifest.RawSecurity;
337
+ const RawNavigation = raw_manifest.RawNavigation;
338
+ const RawExternalLinks = raw_manifest.RawExternalLinks;
339
+ const RawWindow = raw_manifest.RawWindow;
340
+ const RawShell = raw_manifest.RawShell;
341
+ const RawShellWindow = raw_manifest.RawShellWindow;
342
+ const RawShellView = raw_manifest.RawShellView;
343
+ const RawCommand = raw_manifest.RawCommand;
344
+ const RawMenu = raw_manifest.RawMenu;
345
+ const RawMenuItem = raw_manifest.RawMenuItem;
346
+ const RawShortcut = raw_manifest.RawShortcut;
347
+ const RawFileAssociation = raw_manifest.RawFileAssociation;
348
+ const RawUrlScheme = raw_manifest.RawUrlScheme;
349
+
350
+ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !ValidationResult {
351
+ const source = try readFile(allocator, io, path);
352
+ defer allocator.free(source);
353
+
354
+ const metadata = parseText(allocator, source) catch return .{
355
+ .ok = false,
356
+ .message = zonParseFailureMessage(allocator, source) orelse "app.zon metadata could not be parsed",
357
+ };
358
+ defer metadata.deinit(allocator);
359
+
360
+ if (metadata.description) |description| {
361
+ app_manifest.validateDescription(description) catch return .{
362
+ .ok = false,
363
+ .message = "app.zon description is invalid - it must be one non-empty line of at most 256 bytes with no control characters (it becomes the About panel credits line)",
364
+ };
365
+ }
366
+ if (metadata.theme) |theme_name| {
367
+ if (!isKnownThemePack(theme_name)) return .{
368
+ .ok = false,
369
+ .message = "app.zon theme is invalid - expected one of: house, geist",
370
+ };
371
+ }
372
+ validateIconPaths(metadata.icons) catch return .{ .ok = false, .message = "app.zon icons are invalid" };
373
+ if (try checkIconSources(allocator, io, std.fs.path.dirname(path) orelse ".", metadata.icons)) |icon_message| {
374
+ return .{ .ok = false, .message = icon_message };
375
+ }
376
+ const permissions = parsePermissions(allocator, metadata.permissions) catch return .{ .ok = false, .message = "app.zon permissions are invalid" };
377
+ defer allocator.free(permissions);
378
+ const capabilities = parseCapabilities(allocator, metadata.capabilities) catch return .{ .ok = false, .message = "app.zon capabilities are invalid" };
379
+ defer allocator.free(capabilities);
380
+ const bridge_commands = parseBridgeCommands(allocator, metadata.bridge_commands) catch return .{ .ok = false, .message = "app.zon bridge commands are invalid" };
381
+ defer {
382
+ for (bridge_commands) |command| allocator.free(command.permissions);
383
+ allocator.free(bridge_commands);
384
+ }
385
+ const frontend = if (metadata.frontend) |frontend_value| convertFrontend(frontend_value) else null;
386
+ const security = convertSecurity(metadata.security) catch return .{ .ok = false, .message = "app.zon security policy is invalid" };
387
+ const windows = convertWindows(allocator, metadata.windows) catch return .{ .ok = false, .message = "app.zon windows are invalid" };
388
+ defer allocator.free(windows);
389
+ const shell = parseShell(allocator, metadata.shell) catch return .{ .ok = false, .message = "app.zon shell is invalid" };
390
+ defer deinitParsedShell(allocator, shell);
391
+ const commands = parseCommands(allocator, metadata.commands) catch return .{ .ok = false, .message = "app.zon commands are invalid" };
392
+ defer allocator.free(commands);
393
+ const menus = parseMenus(allocator, metadata.menus) catch return .{ .ok = false, .message = "app.zon menus are invalid" };
394
+ defer deinitParsedMenus(allocator, menus);
395
+ const shortcuts = parseShortcuts(allocator, metadata.shortcuts) catch return .{ .ok = false, .message = "app.zon shortcuts are invalid" };
396
+ defer allocator.free(shortcuts);
397
+ const file_associations = parseFileAssociations(allocator, metadata.file_associations) catch return .{ .ok = false, .message = "app.zon file associations are invalid" };
398
+ defer allocator.free(file_associations);
399
+ const url_schemes = parseUrlSchemes(allocator, metadata.url_schemes) catch return .{ .ok = false, .message = "app.zon URL schemes are invalid" };
400
+ defer allocator.free(url_schemes);
401
+ const manifest_web_engine = parseWebEngine(metadata.web_engine) catch return .{ .ok = false, .message = "app.zon web engine is invalid" };
402
+ const platform_settings = parsePlatformSettings(allocator, metadata.platforms) catch return .{ .ok = false, .message = "app.zon platforms are invalid" };
403
+ defer allocator.free(platform_settings);
404
+
405
+ const manifest: app_manifest.Manifest = .{
406
+ .identity = .{ .id = metadata.id, .name = metadata.name, .display_name = metadata.display_name, .description = metadata.description },
407
+ .version = parseVersion(metadata.version) catch return .{ .ok = false, .message = "app.zon version is invalid" },
408
+ .permissions = permissions,
409
+ .capabilities = capabilities,
410
+ .bridge = .{ .commands = bridge_commands },
411
+ .frontend = frontend,
412
+ .security = security,
413
+ .platforms = platform_settings,
414
+ .windows = windows,
415
+ .shell = shell,
416
+ .commands = commands,
417
+ .menus = menus,
418
+ .shortcuts = shortcuts,
419
+ .file_associations = file_associations,
420
+ .url_schemes = url_schemes,
421
+ .cef = .{ .dir = metadata.cef.dir, .auto_install = metadata.cef.auto_install },
422
+ .package = .{ .web_engine = manifest_web_engine },
423
+ };
424
+ app_manifest.validateManifest(manifest) catch return .{ .ok = false, .message = "manifest fields failed semantic validation" };
425
+ return .{ .ok = true, .message = "app.zon is valid" };
426
+ }
427
+
428
+ /// Re-parse a failed manifest with std.zon diagnostics enabled so the
429
+ /// message names the line and column instead of a bare "could not be
430
+ /// parsed". Returns null when no diagnostic could be produced; the
431
+ /// (allocated) message intentionally lives until process exit.
432
+ fn zonParseFailureMessage(allocator: std.mem.Allocator, source: []const u8) ?[]const u8 {
433
+ var arena = std.heap.ArenaAllocator.init(allocator);
434
+ defer arena.deinit();
435
+ const scratch = arena.allocator();
436
+ const source_z = scratch.dupeZ(u8, source) catch return null;
437
+ var diag: std.zon.parse.Diagnostics = .{};
438
+ defer diag.deinit(scratch);
439
+ @setEvalBranchQuota(2000);
440
+ if (std.zon.parse.fromSliceAlloc(RawManifest, scratch, source_z, &diag, .{})) |_| {
441
+ return null;
442
+ } else |_| {
443
+ const rendered = std.fmt.allocPrint(scratch, "{f}", .{&diag}) catch return null;
444
+ const first_line_end = std.mem.indexOfScalar(u8, rendered, '\n') orelse rendered.len;
445
+ const first_line = std.mem.trim(u8, rendered[0..first_line_end], " \n");
446
+ if (first_line.len == 0) return null;
447
+ return std.fmt.allocPrint(allocator, "app.zon could not be parsed - {s}", .{first_line}) catch null;
448
+ }
449
+ }
450
+
451
+ pub fn readMetadata(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !Metadata {
452
+ const source = try readFile(allocator, io, path);
453
+ defer allocator.free(source);
454
+ return parseText(allocator, source);
455
+ }
456
+
457
+ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
458
+ var arena = std.heap.ArenaAllocator.init(allocator);
459
+ defer arena.deinit();
460
+ const scratch = arena.allocator();
461
+ const source_z = try scratch.dupeZ(u8, source);
462
+ @setEvalBranchQuota(2000);
463
+ const raw = try std.zon.parse.fromSliceAlloc(RawManifest, scratch, source_z, null, .{});
464
+ return .{
465
+ .id = try allocator.dupe(u8, raw.id),
466
+ .name = try allocator.dupe(u8, raw.name),
467
+ .display_name = if (raw.display_name) |value| try allocator.dupe(u8, value) else null,
468
+ .description = if (raw.description) |value| try allocator.dupe(u8, value) else null,
469
+ .theme = if (raw.theme) |value| try allocator.dupe(u8, value) else null,
470
+ .version = try allocator.dupe(u8, raw.version),
471
+ .icons = try duplicateStringList(allocator, raw.icons),
472
+ .platforms = try duplicateStringList(allocator, raw.platforms),
473
+ .permissions = try duplicateStringList(allocator, raw.permissions),
474
+ .capabilities = try duplicateStringList(allocator, raw.capabilities),
475
+ .bridge_commands = try convertRawBridgeCommands(allocator, raw.bridge.commands),
476
+ .web_engine = try allocator.dupe(u8, raw.web_engine),
477
+ .cef = .{
478
+ .dir = try allocator.dupe(u8, raw.cef.dir),
479
+ .auto_install = raw.cef.auto_install,
480
+ },
481
+ .frontend = try convertRawFrontend(allocator, raw.frontend),
482
+ .security = try convertRawSecurity(allocator, raw.security),
483
+ .windows = try convertRawWindows(allocator, raw.windows),
484
+ .shell = try convertRawShell(allocator, raw.shell),
485
+ .commands = try convertRawCommands(allocator, raw.commands),
486
+ .menus = try convertRawMenus(allocator, raw.menus),
487
+ .shortcuts = try convertRawShortcuts(allocator, raw.shortcuts),
488
+ .file_associations = try convertRawFileAssociations(allocator, raw.file_associations),
489
+ .url_schemes = try convertRawUrlSchemes(allocator, raw.url_schemes),
490
+ };
491
+ }
492
+
493
+ fn duplicateOptionalString(allocator: std.mem.Allocator, value: ?[]const u8) !?[]const u8 {
494
+ return if (value) |payload| try allocator.dupe(u8, payload) else null;
495
+ }
496
+
497
+ fn duplicateStringList(allocator: std.mem.Allocator, values: []const []const u8) ![]const []const u8 {
498
+ if (values.len == 0) return &.{};
499
+ const out = try allocator.alloc([]const u8, values.len);
500
+ for (values, 0..) |value, index| {
501
+ out[index] = try allocator.dupe(u8, value);
502
+ }
503
+ return out;
504
+ }
505
+
506
+ fn convertRawBridgeCommands(allocator: std.mem.Allocator, commands: []const RawBridgeCommand) ![]const BridgeCommandMetadata {
507
+ if (commands.len == 0) return &.{};
508
+ const converted = try allocator.alloc(BridgeCommandMetadata, commands.len);
509
+ for (commands, 0..) |command, index| {
510
+ converted[index] = .{
511
+ .name = try allocator.dupe(u8, command.name),
512
+ .permissions = try duplicateStringList(allocator, command.permissions),
513
+ .origins = try duplicateStringList(allocator, command.origins),
514
+ };
515
+ }
516
+ return converted;
517
+ }
518
+
519
+ fn convertRawFrontend(allocator: std.mem.Allocator, frontend: ?RawFrontend) !?FrontendMetadata {
520
+ const value = frontend orelse return null;
521
+ return .{
522
+ .dist = try allocator.dupe(u8, value.dist),
523
+ .entry = try allocator.dupe(u8, value.entry),
524
+ .spa_fallback = value.spa_fallback,
525
+ .dev = if (value.dev) |dev| .{
526
+ .url = try allocator.dupe(u8, dev.url),
527
+ .command = try duplicateStringList(allocator, dev.command),
528
+ .ready_path = try allocator.dupe(u8, dev.ready_path),
529
+ .timeout_ms = dev.timeout_ms,
530
+ } else null,
531
+ };
532
+ }
533
+
534
+ fn convertRawSecurity(allocator: std.mem.Allocator, security: RawSecurity) !SecurityMetadata {
535
+ const external_action = if (security.navigation.external_links.allowed_urls.len == 0 and
536
+ std.mem.eql(u8, security.navigation.external_links.action, "deny"))
537
+ "deny"
538
+ else
539
+ try allocator.dupe(u8, security.navigation.external_links.action);
540
+ return .{
541
+ .navigation = .{
542
+ .allowed_origins = try duplicateStringList(allocator, security.navigation.allowed_origins),
543
+ .external_links = .{
544
+ .action = external_action,
545
+ .allowed_urls = try duplicateStringList(allocator, security.navigation.external_links.allowed_urls),
546
+ },
547
+ },
548
+ };
549
+ }
550
+
551
+ fn convertRawWindows(allocator: std.mem.Allocator, windows: []const RawWindow) ![]const WindowMetadata {
552
+ if (windows.len == 0) return &.{};
553
+ const converted = try allocator.alloc(WindowMetadata, windows.len);
554
+ for (windows, 0..) |window, index| {
555
+ converted[index] = .{
556
+ .label = try allocator.dupe(u8, window.label),
557
+ .title = if (window.title) |title| try allocator.dupe(u8, title) else null,
558
+ .width = window.width,
559
+ .height = window.height,
560
+ .x = window.x,
561
+ .y = window.y,
562
+ .resizable = window.resizable,
563
+ .restore_state = window.restore_state,
564
+ .titlebar = try allocator.dupe(u8, window.titlebar),
565
+ .min_width = window.min_width,
566
+ .min_height = window.min_height,
567
+ };
568
+ }
569
+ return converted;
570
+ }
571
+
572
+ fn convertRawShell(allocator: std.mem.Allocator, shell: RawShell) !ShellMetadata {
573
+ return .{
574
+ .windows = try convertRawShellWindows(allocator, shell.windows),
575
+ .chrome = try convertRawShellChrome(allocator, shell.chrome),
576
+ };
577
+ }
578
+
579
+ fn convertRawShellChrome(allocator: std.mem.Allocator, chrome: raw_manifest.RawShellChrome) !ShellChromeMetadata {
580
+ var converted: ShellChromeMetadata = .{};
581
+ if (chrome.tabs.len > 0) {
582
+ const tabs = try allocator.alloc(ShellTabMetadata, chrome.tabs.len);
583
+ for (chrome.tabs, 0..) |tab, index| {
584
+ tabs[index] = .{
585
+ .id = try allocator.dupe(u8, tab.id),
586
+ .label = try allocator.dupe(u8, tab.label),
587
+ .icon = try allocator.dupe(u8, tab.icon),
588
+ };
589
+ }
590
+ converted.tabs = tabs;
591
+ }
592
+ if (chrome.primary_action) |action| {
593
+ converted.primary_action = .{
594
+ .id = try allocator.dupe(u8, action.id),
595
+ .label = try allocator.dupe(u8, action.label),
596
+ .icon = try allocator.dupe(u8, action.icon),
597
+ };
598
+ }
599
+ return converted;
600
+ }
601
+
602
+ fn convertRawShellWindows(allocator: std.mem.Allocator, windows: []const RawShellWindow) ![]const ShellWindowMetadata {
603
+ if (windows.len == 0) return &.{};
604
+ const converted = try allocator.alloc(ShellWindowMetadata, windows.len);
605
+ for (windows, 0..) |window, index| {
606
+ converted[index] = .{
607
+ .label = try allocator.dupe(u8, window.label),
608
+ .title = try duplicateOptionalString(allocator, window.title),
609
+ .width = window.width,
610
+ .height = window.height,
611
+ .x = window.x,
612
+ .y = window.y,
613
+ .resizable = window.resizable,
614
+ .restore_state = window.restore_state,
615
+ .restore_policy = try allocator.dupe(u8, window.restore_policy),
616
+ .titlebar = try allocator.dupe(u8, window.titlebar),
617
+ .min_width = window.min_width,
618
+ .min_height = window.min_height,
619
+ .views = try convertRawShellViews(allocator, window.views),
620
+ };
621
+ }
622
+ return converted;
623
+ }
624
+
625
+ fn convertRawShellViews(allocator: std.mem.Allocator, views: []const RawShellView) ![]const ShellViewMetadata {
626
+ if (views.len == 0) return &.{};
627
+ const converted = try allocator.alloc(ShellViewMetadata, views.len);
628
+ for (views, 0..) |view, index| {
629
+ converted[index] = .{
630
+ .label = try allocator.dupe(u8, view.label),
631
+ .kind = try allocator.dupe(u8, view.kind),
632
+ .parent = try duplicateOptionalString(allocator, view.parent),
633
+ .edge = try duplicateOptionalString(allocator, view.edge),
634
+ .axis = try duplicateOptionalString(allocator, view.axis),
635
+ .x = view.x,
636
+ .y = view.y,
637
+ .width = view.width,
638
+ .height = view.height,
639
+ .min_width = view.min_width,
640
+ .min_height = view.min_height,
641
+ .max_width = view.max_width,
642
+ .max_height = view.max_height,
643
+ .fill = view.fill,
644
+ .layer = view.layer,
645
+ .visible = view.visible,
646
+ .enabled = view.enabled,
647
+ .role = try duplicateOptionalString(allocator, view.role),
648
+ .accessibility_label = try duplicateOptionalString(allocator, view.accessibility_label),
649
+ .url = try duplicateOptionalString(allocator, view.url),
650
+ .text = try duplicateOptionalString(allocator, view.text),
651
+ .command = try duplicateOptionalString(allocator, view.command),
652
+ .gpu_backend = try duplicateOptionalString(allocator, view.gpu_backend),
653
+ .gpu_pixel_format = try duplicateOptionalString(allocator, view.gpu_pixel_format),
654
+ .gpu_present_mode = try duplicateOptionalString(allocator, view.gpu_present_mode),
655
+ .gpu_alpha_mode = try duplicateOptionalString(allocator, view.gpu_alpha_mode),
656
+ .gpu_color_space = try duplicateOptionalString(allocator, view.gpu_color_space),
657
+ .gpu_vsync = view.gpu_vsync,
658
+ };
659
+ }
660
+ return converted;
661
+ }
662
+
663
+ fn convertRawShortcuts(allocator: std.mem.Allocator, shortcuts: []const RawShortcut) ![]const ShortcutMetadata {
664
+ if (shortcuts.len == 0) return &.{};
665
+ const converted = try allocator.alloc(ShortcutMetadata, shortcuts.len);
666
+ for (shortcuts, 0..) |shortcut, index| {
667
+ converted[index] = .{
668
+ .id = try allocator.dupe(u8, shortcut.id),
669
+ .key = try allocator.dupe(u8, shortcut.key),
670
+ .modifiers = try duplicateStringList(allocator, shortcut.modifiers),
671
+ };
672
+ }
673
+ return converted;
674
+ }
675
+
676
+ fn convertRawCommands(allocator: std.mem.Allocator, commands: []const RawCommand) ![]const CommandMetadata {
677
+ if (commands.len == 0) return &.{};
678
+ const converted = try allocator.alloc(CommandMetadata, commands.len);
679
+ for (commands, 0..) |command, index| {
680
+ converted[index] = .{
681
+ .id = try allocator.dupe(u8, command.id),
682
+ .title = try allocator.dupe(u8, command.title),
683
+ .enabled = command.enabled,
684
+ .checked = command.checked,
685
+ };
686
+ }
687
+ return converted;
688
+ }
689
+
690
+ fn convertRawMenus(allocator: std.mem.Allocator, menus: []const RawMenu) ![]const MenuMetadata {
691
+ if (menus.len == 0) return &.{};
692
+ const converted = try allocator.alloc(MenuMetadata, menus.len);
693
+ for (menus, 0..) |menu, index| {
694
+ converted[index] = .{
695
+ .title = try allocator.dupe(u8, menu.title),
696
+ .items = try convertRawMenuItems(allocator, menu.items),
697
+ };
698
+ }
699
+ return converted;
700
+ }
701
+
702
+ fn convertRawMenuItems(allocator: std.mem.Allocator, items: []const RawMenuItem) ![]const MenuItemMetadata {
703
+ if (items.len == 0) return &.{};
704
+ const converted = try allocator.alloc(MenuItemMetadata, items.len);
705
+ for (items, 0..) |item, index| {
706
+ converted[index] = .{
707
+ .label = try allocator.dupe(u8, item.label),
708
+ .command = try allocator.dupe(u8, item.command),
709
+ .key = try allocator.dupe(u8, item.key),
710
+ .modifiers = try duplicateStringList(allocator, item.modifiers),
711
+ .separator = item.separator,
712
+ .enabled = item.enabled,
713
+ .checked = item.checked,
714
+ };
715
+ }
716
+ return converted;
717
+ }
718
+
719
+ fn convertRawFileAssociations(allocator: std.mem.Allocator, associations: []const RawFileAssociation) ![]const FileAssociationMetadata {
720
+ if (associations.len == 0) return &.{};
721
+ const converted = try allocator.alloc(FileAssociationMetadata, associations.len);
722
+ for (associations, 0..) |association, index| {
723
+ converted[index] = .{
724
+ .name = try allocator.dupe(u8, association.name),
725
+ .role = try allocator.dupe(u8, association.role),
726
+ .extensions = try duplicateStringList(allocator, association.extensions),
727
+ .mime_types = try duplicateStringList(allocator, association.mime_types),
728
+ .icon = try duplicateOptionalString(allocator, association.icon),
729
+ };
730
+ }
731
+ return converted;
732
+ }
733
+
734
+ fn convertRawUrlSchemes(allocator: std.mem.Allocator, schemes: []const RawUrlScheme) ![]const UrlSchemeMetadata {
735
+ if (schemes.len == 0) return &.{};
736
+ const converted = try allocator.alloc(UrlSchemeMetadata, schemes.len);
737
+ for (schemes, 0..) |scheme, index| {
738
+ converted[index] = .{
739
+ .scheme = try allocator.dupe(u8, scheme.scheme),
740
+ .role = try allocator.dupe(u8, scheme.role),
741
+ };
742
+ }
743
+ return converted;
744
+ }
745
+
746
+ pub fn parseVersion(value: []const u8) !app_manifest.Version {
747
+ var parts = std.mem.splitScalar(u8, value, '.');
748
+ const major = try parseVersionNumber(parts.next() orelse return error.InvalidVersion);
749
+ const minor = try parseVersionNumber(parts.next() orelse return error.InvalidVersion);
750
+ const patch_text = parts.next() orelse return error.InvalidVersion;
751
+ if (parts.next() != null) return error.InvalidVersion;
752
+ return .{
753
+ .major = major,
754
+ .minor = minor,
755
+ .patch = try parseVersionNumber(patch_text),
756
+ };
757
+ }
758
+
759
+ pub fn printDiagnostic(result: ValidationResult) void {
760
+ const severity: diagnostics.Severity = if (result.ok) .info else .@"error";
761
+ var buffer: [1024]u8 = undefined;
762
+ var writer = std.Io.Writer.fixed(&buffer);
763
+ diagnostics.formatShort(.{ .severity = severity, .code = diagnostics.code("manifest", if (result.ok) "valid" else "invalid"), .message = result.message }, &writer) catch return;
764
+ std.debug.print("{s}\n", .{writer.buffered()});
765
+ }
766
+
767
+ fn readFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8) ![]u8 {
768
+ var file = try std.Io.Dir.cwd().openFile(io, path, .{});
769
+ defer file.close(io);
770
+ var read_buffer: [4096]u8 = undefined;
771
+ var reader = file.reader(io, &read_buffer);
772
+ return reader.interface.allocRemaining(allocator, .limited(1024 * 1024));
773
+ }
774
+
775
+ fn convertFrontend(frontend: FrontendMetadata) app_manifest.FrontendConfig {
776
+ return .{
777
+ .dist = frontend.dist,
778
+ .entry = frontend.entry,
779
+ .spa_fallback = frontend.spa_fallback,
780
+ .dev = if (frontend.dev) |dev| .{
781
+ .url = dev.url,
782
+ .command = dev.command,
783
+ .ready_path = dev.ready_path,
784
+ .timeout_ms = dev.timeout_ms,
785
+ } else null,
786
+ };
787
+ }
788
+
789
+ fn convertSecurity(security: SecurityMetadata) !app_manifest.SecurityConfig {
790
+ return .{
791
+ .navigation = .{
792
+ .allowed_origins = if (security.navigation.allowed_origins.len > 0) security.navigation.allowed_origins else &.{ "zero://app", "zero://inline" },
793
+ .external_links = .{
794
+ .action = parseExternalLinkAction(security.navigation.external_links.action) catch return error.InvalidSecurity,
795
+ .allowed_urls = security.navigation.external_links.allowed_urls,
796
+ },
797
+ },
798
+ };
799
+ }
800
+
801
+ fn convertWindows(allocator: std.mem.Allocator, windows: []const WindowMetadata) ![]const app_manifest.Window {
802
+ if (windows.len == 0) return &.{};
803
+ const converted = try allocator.alloc(app_manifest.Window, windows.len);
804
+ errdefer allocator.free(converted);
805
+ for (windows, 0..) |window, index| {
806
+ converted[index] = .{
807
+ .label = window.label,
808
+ .title = window.title,
809
+ .width = window.width,
810
+ .height = window.height,
811
+ .x = window.x,
812
+ .y = window.y,
813
+ .resizable = window.resizable,
814
+ .restore_state = window.restore_state,
815
+ .titlebar = try parseTitlebarStyle(window.titlebar),
816
+ .min_width = try parseWindowMinSize(window.min_width),
817
+ .min_height = try parseWindowMinSize(window.min_height),
818
+ };
819
+ }
820
+ return converted;
821
+ }
822
+
823
+ fn parseShell(allocator: std.mem.Allocator, shell: ShellMetadata) !app_manifest.ShellConfig {
824
+ const chrome = try parseShellChrome(allocator, shell.chrome);
825
+ errdefer if (chrome.tabs.len > 0) allocator.free(chrome.tabs);
826
+ if (shell.windows.len == 0) return .{ .chrome = chrome };
827
+ const windows = try allocator.alloc(app_manifest.ShellWindow, shell.windows.len);
828
+ errdefer allocator.free(windows);
829
+ var initialized: usize = 0;
830
+ errdefer {
831
+ for (windows[0..initialized]) |window| {
832
+ if (window.views.len > 0) allocator.free(window.views);
833
+ }
834
+ }
835
+ for (shell.windows, 0..) |window, index| {
836
+ // Parse the fallible scalar fields BEFORE allocating the views
837
+ // slice, so a bad policy/titlebar string cannot leak it.
838
+ const restore_policy = try parseRestorePolicy(window.restore_policy);
839
+ const titlebar = try parseTitlebarStyle(window.titlebar);
840
+ const min_width = try parseWindowMinSize(window.min_width);
841
+ const min_height = try parseWindowMinSize(window.min_height);
842
+ const views = try parseShellViews(allocator, window.views);
843
+ windows[index] = .{
844
+ .label = window.label,
845
+ .title = window.title,
846
+ .width = window.width,
847
+ .height = window.height,
848
+ .x = window.x,
849
+ .y = window.y,
850
+ .resizable = window.resizable,
851
+ .restore_state = window.restore_state,
852
+ .restore_policy = restore_policy,
853
+ .titlebar = titlebar,
854
+ .min_width = min_width,
855
+ .min_height = min_height,
856
+ .views = views,
857
+ };
858
+ initialized += 1;
859
+ }
860
+ return .{ .windows = windows, .chrome = chrome };
861
+ }
862
+
863
+ /// Declared platform chrome from app.zon metadata: the strings pass
864
+ /// through (Metadata owns them, exactly like window/view labels); only
865
+ /// the tabs slice is parse-owned. Structural rules live in
866
+ /// `app_manifest.validateShellChrome`, which `parseShell`'s caller runs
867
+ /// over the whole shell.
868
+ fn parseShellChrome(allocator: std.mem.Allocator, chrome: ShellChromeMetadata) !app_manifest.ShellChrome {
869
+ var parsed: app_manifest.ShellChrome = .{};
870
+ if (chrome.tabs.len > 0) {
871
+ const tabs = try allocator.alloc(app_manifest.ShellTab, chrome.tabs.len);
872
+ for (chrome.tabs, 0..) |tab, index| {
873
+ tabs[index] = .{ .id = tab.id, .label = tab.label, .icon = tab.icon };
874
+ }
875
+ parsed.tabs = tabs;
876
+ }
877
+ if (chrome.primary_action) |action| {
878
+ parsed.primary_action = .{ .id = action.id, .label = action.label, .icon = action.icon };
879
+ }
880
+ return parsed;
881
+ }
882
+
883
+ fn parseShellViews(allocator: std.mem.Allocator, values: []const ShellViewMetadata) ![]const app_manifest.ShellView {
884
+ if (values.len == 0) return &.{};
885
+ const views = try allocator.alloc(app_manifest.ShellView, values.len);
886
+ errdefer allocator.free(views);
887
+ for (values, 0..) |view, index| {
888
+ views[index] = .{
889
+ .label = view.label,
890
+ .kind = try parseViewKind(view.kind),
891
+ .parent = view.parent,
892
+ .edge = if (view.edge) |edge| try parseShellEdge(edge) else null,
893
+ .axis = if (view.axis) |axis| try parseShellAxis(axis) else null,
894
+ .x = view.x,
895
+ .y = view.y,
896
+ .width = view.width,
897
+ .height = view.height,
898
+ .min_width = view.min_width,
899
+ .min_height = view.min_height,
900
+ .max_width = view.max_width,
901
+ .max_height = view.max_height,
902
+ .fill = view.fill,
903
+ .layer = view.layer,
904
+ .visible = view.visible,
905
+ .enabled = view.enabled,
906
+ .role = view.role,
907
+ .accessibility_label = view.accessibility_label,
908
+ .url = view.url,
909
+ .text = view.text,
910
+ .command = view.command,
911
+ .gpu_backend = if (view.gpu_backend) |value| try parseGpuSurfaceBackend(value) else null,
912
+ .gpu_pixel_format = if (view.gpu_pixel_format) |value| try parseGpuSurfacePixelFormat(value) else null,
913
+ .gpu_present_mode = if (view.gpu_present_mode) |value| try parseGpuSurfacePresentMode(value) else null,
914
+ .gpu_alpha_mode = if (view.gpu_alpha_mode) |value| try parseGpuSurfaceAlphaMode(value) else null,
915
+ .gpu_color_space = if (view.gpu_color_space) |value| try parseGpuSurfaceColorSpace(value) else null,
916
+ .gpu_vsync = view.gpu_vsync,
917
+ };
918
+ }
919
+ return views;
920
+ }
921
+
922
+ fn deinitParsedShell(allocator: std.mem.Allocator, shell: app_manifest.ShellConfig) void {
923
+ for (shell.windows) |window| {
924
+ if (window.views.len > 0) allocator.free(window.views);
925
+ }
926
+ if (shell.windows.len > 0) allocator.free(shell.windows);
927
+ if (shell.chrome.tabs.len > 0) allocator.free(shell.chrome.tabs);
928
+ }
929
+
930
+ fn deinitParsedMenus(allocator: std.mem.Allocator, menus: []const app_manifest.Menu) void {
931
+ for (menus) |menu| {
932
+ if (menu.items.len > 0) allocator.free(menu.items);
933
+ }
934
+ if (menus.len > 0) allocator.free(menus);
935
+ }
936
+
937
+ /// The built-in theme pack names, kept in step with the canvas
938
+ /// `ThemePack` enum (tooling deliberately does not link the canvas
939
+ /// module; the runner re-validates at comptime, so a drift here shows
940
+ /// up as a build error in the app, never a silently shipped typo).
941
+ fn isKnownThemePack(name: []const u8) bool {
942
+ const known = [_][]const u8{ "house", "geist" };
943
+ for (known) |candidate| {
944
+ if (std.mem.eql(u8, name, candidate)) return true;
945
+ }
946
+ return false;
947
+ }
948
+
949
+ fn validateIconPaths(icons: []const []const u8) !void {
950
+ for (icons, 0..) |icon, index| {
951
+ try validateRelativePath(icon);
952
+ for (icons[0..index]) |previous| {
953
+ if (std.mem.eql(u8, previous, icon)) return error.DuplicateIcon;
954
+ }
955
+ }
956
+ }
957
+
958
+ /// The app-icon teaching checks `native validate` and `native check`
959
+ /// share with packaging (same messages, no packaging): every `.icons`
960
+ /// entry must be a generatable source (.png/.svg) or a prebuilt
961
+ /// container (.icns/.ico), and a source file that exists must decode to
962
+ /// a square image. A missing file is packaging's problem (it warns and
963
+ /// falls back); an undersized source prints the upscaling warning
964
+ /// without failing validation. Returns the error message or null when
965
+ /// the icons pass. The returned message is allocated and intentionally
966
+ /// lives until process exit (same policy as `zonParseFailureMessage`).
967
+ fn checkIconSources(allocator: std.mem.Allocator, io: std.Io, manifest_dir: []const u8, icons: []const []const u8) !?[]const u8 {
968
+ for (icons) |icon_path| {
969
+ const is_prebuilt = app_icon_tool.pathHasExtension(icon_path, ".icns") or
970
+ app_icon_tool.pathHasExtension(icon_path, ".ico");
971
+ const kind = app_icon_tool.sourceKindForPath(icon_path) orelse {
972
+ if (is_prebuilt) continue;
973
+ var buffer: [512]u8 = undefined;
974
+ return try allocator.dupe(u8, app_icon_tool.formatBadExtensionMessage(&buffer, icon_path));
975
+ };
976
+
977
+ const resolved = try std.fs.path.join(allocator, &.{ manifest_dir, icon_path });
978
+ defer allocator.free(resolved);
979
+ const bytes = readFile(allocator, io, resolved) catch continue;
980
+ defer allocator.free(bytes);
981
+ switch (try app_icon_tool.loadSource(allocator, bytes, kind)) {
982
+ .ok => |loaded| {
983
+ var source = loaded;
984
+ defer source.deinit(allocator);
985
+ if (kind == .png and source.width < app_icon_tool.min_recommended_source_size) {
986
+ var buffer: [512]u8 = undefined;
987
+ std.debug.print("{s}\n", .{app_icon_tool.formatSmallSourceMessage(&buffer, icon_path, source.width, source.height)});
988
+ }
989
+ },
990
+ .issue => |issue| {
991
+ var buffer: [512]u8 = undefined;
992
+ const message = switch (issue) {
993
+ .not_square => |dims| app_icon_tool.formatNotSquareMessage(&buffer, icon_path, dims.width, dims.height),
994
+ .unsupported => app_icon_tool.formatUnsupportedMessage(&buffer, icon_path),
995
+ };
996
+ return try allocator.dupe(u8, message);
997
+ },
998
+ }
999
+ }
1000
+ return null;
1001
+ }
1002
+
1003
+ fn parseCapabilities(allocator: std.mem.Allocator, values: []const []const u8) ![]const app_manifest.Capability {
1004
+ var capabilities: std.ArrayList(app_manifest.Capability) = .empty;
1005
+ errdefer capabilities.deinit(allocator);
1006
+ for (values) |value| {
1007
+ try capabilities.append(allocator, parseCapability(value) catch return error.InvalidCapability);
1008
+ }
1009
+ return capabilities.toOwnedSlice(allocator);
1010
+ }
1011
+
1012
+ fn parsePermissions(allocator: std.mem.Allocator, values: []const []const u8) ![]const app_manifest.Permission {
1013
+ var permissions: std.ArrayList(app_manifest.Permission) = .empty;
1014
+ errdefer permissions.deinit(allocator);
1015
+ for (values) |value| {
1016
+ try permissions.append(allocator, parsePermission(value));
1017
+ }
1018
+ return permissions.toOwnedSlice(allocator);
1019
+ }
1020
+
1021
+ fn parsePermission(value: []const u8) app_manifest.Permission {
1022
+ if (std.mem.eql(u8, value, "network")) return .network;
1023
+ if (std.mem.eql(u8, value, "filesystem")) return .filesystem;
1024
+ if (std.mem.eql(u8, value, "camera")) return .camera;
1025
+ if (std.mem.eql(u8, value, "microphone")) return .microphone;
1026
+ if (std.mem.eql(u8, value, "location")) return .location;
1027
+ if (std.mem.eql(u8, value, "notifications")) return .notifications;
1028
+ if (std.mem.eql(u8, value, "clipboard")) return .clipboard;
1029
+ if (std.mem.eql(u8, value, "window")) return .window;
1030
+ if (std.mem.eql(u8, value, "command")) return .command;
1031
+ if (std.mem.eql(u8, value, "view")) return .view;
1032
+ if (std.mem.eql(u8, value, "dialog")) return .dialog;
1033
+ if (std.mem.eql(u8, value, "credentials")) return .credentials;
1034
+ return .{ .custom = value };
1035
+ }
1036
+
1037
+ fn parseCapability(value: []const u8) !app_manifest.Capability {
1038
+ if (std.mem.eql(u8, value, "native_module")) return .native_module;
1039
+ if (std.mem.eql(u8, value, "webview")) return .webview;
1040
+ if (std.mem.eql(u8, value, "js_bridge")) return .js_bridge;
1041
+ if (std.mem.eql(u8, value, "native_views")) return .native_views;
1042
+ if (std.mem.eql(u8, value, "gpu_surfaces")) return .gpu_surfaces;
1043
+ if (std.mem.eql(u8, value, "menus")) return .menus;
1044
+ if (std.mem.eql(u8, value, "shortcuts")) return .shortcuts;
1045
+ if (std.mem.eql(u8, value, "tray")) return .tray;
1046
+ if (std.mem.eql(u8, value, "filesystem")) return .filesystem;
1047
+ if (std.mem.eql(u8, value, "network")) return .network;
1048
+ if (std.mem.eql(u8, value, "notifications")) return .notifications;
1049
+ if (std.mem.eql(u8, value, "dialog")) return .dialog;
1050
+ if (std.mem.eql(u8, value, "clipboard")) return .clipboard;
1051
+ if (std.mem.eql(u8, value, "credentials")) return .credentials;
1052
+ if (std.mem.eql(u8, value, "open_url")) return .open_url;
1053
+ if (std.mem.eql(u8, value, "reveal_path")) return .reveal_path;
1054
+ if (std.mem.eql(u8, value, "recent_documents")) return .recent_documents;
1055
+ if (std.mem.eql(u8, value, "file_drops")) return .file_drops;
1056
+ if (std.mem.eql(u8, value, "app_activation_events")) return .app_activation_events;
1057
+ if (std.mem.eql(u8, value, "file_associations")) return .file_associations;
1058
+ if (std.mem.eql(u8, value, "url_schemes")) return .url_schemes;
1059
+ return error.InvalidCapability;
1060
+ }
1061
+
1062
+ fn parseBridgeCommands(allocator: std.mem.Allocator, values: []const BridgeCommandMetadata) ![]const app_manifest.BridgeCommand {
1063
+ var commands: std.ArrayList(app_manifest.BridgeCommand) = .empty;
1064
+ errdefer commands.deinit(allocator);
1065
+ for (values) |value| {
1066
+ try commands.append(allocator, .{
1067
+ .name = value.name,
1068
+ .permissions = try parsePermissions(allocator, value.permissions),
1069
+ .origins = value.origins,
1070
+ });
1071
+ }
1072
+ return commands.toOwnedSlice(allocator);
1073
+ }
1074
+
1075
+ fn parseShortcuts(allocator: std.mem.Allocator, values: []const ShortcutMetadata) ![]const app_manifest.Shortcut {
1076
+ if (values.len == 0) return &.{};
1077
+ var shortcuts: std.ArrayList(app_manifest.Shortcut) = .empty;
1078
+ errdefer shortcuts.deinit(allocator);
1079
+ for (values) |value| {
1080
+ try shortcuts.append(allocator, .{
1081
+ .id = value.id,
1082
+ .key = value.key,
1083
+ .modifiers = try parseShortcutModifiers(value.modifiers),
1084
+ });
1085
+ }
1086
+ return shortcuts.toOwnedSlice(allocator);
1087
+ }
1088
+
1089
+ fn parseCommands(allocator: std.mem.Allocator, values: []const CommandMetadata) ![]const app_manifest.Command {
1090
+ if (values.len == 0) return &.{};
1091
+ var commands: std.ArrayList(app_manifest.Command) = .empty;
1092
+ errdefer commands.deinit(allocator);
1093
+ for (values) |value| {
1094
+ try commands.append(allocator, .{
1095
+ .id = value.id,
1096
+ .title = value.title,
1097
+ .enabled = value.enabled,
1098
+ .checked = value.checked,
1099
+ });
1100
+ }
1101
+ return commands.toOwnedSlice(allocator);
1102
+ }
1103
+
1104
+ fn parseMenus(allocator: std.mem.Allocator, values: []const MenuMetadata) ![]const app_manifest.Menu {
1105
+ if (values.len == 0) return &.{};
1106
+ var menus: std.ArrayList(app_manifest.Menu) = .empty;
1107
+ errdefer {
1108
+ for (menus.items) |menu| {
1109
+ if (menu.items.len > 0) allocator.free(menu.items);
1110
+ }
1111
+ menus.deinit(allocator);
1112
+ }
1113
+ for (values) |value| {
1114
+ try menus.append(allocator, .{
1115
+ .title = value.title,
1116
+ .items = try parseMenuItems(allocator, value.items),
1117
+ });
1118
+ }
1119
+ return menus.toOwnedSlice(allocator);
1120
+ }
1121
+
1122
+ fn parseMenuItems(allocator: std.mem.Allocator, values: []const MenuItemMetadata) ![]const app_manifest.MenuItem {
1123
+ if (values.len == 0) return &.{};
1124
+ var items: std.ArrayList(app_manifest.MenuItem) = .empty;
1125
+ errdefer items.deinit(allocator);
1126
+ for (values) |value| {
1127
+ try items.append(allocator, .{
1128
+ .label = value.label,
1129
+ .command = value.command,
1130
+ .key = value.key,
1131
+ .modifiers = try parseShortcutModifiers(value.modifiers),
1132
+ .separator = value.separator,
1133
+ .enabled = value.enabled,
1134
+ .checked = value.checked,
1135
+ });
1136
+ }
1137
+ return items.toOwnedSlice(allocator);
1138
+ }
1139
+
1140
+ fn parseFileAssociations(allocator: std.mem.Allocator, values: []const FileAssociationMetadata) ![]const app_manifest.FileAssociation {
1141
+ if (values.len == 0) return &.{};
1142
+ var associations: std.ArrayList(app_manifest.FileAssociation) = .empty;
1143
+ errdefer associations.deinit(allocator);
1144
+ for (values) |value| {
1145
+ try associations.append(allocator, .{
1146
+ .name = value.name,
1147
+ .role = try parseAssociationRole(value.role),
1148
+ .extensions = value.extensions,
1149
+ .mime_types = value.mime_types,
1150
+ .icon = value.icon,
1151
+ });
1152
+ }
1153
+ return associations.toOwnedSlice(allocator);
1154
+ }
1155
+
1156
+ fn parseUrlSchemes(allocator: std.mem.Allocator, values: []const UrlSchemeMetadata) ![]const app_manifest.UrlScheme {
1157
+ if (values.len == 0) return &.{};
1158
+ var schemes: std.ArrayList(app_manifest.UrlScheme) = .empty;
1159
+ errdefer schemes.deinit(allocator);
1160
+ for (values) |value| {
1161
+ try schemes.append(allocator, .{
1162
+ .scheme = value.scheme,
1163
+ .role = try parseAssociationRole(value.role),
1164
+ });
1165
+ }
1166
+ return schemes.toOwnedSlice(allocator);
1167
+ }
1168
+
1169
+ fn parseAssociationRole(value: []const u8) !app_manifest.AssociationRole {
1170
+ if (std.mem.eql(u8, value, "viewer")) return .viewer;
1171
+ if (std.mem.eql(u8, value, "editor")) return .editor;
1172
+ if (std.mem.eql(u8, value, "shell")) return .shell;
1173
+ if (std.mem.eql(u8, value, "none")) return .none;
1174
+ return error.InvalidAssociationRole;
1175
+ }
1176
+
1177
+ fn parseShortcutModifiers(values: []const []const u8) !app_manifest.ShortcutModifiers {
1178
+ var modifiers: app_manifest.ShortcutModifiers = .{};
1179
+ for (values) |value| {
1180
+ if (std.mem.eql(u8, value, "primary")) {
1181
+ modifiers.primary = true;
1182
+ } else if (std.mem.eql(u8, value, "command")) {
1183
+ modifiers.command = true;
1184
+ } else if (std.mem.eql(u8, value, "control")) {
1185
+ modifiers.control = true;
1186
+ } else if (std.mem.eql(u8, value, "option") or std.mem.eql(u8, value, "alt")) {
1187
+ modifiers.option = true;
1188
+ } else if (std.mem.eql(u8, value, "shift")) {
1189
+ modifiers.shift = true;
1190
+ } else {
1191
+ return error.InvalidShortcut;
1192
+ }
1193
+ }
1194
+ return modifiers;
1195
+ }
1196
+
1197
+ fn parsePlatformSettings(allocator: std.mem.Allocator, values: []const []const u8) ![]const app_manifest.PlatformSettings {
1198
+ if (values.len == 0) return &.{};
1199
+ var platforms: std.ArrayList(app_manifest.PlatformSettings) = .empty;
1200
+ errdefer platforms.deinit(allocator);
1201
+ for (values) |value| {
1202
+ try platforms.append(allocator, .{ .platform = parsePlatform(value) });
1203
+ }
1204
+ return platforms.toOwnedSlice(allocator);
1205
+ }
1206
+
1207
+ fn parsePlatform(value: []const u8) app_manifest.Platform {
1208
+ if (std.mem.eql(u8, value, "macos")) return .macos;
1209
+ if (std.mem.eql(u8, value, "windows")) return .windows;
1210
+ if (std.mem.eql(u8, value, "linux")) return .linux;
1211
+ if (std.mem.eql(u8, value, "ios")) return .ios;
1212
+ if (std.mem.eql(u8, value, "android")) return .android;
1213
+ if (std.mem.eql(u8, value, "web")) return .web;
1214
+ return .unknown;
1215
+ }
1216
+
1217
+ fn parseExternalLinkAction(value: []const u8) !app_manifest.ExternalLinkAction {
1218
+ if (std.mem.eql(u8, value, "deny")) return .deny;
1219
+ if (std.mem.eql(u8, value, "open_system_browser")) return .open_system_browser;
1220
+ return error.InvalidAction;
1221
+ }
1222
+
1223
+ fn parseRestorePolicy(value: []const u8) !app_manifest.WindowRestorePolicy {
1224
+ if (std.mem.eql(u8, value, "clamp_to_visible_screen")) return .clamp_to_visible_screen;
1225
+ if (std.mem.eql(u8, value, "center_on_primary")) return .center_on_primary;
1226
+ return error.InvalidWindowRestorePolicy;
1227
+ }
1228
+
1229
+ fn parseTitlebarStyle(value: []const u8) !app_manifest.WindowTitlebarStyle {
1230
+ if (std.mem.eql(u8, value, "standard")) return .standard;
1231
+ if (std.mem.eql(u8, value, "hidden_inset")) return .hidden_inset;
1232
+ if (std.mem.eql(u8, value, "hidden_inset_tall")) return .hidden_inset_tall;
1233
+ if (std.mem.eql(u8, value, "chromeless")) return .chromeless;
1234
+ return error.InvalidWindowTitlebarStyle;
1235
+ }
1236
+
1237
+ /// Same validation posture as the titlebar style: a min-size floor the
1238
+ /// host cannot honor (negative or non-finite) is a manifest error, not
1239
+ /// a silent clamp. 0 is the "no floor" sentinel.
1240
+ fn parseWindowMinSize(value: f32) !f32 {
1241
+ if (!std.math.isFinite(value) or value < 0) return error.InvalidWindowMinSize;
1242
+ return value;
1243
+ }
1244
+
1245
+ fn parseViewKind(value: []const u8) !app_manifest.ViewKind {
1246
+ if (std.mem.eql(u8, value, "webview")) return .webview;
1247
+ if (std.mem.eql(u8, value, "toolbar")) return .toolbar;
1248
+ if (std.mem.eql(u8, value, "titlebar_accessory")) return .titlebar_accessory;
1249
+ if (std.mem.eql(u8, value, "sidebar")) return .sidebar;
1250
+ if (std.mem.eql(u8, value, "statusbar")) return .statusbar;
1251
+ if (std.mem.eql(u8, value, "split")) return .split;
1252
+ if (std.mem.eql(u8, value, "stack")) return .stack;
1253
+ if (std.mem.eql(u8, value, "button")) return .button;
1254
+ if (std.mem.eql(u8, value, "icon_button")) return .icon_button;
1255
+ if (std.mem.eql(u8, value, "list_item")) return .list_item;
1256
+ if (std.mem.eql(u8, value, "checkbox")) return .checkbox;
1257
+ if (std.mem.eql(u8, value, "toggle")) return .toggle;
1258
+ if (std.mem.eql(u8, value, "segmented_control")) return .segmented_control;
1259
+ if (std.mem.eql(u8, value, "text_field")) return .text_field;
1260
+ if (std.mem.eql(u8, value, "search_field")) return .search_field;
1261
+ if (std.mem.eql(u8, value, "label")) return .label;
1262
+ if (std.mem.eql(u8, value, "spacer")) return .spacer;
1263
+ if (std.mem.eql(u8, value, "gpu_surface")) return .gpu_surface;
1264
+ if (std.mem.eql(u8, value, "progress_indicator")) return .progress_indicator;
1265
+ return error.InvalidViewKind;
1266
+ }
1267
+
1268
+ fn parseGpuSurfaceBackend(value: []const u8) !app_manifest.GpuSurfaceBackend {
1269
+ if (std.mem.eql(u8, value, "none")) return .none;
1270
+ if (std.mem.eql(u8, value, "metal")) return .metal;
1271
+ if (std.mem.eql(u8, value, "software")) return .software;
1272
+ return error.InvalidViewKind;
1273
+ }
1274
+
1275
+ fn parseGpuSurfacePixelFormat(value: []const u8) !app_manifest.GpuSurfacePixelFormat {
1276
+ if (std.mem.eql(u8, value, "none")) return .none;
1277
+ if (std.mem.eql(u8, value, "bgra8_unorm")) return .bgra8_unorm;
1278
+ return error.InvalidViewKind;
1279
+ }
1280
+
1281
+ fn parseGpuSurfacePresentMode(value: []const u8) !app_manifest.GpuSurfacePresentMode {
1282
+ if (std.mem.eql(u8, value, "none")) return .none;
1283
+ if (std.mem.eql(u8, value, "timer")) return .timer;
1284
+ return error.InvalidViewKind;
1285
+ }
1286
+
1287
+ fn parseGpuSurfaceAlphaMode(value: []const u8) !app_manifest.GpuSurfaceAlphaMode {
1288
+ if (std.mem.eql(u8, value, "none")) return .none;
1289
+ if (std.mem.eql(u8, value, "opaque")) return .@"opaque";
1290
+ if (std.mem.eql(u8, value, "premultiplied")) return .premultiplied;
1291
+ return error.InvalidViewKind;
1292
+ }
1293
+
1294
+ fn parseGpuSurfaceColorSpace(value: []const u8) !app_manifest.GpuSurfaceColorSpace {
1295
+ if (std.mem.eql(u8, value, "none")) return .none;
1296
+ if (std.mem.eql(u8, value, "srgb")) return .srgb;
1297
+ if (std.mem.eql(u8, value, "display_p3")) return .display_p3;
1298
+ return error.InvalidViewKind;
1299
+ }
1300
+
1301
+ fn parseShellEdge(value: []const u8) !app_manifest.ShellEdge {
1302
+ if (std.mem.eql(u8, value, "top")) return .top;
1303
+ if (std.mem.eql(u8, value, "right")) return .right;
1304
+ if (std.mem.eql(u8, value, "bottom")) return .bottom;
1305
+ if (std.mem.eql(u8, value, "left")) return .left;
1306
+ return error.InvalidLayout;
1307
+ }
1308
+
1309
+ fn parseShellAxis(value: []const u8) !app_manifest.ShellAxis {
1310
+ if (std.mem.eql(u8, value, "row") or std.mem.eql(u8, value, "horizontal")) return .row;
1311
+ if (std.mem.eql(u8, value, "column") or std.mem.eql(u8, value, "vertical")) return .column;
1312
+ return error.InvalidLayout;
1313
+ }
1314
+
1315
+ fn parseWebEngine(value: []const u8) !app_manifest.WebEngine {
1316
+ if (std.mem.eql(u8, value, "system")) return .system;
1317
+ if (std.mem.eql(u8, value, "chromium")) return .chromium;
1318
+ return error.InvalidWebEngine;
1319
+ }
1320
+
1321
+ fn validateRelativePath(path: []const u8) !void {
1322
+ if (path.len == 0) return error.InvalidPath;
1323
+ if (path[0] == '/' or path[0] == '\\') return error.InvalidPath;
1324
+ if (path.len >= 3 and std.ascii.isAlphabetic(path[0]) and path[1] == ':' and (path[2] == '/' or path[2] == '\\')) return error.InvalidPath;
1325
+ var segment_start: usize = 0;
1326
+ for (path, 0..) |ch, index| {
1327
+ if (ch == 0 or ch == '\\') return error.InvalidPath;
1328
+ if (ch == '/') {
1329
+ try validatePathSegment(path[segment_start..index]);
1330
+ segment_start = index + 1;
1331
+ }
1332
+ }
1333
+ try validatePathSegment(path[segment_start..]);
1334
+ }
1335
+
1336
+ fn validatePathSegment(segment: []const u8) !void {
1337
+ if (segment.len == 0) return error.InvalidPath;
1338
+ if (std.mem.eql(u8, segment, ".") or std.mem.eql(u8, segment, "..")) return error.InvalidPath;
1339
+ }
1340
+
1341
+ fn parseVersionNumber(value: []const u8) !u32 {
1342
+ if (value.len == 0) return error.InvalidVersion;
1343
+ return std.fmt.parseUnsigned(u32, value, 10);
1344
+ }
1345
+
1346
+ test "manifest metadata parser reads identity version and lists" {
1347
+ const metadata = try parseText(std.testing.allocator,
1348
+ \\.{
1349
+ \\ .id = "com.example.app",
1350
+ \\ .name = "example",
1351
+ \\ .display_name = "Example App",
1352
+ \\ .description = "An example app for the manifest parser.",
1353
+ \\ .version = "1.2.3",
1354
+ \\ .icons = .{ "assets/icon.png" },
1355
+ \\ .platforms = .{ "macos", "linux" },
1356
+ \\ .capabilities = .{
1357
+ \\ "native_module", "webview", "js_bridge", "native_views", "gpu_surfaces", "menus", "shortcuts", "tray",
1358
+ \\ "dialog", "credentials", "file_drops", "file_associations", "url_schemes",
1359
+ \\ "open_url", "reveal_path", "recent_documents", "app_activation_events",
1360
+ \\ },
1361
+ \\ .bridge = .{ .commands = .{ .{ .name = "native.ping" } } },
1362
+ \\ .web_engine = "chromium",
1363
+ \\ .cef = .{ .dir = "third_party/cef/macos", .auto_install = true },
1364
+ \\ .commands = .{
1365
+ \\ .{ .id = "app.refresh", .title = "Refresh" },
1366
+ \\ .{ .id = "app.sidebar.toggle", .title = "Sidebar", .checked = true },
1367
+ \\ },
1368
+ \\ .menus = .{
1369
+ \\ .{
1370
+ \\ .title = "View",
1371
+ \\ .items = .{
1372
+ \\ .{ .label = "Refresh", .command = "app.refresh", .key = "r", .modifiers = .{ "primary" } },
1373
+ \\ .{ .separator = true },
1374
+ \\ .{ .label = "Sidebar", .command = "app.sidebar.toggle", .checked = true },
1375
+ \\ },
1376
+ \\ },
1377
+ \\ },
1378
+ \\ .shortcuts = .{
1379
+ \\ .{ .id = "command.palette", .key = "p", .modifiers = .{ "primary", "shift" } },
1380
+ \\ },
1381
+ \\ .file_associations = .{
1382
+ \\ .{ .name = "Markdown Document", .extensions = .{ "md", ".markdown" }, .mime_types = .{ "text/markdown" }, .icon = "assets/markdown.icns" },
1383
+ \\ },
1384
+ \\ .url_schemes = .{
1385
+ \\ .{ .scheme = "example-app" },
1386
+ \\ },
1387
+ \\}
1388
+ );
1389
+ defer metadata.deinit(std.testing.allocator);
1390
+
1391
+ try std.testing.expectEqualStrings("com.example.app", metadata.id);
1392
+ try std.testing.expectEqualStrings("example", metadata.name);
1393
+ try std.testing.expectEqualStrings("Example App", metadata.displayName());
1394
+ try std.testing.expectEqualStrings("An example app for the manifest parser.", metadata.description.?);
1395
+ try std.testing.expectEqualStrings("1.2.3", metadata.version);
1396
+ try std.testing.expectEqualStrings("assets/icon.png", metadata.icons[0]);
1397
+ try std.testing.expectEqualStrings("linux", metadata.platforms[1]);
1398
+ try std.testing.expectEqualStrings("webview", metadata.capabilities[1]);
1399
+ try std.testing.expectEqualStrings("native_views", metadata.capabilities[3]);
1400
+ try std.testing.expectEqualStrings("gpu_surfaces", metadata.capabilities[4]);
1401
+ try std.testing.expectEqualStrings("dialog", metadata.capabilities[8]);
1402
+ try std.testing.expectEqualStrings("file_drops", metadata.capabilities[10]);
1403
+ try std.testing.expectEqualStrings("url_schemes", metadata.capabilities[12]);
1404
+ const parsed_capabilities = try parseCapabilities(std.testing.allocator, metadata.capabilities);
1405
+ defer std.testing.allocator.free(parsed_capabilities);
1406
+ try std.testing.expectEqual(app_manifest.CapabilityKind.native_views, parsed_capabilities[3].kind());
1407
+ try std.testing.expectEqual(app_manifest.CapabilityKind.gpu_surfaces, parsed_capabilities[4].kind());
1408
+ try std.testing.expectEqual(app_manifest.CapabilityKind.menus, parsed_capabilities[5].kind());
1409
+ try std.testing.expectEqual(app_manifest.CapabilityKind.shortcuts, parsed_capabilities[6].kind());
1410
+ try std.testing.expectEqual(app_manifest.CapabilityKind.tray, parsed_capabilities[7].kind());
1411
+ try std.testing.expectEqual(app_manifest.CapabilityKind.file_drops, parsed_capabilities[10].kind());
1412
+ try std.testing.expectEqual(app_manifest.CapabilityKind.file_associations, parsed_capabilities[11].kind());
1413
+ try std.testing.expectEqual(app_manifest.CapabilityKind.url_schemes, parsed_capabilities[12].kind());
1414
+ try std.testing.expectEqual(app_manifest.CapabilityKind.open_url, parsed_capabilities[13].kind());
1415
+ try std.testing.expectEqual(app_manifest.CapabilityKind.reveal_path, parsed_capabilities[14].kind());
1416
+ try std.testing.expectEqual(app_manifest.CapabilityKind.recent_documents, parsed_capabilities[15].kind());
1417
+ try std.testing.expectEqual(app_manifest.CapabilityKind.app_activation_events, parsed_capabilities[16].kind());
1418
+ try std.testing.expectEqualStrings("native.ping", metadata.bridge_commands[0].name);
1419
+ try std.testing.expectEqualStrings("app.refresh", metadata.commands[0].id);
1420
+ try std.testing.expectEqualStrings("Refresh", metadata.commands[0].title);
1421
+ try std.testing.expect(metadata.commands[0].enabled);
1422
+ try std.testing.expect(metadata.commands[1].checked);
1423
+ try std.testing.expectEqualStrings("View", metadata.menus[0].title);
1424
+ try std.testing.expectEqualStrings("Refresh", metadata.menus[0].items[0].label);
1425
+ try std.testing.expectEqualStrings("app.refresh", metadata.menus[0].items[0].command);
1426
+ try std.testing.expectEqualStrings("primary", metadata.menus[0].items[0].modifiers[0]);
1427
+ try std.testing.expect(metadata.menus[0].items[1].separator);
1428
+ try std.testing.expect(metadata.menus[0].items[2].checked);
1429
+ try std.testing.expectEqualStrings("command.palette", metadata.shortcuts[0].id);
1430
+ try std.testing.expectEqualStrings("primary", metadata.shortcuts[0].modifiers[0]);
1431
+ try std.testing.expectEqualStrings("Markdown Document", metadata.file_associations[0].name);
1432
+ try std.testing.expectEqualStrings(".markdown", metadata.file_associations[0].extensions[1]);
1433
+ try std.testing.expectEqualStrings("text/markdown", metadata.file_associations[0].mime_types[0]);
1434
+ try std.testing.expectEqualStrings("assets/markdown.icns", metadata.file_associations[0].icon.?);
1435
+ try std.testing.expectEqualStrings("example-app", metadata.url_schemes[0].scheme);
1436
+ try std.testing.expectEqualStrings("chromium", metadata.web_engine);
1437
+ try std.testing.expectEqualStrings("third_party/cef/macos", metadata.cef.dir);
1438
+ try std.testing.expect(metadata.cef.auto_install);
1439
+ try std.testing.expectEqual(@as(u32, 2), (try parseVersion(metadata.version)).minor);
1440
+
1441
+ const associations = try parseFileAssociations(std.testing.allocator, metadata.file_associations);
1442
+ defer std.testing.allocator.free(associations);
1443
+ const schemes = try parseUrlSchemes(std.testing.allocator, metadata.url_schemes);
1444
+ defer std.testing.allocator.free(schemes);
1445
+ const menus = try parseMenus(std.testing.allocator, metadata.menus);
1446
+ defer deinitParsedMenus(std.testing.allocator, menus);
1447
+ const commands = try parseCommands(std.testing.allocator, metadata.commands);
1448
+ defer std.testing.allocator.free(commands);
1449
+ try app_manifest.validateManifest(.{
1450
+ .identity = .{ .id = metadata.id, .name = metadata.name },
1451
+ .version = try parseVersion(metadata.version),
1452
+ .commands = commands,
1453
+ .menus = menus,
1454
+ .file_associations = associations,
1455
+ .url_schemes = schemes,
1456
+ });
1457
+ }
1458
+
1459
+ test "manifest metadata parser reads structured security policy" {
1460
+ const metadata = try parseText(std.testing.allocator,
1461
+ \\.{
1462
+ \\ .id = "com.example.app",
1463
+ \\ .name = "example",
1464
+ \\ .version = "1.2.3",
1465
+ \\ .permissions = .{ "window", "filesystem", "credentials" },
1466
+ \\ .bridge = .{
1467
+ \\ .commands = .{
1468
+ \\ .{ .name = "native.ping", .permissions = .{ "filesystem" }, .origins = .{ "zero://app" } },
1469
+ \\ },
1470
+ \\ },
1471
+ \\ .security = .{
1472
+ \\ .navigation = .{
1473
+ \\ .allowed_origins = .{ "zero://app", "http://127.0.0.1:5173" },
1474
+ \\ .external_links = .{
1475
+ \\ .action = "open_system_browser",
1476
+ \\ .allowed_urls = .{ "https://example.com/*" },
1477
+ \\ },
1478
+ \\ },
1479
+ \\ },
1480
+ \\}
1481
+ );
1482
+ defer metadata.deinit(std.testing.allocator);
1483
+
1484
+ try std.testing.expectEqualStrings("window", metadata.permissions[0]);
1485
+ try std.testing.expectEqualStrings("credentials", metadata.permissions[2]);
1486
+ try std.testing.expectEqualStrings("native.ping", metadata.bridge_commands[0].name);
1487
+ try std.testing.expectEqualStrings("filesystem", metadata.bridge_commands[0].permissions[0]);
1488
+ try std.testing.expectEqualStrings("zero://app", metadata.bridge_commands[0].origins[0]);
1489
+ try std.testing.expectEqualStrings("http://127.0.0.1:5173", metadata.security.navigation.allowed_origins[1]);
1490
+ try std.testing.expectEqualStrings("open_system_browser", metadata.security.navigation.external_links.action);
1491
+ try std.testing.expectEqualStrings("https://example.com/*", metadata.security.navigation.external_links.allowed_urls[0]);
1492
+ }
1493
+
1494
+ test "manifest metadata parser reads declared platform chrome" {
1495
+ const metadata = try parseText(std.testing.allocator,
1496
+ \\.{
1497
+ \\ .id = "com.example.app",
1498
+ \\ .name = "example",
1499
+ \\ .version = "1.2.3",
1500
+ \\ .shell = .{
1501
+ \\ .chrome = .{
1502
+ \\ .tabs = .{
1503
+ \\ .{ .id = "tabs.home", .label = "Home", .icon = "menu" },
1504
+ \\ .{ .id = "tabs.settings", .label = "Settings", .icon = "settings" },
1505
+ \\ },
1506
+ \\ .primary_action = .{ .id = "action.new", .label = "New", .icon = "plus" },
1507
+ \\ },
1508
+ \\ .windows = .{
1509
+ \\ .{
1510
+ \\ .label = "main",
1511
+ \\ .views = .{
1512
+ \\ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html", .fill = true },
1513
+ \\ },
1514
+ \\ },
1515
+ \\ },
1516
+ \\ },
1517
+ \\}
1518
+ );
1519
+ defer metadata.deinit(std.testing.allocator);
1520
+
1521
+ try std.testing.expectEqual(@as(usize, 2), metadata.shell.chrome.tabs.len);
1522
+ try std.testing.expectEqualStrings("tabs.home", metadata.shell.chrome.tabs[0].id);
1523
+ try std.testing.expectEqualStrings("Home", metadata.shell.chrome.tabs[0].label);
1524
+ try std.testing.expectEqualStrings("menu", metadata.shell.chrome.tabs[0].icon);
1525
+ try std.testing.expectEqualStrings("action.new", metadata.shell.chrome.primary_action.?.id);
1526
+
1527
+ // The parsed shell carries the declaration through to the shared
1528
+ // manifest validation, which accepts it whole.
1529
+ const shell = try parseShell(std.testing.allocator, metadata.shell);
1530
+ defer deinitParsedShell(std.testing.allocator, shell);
1531
+ try std.testing.expectEqual(@as(usize, 2), shell.chrome.tabs.len);
1532
+ try std.testing.expectEqualStrings("tabs.settings", shell.chrome.tabs[1].id);
1533
+ try std.testing.expectEqualStrings("plus", shell.chrome.primary_action.?.icon);
1534
+ try app_manifest.validateShellChrome(shell.chrome);
1535
+ }
1536
+
1537
+ test "manifest metadata parser reads shell windows and views" {
1538
+ const metadata = try parseText(std.testing.allocator,
1539
+ \\.{
1540
+ \\ .id = "com.example.app",
1541
+ \\ .name = "example",
1542
+ \\ .version = "1.2.3",
1543
+ \\ .shell = .{
1544
+ \\ .windows = .{
1545
+ \\ .{
1546
+ \\ .label = "main",
1547
+ \\ .title = "Example",
1548
+ \\ .width = 1100,
1549
+ \\ .height = 760,
1550
+ \\ .restore_policy = "center_on_primary",
1551
+ \\ .views = .{
1552
+ \\ .{ .label = "toolbar", .kind = "toolbar", .edge = "top", .height = 44, .role = "toolbar" },
1553
+ \\ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html", .fill = true, .min_width = 640, .min_height = 400, .max_width = 1440, .max_height = 900 },
1554
+ \\ .{ .label = "status", .kind = "statusbar", .edge = "bottom", .height = 24, .text = "Ready" },
1555
+ \\ .{ .label = "toolbar-stack", .kind = "stack", .parent = "toolbar", .axis = "column" },
1556
+ \\ .{ .label = "refresh-icon", .kind = "icon_button", .parent = "toolbar", .text = "R", .command = "app.refresh.icon" },
1557
+ \\ .{ .label = "save", .kind = "button", .parent = "toolbar", .accessibility_label = "Save document", .text = "Save", .command = "app.save" },
1558
+ \\ .{ .label = "mode", .kind = "segmented_control", .parent = "toolbar", .text = "List|Grid", .command = "app.view.mode" },
1559
+ \\ .{ .label = "syncing", .kind = "progress_indicator", .parent = "toolbar", .role = "Syncing" },
1560
+ \\ .{ .label = "nav-row", .kind = "list_item", .parent = "toolbar-stack", .text = "Inbox", .command = "app.open.inbox" },
1561
+ \\ .{ .label = "canvas", .kind = "gpu_surface", .gpu_backend = "metal", .gpu_pixel_format = "bgra8_unorm", .gpu_present_mode = "timer", .gpu_alpha_mode = "opaque", .gpu_color_space = "srgb", .gpu_vsync = true },
1562
+ \\ },
1563
+ \\ },
1564
+ \\ },
1565
+ \\ },
1566
+ \\}
1567
+ );
1568
+ defer metadata.deinit(std.testing.allocator);
1569
+
1570
+ try std.testing.expectEqualStrings("main", metadata.shell.windows[0].label);
1571
+ try std.testing.expectEqualStrings("center_on_primary", metadata.shell.windows[0].restore_policy);
1572
+ try std.testing.expectEqualStrings("toolbar", metadata.shell.windows[0].views[0].kind);
1573
+ try std.testing.expectEqualStrings("zero://app/index.html", metadata.shell.windows[0].views[1].url.?);
1574
+ try std.testing.expect(metadata.shell.windows[0].views[1].fill);
1575
+ try std.testing.expectEqual(@as(?f32, 640), metadata.shell.windows[0].views[1].min_width);
1576
+ try std.testing.expectEqual(@as(?f32, 400), metadata.shell.windows[0].views[1].min_height);
1577
+ try std.testing.expectEqual(@as(?f32, 1440), metadata.shell.windows[0].views[1].max_width);
1578
+ try std.testing.expectEqual(@as(?f32, 900), metadata.shell.windows[0].views[1].max_height);
1579
+ try std.testing.expectEqualStrings("stack", metadata.shell.windows[0].views[3].kind);
1580
+ try std.testing.expectEqualStrings("column", metadata.shell.windows[0].views[3].axis.?);
1581
+ try std.testing.expectEqualStrings("icon_button", metadata.shell.windows[0].views[4].kind);
1582
+ try std.testing.expectEqualStrings("app.save", metadata.shell.windows[0].views[5].command.?);
1583
+ try std.testing.expectEqualStrings("Save document", metadata.shell.windows[0].views[5].accessibility_label.?);
1584
+ try std.testing.expectEqualStrings("segmented_control", metadata.shell.windows[0].views[6].kind);
1585
+ try std.testing.expectEqualStrings("progress_indicator", metadata.shell.windows[0].views[7].kind);
1586
+ try std.testing.expectEqualStrings("list_item", metadata.shell.windows[0].views[8].kind);
1587
+ try std.testing.expectEqualStrings("gpu_surface", metadata.shell.windows[0].views[9].kind);
1588
+ try std.testing.expectEqualStrings("metal", metadata.shell.windows[0].views[9].gpu_backend.?);
1589
+ try std.testing.expectEqualStrings("bgra8_unorm", metadata.shell.windows[0].views[9].gpu_pixel_format.?);
1590
+ try std.testing.expectEqualStrings("timer", metadata.shell.windows[0].views[9].gpu_present_mode.?);
1591
+ try std.testing.expectEqualStrings("opaque", metadata.shell.windows[0].views[9].gpu_alpha_mode.?);
1592
+ try std.testing.expectEqualStrings("srgb", metadata.shell.windows[0].views[9].gpu_color_space.?);
1593
+ try std.testing.expect(metadata.shell.windows[0].views[9].gpu_vsync.?);
1594
+
1595
+ const shell = try parseShell(std.testing.allocator, metadata.shell);
1596
+ defer deinitParsedShell(std.testing.allocator, shell);
1597
+ try std.testing.expectEqual(app_manifest.ViewKind.webview, shell.windows[0].views[1].kind);
1598
+ try std.testing.expectEqual(@as(?f32, 640), shell.windows[0].views[1].min_width);
1599
+ try std.testing.expectEqual(@as(?f32, 400), shell.windows[0].views[1].min_height);
1600
+ try std.testing.expectEqual(@as(?f32, 1440), shell.windows[0].views[1].max_width);
1601
+ try std.testing.expectEqual(@as(?f32, 900), shell.windows[0].views[1].max_height);
1602
+ try std.testing.expectEqual(app_manifest.ViewKind.stack, shell.windows[0].views[3].kind);
1603
+ try std.testing.expectEqual(app_manifest.ShellAxis.column, shell.windows[0].views[3].axis.?);
1604
+ try std.testing.expectEqual(app_manifest.ViewKind.icon_button, shell.windows[0].views[4].kind);
1605
+ try std.testing.expectEqualStrings("Save document", shell.windows[0].views[5].accessibility_label.?);
1606
+ try std.testing.expectEqual(app_manifest.ViewKind.segmented_control, shell.windows[0].views[6].kind);
1607
+ try std.testing.expectEqual(app_manifest.ViewKind.progress_indicator, shell.windows[0].views[7].kind);
1608
+ try std.testing.expectEqual(app_manifest.ViewKind.list_item, shell.windows[0].views[8].kind);
1609
+ try std.testing.expectEqual(app_manifest.ViewKind.gpu_surface, shell.windows[0].views[9].kind);
1610
+ try std.testing.expectEqual(app_manifest.GpuSurfaceBackend.metal, shell.windows[0].views[9].gpu_backend.?);
1611
+ try std.testing.expectEqual(app_manifest.GpuSurfacePixelFormat.bgra8_unorm, shell.windows[0].views[9].gpu_pixel_format.?);
1612
+ try std.testing.expectEqual(app_manifest.GpuSurfacePresentMode.timer, shell.windows[0].views[9].gpu_present_mode.?);
1613
+ try std.testing.expectEqual(app_manifest.GpuSurfaceAlphaMode.@"opaque", shell.windows[0].views[9].gpu_alpha_mode.?);
1614
+ try std.testing.expectEqual(app_manifest.GpuSurfaceColorSpace.srgb, shell.windows[0].views[9].gpu_color_space.?);
1615
+ try std.testing.expect(shell.windows[0].views[9].gpu_vsync.?);
1616
+ try std.testing.expectEqual(app_manifest.ShellEdge.top, shell.windows[0].views[0].edge.?);
1617
+ try app_manifest.validateManifest(.{
1618
+ .identity = .{ .id = metadata.id, .name = metadata.name },
1619
+ .version = try parseVersion(metadata.version),
1620
+ .shell = shell,
1621
+ });
1622
+ }
1623
+
1624
+ test "manifest parser reads window titlebar styles" {
1625
+ const metadata = try parseText(std.testing.allocator,
1626
+ \\.{
1627
+ \\ .id = "com.example.app",
1628
+ \\ .name = "example",
1629
+ \\ .version = "1.2.3",
1630
+ \\ .windows = .{
1631
+ \\ .{ .label = "main", .resizable = false, .titlebar = "hidden_inset" },
1632
+ \\ .{ .label = "tall", .titlebar = "hidden_inset_tall" },
1633
+ \\ .{ .label = "skinned", .titlebar = "chromeless" },
1634
+ \\ },
1635
+ \\ .shell = .{
1636
+ \\ .windows = .{
1637
+ \\ .{ .label = "scene", .titlebar = "hidden_inset_tall", .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1638
+ \\ },
1639
+ \\ },
1640
+ \\}
1641
+ );
1642
+ defer metadata.deinit(std.testing.allocator);
1643
+
1644
+ try std.testing.expectEqualStrings("hidden_inset", metadata.windows[0].titlebar);
1645
+ try std.testing.expect(!metadata.windows[0].resizable);
1646
+ try std.testing.expectEqualStrings("hidden_inset_tall", metadata.windows[1].titlebar);
1647
+ try std.testing.expectEqualStrings("chromeless", metadata.windows[2].titlebar);
1648
+ try std.testing.expectEqualStrings("hidden_inset_tall", metadata.shell.windows[0].titlebar);
1649
+
1650
+ const windows = try convertWindows(std.testing.allocator, metadata.windows);
1651
+ defer std.testing.allocator.free(windows);
1652
+ try std.testing.expectEqual(app_manifest.WindowTitlebarStyle.hidden_inset, windows[0].titlebar);
1653
+ try std.testing.expect(!windows[0].resizable);
1654
+ try std.testing.expectEqual(app_manifest.WindowTitlebarStyle.hidden_inset_tall, windows[1].titlebar);
1655
+ try std.testing.expectEqual(app_manifest.WindowTitlebarStyle.chromeless, windows[2].titlebar);
1656
+
1657
+ const shell = try parseShell(std.testing.allocator, metadata.shell);
1658
+ defer deinitParsedShell(std.testing.allocator, shell);
1659
+ try std.testing.expectEqual(app_manifest.WindowTitlebarStyle.hidden_inset_tall, shell.windows[0].titlebar);
1660
+ }
1661
+
1662
+ test "manifest parser reads window min sizes" {
1663
+ const metadata = try parseText(std.testing.allocator,
1664
+ \\.{
1665
+ \\ .id = "com.example.app",
1666
+ \\ .name = "example",
1667
+ \\ .version = "1.2.3",
1668
+ \\ .windows = .{
1669
+ \\ .{ .label = "main", .min_width = 596, .min_height = 420 },
1670
+ \\ },
1671
+ \\ .shell = .{
1672
+ \\ .windows = .{
1673
+ \\ .{ .label = "scene", .min_width = 596, .min_height = 420, .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1674
+ \\ },
1675
+ \\ },
1676
+ \\}
1677
+ );
1678
+ defer metadata.deinit(std.testing.allocator);
1679
+
1680
+ try std.testing.expectEqual(@as(f32, 596), metadata.windows[0].min_width);
1681
+ try std.testing.expectEqual(@as(f32, 420), metadata.windows[0].min_height);
1682
+ try std.testing.expectEqual(@as(f32, 596), metadata.shell.windows[0].min_width);
1683
+
1684
+ const windows = try convertWindows(std.testing.allocator, metadata.windows);
1685
+ defer std.testing.allocator.free(windows);
1686
+ try std.testing.expectEqual(@as(f32, 596), windows[0].min_width);
1687
+ try std.testing.expectEqual(@as(f32, 420), windows[0].min_height);
1688
+
1689
+ const shell = try parseShell(std.testing.allocator, metadata.shell);
1690
+ defer deinitParsedShell(std.testing.allocator, shell);
1691
+ try std.testing.expectEqual(@as(f32, 596), shell.windows[0].min_width);
1692
+ try std.testing.expectEqual(@as(f32, 420), shell.windows[0].min_height);
1693
+ }
1694
+
1695
+ test "manifest parser rejects negative window min sizes" {
1696
+ const metadata = try parseText(std.testing.allocator,
1697
+ \\.{
1698
+ \\ .id = "com.example.app",
1699
+ \\ .name = "example",
1700
+ \\ .version = "1.2.3",
1701
+ \\ .windows = .{
1702
+ \\ .{ .label = "main", .min_width = -1 },
1703
+ \\ },
1704
+ \\ .shell = .{
1705
+ \\ .windows = .{
1706
+ \\ .{ .label = "scene", .min_height = -20, .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1707
+ \\ },
1708
+ \\ },
1709
+ \\}
1710
+ );
1711
+ defer metadata.deinit(std.testing.allocator);
1712
+
1713
+ try std.testing.expectError(error.InvalidWindowMinSize, convertWindows(std.testing.allocator, metadata.windows));
1714
+ try std.testing.expectError(error.InvalidWindowMinSize, parseShell(std.testing.allocator, metadata.shell));
1715
+ }
1716
+
1717
+ test "manifest parser rejects unknown window titlebar style" {
1718
+ const metadata = try parseText(std.testing.allocator,
1719
+ \\.{
1720
+ \\ .id = "com.example.app",
1721
+ \\ .name = "example",
1722
+ \\ .version = "1.2.3",
1723
+ \\ .windows = .{
1724
+ \\ .{ .label = "main", .titlebar = "transparent" },
1725
+ \\ },
1726
+ \\ .shell = .{
1727
+ \\ .windows = .{
1728
+ \\ .{ .label = "scene", .titlebar = "frameless", .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1729
+ \\ },
1730
+ \\ },
1731
+ \\}
1732
+ );
1733
+ defer metadata.deinit(std.testing.allocator);
1734
+
1735
+ try std.testing.expectError(error.InvalidWindowTitlebarStyle, convertWindows(std.testing.allocator, metadata.windows));
1736
+ try std.testing.expectError(error.InvalidWindowTitlebarStyle, parseShell(std.testing.allocator, metadata.shell));
1737
+ }
1738
+
1739
+ test "manifest parser rejects invalid shell view kind" {
1740
+ const metadata = try parseText(std.testing.allocator,
1741
+ \\.{
1742
+ \\ .id = "com.example.app",
1743
+ \\ .name = "example",
1744
+ \\ .version = "1.2.3",
1745
+ \\ .shell = .{
1746
+ \\ .windows = .{
1747
+ \\ .{ .views = .{ .{ .label = "content", .kind = "unknown", .url = "zero://app/index.html" } } },
1748
+ \\ },
1749
+ \\ },
1750
+ \\}
1751
+ );
1752
+ defer metadata.deinit(std.testing.allocator);
1753
+
1754
+ try std.testing.expectError(error.InvalidViewKind, parseShell(std.testing.allocator, metadata.shell));
1755
+ }
1756
+
1757
+ test "manifest parser rejects duplicate compatibility and shell window labels" {
1758
+ const metadata = try parseText(std.testing.allocator,
1759
+ \\.{
1760
+ \\ .id = "com.example.app",
1761
+ \\ .name = "example",
1762
+ \\ .version = "1.2.3",
1763
+ \\ .windows = .{
1764
+ \\ .{ .label = "main" },
1765
+ \\ },
1766
+ \\ .shell = .{
1767
+ \\ .windows = .{
1768
+ \\ .{ .label = "main", .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1769
+ \\ },
1770
+ \\ },
1771
+ \\}
1772
+ );
1773
+ defer metadata.deinit(std.testing.allocator);
1774
+
1775
+ const windows = try convertWindows(std.testing.allocator, metadata.windows);
1776
+ defer std.testing.allocator.free(windows);
1777
+ const shell = try parseShell(std.testing.allocator, metadata.shell);
1778
+ defer deinitParsedShell(std.testing.allocator, shell);
1779
+
1780
+ try std.testing.expectError(error.DuplicateWindow, app_manifest.validateManifest(.{
1781
+ .identity = .{ .id = metadata.id, .name = metadata.name },
1782
+ .version = try parseVersion(metadata.version),
1783
+ .windows = windows,
1784
+ .shell = shell,
1785
+ }));
1786
+ }
1787
+
1788
+ test "manifest metadata parser reads frontend config" {
1789
+ const metadata = try parseText(std.testing.allocator,
1790
+ \\.{
1791
+ \\ .id = "com.example.app",
1792
+ \\ .name = "example",
1793
+ \\ .version = "1.2.3",
1794
+ \\ .frontend = .{
1795
+ \\ .dist = "frontend/dist",
1796
+ \\ .entry = "index.html",
1797
+ \\ .spa_fallback = false,
1798
+ \\ .dev = .{
1799
+ \\ .url = "http://127.0.0.1:5173/",
1800
+ \\ .command = .{ "npm", "run", "dev" },
1801
+ \\ .ready_path = "/health",
1802
+ \\ .timeout_ms = 12000,
1803
+ \\ },
1804
+ \\ },
1805
+ \\}
1806
+ );
1807
+ defer metadata.deinit(std.testing.allocator);
1808
+
1809
+ try std.testing.expectEqualStrings("frontend/dist", metadata.frontend.?.dist);
1810
+ try std.testing.expectEqual(false, metadata.frontend.?.spa_fallback);
1811
+ try std.testing.expectEqualStrings("http://127.0.0.1:5173/", metadata.frontend.?.dev.?.url);
1812
+ try std.testing.expectEqualStrings("npm", metadata.frontend.?.dev.?.command[0]);
1813
+ try std.testing.expectEqual(@as(u32, 12000), metadata.frontend.?.dev.?.timeout_ms);
1814
+ }
1815
+
1816
+ test "validate surfaces the non-square icon teaching error with dimensions" {
1817
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
1818
+ defer arena.deinit();
1819
+ const gpa = arena.allocator();
1820
+ var cwd = std.Io.Dir.cwd();
1821
+ const root = ".zig-cache/test-validate-icon-nonsquare";
1822
+ try cwd.deleteTree(std.testing.io, root);
1823
+ defer cwd.deleteTree(std.testing.io, root) catch {};
1824
+ try cwd.createDirPath(std.testing.io, root ++ "/assets");
1825
+
1826
+ // A 6x4 white PNG source.
1827
+ const pixels = try gpa.alloc(u8, 6 * 4 * 4);
1828
+ @memset(pixels, 255);
1829
+ const encoded = try app_icon_tool.encodePng(gpa, pixels, 6, 4);
1830
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/assets/icon.png", .data = encoded });
1831
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
1832
+ \\.{
1833
+ \\ .id = "dev.example.app",
1834
+ \\ .name = "demo",
1835
+ \\ .version = "1.0.0",
1836
+ \\ .icons = .{"assets/icon.png"},
1837
+ \\}
1838
+ });
1839
+
1840
+ const result = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
1841
+ try std.testing.expect(!result.ok);
1842
+ try std.testing.expect(std.mem.indexOf(u8, result.message, "6x4") != null);
1843
+ try std.testing.expect(std.mem.indexOf(u8, result.message, "square") != null);
1844
+ }
1845
+
1846
+ test "validate rejects unsupported icon extensions naming the accepted forms" {
1847
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
1848
+ defer arena.deinit();
1849
+ const gpa = arena.allocator();
1850
+ var cwd = std.Io.Dir.cwd();
1851
+ const root = ".zig-cache/test-validate-icon-ext";
1852
+ try cwd.deleteTree(std.testing.io, root);
1853
+ defer cwd.deleteTree(std.testing.io, root) catch {};
1854
+ try cwd.createDirPath(std.testing.io, root);
1855
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
1856
+ \\.{
1857
+ \\ .id = "dev.example.app",
1858
+ \\ .name = "demo",
1859
+ \\ .version = "1.0.0",
1860
+ \\ .icons = .{"assets/icon.jpg"},
1861
+ \\}
1862
+ });
1863
+
1864
+ const result = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
1865
+ try std.testing.expect(!result.ok);
1866
+ try std.testing.expect(std.mem.indexOf(u8, result.message, ".png") != null);
1867
+ try std.testing.expect(std.mem.indexOf(u8, result.message, ".svg") != null);
1868
+ }
1869
+
1870
+ test "validate reports an unreadable icon source naming the accepted forms" {
1871
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
1872
+ defer arena.deinit();
1873
+ const gpa = arena.allocator();
1874
+ var cwd = std.Io.Dir.cwd();
1875
+ const root = ".zig-cache/test-validate-icon-bad";
1876
+ try cwd.deleteTree(std.testing.io, root);
1877
+ defer cwd.deleteTree(std.testing.io, root) catch {};
1878
+ try cwd.createDirPath(std.testing.io, root ++ "/assets");
1879
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/assets/icon.png", .data = "this is not a png" });
1880
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
1881
+ \\.{
1882
+ \\ .id = "dev.example.app",
1883
+ \\ .name = "demo",
1884
+ \\ .version = "1.0.0",
1885
+ \\ .icons = .{"assets/icon.png"},
1886
+ \\}
1887
+ });
1888
+
1889
+ const result = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
1890
+ try std.testing.expect(!result.ok);
1891
+ try std.testing.expect(std.mem.indexOf(u8, result.message, "could not be read") != null);
1892
+ try std.testing.expect(std.mem.indexOf(u8, result.message, ".png") != null);
1893
+ try std.testing.expect(std.mem.indexOf(u8, result.message, ".svg") != null);
1894
+ }
1895
+
1896
+ test "validate accepts a square icon source and prebuilt containers" {
1897
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
1898
+ defer arena.deinit();
1899
+ const gpa = arena.allocator();
1900
+ var cwd = std.Io.Dir.cwd();
1901
+ const root = ".zig-cache/test-validate-icon-ok";
1902
+ try cwd.deleteTree(std.testing.io, root);
1903
+ defer cwd.deleteTree(std.testing.io, root) catch {};
1904
+ try cwd.createDirPath(std.testing.io, root ++ "/assets");
1905
+
1906
+ const pixels = try gpa.alloc(u8, 600 * 600 * 4);
1907
+ @memset(pixels, 128);
1908
+ const encoded = try app_icon_tool.encodePng(gpa, pixels, 600, 600);
1909
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/assets/icon.png", .data = encoded });
1910
+ try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
1911
+ \\.{
1912
+ \\ .id = "dev.example.app",
1913
+ \\ .name = "demo",
1914
+ \\ .version = "1.0.0",
1915
+ \\ .icons = .{ "assets/icon.png", "assets/prebuilt.icns", "assets/prebuilt.ico" },
1916
+ \\}
1917
+ });
1918
+
1919
+ const result = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
1920
+ try std.testing.expect(result.ok);
1921
+ }
1922
+
1923
+ test "manifest validates the theme pack name" {
1924
+ const metadata = try parseText(std.testing.allocator,
1925
+ \\.{
1926
+ \\ .id = "com.example.app",
1927
+ \\ .name = "example",
1928
+ \\ .version = "1.0.0",
1929
+ \\ .theme = "geist",
1930
+ \\}
1931
+ );
1932
+ defer metadata.deinit(std.testing.allocator);
1933
+ try std.testing.expectEqualStrings("geist", metadata.theme.?);
1934
+ // The known-pack check is the tooling half of the contract; the
1935
+ // runner re-validates the same names at comptime in the app build.
1936
+ try std.testing.expect(isKnownThemePack("house"));
1937
+ try std.testing.expect(isKnownThemePack("geist"));
1938
+ try std.testing.expect(!isKnownThemePack("neon"));
1939
+ }