@native-sdk/cli 0.5.0 → 0.5.2

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 (60) hide show
  1. package/build/app.zig +198 -13
  2. package/build/ts_run.mjs +58 -19
  3. package/build.zig +42 -0
  4. package/package.json +13 -9
  5. package/packages/core/package-lock.json +4 -3
  6. package/packages/core/package.json +3 -2
  7. package/packages/core/src/typed_ast.ts +11 -1
  8. package/skill-data/native-ui/SKILL.md +2 -2
  9. package/src/platform/types.zig +9 -0
  10. package/src/platform/windows/webview2_host.cpp +24 -0
  11. package/src/primitives/canvas/layout_audit.zig +5 -5
  12. package/src/primitives/canvas/root.zig +6 -0
  13. package/src/primitives/canvas/tokens.zig +185 -7
  14. package/src/primitives/canvas/ui.zig +27 -5
  15. package/src/primitives/canvas/ui_markup.zig +27 -4
  16. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  17. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  18. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  19. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  20. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  21. package/src/primitives/canvas/ui_schema.zig +15 -1
  22. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  23. package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
  24. package/src/primitives/canvas/widget_layout.zig +142 -3
  25. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  26. package/src/primitives/canvas/widget_metrics.zig +16 -8
  27. package/src/primitives/canvas/widget_tree.zig +14 -2
  28. package/src/primitives/canvas/widgets.zig +12 -0
  29. package/src/runtime/automation_widget_dispatch.zig +95 -28
  30. package/src/runtime/canvas_frame.zig +15 -0
  31. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  32. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  33. package/src/runtime/canvas_widget_events.zig +1271 -3
  34. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  35. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  36. package/src/runtime/canvas_widget_state.zig +82 -5
  37. package/src/runtime/core.zig +30 -0
  38. package/src/runtime/effects.zig +1037 -133
  39. package/src/runtime/effects_fetch_tests.zig +42 -0
  40. package/src/runtime/effects_file_tests.zig +220 -0
  41. package/src/runtime/effects_tests.zig +287 -0
  42. package/src/runtime/flow.zig +24 -1
  43. package/src/runtime/gpu_surface_events.zig +44 -5
  44. package/src/runtime/session_journal.zig +25 -13
  45. package/src/runtime/session_record.zig +166 -0
  46. package/src/runtime/session_tests.zig +453 -0
  47. package/src/runtime/ui_app.zig +137 -39
  48. package/src/runtime/ui_app_tests.zig +681 -0
  49. package/src/runtime/ui_app_window_tests.zig +182 -0
  50. package/src/runtime/view.zig +86 -0
  51. package/src/runtime/view_widget_text.zig +18 -1
  52. package/src/runtime/view_widget_tree.zig +339 -20
  53. package/src/runtime/widget_bridge.zig +26 -0
  54. package/src/runtime/window_storage.zig +61 -15
  55. package/src/runtime/window_view_runtime.zig +13 -0
  56. package/src/runtime/window_views.zig +6 -0
  57. package/src/tooling/package.zig +311 -8
  58. package/src/tooling/templates.zig +97 -9
  59. package/src/tooling/ts_core.zig +626 -13
  60. package/src/tooling/verbs.zig +88 -2
@@ -7,6 +7,7 @@
7
7
 
8
8
  const std = @import("std");
9
9
  const geometry = @import("geometry");
10
+ const canvas = @import("canvas");
10
11
  const app_manifest = @import("app_manifest");
11
12
  const core = @import("core.zig");
12
13
  const ui_app_mod = @import("ui_app.zig");
