@native-sdk/cli 0.4.3 → 0.5.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 +308 -72
- package/build/ts_run.mjs +63 -0
- package/build.zig +336 -7
- package/build.zig.zon +1 -0
- package/package.json +15 -10
- package/packages/core/package-lock.json +43 -0
- package/packages/core/package.json +37 -0
- package/packages/core/rt/rt.zig +1579 -0
- package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
- package/packages/core/sdk/core.ts +694 -0
- package/packages/core/sdk/events.ts +137 -0
- package/packages/core/sdk/text.ts +519 -0
- package/packages/core/src/checker.ts +1869 -0
- package/packages/core/src/cli.ts +68 -0
- package/packages/core/src/devhost.ts +291 -0
- package/packages/core/src/devhost_resolver.mjs +22 -0
- package/packages/core/src/diagnostics.ts +417 -0
- package/packages/core/src/emitter.ts +8815 -0
- package/packages/core/src/infer.ts +1515 -0
- package/packages/core/src/modules.ts +173 -0
- package/packages/core/src/ownership.ts +740 -0
- package/packages/core/src/text_polyfill.ts +337 -0
- package/packages/core/src/text_tables.ts +408 -0
- package/packages/core/src/transpile.ts +146 -0
- package/packages/core/src/typed_ast.ts +536 -0
- package/packages/core/src/types.ts +815 -0
- package/skill-data/core/SKILL.md +3 -0
- package/skill-data/native-ui/SKILL.md +30 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +208 -0
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/root.zig +75 -9
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/platform/linux/gtk_host.c +226 -21
- package/src/platform/windows/webview2_host.cpp +16 -10
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +13 -0
- package/src/primitives/app_manifest/types.zig +14 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/app_manifest/web_layer.zig +366 -0
- package/src/primitives/canvas/commands.zig +14 -7
- package/src/primitives/canvas/lazy_tls.zig +73 -0
- package/src/primitives/canvas/render_generic_resources.zig +22 -15
- package/src/primitives/canvas/root.zig +6 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +40 -32
- package/src/primitives/canvas/text_layout_cache.zig +29 -22
- package/src/primitives/canvas/text_measure_cache.zig +56 -41
- package/src/primitives/canvas/text_spans.zig +39 -26
- package/src/primitives/canvas/tokens.zig +54 -0
- package/src/primitives/canvas/ui.zig +125 -0
- package/src/primitives/canvas/ui_markup.zig +22 -3
- package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
- package/src/primitives/canvas/ui_markup_contract.zig +68 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
- package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
- package/src/primitives/canvas/ui_markup_view.zig +105 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
- package/src/primitives/canvas/ui_schema.zig +8 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_invalidation.zig +14 -7
- package/src/primitives/canvas/widget_render.zig +25 -15
- package/src/primitives/canvas/widget_render_controls.zig +15 -9
- package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +7 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +6 -0
- package/src/runtime/canvas_frame.zig +57 -36
- package/src/runtime/canvas_images.zig +9 -3
- package/src/runtime/canvas_widget_control_tests.zig +5 -6
- package/src/runtime/canvas_widget_runtime.zig +7 -4
- package/src/runtime/effects.zig +490 -2
- package/src/runtime/effects_host_tests.zig +594 -0
- package/src/runtime/flow.zig +8 -0
- package/src/runtime/platform_bridge_tests.zig +1 -0
- package/src/runtime/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- package/src/runtime/session_tests.zig +35 -8
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_core_host.zig +1505 -0
- package/src/runtime/ts_core_host_tests.zig +1408 -0
- package/src/runtime/ts_ui_app.zig +469 -0
- package/src/runtime/ui_app.zig +58 -0
- package/src/runtime/view_canvas.zig +24 -17
- package/src/runtime/view_widget_tree.zig +2 -2
- package/src/runtime/web_layer_gate_tests.zig +242 -0
- package/src/runtime/window_storage.zig +5 -0
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/buildgraph.zig +7 -1
- package/src/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +314 -1
- package/src/tooling/package.zig +722 -18
- package/src/tooling/raw_manifest.zig +16 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +911 -88
- package/src/tooling/ts_core.zig +486 -0
- package/src/tooling/verbs.zig +22 -0
package/src/tooling/manifest.zig
CHANGED
|
@@ -24,11 +24,21 @@ pub const Metadata = struct {
|
|
|
24
24
|
capabilities: []const []const u8 = &.{},
|
|
25
25
|
bridge_commands: []const BridgeCommandMetadata = &.{},
|
|
26
26
|
web_engine: []const u8 = "system",
|
|
27
|
+
/// Whether the app ships the embedded web layer: "auto" (default,
|
|
28
|
+
/// inferred from the manifest's web declarations), "include", or
|
|
29
|
+
/// "exclude". See `webLayer` for the inference.
|
|
30
|
+
webview_layer: []const u8 = "auto",
|
|
27
31
|
/// The built-in theme pack the app selects (`theme = "geist"`).
|
|
28
32
|
/// Optional — absent keeps the house register. Validated against
|
|
29
33
|
/// the known pack names so a typo is a check error, never a silent
|
|
30
34
|
/// default-theme fallback.
|
|
31
35
|
theme: ?[]const u8 = null,
|
|
36
|
+
/// The manifest's one-accent brand override (`theme_accent =
|
|
37
|
+
/// "#df2670"`), layered over the resolved pack by the runtime
|
|
38
|
+
/// (`canvas.accentOverrides`; high contrast skips it). Optional —
|
|
39
|
+
/// absent keeps the pack's own accent. Validated as a #rrggbb hex
|
|
40
|
+
/// color so a typo is a check error, never a silent stock accent.
|
|
41
|
+
theme_accent: ?[]const u8 = null,
|
|
32
42
|
cef: web_engine_tool.CefConfig = .{},
|
|
33
43
|
frontend: ?FrontendMetadata = null,
|
|
34
44
|
security: SecurityMetadata = .{},
|
|
@@ -50,8 +60,10 @@ pub const Metadata = struct {
|
|
|
50
60
|
if (self.display_name) |value| allocator.free(value);
|
|
51
61
|
if (self.description) |value| allocator.free(value);
|
|
52
62
|
if (self.theme) |value| allocator.free(value);
|
|
63
|
+
if (self.theme_accent) |value| allocator.free(value);
|
|
53
64
|
allocator.free(self.version);
|
|
54
65
|
allocator.free(self.web_engine);
|
|
66
|
+
allocator.free(self.webview_layer);
|
|
55
67
|
allocator.free(self.cef.dir);
|
|
56
68
|
for (self.icons) |value| allocator.free(value);
|
|
57
69
|
if (self.icons.len > 0) allocator.free(self.icons);
|
|
@@ -369,6 +381,12 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
|
|
|
369
381
|
.message = "app.zon theme is invalid - expected one of: house, geist",
|
|
370
382
|
};
|
|
371
383
|
}
|
|
384
|
+
if (metadata.theme_accent) |accent| {
|
|
385
|
+
if (!isHexColor(accent)) return .{
|
|
386
|
+
.ok = false,
|
|
387
|
+
.message = "app.zon theme_accent is invalid - expected a #rrggbb hex color (e.g. \"#df2670\")",
|
|
388
|
+
};
|
|
389
|
+
}
|
|
372
390
|
validateIconPaths(metadata.icons) catch return .{ .ok = false, .message = "app.zon icons are invalid" };
|
|
373
391
|
if (try checkIconSources(allocator, io, std.fs.path.dirname(path) orelse ".", metadata.icons)) |icon_message| {
|
|
374
392
|
return .{ .ok = false, .message = icon_message };
|
|
@@ -399,6 +417,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
|
|
|
399
417
|
const url_schemes = parseUrlSchemes(allocator, metadata.url_schemes) catch return .{ .ok = false, .message = "app.zon URL schemes are invalid" };
|
|
400
418
|
defer allocator.free(url_schemes);
|
|
401
419
|
const manifest_web_engine = parseWebEngine(metadata.web_engine) catch return .{ .ok = false, .message = "app.zon web engine is invalid" };
|
|
420
|
+
const manifest_webview_layer = parseWebViewLayer(metadata.webview_layer) catch return .{ .ok = false, .message = "app.zon webview_layer is invalid - expected \"auto\", \"include\", or \"exclude\"" };
|
|
402
421
|
const platform_settings = parsePlatformSettings(allocator, metadata.platforms) catch return .{ .ok = false, .message = "app.zon platforms are invalid" };
|
|
403
422
|
defer allocator.free(platform_settings);
|
|
404
423
|
|
|
@@ -419,9 +438,16 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
|
|
|
419
438
|
.file_associations = file_associations,
|
|
420
439
|
.url_schemes = url_schemes,
|
|
421
440
|
.cef = .{ .dir = metadata.cef.dir, .auto_install = metadata.cef.auto_install },
|
|
441
|
+
.webview_layer = manifest_webview_layer,
|
|
422
442
|
.package = .{ .web_engine = manifest_web_engine },
|
|
423
443
|
};
|
|
424
|
-
app_manifest.validateManifest(manifest) catch return .{
|
|
444
|
+
app_manifest.validateManifest(manifest) catch |err| return .{
|
|
445
|
+
.ok = false,
|
|
446
|
+
.message = switch (err) {
|
|
447
|
+
error.WebViewLayerConflict => web_layer_conflict_message,
|
|
448
|
+
else => "manifest fields failed semantic validation",
|
|
449
|
+
},
|
|
450
|
+
};
|
|
425
451
|
return .{ .ok = true, .message = "app.zon is valid" };
|
|
426
452
|
}
|
|
427
453
|
|
|
@@ -467,6 +493,7 @@ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
|
|
|
467
493
|
.display_name = if (raw.display_name) |value| try allocator.dupe(u8, value) else null,
|
|
468
494
|
.description = if (raw.description) |value| try allocator.dupe(u8, value) else null,
|
|
469
495
|
.theme = if (raw.theme) |value| try allocator.dupe(u8, value) else null,
|
|
496
|
+
.theme_accent = if (raw.theme_accent) |value| try allocator.dupe(u8, value) else null,
|
|
470
497
|
.version = try allocator.dupe(u8, raw.version),
|
|
471
498
|
.icons = try duplicateStringList(allocator, raw.icons),
|
|
472
499
|
.platforms = try duplicateStringList(allocator, raw.platforms),
|
|
@@ -474,6 +501,7 @@ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
|
|
|
474
501
|
.capabilities = try duplicateStringList(allocator, raw.capabilities),
|
|
475
502
|
.bridge_commands = try convertRawBridgeCommands(allocator, raw.bridge.commands),
|
|
476
503
|
.web_engine = try allocator.dupe(u8, raw.web_engine),
|
|
504
|
+
.webview_layer = try allocator.dupe(u8, raw.webview_layer),
|
|
477
505
|
.cef = .{
|
|
478
506
|
.dir = try allocator.dupe(u8, raw.cef.dir),
|
|
479
507
|
.auto_install = raw.cef.auto_install,
|
|
@@ -946,6 +974,17 @@ fn isKnownThemePack(name: []const u8) bool {
|
|
|
946
974
|
return false;
|
|
947
975
|
}
|
|
948
976
|
|
|
977
|
+
/// One #rrggbb hex color — the `theme_accent` shape the runner's
|
|
978
|
+
/// comptime parse accepts (kept in step the same way as the pack names:
|
|
979
|
+
/// a drift is a build error in the app, never a shipped typo).
|
|
980
|
+
fn isHexColor(value: []const u8) bool {
|
|
981
|
+
if (value.len != 7 or value[0] != '#') return false;
|
|
982
|
+
for (value[1..]) |byte| {
|
|
983
|
+
_ = std.fmt.charToDigit(byte, 16) catch return false;
|
|
984
|
+
}
|
|
985
|
+
return true;
|
|
986
|
+
}
|
|
987
|
+
|
|
949
988
|
fn validateIconPaths(icons: []const []const u8) !void {
|
|
950
989
|
for (icons, 0..) |icon, index| {
|
|
951
990
|
try validateRelativePath(icon);
|
|
@@ -1318,6 +1357,113 @@ fn parseWebEngine(value: []const u8) !app_manifest.WebEngine {
|
|
|
1318
1357
|
return error.InvalidWebEngine;
|
|
1319
1358
|
}
|
|
1320
1359
|
|
|
1360
|
+
fn parseWebViewLayer(value: []const u8) !app_manifest.WebViewLayer {
|
|
1361
|
+
if (std.mem.eql(u8, value, "auto")) return .auto;
|
|
1362
|
+
if (std.mem.eql(u8, value, "include")) return .include;
|
|
1363
|
+
if (std.mem.eql(u8, value, "exclude")) return .exclude;
|
|
1364
|
+
return error.InvalidWebViewLayer;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/// The teaching message every boundary prints for the same
|
|
1368
|
+
/// contradiction: a manifest that excludes the web layer while declaring
|
|
1369
|
+
/// web content.
|
|
1370
|
+
pub const web_layer_conflict_message = "app.zon sets .webview_layer = \"exclude\" but the app declares web content (a .frontend block, the \"webview\" capability, a .shell webview view, or the Chromium web engine - from .web_engine or --web-engine) - remove the web declarations or drop the exclude";
|
|
1371
|
+
|
|
1372
|
+
/// The same contradiction arriving through the CLI flag instead of the
|
|
1373
|
+
/// manifest field: `--web-layer exclude` against an app that declares
|
|
1374
|
+
/// web content.
|
|
1375
|
+
pub const web_layer_flag_conflict_message = "--web-layer exclude contradicts the app's web declarations (a .frontend block, the \"webview\" capability, a .shell webview view, or the Chromium web engine - from .web_engine or --web-engine) - remove the web declarations or drop the flag";
|
|
1376
|
+
|
|
1377
|
+
/// Why the web layer is (or is not) in the build, for verdict lines —
|
|
1378
|
+
/// the shared contract's reason set.
|
|
1379
|
+
pub const WebLayerReason = app_manifest.web_layer.Reason;
|
|
1380
|
+
|
|
1381
|
+
/// The layer setting a boundary resolves before deciding: "auto",
|
|
1382
|
+
/// "include", or "exclude" — the shared contract's input enum, exported
|
|
1383
|
+
/// for the CLI's `--web-layer` flag.
|
|
1384
|
+
pub const WebViewLayerSetting = app_manifest.WebViewLayer;
|
|
1385
|
+
|
|
1386
|
+
/// Parse a `--web-layer` flag value (auto|include|exclude), via the
|
|
1387
|
+
/// shared contract so the flag and the app.zon field accept exactly the
|
|
1388
|
+
/// same vocabulary.
|
|
1389
|
+
pub const parseWebViewLayerSetting = app_manifest.web_layer.parseWebViewLayer;
|
|
1390
|
+
|
|
1391
|
+
pub const WebLayer = struct {
|
|
1392
|
+
enabled: bool,
|
|
1393
|
+
reason: WebLayerReason,
|
|
1394
|
+
/// Whether the deciding include/exclude came from the CLI's
|
|
1395
|
+
/// `--web-layer` flag rather than app.zon's `.webview_layer`; only
|
|
1396
|
+
/// meaningful for the declared_include/declared_exclude reasons.
|
|
1397
|
+
from_flag: bool = false,
|
|
1398
|
+
|
|
1399
|
+
/// The parenthesized half of a verdict line: `web layer: none
|
|
1400
|
+
/// (inferred)` / `web layer: webview2 (declared: capabilities)`.
|
|
1401
|
+
pub fn sourceText(self: WebLayer) []const u8 {
|
|
1402
|
+
return switch (self.reason) {
|
|
1403
|
+
.inferred_native_only => "inferred: nothing in app.zon declares web use",
|
|
1404
|
+
.declared_exclude => if (self.from_flag) "declared: --web-layer exclude" else "declared: .webview_layer = \"exclude\"",
|
|
1405
|
+
.capability => "declared: capabilities",
|
|
1406
|
+
.frontend => "declared: .frontend",
|
|
1407
|
+
.shell_webview => "declared: .shell webview view",
|
|
1408
|
+
.chromium_engine => "declared: the Chromium web engine (.web_engine or --web-engine)",
|
|
1409
|
+
.declared_include => if (self.from_flag) "declared: --web-layer include" else "declared: .webview_layer = \"include\"",
|
|
1410
|
+
// Only the build graph's lenient parse can produce this
|
|
1411
|
+
// reason; parsed metadata always reaches this fn readable.
|
|
1412
|
+
.unreadable_manifest => "kept: app.zon could not be parsed",
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
pub const WebLayerError = error{ InvalidWebViewLayer, WebViewLayerConflict };
|
|
1418
|
+
|
|
1419
|
+
/// The CLI-side adapter over the shared web-layer contract
|
|
1420
|
+
/// (app_manifest.web_layer): the same declare-to-use rule the build
|
|
1421
|
+
/// graph and the runner apply, fed the engine this boundary RESOLVED —
|
|
1422
|
+
/// `--web-engine` orelse app.zon, already resolved by the CLI's verb
|
|
1423
|
+
/// handlers. `.webview_layer = "include"|"exclude"` overrides, and an
|
|
1424
|
+
/// exclude that contradicts a web declaration (including a resolved
|
|
1425
|
+
/// Chromium engine) is refused.
|
|
1426
|
+
pub fn webLayer(metadata: Metadata, resolved_engine: web_engine_tool.Engine) WebLayerError!WebLayer {
|
|
1427
|
+
return webLayerResolved(metadata, resolved_engine, null);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/// `webLayer` with the CLI's `--web-layer` flag in play: the flag beats
|
|
1431
|
+
/// app.zon's `.webview_layer` exactly as `-Dweb-layer` beats it in the
|
|
1432
|
+
/// build graph (effective setting = flag orelse manifest), so the build
|
|
1433
|
+
/// graphs can forward their resolved decision and hand-run packages can
|
|
1434
|
+
/// override the field without editing app.zon. An exclude flag against
|
|
1435
|
+
/// a web declaration is the same refused conflict as a manifest exclude.
|
|
1436
|
+
pub fn webLayerResolved(metadata: Metadata, resolved_engine: web_engine_tool.Engine, layer_flag: ?WebViewLayerSetting) WebLayerError!WebLayer {
|
|
1437
|
+
const manifest_setting = parseWebViewLayer(metadata.webview_layer) catch return error.InvalidWebViewLayer;
|
|
1438
|
+
const engine: app_manifest.WebEngine = switch (resolved_engine) {
|
|
1439
|
+
.system => .system,
|
|
1440
|
+
.chromium => .chromium,
|
|
1441
|
+
};
|
|
1442
|
+
const decision = app_manifest.web_layer.infer(metadata, engine, layer_flag orelse manifest_setting) catch return error.WebViewLayerConflict;
|
|
1443
|
+
if (layer_flag != null) {
|
|
1444
|
+
// The flag decides, but the verdict line keeps app.zon's own
|
|
1445
|
+
// richer reason whenever the flag merely confirms what the
|
|
1446
|
+
// manifest already decides: the build graphs forward their
|
|
1447
|
+
// resolved decision on every `zig build package`, and the common
|
|
1448
|
+
// case must keep reporting "declared: capabilities", not the
|
|
1449
|
+
// forwarded flag. Only a flag that CHANGES the outcome names
|
|
1450
|
+
// itself as the cause.
|
|
1451
|
+
if (app_manifest.web_layer.infer(metadata, engine, manifest_setting)) |manifest_decision| {
|
|
1452
|
+
if (manifest_decision.enabled == decision.enabled) {
|
|
1453
|
+
return .{ .enabled = manifest_decision.enabled, .reason = manifest_decision.reason };
|
|
1454
|
+
}
|
|
1455
|
+
} else |_| {}
|
|
1456
|
+
return .{ .enabled = decision.enabled, .reason = decision.reason, .from_flag = true };
|
|
1457
|
+
}
|
|
1458
|
+
return .{ .enabled = decision.enabled, .reason = decision.reason };
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/// The web-layer verdict for callers with no engine flag in play
|
|
1462
|
+
/// (`native check`): the manifest's own engine is the resolved engine.
|
|
1463
|
+
pub fn webLayerFromManifest(metadata: Metadata) WebLayerError!WebLayer {
|
|
1464
|
+
return webLayer(metadata, web_engine_tool.Engine.parse(metadata.web_engine) orelse .system);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1321
1467
|
fn validateRelativePath(path: []const u8) !void {
|
|
1322
1468
|
if (path.len == 0) return error.InvalidPath;
|
|
1323
1469
|
if (path[0] == '/' or path[0] == '\\') return error.InvalidPath;
|
|
@@ -1920,6 +2066,151 @@ test "validate accepts a square icon source and prebuilt containers" {
|
|
|
1920
2066
|
try std.testing.expect(result.ok);
|
|
1921
2067
|
}
|
|
1922
2068
|
|
|
2069
|
+
test "web layer inference is declare-to-use over parsed metadata" {
|
|
2070
|
+
// Nothing declared: native-only.
|
|
2071
|
+
const canvas_capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2072
|
+
const canvas: Metadata = .{ .id = "dev.example.canvas", .name = "canvas", .version = "1.0.0", .capabilities = &canvas_capabilities };
|
|
2073
|
+
const canvas_layer = try webLayerFromManifest(canvas);
|
|
2074
|
+
try std.testing.expect(!canvas_layer.enabled);
|
|
2075
|
+
try std.testing.expectEqual(WebLayerReason.inferred_native_only, canvas_layer.reason);
|
|
2076
|
+
|
|
2077
|
+
// Each web declaration flips the inference.
|
|
2078
|
+
const webview_capabilities = [_][]const u8{"webview"};
|
|
2079
|
+
const by_capability = try webLayerFromManifest(.{ .id = "dev.example.a", .name = "a", .version = "1.0.0", .capabilities = &webview_capabilities });
|
|
2080
|
+
try std.testing.expect(by_capability.enabled);
|
|
2081
|
+
try std.testing.expectEqual(WebLayerReason.capability, by_capability.reason);
|
|
2082
|
+
|
|
2083
|
+
const by_frontend = try webLayerFromManifest(.{ .id = "dev.example.b", .name = "b", .version = "1.0.0", .frontend = .{} });
|
|
2084
|
+
try std.testing.expect(by_frontend.enabled);
|
|
2085
|
+
try std.testing.expectEqual(WebLayerReason.frontend, by_frontend.reason);
|
|
2086
|
+
|
|
2087
|
+
const shell_views = [_]ShellViewMetadata{.{ .label = "content", .kind = "webview", .url = "zero://app/index.html" }};
|
|
2088
|
+
const shell_windows = [_]ShellWindowMetadata{.{ .label = "main", .views = &shell_views }};
|
|
2089
|
+
const by_shell = try webLayerFromManifest(.{ .id = "dev.example.c", .name = "c", .version = "1.0.0", .shell = .{ .windows = &shell_windows } });
|
|
2090
|
+
try std.testing.expect(by_shell.enabled);
|
|
2091
|
+
try std.testing.expectEqual(WebLayerReason.shell_webview, by_shell.reason);
|
|
2092
|
+
|
|
2093
|
+
// The Chromium engine is web intent; the system default alone is not.
|
|
2094
|
+
const by_chromium = try webLayerFromManifest(.{ .id = "dev.example.d", .name = "d", .version = "1.0.0", .web_engine = "chromium" });
|
|
2095
|
+
try std.testing.expect(by_chromium.enabled);
|
|
2096
|
+
try std.testing.expectEqual(WebLayerReason.chromium_engine, by_chromium.reason);
|
|
2097
|
+
|
|
2098
|
+
// The RESOLVED engine decides, not the raw manifest value: a system
|
|
2099
|
+
// manifest packaged with `--web-engine chromium` ships the layer.
|
|
2100
|
+
const by_resolved_chromium = try webLayer(.{ .id = "dev.example.i", .name = "i", .version = "1.0.0" }, .chromium);
|
|
2101
|
+
try std.testing.expect(by_resolved_chromium.enabled);
|
|
2102
|
+
try std.testing.expectEqual(WebLayerReason.chromium_engine, by_resolved_chromium.reason);
|
|
2103
|
+
|
|
2104
|
+
// Explicit overrides.
|
|
2105
|
+
const included = try webLayerFromManifest(.{ .id = "dev.example.e", .name = "e", .version = "1.0.0", .webview_layer = "include" });
|
|
2106
|
+
try std.testing.expect(included.enabled);
|
|
2107
|
+
const excluded = try webLayerFromManifest(.{ .id = "dev.example.f", .name = "f", .version = "1.0.0", .webview_layer = "exclude" });
|
|
2108
|
+
try std.testing.expect(!excluded.enabled);
|
|
2109
|
+
try std.testing.expectEqual(WebLayerReason.declared_exclude, excluded.reason);
|
|
2110
|
+
|
|
2111
|
+
// Contradictions and typos are refused, never resolved silently —
|
|
2112
|
+
// including an exclude against a flag-resolved Chromium engine.
|
|
2113
|
+
try std.testing.expectError(error.WebViewLayerConflict, webLayerFromManifest(.{ .id = "dev.example.g", .name = "g", .version = "1.0.0", .capabilities = &webview_capabilities, .webview_layer = "exclude" }));
|
|
2114
|
+
try std.testing.expectError(error.WebViewLayerConflict, webLayer(.{ .id = "dev.example.j", .name = "j", .version = "1.0.0", .webview_layer = "exclude" }, .chromium));
|
|
2115
|
+
try std.testing.expectError(error.InvalidWebViewLayer, webLayerFromManifest(.{ .id = "dev.example.h", .name = "h", .version = "1.0.0", .webview_layer = "never" }));
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
test "web layer --web-layer flag beats the manifest field like -Dweb-layer does" {
|
|
2119
|
+
const canvas_capabilities = [_][]const u8{ "native_views", "gpu_surfaces" };
|
|
2120
|
+
const canvas: Metadata = .{ .id = "dev.example.canvas", .name = "canvas", .version = "1.0.0", .capabilities = &canvas_capabilities };
|
|
2121
|
+
const webview_capabilities = [_][]const u8{"webview"};
|
|
2122
|
+
const web: Metadata = .{ .id = "dev.example.web", .name = "web", .version = "1.0.0", .capabilities = &webview_capabilities };
|
|
2123
|
+
|
|
2124
|
+
// An include flag that changes the outcome names itself as the cause.
|
|
2125
|
+
const forced_in = try webLayerResolved(canvas, .system, .include);
|
|
2126
|
+
try std.testing.expect(forced_in.enabled);
|
|
2127
|
+
try std.testing.expectEqual(WebLayerReason.declared_include, forced_in.reason);
|
|
2128
|
+
try std.testing.expectEqualStrings("declared: --web-layer include", forced_in.sourceText());
|
|
2129
|
+
|
|
2130
|
+
// A flag that merely confirms the inference keeps the manifest's own
|
|
2131
|
+
// richer reason, so graph-forwarded packages report like hand-run ones.
|
|
2132
|
+
const confirmed = try webLayerResolved(web, .system, .include);
|
|
2133
|
+
try std.testing.expect(confirmed.enabled);
|
|
2134
|
+
try std.testing.expectEqual(WebLayerReason.capability, confirmed.reason);
|
|
2135
|
+
try std.testing.expectEqualStrings("declared: capabilities", confirmed.sourceText());
|
|
2136
|
+
const confirmed_off = try webLayerResolved(canvas, .system, .exclude);
|
|
2137
|
+
try std.testing.expect(!confirmed_off.enabled);
|
|
2138
|
+
try std.testing.expectEqual(WebLayerReason.inferred_native_only, confirmed_off.reason);
|
|
2139
|
+
|
|
2140
|
+
// An exclude flag against a web declaration is the same refused
|
|
2141
|
+
// conflict as a manifest exclude — including a resolved Chromium engine.
|
|
2142
|
+
try std.testing.expectError(error.WebViewLayerConflict, webLayerResolved(web, .system, .exclude));
|
|
2143
|
+
try std.testing.expectError(error.WebViewLayerConflict, webLayerResolved(canvas, .chromium, .exclude));
|
|
2144
|
+
|
|
2145
|
+
// `--web-layer auto` overrides a manifest exclude back to inference,
|
|
2146
|
+
// exactly as `-Dweb-layer=auto` does in the build graph.
|
|
2147
|
+
const reopened = try webLayerResolved(.{ .id = "dev.example.k", .name = "k", .version = "1.0.0", .capabilities = &webview_capabilities, .webview_layer = "exclude" }, .system, .auto);
|
|
2148
|
+
try std.testing.expect(reopened.enabled);
|
|
2149
|
+
try std.testing.expectEqual(WebLayerReason.capability, reopened.reason);
|
|
2150
|
+
|
|
2151
|
+
// No flag: identical to `webLayer` (the manifest field decides).
|
|
2152
|
+
const plain = try webLayerResolved(canvas, .system, null);
|
|
2153
|
+
try std.testing.expect(!plain.enabled);
|
|
2154
|
+
try std.testing.expectEqual(WebLayerReason.inferred_native_only, plain.reason);
|
|
2155
|
+
|
|
2156
|
+
// The flag parser shares the contract's vocabulary.
|
|
2157
|
+
try std.testing.expectEqual(WebViewLayerSetting.include, parseWebViewLayerSetting("include").?);
|
|
2158
|
+
try std.testing.expectEqual(WebViewLayerSetting.exclude, parseWebViewLayerSetting("exclude").?);
|
|
2159
|
+
try std.testing.expectEqual(WebViewLayerSetting.auto, parseWebViewLayerSetting("auto").?);
|
|
2160
|
+
try std.testing.expectEqual(null, parseWebViewLayerSetting("never"));
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
test "validate rejects a web-declaring manifest that excludes the web layer" {
|
|
2164
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
2165
|
+
defer arena.deinit();
|
|
2166
|
+
const gpa = arena.allocator();
|
|
2167
|
+
var cwd = std.Io.Dir.cwd();
|
|
2168
|
+
const root = ".zig-cache/test-validate-web-layer-conflict";
|
|
2169
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2170
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2171
|
+
try cwd.createDirPath(std.testing.io, root);
|
|
2172
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
|
|
2173
|
+
\\.{
|
|
2174
|
+
\\ .id = "dev.example.app",
|
|
2175
|
+
\\ .name = "demo",
|
|
2176
|
+
\\ .version = "1.0.0",
|
|
2177
|
+
\\ .capabilities = .{"webview"},
|
|
2178
|
+
\\ .webview_layer = "exclude",
|
|
2179
|
+
\\}
|
|
2180
|
+
});
|
|
2181
|
+
|
|
2182
|
+
const result = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
|
|
2183
|
+
try std.testing.expect(!result.ok);
|
|
2184
|
+
try std.testing.expect(std.mem.indexOf(u8, result.message, ".webview_layer = \"exclude\"") != null);
|
|
2185
|
+
try std.testing.expect(std.mem.indexOf(u8, result.message, "declares web content") != null);
|
|
2186
|
+
|
|
2187
|
+
// A native-only manifest with the same exclude is valid.
|
|
2188
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
|
|
2189
|
+
\\.{
|
|
2190
|
+
\\ .id = "dev.example.app",
|
|
2191
|
+
\\ .name = "demo",
|
|
2192
|
+
\\ .version = "1.0.0",
|
|
2193
|
+
\\ .capabilities = .{"gpu_surfaces"},
|
|
2194
|
+
\\ .webview_layer = "exclude",
|
|
2195
|
+
\\}
|
|
2196
|
+
});
|
|
2197
|
+
const native_only = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
|
|
2198
|
+
try std.testing.expect(native_only.ok);
|
|
2199
|
+
|
|
2200
|
+
// A typo in the setting is its own teaching error.
|
|
2201
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/app.zon", .data =
|
|
2202
|
+
\\.{
|
|
2203
|
+
\\ .id = "dev.example.app",
|
|
2204
|
+
\\ .name = "demo",
|
|
2205
|
+
\\ .version = "1.0.0",
|
|
2206
|
+
\\ .webview_layer = "never",
|
|
2207
|
+
\\}
|
|
2208
|
+
});
|
|
2209
|
+
const invalid = try validateFile(gpa, std.testing.io, root ++ "/app.zon");
|
|
2210
|
+
try std.testing.expect(!invalid.ok);
|
|
2211
|
+
try std.testing.expect(std.mem.indexOf(u8, invalid.message, "webview_layer is invalid") != null);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
1923
2214
|
test "manifest validates the theme pack name" {
|
|
1924
2215
|
const metadata = try parseText(std.testing.allocator,
|
|
1925
2216
|
\\.{
|
|
@@ -1937,3 +2228,25 @@ test "manifest validates the theme pack name" {
|
|
|
1937
2228
|
try std.testing.expect(isKnownThemePack("geist"));
|
|
1938
2229
|
try std.testing.expect(!isKnownThemePack("neon"));
|
|
1939
2230
|
}
|
|
2231
|
+
|
|
2232
|
+
test "manifest validates the theme accent hex color" {
|
|
2233
|
+
const metadata = try parseText(std.testing.allocator,
|
|
2234
|
+
\\.{
|
|
2235
|
+
\\ .id = "com.example.app",
|
|
2236
|
+
\\ .name = "example",
|
|
2237
|
+
\\ .version = "1.0.0",
|
|
2238
|
+
\\ .theme = "geist",
|
|
2239
|
+
\\ .theme_accent = "#df2670",
|
|
2240
|
+
\\}
|
|
2241
|
+
);
|
|
2242
|
+
defer metadata.deinit(std.testing.allocator);
|
|
2243
|
+
try std.testing.expectEqualStrings("#df2670", metadata.theme_accent.?);
|
|
2244
|
+
// The hex-shape check is the tooling half of the contract; the
|
|
2245
|
+
// runner re-parses the same shape at comptime in the app build.
|
|
2246
|
+
try std.testing.expect(isHexColor("#df2670"));
|
|
2247
|
+
try std.testing.expect(isHexColor("#000000"));
|
|
2248
|
+
try std.testing.expect(!isHexColor("df2670"));
|
|
2249
|
+
try std.testing.expect(!isHexColor("#df267"));
|
|
2250
|
+
try std.testing.expect(!isHexColor("#df26700"));
|
|
2251
|
+
try std.testing.expect(!isHexColor("#df267g"));
|
|
2252
|
+
}
|