@native-sdk/cli 0.5.3 → 0.5.4

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 (79) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +223 -3
  3. package/native-sdk.d.ts +17 -1
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/rt/rt.zig +138 -3
  8. package/packages/core/sdk/core.ts +225 -3
  9. package/packages/core/src/emitter.ts +2586 -259
  10. package/skill-data/native-ui/SKILL.md +3 -2
  11. package/skill-data/ts-core/SKILL.md +9 -1
  12. package/src/app_runner/root.zig +81 -1
  13. package/src/app_runner/ts_core_main.zig +4 -0
  14. package/src/embed/tests.zig +119 -1
  15. package/src/platform/linux/gtk_host.c +112 -3
  16. package/src/platform/linux/root.zig +71 -0
  17. package/src/platform/macos/appkit_host.h +48 -2
  18. package/src/platform/macos/appkit_host.m +533 -34
  19. package/src/platform/macos/cef_host.mm +262 -10
  20. package/src/platform/macos/root.zig +92 -4
  21. package/src/platform/null_platform.zig +298 -5
  22. package/src/platform/root.zig +33 -0
  23. package/src/platform/types.zig +138 -4
  24. package/src/platform/windows/root.zig +134 -0
  25. package/src/platform/windows/webview2_host.cpp +152 -40
  26. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  27. package/src/primitives/app_manifest/root.zig +1 -0
  28. package/src/primitives/app_manifest/types.zig +32 -0
  29. package/src/primitives/canvas/tests.zig +1 -0
  30. package/src/primitives/canvas/ui.zig +11 -7
  31. package/src/primitives/canvas/ui_markup.zig +58 -34
  32. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  33. package/src/primitives/canvas/ui_markup_compiled.zig +23 -8
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +1 -1
  36. package/src/primitives/canvas/ui_markup_contract_tests.zig +26 -0
  37. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  38. package/src/primitives/canvas/ui_markup_tests.zig +29 -9
  39. package/src/primitives/canvas/ui_markup_view.zig +29 -11
  40. package/src/primitives/canvas/ui_markup_view_tests.zig +150 -9
  41. package/src/primitives/canvas/ui_schema.zig +13 -0
  42. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  43. package/src/root.zig +7 -0
  44. package/src/runtime/api.zig +6 -4
  45. package/src/runtime/bridge_payload.zig +7 -0
  46. package/src/runtime/bridge_responses.zig +5 -0
  47. package/src/runtime/builtin_bridge.zig +9 -4
  48. package/src/runtime/canvas_font_tests.zig +439 -2
  49. package/src/runtime/canvas_fonts.zig +61 -6
  50. package/src/runtime/canvas_image_tests.zig +195 -0
  51. package/src/runtime/canvas_images.zig +45 -12
  52. package/src/runtime/core.zig +58 -11
  53. package/src/runtime/effects.zig +1664 -43
  54. package/src/runtime/effects_fetch_tests.zig +89 -1
  55. package/src/runtime/effects_file_tests.zig +41 -1
  56. package/src/runtime/effects_image_tests.zig +1304 -0
  57. package/src/runtime/effects_tests.zig +153 -0
  58. package/src/runtime/flow.zig +17 -0
  59. package/src/runtime/root.zig +11 -0
  60. package/src/runtime/session_blobs.zig +689 -0
  61. package/src/runtime/session_journal.zig +85 -21
  62. package/src/runtime/session_record.zig +27 -2
  63. package/src/runtime/session_replay.zig +168 -16
  64. package/src/runtime/session_tests.zig +1992 -0
  65. package/src/runtime/shell_layout.zig +7 -0
  66. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  67. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +439 -4
  70. package/src/runtime/ts_core_host_tests.zig +41 -0
  71. package/src/runtime/ts_ui_app.zig +7 -0
  72. package/src/runtime/ui_app.zig +111 -6
  73. package/src/runtime/ui_app_window_tests.zig +468 -0
  74. package/src/runtime/window_command_bridge_tests.zig +117 -0
  75. package/src/runtime/window_storage.zig +32 -0
  76. package/src/runtime/window_views.zig +61 -1
  77. package/src/tooling/manifest.zig +75 -0
  78. package/src/tooling/raw_manifest.zig +2 -0
  79. package/src/tooling/templates.zig +219 -1
