@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.
- package/build/app.zig +91 -2
- package/build.zig +756 -5
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +19 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +416 -9
- package/packages/core/sdk/core.ts +706 -5
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +3187 -264
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +42 -4
- package/skill-data/ts-core/SKILL.md +13 -3
- package/src/app_runner/root.zig +112 -10
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/tests.zig +119 -1
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +639 -16
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +351 -7
- package/src/platform/macos/appkit_host.h +152 -8
- package/src/platform/macos/appkit_host.m +1816 -100
- package/src/platform/macos/cef_host.mm +372 -11
- package/src/platform/macos/root.zig +379 -11
- package/src/platform/null_platform.zig +696 -9
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +42 -0
- package/src/platform/types.zig +524 -18
- package/src/platform/windows/root.zig +432 -9
- package/src/platform/windows/webview2_host.cpp +482 -45
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +535 -12
- package/src/primitives/canvas/ui_markup.zig +253 -36
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
- package/src/primitives/canvas/ui_markup_contract.zig +89 -6
- package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +178 -9
- package/src/primitives/canvas/ui_markup_view.zig +220 -11
- package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
- package/src/primitives/canvas/ui_schema.zig +110 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -10
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +23 -0
- package/src/runtime/api.zig +76 -5
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +8 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +439 -2
- package/src/runtime/canvas_fonts.zig +61 -6
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_image_tests.zig +195 -0
- package/src/runtime/canvas_images.zig +45 -12
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +131 -13
- package/src/runtime/effects.zig +8136 -180
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +167 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +42 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +36 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +432 -62
- package/src/runtime/session_record.zig +43 -2
- package/src/runtime/session_replay.zig +556 -20
- package/src/runtime/session_tests.zig +2087 -1
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +8 -0
- package/src/runtime/ts_core_host.zig +1320 -45
- package/src/runtime/ts_core_host_tests.zig +1100 -1
- package/src/runtime/ts_ui_app.zig +23 -5
- package/src/runtime/ui_app.zig +2444 -69
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +736 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +77 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +62 -1
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +244 -8
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
//! Comptime layout fingerprints: build identity for wire formats that
|
|
2
|
+
//! never migrate.
|
|
3
|
+
//!
|
|
4
|
+
//! The session journal and the automation dropbox protocol refuse ANY
|
|
5
|
+
//! skew — both sides always rebuild from one checkout, no old shape is
|
|
6
|
+
//! ever read — so an ordered version integer carried no information
|
|
7
|
+
//! ("same or different" is the entire question) while costing two
|
|
8
|
+
//! recurring failures: parallel branches contending for the next
|
|
9
|
+
//! integer, and forgettable bumps. A fingerprint has neither: it is a
|
|
10
|
+
//! Wyhash over a canonical comptime-built DESCRIPTION of the layout
|
|
11
|
+
//! (the ui_schema registry's fingerprint idiom), and because the
|
|
12
|
+
//! description reflects over the actual declared types, a layout change
|
|
13
|
+
//! moves the identity with no manual step.
|
|
14
|
+
//!
|
|
15
|
+
//! `describe` renders a type structurally and deterministically:
|
|
16
|
+
//! integers/floats/bools by name, enums with every field name AND value
|
|
17
|
+
//! (journaled enums ride their declaration-order integers, so a reorder
|
|
18
|
+
//! must move the fingerprint), structs and unions with field names and
|
|
19
|
+
//! recursively-described types in declaration order (a tagged union's
|
|
20
|
+
//! tag enum included, names and values — discriminants are layout when
|
|
21
|
+
//! the tag rides the wire), optionals, arrays with lengths, slices, and
|
|
22
|
+
//! pointers. What reflection cannot see —
|
|
23
|
+
//! hand-written byte layouts inside codecs (bit assignments, chosen
|
|
24
|
+
//! integer widths, framing) — the caller states as deliberate constants
|
|
25
|
+
//! in its description string, with the coupling commented at the codec.
|
|
26
|
+
//!
|
|
27
|
+
//! Fingerprints are combined with a small manual `semantic_epoch` at
|
|
28
|
+
//! each call site: the escape hatch for a change in MEANING that leaves
|
|
29
|
+
//! the bytes identical, which no layout description can see.
|
|
30
|
+
|
|
31
|
+
const std = @import("std");
|
|
32
|
+
|
|
33
|
+
/// Wyhash over a canonical layout description. Stated once so every
|
|
34
|
+
/// fingerprint (and every test perturbing one) agrees on what a
|
|
35
|
+
/// fingerprint is.
|
|
36
|
+
pub fn hash(description: []const u8) u64 {
|
|
37
|
+
return std.hash.Wyhash.hash(0, description);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// A canonical, structural, comptime description of `T`. Two types
|
|
41
|
+
/// describe equal exactly when their declared layouts match — field
|
|
42
|
+
/// names, field order, field types (recursively), enum values, array
|
|
43
|
+
/// lengths. Type NAMES are deliberately not included (a rename that
|
|
44
|
+
/// keeps the shape is not a layout change); field names are (decoders
|
|
45
|
+
/// key meaning off them).
|
|
46
|
+
pub fn describe(comptime T: type) []const u8 {
|
|
47
|
+
comptime {
|
|
48
|
+
@setEvalBranchQuota(200_000);
|
|
49
|
+
switch (@typeInfo(T)) {
|
|
50
|
+
.int, .float => return @typeName(T),
|
|
51
|
+
.bool => return "bool",
|
|
52
|
+
.void => return "void",
|
|
53
|
+
.@"enum" => |info| {
|
|
54
|
+
var out: []const u8 = "enum(" ++ @typeName(info.tag_type) ++ "){";
|
|
55
|
+
for (info.fields) |field| {
|
|
56
|
+
out = out ++ field.name ++ "=" ++ std.fmt.comptimePrint("{d}", .{field.value}) ++ ",";
|
|
57
|
+
}
|
|
58
|
+
return out ++ "}";
|
|
59
|
+
},
|
|
60
|
+
.@"struct" => |info| {
|
|
61
|
+
var out: []const u8 = "struct{";
|
|
62
|
+
for (info.fields) |field| {
|
|
63
|
+
out = out ++ field.name ++ ":" ++ describe(field.type) ++ ",";
|
|
64
|
+
}
|
|
65
|
+
return out ++ "}";
|
|
66
|
+
},
|
|
67
|
+
.@"union" => |info| {
|
|
68
|
+
// A tagged union's discriminant VALUES are layout when
|
|
69
|
+
// the tag rides the wire, so the tag enum (names and
|
|
70
|
+
// values) is part of the description — two unions with
|
|
71
|
+
// identical fields but swapped tag values must never
|
|
72
|
+
// fingerprint equal.
|
|
73
|
+
var out: []const u8 = if (info.tag_type) |tag|
|
|
74
|
+
"union(" ++ describe(tag) ++ "){"
|
|
75
|
+
else
|
|
76
|
+
"union{";
|
|
77
|
+
for (info.fields) |field| {
|
|
78
|
+
out = out ++ field.name ++ ":" ++ describe(field.type) ++ ",";
|
|
79
|
+
}
|
|
80
|
+
return out ++ "}";
|
|
81
|
+
},
|
|
82
|
+
.optional => |info| return "?" ++ describe(info.child),
|
|
83
|
+
.array => |info| return "[" ++ std.fmt.comptimePrint("{d}", .{info.len}) ++ "]" ++ describe(info.child),
|
|
84
|
+
.pointer => |info| switch (info.size) {
|
|
85
|
+
.slice => return "[]" ++ describe(info.child),
|
|
86
|
+
else => return "*" ++ if (info.child == anyopaque) "anyopaque" else describe(info.child),
|
|
87
|
+
},
|
|
88
|
+
.@"opaque" => return @typeName(T),
|
|
89
|
+
else => @compileError("layout fingerprint cannot describe " ++ @typeName(T)),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// -------------------------------------------------------------- tests
|
|
95
|
+
|
|
96
|
+
const testing = std.testing;
|
|
97
|
+
|
|
98
|
+
test "describe renders shape, not names" {
|
|
99
|
+
const A = struct { count: u32, label: []const u8 };
|
|
100
|
+
const B = struct { count: u32, label: []const u8 };
|
|
101
|
+
// Same shape, different type name: identical description.
|
|
102
|
+
try testing.expectEqualStrings(comptime describe(A), comptime describe(B));
|
|
103
|
+
try testing.expectEqualStrings("struct{count:u32,label:[]u8,}", comptime describe(A));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test "an added field moves the fingerprint with no manual step" {
|
|
107
|
+
// The forgettable-bump killer, pinned: a deliberately-different
|
|
108
|
+
// layout (one extra field) through the same description builder
|
|
109
|
+
// yields a different fingerprint.
|
|
110
|
+
const Base = struct { kind: u8, key: u64, payload: []const u8 };
|
|
111
|
+
const Extended = struct { kind: u8, key: u64, payload: []const u8, dropped: u32 };
|
|
112
|
+
try testing.expect(hash(comptime describe(Base)) != hash(comptime describe(Extended)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
test "field renames, reorders, and type changes all move the fingerprint" {
|
|
116
|
+
const Base = struct { width: u32, height: u32 };
|
|
117
|
+
const Renamed = struct { w: u32, height: u32 };
|
|
118
|
+
const Reordered = struct { height: u32, width: u32 };
|
|
119
|
+
const Widened = struct { width: u64, height: u32 };
|
|
120
|
+
const base = hash(comptime describe(Base));
|
|
121
|
+
try testing.expect(base != hash(comptime describe(Renamed)));
|
|
122
|
+
try testing.expect(base != hash(comptime describe(Reordered)));
|
|
123
|
+
try testing.expect(base != hash(comptime describe(Widened)));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
test "enum reorders move the fingerprint (declaration values ride the wire)" {
|
|
127
|
+
const Forward = enum(u8) { header = 1, event = 2 };
|
|
128
|
+
const Swapped = enum(u8) { header = 2, event = 1 };
|
|
129
|
+
try testing.expect(hash(comptime describe(Forward)) != hash(comptime describe(Swapped)));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
test "union tag discriminants move the fingerprint" {
|
|
133
|
+
// Identical field names and payload types, swapped tag VALUES: a
|
|
134
|
+
// serialized tag byte would decode as the wrong variant, so the
|
|
135
|
+
// descriptions must differ.
|
|
136
|
+
const TagForward = enum(u8) { data = 1, closed = 2 };
|
|
137
|
+
const TagSwapped = enum(u8) { data = 2, closed = 1 };
|
|
138
|
+
const Forward = union(TagForward) { data: u32, closed: void };
|
|
139
|
+
const Swapped = union(TagSwapped) { data: u32, closed: void };
|
|
140
|
+
try testing.expect(hash(comptime describe(Forward)) != hash(comptime describe(Swapped)));
|
|
141
|
+
try testing.expectEqualStrings(
|
|
142
|
+
"union(enum(u8){data=1,closed=2,}){data:u32,closed:void,}",
|
|
143
|
+
comptime describe(Forward),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
test "describe reaches through optionals, arrays, slices, and nesting" {
|
|
148
|
+
const Inner = enum(u8) { light, dark };
|
|
149
|
+
const Outer = struct {
|
|
150
|
+
scheme: Inner,
|
|
151
|
+
point: ?struct { x: f32, y: f32 },
|
|
152
|
+
bands: [4]u8,
|
|
153
|
+
paths: []const []const u8,
|
|
154
|
+
handle: ?*anyopaque,
|
|
155
|
+
};
|
|
156
|
+
try testing.expectEqualStrings(
|
|
157
|
+
"struct{scheme:enum(u8){light=0,dark=1,},point:?struct{x:f32,y:f32,},bands:[4]u8,paths:[][]u8,handle:?*anyopaque,}",
|
|
158
|
+
comptime describe(Outer),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
@@ -1,43 +1,79 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
|
+
const layout_fingerprint = @import("layout_fingerprint.zig");
|
|
2
3
|
|
|
3
4
|
pub const default_dir = ".zig-cache/native-sdk-automation";
|
|
4
5
|
pub const max_command_bytes: usize = 16 * 1024 + 64;
|
|
5
6
|
|
|
6
|
-
/// CLI <-> app dropbox protocol
|
|
7
|
-
///
|
|
8
|
-
/// header (`protocol=
|
|
9
|
-
/// its own — so a stale `native` binary driving a
|
|
10
|
-
/// the reverse) fails loudly, naming both
|
|
11
|
-
/// reading yesterday's state.
|
|
12
|
-
/// would misread: the dropbox directory name, the snapshot header/format,
|
|
13
|
-
/// or the command vocabulary.
|
|
7
|
+
/// CLI <-> app dropbox protocol identity. Both binaries bake this
|
|
8
|
+
/// fingerprint at THEIR build time: the app stamps it into every
|
|
9
|
+
/// snapshot header (`protocol=0x...`), the CLI refuses a snapshot whose
|
|
10
|
+
/// fingerprint is not its own — so a stale `native` binary driving a
|
|
11
|
+
/// freshly built app (or the reverse) fails loudly, naming both
|
|
12
|
+
/// fingerprints, instead of silently reading yesterday's state.
|
|
14
13
|
///
|
|
15
|
-
///
|
|
16
|
-
///
|
|
17
|
-
///
|
|
18
|
-
///
|
|
19
|
-
///
|
|
20
|
-
///
|
|
21
|
-
///
|
|
22
|
-
///
|
|
23
|
-
///
|
|
24
|
-
///
|
|
25
|
-
///
|
|
26
|
-
///
|
|
27
|
-
///
|
|
28
|
-
///
|
|
29
|
-
///
|
|
14
|
+
/// This replaces the manually-bumped integer counter the handshake
|
|
15
|
+
/// carried through v8. No skew is ever migrated — both sides always
|
|
16
|
+
/// rebuild from one checkout — so an ORDERED version carried no
|
|
17
|
+
/// information ("same or different" is the entire question) while
|
|
18
|
+
/// costing two recurring failures: parallel branches contending for the
|
|
19
|
+
/// next integer, and forgettable bumps. The fingerprint is a comptime
|
|
20
|
+
/// Wyhash over a canonical description of the protocol surface this
|
|
21
|
+
/// file declares (see `layoutDescription`), so any change to that
|
|
22
|
+
/// surface moves the identity with no manual step.
|
|
23
|
+
///
|
|
24
|
+
/// History of the retired integer counter, kept because the refusal
|
|
25
|
+
/// teachings it produced are still in the field: 1 = the first stamped
|
|
26
|
+
/// version (post-rename dropbox `.zig-cache/native-sdk-automation`,
|
|
27
|
+
/// publisher_pid liveness, stdout payloads). 2 = the gesture verbs
|
|
28
|
+
/// (`widget-hold`, `widget-context-press`) and per-window snapshot
|
|
29
|
+
/// view/widget scoping. 3 = the `profile on|off` verb and the
|
|
30
|
+
/// snapshot's `frame_profile` per-stage timing line. 4 = the
|
|
31
|
+
/// `provenance` verb (widget id or point -> authored markup) and its
|
|
32
|
+
/// `provenance.txt` response artifact, the write-back read half. 5 =
|
|
33
|
+
/// the `widget-context-menu` verb and the snapshot's per-widget
|
|
34
|
+
/// `context_menu=[...]` item listing. 6 = the queued command dropbox:
|
|
35
|
+
/// numbered `command-<n>.txt` entries replace the single-entry
|
|
30
36
|
/// `command.txt` slot that rapid back-to-back writers could overwrite
|
|
31
|
-
/// before the app drained it
|
|
32
|
-
///
|
|
33
|
-
///
|
|
34
|
-
///
|
|
35
|
-
///
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
///
|
|
39
|
-
///
|
|
40
|
-
|
|
37
|
+
/// before the app drained it (snapshots without a `protocol=` field
|
|
38
|
+
/// predate the handshake entirely). 7 = the `widget-pinch` verb. 8 =
|
|
39
|
+
/// context-menu action tokens as per-request generations, not widget
|
|
40
|
+
/// ids — a SEMANTIC break with identical bytes, exactly the shape
|
|
41
|
+
/// `semantic_epoch` now expresses.
|
|
42
|
+
pub const fingerprint: u64 = layout_fingerprint.hash(layoutDescription(semantic_epoch));
|
|
43
|
+
|
|
44
|
+
/// The escape hatch for protocol changes `layoutDescription` cannot
|
|
45
|
+
/// see. Bump this ONLY for: a same-bytes MEANING change (the
|
|
46
|
+
/// per-request context-menu action-token generations were exactly that
|
|
47
|
+
/// — identical layout, values a stale peer could never match), a
|
|
48
|
+
/// snapshot text-format change a stale binary would misread
|
|
49
|
+
/// (snapshot.zig hand-writes that layout), or a verb spelling change in
|
|
50
|
+
/// `Command.parse` (the wire strings live there, not in the `Action`
|
|
51
|
+
/// enum). Declared-shape changes — new verbs, renamed actions, budget
|
|
52
|
+
/// or naming changes — need NO action here: the fingerprint moves on
|
|
53
|
+
/// its own.
|
|
54
|
+
pub const semantic_epoch: u32 = 1;
|
|
55
|
+
|
|
56
|
+
/// The canonical description the protocol fingerprint hashes: the
|
|
57
|
+
/// command vocabulary (the `Action` enum, reflected — names and values,
|
|
58
|
+
/// so additions, removals, renames, and reorders all move the
|
|
59
|
+
/// identity), the `Command` shape, the dropbox directory and
|
|
60
|
+
/// queue-entry naming, and the size budgets. Deliberate constants cover
|
|
61
|
+
/// what reflection cannot see; anything else invisible to this string
|
|
62
|
+
/// is `semantic_epoch`'s job (see its doc).
|
|
63
|
+
fn layoutDescription(comptime epoch: u32) []const u8 {
|
|
64
|
+
comptime {
|
|
65
|
+
@setEvalBranchQuota(200_000);
|
|
66
|
+
return "native-sdk automation protocol layout\n" ++
|
|
67
|
+
std.fmt.comptimePrint("semantic_epoch={d}\n", .{epoch}) ++
|
|
68
|
+
"dropbox_dir=" ++ default_dir ++ "\n" ++
|
|
69
|
+
"queue_entry=" ++ queue_file_prefix ++ "<n>" ++ queue_file_suffix ++ "\n" ++
|
|
70
|
+
std.fmt.comptimePrint("max_command_bytes={d} max_queued_commands={d} max_screenshot_label_bytes={d}\n", .{
|
|
71
|
+
max_command_bytes, max_queued_commands, max_screenshot_label_bytes,
|
|
72
|
+
}) ++
|
|
73
|
+
"actions=" ++ layout_fingerprint.describe(Action) ++ "\n" ++
|
|
74
|
+
"command=" ++ layout_fingerprint.describe(Command) ++ "\n";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
41
77
|
|
|
42
78
|
/// How many commands may sit in the dropbox queue at once. Automation
|
|
43
79
|
/// drivers are scripts, not firehoses: the app drains one command per
|
|
@@ -294,6 +330,19 @@ test "queue entry names round-trip and reject non-queue files" {
|
|
|
294
330
|
try std.testing.expectEqual(@as(?u64, null), queueFileSequence("bridge-response.txt"));
|
|
295
331
|
}
|
|
296
332
|
|
|
333
|
+
test "semantic epoch moves the protocol fingerprint" {
|
|
334
|
+
// Same layout, bumped epoch: the combined identity must move, so a
|
|
335
|
+
// meaning-only change still refuses stale peers loudly.
|
|
336
|
+
const bumped = layout_fingerprint.hash(comptime layoutDescription(semantic_epoch + 1));
|
|
337
|
+
try std.testing.expect(bumped != fingerprint);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
test {
|
|
341
|
+
// The description builder's own suite (including the pinned proof
|
|
342
|
+
// that an added field moves a fingerprint with no manual step).
|
|
343
|
+
_ = layout_fingerprint;
|
|
344
|
+
}
|
|
345
|
+
|
|
297
346
|
test "screenshot file names stay inside the automation directory" {
|
|
298
347
|
var buffer: [128]u8 = undefined;
|
|
299
348
|
try std.testing.expectEqualStrings("screenshot-inbox-canvas.png", try screenshotFileName("inbox-canvas", &buffer));
|
package/src/automation/root.zig
CHANGED
|
@@ -448,7 +448,7 @@ test "server reports pending commands without consuming them" {
|
|
|
448
448
|
|
|
449
449
|
// An empty dropbox is idle, and so is one holding only non-queue
|
|
450
450
|
// files — response artifacts and, pointedly, a retired-v5 writer's
|
|
451
|
-
// `command.txt` slot, which this protocol
|
|
451
|
+
// `command.txt` slot, which this protocol must never consume
|
|
452
452
|
// (acking it would tell that stale CLI its command dispatched).
|
|
453
453
|
try std.testing.expect(!server.hasPendingCommand());
|
|
454
454
|
try writePath(std.testing.io, server.path("command.txt", &path_buffer), "widget-click canvas 7\n");
|
|
@@ -73,11 +73,26 @@ pub const FrameProfile = struct {
|
|
|
73
73
|
/// verb targeted.
|
|
74
74
|
pub const DispatchError = struct {
|
|
75
75
|
timestamp_ns: u64 = 0,
|
|
76
|
-
|
|
76
|
+
event_storage: [max_dispatch_error_event_bytes]u8 = undefined,
|
|
77
|
+
event_len: u8 = 0,
|
|
77
78
|
error_name: []const u8 = "",
|
|
78
79
|
detail_storage: [max_dispatch_error_detail_bytes]u8 = undefined,
|
|
79
80
|
detail_len: u8 = 0,
|
|
80
81
|
|
|
82
|
+
/// The event name is INLINE storage like `detail`, never a borrowed
|
|
83
|
+
/// slice: records are copied by value into a ring that outlives any
|
|
84
|
+
/// caller's buffer, so a name passed from stack or reusable storage
|
|
85
|
+
/// must be owned at record time.
|
|
86
|
+
pub fn event(self: *const DispatchError) []const u8 {
|
|
87
|
+
return self.event_storage[0..self.event_len];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pub fn setEvent(self: *DispatchError, text: []const u8) void {
|
|
91
|
+
const len = @min(text.len, self.event_storage.len);
|
|
92
|
+
@memcpy(self.event_storage[0..len], text[0..len]);
|
|
93
|
+
self.event_len = @intCast(len);
|
|
94
|
+
}
|
|
95
|
+
|
|
81
96
|
pub fn detail(self: *const DispatchError) []const u8 {
|
|
82
97
|
return self.detail_storage[0..self.detail_len];
|
|
83
98
|
}
|
|
@@ -89,6 +104,10 @@ pub const DispatchError = struct {
|
|
|
89
104
|
}
|
|
90
105
|
};
|
|
91
106
|
|
|
107
|
+
/// Event-name bytes kept per degraded dispatch error (a truncated copy,
|
|
108
|
+
/// owned by the record — the ring outlives every caller's buffer).
|
|
109
|
+
pub const max_dispatch_error_event_bytes: usize = 64;
|
|
110
|
+
|
|
92
111
|
/// Detail context kept per degraded dispatch error (a truncated copy of
|
|
93
112
|
/// the failing automation command's arguments).
|
|
94
113
|
pub const max_dispatch_error_detail_bytes: usize = 48;
|
|
@@ -238,6 +257,29 @@ pub const Audio = struct {
|
|
|
238
257
|
spectrum_bands: []const u8 = &.{},
|
|
239
258
|
};
|
|
240
259
|
|
|
260
|
+
/// Live video playback state (the effects channel's single player), as
|
|
261
|
+
/// the runtime last mirrored it — the audio snapshot's twin. The
|
|
262
|
+
/// advancing `position_ms` and the `.loaded` dimensions are the
|
|
263
|
+
/// automation-visible evidence a video is actually decoding; `surface`
|
|
264
|
+
/// names the media-surface texture channel its frames feed. Like the
|
|
265
|
+
/// media-surface texture itself, this line prints in the FULL snapshot
|
|
266
|
+
/// only, never the a11y text session fingerprints hash — playback
|
|
267
|
+
/// transport is journaled effect truth, not tree state, so a replay
|
|
268
|
+
/// with no producer stays fingerprint-identical by construction.
|
|
269
|
+
pub const Video = struct {
|
|
270
|
+
key: u64 = 0,
|
|
271
|
+
surface: u64 = 0,
|
|
272
|
+
playing: bool = false,
|
|
273
|
+
buffering: bool = false,
|
|
274
|
+
looping: bool = false,
|
|
275
|
+
muted: bool = false,
|
|
276
|
+
source: []const u8 = "local",
|
|
277
|
+
position_ms: u64 = 0,
|
|
278
|
+
duration_ms: u64 = 0,
|
|
279
|
+
width: u64 = 0,
|
|
280
|
+
height: u64 = 0,
|
|
281
|
+
};
|
|
282
|
+
|
|
241
283
|
pub const Input = struct {
|
|
242
284
|
windows: []const Window,
|
|
243
285
|
views: []const platform.ViewInfo = &.{},
|
|
@@ -263,6 +305,8 @@ pub const Input = struct {
|
|
|
263
305
|
/// Live audio playback, when the app started any (null once stopped
|
|
264
306
|
/// or failed — an idle player is honest, not zeroed-out noise).
|
|
265
307
|
audio: ?Audio = null,
|
|
308
|
+
/// Live video playback, same contract as `audio`.
|
|
309
|
+
video: ?Video = null,
|
|
266
310
|
/// The most recent degraded dispatch errors, oldest first (bounded
|
|
267
311
|
/// ring; `diagnostics.dispatch_error_count` is the lifetime total).
|
|
268
312
|
errors: []const DispatchError = &.{},
|
|
@@ -271,11 +315,11 @@ pub const Input = struct {
|
|
|
271
315
|
|
|
272
316
|
pub fn writeText(input: Input, writer: anytype) !void {
|
|
273
317
|
// `protocol=` is the CLI/app handshake: the publishing app
|
|
274
|
-
// stamps ITS baked-in protocol
|
|
275
|
-
// (or a stale app) is refused loudly instead of silently
|
|
276
|
-
// yesterday's dropbox shape.
|
|
277
|
-
try writer.print("ready=true protocol={
|
|
278
|
-
protocol.
|
|
318
|
+
// stamps ITS baked-in protocol fingerprint so a stale `native`
|
|
319
|
+
// binary (or a stale app) is refused loudly instead of silently
|
|
320
|
+
// driving yesterday's dropbox shape.
|
|
321
|
+
try writer.print("ready=true protocol=0x{x:0>16} frame={d} commands={d} runtime_uptime_ns={d} dispatch_errors={d} dropped_trace_records={d} publisher_pid={d} markup_watch={s}\n", .{
|
|
322
|
+
protocol.fingerprint,
|
|
279
323
|
input.diagnostics.frame_index,
|
|
280
324
|
input.diagnostics.command_count,
|
|
281
325
|
input.diagnostics.runtime_uptime_ns,
|
|
@@ -577,17 +621,32 @@ pub fn writeText(input: Input, writer: anytype) !void {
|
|
|
577
621
|
}
|
|
578
622
|
try writer.print("\n", .{});
|
|
579
623
|
}
|
|
624
|
+
if (input.video) |video| {
|
|
625
|
+
try writer.print("video key={d} surface={d} state={s} source={s} position_ms={d} duration_ms={d} dimensions={d}x{d} loop={any} muted={any}\n", .{
|
|
626
|
+
video.key,
|
|
627
|
+
video.surface,
|
|
628
|
+
// The audio line's honest third state, verbatim.
|
|
629
|
+
if (video.buffering) "buffering" else if (video.playing) "playing" else "paused",
|
|
630
|
+
video.source,
|
|
631
|
+
video.position_ms,
|
|
632
|
+
video.duration_ms,
|
|
633
|
+
video.width,
|
|
634
|
+
video.height,
|
|
635
|
+
video.looping,
|
|
636
|
+
video.muted,
|
|
637
|
+
});
|
|
638
|
+
}
|
|
580
639
|
for (input.errors) |dispatch_error| {
|
|
581
640
|
if (dispatch_error.detail_len > 0) {
|
|
582
641
|
try writer.print(" error event={s} name={s} detail=\"{s}\" timestamp_ns={d}\n", .{
|
|
583
|
-
dispatch_error.event,
|
|
642
|
+
dispatch_error.event(),
|
|
584
643
|
dispatch_error.error_name,
|
|
585
644
|
dispatch_error.detail(),
|
|
586
645
|
dispatch_error.timestamp_ns,
|
|
587
646
|
});
|
|
588
647
|
} else {
|
|
589
648
|
try writer.print(" error event={s} name={s} timestamp_ns={d}\n", .{
|
|
590
|
-
dispatch_error.event,
|
|
649
|
+
dispatch_error.event(),
|
|
591
650
|
dispatch_error.error_name,
|
|
592
651
|
dispatch_error.timestamp_ns,
|
|
593
652
|
});
|
|
@@ -809,7 +868,7 @@ test "snapshot emits window and source" {
|
|
|
809
868
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "runtime_uptime_ns=42") != null);
|
|
810
869
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "publisher_pid=4242") != null);
|
|
811
870
|
var protocol_field_buffer: [32]u8 = undefined;
|
|
812
|
-
const protocol_field = try std.fmt.bufPrint(&protocol_field_buffer, "protocol={
|
|
871
|
+
const protocol_field = try std.fmt.bufPrint(&protocol_field_buffer, "protocol=0x{x:0>16} ", .{protocol.fingerprint});
|
|
813
872
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), protocol_field) != null);
|
|
814
873
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "@w1") != null);
|
|
815
874
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "view @w1/main kind=webview") != null);
|
|
@@ -134,7 +134,7 @@ test "watcher requests frames while a command is pending" {
|
|
|
134
134
|
// Idle queue: give the watcher a few polls; no frame requests. A
|
|
135
135
|
// leftover non-queue file (a retired-v5 writer's `command.txt`)
|
|
136
136
|
// stays invisible — the watcher must not wake the loop for traffic
|
|
137
|
-
// this protocol
|
|
137
|
+
// this protocol never consumes.
|
|
138
138
|
var path_buffer: [96]u8 = undefined;
|
|
139
139
|
try cwd.writeFile(std.testing.io, .{
|
|
140
140
|
.sub_path = try std.fmt.bufPrint(&path_buffer, "{s}/command.txt", .{directory}),
|
package/src/embed/host.zig
CHANGED
|
@@ -725,6 +725,11 @@ pub const MobileHostApp = struct {
|
|
|
725
725
|
// below so the runtime's service table starts without audio.
|
|
726
726
|
self.null_platform.audio_playback = false;
|
|
727
727
|
self.null_platform.audio_streaming = false;
|
|
728
|
+
// Video is declined the same way: no mobile shim registers a
|
|
729
|
+
// decoder yet, and the null platform's fake player belongs to
|
|
730
|
+
// hermetic tests — a load that "succeeds" but never decodes
|
|
731
|
+
// would be a lie. Apps hear one honest failed event instead.
|
|
732
|
+
self.null_platform.video_playback = false;
|
|
728
733
|
self.last_error = null;
|
|
729
734
|
self.activation_count = 0;
|
|
730
735
|
self.deactivation_count = 0;
|
package/src/embed/tests.zig
CHANGED
|
@@ -109,9 +109,91 @@ test "embedded app deinit returns registered font bytes across create-destroy cy
|
|
|
109
109
|
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
110
110
|
try std.testing.expectEqual(@as(usize, 1), embedded.runtime.registeredCanvasFontCount());
|
|
111
111
|
try embedded.stop();
|
|
112
|
+
|
|
113
|
+
// Deinit returns BOTH sides of the registration: the Zig-side
|
|
114
|
+
// bytes (the leak-checking allocator above) and the host-side
|
|
115
|
+
// registration — the runtime must call the platform's
|
|
116
|
+
// font-unregister seam per registered id, the call a macOS host
|
|
117
|
+
// answers by dropping its CoreText descriptor and caches. The
|
|
118
|
+
// null platform records that call; the deferred second deinit
|
|
119
|
+
// stays the idempotence backstop.
|
|
120
|
+
embedded.deinit();
|
|
121
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.gpu_surface_font_unregister_count);
|
|
122
|
+
try std.testing.expectEqual(@as(u64, canvas.min_registered_font_id), null_platform.gpu_surface_font_unregister_id);
|
|
123
|
+
// The null platform's register seam is off by default, so the
|
|
124
|
+
// runtime captured ownership token 0 (nothing installed
|
|
125
|
+
// host-side) and the teardown call must carry exactly that.
|
|
126
|
+
try std.testing.expectEqual(@as(u64, 0), null_platform.gpu_surface_font_unregister_token);
|
|
112
127
|
}
|
|
113
128
|
}
|
|
114
129
|
|
|
130
|
+
test "embedded app deinit leaves a newer runtime's re-registration of the same font id intact" {
|
|
131
|
+
// Host font state is per-process while font ids are only permanent
|
|
132
|
+
// per-runtime, so two live runtimes can pass the same id through one
|
|
133
|
+
// host: the later registration wins (the documented lifecycle), and
|
|
134
|
+
// the OLDER runtime's deinit must return only its own already-
|
|
135
|
+
// replaced registration — never the newer runtime's live face,
|
|
136
|
+
// which that runtime's engine still holds and draws through. The
|
|
137
|
+
// null platform's host-font mirror models the stateful host (the
|
|
138
|
+
// shape of macOS's descriptor and token tables): one instance
|
|
139
|
+
// stands in for the process, both runtimes register through it, and
|
|
140
|
+
// the per-registration ownership token is what the unregister guard
|
|
141
|
+
// matches. An id-keyed removal is exactly the regression this test
|
|
142
|
+
// catches — it would empty the mirror at A's deinit and fail the
|
|
143
|
+
// survives assertion below.
|
|
144
|
+
var host_platform = platform.NullPlatform.init(.{});
|
|
145
|
+
host_platform.gpu_surface_font_registrations = true;
|
|
146
|
+
var state_a: u8 = 0;
|
|
147
|
+
var state_b: u8 = 0;
|
|
148
|
+
const embedded_a = try std.testing.allocator.create(EmbeddedApp);
|
|
149
|
+
defer std.testing.allocator.destroy(embedded_a);
|
|
150
|
+
const embedded_b = try std.testing.allocator.create(EmbeddedApp);
|
|
151
|
+
defer std.testing.allocator.destroy(embedded_b);
|
|
152
|
+
embedded_a.initInPlace(.{
|
|
153
|
+
.context = &state_a,
|
|
154
|
+
.name = "embedded-font-owner-a",
|
|
155
|
+
.source = platform.WebViewSource.html("<p>A</p>"),
|
|
156
|
+
}, host_platform.platform());
|
|
157
|
+
defer embedded_a.deinit();
|
|
158
|
+
embedded_b.initInPlace(.{
|
|
159
|
+
.context = &state_b,
|
|
160
|
+
.name = "embedded-font-owner-b",
|
|
161
|
+
.source = platform.WebViewSource.html("<p>B</p>"),
|
|
162
|
+
}, host_platform.platform());
|
|
163
|
+
defer embedded_b.deinit();
|
|
164
|
+
embedded_a.runtime.owned_allocator = std.testing.allocator;
|
|
165
|
+
embedded_b.runtime.owned_allocator = std.testing.allocator;
|
|
166
|
+
|
|
167
|
+
// A registers first, B re-registers the same id: last wins, each
|
|
168
|
+
// runtime captured its own never-repeating ownership token.
|
|
169
|
+
try embedded_a.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
170
|
+
const token_a = embedded_a.runtime.canvas_font_entries[0].host_registration_token;
|
|
171
|
+
try embedded_b.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
172
|
+
const token_b = embedded_b.runtime.canvas_font_entries[0].host_registration_token;
|
|
173
|
+
try std.testing.expect(token_a != 0);
|
|
174
|
+
try std.testing.expect(token_b != 0);
|
|
175
|
+
try std.testing.expect(token_a != token_b);
|
|
176
|
+
const live = host_platform.gpuSurfaceFont(canvas.min_registered_font_id) orelse return error.TestUnexpectedResult;
|
|
177
|
+
try std.testing.expectEqual(token_b, live.token);
|
|
178
|
+
|
|
179
|
+
// A's deinit presents its stale token: recorded and accepted (the
|
|
180
|
+
// registration it owned is already gone), and provably removing
|
|
181
|
+
// nothing — B's registration is still the one the host resolves.
|
|
182
|
+
embedded_a.deinit();
|
|
183
|
+
try std.testing.expectEqual(@as(usize, 1), host_platform.gpu_surface_font_unregister_count);
|
|
184
|
+
try std.testing.expectEqual(@as(u64, canvas.min_registered_font_id), host_platform.gpu_surface_font_unregister_id);
|
|
185
|
+
try std.testing.expectEqual(token_a, host_platform.gpu_surface_font_unregister_token);
|
|
186
|
+
const survivor = host_platform.gpuSurfaceFont(canvas.min_registered_font_id) orelse return error.TestUnexpectedResult;
|
|
187
|
+
try std.testing.expectEqual(token_b, survivor.token);
|
|
188
|
+
|
|
189
|
+
// B's deinit presents the live token and the host state comes out —
|
|
190
|
+
// the guard blocks the wrong owner, not teardown itself.
|
|
191
|
+
embedded_b.deinit();
|
|
192
|
+
try std.testing.expectEqual(@as(usize, 2), host_platform.gpu_surface_font_unregister_count);
|
|
193
|
+
try std.testing.expectEqual(token_b, host_platform.gpu_surface_font_unregister_token);
|
|
194
|
+
try std.testing.expect(host_platform.gpuSurfaceFont(canvas.min_registered_font_id) == null);
|
|
195
|
+
}
|
|
196
|
+
|
|
115
197
|
test "embedded app deinit is idempotent" {
|
|
116
198
|
var null_platform = platform.NullPlatform.init(.{});
|
|
117
199
|
var state: u8 = 0;
|
|
@@ -127,10 +209,46 @@ test "embedded app deinit is idempotent" {
|
|
|
127
209
|
|
|
128
210
|
// The documented idiom is `defer embedded.deinit()`, which must
|
|
129
211
|
// compose with an explicit early teardown: the second call is a
|
|
130
|
-
// no-op, never a double free
|
|
212
|
+
// no-op, never a double free — and never a double host unregister
|
|
213
|
+
// (the first deinit already returned the host-side registration).
|
|
131
214
|
embedded.deinit();
|
|
132
215
|
try std.testing.expectEqual(@as(usize, 0), embedded.runtime.registeredCanvasFontCount());
|
|
216
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.gpu_surface_font_unregister_count);
|
|
217
|
+
embedded.deinit();
|
|
218
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.gpu_surface_font_unregister_count);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
test "embedded app deinit returns the font registration to the platform that received it" {
|
|
222
|
+
// `Runtime.options` is public and mutable, and embedders genuinely
|
|
223
|
+
// swap the platform on a live runtime (tests in this repo do it
|
|
224
|
+
// constantly). The host-side registration must still come back to
|
|
225
|
+
// the host that RECEIVED it: each font entry captures its
|
|
226
|
+
// unregistration owner at registration time (the allocator-identity
|
|
227
|
+
// freeze, applied to the host seam), so a swap between registration
|
|
228
|
+
// and teardown retargets nothing. A deinit reading the live options
|
|
229
|
+
// instead would unregister against the swapped-in platform — the
|
|
230
|
+
// wrong host, or a null seam — and strand the original host's
|
|
231
|
+
// descriptor and caches for the process lifetime.
|
|
232
|
+
var platform_a = platform.NullPlatform.init(.{});
|
|
233
|
+
var platform_b = platform.NullPlatform.init(.{});
|
|
234
|
+
var state: u8 = 0;
|
|
235
|
+
const embedded = try std.testing.allocator.create(EmbeddedApp);
|
|
236
|
+
defer std.testing.allocator.destroy(embedded);
|
|
237
|
+
embedded.initInPlace(.{
|
|
238
|
+
.context = &state,
|
|
239
|
+
.name = "embedded-font-platform-swap",
|
|
240
|
+
.source = platform.WebViewSource.html("<p>Fonts</p>"),
|
|
241
|
+
}, platform_a.platform());
|
|
242
|
+
embedded.runtime.owned_allocator = std.testing.allocator;
|
|
243
|
+
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
244
|
+
|
|
245
|
+
// The swap under test: platform B holds the option by teardown time,
|
|
246
|
+
// but it never saw the registration.
|
|
247
|
+
embedded.runtime.options.platform = platform_b.platform();
|
|
133
248
|
embedded.deinit();
|
|
249
|
+
try std.testing.expectEqual(@as(usize, 1), platform_a.gpu_surface_font_unregister_count);
|
|
250
|
+
try std.testing.expectEqual(@as(u64, canvas.min_registered_font_id), platform_a.gpu_surface_font_unregister_id);
|
|
251
|
+
try std.testing.expectEqual(@as(usize, 0), platform_b.gpu_surface_font_unregister_count);
|
|
134
252
|
}
|
|
135
253
|
|
|
136
254
|
test "mobile C ABI destroy returns registered font bytes through the embedded deinit" {
|
package/src/embed/ui_host.zig
CHANGED
|
@@ -178,6 +178,19 @@ pub fn UiAppHost(comptime AppDef: type) type {
|
|
|
178
178
|
// its heap-owned registrations (registered canvas font
|
|
179
179
|
// bytes) before the host storage goes.
|
|
180
180
|
self.embedded.deinit();
|
|
181
|
+
// The embedded null platform lives inside `self`, so freeing
|
|
182
|
+
// `self` IS this path's platform destruction — and an
|
|
183
|
+
// abandoned channel wake call may still enter that platform
|
|
184
|
+
// at any later time (see
|
|
185
|
+
// `PlatformServices.note_channel_wake_abandoned_fn`; the
|
|
186
|
+
// null platform's own enqueue-only wake never triggers it,
|
|
187
|
+
// but a shim-registered service could). Consult the latch
|
|
188
|
+
// like every first-party destroy path: skip the free and
|
|
189
|
+
// leak the host storage, process-lived, with one loud line.
|
|
190
|
+
if (self.null_platform.channel_wake_abandoned.load(.seq_cst)) {
|
|
191
|
+
std.debug.print("mobile ui host teardown: an abandoned channel wake call may still enter the embedded platform; skipping the host free and leaking it, process-lived, so the stale call stays safe\n", .{});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
181
194
|
std.heap.page_allocator.destroy(self);
|
|
182
195
|
}
|
|
183
196
|
|