@native-sdk/cli 0.5.3 → 0.6.0

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 (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -125,6 +125,7 @@ const GpuSurfaceInputEvent = types.GpuSurfaceInputEvent;
125
125
  const GpuSurfacePixels = types.GpuSurfacePixels;
126
126
  const GpuSurfacePacket = types.GpuSurfacePacket;
127
127
  const GpuSurfaceImagePixels = types.GpuSurfaceImagePixels;
128
+ const GpuSurfaceFontData = types.GpuSurfaceFontData;
128
129
  const max_gpu_surface_scroll_drivers = types.max_gpu_surface_scroll_drivers;
129
130
  const GpuSurfaceScrollDriver = types.GpuSurfaceScrollDriver;
130
131
  const max_context_menu_items = types.max_context_menu_items;
@@ -161,6 +162,20 @@ pub const NullGpuSurfaceImage = struct {
161
162
  sample_rgba: [4]u8 = .{ 0, 0, 0, 0 },
162
163
  };
163
164
 
165
+ /// Matches the runtime font registry's slot count
166
+ /// (`canvas_limits.max_registered_canvas_fonts`).
167
+ pub const max_gpu_surface_fonts: usize = 16;
168
+
169
+ /// One mirrored host font registration (see `gpu_surface_fonts`): the
170
+ /// id-keyed record a stateful host retains per registered face, plus the
171
+ /// ownership token the register call reported for it — the shape of the
172
+ /// AppKit host's descriptor-and-token tables, minus the CoreText.
173
+ pub const NullGpuSurfaceFont = struct {
174
+ id: u64 = 0,
175
+ token: u64 = 0,
176
+ byte_len: usize = 0,
177
+ };
178
+
164
179
  pub const NullTimer = struct {
165
180
  id: u64 = 0,
166
181
  interval_ns: u64 = 0,
@@ -194,6 +209,59 @@ pub const max_null_audio_cached_urls: usize = 8;
194
209
  /// (not a local file and not a fake-cache hit) — completing a streamed
195
210
  /// track flips its URL into the fake cache, so the next `audioLoadUrl`
196
211
  /// of the same URL resolves `.cache` deterministically.
212
+ /// Metadata table entries for the fake video player (see
213
+ /// `setVideoMeta`): a loaded source whose tail matches `suffix` reports
214
+ /// `duration_ms` and `width`x`height`. A table instead of real decoding
215
+ /// keeps tests hermetic — no video files, no codecs, still honest
216
+ /// dimensions and durations.
217
+ pub const max_null_video_metas: usize = 8;
218
+
219
+ pub const NullVideoMeta = struct {
220
+ suffix: [128]u8 = undefined,
221
+ suffix_len: usize = 0,
222
+ duration_ms: u64 = 0,
223
+ width: u64 = 0,
224
+ height: u64 = 0,
225
+ };
226
+
227
+ /// Every loaded video source without a table entry reports these.
228
+ pub const default_null_video_duration_ms: u64 = 60_000;
229
+ pub const default_null_video_width: u64 = 640;
230
+ pub const default_null_video_height: u64 = 360;
231
+
232
+ /// The fake video player's whole state: what a deterministic host would
233
+ /// know. Position never advances on its own — tests move it explicitly
234
+ /// with `advanceVideo`, mirroring `advanceAudio`. Frames never decode on
235
+ /// their own either: tests push synthetic RGBA8 through the captured
236
+ /// sink with `pushVideoFrame`, standing in for a real decode callback.
237
+ /// A looping player wraps at the end instead of completing.
238
+ pub const NullVideo = struct {
239
+ loaded: bool = false,
240
+ /// The engine-minted load token this playback echoes in every
241
+ /// event it emits (the real hosts' contract — see
242
+ /// `platform.VideoEvent.token`).
243
+ token: u64 = 0,
244
+ playing: bool = false,
245
+ streaming: bool = false,
246
+ looping: bool = false,
247
+ muted: bool = false,
248
+ position_ms: u64 = 0,
249
+ duration_ms: u64 = 0,
250
+ width: u64 = 0,
251
+ height: u64 = 0,
252
+ volume: f32 = 1.0,
253
+ /// The frame sink the last load handed over — where a real host's
254
+ /// decode callback would push pixels. Kept across pause (a paused
255
+ /// player keeps its claim); cleared by stop.
256
+ sink: types.VideoFrameSink = .{},
257
+ path_storage: [types.max_video_path_bytes]u8 = undefined,
258
+ path_len: usize = 0,
259
+
260
+ pub fn path(self: *const NullVideo) []const u8 {
261
+ return self.path_storage[0..self.path_len];
262
+ }
263
+ };
264
+
197
265
  pub const NullAudio = struct {
198
266
  loaded: bool = false,
199
267
  playing: bool = false,
@@ -265,6 +333,23 @@ pub const NullPlatform = struct {
265
333
  /// the null platform has no Dock to genie into, so the count IS the
266
334
  /// behavior tests pin.
267
335
  window_minimize_count: [max_windows]u32 = [_]u32{0} ** max_windows,
336
+ /// Show calls per window (`show_window_fn`), indexed like `windows`
337
+ /// — the counterpart seam (tray "Open", the un-hide verb).
338
+ window_show_count: [max_windows]u32 = [_]u32{0} ** max_windows,
339
+ /// Graceful-quit requests (`quit_app_fn`). The real hosts QUEUE
340
+ /// the stop onto their run loop (macOS dispatch_async, GTK
341
+ /// g_idle_add, Windows PostQuitMessage) so `app_shutdown` emits
342
+ /// only on the NEXT loop turn, after the dispatch that requested
343
+ /// the quit has returned — a recorded command that quits commits
344
+ /// to the session journal before the shutdown record seals it.
345
+ /// The modeled host mirrors that shape: `quitApp` only records the
346
+ /// request, and `takeQueuedQuit` hands the test the deferred
347
+ /// shutdown event to dispatch as its own loop turn.
348
+ quit_request_count: u32 = 0,
349
+ /// The queued stop `quitApp` armed and `takeQueuedQuit` has not
350
+ /// yet drained — the modeled twin of the hosts' pending idle/queue
351
+ /// entry (exactly-once, like their did-shutdown latches).
352
+ quit_pending: bool = false,
268
353
  /// Modeled occlusion per window, indexed like `windows`: true while
269
354
  /// the modeled window does not reach the glass (minimized, or a
270
355
  /// test covered it via `setWindowOccluded`). Drives the
@@ -277,6 +362,23 @@ pub const NullPlatform = struct {
277
362
  /// Captured `WindowOptions.show` per created window: the
278
363
  /// present-before-show policy that must survive to the create seam.
279
364
  window_show: [max_windows]types.WindowShowMode = [_]types.WindowShowMode{.immediate} ** max_windows,
365
+ /// Captured `WindowOptions.close_policy` per created window — the
366
+ /// seam-regression capture (like `window_resizable`) AND the
367
+ /// modeled behavior: `userCloseWindow` consults it exactly like the
368
+ /// real hosts' close delegates, hiding instead of closing under
369
+ /// `.hide`.
370
+ window_close_policy: [max_windows]types.WindowClosePolicy = [_]types.WindowClosePolicy{.quit} ** max_windows,
371
+ /// Test seam: make the NEXT `close_window_fn` call fail with
372
+ /// `error.CloseFailed` (the real hosts' refusal), consuming the
373
+ /// flag — the injection runtime rollback tests use to assert
374
+ /// `closeWindow` restores every flag it flipped optimistically
375
+ /// (open, focused, hidden).
376
+ fail_next_close_window: bool = false,
377
+ /// Test seam: make the NEXT `show_window_fn` call fail with
378
+ /// `error.ShowFailed`, consuming the flag — the injection the
379
+ /// runtime's `showWindow` rollback test uses to assert a refused
380
+ /// show restores hidden and moves no focus.
381
+ fail_next_show_window: bool = false,
280
382
  /// Captured `WindowOptions.min_width`/`min_height` per created
281
383
  /// window — the content min-size floor that must survive to the
282
384
  /// create seam (macOS applies it as `contentMinSize`); same
@@ -433,6 +535,40 @@ pub const NullPlatform = struct {
433
535
  gpu_surface_image_upload_byte_len: usize = 0,
434
536
  gpu_surface_image_upload_sample_rgba: [4]u8 = .{ 0, 0, 0, 0 },
435
537
  gpu_surface_image_remove_id: u64 = 0,
538
+ /// Host-font mirror for the registration seam, default OFF: the null
539
+ /// platform models a platform without host-side text, whose register
540
+ /// seam is null (engine-side registration is the whole story there,
541
+ /// and the runtime records ownership token 0 — nothing installed).
542
+ /// Tests modelling a stateful host (macOS's per-process descriptor
543
+ /// and token tables) enable this before taking `platform()`: the
544
+ /// mirror then accepts registrations id-keyed and last-wins, mints a
545
+ /// monotonic ownership token per registration exactly like the
546
+ /// AppKit host, and honors the token guard at unregister — so the
547
+ /// shared-id lifecycle (an older runtime's deinit must leave a newer
548
+ /// runtime's re-registration intact) is assertable without CoreText.
549
+ /// Per-instance where the real host tables are per-process: tests
550
+ /// model "one process" by pointing every runtime at ONE instance.
551
+ gpu_surface_font_registrations: bool = false,
552
+ gpu_surface_fonts: [max_gpu_surface_fonts]NullGpuSurfaceFont = [_]NullGpuSurfaceFont{.{}} ** max_gpu_surface_fonts,
553
+ gpu_surface_font_count: usize = 0,
554
+ gpu_surface_font_register_count: usize = 0,
555
+ /// The mirror's monotonic token counter, pre-incremented per
556
+ /// registration so 0 is never a live token — the AppKit host's
557
+ /// counter discipline, which is what makes a stale (or 0) token
558
+ /// provably match nothing.
559
+ gpu_surface_font_token_counter: u64 = 0,
560
+ /// Font-unregister recorder for the host-teardown seam Runtime.deinit
561
+ /// drives. Present even with the mirror off: the null platform then
562
+ /// has no register seam (no host-side text — engine-side registration
563
+ /// is the whole story), but it still accepts and records the teardown
564
+ /// call, so embed tests can pin that deinit returns the host-side
565
+ /// registration on platforms that do retain per-id font state
566
+ /// (macOS's CoreText descriptor and caches). The recorded token is
567
+ /// exactly what the call carried — 0 when the runtime captured no
568
+ /// register-time token, the minted stamp when the mirror is on.
569
+ gpu_surface_font_unregister_count: usize = 0,
570
+ gpu_surface_font_unregister_id: u64 = 0,
571
+ gpu_surface_font_unregister_token: u64 = 0,
436
572
  timers: [max_null_timers]NullTimer = [_]NullTimer{.{}} ** max_null_timers,
437
573
  timer_count: usize = 0,
438
574
  timer_start_count: usize = 0,
@@ -485,11 +621,54 @@ pub const NullPlatform = struct {
485
621
  audio_stop_count: usize = 0,
486
622
  audio_seek_count: usize = 0,
487
623
  audio_volume_count: usize = 0,
624
+ /// Whether this modeled host has a video decoder. On by default (the
625
+ /// fake below stands in for AVFoundation); tests modelling a staged
626
+ /// host (Windows/Linux today) set it false BEFORE `platform()` so
627
+ /// every video service fn is absent, exactly like the real hosts.
628
+ video_playback: bool = true,
629
+ /// Whether the modeled filesystem holds the local video files apps
630
+ /// name in `videoLoad`. On by default; false models the
631
+ /// assets-absent machine: every local load answers
632
+ /// `error.VideoSourceNotFound`, which is what sends the source
633
+ /// cascade to the URL.
634
+ video_local_files: bool = true,
635
+ /// The deterministic fake video player: services mutate it, tests
636
+ /// read it and synthesize the events a live host would deliver
637
+ /// (`takeVideoLoaded`, `advanceVideo`), and push synthetic frames
638
+ /// through its captured sink (`pushVideoFrame`).
639
+ video: NullVideo = .{},
640
+ /// A `.loaded` acknowledgment waiting to be taken — set by a
641
+ /// successful video load, consumed by `takeVideoLoaded`.
642
+ video_loaded_pending: bool = false,
643
+ video_metas: [max_null_video_metas]NullVideoMeta = [_]NullVideoMeta{.{}} ** max_null_video_metas,
644
+ video_meta_count: usize = 0,
645
+ video_load_count: usize = 0,
646
+ video_load_url_count: usize = 0,
647
+ video_play_count: usize = 0,
648
+ video_pause_count: usize = 0,
649
+ video_stop_count: usize = 0,
650
+ video_seek_count: usize = 0,
651
+ video_volume_count: usize = 0,
652
+ video_muted_count: usize = 0,
653
+ video_loop_count: usize = 0,
488
654
  /// Pending cross-thread wake requests. Incremented atomically because
489
655
  /// `wake_fn` is the one service worker threads call; tests and the
490
656
  /// embed host drain it on their own thread via `takeWake` and then
491
657
  /// dispatch the `.wake` platform event themselves.
492
658
  wake_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
659
+ /// Latched when the runtime's effects teardown abandons an in-flight
660
+ /// channel `wake_fn` call (see
661
+ /// `PlatformServices.note_channel_wake_abandoned_fn`): the stale call
662
+ /// still holds this platform as its context, so `deinit` must skip
663
+ /// destruction and leak the host, process-lived — the reference model
664
+ /// of the real hosts' destroy gate, and the seam channel teardown
665
+ /// tests observe.
666
+ channel_wake_abandoned: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
667
+ /// Whether `deinit` actually ran its destruction (the null platform
668
+ /// holds no OS resources, so "destruction" is this flag): stays false
669
+ /// when `channel_wake_abandoned` forced the deliberate leak. The
670
+ /// observation seam the abandon tests assert against.
671
+ destroyed: bool = false,
493
672
  /// Pending cross-thread frame requests (`request_frame_fn`), counted
494
673
  /// atomically like `wake_count`: the automation arrival watcher calls
495
674
  /// it from its own thread, and a scripted run loop (or test) drains
@@ -509,9 +688,12 @@ pub const NullPlatform = struct {
509
688
  scroll_driver_label_len: usize = 0,
510
689
  scroll_drivers: [max_gpu_surface_scroll_drivers]GpuSurfaceScrollDriver = undefined,
511
690
  scroll_driver_count: usize = 0,
691
+ scroll_occluders: [types.max_gpu_surface_scroll_occluders]types.GpuSurfaceScrollOccluder = undefined,
692
+ scroll_occluder_count: usize = 0,
512
693
  scroll_driver_set_count: usize = 0,
513
- /// Lifetime count of driver entries pushed with `set_offset = true`
514
- /// (the runtime forcing its offset into the native scroller).
694
+ /// Lifetime count of driver entries pushed with a set-offset flag
695
+ /// on EITHER axis (the runtime forcing an offset into the native
696
+ /// scroller).
515
697
  scroll_driver_set_offset_count: usize = 0,
516
698
  /// Whether this modeled host presents native context menus. On by
517
699
  /// default (the recorder below stands in for the OS menu); tests
@@ -519,6 +701,11 @@ pub const NullPlatform = struct {
519
701
  /// path) set it false, which nulls the service AND the feature
520
702
  /// report — the same shape as a real host without a presenter.
521
703
  context_menus: bool = true,
704
+ /// Whether this modeled host can hide-on-close and re-show (the
705
+ /// `close_policy = .hide` shape). On by default, modeling
706
+ /// macOS/Windows; tests modeling a host without the affordance
707
+ /// (GTK) set it false and pin the runtime's create-time refusal.
708
+ window_hide_on_close: bool = true,
522
709
  /// Native context-menu recorder: presentations record the request and
523
710
  /// return; tests then feed the selection back as a
524
711
  /// `.context_menu_action` platform event.
@@ -545,6 +732,53 @@ pub const NullPlatform = struct {
545
732
  return .{ .surface_value = surface_value, .web_engine = web_engine, .app_info = app_info };
546
733
  }
547
734
 
735
+ /// Heap-allocate the wrapper (process allocator) and initialize it
736
+ /// in place — the reference model of the real hosts'
737
+ /// `createWithOptions`. Runners must use this over a stack
738
+ /// `initWithOptions` value: `platform().services.context` is this
739
+ /// wrapper's ADDRESS, worker threads dereference it inside the
740
+ /// channel wake path (the null wake counts into `wake_count`, a
741
+ /// wrapper field), and a wake call teardown abandons may do so at
742
+ /// any later time — after a runner's stack frame would have
743
+ /// unwound. Pair with `destroy`, the latch-gated free. Tests that
744
+ /// own the wrapper's lifetime themselves keep using the stack
745
+ /// initializers.
746
+ pub fn createWithOptions(surface_value: Surface, web_engine: WebEngine, app_info: AppInfo) std.mem.Allocator.Error!*NullPlatform {
747
+ const self = try std.heap.page_allocator.create(NullPlatform);
748
+ self.* = initWithOptions(surface_value, web_engine, app_info);
749
+ return self;
750
+ }
751
+
752
+ /// `deinit` plus the wrapper's own storage, gated by the same
753
+ /// latch: an abandoned channel wake call dereferences this wrapper
754
+ /// (its context) the moment it resumes, so on abandon the storage
755
+ /// is leaked, process-lived — deinit-gating extended to
756
+ /// lifetime-gating, the reference model of the real hosts'
757
+ /// `destroy`. No cross-thread race on the gate: the latch is set
758
+ /// synchronously on the loop thread during effects teardown, which
759
+ /// runs before the runner's deferred destroy.
760
+ pub fn destroy(self: *NullPlatform) void {
761
+ self.deinit();
762
+ if (self.channel_wake_abandoned.load(.seq_cst)) return;
763
+ std.heap.page_allocator.destroy(self);
764
+ }
765
+
766
+ /// The reference model of the real hosts' destroy gate (`MacPlatform`
767
+ /// / `LinuxPlatform` / `WindowsPlatform` `deinit`): destruction is
768
+ /// SKIPPED — the platform deliberately leaked, process-lived, with
769
+ /// one loud line — while an abandoned channel wake call may still
770
+ /// enter this host (see `channel_wake_abandoned`); otherwise the
771
+ /// `destroyed` flag records that destruction ran. The null platform
772
+ /// holds no OS resources, so the flag is the whole destruction —
773
+ /// which is exactly what makes the gate observable in tests.
774
+ pub fn deinit(self: *NullPlatform) void {
775
+ if (self.channel_wake_abandoned.load(.seq_cst)) {
776
+ std.debug.print("null platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it, process-lived, so the stale call stays safe\n", .{});
777
+ return;
778
+ }
779
+ self.destroyed = true;
780
+ }
781
+
548
782
  pub fn platform(self: *NullPlatform) Platform {
549
783
  return .{
550
784
  .context = self,
@@ -567,6 +801,8 @@ pub const NullPlatform = struct {
567
801
  .focus_window_fn = focusWindow,
568
802
  .close_window_fn = closeWindow,
569
803
  .minimize_window_fn = minimizeWindow,
804
+ .show_window_fn = showWindow,
805
+ .quit_app_fn = quitApp,
570
806
  .start_window_drag_fn = startWindowDrag,
571
807
  .window_chrome_fn = windowChrome,
572
808
  .set_window_drag_regions_fn = setWindowDragRegions,
@@ -611,7 +847,17 @@ pub const NullPlatform = struct {
611
847
  .audio_stop_fn = if (self.audio_playback) audioStop else null,
612
848
  .audio_seek_fn = if (self.audio_playback) audioSeek else null,
613
849
  .audio_set_volume_fn = if (self.audio_playback) audioSetVolume else null,
850
+ .video_load_fn = if (self.video_playback) videoLoad else null,
851
+ .video_load_url_fn = if (self.video_playback) videoLoadUrl else null,
852
+ .video_play_fn = if (self.video_playback) videoPlay else null,
853
+ .video_pause_fn = if (self.video_playback) videoPause else null,
854
+ .video_stop_fn = if (self.video_playback) videoStop else null,
855
+ .video_seek_fn = if (self.video_playback) videoSeek else null,
856
+ .video_set_volume_fn = if (self.video_playback) videoSetVolume else null,
857
+ .video_set_muted_fn = if (self.video_playback) videoSetMuted else null,
858
+ .video_set_loop_fn = if (self.video_playback) videoSetLoop else null,
614
859
  .wake_fn = wakeService,
860
+ .note_channel_wake_abandoned_fn = noteChannelWakeAbandoned,
615
861
  .request_frame_fn = requestFrameService,
616
862
  .request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
617
863
  .present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
@@ -619,6 +865,8 @@ pub const NullPlatform = struct {
619
865
  .present_gpu_surface_packet_binary_fn = presentGpuSurfacePacketBinary,
620
866
  .upload_gpu_surface_image_fn = uploadGpuSurfaceImage,
621
867
  .remove_gpu_surface_image_fn = removeGpuSurfaceImage,
868
+ .register_gpu_surface_font_fn = if (self.gpu_surface_font_registrations) registerGpuSurfaceFont else null,
869
+ .unregister_gpu_surface_font_fn = unregisterGpuSurfaceFont,
622
870
  .decode_image_fn = decodeImage,
623
871
  .set_gpu_surface_scroll_drivers_fn = setGpuSurfaceScrollDrivers,
624
872
  .show_context_menu_fn = if (self.context_menus) showContextMenu else null,
@@ -655,9 +903,15 @@ pub const NullPlatform = struct {
655
903
  // app-owned platform view into — reporting support would be a
656
904
  // lie the first adopt call exposes.
657
905
  .view_surface_adoption => false,
906
+ // Models the macOS/Windows hosts by default: user closes
907
+ // honor the captured close policy and hidden windows
908
+ // re-show, so the runtime suites can pin the whole
909
+ // menu-bar-app loop. Tests flip it false to model GTK.
910
+ .window_hide_on_close => self.window_hide_on_close,
658
911
  .audio_playback => self.audio_playback,
659
912
  .audio_streaming => self.audio_playback and self.audio_streaming,
660
913
  .audio_spectrum => self.audio_playback and self.audio_spectrum,
914
+ .video_playback => self.video_playback,
661
915
  };
662
916
  }
663
917
 
@@ -796,6 +1050,7 @@ pub const NullPlatform = struct {
796
1050
  self.window_resizable[self.window_count] = options.resizable;
797
1051
  self.window_titlebar[self.window_count] = options.titlebar;
798
1052
  self.window_show[self.window_count] = options.show;
1053
+ self.window_close_policy[self.window_count] = options.close_policy;
799
1054
  self.window_min_width[self.window_count] = options.min_width;
800
1055
  self.window_min_height[self.window_count] = options.min_height;
801
1056
  self.window_first_present_seq[self.window_count] = 0;
@@ -877,9 +1132,19 @@ pub const NullPlatform = struct {
877
1132
 
878
1133
  fn closeWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
879
1134
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1135
+ if (self.fail_next_close_window) {
1136
+ self.fail_next_close_window = false;
1137
+ return error.CloseFailed;
1138
+ }
880
1139
  const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
881
1140
  self.windows[index].open = false;
882
1141
  self.windows[index].focused = false;
1142
+ // hidden clears WITH open, mirroring the real hosts' close
1143
+ // paths (every macOS close exit leaves the policy-hidden set
1144
+ // before its emit) and the runtime table's own close flip: a
1145
+ // closed window is not "hidden", it is gone — a stale
1146
+ // hidden=true here is exactly what lets a reopen resurrect it.
1147
+ self.windows[index].hidden = false;
883
1148
  self.removeViewsForWindow(window_id);
884
1149
  self.removeWebViewsForWindow(window_id);
885
1150
  }
@@ -897,6 +1162,54 @@ pub const NullPlatform = struct {
897
1162
  self.window_occluded[index] = true;
898
1163
  }
899
1164
 
1165
+ fn showWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
1166
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1167
+ if (self.fail_next_show_window) {
1168
+ self.fail_next_show_window = false;
1169
+ return error.ShowFailed;
1170
+ }
1171
+ const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
1172
+ // The un-hide verb: back on the glass with focus, exactly the
1173
+ // real hosts' deminiaturize + order-front + activate. Clears a
1174
+ // policy-hide, a minimize's occlusion, and a still-deferred
1175
+ // present-before-show alike.
1176
+ self.windows[index].hidden = false;
1177
+ self.window_occluded[index] = false;
1178
+ for (self.windows[0..self.window_count], 0..) |*window, cursor| {
1179
+ window.focused = cursor == index;
1180
+ }
1181
+ if (!self.window_visible[index]) {
1182
+ self.window_visible[index] = true;
1183
+ self.show_op_seq += 1;
1184
+ self.window_shown_seq[index] = self.show_op_seq;
1185
+ }
1186
+ self.window_show_count[index] += 1;
1187
+ }
1188
+
1189
+ fn quitApp(context: ?*anyopaque) anyerror!void {
1190
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1191
+ self.quit_request_count += 1;
1192
+ self.quit_pending = true;
1193
+ }
1194
+
1195
+ /// Test seam: drain the stop the quit verb queued — the modeled
1196
+ /// host echo, and the modeled NEXT LOOP TURN. Real hosts defer the
1197
+ /// shutdown emit past the dispatch that requested it (see
1198
+ /// `quit_request_count`); a test models that by dispatching the
1199
+ /// returned event only after the quitting dispatch has returned,
1200
+ /// exactly the `userCloseWindow` shape. The PRE-RUN quit rides the
1201
+ /// same model: a quit requested before the hosts' run loop exists
1202
+ /// (App.start's update, a boot command in the synchronous first
1203
+ /// canvas frame) parks on the host and drains at top level after
1204
+ /// the boot dispatch returns — arm here, drain here, identically.
1205
+ /// Answers exactly once per armed quit; null while nothing is
1206
+ /// queued.
1207
+ pub fn takeQueuedQuit(self: *NullPlatform) ?Event {
1208
+ if (!self.quit_pending) return null;
1209
+ self.quit_pending = false;
1210
+ return .app_shutdown;
1211
+ }
1212
+
900
1213
  fn createView(context: ?*anyopaque, options: ViewOptions) anyerror!void {
901
1214
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
902
1215
  if (options.kind == .webview) return createWebView(context, options.webViewOptions());
@@ -1495,11 +1808,245 @@ pub const NullPlatform = struct {
1495
1808
  return .{ .audio = .{ .kind = .failed } };
1496
1809
  }
1497
1810
 
1811
+ fn videoLoad(context: ?*anyopaque, path: []const u8, token: u64, sink: types.VideoFrameSink) anyerror!void {
1812
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1813
+ self.video_load_count += 1;
1814
+ // Retire the previous player FIRST — the macOS host's ordering
1815
+ // (videoStop before the file probe): a load that then refuses
1816
+ // must not leave the replaced playback emitting frames and
1817
+ // events under its old token.
1818
+ const volume = self.video.volume;
1819
+ self.video = .{ .volume = volume };
1820
+ self.video_loaded_pending = false;
1821
+ if (path.len > self.video.path_storage.len) return error.VideoPathTooLarge;
1822
+ // Model the assets-absent machine: the local file is not there,
1823
+ // exactly the synchronous refusal a real host's open gives.
1824
+ if (!self.video_local_files) return error.VideoSourceNotFound;
1825
+ self.video = .{ .volume = volume, .sink = sink, .token = token };
1826
+ @memcpy(self.video.path_storage[0..path.len], path);
1827
+ self.video.path_len = path.len;
1828
+ self.video.loaded = true;
1829
+ self.applyVideoMeta(path);
1830
+ self.video_loaded_pending = true;
1831
+ }
1832
+
1833
+ fn videoLoadUrl(context: ?*anyopaque, url: []const u8, token: u64, sink: types.VideoFrameSink) anyerror!void {
1834
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1835
+ self.video_load_url_count += 1;
1836
+ // Retire-first, `videoLoad`'s ordering.
1837
+ const volume = self.video.volume;
1838
+ self.video = .{ .volume = volume };
1839
+ self.video_loaded_pending = false;
1840
+ if (url.len > self.video.path_storage.len) return error.VideoPathTooLarge;
1841
+ self.video = .{ .volume = volume, .sink = sink, .token = token };
1842
+ @memcpy(self.video.path_storage[0..url.len], url);
1843
+ self.video.path_len = url.len;
1844
+ self.video.loaded = true;
1845
+ self.video.streaming = true;
1846
+ self.applyVideoMeta(url);
1847
+ self.video_loaded_pending = true;
1848
+ }
1849
+
1850
+ fn videoPlay(context: ?*anyopaque) anyerror!void {
1851
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1852
+ self.video_play_count += 1;
1853
+ if (!self.video.loaded) return error.InvalidVideoOptions;
1854
+ self.video.playing = true;
1855
+ }
1856
+
1857
+ fn videoPause(context: ?*anyopaque) anyerror!void {
1858
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1859
+ self.video_pause_count += 1;
1860
+ self.video.playing = false;
1861
+ }
1862
+
1863
+ fn videoStop(context: ?*anyopaque) anyerror!void {
1864
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1865
+ self.video_stop_count += 1;
1866
+ self.video = .{ .volume = self.video.volume };
1867
+ self.video_loaded_pending = false;
1868
+ }
1869
+
1870
+ fn videoSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
1871
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1872
+ self.video_seek_count += 1;
1873
+ if (!self.video.loaded) return error.InvalidVideoOptions;
1874
+ self.video.position_ms = @min(position_ms, self.video.duration_ms);
1875
+ }
1876
+
1877
+ fn videoSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1878
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1879
+ self.video_volume_count += 1;
1880
+ self.video.volume = volume;
1881
+ }
1882
+
1883
+ fn videoSetMuted(context: ?*anyopaque, muted: bool) anyerror!void {
1884
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1885
+ self.video_muted_count += 1;
1886
+ self.video.muted = muted;
1887
+ }
1888
+
1889
+ fn videoSetLoop(context: ?*anyopaque, loop: bool) anyerror!void {
1890
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1891
+ self.video_loop_count += 1;
1892
+ self.video.looping = loop;
1893
+ }
1894
+
1895
+ fn applyVideoMeta(self: *NullPlatform, source: []const u8) void {
1896
+ for (self.video_metas[0..self.video_meta_count]) |entry| {
1897
+ const suffix = entry.suffix[0..entry.suffix_len];
1898
+ if (suffix.len <= source.len and std.mem.eql(u8, source[source.len - suffix.len ..], suffix)) {
1899
+ self.video.duration_ms = entry.duration_ms;
1900
+ self.video.width = entry.width;
1901
+ self.video.height = entry.height;
1902
+ return;
1903
+ }
1904
+ }
1905
+ self.video.duration_ms = default_null_video_duration_ms;
1906
+ self.video.width = default_null_video_width;
1907
+ self.video.height = default_null_video_height;
1908
+ }
1909
+
1910
+ /// Test helper: register duration and dimensions for any loaded
1911
+ /// video source ending in `suffix`. Sources without a match report
1912
+ /// the `default_null_video_*` values.
1913
+ pub fn setVideoMeta(self: *NullPlatform, suffix: []const u8, duration_ms: u64, width: u64, height: u64) !void {
1914
+ if (suffix.len == 0 or suffix.len > 128) return error.InvalidVideoOptions;
1915
+ if (self.video_meta_count >= max_null_video_metas) return error.InvalidVideoOptions;
1916
+ var entry = &self.video_metas[self.video_meta_count];
1917
+ @memcpy(entry.suffix[0..suffix.len], suffix);
1918
+ entry.suffix_len = suffix.len;
1919
+ entry.duration_ms = duration_ms;
1920
+ entry.width = width;
1921
+ entry.height = height;
1922
+ self.video_meta_count += 1;
1923
+ }
1924
+
1925
+ /// Consume the pending video `.loaded` acknowledgment — the platform
1926
+ /// event a live host delivers after a successful load, carrying the
1927
+ /// stream's dimensions and the player's duration readout. Dispatch
1928
+ /// it through the runtime, like `takeAudioLoaded`.
1929
+ pub fn takeVideoLoaded(self: *NullPlatform) ?Event {
1930
+ if (!self.video_loaded_pending) return null;
1931
+ self.video_loaded_pending = false;
1932
+ return .{ .video = .{
1933
+ .kind = .loaded,
1934
+ .token = self.video.token,
1935
+ .position_ms = self.video.position_ms,
1936
+ .duration_ms = self.video.duration_ms,
1937
+ .playing = self.video.playing,
1938
+ .width = self.video.width,
1939
+ .height = self.video.height,
1940
+ } };
1941
+ }
1942
+
1943
+ /// Test helper: advance fake playback by `delta_ms` and synthesize
1944
+ /// the event a live host's position timer would deliver — a
1945
+ /// `.position` tick, or `.completed` when a non-looping video
1946
+ /// reaches its end. A non-looping completion unloads the player
1947
+ /// (retire-before-emit, the live hosts' teardown): a later
1948
+ /// `videoPlay`/`videoSeek` refuses exactly as it would against a
1949
+ /// torn-down AVPlayer, and no second completion can ever emit. A
1950
+ /// LOOPING player wraps past the end and keeps ticking: no
1951
+ /// completion, because the playback never ends. Returns null when
1952
+ /// nothing is loaded or playing; position never advances on its own.
1953
+ pub fn advanceVideo(self: *NullPlatform, delta_ms: u64) ?Event {
1954
+ if (!self.video.loaded or !self.video.playing) return null;
1955
+ // Widened, not saturated: a hostile or fuzzing advance past
1956
+ // u64 completes (or wraps EXACTLY, for a looping player)
1957
+ // instead of trapping — saturating before the loop modulo
1958
+ // would land the wrapped position on the wrong residue.
1959
+ const advanced = @as(u128, self.video.position_ms) + delta_ms;
1960
+ if (advanced >= self.video.duration_ms and self.video.duration_ms > 0) {
1961
+ if (self.video.looping) {
1962
+ self.video.position_ms = @intCast(advanced % self.video.duration_ms);
1963
+ return .{ .video = .{
1964
+ .kind = .position,
1965
+ .token = self.video.token,
1966
+ .position_ms = self.video.position_ms,
1967
+ .duration_ms = self.video.duration_ms,
1968
+ .playing = true,
1969
+ } };
1970
+ }
1971
+ const token = self.video.token;
1972
+ const duration_ms = self.video.duration_ms;
1973
+ self.video = .{ .volume = self.video.volume };
1974
+ self.video_loaded_pending = false;
1975
+ return .{ .video = .{
1976
+ .kind = .completed,
1977
+ .token = token,
1978
+ .position_ms = duration_ms,
1979
+ .duration_ms = duration_ms,
1980
+ .playing = false,
1981
+ } };
1982
+ }
1983
+ // Below the duration, so it fits u64 again by construction —
1984
+ // except under a zero duration (no end to reach), where the
1985
+ // readout saturates like a real clock display would.
1986
+ self.video.position_ms = if (advanced > std.math.maxInt(u64))
1987
+ std.math.maxInt(u64)
1988
+ else
1989
+ @intCast(advanced);
1990
+ return .{ .video = .{
1991
+ .kind = .position,
1992
+ .token = self.video.token,
1993
+ .position_ms = self.video.position_ms,
1994
+ .duration_ms = self.video.duration_ms,
1995
+ .playing = true,
1996
+ } };
1997
+ }
1998
+
1999
+ /// Test helper: synthesize a mid-stream stall — the `.position`
2000
+ /// event a live host's tick delivers while the stream waits for
2001
+ /// network bytes. Only a streaming playback can stall; local files
2002
+ /// never buffer, so anything else answers null.
2003
+ pub fn stallVideo(self: *NullPlatform) ?Event {
2004
+ if (!self.video.loaded or !self.video.playing or !self.video.streaming) return null;
2005
+ return .{ .video = .{
2006
+ .kind = .position,
2007
+ .token = self.video.token,
2008
+ .position_ms = self.video.position_ms,
2009
+ .duration_ms = self.video.duration_ms,
2010
+ .playing = true,
2011
+ .buffering = true,
2012
+ } };
2013
+ }
2014
+
2015
+ /// Test helper: synthesize an asynchronous decode/device failure,
2016
+ /// the `.failed` event a live host would deliver. Unloads the
2017
+ /// player like a real failure would.
2018
+ pub fn failVideo(self: *NullPlatform) ?Event {
2019
+ if (!self.video.loaded) return null;
2020
+ const token = self.video.token;
2021
+ self.video = .{ .volume = self.video.volume };
2022
+ self.video_loaded_pending = false;
2023
+ return .{ .video = .{ .kind = .failed, .token = token } };
2024
+ }
2025
+
2026
+ /// Test helper: push one synthetic RGBA8 frame through the sink the
2027
+ /// last load captured — the deterministic stand-in for a real
2028
+ /// host's decode callback delivering a converted CVPixelBuffer.
2029
+ /// Errors surface exactly as a real producer push would
2030
+ /// (`error.MediaSurfaceReleased` after the claim ended,
2031
+ /// `error.InvalidVideoOptions` when nothing is loaded).
2032
+ pub fn pushVideoFrame(self: *NullPlatform, width: usize, height: usize, rgba8: []const u8) anyerror!void {
2033
+ if (!self.video.loaded) return error.InvalidVideoOptions;
2034
+ return self.video.sink.push(width, height, rgba8);
2035
+ }
2036
+
1498
2037
  fn wakeService(context: ?*anyopaque) anyerror!void {
1499
2038
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1500
2039
  _ = self.wake_count.fetchAdd(1, .release);
1501
2040
  }
1502
2041
 
2042
+ /// Teardown abandoned an in-flight channel wake call: latch the
2043
+ /// flag `deinit` consults so this host is leaked rather than
2044
+ /// destroyed (see `channel_wake_abandoned`).
2045
+ fn noteChannelWakeAbandoned(context: ?*anyopaque) void {
2046
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
2047
+ self.channel_wake_abandoned.store(true, .seq_cst);
2048
+ }
2049
+
1503
2050
  fn requestFrameService(context: ?*anyopaque) anyerror!void {
1504
2051
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1505
2052
  _ = self.frame_request_count.fetchAdd(1, .release);
@@ -1761,6 +2308,69 @@ pub const NullPlatform = struct {
1761
2308
  self.gpu_surface_image_count = last;
1762
2309
  }
1763
2310
 
2311
+ /// The host-font mirror's register half (installed only when
2312
+ /// `gpu_surface_font_registrations` is on — see that flag): id-keyed
2313
+ /// and last-wins like the AppKit host's descriptor table, minting a
2314
+ /// pre-incremented monotonic ownership token per registration and
2315
+ /// returning it, so tests can assert the token lifecycle the real
2316
+ /// host runs.
2317
+ fn registerGpuSurfaceFont(context: ?*anyopaque, font: GpuSurfaceFontData) anyerror!u64 {
2318
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
2319
+ self.gpu_surface_font_register_count += 1;
2320
+ self.gpu_surface_font_token_counter += 1;
2321
+ const token = self.gpu_surface_font_token_counter;
2322
+ const index = self.findGpuSurfaceFontIndex(font.id) orelse blk: {
2323
+ if (self.gpu_surface_font_count >= max_gpu_surface_fonts) return error.InvalidGpuSurfaceFont;
2324
+ const index = self.gpu_surface_font_count;
2325
+ self.gpu_surface_font_count += 1;
2326
+ break :blk index;
2327
+ };
2328
+ self.gpu_surface_fonts[index] = .{
2329
+ .id = font.id,
2330
+ .token = token,
2331
+ .byte_len = font.ttf.len,
2332
+ };
2333
+ return token;
2334
+ }
2335
+
2336
+ /// Records every teardown call (see the recorder fields; unlike the
2337
+ /// image seam this one is not gated on `gpu_surfaces` — Runtime.deinit
2338
+ /// unregisters every registered font regardless of what the surface
2339
+ /// renders through), then applies the mirror's token guard: the id's
2340
+ /// entry comes out only while it still carries `token`, so a stale
2341
+ /// owner (the id was re-registered since, last wins) removes nothing
2342
+ /// — the guard an id-keyed removal would violate by letting an older
2343
+ /// runtime's deinit delete a newer runtime's live registration. With
2344
+ /// the mirror off the table is empty and this is the recording no-op
2345
+ /// it always was: there is no host font state to drop.
2346
+ fn unregisterGpuSurfaceFont(context: ?*anyopaque, id: u64, token: u64) anyerror!void {
2347
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
2348
+ self.gpu_surface_font_unregister_id = id;
2349
+ self.gpu_surface_font_unregister_token = token;
2350
+ self.gpu_surface_font_unregister_count += 1;
2351
+ const index = self.findGpuSurfaceFontIndex(id) orelse return;
2352
+ if (self.gpu_surface_fonts[index].token != token) return;
2353
+ const last = self.gpu_surface_font_count - 1;
2354
+ if (index != last) self.gpu_surface_fonts[index] = self.gpu_surface_fonts[last];
2355
+ self.gpu_surface_fonts[last] = .{};
2356
+ self.gpu_surface_font_count = last;
2357
+ }
2358
+
2359
+ /// The mirrored host font registration for `id`, or null when the id
2360
+ /// holds none (never registered, or returned at teardown) — what a
2361
+ /// stateful host would resolve measurement and drawing through.
2362
+ pub fn gpuSurfaceFont(self: *const NullPlatform, id: u64) ?NullGpuSurfaceFont {
2363
+ const index = self.findGpuSurfaceFontIndex(id) orelse return null;
2364
+ return self.gpu_surface_fonts[index];
2365
+ }
2366
+
2367
+ fn findGpuSurfaceFontIndex(self: *const NullPlatform, id: u64) ?usize {
2368
+ for (self.gpu_surface_fonts[0..self.gpu_surface_font_count], 0..) |font, index| {
2369
+ if (font.id == id) return index;
2370
+ }
2371
+ return null;
2372
+ }
2373
+
1764
2374
  /// The recorded side-channel entry for `id`, or null when the id was
1765
2375
  /// never uploaded (or has been removed) — the store a packet host
1766
2376
  /// would consult on an upload cache action.
@@ -1851,13 +2461,34 @@ pub const NullPlatform = struct {
1851
2461
  self.view_count -= 1;
1852
2462
  }
1853
2463
 
1854
- /// Test seam: the USER closed a window. Real hosts' window
1855
- /// delegates tear the native window out of their records before
1856
- /// emitting the open=false frame event (macOS `windowWillClose`),
1857
- /// so the fake host mirrors that — remove the window and its views
1858
- /// here, then dispatch the returned event through the runtime.
2464
+ /// Test seam: the USER closed a window. Under the default `.quit`
2465
+ /// policy this models the real hosts' window delegates, which tear
2466
+ /// the native window out of their records before emitting the
2467
+ /// open=false frame event (macOS `windowWillClose`) — remove the
2468
+ /// window and its views here, then dispatch the returned event
2469
+ /// through the runtime. Under `close_policy = .hide` it models the
2470
+ /// intercepting delegate instead (macOS `windowShouldClose`
2471
+ /// answering NO + `orderOut`, Win32 `WM_CLOSE` answering with
2472
+ /// `SW_HIDE`): the window and its views stay, only the glass loses
2473
+ /// it, and the returned frame event carries open=true hidden=true.
1859
2474
  pub fn userCloseWindow(self: *NullPlatform, window_id: WindowId) ?Event {
1860
2475
  const index = self.findWindowIndex(window_id) orelse return null;
2476
+ if (self.window_close_policy[index] == .hide) {
2477
+ self.windows[index].hidden = true;
2478
+ self.windows[index].focused = false;
2479
+ self.window_occluded[index] = true;
2480
+ const info = self.windows[index];
2481
+ return .{ .window_frame_changed = .{
2482
+ .id = info.id,
2483
+ .label = info.label,
2484
+ .title = info.title,
2485
+ .frame = info.frame,
2486
+ .scale_factor = info.scale_factor,
2487
+ .open = true,
2488
+ .focused = false,
2489
+ .hidden = true,
2490
+ } };
2491
+ }
1861
2492
  const info = self.windows[index];
1862
2493
  self.removeViewsForWindow(window_id);
1863
2494
  self.removeWebViewsForWindow(window_id);
@@ -1873,6 +2504,50 @@ pub const NullPlatform = struct {
1873
2504
  } };
1874
2505
  }
1875
2506
 
2507
+ /// Test seam: the user asked the app to come back with no window on
2508
+ /// the glass (the macOS Dock-icon reopen). Models the host's
2509
+ /// `applicationShouldHandleReopen:` — every window hidden by its
2510
+ /// `.hide` close policy re-shows — and returns one frame event per
2511
+ /// re-shown window (dispatch them through the runtime like any
2512
+ /// platform event). Windows hidden some other way (minimized,
2513
+ /// occluded) are the OS's to restore, exactly like the real host.
2514
+ pub fn userReopenApp(self: *NullPlatform, output: []Event) []const Event {
2515
+ var count: usize = 0;
2516
+ for (self.windows[0..self.window_count], 0..) |*window, index| {
2517
+ if (!window.hidden) continue;
2518
+ // Liveness, not just the hidden flag: a closed window keeps
2519
+ // its slot in this mirror, and the reopen must never
2520
+ // resurrect one — even if a close path left the hidden flag
2521
+ // stale, re-showing a window the app closed (hidden=false,
2522
+ // focused=true, a frame event) is the exact bug the real
2523
+ // hosts' set hygiene prevents.
2524
+ if (!window.open) continue;
2525
+ if (count >= output.len) break;
2526
+ window.hidden = false;
2527
+ window.focused = count == 0;
2528
+ self.window_occluded[index] = false;
2529
+ output[count] = .{ .window_frame_changed = .{
2530
+ .id = window.id,
2531
+ .label = window.label,
2532
+ .title = window.title,
2533
+ .frame = window.frame,
2534
+ .scale_factor = window.scale_factor,
2535
+ .open = true,
2536
+ .focused = window.focused,
2537
+ .hidden = false,
2538
+ } };
2539
+ count += 1;
2540
+ }
2541
+ return output[0..count];
2542
+ }
2543
+
2544
+ /// Test seam: the captured close policy for a created window (the
2545
+ /// create-seam regression observable, like `window_titlebar`).
2546
+ pub fn closePolicyForWindow(self: *const NullPlatform, window_id: WindowId) ?types.WindowClosePolicy {
2547
+ const index = self.findWindowIndex(window_id) orelse return null;
2548
+ return self.window_close_policy[index];
2549
+ }
2550
+
1876
2551
  /// Test seam: minimize calls observed for a window (the null host
1877
2552
  /// has no Dock, so the count is the pinned behavior).
1878
2553
  pub fn minimizeCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
@@ -1880,6 +2555,13 @@ pub const NullPlatform = struct {
1880
2555
  return self.window_minimize_count[index];
1881
2556
  }
1882
2557
 
2558
+ /// Test seam: show calls observed for a window (the un-hide verb's
2559
+ /// pinned observable, like `minimizeCountForWindow`).
2560
+ pub fn showCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
2561
+ const index = self.findWindowIndex(window_id) orelse return 0;
2562
+ return self.window_show_count[index];
2563
+ }
2564
+
1883
2565
  /// Test seam: model a window leaving or returning to the glass
1884
2566
  /// without a minimize verb (fully covered by another app, revealed
1885
2567
  /// again) — the occlusion fact the real hosts' spectrum gating
@@ -1912,7 +2594,9 @@ pub const NullPlatform = struct {
1912
2594
  self.window_min_width[cursor] = self.window_min_width[cursor + 1];
1913
2595
  self.window_min_height[cursor] = self.window_min_height[cursor + 1];
1914
2596
  self.window_minimize_count[cursor] = self.window_minimize_count[cursor + 1];
2597
+ self.window_show_count[cursor] = self.window_show_count[cursor + 1];
1915
2598
  self.window_occluded[cursor] = self.window_occluded[cursor + 1];
2599
+ self.window_close_policy[cursor] = self.window_close_policy[cursor + 1];
1916
2600
  }
1917
2601
  self.window_count -= 1;
1918
2602
  }
@@ -2113,7 +2797,7 @@ pub const NullPlatform = struct {
2113
2797
  return self.menus[0..self.menu_count];
2114
2798
  }
2115
2799
 
2116
- fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void {
2800
+ fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver, occluders: []const types.GpuSurfaceScrollOccluder) anyerror!void {
2117
2801
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
2118
2802
  if (!self.gpu_surface_scroll_drivers) return error.UnsupportedService;
2119
2803
  self.scroll_driver_set_count += 1;
@@ -2123,8 +2807,11 @@ pub const NullPlatform = struct {
2123
2807
  const count = @min(drivers.len, self.scroll_drivers.len);
2124
2808
  @memcpy(self.scroll_drivers[0..count], drivers[0..count]);
2125
2809
  self.scroll_driver_count = count;
2810
+ const occluder_count = @min(occluders.len, self.scroll_occluders.len);
2811
+ @memcpy(self.scroll_occluders[0..occluder_count], occluders[0..occluder_count]);
2812
+ self.scroll_occluder_count = occluder_count;
2126
2813
  for (drivers) |driver| {
2127
- if (driver.set_offset) self.scroll_driver_set_offset_count += 1;
2814
+ if (driver.set_offset_x or driver.set_offset_y) self.scroll_driver_set_offset_count += 1;
2128
2815
  }
2129
2816
  }
2130
2817