@@ -32,10 +33,36 @@ const SessionModel = struct {
32
33
  /// pin, without 32 array fields in the equality check.
33
34
  spectrum_count: u32 = 0,
34
35
  band_checksum: u64 = 0,
36
+ /// The search query's `on_input` mirror, zero-padded so the deep
37
+ /// model equality below stays deterministic. The reference session
38
+ /// types into the field and Escape-clears it: the journal records
39
+ /// only the RAW click/type/Escape platform events, so replay must
40
+ /// re-derive the same clear edit the recording's editor applied.
41
+ query: [32]u8 = [_]u8{0} ** 32,
42
+ query_len: usize = 0,
43
+ query_anchor: usize = 0,
44
+ query_focus: usize = 0,
45
+ query_edits: u32 = 0,
46
+ /// A SECOND editable field's mirror: the direct-verb replay tests
47
+ /// need two editors so a composition targeting one can prove it
48
+ /// does not land on whichever field the session left focused.
49
+ name: [32]u8 = [_]u8{0} ** 32,
50
+ name_len: usize = 0,
51
+ name_anchor: usize = 0,
52
+ name_focus: usize = 0,
53
+ name_edits: u32 = 0,
35
54
 
36
55
  fn bodyText(self: *const SessionModel) []const u8 {
37
56
  return self.body[0..self.body_len];
38
57
  }
58
+
59
+ fn queryText(self: *const SessionModel) []const u8 {
60
+ return self.query[0..self.query_len];
61
+ }
62
+
63
+ fn nameText(self: *const SessionModel) []const u8 {
64
+ return self.name[0..self.name_len];
65
+ }
39
66
  };
40
67
 
41
68
  const SessionMsg = union(enum) {
@@ -44,6 +71,8 @@ const SessionMsg = union(enum) {
44
71
  start_fetch,
45
72
  start_spawn,
46
73
  start_audio,
74
+ query_edit: canvas.TextInputEvent,
75
+ name_edit: canvas.TextInputEvent,
47
76
  fetched: effects_mod.EffectResponse,
48
77
  line: effects_mod.EffectLine,
49
78
  exited: effects_mod.EffectExit,
@@ -92,17 +121,48 @@ fn sessionUpdate(model: *SessionModel, msg: SessionMsg, fx: *SessionApp.Effects)
92
121
  for (event.bands) |band| checksum = checksum *% 31 +% band;
93
122
  model.band_checksum = checksum;
94
123
  },
124
+ .query_edit => |edit| applyMirrorEdit(&model.query, &model.query_len, &model.query_anchor, &model.query_focus, &model.query_edits, edit),
125
+ .name_edit => |edit| applyMirrorEdit(&model.name, &model.name_len, &model.name_anchor, &model.name_focus, &model.name_edits, edit),
95
126
  .line => model.line_count += 1,
96
127
  .exited => |exit| model.exit_code = exit.code,
97
128
  .tick => |timer| model.tick_timestamp_ns = timer.timestamp_ns,
98
129
  }
99
130
  }
100
131
 
132
+ /// One editable-field mirror step: apply `edit` to the zero-padded
133
+ /// text + selection mirror the deep model equality checks compare.
134
+ fn applyMirrorEdit(store: *[32]u8, len: *usize, anchor: *usize, focus: *usize, edits: *u32, edit: canvas.TextInputEvent) void {
135
+ var scratch: [32]u8 = undefined;
136
+ const next = (canvas.TextEditState{
137
+ .text = store[0..len.*],
138
+ .selection = .{ .anchor = anchor.*, .focus = focus.* },
139
+ }).apply(edit, &scratch) catch return;
140
+ var out = [_]u8{0} ** 32;
141
+ const out_len = @min(next.text.len, out.len);
142
+ std.mem.copyForwards(u8, out[0..out_len], next.text[0..out_len]);
143
+ store.* = out;
144
+ len.* = out_len;
145
+ anchor.* = next.selection.anchor;
146
+ focus.* = next.selection.focus;
147
+ edits.* += 1;
148
+ }
149
+
101
150
  fn sessionView(ui: *SessionApp.Ui, model: *const SessionModel) SessionApp.Ui.Node {
102
151
  return ui.column(.{ .gap = 8, .padding = 12 }, .{
103
152
  ui.text(.{}, ui.fmt("Count {d}", .{model.count})),
104
153
  ui.text(.{}, ui.fmt("Body {s} ({d})", .{ model.bodyText(), model.fetch_status })),
105
154
  ui.text(.{}, ui.fmt("Lines {d} Exit {d} Tick {d} Stamp {d}", .{ model.line_count, model.exit_code, model.tick_timestamp_ns, model.stamp_ms })),
155
+ ui.el(.search_field, .{
156
+ .text = model.queryText(),
157
+ .placeholder = "Search",
158
+ .on_input = SessionApp.Ui.inputMsg(.query_edit),
159
+ }, .{}),
160
+ ui.el(.text_field, .{
161
+ .text = model.nameText(),
162
+ .placeholder = "Name",
163
+ .on_input = SessionApp.Ui.inputMsg(.name_edit),
164
+ }, .{}),
165
+ ui.text(.{}, ui.fmt("Query {s} ({d}) Name {s} ({d})", .{ model.queryText(), model.query_edits, model.nameText(), model.name_edits })),
106
166
  ui.button(.{ .on_press = .increment }, "Increment"),
107
167
  });
108
168
  }
