@native-sdk/cli 0.5.2 → 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.
- package/build/app.zig +41 -1
- package/build.zig +264 -3
- package/native-sdk.d.ts +17 -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 +138 -3
- package/packages/core/sdk/core.ts +225 -3
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +2625 -262
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +4 -2
- package/skill-data/ts-core/SKILL.md +9 -1
- package/src/app_runner/root.zig +106 -1
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +187 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/linux/gtk_host.c +112 -3
- package/src/platform/linux/root.zig +71 -0
- package/src/platform/macos/appkit_host.h +59 -2
- package/src/platform/macos/appkit_host.m +663 -34
- package/src/platform/macos/cef_host.mm +262 -10
- package/src/platform/macos/root.zig +126 -4
- package/src/platform/null_platform.zig +298 -5
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +36 -0
- package/src/platform/types.zig +247 -8
- package/src/platform/windows/root.zig +134 -0
- package/src/platform/windows/webview2_host.cpp +152 -40
- 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/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +25 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/ui.zig +46 -9
- package/src/primitives/canvas/ui_markup.zig +82 -34
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
- package/src/primitives/canvas/ui_markup_contract.zig +10 -1
- package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_tests.zig +55 -9
- package/src/primitives/canvas/ui_markup_view.zig +81 -14
- package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
- package/src/primitives/canvas/ui_schema.zig +29 -0
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
- package/src/primitives/canvas/widget_layout.zig +9 -4
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widgets.zig +16 -0
- package/src/root.zig +12 -0
- package/src/runtime/api.zig +15 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +64 -0
- package/src/runtime/bridge_payload.zig +7 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +711 -5
- package/src/runtime/canvas_fonts.zig +120 -25
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +221 -0
- package/src/runtime/canvas_images.zig +78 -19
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +24 -4
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +148 -9
- package/src/runtime/effects.zig +1664 -43
- 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_tests.zig +153 -0
- package/src/runtime/flow.zig +44 -0
- package/src/runtime/gpu_surface_events.zig +7 -0
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +20 -0
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +111 -20
- package/src/runtime/session_record.zig +27 -2
- package/src/runtime/session_replay.zig +168 -16
- package/src/runtime/session_tests.zig +2118 -4
- package/src/runtime/shell_layout.zig +7 -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 +3 -0
- package/src/runtime/ts_core_host.zig +439 -4
- package/src/runtime/ts_core_host_tests.zig +41 -0
- package/src/runtime/ts_ui_app.zig +63 -0
- package/src/runtime/ui_app.zig +169 -6
- package/src/runtime/ui_app_tests.zig +334 -0
- package/src/runtime/ui_app_window_tests.zig +468 -0
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +32 -0
- package/src/runtime/window_views.zig +61 -1
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +219 -1
|
@@ -405,6 +405,21 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
405
405
|
}
|
|
406
406
|
if (pane_count != 2) fail(node, markup.split_children_message);
|
|
407
407
|
}
|
|
408
|
+
// Interpreter parity: the image leaf's static shape.
|
|
409
|
+
// Without its id binding the leaf can never draw —
|
|
410
|
+
// statically dead markup, a compile error here too. And
|
|
411
|
+
// it takes no children at all (icon's leaf policy): the
|
|
412
|
+
// check reads the ORIGINAL node, so an extracted
|
|
413
|
+
// context-menu still counts as a child exactly like the
|
|
414
|
+
// validator's raw-node check.
|
|
415
|
+
if (kind == .image) {
|
|
416
|
+
if (node.attr("image") == null) {
|
|
417
|
+
fail(node, markup.image_missing_image_message);
|
|
418
|
+
}
|
|
419
|
+
if (node.children.len > 0) {
|
|
420
|
+
fail(node, markup.image_children_message);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
408
423
|
// Interpreter parity: the a11y lint's error half — an
|
|
409
424
|
// unnamed interactive control or a misused role ships a
|
|
410
425
|
// view a screen reader user cannot operate, so it is a
|
|
@@ -1589,6 +1604,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1589
1604
|
};
|
|
1590
1605
|
} else if (comptime std.mem.eql(u8, attribute.name, "image")) {
|
|
1591
1606
|
applyImageAttr(node, attribute.value, entries, ui, model, scope, options);
|
|
1607
|
+
} else if (comptime std.mem.eql(u8, attribute.name, "surface")) {
|
|
1608
|
+
applySurfaceAttr(node, attribute.value, entries, ui, model, scope, options);
|
|
1592
1609
|
} else if (comptime std.mem.eql(u8, attribute.name, "name")) {
|
|
1593
1610
|
// Consumed by the icon branch in buildElement; a
|
|
1594
1611
|
// compile error on any other element (interpreter and
|
|
@@ -1654,20 +1671,47 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1654
1671
|
}
|
|
1655
1672
|
|
|
1656
1673
|
/// Comptime mirror of the interpreter's `applyImageAttr`:
|
|
1657
|
-
/// `image="{binding}"` on avatar resolves to a `u64`
|
|
1658
|
-
/// app registered at runtime —
|
|
1659
|
-
/// binding must produce an integer, all checked at comptime
|
|
1660
|
-
/// the interpreter's messages.
|
|
1674
|
+
/// `image="{binding}"` on avatar and image resolves to a `u64`
|
|
1675
|
+
/// ImageId the app registered at runtime — binding-only, and
|
|
1676
|
+
/// the binding must produce an integer, all checked at comptime
|
|
1677
|
+
/// with the interpreter's messages.
|
|
1661
1678
|
fn applyImageAttr(comptime node: markup.MarkupNode, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
1662
1679
|
comptime {
|
|
1663
|
-
if (!std.mem.eql(u8, node.name, "avatar")) fail(node, markup.
|
|
1664
|
-
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.
|
|
1665
|
-
if (expression != .binding) fail(node, markup.
|
|
1680
|
+
if (!std.mem.eql(u8, node.name, "avatar") and !std.mem.eql(u8, node.name, "image")) fail(node, markup.image_binding_element_message);
|
|
1681
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.image_binding_message);
|
|
1682
|
+
if (expression != .binding) fail(node, markup.image_binding_message);
|
|
1683
|
+
}
|
|
1684
|
+
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1685
|
+
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.image_binding_message);
|
|
1686
|
+
// Range-checked before the u64 cast (the interpreter fails
|
|
1687
|
+
// the same way): a signed model field (`image: i64 = -1`)
|
|
1688
|
+
// can deliver a negative — fail the build, never trap.
|
|
1689
|
+
options.image = switch (bindingValue(node, entries, path, ui, model, scope, true)) {
|
|
1690
|
+
.integer => |int| if (int < 0) runtimeFail(canvas.ImageId, ui) else @intCast(int),
|
|
1691
|
+
else => runtimeFail(canvas.ImageId, ui),
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
/// Comptime mirror of the interpreter's `applySurfaceAttr`:
|
|
1696
|
+
/// `surface="{binding}"` on media-surface resolves to the
|
|
1697
|
+
/// model-owned u64 surface id a producer targets —
|
|
1698
|
+
/// media-surface-only, binding-only, integer-valued, all checked
|
|
1699
|
+
/// at comptime with the interpreter's messages. The id rides
|
|
1700
|
+
/// `options.image` into `Widget.image_id`, the media surface's
|
|
1701
|
+
/// surface-id channel.
|
|
1702
|
+
fn applySurfaceAttr(comptime node: markup.MarkupNode, comptime raw: []const u8, comptime entries: []const ScopeEntry, ui: *Ui, model: *const ModelT, scope: anytype, options: *Ui.ElementOptions) void {
|
|
1703
|
+
comptime {
|
|
1704
|
+
if (!std.mem.eql(u8, node.name, "media-surface")) fail(node, markup.media_surface_surface_element_message);
|
|
1705
|
+
const expression = markup.parseAttrExpression(raw) orelse fail(node, markup.media_surface_surface_message);
|
|
1706
|
+
if (expression != .binding) fail(node, markup.media_surface_surface_message);
|
|
1666
1707
|
}
|
|
1667
1708
|
const path = comptime markup.parseAttrExpression(raw).?.binding;
|
|
1668
|
-
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.
|
|
1709
|
+
comptime requireVariant(pathVariant(node, entries, path, true), &.{.integer}, node, markup.media_surface_surface_message);
|
|
1710
|
+
// Range-checked before the u64 cast (the interpreter fails
|
|
1711
|
+
// the same way): a signed model field (`surface: i64 = -1`)
|
|
1712
|
+
// can deliver a negative — fail the build, never trap.
|
|
1669
1713
|
options.image = switch (bindingValue(node, entries, path, ui, model, scope, true)) {
|
|
1670
|
-
.integer => |int| @intCast(int),
|
|
1714
|
+
.integer => |int| if (int < 0) runtimeFail(canvas.ImageId, ui) else @intCast(int),
|
|
1671
1715
|
else => runtimeFail(canvas.ImageId, ui),
|
|
1672
1716
|
};
|
|
1673
1717
|
}
|
|
@@ -1778,7 +1822,10 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1778
1822
|
|
|
1779
1823
|
fn uiKeyFromValue(value: Value, ui: *Ui) canvas.UiKey {
|
|
1780
1824
|
return switch (value) {
|
|
1781
|
-
|
|
1825
|
+
// Keys are identity, not quantities: a negative integer
|
|
1826
|
+
// id maps bijectively into the u64 key space (the
|
|
1827
|
+
// interpreter's itemKey/attrKey rule), never a trap.
|
|
1828
|
+
.integer => |int| canvas.uiKey(@as(u64, @bitCast(int))),
|
|
1782
1829
|
.string => |text| canvas.uiKey(text),
|
|
1783
1830
|
else => blk: {
|
|
1784
1831
|
ui.failed = true;
|
|
@@ -1977,8 +2024,13 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
1977
2024
|
switch (comptime @typeInfo(T)) {
|
|
1978
2025
|
.int => {
|
|
1979
2026
|
comptime requireVariant(variant, &.{.integer}, node, "payload type does not match the message");
|
|
2027
|
+
// Range-checked against the payload's own integer
|
|
2028
|
+
// type before the cast (the interpreter fails the
|
|
2029
|
+
// same way): a binding's i64 can deliver a negative
|
|
2030
|
+
// to an unsigned payload or overflow a small one.
|
|
2031
|
+
// Signed payloads keep their negative range.
|
|
1980
2032
|
return switch (value) {
|
|
1981
|
-
.integer => |int| @intCast(int),
|
|
2033
|
+
.integer => |int| if (int < std.math.minInt(T) or int > std.math.maxInt(T)) runtimeFail(T, ui) else @intCast(int),
|
|
1982
2034
|
else => runtimeFail(T, ui),
|
|
1983
2035
|
};
|
|
1984
2036
|
},
|
|
@@ -1218,6 +1218,94 @@ test "compiled avatar image binding matches the interpreter and the hand-written
|
|
|
1218
1218
|
try testing.expectEqualStrings("CT", fixture.findByText(empty.root, .avatar, "CT").?.text);
|
|
1219
1219
|
}
|
|
1220
1220
|
|
|
1221
|
+
// ------------------------------- negative id bindings fail, never trap
|
|
1222
|
+
|
|
1223
|
+
const AvatarNegativeCompiled = canvas.CompiledMarkupView(fixture.AvatarModel, fixture.AvatarMsg, fixture.avatar_negative_markup_source);
|
|
1224
|
+
const SurfaceUi = fixture.SurfaceUi;
|
|
1225
|
+
const SurfaceCompiled = canvas.CompiledMarkupView(fixture.SurfaceModel, fixture.SurfaceMsg, fixture.surface_markup_source);
|
|
1226
|
+
const SurfaceNegativeCompiled = canvas.CompiledMarkupView(fixture.SurfaceModel, fixture.SurfaceMsg, fixture.surface_negative_markup_source);
|
|
1227
|
+
|
|
1228
|
+
test "compiled avatar and media-surface id bindings refuse negative model values instead of trapping" {
|
|
1229
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1230
|
+
defer arena_state.deinit();
|
|
1231
|
+
const arena = arena_state.allocator();
|
|
1232
|
+
|
|
1233
|
+
// The u64 surface id resolves like the interpreter's.
|
|
1234
|
+
var ok_ui = SurfaceUi.init(arena);
|
|
1235
|
+
const ok_tree = try ok_ui.finalize(SurfaceCompiled.build(&ok_ui, &fixture.SurfaceModel{}));
|
|
1236
|
+
const surface = ok_tree.root.children[0];
|
|
1237
|
+
try testing.expectEqual(canvas.WidgetKind.media_surface, surface.kind);
|
|
1238
|
+
try testing.expectEqual(@as(canvas.ImageId, 5), surface.image_id);
|
|
1239
|
+
|
|
1240
|
+
// A negative i64 binding into either u64 id seam latches the
|
|
1241
|
+
// failed build (the interpreter's teaching error mirrors it), and
|
|
1242
|
+
// finalize surfaces the failure — never an @intCast trap.
|
|
1243
|
+
var avatar_ui = AvatarUi.init(arena);
|
|
1244
|
+
const avatar_node = AvatarNegativeCompiled.build(&avatar_ui, &fixture.AvatarModel{});
|
|
1245
|
+
try testing.expect(avatar_ui.failed);
|
|
1246
|
+
try testing.expectError(error.OutOfMemory, avatar_ui.finalize(avatar_node));
|
|
1247
|
+
|
|
1248
|
+
var surface_ui = SurfaceUi.init(arena);
|
|
1249
|
+
const surface_node = SurfaceNegativeCompiled.build(&surface_ui, &fixture.SurfaceModel{});
|
|
1250
|
+
try testing.expect(surface_ui.failed);
|
|
1251
|
+
try testing.expectError(error.OutOfMemory, surface_ui.finalize(surface_node));
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// ------------------------------------------------ image leaf id binding
|
|
1255
|
+
|
|
1256
|
+
const ImageLeafUi = fixture.ImageLeafUi;
|
|
1257
|
+
const ImageLeafInterpreter = markup_view.MarkupView(fixture.ImageLeafModel, fixture.ImageLeafMsg);
|
|
1258
|
+
const ImageLeafCompiled = canvas.CompiledMarkupView(fixture.ImageLeafModel, fixture.ImageLeafMsg, fixture.image_markup_source);
|
|
1259
|
+
const ImageLeafNegativeCompiled = canvas.CompiledMarkupView(fixture.ImageLeafModel, fixture.ImageLeafMsg, fixture.image_negative_markup_source);
|
|
1260
|
+
|
|
1261
|
+
test "compiled image leaf binding matches the interpreter and the hand-written view" {
|
|
1262
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1263
|
+
defer arena_state.deinit();
|
|
1264
|
+
const arena = arena_state.allocator();
|
|
1265
|
+
|
|
1266
|
+
const model = fixture.ImageLeafModel{ .cover = 42 };
|
|
1267
|
+
|
|
1268
|
+
var view = try ImageLeafInterpreter.init(arena, fixture.image_markup_source);
|
|
1269
|
+
var interpreted_ui = ImageLeafUi.init(arena);
|
|
1270
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1271
|
+
|
|
1272
|
+
var compiled_ui = ImageLeafUi.init(arena);
|
|
1273
|
+
const compiled = try compiled_ui.finalize(ImageLeafCompiled.build(&compiled_ui, &model));
|
|
1274
|
+
|
|
1275
|
+
var hand_ui = ImageLeafUi.init(arena);
|
|
1276
|
+
const hand = try hand_ui.finalize(fixture.handImageLeafView(&hand_ui, &model));
|
|
1277
|
+
|
|
1278
|
+
try expectSameTree(fixture.ImageLeafMsg, hand, interpreted);
|
|
1279
|
+
try expectSameTree(fixture.ImageLeafMsg, hand, compiled);
|
|
1280
|
+
|
|
1281
|
+
// The field binding and the fn binding both resolve to the
|
|
1282
|
+
// widget's image id at comptime-unrolled access.
|
|
1283
|
+
const cover = compiled.root.children[0];
|
|
1284
|
+
try testing.expectEqual(canvas.WidgetKind.image, cover.kind);
|
|
1285
|
+
try testing.expectEqual(@as(canvas.ImageId, 42), cover.image_id);
|
|
1286
|
+
try testing.expectEqual(@as(canvas.ImageId, 43), compiled.root.children[1].image_id);
|
|
1287
|
+
|
|
1288
|
+
// 0 draws nothing in both engines — the not-loaded-yet state.
|
|
1289
|
+
const empty_model = fixture.ImageLeafModel{};
|
|
1290
|
+
var empty_ui = ImageLeafUi.init(arena);
|
|
1291
|
+
const empty = try empty_ui.finalize(ImageLeafCompiled.build(&empty_ui, &empty_model));
|
|
1292
|
+
try testing.expectEqual(@as(canvas.ImageId, 0), empty.root.children[0].image_id);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
test "compiled image leaf binding refuses negative model values instead of trapping" {
|
|
1296
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1297
|
+
defer arena_state.deinit();
|
|
1298
|
+
const arena = arena_state.allocator();
|
|
1299
|
+
|
|
1300
|
+
// A negative i64 binding into the u64 id seam latches the failed
|
|
1301
|
+
// build (the interpreter's teaching error mirrors it), and
|
|
1302
|
+
// finalize surfaces the failure — never an @intCast trap.
|
|
1303
|
+
var image_ui = ImageLeafUi.init(arena);
|
|
1304
|
+
const image_node = ImageLeafNegativeCompiled.build(&image_ui, &fixture.ImageLeafModel{});
|
|
1305
|
+
try testing.expect(image_ui.failed);
|
|
1306
|
+
try testing.expectError(error.OutOfMemory, image_ui.finalize(image_node));
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1221
1309
|
// ------------------------------------------------------ text wrap parity
|
|
1222
1310
|
|
|
1223
1311
|
const WrapUi = fixture.WrapUi;
|
|
@@ -1193,7 +1193,16 @@ const Checker = struct {
|
|
|
1193
1193
|
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1194
1194
|
if (expression != .binding) continue;
|
|
1195
1195
|
const resolved = try self.resolveBinding(node, expression.binding, true);
|
|
1196
|
-
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.
|
|
1196
|
+
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.image_binding_message);
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
if (std.mem.eql(u8, attribute.name, "surface")) {
|
|
1200
|
+
// Media-surface ids are model integers (engine parity —
|
|
1201
|
+
// the runtime-image-id shape exactly).
|
|
1202
|
+
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1203
|
+
if (expression != .binding) continue;
|
|
1204
|
+
const resolved = try self.resolveBinding(node, expression.binding, true);
|
|
1205
|
+
try self.requireAttrKind(node, attribute, resolved.kind, &.{.integer}, markup.media_surface_surface_message);
|
|
1197
1206
|
continue;
|
|
1198
1207
|
}
|
|
1199
1208
|
if (std.mem.eql(u8, attribute.name, "icon") or
|
|
@@ -719,6 +719,56 @@ test "expression type errors name the model field and its Zig type" {
|
|
|
719
719
|
try testing.expect(std.mem.indexOf(u8, message, "name: []const u8") != null);
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
+
test "the media-surface surface binding checks as a model integer" {
|
|
723
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
724
|
+
defer arena_state.deinit();
|
|
725
|
+
const arena = arena_state.allocator();
|
|
726
|
+
|
|
727
|
+
// An integer-producing binding passes — the exact grammar `native
|
|
728
|
+
// check`'s model-aware pass applies to TS and Zig cores alike.
|
|
729
|
+
const good = try parseFixture(arena,
|
|
730
|
+
\\<column>
|
|
731
|
+
\\ <media-surface surface="{count}" label="Preview" />
|
|
732
|
+
\\</column>
|
|
733
|
+
);
|
|
734
|
+
try testing.expectEqual(null, try contractMessage(arena, good, null));
|
|
735
|
+
|
|
736
|
+
// A non-integer binding is refused with the surface teaching.
|
|
737
|
+
const wrong = try parseFixture(arena,
|
|
738
|
+
\\<column>
|
|
739
|
+
\\ <media-surface surface="{name}" label="Preview" />
|
|
740
|
+
\\</column>
|
|
741
|
+
);
|
|
742
|
+
const message = (try contractMessage(arena, wrong, null)).?;
|
|
743
|
+
try testing.expectEqualStrings(markup.media_surface_surface_message, message);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
test "the image leaf's image binding checks as a model integer" {
|
|
747
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
748
|
+
defer arena_state.deinit();
|
|
749
|
+
const arena = arena_state.allocator();
|
|
750
|
+
|
|
751
|
+
// An integer-producing binding passes on avatar and the image leaf
|
|
752
|
+
// alike — the exact grammar `native check`'s model-aware pass
|
|
753
|
+
// applies to TS and Zig cores.
|
|
754
|
+
const good = try parseFixture(arena,
|
|
755
|
+
\\<column>
|
|
756
|
+
\\ <image image="{count}" label="Cover art" />
|
|
757
|
+
\\ <avatar image="{count}">CT</avatar>
|
|
758
|
+
\\</column>
|
|
759
|
+
);
|
|
760
|
+
try testing.expectEqual(null, try contractMessage(arena, good, null));
|
|
761
|
+
|
|
762
|
+
// A non-integer binding is refused with the image teaching.
|
|
763
|
+
const wrong = try parseFixture(arena,
|
|
764
|
+
\\<column>
|
|
765
|
+
\\ <image image="{name}" label="Cover art" />
|
|
766
|
+
\\</column>
|
|
767
|
+
);
|
|
768
|
+
const message = (try contractMessage(arena, wrong, null)).?;
|
|
769
|
+
try testing.expectEqualStrings(markup.image_binding_message, message);
|
|
770
|
+
}
|
|
771
|
+
|
|
722
772
|
test "app: icon references check against the contract's registered icon list" {
|
|
723
773
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
724
774
|
defer arena_state.deinit();
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//! Compile-cost guard: a deliberately huge `.native` document — well past
|
|
2
|
+
//! 16KB of realistically nested markup — must build through the compiled
|
|
3
|
+
//! engine without the test (or any app) raising `@setEvalBranchQuota`.
|
|
4
|
+
//! Before the fix, `canonicalizeComptime` sized its quota by recursively
|
|
5
|
+
//! measuring the tree INSIDE the quota argument, which evaluates under the
|
|
6
|
+
//! caller's default 1000-backwards-branch budget — so any document past
|
|
7
|
+
//! ~10KB failed to compile with "evaluation exceeded 1000 backwards
|
|
8
|
+
//! branches" while the runtime interpreter handled it fine. The document
|
|
9
|
+
//! now carries `source_bytes` from parse/resolve time (O(1) to read);
|
|
10
|
+
//! this fixture is the regression tripwire for the single-file path, and
|
|
11
|
+
//! the import fixture below pins the resolver's size accounting (the
|
|
12
|
+
//! merged document's `source_bytes` must cover imported template trees,
|
|
13
|
+
//! not just the root file).
|
|
14
|
+
|
|
15
|
+
const std = @import("std");
|
|
16
|
+
const canvas = @import("root.zig");
|
|
17
|
+
const compiled_view = @import("ui_markup_compiled.zig");
|
|
18
|
+
|
|
19
|
+
const Item = struct {
|
|
20
|
+
id: u32,
|
|
21
|
+
name: []const u8,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const Model = struct {
|
|
25
|
+
title: []const u8 = "ops console",
|
|
26
|
+
count: u32 = 3,
|
|
27
|
+
items: []const Item = &.{},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const Msg = union(enum) {
|
|
31
|
+
refresh,
|
|
32
|
+
press: u32,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/// One realistic dashboard section, ~560 bytes of markup: a header row
|
|
36
|
+
/// with an interpolated title, a conditional status line, and a keyed-off
|
|
37
|
+
/// item list with per-item dispatch. Repeated enough times to put the
|
|
38
|
+
/// whole source safely past the old ~10KB comptime cliff.
|
|
39
|
+
fn sectionSource(comptime index: usize) []const u8 {
|
|
40
|
+
return std.fmt.comptimePrint(
|
|
41
|
+
\\ <panel padding="12">
|
|
42
|
+
\\ <row gap="8" cross="center">
|
|
43
|
+
\\ <badge radius="md">Section {d}</badge>
|
|
44
|
+
\\ <text grow="1">{{title}} - block {d} of the oversized regression document, padded with realistic prose so the source passes the old comptime measurement cliff.</text>
|
|
45
|
+
\\ <button size="sm" on-press="refresh">Reload</button>
|
|
46
|
+
\\ </row>
|
|
47
|
+
\\ <if test="{{count}}">
|
|
48
|
+
\\ <text>block {d} has {{count}} pending updates</text>
|
|
49
|
+
\\ </if>
|
|
50
|
+
\\ <for each="items" as="it">
|
|
51
|
+
\\ <row gap="6" cross="center">
|
|
52
|
+
\\ <text grow="1">{{it.name}}</text>
|
|
53
|
+
\\ <button size="sm" on-press="press:{{it.id}}">Open</button>
|
|
54
|
+
\\ </row>
|
|
55
|
+
\\ </for>
|
|
56
|
+
\\ </panel>
|
|
57
|
+
\\
|
|
58
|
+
, .{ index, index, index });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fn hugeSource(comptime sections: usize) []const u8 {
|
|
62
|
+
comptime {
|
|
63
|
+
// Quota for the fixture GENERATOR only (comptime string
|
|
64
|
+
// concatenation over ~20KB); the engine under test must get by on
|
|
65
|
+
// its own derived quotas.
|
|
66
|
+
@setEvalBranchQuota(1_000_000);
|
|
67
|
+
var source: []const u8 = "<column gap=\"8\">\n <text>{title}</text>\n";
|
|
68
|
+
for (0..sections) |index| {
|
|
69
|
+
source = source ++ sectionSource(index);
|
|
70
|
+
}
|
|
71
|
+
return source ++ "</column>\n";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const huge_source = hugeSource(36);
|
|
76
|
+
|
|
77
|
+
fn testItems() []const Item {
|
|
78
|
+
return &.{ .{ .id = 1, .name = "alpha" }, .{ .id = 2, .name = "beta" } };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
test "a 16KB+ document compiles through the compiled engine without raising the eval-branch quota" {
|
|
82
|
+
try std.testing.expect(huge_source.len >= 16_000);
|
|
83
|
+
|
|
84
|
+
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
85
|
+
defer arena_state.deinit();
|
|
86
|
+
const arena = arena_state.allocator();
|
|
87
|
+
|
|
88
|
+
var ui = canvas.Ui(Msg).init(arena);
|
|
89
|
+
const model: Model = .{ .items = testItems() };
|
|
90
|
+
const tree = try ui.finalize(compiled_view.CompiledMarkupView(Model, Msg, huge_source).build(&ui, &model));
|
|
91
|
+
|
|
92
|
+
// The whole document rendered: every section's badge, per-item
|
|
93
|
+
// dispatch from the last section's list, and the conditional branch.
|
|
94
|
+
var badges: usize = 0;
|
|
95
|
+
countKind(tree.root, .badge, &badges);
|
|
96
|
+
try std.testing.expectEqual(@as(usize, 36), badges);
|
|
97
|
+
var buttons: usize = 0;
|
|
98
|
+
countKind(tree.root, .button, &buttons);
|
|
99
|
+
try std.testing.expectEqual(@as(usize, 36 + 36 * 2), buttons);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// A component file carrying one huge template body. The root view is
|
|
103
|
+
/// tiny, so if import resolution failed to count imported sources into
|
|
104
|
+
/// the merged document's `source_bytes`, the canonicalize walk over the
|
|
105
|
+
/// spliced template tree would outrun its quota and this file would not
|
|
106
|
+
/// compile.
|
|
107
|
+
fn hugeTemplateSource(comptime rows: usize) []const u8 {
|
|
108
|
+
comptime {
|
|
109
|
+
@setEvalBranchQuota(1_000_000);
|
|
110
|
+
var source: []const u8 = "<template name=\"big-panel\" args=\"heading\">\n <column gap=\"4\">\n";
|
|
111
|
+
for (0..rows) |index| {
|
|
112
|
+
source = source ++ std.fmt.comptimePrint(
|
|
113
|
+
\\ <row gap="6" cross="center">
|
|
114
|
+
\\ <badge radius="md">{{heading}} {d}</badge>
|
|
115
|
+
\\ <text grow="1">imported row {d}, padded with enough literal prose that the imported file alone crosses the old comptime measurement cliff.</text>
|
|
116
|
+
\\ </row>
|
|
117
|
+
\\
|
|
118
|
+
, .{ index, index });
|
|
119
|
+
}
|
|
120
|
+
return source ++ " </column>\n</template>\n";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const huge_import_sources = [_]canvas.ui_markup.SourceFile{
|
|
125
|
+
.{ .path = "view.native", .source =
|
|
126
|
+
\\<import src="components/big.native"/>
|
|
127
|
+
\\<column gap="8">
|
|
128
|
+
\\ <use template="big-panel" heading="Imported" />
|
|
129
|
+
\\</column>
|
|
130
|
+
},
|
|
131
|
+
.{ .path = "components/big.native", .source = hugeTemplateSource(72) },
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
test "a large imported template compiles through the compiled engine's import resolution" {
|
|
135
|
+
try std.testing.expect(huge_import_sources[1].source.len >= 16_000);
|
|
136
|
+
|
|
137
|
+
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
138
|
+
defer arena_state.deinit();
|
|
139
|
+
const arena = arena_state.allocator();
|
|
140
|
+
|
|
141
|
+
const Compiled = canvas.CompiledMarkupImports(Model, Msg, "view.native", &huge_import_sources);
|
|
142
|
+
var ui = canvas.Ui(Msg).init(arena);
|
|
143
|
+
const model: Model = .{};
|
|
144
|
+
const tree = try ui.finalize(Compiled.build(&ui, &model));
|
|
145
|
+
|
|
146
|
+
var badges: usize = 0;
|
|
147
|
+
countKind(tree.root, .badge, &badges);
|
|
148
|
+
try std.testing.expectEqual(@as(usize, 72), badges);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fn countKind(widget: canvas.Widget, kind: canvas.WidgetKind, total: *usize) void {
|
|
152
|
+
if (widget.kind == kind) total.* += 1;
|
|
153
|
+
for (widget.children) |child| countKind(child, kind, total);
|
|
154
|
+
}
|
|
@@ -673,22 +673,68 @@ test "gap on stacking containers is rejected with the teaching error" {
|
|
|
673
673
|
}
|
|
674
674
|
}
|
|
675
675
|
|
|
676
|
-
test "the
|
|
676
|
+
test "the image attribute validates as one binding on avatar and image" {
|
|
677
677
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
678
678
|
defer arena_state.deinit();
|
|
679
679
|
const arena = arena_state.allocator();
|
|
680
680
|
|
|
681
|
-
// One {binding} on avatar is the whole grammar.
|
|
682
|
-
|
|
683
|
-
|
|
681
|
+
// One {binding} on avatar or the image leaf is the whole grammar.
|
|
682
|
+
const valid = [_][]const u8{
|
|
683
|
+
"<row>\n <avatar image=\"{user_image}\">CT</avatar>\n</row>",
|
|
684
|
+
"<row>\n <image image=\"{cover}\" width=\"120\" height=\"80\" label=\"Cover art\" />\n</row>",
|
|
685
|
+
};
|
|
686
|
+
for (valid) |source| {
|
|
687
|
+
var parser = markup.Parser.init(arena, source);
|
|
688
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
|
|
689
|
+
}
|
|
684
690
|
|
|
685
691
|
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
686
692
|
// Runtime image ids are model data, never markup literals.
|
|
687
|
-
.{ .source = "<row>\n <avatar image=\"7\">CT</avatar>\n</row>", .message = markup.
|
|
688
|
-
.{ .source = "<row>\n <avatar image=\"{a == b}\">CT</avatar>\n</row>", .message = markup.
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
693
|
+
.{ .source = "<row>\n <avatar image=\"7\">CT</avatar>\n</row>", .message = markup.image_binding_message },
|
|
694
|
+
.{ .source = "<row>\n <avatar image=\"{a == b}\">CT</avatar>\n</row>", .message = markup.image_binding_message },
|
|
695
|
+
.{ .source = "<row>\n <image image=\"7\" label=\"Art\" />\n</row>", .message = markup.image_binding_message },
|
|
696
|
+
// Scoped to the two ImageId-drawing widgets: anywhere else the
|
|
697
|
+
// attribute would be silently inert.
|
|
698
|
+
.{ .source = "<row>\n <badge image=\"{user_image}\">3</badge>\n</row>", .message = markup.image_binding_element_message },
|
|
699
|
+
.{ .source = "<column>\n <panel image=\"{user_image}\" />\n</column>", .message = markup.image_binding_element_message },
|
|
700
|
+
// ...and required on the leaf: an unbound image is statically
|
|
701
|
+
// dead markup (avatar keeps its initials fallback instead).
|
|
702
|
+
.{ .source = "<row>\n <image label=\"Art\" />\n</row>", .message = markup.image_missing_image_message },
|
|
703
|
+
// The leaf takes no children (icon's policy): widget layout
|
|
704
|
+
// gives an image no child slots, so a nested caption would
|
|
705
|
+
// silently vanish instead of rendering.
|
|
706
|
+
.{ .source = "<row>\n <image image=\"{cover}\" label=\"Art\"><text>Caption</text></image>\n</row>", .message = markup.image_children_message },
|
|
707
|
+
// ...and the rejection reads the RAW node: an extracted
|
|
708
|
+
// context-menu (host metadata on a pressable host) still counts
|
|
709
|
+
// as a child - the leaf takes no children at all, and both
|
|
710
|
+
// engines check the original node the same way.
|
|
711
|
+
.{ .source = "<row>\n <image image=\"{cover}\" label=\"Art\" on-press=\"refresh\"><context-menu><menu-item on-press=\"refresh\">Reload</menu-item></context-menu></image>\n</row>", .message = markup.image_children_message },
|
|
712
|
+
};
|
|
713
|
+
for (cases) |case| {
|
|
714
|
+
var case_parser = markup.Parser.init(arena, case.source);
|
|
715
|
+
const info = markup.validate(try case_parser.parse()) orelse return error.TestUnexpectedResult;
|
|
716
|
+
try testing.expectEqualStrings(case.message, info.message);
|
|
717
|
+
try testing.expectEqual(@as(usize, 2), info.line);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
test "the media-surface surface attribute validates as one binding, required, media-surface-only" {
|
|
722
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
723
|
+
defer arena_state.deinit();
|
|
724
|
+
const arena = arena_state.allocator();
|
|
725
|
+
|
|
726
|
+
// One {binding} on media-surface is the whole grammar.
|
|
727
|
+
var parser = markup.Parser.init(arena, "<row>\n <media-surface surface=\"{preview}\" label=\"Preview\" />\n</row>");
|
|
728
|
+
try testing.expectEqual(@as(?markup.MarkupErrorInfo, null), markup.validate(try parser.parse()));
|
|
729
|
+
|
|
730
|
+
const cases = [_]struct { source: []const u8, message: []const u8 }{
|
|
731
|
+
// Surface ids are model data, never markup literals.
|
|
732
|
+
.{ .source = "<row>\n <media-surface surface=\"7\" label=\"Preview\" />\n</row>", .message = markup.media_surface_surface_message },
|
|
733
|
+
.{ .source = "<row>\n <media-surface surface=\"{a == b}\" label=\"Preview\" />\n</row>", .message = markup.media_surface_surface_message },
|
|
734
|
+
// Scoped to media-surface: anywhere else it would be inert.
|
|
735
|
+
.{ .source = "<row>\n <panel surface=\"{preview}\" />\n</row>", .message = markup.media_surface_surface_element_message },
|
|
736
|
+
// ...and required: an unbound surface is statically dead markup.
|
|
737
|
+
.{ .source = "<row>\n <media-surface label=\"Preview\" />\n</row>", .message = markup.media_surface_missing_surface_message },
|
|
692
738
|
};
|
|
693
739
|
for (cases) |case| {
|
|
694
740
|
var case_parser = markup.Parser.init(arena, case.source);
|