@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,690 @@
1
+ //! Audio-effect coverage: `fx.playAudio` and the transport commands
2
+ //! (`pauseAudio`/`resumeAudio`/`stopAudio`/`seekAudio`/`setAudioVolume`)
3
+ //! through the fake executor (deterministic request/feed round trips,
4
+ //! rejection) and the real executor against the null platform's fake
5
+ //! player — the same `PlatformServices` seam AVAudioPlayer serves on
6
+ //! macOS. One channel, key-identified events, explicit failure kinds,
7
+ //! and honest automation-snapshot state.
8
+
9
+ const std = @import("std");
10
+ const geometry = @import("geometry");
11
+ const app_manifest = @import("app_manifest");
12
+ const core = @import("core.zig");
13
+ const ui_app_model = @import("ui_app.zig");
14
+ const effects_mod = @import("effects.zig");
15
+ const platform = @import("../platform/root.zig");
16
+
17
+ const canvas_label = "audio-canvas";
18
+
19
+ const audio_views = [_]app_manifest.ShellView{
20
+ .{ .label = canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
21
+ };
22
+ const audio_windows = [_]app_manifest.ShellWindow{.{
23
+ .label = "main",
24
+ .title = "Audio",
25
+ .width = 400,
26
+ .height = 300,
27
+ .views = &audio_views,
28
+ }};
29
+ const audio_scene: app_manifest.ShellConfig = .{ .windows = &audio_windows };
30
+
31
+ const AudioModel = struct {
32
+ event_count: usize = 0,
33
+ last_kind: ?effects_mod.EffectAudioEventKind = null,
34
+ last_key: u64 = 0,
35
+ last_position_ms: u64 = 0,
36
+ last_duration_ms: u64 = 0,
37
+ last_playing: bool = false,
38
+ last_buffering: bool = false,
39
+ last_bands: [platform.audio_spectrum_band_count]u8 = @splat(0),
40
+ completed_count: usize = 0,
41
+ spectrum_count: usize = 0,
42
+
43
+ fn record(model: *AudioModel, event: effects_mod.EffectAudio) void {
44
+ model.event_count += 1;
45
+ model.last_kind = event.kind;
46
+ model.last_key = event.key;
47
+ model.last_position_ms = event.position_ms;
48
+ model.last_duration_ms = event.duration_ms;
49
+ model.last_playing = event.playing;
50
+ model.last_buffering = event.buffering;
51
+ model.last_bands = event.bands;
52
+ if (event.kind == .completed) model.completed_count += 1;
53
+ if (event.kind == .spectrum) model.spectrum_count += 1;
54
+ }
55
+ };
56
+
57
+ const AudioMsg = union(enum) {
58
+ play,
59
+ play_url,
60
+ play_url_only,
61
+ play_empty_path,
62
+ pause,
63
+ unpause,
64
+ stop,
65
+ seek_half,
66
+ quiet,
67
+ audio_event: effects_mod.EffectAudio,
68
+ };
69
+
70
+ const AudioApp = ui_app_model.UiApp(AudioModel, AudioMsg);
71
+ const AudioEffects = AudioApp.Effects;
72
+
73
+ const track_key: u64 = 41;
74
+ const track_path = "assets/music/exit-signs/cedar-ave.mp3";
75
+ const track_url = "https://music.example.test/pack/music/exit-signs/cedar-ave.mp3";
76
+ const track_cache_path = "/tmp/fake-caches/audio/cedar-ave-cache.mp3";
77
+ const track_bytes: u64 = 2_154_887;
78
+
79
+ fn audioUpdate(model: *AudioModel, msg: AudioMsg, fx: *AudioEffects) void {
80
+ switch (msg) {
81
+ .play => fx.playAudio(.{
82
+ .key = track_key,
83
+ .path = track_path,
84
+ .on_event = AudioEffects.audioMsg(.audio_event),
85
+ }),
86
+ // The full cascade shape: local path first, url fallback with a
87
+ // cache path and the manifest's byte size as the integrity gate.
88
+ .play_url => fx.playAudio(.{
89
+ .key = track_key,
90
+ .path = track_path,
91
+ .url = track_url,
92
+ .cache_path = track_cache_path,
93
+ .expected_bytes = track_bytes,
94
+ .on_event = AudioEffects.audioMsg(.audio_event),
95
+ }),
96
+ // URL-only: no local probe at all.
97
+ .play_url_only => fx.playAudio(.{
98
+ .key = track_key,
99
+ .url = track_url,
100
+ .cache_path = track_cache_path,
101
+ .expected_bytes = track_bytes,
102
+ .on_event = AudioEffects.audioMsg(.audio_event),
103
+ }),
104
+ .play_empty_path => fx.playAudio(.{
105
+ .key = track_key,
106
+ .path = "",
107
+ .on_event = AudioEffects.audioMsg(.audio_event),
108
+ }),
109
+ .pause => fx.pauseAudio(),
110
+ .unpause => fx.resumeAudio(),
111
+ .stop => fx.stopAudio(),
112
+ .seek_half => fx.seekAudio(60_000),
113
+ .quiet => fx.setAudioVolume(0.25),
114
+ .audio_event => |event| model.record(event),
115
+ }
116
+ }
117
+
118
+ fn audioView(ui: *AudioApp.Ui, model: *const AudioModel) AudioApp.Ui.Node {
119
+ return ui.column(.{ .gap = 4, .padding = 8 }, .{
120
+ ui.text(.{}, ui.fmt("{d} events", .{model.event_count})),
121
+ ui.button(.{ .on_press = .play }, "Play"),
122
+ ui.button(.{ .on_press = .pause }, "Pause"),
123
+ ui.button(.{ .on_press = .stop }, "Stop"),
124
+ });
125
+ }
126
+
127
+ const Harness = struct {
128
+ harness: *core.TestHarness(),
129
+ app_state: *AudioApp,
130
+ app: core.App,
131
+
132
+ const Config = struct {
133
+ /// false models a host without an audio player (a GTK host
134
+ /// without runtime GStreamer): the services are nulled BEFORE the
135
+ /// platform value is captured, the same shape a real player-less host wires.
136
+ audio_playback: bool = true,
137
+ /// false models a host with a local player but no streaming
138
+ /// path: `audioLoadUrl` is absent and URL playback degrades to
139
+ /// one loud failed Msg.
140
+ audio_streaming: bool = true,
141
+ /// false models a host that plays but cannot analyze its own
142
+ /// playback: `audio_spectrum` reports unsupported and the fake
143
+ /// generator answers null — the honest-absence path consumers
144
+ /// must rest on instead of fabricating bands.
145
+ audio_spectrum: bool = true,
146
+ };
147
+
148
+ fn create() !Harness {
149
+ return createConfigured(.{});
150
+ }
151
+
152
+ fn createConfigured(config: Config) !Harness {
153
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
154
+ errdefer harness.destroy(std.testing.allocator);
155
+ harness.null_platform.gpu_surfaces = true;
156
+ harness.null_platform.audio_playback = config.audio_playback;
157
+ harness.null_platform.audio_streaming = config.audio_streaming;
158
+ harness.null_platform.audio_spectrum = config.audio_spectrum;
159
+ // The harness snapshots the services at create; re-capture so
160
+ // the audio toggle above nulls the service fns the runtime
161
+ // hands the effects channel — the same wiring a real
162
+ // player-less host ships.
163
+ harness.runtime.options.platform = harness.null_platform.platform();
164
+ const app_state = try std.testing.allocator.create(AudioApp);
165
+ errdefer std.testing.allocator.destroy(app_state);
166
+ app_state.* = AudioApp.init(std.heap.page_allocator, .{}, .{
167
+ .name = "effects-audio",
168
+ .scene = audio_scene,
169
+ .canvas_label = canvas_label,
170
+ .update_fx = audioUpdate,
171
+ .view = audioView,
172
+ });
173
+ const app = app_state.app();
174
+ try harness.start(app);
175
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
176
+ .label = canvas_label,
177
+ .size = geometry.SizeF.init(400, 300),
178
+ .scale_factor = 1,
179
+ .frame_index = 1,
180
+ .timestamp_ns = 1_000_000,
181
+ .nonblank = true,
182
+ } });
183
+ try std.testing.expect(app_state.installed);
184
+ return .{ .harness = harness, .app_state = app_state, .app = app };
185
+ }
186
+
187
+ fn destroy(self: *Harness) void {
188
+ self.app_state.deinit();
189
+ std.testing.allocator.destroy(self.app_state);
190
+ self.harness.destroy(std.testing.allocator);
191
+ }
192
+
193
+ fn drainWakes(self: *Harness) !void {
194
+ var nudged = false;
195
+ while (self.harness.null_platform.takeWake()) |_| nudged = true;
196
+ if (nudged) try self.harness.runtime.dispatchPlatformEvent(self.app, .wake);
197
+ }
198
+ };
199
+
200
+ // ------------------------------------------------------------ fake executor
201
+
202
+ test "fake executor records the playback request and feeds events back as msgs" {
203
+ var h = try Harness.create();
204
+ defer h.destroy();
205
+ const fx = &h.app_state.effects;
206
+ fx.executor = .fake;
207
+
208
+ // Play: the request is recorded whole, not executed — nothing
209
+ // touches the platform player.
210
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
211
+ const request = fx.pendingAudio().?;
212
+ try std.testing.expectEqual(track_key, request.key);
213
+ try std.testing.expectEqualStrings(track_path, request.path);
214
+ try std.testing.expect(request.playing);
215
+ try std.testing.expectEqual(@as(usize, 0), h.harness.null_platform.audio_load_count);
216
+
217
+ // The loaded acknowledgment carries the real duration into update.
218
+ try fx.feedAudioEvent(.loaded, 0, 89_160, true);
219
+ try h.harness.runtime.dispatchPlatformEvent(h.app, .wake);
220
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.event_count);
221
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.loaded, h.app_state.model.last_kind.?);
222
+ try std.testing.expectEqual(track_key, h.app_state.model.last_key);
223
+ try std.testing.expectEqual(@as(u64, 89_160), h.app_state.model.last_duration_ms);
224
+
225
+ // Position ticks advance the mirrors the snapshot reports.
226
+ try fx.feedAudioEvent(.position, 1_500, 89_160, true);
227
+ try h.harness.runtime.dispatchPlatformEvent(h.app, .wake);
228
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.position, h.app_state.model.last_kind.?);
229
+ try std.testing.expectEqual(@as(u64, 1_500), h.app_state.model.last_position_ms);
230
+ try std.testing.expect(h.app_state.model.last_playing);
231
+ try std.testing.expectEqual(@as(u64, 1_500), fx.audioSnapshot().position_ms);
232
+
233
+ // Completion fires once, pinned to the duration, playback stopped.
234
+ try fx.feedAudioEvent(.completed, 89_160, 89_160, false);
235
+ try h.harness.runtime.dispatchPlatformEvent(h.app, .wake);
236
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.completed_count);
237
+ try std.testing.expectEqual(@as(u64, 89_160), h.app_state.model.last_position_ms);
238
+ try std.testing.expect(!h.app_state.model.last_playing);
239
+ try std.testing.expect(fx.audioSnapshot().active);
240
+ try std.testing.expect(!fx.audioSnapshot().playing);
241
+ }
242
+
243
+ test "fake transport commands move the mirrors without a platform" {
244
+ var h = try Harness.create();
245
+ defer h.destroy();
246
+ const fx = &h.app_state.effects;
247
+ fx.executor = .fake;
248
+
249
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
250
+ try fx.feedAudioEvent(.loaded, 0, 120_000, true);
251
+ try h.harness.runtime.dispatchPlatformEvent(h.app, .wake);
252
+
253
+ try h.app_state.dispatch(&h.harness.runtime, 1, .pause);
254
+ try std.testing.expect(!fx.audioSnapshot().playing);
255
+ try h.app_state.dispatch(&h.harness.runtime, 1, .unpause);
256
+ try std.testing.expect(fx.audioSnapshot().playing);
257
+ try h.app_state.dispatch(&h.harness.runtime, 1, .seek_half);
258
+ try std.testing.expectEqual(@as(u64, 60_000), fx.audioSnapshot().position_ms);
259
+ try h.app_state.dispatch(&h.harness.runtime, 1, .quiet);
260
+ try std.testing.expectEqual(@as(f32, 0.25), fx.pendingAudio().?.volume);
261
+
262
+ // Stop clears the channel; late feeds report EffectNotFound.
263
+ try h.app_state.dispatch(&h.harness.runtime, 1, .stop);
264
+ try std.testing.expect(fx.pendingAudio() == null);
265
+ try std.testing.expect(!fx.audioSnapshot().active);
266
+ try std.testing.expectError(error.EffectNotFound, fx.feedAudioEvent(.position, 61_000, 120_000, true));
267
+ }
268
+
269
+ test "playback requests that cannot run are rejected loudly, never silently" {
270
+ var h = try Harness.create();
271
+ defer h.destroy();
272
+ const fx = &h.app_state.effects;
273
+ fx.executor = .fake;
274
+
275
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_empty_path);
276
+ try h.drainWakes();
277
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.event_count);
278
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.rejected, h.app_state.model.last_kind.?);
279
+ try std.testing.expectEqual(track_key, h.app_state.model.last_key);
280
+ try std.testing.expect(fx.pendingAudio() == null);
281
+ }
282
+
283
+ // ------------------------------------------------------------ real executor
284
+
285
+ test "real executor drives the platform player and events round-trip" {
286
+ var h = try Harness.create();
287
+ defer h.destroy();
288
+ const np = &h.harness.null_platform;
289
+ try np.setAudioDuration("cedar-ave.mp3", 89_160);
290
+
291
+ // Play loads and starts the platform's single player.
292
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
293
+ try std.testing.expectEqual(@as(usize, 1), np.audio_load_count);
294
+ try std.testing.expectEqual(@as(usize, 1), np.audio_play_count);
295
+ try std.testing.expectEqualStrings(track_path, np.audio.path());
296
+ try std.testing.expect(np.audio.playing);
297
+
298
+ // The loaded acknowledgment arrives as a platform event, exactly as
299
+ // a live host would deliver it after the load call returned.
300
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.takeAudioLoaded().?);
301
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.loaded, h.app_state.model.last_kind.?);
302
+ try std.testing.expectEqual(@as(u64, 89_160), h.app_state.model.last_duration_ms);
303
+
304
+ // Position ticks advance on the test's explicit clock, never on
305
+ // their own.
306
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(500).?);
307
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(500).?);
308
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.position, h.app_state.model.last_kind.?);
309
+ try std.testing.expectEqual(@as(u64, 1_000), h.app_state.model.last_position_ms);
310
+
311
+ // The automation snapshot reports playback honestly.
312
+ const playing_snapshot = h.harness.runtime.automationSnapshot("Audio").audio.?;
313
+ try std.testing.expectEqual(track_key, playing_snapshot.key);
314
+ try std.testing.expect(playing_snapshot.playing);
315
+ try std.testing.expectEqual(@as(u64, 1_000), playing_snapshot.position_ms);
316
+ try std.testing.expectEqual(@as(u64, 89_160), playing_snapshot.duration_ms);
317
+
318
+ // Pause freezes the platform player; ticks stop with it.
319
+ try h.app_state.dispatch(&h.harness.runtime, 1, .pause);
320
+ try std.testing.expectEqual(@as(usize, 1), np.audio_pause_count);
321
+ try std.testing.expect(np.advanceAudio(500) == null);
322
+ try h.app_state.dispatch(&h.harness.runtime, 1, .unpause);
323
+
324
+ // Seek moves the platform position; the next tick reports from it.
325
+ try h.app_state.dispatch(&h.harness.runtime, 1, .seek_half);
326
+ try std.testing.expectEqual(@as(u64, 60_000), np.audio.position_ms);
327
+
328
+ // Advancing past the end delivers the one completion.
329
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(40_000).?);
330
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.completed_count);
331
+ try std.testing.expectEqual(@as(u64, 89_160), h.app_state.model.last_position_ms);
332
+ try std.testing.expect(!h.app_state.model.last_playing);
333
+ try std.testing.expect(np.advanceAudio(500) == null);
334
+
335
+ // Volume rides through to the platform player.
336
+ try h.app_state.dispatch(&h.harness.runtime, 1, .quiet);
337
+ try std.testing.expectEqual(@as(f32, 0.25), np.audio.volume);
338
+
339
+ // Stop unloads; the snapshot goes honestly idle (null, not zeros).
340
+ try h.app_state.dispatch(&h.harness.runtime, 1, .stop);
341
+ try std.testing.expectEqual(@as(usize, 1), np.audio_stop_count);
342
+ try std.testing.expect(!np.audio.loaded);
343
+ try std.testing.expect(h.harness.runtime.automationSnapshot("Audio").audio == null);
344
+ }
345
+
346
+ test "real spectrum reports round-trip: deterministic fake, honest gating, snapshot evidence" {
347
+ var h = try Harness.create();
348
+ defer h.destroy();
349
+ const np = &h.harness.null_platform;
350
+ try np.setAudioDuration("cedar-ave.mp3", 89_160);
351
+
352
+ // No spectrum before anything plays: analysis rides playback.
353
+ try std.testing.expect(np.audioSpectrum() == null);
354
+
355
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
356
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.takeAudioLoaded().?);
357
+
358
+ // The fake generator is a pure function of (source, position): the
359
+ // same instant answers identical bands — the event-shape pin the
360
+ // journal round-trip and replay determinism rely on.
361
+ const first = np.audioSpectrum().?;
362
+ const again = np.audioSpectrum().?;
363
+ try std.testing.expectEqual(platform.AudioEventKind.spectrum, first.audio.kind);
364
+ try std.testing.expectEqualSlices(u8, &first.audio.bands, &again.audio.bands);
365
+ var nonzero = false;
366
+ for (first.audio.bands) |band| {
367
+ if (band != 0) nonzero = true;
368
+ }
369
+ try std.testing.expect(nonzero);
370
+
371
+ // Delivered like every audio event: through the channel into the
372
+ // app's Msg, bands verbatim, plus the snapshot's evidence mirrors.
373
+ try h.harness.runtime.dispatchPlatformEvent(h.app, first);
374
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.spectrum, h.app_state.model.last_kind.?);
375
+ try std.testing.expectEqual(track_key, h.app_state.model.last_key);
376
+ try std.testing.expectEqualSlices(u8, &first.audio.bands, &h.app_state.model.last_bands);
377
+ var snapshot = h.harness.runtime.automationSnapshot("Audio").audio.?;
378
+ try std.testing.expectEqual(@as(u64, 1), snapshot.spectrum_events);
379
+ try std.testing.expectEqualSlices(u8, &first.audio.bands, snapshot.spectrum_bands);
380
+
381
+ // Bands move with the playback position (per-instant determinism,
382
+ // not a frozen frame) ...
383
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(500).?);
384
+ const later = np.audioSpectrum().?;
385
+ try std.testing.expect(!std.mem.eql(u8, &first.audio.bands, &later.audio.bands));
386
+
387
+ // ... and spectrum reports never steer the transport: the position
388
+ // mirror stays where the position ticks put it.
389
+ try h.harness.runtime.dispatchPlatformEvent(h.app, later);
390
+ snapshot = h.harness.runtime.automationSnapshot("Audio").audio.?;
391
+ try std.testing.expectEqual(@as(u64, 500), snapshot.position_ms);
392
+ try std.testing.expectEqual(@as(u64, 2), snapshot.spectrum_events);
393
+
394
+ // Pause starves the stream — freeze-on-pause holds with real data.
395
+ try h.app_state.dispatch(&h.harness.runtime, 1, .pause);
396
+ try std.testing.expect(np.audioSpectrum() == null);
397
+ try h.app_state.dispatch(&h.harness.runtime, 1, .unpause);
398
+
399
+ // Stop unloads: no more reports, and a straggler after stop is
400
+ // swallowed by the channel like every other audio event.
401
+ const straggler = np.audioSpectrum().?;
402
+ try h.app_state.dispatch(&h.harness.runtime, 1, .stop);
403
+ try std.testing.expect(np.audioSpectrum() == null);
404
+ const before = h.app_state.model.event_count;
405
+ try h.harness.runtime.dispatchPlatformEvent(h.app, straggler);
406
+ try std.testing.expectEqual(before, h.app_state.model.event_count);
407
+ }
408
+
409
+ test "occluded-emission rule: spectrum stops while every window is off the glass, resumes current on reveal" {
410
+ var h = try Harness.create();
411
+ defer h.destroy();
412
+ const np = &h.harness.null_platform;
413
+ try np.setAudioDuration("cedar-ave.mp3", 89_160);
414
+ // The headless harness models no windows of its own; create the one
415
+ // whose glass the modeled occlusion covers and reveals.
416
+ const window = try h.harness.runtime.createWindow(.{ .label = "glass", .title = "Audio", .source = platform.WebViewSource.html("<p>audio</p>") });
417
+ const window_id = window.id;
418
+
419
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
420
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.takeAudioLoaded().?);
421
+ try std.testing.expect(np.audioSpectrum() != null);
422
+
423
+ // Fully covered (no minimize verb involved): reports stop, while
424
+ // playback and the position ticks keep flowing untouched — the
425
+ // transport keeps telling the truth, only the display data pauses.
426
+ try np.setWindowOccluded(window_id, true);
427
+ try std.testing.expect(np.audioSpectrum() == null);
428
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(500).?);
429
+ var snapshot = h.harness.runtime.automationSnapshot("Audio").audio.?;
430
+ try std.testing.expectEqual(@as(u64, 500), snapshot.position_ms);
431
+ // The lifetime counter proves the occluded stretch delivered
432
+ // nothing: an occluded journal simply has no spectrum records.
433
+ try std.testing.expectEqual(@as(u64, 0), snapshot.spectrum_events);
434
+
435
+ // Reveal: the very next beat has a report, and it describes NOW —
436
+ // the position moved under the occlusion and the bands moved with
437
+ // it, not a replay of the pre-occlusion frame.
438
+ try np.setWindowOccluded(window_id, false);
439
+ const revealed = np.audioSpectrum().?;
440
+ try h.harness.runtime.dispatchPlatformEvent(h.app, revealed);
441
+ snapshot = h.harness.runtime.automationSnapshot("Audio").audio.?;
442
+ try std.testing.expectEqual(@as(u64, 1), snapshot.spectrum_events);
443
+ try std.testing.expectEqualSlices(u8, &revealed.audio.bands, snapshot.spectrum_bands);
444
+
445
+ // The minimize verb is the same fact: a minimized-away app emits
446
+ // no spectrum, and focus (the Dock-click restore) brings the
447
+ // reports back with the window.
448
+ try h.harness.runtime.minimizeWindow(window_id);
449
+ try std.testing.expect(np.audioSpectrum() == null);
450
+ try h.harness.runtime.focusWindow(window_id);
451
+ try std.testing.expect(np.audioSpectrum() != null);
452
+ }
453
+
454
+ test "a host that cannot analyze reports audio_spectrum unsupported and never emits bands" {
455
+ var h = try Harness.createConfigured(.{ .audio_spectrum = false });
456
+ defer h.destroy();
457
+ const np = &h.harness.null_platform;
458
+ try std.testing.expect(!h.harness.runtime.supports(.audio_spectrum));
459
+ try std.testing.expect(h.harness.runtime.supports(.audio_playback));
460
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
461
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.takeAudioLoaded().?);
462
+ // Playback itself is untouched; only analysis is absent — and the
463
+ // snapshot shows the honest zero instead of fabricated bands.
464
+ try std.testing.expect(np.audioSpectrum() == null);
465
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(500).?);
466
+ const snapshot = h.harness.runtime.automationSnapshot("Audio").audio.?;
467
+ try std.testing.expectEqual(@as(u64, 500), snapshot.position_ms);
468
+ try std.testing.expectEqual(@as(u64, 0), snapshot.spectrum_events);
469
+ }
470
+
471
+ test "a platform without audio playback degrades to one failed event" {
472
+ // Model a player-less host (a GTK host whose runtime-loaded
473
+ // GStreamer is absent): the services are absent and the feature
474
+ // reports false, so playback fails loudly through the Msg loop
475
+ // instead of crashing or silently no-opping.
476
+ var h = try Harness.createConfigured(.{ .audio_playback = false });
477
+ defer h.destroy();
478
+
479
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
480
+ try h.drainWakes();
481
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.event_count);
482
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.failed, h.app_state.model.last_kind.?);
483
+ try std.testing.expectEqual(track_key, h.app_state.model.last_key);
484
+ try std.testing.expect(h.harness.runtime.automationSnapshot("Audio").audio == null);
485
+ }
486
+
487
+ test "a missing local file falls through to the url: stream now, cache next time" {
488
+ var h = try Harness.create();
489
+ defer h.destroy();
490
+ const np = &h.harness.null_platform;
491
+ const fx = &h.app_state.effects;
492
+ // Model the assets-absent machine: every local load answers
493
+ // AudioSourceNotFound, exactly what sends the cascade to the URL.
494
+ np.audio_local_files = false;
495
+ try np.setAudioDuration("cedar-ave.mp3", 89_160);
496
+
497
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_url);
498
+ // The local path was honestly tried (and missing) before the URL
499
+ // resolved — resolution order is pinned, not assumed.
500
+ try std.testing.expectEqual(@as(usize, 1), np.audio_load_count);
501
+ try std.testing.expectEqual(@as(usize, 1), np.audio_load_url_count);
502
+ try std.testing.expectEqualStrings(track_url, np.audio.path());
503
+ try std.testing.expectEqual(effects_mod.EffectAudioSource.stream, fx.audioSnapshot().source);
504
+ // A fresh stream has no bytes yet: buffering starts true
505
+ // optimistically, and the loaded acknowledgment clears it.
506
+ try std.testing.expect(fx.audioSnapshot().buffering);
507
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.takeAudioLoaded().?);
508
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.loaded, h.app_state.model.last_kind.?);
509
+ try std.testing.expect(!fx.audioSnapshot().buffering);
510
+
511
+ // A mid-stream stall rides a position tick with buffering=true; the
512
+ // Msg payload and the snapshot both report it, and the next healthy
513
+ // tick clears it.
514
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.stallAudio().?);
515
+ try std.testing.expect(h.app_state.model.last_buffering);
516
+ try std.testing.expect(fx.audioSnapshot().buffering);
517
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(500).?);
518
+ try std.testing.expect(!h.app_state.model.last_buffering);
519
+ try std.testing.expect(!fx.audioSnapshot().buffering);
520
+
521
+ // Completion installs the cache entry (the fake analog of the
522
+ // host's verify-then-rename): the SECOND play of the same URL
523
+ // resolves from cache — local playback, no buffering, no stream.
524
+ try h.harness.runtime.dispatchPlatformEvent(h.app, np.advanceAudio(89_160).?);
525
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.completed_count);
526
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_url);
527
+ try std.testing.expectEqual(@as(usize, 2), np.audio_load_url_count);
528
+ try std.testing.expectEqual(effects_mod.EffectAudioSource.cache, fx.audioSnapshot().source);
529
+ try std.testing.expect(!fx.audioSnapshot().buffering);
530
+ }
531
+
532
+ test "url-only playback skips the local probe entirely" {
533
+ var h = try Harness.create();
534
+ defer h.destroy();
535
+ const np = &h.harness.null_platform;
536
+ const fx = &h.app_state.effects;
537
+
538
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_url_only);
539
+ try std.testing.expectEqual(@as(usize, 0), np.audio_load_count);
540
+ try std.testing.expectEqual(@as(usize, 1), np.audio_load_url_count);
541
+ try std.testing.expectEqual(effects_mod.EffectAudioSource.stream, fx.audioSnapshot().source);
542
+ }
543
+
544
+ test "a local decode failure never retries the url: masking the real problem helps nobody" {
545
+ var h = try Harness.create();
546
+ defer h.destroy();
547
+ const np = &h.harness.null_platform;
548
+ // An oversized path is the one synchronous local failure the fake
549
+ // can produce that is NOT AudioSourceNotFound... a present file
550
+ // that fails decode is terminal. The fake models source-missing
551
+ // only, so pin the complement: with local files PRESENT the url is
552
+ // never consulted.
553
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_url);
554
+ try std.testing.expectEqual(@as(usize, 1), np.audio_load_count);
555
+ try std.testing.expectEqual(@as(usize, 0), np.audio_load_url_count);
556
+ try std.testing.expectEqual(effects_mod.EffectAudioSource.local, h.app_state.effects.audioSnapshot().source);
557
+ }
558
+
559
+ test "a host with a player but no streaming path degrades url playback to one failed msg" {
560
+ var h = try Harness.createConfigured(.{ .audio_streaming = false });
561
+ defer h.destroy();
562
+ h.harness.null_platform.audio_local_files = false;
563
+
564
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_url);
565
+ try h.drainWakes();
566
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.event_count);
567
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.failed, h.app_state.model.last_kind.?);
568
+ try std.testing.expectEqual(track_key, h.app_state.model.last_key);
569
+ }
570
+
571
+ test "a missing local file with no url is still the original failed degrade" {
572
+ var h = try Harness.create();
573
+ defer h.destroy();
574
+ h.harness.null_platform.audio_local_files = false;
575
+
576
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
577
+ try h.drainWakes();
578
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.event_count);
579
+ try std.testing.expectEqual(effects_mod.EffectAudioEventKind.failed, h.app_state.model.last_kind.?);
580
+ }
581
+
582
+ test "fake executor records the whole url request shape" {
583
+ var h = try Harness.create();
584
+ defer h.destroy();
585
+ const fx = &h.app_state.effects;
586
+ fx.executor = .fake;
587
+
588
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play_url);
589
+ const request = fx.pendingAudio().?;
590
+ try std.testing.expectEqualStrings(track_path, request.path);
591
+ try std.testing.expectEqualStrings(track_url, request.url);
592
+ try std.testing.expectEqualStrings(track_cache_path, request.cache_path);
593
+ try std.testing.expectEqual(track_bytes, request.expected_bytes);
594
+ try std.testing.expectEqual(@as(usize, 0), h.harness.null_platform.audio_load_url_count);
595
+ }
596
+
597
+ test "audioCachePath keys by url hash under audio/ and keeps the extension" {
598
+ var buffer: [512]u8 = undefined;
599
+ const first = try effects_mod.audioCachePath(&buffer, "/tmp/caches/app", track_url);
600
+ try std.testing.expect(std.mem.startsWith(u8, first, "/tmp/caches/app/audio/"));
601
+ try std.testing.expect(std.mem.endsWith(u8, first, ".mp3"));
602
+
603
+ // Same url, same path — the cache is content-addressed by source.
604
+ var second_buffer: [512]u8 = undefined;
605
+ const second = try effects_mod.audioCachePath(&second_buffer, "/tmp/caches/app", track_url);
606
+ try std.testing.expectEqualStrings(first, second);
607
+
608
+ // Different url, different path.
609
+ var third_buffer: [512]u8 = undefined;
610
+ const third = try effects_mod.audioCachePath(&third_buffer, "/tmp/caches/app", "https://music.example.test/pack/music/exit-signs/harvest-lot.mp3");
611
+ try std.testing.expect(!std.mem.eql(u8, first, third));
612
+
613
+ // URL machinery never smuggles into the file name: a query-string
614
+ // "extension" is dropped, not embedded.
615
+ var fourth_buffer: [512]u8 = undefined;
616
+ const fourth = try effectsCachePathNoExt(&fourth_buffer);
617
+ try std.testing.expect(std.mem.indexOfAny(u8, std.fs.path.basename(fourth), "?#&") == null);
618
+ }
619
+
620
+ fn effectsCachePathNoExt(buffer: []u8) ![]const u8 {
621
+ return effects_mod.audioCachePath(buffer, "/tmp/caches/app", "https://music.example.test/stream?id=42");
622
+ }
623
+
624
+ test "quit while playing: the stop hook silences audio on the live platform, and app deinit after platform teardown answers inert" {
625
+ // The desktop runner's exit ordering, replayed exactly: main defers
626
+ // app deinit FIRST and calls the runner, whose own defers destroy
627
+ // the platform host and free the runtime — so on quit the platform
628
+ // dies BEFORE the app's deinit runs. The runtime therefore delivers
629
+ // the app's stop hook before its loop returns; the hook must stop a
630
+ // live playback through the still-alive services and sever the
631
+ // effects channel's binding, so the late deinit never reaches into
632
+ // freed platform memory (the quit-while-audio-plays crash this
633
+ // pins: deinit used to call audioStop through the dead host).
634
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
635
+ errdefer harness.destroy(std.testing.allocator);
636
+ harness.null_platform.gpu_surfaces = true;
637
+ const app_state = try std.testing.allocator.create(AudioApp);
638
+ errdefer std.testing.allocator.destroy(app_state);
639
+ app_state.* = AudioApp.init(std.heap.page_allocator, .{}, .{
640
+ .name = "effects-audio-quit",
641
+ .scene = audio_scene,
642
+ .canvas_label = canvas_label,
643
+ .update_fx = audioUpdate,
644
+ .view = audioView,
645
+ });
646
+ errdefer app_state.deinit();
647
+ const app = app_state.app();
648
+ try harness.start(app);
649
+
650
+ // A track is playing on the platform's player when the quit lands.
651
+ try app_state.dispatch(&harness.runtime, 1, .play);
652
+ try std.testing.expect(app_state.effects.audioSnapshot().active);
653
+ try std.testing.expect(harness.null_platform.audio.playing);
654
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.audio_stop_count);
655
+
656
+ // The platform loop's final event: app_shutdown delivers the stop
657
+ // hook. It silences the player through the LIVE services and severs
658
+ // the channel's binding.
659
+ try harness.stop(app);
660
+ try std.testing.expectEqual(@as(usize, 1), harness.null_platform.audio_stop_count);
661
+ try std.testing.expect(!harness.null_platform.audio.loaded);
662
+ try std.testing.expect(app_state.effects.services == null);
663
+ try std.testing.expect(!app_state.effects.audioSnapshot().active);
664
+
665
+ // The runner's defers: platform host and runtime memory are gone
666
+ // now. (The harness allocation holds both; freeing it makes any
667
+ // late service call a real use-after-free, exactly like main.)
668
+ harness.destroy(std.testing.allocator);
669
+
670
+ // Main's deferred deinit runs last. It must free app-side memory
671
+ // only — no audioStop, no timer cancels, no worker wakes against
672
+ // the dead platform.
673
+ app_state.deinit();
674
+ std.testing.allocator.destroy(app_state);
675
+ }
676
+
677
+ test "a platform straggler after stop is swallowed, never misattributed" {
678
+ var h = try Harness.create();
679
+ defer h.destroy();
680
+ const np = &h.harness.null_platform;
681
+
682
+ try h.app_state.dispatch(&h.harness.runtime, 1, .play);
683
+ const loaded = np.takeAudioLoaded().?;
684
+ try h.app_state.dispatch(&h.harness.runtime, 1, .stop);
685
+ // The loaded event from before the stop arrives late: no Msg, no
686
+ // model change.
687
+ const before = h.app_state.model.event_count;
688
+ try h.harness.runtime.dispatchPlatformEvent(h.app, loaded);
689
+ try std.testing.expectEqual(before, h.app_state.model.event_count);
690
+ }