@@ -242,6 +302,41 @@ fn recordReferenceSession(gpa: std.mem.Allocator, buffer: *JournalBuffer, web_la
242
302
  try harness.runtime.dispatchPlatformEvent(app, .wake);
243
303
  try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
244
304
 
305
+ // An Escape-clear in the search field is DERIVED input state: the
306
+ // journal records only the raw click/type/Escape platform events,
307
+ // and replay must re-derive the same clear edit the recording's
308
+ // editor applied — model mirror, retained editor, and fingerprint
309
+ // all landing identically.
310
+ const layout = try harness.runtime.canvasWidgetLayout(1, canvas_label);
311
+ var search_frame: ?geometry.RectF = null;
312
+ for (layout.nodes) |node| {
313
+ if (node.widget.kind == .search_field) search_frame = node.frame;
314
+ }
315
+ const field_frame = search_frame.?;
316
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
317
+ .window_id = 1,
318
+ .label = canvas_label,
319
+ .kind = .pointer_down,
320
+ .x = field_frame.x + field_frame.width * 0.5,
321
+ .y = field_frame.y + field_frame.height * 0.5,
322
+ } });
323
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
324
+ .window_id = 1,
325
+ .label = canvas_label,
326
+ .kind = .text_input,
327
+ .text = "glass",
328
+ } });
329
+ try std.testing.expectEqualStrings("glass", app_state.model.queryText());
330
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
331
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
332
+ .window_id = 1,
333
+ .label = canvas_label,
334
+ .kind = .key_down,
335
+ .key = "escape",
336
+ } });
337
+ try std.testing.expectEqualStrings("", app_state.model.queryText());
338
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
339
+
245
340
  recorder.finish();
246
341
  try std.testing.expect(!recorder.failed);
247
342
 