@@ -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,
@@ -265,6 +280,23 @@ pub const NullPlatform = struct {
265
280
  /// the null platform has no Dock to genie into, so the count IS the
266
281
  /// behavior tests pin.
267
282
  window_minimize_count: [max_windows]u32 = [_]u32{0} ** max_windows,
283
+ /// Show calls per window (`show_window_fn`), indexed like `windows`
284
+ /// — the counterpart seam (tray "Open", the un-hide verb).
285
+ window_show_count: [max_windows]u32 = [_]u32{0} ** max_windows,
286
+ /// Graceful-quit requests (`quit_app_fn`). The real hosts QUEUE
287
+ /// the stop onto their run loop (macOS dispatch_async, GTK
288
+ /// g_idle_add, Windows PostQuitMessage) so `app_shutdown` emits
289
+ /// only on the NEXT loop turn, after the dispatch that requested
290
+ /// the quit has returned — a recorded command that quits commits
291
+ /// to the session journal before the shutdown record seals it.
292
+ /// The modeled host mirrors that shape: `quitApp` only records the
293
+ /// request, and `takeQueuedQuit` hands the test the deferred
294
+ /// shutdown event to dispatch as its own loop turn.
295
+ quit_request_count: u32 = 0,
296
+ /// The queued stop `quitApp` armed and `takeQueuedQuit` has not
297
+ /// yet drained — the modeled twin of the hosts' pending idle/queue
298
+ /// entry (exactly-once, like their did-shutdown latches).
299
+ quit_pending: bool = false,
268
300
  /// Modeled occlusion per window, indexed like `windows`: true while
269
301
  /// the modeled window does not reach the glass (minimized, or a
270
302
  /// test covered it via `setWindowOccluded`). Drives the
@@ -277,6 +309,23 @@ pub const NullPlatform = struct {
277
309
  /// Captured `WindowOptions.show` per created window: the
278
310
  /// present-before-show policy that must survive to the create seam.
279
311
  window_show: [max_windows]types.WindowShowMode = [_]types.WindowShowMode{.immediate} ** max_windows,
312
+ /// Captured `WindowOptions.close_policy` per created window — the
313
+ /// seam-regression capture (like `window_resizable`) AND the
314
+ /// modeled behavior: `userCloseWindow` consults it exactly like the
315
+ /// real hosts' close delegates, hiding instead of closing under
316
+ /// `.hide`.
317
+ window_close_policy: [max_windows]types.WindowClosePolicy = [_]types.WindowClosePolicy{.quit} ** max_windows,
318
+ /// Test seam: make the NEXT `close_window_fn` call fail with
319
+ /// `error.CloseFailed` (the real hosts' refusal), consuming the
320
+ /// flag — the injection runtime rollback tests use to assert
321
+ /// `closeWindow` restores every flag it flipped optimistically
322
+ /// (open, focused, hidden).
323
+ fail_next_close_window: bool = false,
324
+ /// Test seam: make the NEXT `show_window_fn` call fail with
325
+ /// `error.ShowFailed`, consuming the flag — the injection the
326
+ /// runtime's `showWindow` rollback test uses to assert a refused
327
+ /// show restores hidden and moves no focus.
328
+ fail_next_show_window: bool = false,
280
329
  /// Captured `WindowOptions.min_width`/`min_height` per created
281
330
  /// window — the content min-size floor that must survive to the
282
331
  /// create seam (macOS applies it as `contentMinSize`); same
@@ -433,6 +482,40 @@ pub const NullPlatform = struct {
433
482
  gpu_surface_image_upload_byte_len: usize = 0,
434
483
  gpu_surface_image_upload_sample_rgba: [4]u8 = .{ 0, 0, 0, 0 },
435
484
  gpu_surface_image_remove_id: u64 = 0,
485
+ /// Host-font mirror for the registration seam, default OFF: the null
486
+ /// platform models a platform without host-side text, whose register
487
+ /// seam is null (engine-side registration is the whole story there,
488
+ /// and the runtime records ownership token 0 — nothing installed).
489
+ /// Tests modelling a stateful host (macOS's per-process descriptor
490
+ /// and token tables) enable this before taking `platform()`: the
491
+ /// mirror then accepts registrations id-keyed and last-wins, mints a
492
+ /// monotonic ownership token per registration exactly like the
493
+ /// AppKit host, and honors the token guard at unregister — so the
494
+ /// shared-id lifecycle (an older runtime's deinit must leave a newer
495
+ /// runtime's re-registration intact) is assertable without CoreText.
496
+ /// Per-instance where the real host tables are per-process: tests
497
+ /// model "one process" by pointing every runtime at ONE instance.
498
+ gpu_surface_font_registrations: bool = false,
499
+ gpu_surface_fonts: [max_gpu_surface_fonts]NullGpuSurfaceFont = [_]NullGpuSurfaceFont{.{}} ** max_gpu_surface_fonts,
500
+ gpu_surface_font_count: usize = 0,
501
+ gpu_surface_font_register_count: usize = 0,
502
+ /// The mirror's monotonic token counter, pre-incremented per
503
+ /// registration so 0 is never a live token — the AppKit host's
504
+ /// counter discipline, which is what makes a stale (or 0) token
505
+ /// provably match nothing.
506
+ gpu_surface_font_token_counter: u64 = 0,
507
+ /// Font-unregister recorder for the host-teardown seam Runtime.deinit
508
+ /// drives. Present even with the mirror off: the null platform then
509
+ /// has no register seam (no host-side text — engine-side registration
510
+ /// is the whole story), but it still accepts and records the teardown
511
+ /// call, so embed tests can pin that deinit returns the host-side
512
+ /// registration on platforms that do retain per-id font state
513
+ /// (macOS's CoreText descriptor and caches). The recorded token is
514
+ /// exactly what the call carried — 0 when the runtime captured no
515
+ /// register-time token, the minted stamp when the mirror is on.
516
+ gpu_surface_font_unregister_count: usize = 0,
517
+ gpu_surface_font_unregister_id: u64 = 0,
518
+ gpu_surface_font_unregister_token: u64 = 0,
436
519
  timers: [max_null_timers]NullTimer = [_]NullTimer{.{}} ** max_null_timers,
437
520
  timer_count: usize = 0,
438
521
  timer_start_count: usize = 0,
@@ -519,6 +602,11 @@ pub const NullPlatform = struct {
519
602
  /// path) set it false, which nulls the service AND the feature
520
603
  /// report — the same shape as a real host without a presenter.
521
604
  context_menus: bool = true,
605
+ /// Whether this modeled host can hide-on-close and re-show (the
606
+ /// `close_policy = .hide` shape). On by default, modeling
607
+ /// macOS/Windows; tests modeling a host without the affordance
608
+ /// (GTK) set it false and pin the runtime's create-time refusal.
609
+ window_hide_on_close: bool = true,
522
610
  /// Native context-menu recorder: presentations record the request and
523
611
  /// return; tests then feed the selection back as a
524
612
  /// `.context_menu_action` platform event.
@@ -567,6 +655,8 @@ pub const NullPlatform = struct {
567
655
  .focus_window_fn = focusWindow,
568
656
  .close_window_fn = closeWindow,
569
657
  .minimize_window_fn = minimizeWindow,
658
+ .show_window_fn = showWindow,
659
+ .quit_app_fn = quitApp,
570
660
  .start_window_drag_fn = startWindowDrag,
571
661
  .window_chrome_fn = windowChrome,
572
662
  .set_window_drag_regions_fn = setWindowDragRegions,
@@ -619,6 +709,8 @@ pub const NullPlatform = struct {
619
709
  .present_gpu_surface_packet_binary_fn = presentGpuSurfacePacketBinary,
620
710
  .upload_gpu_surface_image_fn = uploadGpuSurfaceImage,
621
711
  .remove_gpu_surface_image_fn = removeGpuSurfaceImage,
712
+ .register_gpu_surface_font_fn = if (self.gpu_surface_font_registrations) registerGpuSurfaceFont else null,
713
+ .unregister_gpu_surface_font_fn = unregisterGpuSurfaceFont,
622
714
  .decode_image_fn = decodeImage,
623
715
  .set_gpu_surface_scroll_drivers_fn = setGpuSurfaceScrollDrivers,
624
716
  .show_context_menu_fn = if (self.context_menus) showContextMenu else null,
@@ -655,6 +747,11 @@ pub const NullPlatform = struct {
655
747
  // app-owned platform view into — reporting support would be a
656
748
  // lie the first adopt call exposes.
657
749
  .view_surface_adoption => false,
750
+ // Models the macOS/Windows hosts by default: user closes
751
+ // honor the captured close policy and hidden windows
752
+ // re-show, so the runtime suites can pin the whole
753
+ // menu-bar-app loop. Tests flip it false to model GTK.
754
+ .window_hide_on_close => self.window_hide_on_close,
658
755
  .audio_playback => self.audio_playback,
659
756
  .audio_streaming => self.audio_playback and self.audio_streaming,
660
757
  .audio_spectrum => self.audio_playback and self.audio_spectrum,
@@ -796,6 +893,7 @@ pub const NullPlatform = struct {
796
893
  self.window_resizable[self.window_count] = options.resizable;
797
894
  self.window_titlebar[self.window_count] = options.titlebar;
798
895
  self.window_show[self.window_count] = options.show;
896
+ self.window_close_policy[self.window_count] = options.close_policy;
799
897
  self.window_min_width[self.window_count] = options.min_width;
800
898
  self.window_min_height[self.window_count] = options.min_height;
801
899
  self.window_first_present_seq[self.window_count] = 0;
@@ -877,9 +975,19 @@ pub const NullPlatform = struct {
877
975
 
878
976
  fn closeWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
879
977
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
978
+ if (self.fail_next_close_window) {
979
+ self.fail_next_close_window = false;
980
+ return error.CloseFailed;
981
+ }
880
982
  const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
881
983
  self.windows[index].open = false;
882
984
  self.windows[index].focused = false;
985
+ // hidden clears WITH open, mirroring the real hosts' close
986
+ // paths (every macOS close exit leaves the policy-hidden set
987
+ // before its emit) and the runtime table's own close flip: a
988
+ // closed window is not "hidden", it is gone — a stale
989
+ // hidden=true here is exactly what lets a reopen resurrect it.
990
+ self.windows[index].hidden = false;
883
991
  self.removeViewsForWindow(window_id);
884
992
  self.removeWebViewsForWindow(window_id);
885
993
  }
@@ -897,6 +1005,54 @@ pub const NullPlatform = struct {
897
1005
  self.window_occluded[index] = true;
898
1006
  }
899
1007
 
1008
+ fn showWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
1009
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1010
+ if (self.fail_next_show_window) {
1011
+ self.fail_next_show_window = false;
1012
+ return error.ShowFailed;
1013
+ }
1014
+ const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
1015
+ // The un-hide verb: back on the glass with focus, exactly the
1016
+ // real hosts' deminiaturize + order-front + activate. Clears a
1017
+ // policy-hide, a minimize's occlusion, and a still-deferred
1018
+ // present-before-show alike.
1019
+ self.windows[index].hidden = false;
1020
+ self.window_occluded[index] = false;
1021
+ for (self.windows[0..self.window_count], 0..) |*window, cursor| {
1022
+ window.focused = cursor == index;
1023
+ }
1024
+ if (!self.window_visible[index]) {
1025
+ self.window_visible[index] = true;
1026
+ self.show_op_seq += 1;
1027
+ self.window_shown_seq[index] = self.show_op_seq;
1028
+ }
1029
+ self.window_show_count[index] += 1;
1030
+ }
1031
+
1032
+ fn quitApp(context: ?*anyopaque) anyerror!void {
1033
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1034
+ self.quit_request_count += 1;
1035
+ self.quit_pending = true;
1036
+ }
1037
+
1038
+ /// Test seam: drain the stop the quit verb queued — the modeled
1039
+ /// host echo, and the modeled NEXT LOOP TURN. Real hosts defer the
1040
+ /// shutdown emit past the dispatch that requested it (see
1041
+ /// `quit_request_count`); a test models that by dispatching the
1042
+ /// returned event only after the quitting dispatch has returned,
1043
+ /// exactly the `userCloseWindow` shape. The PRE-RUN quit rides the
1044
+ /// same model: a quit requested before the hosts' run loop exists
1045
+ /// (App.start's update, a boot command in the synchronous first
1046
+ /// canvas frame) parks on the host and drains at top level after
1047
+ /// the boot dispatch returns — arm here, drain here, identically.
1048
+ /// Answers exactly once per armed quit; null while nothing is
1049
+ /// queued.
1050
+ pub fn takeQueuedQuit(self: *NullPlatform) ?Event {
1051
+ if (!self.quit_pending) return null;
1052
+ self.quit_pending = false;
1053
+ return .app_shutdown;
1054
+ }
1055
+
900
1056
  fn createView(context: ?*anyopaque, options: ViewOptions) anyerror!void {
901
1057
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
902
1058
  if (options.kind == .webview) return createWebView(context, options.webViewOptions());
@@ -1761,6 +1917,69 @@ pub const NullPlatform = struct {
1761
1917
  self.gpu_surface_image_count = last;
1762
1918
  }
1763
1919
 
1920
+ /// The host-font mirror's register half (installed only when
1921
+ /// `gpu_surface_font_registrations` is on — see that flag): id-keyed
1922
+ /// and last-wins like the AppKit host's descriptor table, minting a
1923
+ /// pre-incremented monotonic ownership token per registration and
1924
+ /// returning it, so tests can assert the token lifecycle the real
1925
+ /// host runs.
1926
+ fn registerGpuSurfaceFont(context: ?*anyopaque, font: GpuSurfaceFontData) anyerror!u64 {
1927
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1928
+ self.gpu_surface_font_register_count += 1;
1929
+ self.gpu_surface_font_token_counter += 1;
1930
+ const token = self.gpu_surface_font_token_counter;
1931
+ const index = self.findGpuSurfaceFontIndex(font.id) orelse blk: {
1932
+ if (self.gpu_surface_font_count >= max_gpu_surface_fonts) return error.InvalidGpuSurfaceFont;
1933
+ const index = self.gpu_surface_font_count;
1934
+ self.gpu_surface_font_count += 1;
1935
+ break :blk index;
1936
+ };
1937
+ self.gpu_surface_fonts[index] = .{
1938
+ .id = font.id,
1939
+ .token = token,
1940
+ .byte_len = font.ttf.len,
1941
+ };
1942
+ return token;
1943
+ }
1944
+
1945
+ /// Records every teardown call (see the recorder fields; unlike the
1946
+ /// image seam this one is not gated on `gpu_surfaces` — Runtime.deinit
1947
+ /// unregisters every registered font regardless of what the surface
1948
+ /// renders through), then applies the mirror's token guard: the id's
1949
+ /// entry comes out only while it still carries `token`, so a stale
1950
+ /// owner (the id was re-registered since, last wins) removes nothing
1951
+ /// — the guard an id-keyed removal would violate by letting an older
1952
+ /// runtime's deinit delete a newer runtime's live registration. With
1953
+ /// the mirror off the table is empty and this is the recording no-op
1954
+ /// it always was: there is no host font state to drop.
1955
+ fn unregisterGpuSurfaceFont(context: ?*anyopaque, id: u64, token: u64) anyerror!void {
1956
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1957
+ self.gpu_surface_font_unregister_id = id;
1958
+ self.gpu_surface_font_unregister_token = token;
1959
+ self.gpu_surface_font_unregister_count += 1;
1960
+ const index = self.findGpuSurfaceFontIndex(id) orelse return;
1961
+ if (self.gpu_surface_fonts[index].token != token) return;
1962
+ const last = self.gpu_surface_font_count - 1;
1963
+ if (index != last) self.gpu_surface_fonts[index] = self.gpu_surface_fonts[last];
1964
+ self.gpu_surface_fonts[last] = .{};
1965
+ self.gpu_surface_font_count = last;
1966
+ }
1967
+
1968
+ /// The mirrored host font registration for `id`, or null when the id
1969
+ /// holds none (never registered, or returned at teardown) — what a
1970
+ /// stateful host would resolve measurement and drawing through.
1971
+ pub fn gpuSurfaceFont(self: *const NullPlatform, id: u64) ?NullGpuSurfaceFont {
1972
+ const index = self.findGpuSurfaceFontIndex(id) orelse return null;
1973
+ return self.gpu_surface_fonts[index];
1974
+ }
1975
+
1976
+ fn findGpuSurfaceFontIndex(self: *const NullPlatform, id: u64) ?usize {
1977
+ for (self.gpu_surface_fonts[0..self.gpu_surface_font_count], 0..) |font, index| {
1978
+ if (font.id == id) return index;
1979
+ }
1980
+ return null;
1981
+ }
1982
+
1764
1983
  /// The recorded side-channel entry for `id`, or null when the id was
1765
1984
  /// never uploaded (or has been removed) — the store a packet host
1766
1985
  /// would consult on an upload cache action.
@@ -1851,13 +2070,34 @@ pub const NullPlatform = struct {
1851
2070
  self.view_count -= 1;
1852
2071
  }
1853
2072
 
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.
2073
+ /// Test seam: the USER closed a window. Under the default `.quit`
2074
+ /// policy this models the real hosts' window delegates, which tear
2075
+ /// the native window out of their records before emitting the
2076
+ /// open=false frame event (macOS `windowWillClose`) — remove the
2077
+ /// window and its views here, then dispatch the returned event
2078
+ /// through the runtime. Under `close_policy = .hide` it models the
2079
+ /// intercepting delegate instead (macOS `windowShouldClose`
2080
+ /// answering NO + `orderOut`, Win32 `WM_CLOSE` answering with
2081
+ /// `SW_HIDE`): the window and its views stay, only the glass loses
2082
+ /// it, and the returned frame event carries open=true hidden=true.
1859
2083
  pub fn userCloseWindow(self: *NullPlatform, window_id: WindowId) ?Event {
1860
2084
  const index = self.findWindowIndex(window_id) orelse return null;
2085
+ if (self.window_close_policy[index] == .hide) {
2086
+ self.windows[index].hidden = true;
2087
+ self.windows[index].focused = false;
2088
+ self.window_occluded[index] = true;
2089
+ const info = self.windows[index];
2090
+ return .{ .window_frame_changed = .{
2091
+ .id = info.id,
2092
+ .label = info.label,
2093
+ .title = info.title,
2094
+ .frame = info.frame,
2095
+ .scale_factor = info.scale_factor,
2096
+ .open = true,
2097
+ .focused = false,
2098
+ .hidden = true,
2099
+ } };
2100
+ }
1861
2101
  const info = self.windows[index];
1862
2102
  self.removeViewsForWindow(window_id);
1863
2103
  self.removeWebViewsForWindow(window_id);
@@ -1873,6 +2113,50 @@ pub const NullPlatform = struct {
1873
2113
  } };
1874
2114
  }
1875
2115
 
2116
+ /// Test seam: the user asked the app to come back with no window on
2117
+ /// the glass (the macOS Dock-icon reopen). Models the host's
2118
+ /// `applicationShouldHandleReopen:` — every window hidden by its
2119
+ /// `.hide` close policy re-shows — and returns one frame event per
2120
+ /// re-shown window (dispatch them through the runtime like any
2121
+ /// platform event). Windows hidden some other way (minimized,
2122
+ /// occluded) are the OS's to restore, exactly like the real host.
2123
+ pub fn userReopenApp(self: *NullPlatform, output: []Event) []const Event {
2124
+ var count: usize = 0;
2125
+ for (self.windows[0..self.window_count], 0..) |*window, index| {
2126
+ if (!window.hidden) continue;
2127
+ // Liveness, not just the hidden flag: a closed window keeps
2128
+ // its slot in this mirror, and the reopen must never
2129
+ // resurrect one — even if a close path left the hidden flag
2130
+ // stale, re-showing a window the app closed (hidden=false,
2131
+ // focused=true, a frame event) is the exact bug the real
2132
+ // hosts' set hygiene prevents.
2133
+ if (!window.open) continue;
2134
+ if (count >= output.len) break;
2135
+ window.hidden = false;
2136
+ window.focused = count == 0;
2137
+ self.window_occluded[index] = false;
2138
+ output[count] = .{ .window_frame_changed = .{
2139
+ .id = window.id,
2140
+ .label = window.label,
2141
+ .title = window.title,
2142
+ .frame = window.frame,
2143
+ .scale_factor = window.scale_factor,
2144
+ .open = true,
2145
+ .focused = window.focused,
2146
+ .hidden = false,
2147
+ } };
2148
+ count += 1;
2149
+ }
2150
+ return output[0..count];
2151
+ }
2152
+
2153
+ /// Test seam: the captured close policy for a created window (the
2154
+ /// create-seam regression observable, like `window_titlebar`).
2155
+ pub fn closePolicyForWindow(self: *const NullPlatform, window_id: WindowId) ?types.WindowClosePolicy {
2156
+ const index = self.findWindowIndex(window_id) orelse return null;
2157
+ return self.window_close_policy[index];
2158
+ }
2159
+
1876
2160
  /// Test seam: minimize calls observed for a window (the null host
1877
2161
  /// has no Dock, so the count is the pinned behavior).
1878
2162
  pub fn minimizeCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
@@ -1880,6 +2164,13 @@ pub const NullPlatform = struct {
1880
2164
  return self.window_minimize_count[index];
1881
2165
  }
1882
2166
 
2167
+ /// Test seam: show calls observed for a window (the un-hide verb's
2168
+ /// pinned observable, like `minimizeCountForWindow`).
2169
+ pub fn showCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
2170
+ const index = self.findWindowIndex(window_id) orelse return 0;
2171
+ return self.window_show_count[index];
2172
+ }
2173
+
1883
2174
  /// Test seam: model a window leaving or returning to the glass
1884
2175
  /// without a minimize verb (fully covered by another app, revealed
1885
2176
  /// again) — the occlusion fact the real hosts' spectrum gating
@@ -1912,7 +2203,9 @@ pub const NullPlatform = struct {
1912
2203
  self.window_min_width[cursor] = self.window_min_width[cursor + 1];
1913
2204
  self.window_min_height[cursor] = self.window_min_height[cursor + 1];
1914
2205
  self.window_minimize_count[cursor] = self.window_minimize_count[cursor + 1];
2206
+ self.window_show_count[cursor] = self.window_show_count[cursor + 1];
1915
2207
  self.window_occluded[cursor] = self.window_occluded[cursor + 1];
2208
+ self.window_close_policy[cursor] = self.window_close_policy[cursor + 1];
1916
2209
  }
1917
2210
  self.window_count -= 1;
1918
2211
  }
@@ -78,6 +78,7 @@ pub const WindowChrome = types.WindowChrome;
78
78
  pub const FormFactor = types.FormFactor;
79
79
  pub const WindowDragRegion = types.WindowDragRegion;
80
80
  pub const WindowShowMode = types.WindowShowMode;
81
+ pub const WindowClosePolicy = types.WindowClosePolicy;
81
82
  pub const WindowOptions = types.WindowOptions;
82
83
  pub const WindowState = types.WindowState;
83
84
  pub const WindowInfo = types.WindowInfo;
@@ -178,6 +179,38 @@ pub const macos = @import("macos/root.zig");
178
179
  pub const linux = @import("linux/root.zig");
179
180
  pub const windows = @import("windows/root.zig");
180
181
 
182
+ /// Install the host image codec for a headless session replay over the
183
+ /// null platform. Replay decode serves JOURNALED bytes only — the
184
+ /// network and the filesystem stay absent — but those bytes must decode
185
+ /// through the SAME codec the recording host used, or replayed loads
186
+ /// drop their pixels and replayed screenshots lose images. Every
187
+ /// desktop host's codec is a context-free bytes-to-pixels call
188
+ /// (CGImageSource / gdk-pixbuf / WIC), so a headless replay serves it
189
+ /// with no window and no run loop. `platform_name` is the build's
190
+ /// platform selection (the app runner's `build_options.platform`,
191
+ /// comptime — arms for other platforms are never analyzed, so the
192
+ /// codec-less test tier links without the host shims). A build with no
193
+ /// host codec ("null") falls back to the null platform's strict
194
+ /// test-PNG decoder — honest but narrow: only the canvas PNG writer's
195
+ /// subset decodes there, and any other recorded format drops its pixels
196
+ /// with the replay diagnostic while the Msg stream still replays
197
+ /// verbatim.
198
+ pub fn installHeadlessImageCodec(
199
+ comptime platform_name: []const u8,
200
+ headless_host: *NullPlatform,
201
+ services: *PlatformServices,
202
+ ) void {
203
+ if (comptime std.mem.eql(u8, platform_name, "macos")) {
204
+ macos.installHeadlessImageCodec(services);
205
+ } else if (comptime std.mem.eql(u8, platform_name, "linux")) {
206
+ linux.installHeadlessImageCodec(services);
207
+ } else if (comptime std.mem.eql(u8, platform_name, "windows")) {
208
+ windows.installHeadlessImageCodec(services);
209
+ } else {
210
+ headless_host.image_decode = true;
211
+ }
212
+ }
213
+
181
214
  test {
182
215
  std.testing.refAllDecls(@This());
183
216
  _ = @import("null_platform_tests.zig");