@@ -294,6 +389,10 @@ test "a recorded session replays to identical model state and fingerprints" {
294
389
  try std.testing.expect(recorded.model.stamp_ms != 0);
295
390
  try std.testing.expectEqual(@as(u32, 1), recorded.model.spectrum_count);
296
391
  try std.testing.expect(recorded.model.band_checksum != 0);
392
+ // The typed insert and the DERIVED Escape-clear both reached the
393
+ // model's `on_input` mirror, and the clear left it empty.
394
+ try std.testing.expectEqual(@as(u32, 2), recorded.model.query_edits);
395
+ try std.testing.expectEqualStrings("", recorded.model.queryText());
297
396
 
298
397
  const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
299
398
  try std.testing.expect(replayed.report.ok());
@@ -327,6 +426,360 @@ test "a native-only session records and replays like a web-layer one" {
327
426
  try std.testing.expectEqual(recorded.fingerprint, replayed.fingerprint);
328
427
  }
329
428
 
429
+ test "accessibility actions journal once and replay without double-dispatch" {
430
+ // A journaled `widget_accessibility_action` re-runs its verb on
431
+ // replay, and the verb synthesizes REAL platform events (press its
432
+ // Enter key, set_text a select-all plus a text input). If those
433
+ // children also landed in the journal, replay would dispatch them
434
+ // twice — the stray child arrives first, against the focus the
435
+ // PREVIOUS action left behind, so a repeated press increments an
436
+ // extra time and a repeated set_text edits the field extra times.
437
+ // The recorder journals outer-wins: exactly one record per action,
438
+ // and live/replay model counters match exactly.
439
+ const gpa = std.testing.allocator;
440
+ const buffer = try std.heap.page_allocator.create(JournalBuffer);
441
+ defer std.heap.page_allocator.destroy(buffer);
442
+ buffer.len = 0;
443
+
444
+ const recorder = try std.heap.page_allocator.create(session_record.SessionRecorder);
445
+ defer std.heap.page_allocator.destroy(recorder);
446
+ recorder.* = session_record.SessionRecorder.init(buffer.sink());
447
+ recorder.begin(.{ .platform_name = "test", .app_name = "session-demo", .window_width = 400, .window_height = 300 });
448
+
449
+ const harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
450
+ defer harness.destroy(gpa);
451
+ harness.null_platform.gpu_surfaces = true;
452
+ harness.runtime.options.session_recorder = recorder;
453
+
454
+ const app_state = try gpa.create(SessionApp);
455
+ defer gpa.destroy(app_state);
456
+ app_state.* = SessionApp.init(std.heap.page_allocator, .{}, sessionOptions());
457
+ defer app_state.deinit();
458
+ app_state.effects.executor = .fake;
459
+ const app = app_state.app();
460
+
461
+ try harness.start(app);
462
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
463
+ .label = canvas_label,
464
+ .size = geometry.SizeF.init(400, 300),
465
+ .scale_factor = 2,
466
+ .frame_index = 1,
467
+ .timestamp_ns = 1_000_000,
468
+ } });
469
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
470
+
471
+ const layout = try harness.runtime.canvasWidgetLayout(1, canvas_label);
472
+ var button_id: canvas.ObjectId = 0;
473
+ var field_id: canvas.ObjectId = 0;
474
+ for (layout.nodes) |node| {
475
+ if (node.widget.kind == .button) button_id = node.widget.id;
476
+ if (node.widget.kind == .search_field) field_id = node.widget.id;
477
+ }
478
+ try std.testing.expect(button_id != 0);
479
+ try std.testing.expect(field_id != 0);
480
+
481
+ // Two AX presses: the second is the doubling witness — with the
482
+ // synthesized Enter also journaled, replay delivers it against the
483
+ // already-focused button and the count lands at 3, not 2.
484
+ try harness.runtime.dispatchPlatformEvent(app, .{ .widget_accessibility_action = .{
485
+ .window_id = 1,
486
+ .label = canvas_label,
487
+ .id = button_id,
488
+ .action = .press,
489
+ } });
490
+ try harness.runtime.dispatchPlatformEvent(app, .{ .widget_accessibility_action = .{
491
+ .window_id = 1,
492
+ .label = canvas_label,
493
+ .id = button_id,
494
+ .action = .press,
495
+ } });
496
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.count);
497
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
498
+
499
+ // Two AX set_texts: the second one's stray select-all + text input
500
+ // would hit the focused field on replay and inflate `query_edits`.
501
+ try harness.runtime.dispatchPlatformEvent(app, .{ .widget_accessibility_action = .{
502
+ .window_id = 1,
503
+ .label = canvas_label,
504
+ .id = field_id,
505
+ .action = .set_text,
506
+ .text = "glass",
507
+ } });
508
+ try harness.runtime.dispatchPlatformEvent(app, .{ .widget_accessibility_action = .{
509
+ .window_id = 1,
510
+ .label = canvas_label,
511
+ .id = field_id,
512
+ .action = .set_text,
513
+ .text = "brass",
514
+ } });
515
+ try std.testing.expectEqualStrings("brass", app_state.model.queryText());
516
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
517
+ const edits_after_set_text = app_state.model.query_edits;
518
+
519
+ // An IME composition through the DIRECT verb surface (the embed
520
+ // host's `widgetAction` path): no platform event arrives, so the
521
+ // dispatch stages its own synthetic `widget_accessibility_action`
522
+ // record — outer-wins exactly like the platform path — and the
523
+ // synthesized ime children stay out of the journal. Replay re-runs
524
+ // the verb, focus included.
525
+ _ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, canvas_label, .{
526
+ .id = field_id,
527
+ .action = .set_composition,
528
+ .text = "ne",
529
+ });
530
+ _ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, canvas_label, .{
531
+ .id = field_id,
532
+ .action = .commit_composition,
533
+ });
534
+ try std.testing.expectEqualStrings("brassne", app_state.model.queryText());
535
+ // Both composition edits reached the model's `on_input` mirror.
536
+ try std.testing.expect(app_state.model.query_edits > edits_after_set_text);
537
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
538
+
539
+ recorder.finish();
540
+ try std.testing.expect(!recorder.failed);
541
+ const recorded_model = app_state.model;
542
+ const recorded_fingerprint = harness.runtime.sessionStateFingerprint();
543
+
544
+ // The journal carries one record per AX action — platform events
545
+ // AND direct verb calls — and none of their synthesized key/text/ime
546
+ // children.
547
+ var reader = try journal.Reader.init(buffer.journalBytes());
548
+ var action_records: usize = 0;
549
+ while (try reader.next()) |record| {
550
+ if (record != .event) continue;
551
+ switch (record.event) {
552
+ .widget_accessibility_action => action_records += 1,
553
+ .gpu_surface_input => |input| switch (input.kind) {
554
+ .ime_set_composition, .ime_commit_composition, .ime_cancel_composition, .key_down, .text_input => return error.SynthesizedChildJournaled,
555
+ else => {},
556
+ },
557
+ else => {},
558
+ }
559
+ }
560
+ try std.testing.expectEqual(@as(usize, 6), action_records);
561
+
562
+ // Replay into a fresh app: every counter must match exactly — a
563
+ // double-dispatched child shows up as +1 on `count` or extra
564
+ // `query_edits`.
565
+ const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
566
+ try std.testing.expect(replayed.report.ok());
567
+ try std.testing.expectEqual(@as(u32, 2), replayed.model.count);
568
+ try std.testing.expectEqual(recorded_model.query_edits, replayed.model.query_edits);
569
+ try std.testing.expectEqualDeep(recorded_model, replayed.model);
570
+ try std.testing.expectEqual(recorded_fingerprint, replayed.fingerprint);
571
+ }
572
+
573
+ /// Shared scaffold for the direct-verb replay tests: recorder, harness,
574
+ /// started app, one presented frame, and the two editors' widget ids.
575
+ const DirectVerbSession = struct {
576
+ recorder: *session_record.SessionRecorder,
577
+ harness: *core.TestHarness(),
578
+ app_state: *SessionApp,
579
+ app: core.App,
580
+ search_id: canvas.ObjectId,
581
+ name_id: canvas.ObjectId,
582
+
583
+ fn start(gpa: std.mem.Allocator, buffer: *JournalBuffer) !DirectVerbSession {
584
+ const recorder = try std.heap.page_allocator.create(session_record.SessionRecorder);
585
+ errdefer std.heap.page_allocator.destroy(recorder);
586
+ recorder.* = session_record.SessionRecorder.init(buffer.sink());
587
+ recorder.begin(.{ .platform_name = "test", .app_name = "session-demo", .window_width = 400, .window_height = 300 });
588
+
589
+ const harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
590
+ errdefer harness.destroy(gpa);
591
+ harness.null_platform.gpu_surfaces = true;
592
+ harness.runtime.options.session_recorder = recorder;
593
+
594
+ const app_state = try gpa.create(SessionApp);
595
+ errdefer gpa.destroy(app_state);
596
+ app_state.* = SessionApp.init(std.heap.page_allocator, .{}, sessionOptions());
597
+ app_state.effects.executor = .fake;
598
+ const app = app_state.app();
599
+
600
+ try harness.start(app);
601
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
602
+ .label = canvas_label,
603
+ .size = geometry.SizeF.init(400, 300),
604
+ .scale_factor = 2,
605
+ .frame_index = 1,
606
+ .timestamp_ns = 1_000_000,
607
+ } });
608
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
609
+
610
+ const layout = try harness.runtime.canvasWidgetLayout(1, canvas_label);
611
+ var search_id: canvas.ObjectId = 0;
612
+ var name_id: canvas.ObjectId = 0;
613
+ for (layout.nodes) |node| {
614
+ if (node.widget.kind == .search_field) search_id = node.widget.id;
615
+ if (node.widget.kind == .text_field) name_id = node.widget.id;
616
+ }
617
+ try std.testing.expect(search_id != 0);
618
+ try std.testing.expect(name_id != 0);
619
+
620
+ return .{
621
+ .recorder = recorder,
622
+ .harness = harness,
623
+ .app_state = app_state,
624
+ .app = app,
625
+ .search_id = search_id,
626
+ .name_id = name_id,
627
+ };
628
+ }
629
+
630
+ fn destroy(self: *const DirectVerbSession, gpa: std.mem.Allocator) void {
631
+ self.app_state.deinit();
632
+ gpa.destroy(self.app_state);
633
+ self.harness.destroy(gpa);
634
+ std.heap.page_allocator.destroy(self.recorder);
635
+ }
636
+ };
637
+
638
+ /// The direct-verb journal must carry the AX action records and NONE of
639
+ /// their synthesized children — a child record is exactly the stray
640
+ /// input that replays against the wrong focus.
641
+ fn expectActionOnlyJournal(journal_bytes: []const u8, expected_actions: usize) !void {
642
+ var reader = try journal.Reader.init(journal_bytes);
643
+ var action_records: usize = 0;
644
+ while (try reader.next()) |record| {
645
+ if (record != .event) continue;
646
+ switch (record.event) {
647
+ .widget_accessibility_action => action_records += 1,
648
+ .gpu_surface_input => |input| switch (input.kind) {
649
+ .ime_set_composition, .ime_commit_composition, .ime_cancel_composition, .key_down, .text_input => return error.SynthesizedChildJournaled,
650
+ else => {},
651
+ },
652
+ else => {},
653
+ }
654
+ }
655
+ try std.testing.expectEqual(expected_actions, action_records);
656
+ }
657
+
658
+ test "a direct-verb composition first in a session replays onto its target editor" {
659
+ // The P1 this pins: a direct-verb call (embed `widgetAction`,
660
+ // automation `widget_action`) journaled only its synthesized ime
661
+ // children — untargeted inputs routed by focus — while the verb's
662
+ // own focus write never reached the journal. A composition as the
663
+ // FIRST action of a session therefore replayed against a fresh
664
+ // runtime with NO focused editor and the text vanished (the old
665
+ // test passed only because earlier journaled AX records happened to
666
+ // re-focus the same field). The synthetic outer record replays the
667
+ // verb, which re-runs the focus.
668
+ const gpa = std.testing.allocator;
669
+ const buffer = try std.heap.page_allocator.create(JournalBuffer);
670
+ defer std.heap.page_allocator.destroy(buffer);
671
+ buffer.len = 0;
672
+
673
+ const session = try DirectVerbSession.start(gpa, buffer);
674
+ defer session.destroy(gpa);
675
+
676
+ _ = try session.harness.runtime.dispatchCanvasWidgetAccessibilityAction(session.app, 1, canvas_label, .{
677
+ .id = session.search_id,
678
+ .action = .set_composition,
679
+ .text = "ne",
680
+ });
681
+ _ = try session.harness.runtime.dispatchCanvasWidgetAccessibilityAction(session.app, 1, canvas_label, .{
682
+ .id = session.search_id,
683
+ .action = .commit_composition,
684
+ });
685
+ try std.testing.expectEqualStrings("ne", session.app_state.model.queryText());
686
+ try session.harness.runtime.dispatchPlatformEvent(session.app, .frame_requested);
687
+
688
+ session.recorder.finish();
689
+ try std.testing.expect(!session.recorder.failed);
690
+ try expectActionOnlyJournal(buffer.journalBytes(), 2);
691
+
692
+ const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
693
+ try std.testing.expect(replayed.report.ok());
694
+ try std.testing.expectEqualStrings("ne", replayed.model.queryText());
695
+ try std.testing.expectEqualDeep(session.app_state.model, replayed.model);
696
+ try std.testing.expectEqual(session.harness.runtime.sessionStateFingerprint(), replayed.fingerprint);
697
+ }
698
+
699
+ test "a direct-verb composition targets its editor while another field holds focus" {
700
+ // Focus field B (a real journaled click), then compose into field A
701
+ // through the direct verb surface. Live, the verb re-focuses A; a
702
+ // replay that only saw the ime children would deliver them to B —
703
+ // the field the session left focused — writing the text into the
704
+ // wrong editor. The outer record re-runs the verb against A.
705
+ const gpa = std.testing.allocator;
706
+ const buffer = try std.heap.page_allocator.create(JournalBuffer);
707
+ defer std.heap.page_allocator.destroy(buffer);
708
+ buffer.len = 0;
709
+
710
+ const session = try DirectVerbSession.start(gpa, buffer);
711
+ defer session.destroy(gpa);
712
+
713
+ const layout = try session.harness.runtime.canvasWidgetLayout(1, canvas_label);
714
+ const search_frame = layout.findById(session.search_id).?.frame;
715
+ try session.harness.runtime.dispatchPlatformEvent(session.app, .{ .gpu_surface_input = .{
716
+ .window_id = 1,
717
+ .label = canvas_label,
718
+ .kind = .pointer_down,
719
+ .x = search_frame.x + search_frame.width * 0.5,
720
+ .y = search_frame.y + search_frame.height * 0.5,
721
+ } });
722
+ try session.harness.runtime.dispatchPlatformEvent(session.app, .frame_requested);
723
+
724
+ _ = try session.harness.runtime.dispatchCanvasWidgetAccessibilityAction(session.app, 1, canvas_label, .{
725
+ .id = session.name_id,
726
+ .action = .set_composition,
727
+ .text = "ada",
728
+ });
729
+ _ = try session.harness.runtime.dispatchCanvasWidgetAccessibilityAction(session.app, 1, canvas_label, .{
730
+ .id = session.name_id,
731
+ .action = .commit_composition,
732
+ });
733
+ try std.testing.expectEqualStrings("ada", session.app_state.model.nameText());
734
+ try std.testing.expectEqualStrings("", session.app_state.model.queryText());
735
+ try session.harness.runtime.dispatchPlatformEvent(session.app, .frame_requested);
736
+
737
+ session.recorder.finish();
738
+ try std.testing.expect(!session.recorder.failed);
739
+ try expectActionOnlyJournal(buffer.journalBytes(), 2);
740
+
741
+ const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
742
+ try std.testing.expect(replayed.report.ok());
743
+ // The composition landed on A, and B stayed clean — the wrong-focus
744
+ // failure writes "ada" into `query` instead.
745
+ try std.testing.expectEqualStrings("ada", replayed.model.nameText());
746
+ try std.testing.expectEqualStrings("", replayed.model.queryText());
747
+ try std.testing.expectEqualDeep(session.app_state.model, replayed.model);
748
+ try std.testing.expectEqual(session.harness.runtime.sessionStateFingerprint(), replayed.fingerprint);
749
+ }
750
+
751
+ test "a direct-surface set_text first in a session replays onto its target editor" {
752
+ // Same hole, set_text shape: the direct verb journaled a select-all
753
+ // key plus a text input — both routed by focus — so first-in-session
754
+ // they replayed into nothing. One outer record, replayed through the
755
+ // verb, re-runs focus + select-all + insert exactly as live.
756
+ const gpa = std.testing.allocator;
757
+ const buffer = try std.heap.page_allocator.create(JournalBuffer);
758
+ defer std.heap.page_allocator.destroy(buffer);
759
+ buffer.len = 0;
760
+
761
+ const session = try DirectVerbSession.start(gpa, buffer);
762
+ defer session.destroy(gpa);
763
+
764
+ _ = try session.harness.runtime.dispatchCanvasWidgetAccessibilityAction(session.app, 1, canvas_label, .{
765
+ .id = session.search_id,
766
+ .action = .set_text,
767
+ .text = "glass",
768
+ });
769
+ try std.testing.expectEqualStrings("glass", session.app_state.model.queryText());
770
+ try session.harness.runtime.dispatchPlatformEvent(session.app, .frame_requested);
771
+
772
+ session.recorder.finish();
773
+ try std.testing.expect(!session.recorder.failed);
774
+ try expectActionOnlyJournal(buffer.journalBytes(), 1);
775
+
776
+ const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
777
+ try std.testing.expect(replayed.report.ok());
778
+ try std.testing.expectEqualStrings("glass", replayed.model.queryText());
779
+ try std.testing.expectEqualDeep(session.app_state.model, replayed.model);
780
+ try std.testing.expectEqual(session.harness.runtime.sessionStateFingerprint(), replayed.fingerprint);
781
+ }
782
+
330
783
  test "a truncated journal is refused loudly" {
331
784
  const gpa = std.testing.allocator;
332
785
  const buffer = try std.heap.page_allocator.create(JournalBuffer);