@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.
Files changed (100) hide show
  1. package/build/app.zig +308 -72
  2. package/build/ts_run.mjs +63 -0
  3. package/build.zig +336 -7
  4. package/build.zig.zon +1 -0
  5. package/package.json +15 -10
  6. package/packages/core/package-lock.json +43 -0
  7. package/packages/core/package.json +37 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +536 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/core/SKILL.md +3 -0
  28. package/skill-data/native-ui/SKILL.md +30 -0
  29. package/skill-data/ts-core/SKILL.md +493 -0
  30. package/skill-data/zig/SKILL.md +208 -0
  31. package/skills/native-sdk/SKILL.md +1 -1
  32. package/src/app_runner/root.zig +75 -9
  33. package/src/app_runner/ts_core_main.zig +231 -0
  34. package/src/platform/linux/gtk_host.c +226 -21
  35. package/src/platform/windows/webview2_host.cpp +16 -10
  36. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  37. package/src/primitives/app_manifest/root.zig +13 -0
  38. package/src/primitives/app_manifest/types.zig +14 -0
  39. package/src/primitives/app_manifest/validation.zig +18 -0
  40. package/src/primitives/app_manifest/web_layer.zig +366 -0
  41. package/src/primitives/canvas/commands.zig +14 -7
  42. package/src/primitives/canvas/lazy_tls.zig +73 -0
  43. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  44. package/src/primitives/canvas/root.zig +6 -0
  45. package/src/primitives/canvas/tests.zig +1 -0
  46. package/src/primitives/canvas/text_atlas.zig +40 -32
  47. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  48. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  49. package/src/primitives/canvas/text_spans.zig +39 -26
  50. package/src/primitives/canvas/tokens.zig +54 -0
  51. package/src/primitives/canvas/ui.zig +125 -0
  52. package/src/primitives/canvas/ui_markup.zig +22 -3
  53. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  54. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  55. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  56. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  57. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  58. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  60. package/src/primitives/canvas/ui_schema.zig +8 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  62. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  63. package/src/primitives/canvas/widget_render.zig +25 -15
  64. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  65. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  66. package/src/root.zig +7 -0
  67. package/src/runtime/api.zig +7 -0
  68. package/src/runtime/bridge_responses.zig +2 -0
  69. package/src/runtime/builtin_bridge.zig +6 -0
  70. package/src/runtime/canvas_frame.zig +57 -36
  71. package/src/runtime/canvas_images.zig +9 -3
  72. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  73. package/src/runtime/canvas_widget_runtime.zig +7 -4
  74. package/src/runtime/effects.zig +490 -2
  75. package/src/runtime/effects_host_tests.zig +594 -0
  76. package/src/runtime/flow.zig +8 -0
  77. package/src/runtime/platform_bridge_tests.zig +1 -0
  78. package/src/runtime/root.zig +18 -0
  79. package/src/runtime/session_replay.zig +7 -1
  80. package/src/runtime/session_tests.zig +35 -8
  81. package/src/runtime/tests.zig +2 -0
  82. package/src/runtime/ts_core_host.zig +1505 -0
  83. package/src/runtime/ts_core_host_tests.zig +1408 -0
  84. package/src/runtime/ts_ui_app.zig +469 -0
  85. package/src/runtime/ui_app.zig +58 -0
  86. package/src/runtime/view_canvas.zig +24 -17
  87. package/src/runtime/view_widget_tree.zig +2 -2
  88. package/src/runtime/web_layer_gate_tests.zig +242 -0
  89. package/src/runtime/window_storage.zig +5 -0
  90. package/src/runtime/window_view_runtime.zig +1 -0
  91. package/src/tooling/buildgraph.zig +7 -1
  92. package/src/tooling/codesign.zig +212 -105
  93. package/src/tooling/doctor.zig +78 -0
  94. package/src/tooling/manifest.zig +314 -1
  95. package/src/tooling/package.zig +722 -18
  96. package/src/tooling/raw_manifest.zig +16 -0
  97. package/src/tooling/root.zig +1 -0
  98. package/src/tooling/templates.zig +911 -88
  99. package/src/tooling/ts_core.zig +486 -0
  100. package/src/tooling/verbs.zig +22 -0
@@ -1,8 +1,11 @@
1
1
  const std = @import("std");
2
2
 
3
+ /// The outcome of one signing-pipeline tool run. `message` is always
4
+ /// allocated (the tool's own stdout+stderr for failures — codesign says
5
+ /// exactly why it refused — or a short success note); the caller frees.
3
6
  pub const SignResult = struct {
4
7
  ok: bool,
5
- message: []const u8,
8
+ message: []u8,
6
9
  };
7
10
 
8
11
  pub const CodesignArgs = struct {
@@ -20,62 +23,99 @@ pub const NotarizeArgs = struct {
20
23
  password_keychain_item: ?[]const u8 = null,
21
24
  };
22
25
 
23
- pub fn buildSignCommand(buffer: []u8, args: CodesignArgs) ![]const u8 {
24
- var writer = std.Io.Writer.fixed(buffer);
25
- try writer.writeAll("codesign --sign ");
26
- try writer.writeAll(args.identity);
27
- try writer.writeAll(" --force");
28
- if (args.deep) try writer.writeAll(" --deep");
29
- if (args.hardened_runtime) try writer.writeAll(" --options runtime");
26
+ // Every command in this pipeline is built as an ARGV ARRAY, never as a
27
+ // shell string: a bundle path (or identity) with spaces must reach
28
+ // codesign/ditto/notarytool as one argument. The shell-string shape this
29
+ // replaced split `My App.app` into two arguments, codesign signed
30
+ // nothing, and the failure never surfaced.
31
+
32
+ pub const sign_argv_capacity = 10;
33
+
34
+ pub fn signArgv(buffer: *[sign_argv_capacity][]const u8, args: CodesignArgs) []const []const u8 {
35
+ var len: usize = 0;
36
+ buffer[len] = "codesign";
37
+ len += 1;
38
+ buffer[len] = "--sign";
39
+ len += 1;
40
+ buffer[len] = args.identity;
41
+ len += 1;
42
+ buffer[len] = "--force";
43
+ len += 1;
44
+ if (args.deep) {
45
+ buffer[len] = "--deep";
46
+ len += 1;
47
+ }
48
+ if (args.hardened_runtime) {
49
+ buffer[len] = "--options";
50
+ len += 1;
51
+ buffer[len] = "runtime";
52
+ len += 1;
53
+ }
30
54
  if (args.entitlements) |ent| {
31
- try writer.writeAll(" --entitlements ");
32
- try writer.writeAll(ent);
55
+ buffer[len] = "--entitlements";
56
+ len += 1;
57
+ buffer[len] = ent;
58
+ len += 1;
33
59
  }
34
- try writer.writeAll(" ");
35
- try writer.writeAll(args.app_path);
36
- return writer.buffered();
60
+ buffer[len] = args.app_path;
61
+ len += 1;
62
+ return buffer[0..len];
37
63
  }
38
64
 
39
- pub fn buildNotarizeSubmitCommand(buffer: []u8, zip_path: []const u8, args: NotarizeArgs) ![]const u8 {
40
- var writer = std.Io.Writer.fixed(buffer);
41
- try writer.writeAll("xcrun notarytool submit ");
42
- try writer.writeAll(zip_path);
43
- try writer.writeAll(" --team-id ");
44
- try writer.writeAll(args.team_id);
45
- if (args.apple_id) |apple_id| {
46
- try writer.writeAll(" --apple-id ");
47
- try writer.writeAll(apple_id);
48
- }
49
- if (args.password_keychain_item) |item| {
50
- try writer.writeAll(" --password @keychain:");
51
- try writer.writeAll(item);
52
- }
53
- try writer.writeAll(" --wait");
54
- return writer.buffered();
65
+ pub fn verifyArgv(buffer: *[6][]const u8, app_path: []const u8) []const []const u8 {
66
+ buffer.* = .{ "codesign", "--verify", "--deep", "--strict", "--verbose=2", app_path };
67
+ return buffer;
55
68
  }
56
69
 
57
- pub fn buildStapleCommand(buffer: []u8, app_path: []const u8) ![]const u8 {
58
- var writer = std.Io.Writer.fixed(buffer);
59
- try writer.writeAll("xcrun stapler staple ");
60
- try writer.writeAll(app_path);
61
- return writer.buffered();
70
+ pub fn zipArgv(buffer: *[6][]const u8, app_path: []const u8, zip_path: []const u8) []const []const u8 {
71
+ buffer.* = .{ "ditto", "-c", "-k", "--keepParent", app_path, zip_path };
72
+ return buffer;
62
73
  }
63
74
 
64
- pub fn buildZipCommand(buffer: []u8, app_path: []const u8, zip_path: []const u8) ![]const u8 {
65
- var writer = std.Io.Writer.fixed(buffer);
66
- try writer.writeAll("ditto -c -k --keepParent ");
67
- try writer.writeAll(app_path);
68
- try writer.writeAll(" ");
69
- try writer.writeAll(zip_path);
70
- return writer.buffered();
75
+ pub fn stapleArgv(buffer: *[4][]const u8, app_path: []const u8) []const []const u8 {
76
+ buffer.* = .{ "xcrun", "stapler", "staple", app_path };
77
+ return buffer;
71
78
  }
72
79
 
73
- pub fn signAdHoc(io: std.Io, app_path: []const u8) !SignResult {
74
- return runSign(io, .{ .app_path = app_path, .identity = "-", .deep = true });
80
+ pub const notarize_submit_argv_capacity = 11;
81
+
82
+ pub fn notarizeSubmitArgv(buffer: *[notarize_submit_argv_capacity][]const u8, zip_path: []const u8, password_value: ?[]const u8, args: NotarizeArgs) []const []const u8 {
83
+ var len: usize = 0;
84
+ buffer[len] = "xcrun";
85
+ len += 1;
86
+ buffer[len] = "notarytool";
87
+ len += 1;
88
+ buffer[len] = "submit";
89
+ len += 1;
90
+ buffer[len] = zip_path;
91
+ len += 1;
92
+ buffer[len] = "--team-id";
93
+ len += 1;
94
+ buffer[len] = args.team_id;
95
+ len += 1;
96
+ if (args.apple_id) |apple_id| {
97
+ buffer[len] = "--apple-id";
98
+ len += 1;
99
+ buffer[len] = apple_id;
100
+ len += 1;
101
+ }
102
+ if (password_value) |value| {
103
+ buffer[len] = "--password";
104
+ len += 1;
105
+ buffer[len] = value;
106
+ len += 1;
107
+ }
108
+ buffer[len] = "--wait";
109
+ len += 1;
110
+ return buffer[0..len];
75
111
  }
76
112
 
77
- pub fn signIdentity(io: std.Io, app_path: []const u8, identity: []const u8, entitlements: ?[]const u8) !SignResult {
78
- return runSign(io, .{
113
+ pub fn signAdHoc(allocator: std.mem.Allocator, io: std.Io, app_path: []const u8) !SignResult {
114
+ return runSign(allocator, io, .{ .app_path = app_path, .identity = "-", .deep = true });
115
+ }
116
+
117
+ pub fn signIdentity(allocator: std.mem.Allocator, io: std.Io, app_path: []const u8, identity: []const u8, entitlements: ?[]const u8) !SignResult {
118
+ return runSign(allocator, io, .{
79
119
  .app_path = app_path,
80
120
  .identity = identity,
81
121
  .entitlements = entitlements,
@@ -84,89 +124,156 @@ pub fn signIdentity(io: std.Io, app_path: []const u8, identity: []const u8, enti
84
124
  });
85
125
  }
86
126
 
127
+ /// `codesign --verify --deep --strict` over the signed bundle: the same
128
+ /// check Gatekeeper and an Apple silicon launch effectively run, so a
129
+ /// signature that only LOOKS applied (stale seal, unsigned nested code)
130
+ /// fails here at package time instead of on the user's machine.
131
+ pub fn verify(allocator: std.mem.Allocator, io: std.Io, app_path: []const u8) !SignResult {
132
+ var buffer: [6][]const u8 = undefined;
133
+ return runTool(allocator, io, verifyArgv(&buffer, app_path));
134
+ }
135
+
87
136
  pub fn notarize(allocator: std.mem.Allocator, io: std.Io, args: NotarizeArgs) !SignResult {
88
137
  const zip_path = try std.fmt.allocPrint(allocator, "{s}.zip", .{args.app_path});
89
138
  defer allocator.free(zip_path);
90
139
 
91
- var zip_buf: [1024]u8 = undefined;
92
- const zip_cmd = try buildZipCommand(&zip_buf, args.app_path, zip_path);
93
- var zip_result = runShell(io, zip_cmd) catch return .{ .ok = false, .message = "failed to zip app for notarization" };
94
- _ = &zip_result;
140
+ {
141
+ var zip_buffer: [6][]const u8 = undefined;
142
+ const zip_result = try runTool(allocator, io, zipArgv(&zip_buffer, args.app_path, zip_path));
143
+ if (!zip_result.ok) return failedStep(allocator, "ditto (zip for notarization)", zip_result);
144
+ allocator.free(zip_result.message);
145
+ }
95
146
 
96
- var submit_buf: [1024]u8 = undefined;
97
- const submit_cmd = try buildNotarizeSubmitCommand(&submit_buf, zip_path, args);
98
- runShell(io, submit_cmd) catch return .{ .ok = false, .message = "notarytool submit failed" };
147
+ {
148
+ const password_value: ?[]const u8 = if (args.password_keychain_item) |item|
149
+ try std.fmt.allocPrint(allocator, "@keychain:{s}", .{item})
150
+ else
151
+ null;
152
+ defer if (password_value) |value| allocator.free(value);
153
+ var submit_buffer: [notarize_submit_argv_capacity][]const u8 = undefined;
154
+ const submit_result = try runTool(allocator, io, notarizeSubmitArgv(&submit_buffer, zip_path, password_value, args));
155
+ if (!submit_result.ok) return failedStep(allocator, "notarytool submit", submit_result);
156
+ allocator.free(submit_result.message);
157
+ }
99
158
 
100
- var staple_buf: [512]u8 = undefined;
101
- const staple_cmd = try buildStapleCommand(&staple_buf, args.app_path);
102
- runShell(io, staple_cmd) catch return .{ .ok = false, .message = "stapler staple failed" };
159
+ {
160
+ var staple_buffer: [4][]const u8 = undefined;
161
+ const staple_result = try runTool(allocator, io, stapleArgv(&staple_buffer, args.app_path));
162
+ if (!staple_result.ok) return failedStep(allocator, "stapler staple", staple_result);
163
+ allocator.free(staple_result.message);
164
+ }
103
165
 
104
- return .{ .ok = true, .message = "notarization complete" };
166
+ return .{ .ok = true, .message = try allocator.dupe(u8, "notarization complete") };
105
167
  }
106
168
 
107
- fn runSign(io: std.Io, args: CodesignArgs) !SignResult {
108
- var buffer: [1024]u8 = undefined;
109
- const cmd = try buildSignCommand(&buffer, args);
110
- runShell(io, cmd) catch return .{ .ok = false, .message = "codesign failed" };
111
- return .{ .ok = true, .message = "signed" };
169
+ fn failedStep(allocator: std.mem.Allocator, step: []const u8, result: SignResult) !SignResult {
170
+ defer allocator.free(result.message);
171
+ return .{ .ok = false, .message = try std.fmt.allocPrint(allocator, "{s} failed:\n{s}", .{ step, result.message }) };
112
172
  }
113
173
 
114
- /// Run one shell command and FAIL on a non-zero exit: a codesign that
115
- /// exits 1 (or a host without codesign at all, exit 127) must surface as
116
- /// an error so callers record the bundle as unsigned instead of
117
- /// reporting a signature that does not exist.
118
- fn runShell(io: std.Io, cmd: []const u8) !void {
119
- const argv = [_][]const u8{ "sh", "-c", cmd };
120
- var child = try std.process.spawn(io, .{
121
- .argv = &argv,
122
- .stdin = .ignore,
123
- .stdout = .inherit,
124
- .stderr = .inherit,
125
- });
126
- const term = try child.wait(io);
127
- switch (term) {
128
- .exited => |code| if (code != 0) return error.CommandFailed,
129
- else => return error.CommandFailed,
130
- }
174
+ fn runSign(allocator: std.mem.Allocator, io: std.Io, args: CodesignArgs) !SignResult {
175
+ var buffer: [sign_argv_capacity][]const u8 = undefined;
176
+ return runTool(allocator, io, signArgv(&buffer, args));
177
+ }
178
+
179
+ /// Run one pipeline tool and report a non-zero exit as a failure that
180
+ /// carries the tool's own output: a codesign that exits 1 — or a host
181
+ /// without codesign at all — must surface with its reason so callers can
182
+ /// refuse to report a signature that does not exist.
183
+ fn runTool(allocator: std.mem.Allocator, io: std.Io, argv: []const []const u8) !SignResult {
184
+ const result = std.process.run(allocator, io, .{
185
+ .argv = argv,
186
+ .stdout_limit = .limited(256 * 1024),
187
+ .stderr_limit = .limited(256 * 1024),
188
+ }) catch |err| switch (err) {
189
+ error.OutOfMemory => return error.OutOfMemory,
190
+ else => return .{
191
+ .ok = false,
192
+ .message = try std.fmt.allocPrint(allocator, "could not run `{s}`: {t} (it ships with the Xcode Command Line Tools; signing macOS bundles needs a macOS host)", .{ argv[0], err }),
193
+ },
194
+ };
195
+ defer allocator.free(result.stdout);
196
+ defer allocator.free(result.stderr);
197
+ const ok = result.term == .exited and result.term.exited == 0;
198
+ // codesign explains failures on stderr; notarytool narrates on
199
+ // stdout. Keep both, stderr last so the refusal reads closest to
200
+ // the caller's teaching message.
201
+ return .{ .ok = ok, .message = try std.mem.concat(allocator, u8, &.{ result.stdout, result.stderr }) };
131
202
  }
132
203
 
133
- test "ad-hoc sign command is well-formed" {
134
- var buffer: [512]u8 = undefined;
135
- const cmd = try buildSignCommand(&buffer, .{ .app_path = "/tmp/Test.app" });
136
- try std.testing.expectEqualStrings("codesign --sign - --force --deep /tmp/Test.app", cmd);
204
+ test "ad-hoc sign argv keeps a spaced bundle path as one argument" {
205
+ var buffer: [sign_argv_capacity][]const u8 = undefined;
206
+ const argv = signArgv(&buffer, .{ .app_path = "/tmp/My Demo App.app" });
207
+ const expected = [_][]const u8{ "codesign", "--sign", "-", "--force", "--deep", "/tmp/My Demo App.app" };
208
+ try expectArgv(&expected, argv);
137
209
  }
138
210
 
139
- test "identity sign command includes runtime and entitlements" {
140
- var buffer: [512]u8 = undefined;
141
- const cmd = try buildSignCommand(&buffer, .{
142
- .app_path = "/tmp/Test.app",
143
- .identity = "Developer ID Application: Test",
144
- .entitlements = "assets/native-sdk.entitlements",
211
+ test "identity sign argv includes runtime and entitlements as single arguments" {
212
+ var buffer: [sign_argv_capacity][]const u8 = undefined;
213
+ const argv = signArgv(&buffer, .{
214
+ .app_path = "/tmp/My Demo App.app",
215
+ .identity = "Developer ID Application: Test Person (ABCD1234)",
216
+ .entitlements = "assets dir/native-sdk.entitlements",
145
217
  .hardened_runtime = true,
146
218
  });
147
- try std.testing.expectEqualStrings(
148
- "codesign --sign Developer ID Application: Test --force --deep --options runtime --entitlements assets/native-sdk.entitlements /tmp/Test.app",
149
- cmd,
150
- );
219
+ const expected = [_][]const u8{
220
+ "codesign", "--sign",
221
+ "Developer ID Application: Test Person (ABCD1234)", "--force",
222
+ "--deep", "--options",
223
+ "runtime", "--entitlements",
224
+ "assets dir/native-sdk.entitlements", "/tmp/My Demo App.app",
225
+ };
226
+ try expectArgv(&expected, argv);
151
227
  }
152
228
 
153
- test "notarize submit command includes team id and wait" {
154
- var buffer: [512]u8 = undefined;
155
- const cmd = try buildNotarizeSubmitCommand(&buffer, "/tmp/Test.app.zip", .{
156
- .app_path = "/tmp/Test.app",
229
+ test "verify argv runs the strict deep check on the bundle path" {
230
+ var buffer: [6][]const u8 = undefined;
231
+ const argv = verifyArgv(&buffer, "/tmp/My Demo App.app");
232
+ const expected = [_][]const u8{ "codesign", "--verify", "--deep", "--strict", "--verbose=2", "/tmp/My Demo App.app" };
233
+ try expectArgv(&expected, argv);
234
+ }
235
+
236
+ test "notarize submit argv includes team id, keychain password, and wait" {
237
+ var buffer: [notarize_submit_argv_capacity][]const u8 = undefined;
238
+ const argv = notarizeSubmitArgv(&buffer, "/tmp/My Demo App.app.zip", "@keychain:AC_PASSWORD", .{
239
+ .app_path = "/tmp/My Demo App.app",
157
240
  .team_id = "ABCD1234",
241
+ .apple_id = "dev@example.com",
158
242
  });
159
- try std.testing.expectEqualStrings("xcrun notarytool submit /tmp/Test.app.zip --team-id ABCD1234 --wait", cmd);
243
+ const expected = [_][]const u8{ "xcrun", "notarytool", "submit", "/tmp/My Demo App.app.zip", "--team-id", "ABCD1234", "--apple-id", "dev@example.com", "--password", "@keychain:AC_PASSWORD", "--wait" };
244
+ try expectArgv(&expected, argv);
245
+ }
246
+
247
+ test "staple and zip argv carry spaced paths as single arguments" {
248
+ var staple_buffer: [4][]const u8 = undefined;
249
+ const staple = stapleArgv(&staple_buffer, "/tmp/My Demo App.app");
250
+ const staple_expected = [_][]const u8{ "xcrun", "stapler", "staple", "/tmp/My Demo App.app" };
251
+ try expectArgv(&staple_expected, staple);
252
+
253
+ var zip_buffer: [6][]const u8 = undefined;
254
+ const zip = zipArgv(&zip_buffer, "/tmp/My Demo App.app", "/tmp/My Demo App.app.zip");
255
+ const zip_expected = [_][]const u8{ "ditto", "-c", "-k", "--keepParent", "/tmp/My Demo App.app", "/tmp/My Demo App.app.zip" };
256
+ try expectArgv(&zip_expected, zip);
160
257
  }
161
258
 
162
- test "staple command targets app path" {
163
- var buffer: [256]u8 = undefined;
164
- const cmd = try buildStapleCommand(&buffer, "/tmp/Test.app");
165
- try std.testing.expectEqualStrings("xcrun stapler staple /tmp/Test.app", cmd);
259
+ test "a failing tool surfaces its own output, not a silent success" {
260
+ if (@import("builtin").os.tag == .windows) return error.SkipZigTest;
261
+ // `false` exits 1 with no output: the result must be a failure.
262
+ const result = try runTool(std.testing.allocator, std.testing.io, &.{"false"});
263
+ defer std.testing.allocator.free(result.message);
264
+ try std.testing.expect(!result.ok);
166
265
  }
167
266
 
168
- test "zip command uses ditto" {
169
- var buffer: [256]u8 = undefined;
170
- const cmd = try buildZipCommand(&buffer, "/tmp/Test.app", "/tmp/Test.app.zip");
171
- try std.testing.expectEqualStrings("ditto -c -k --keepParent /tmp/Test.app /tmp/Test.app.zip", cmd);
267
+ test "a missing tool reports a failure that names it" {
268
+ const result = try runTool(std.testing.allocator, std.testing.io, &.{"native-sdk-no-such-tool-xyz"});
269
+ defer std.testing.allocator.free(result.message);
270
+ try std.testing.expect(!result.ok);
271
+ try std.testing.expect(std.mem.indexOf(u8, result.message, "native-sdk-no-such-tool-xyz") != null);
272
+ }
273
+
274
+ fn expectArgv(expected: []const []const u8, actual: []const []const u8) !void {
275
+ try std.testing.expectEqual(expected.len, actual.len);
276
+ for (expected, actual) |want, got| {
277
+ try std.testing.expectEqualStrings(want, got);
278
+ }
172
279
  }
@@ -4,6 +4,8 @@ const cef = @import("cef.zig");
4
4
  const debug = @import("debug");
5
5
  const manifest_tool = @import("manifest.zig");
6
6
  const web_engine = @import("web_engine.zig");
7
+ const buildgraph = @import("buildgraph.zig");
8
+ const ts_core = @import("ts_core.zig");
7
9
 
8
10
  pub const Error = error{
9
11
  DoctorProblems,
@@ -142,6 +144,7 @@ pub fn reportForCurrentHostWithProbe(
142
144
  try buffers.add("null-backend", .available, "headless WebView shell platform is available", .{});
143
145
  try addLogPathCheck(buffers, env_map);
144
146
  try addManifestCheck(buffers, allocator, io, options);
147
+ try addTsEditorPackageCheck(buffers, allocator, io, env_map, probe);
145
148
  if (target.os == .macos) {
146
149
  try buffers.add("webview-system", .available, "WKWebView system WebView backend is available on macOS hosts", .{});
147
150
  try addPathCheck(buffers, io, probe, "codesign", "/usr/bin/codesign", "codesign is available for macOS signing", "codesign was not found");
@@ -226,6 +229,30 @@ fn addLogPathCheck(buffers: *ReportBuffers, env_map: *std.process.Environ.Map) !
226
229
  try buffers.add("log-path", .available, "runtime logs will be written to {s}", .{paths.log_file});
227
230
  }
228
231
 
232
+ /// TypeScript apps only (cwd has src/core.ts): compare the app's editor
233
+ /// copy of @native-sdk/core (node_modules — the pre-publish surface stock
234
+ /// tsc resolves) against the SDK's bundled package. A mismatch never breaks
235
+ /// a build (builds don't read node_modules); it breaks IntelliSense, so the
236
+ /// teaching line names the fix.
237
+ fn addTsEditorPackageCheck(buffers: *ReportBuffers, allocator: std.mem.Allocator, io: std.Io, env_map: *std.process.Environ.Map, probe: Probe) !void {
238
+ if (!probe.pathExists(io, "src/core.ts")) return;
239
+ const framework_root = (buildgraph.resolveFrameworkRoot(allocator, io, env_map) catch null) orelse {
240
+ return buffers.add("ts-editor-package", .missing, "cannot locate the Native SDK framework to verify node_modules/@native-sdk/core; set NATIVE_SDK_PATH to your framework checkout", .{});
241
+ };
242
+ defer allocator.free(framework_root);
243
+ const status = ts_core.editorPackageStatus(allocator, io, framework_root, ".") catch {
244
+ return buffers.add("ts-editor-package", .missing, "the SDK at {s} is missing packages/core - cannot verify the editor package", .{framework_root});
245
+ };
246
+ defer status.deinit(allocator);
247
+ if (status.fresh()) {
248
+ try buffers.add("ts-editor-package", .available, "node_modules/@native-sdk/core matches the SDK (v{s}) - stock editor TypeScript resolves the SDK", .{status.bundled});
249
+ } else if (status.installed) |installed| {
250
+ try buffers.add("ts-editor-package", .missing, "node_modules/@native-sdk/core is v{s} but the SDK ships v{s} - `native check` refreshes it (after the npm publish: `npm install`); builds are unaffected", .{ installed, status.bundled });
251
+ } else {
252
+ try buffers.add("ts-editor-package", .missing, "node_modules/@native-sdk/core is missing - editor TypeScript cannot resolve the SDK; `native check` materializes it (builds are unaffected)", .{});
253
+ }
254
+ }
255
+
229
256
  fn addManifestCheck(buffers: *ReportBuffers, allocator: std.mem.Allocator, io: std.Io, options: Options) !void {
230
257
  const path = options.manifest_path orelse return;
231
258
  const result = manifest_tool.validateFile(allocator, io, path) catch |err| {
@@ -318,6 +345,57 @@ test "doctor options parse strict manifest and cef checks" {
318
345
  try std.testing.expectEqualStrings("third_party/cef/macos", options.cef_dir_override.?);
319
346
  }
320
347
 
348
+ test "doctor reports the TS editor package when the tree has a core.ts" {
349
+ const allocator = std.testing.allocator;
350
+ const io = std.testing.io;
351
+ // A fake SDK checkout (framework marker + bundled package) under the
352
+ // cache; the cwd (repo root) plays the app dir and has no
353
+ // node_modules/@native-sdk/core, so the check reports the missing copy.
354
+ const sdk = ".zig-cache/test-doctor-editor-package/sdk";
355
+ var cwd = std.Io.Dir.cwd();
356
+ cwd.deleteTree(io, ".zig-cache/test-doctor-editor-package") catch {};
357
+ defer cwd.deleteTree(io, ".zig-cache/test-doctor-editor-package") catch {};
358
+ try cwd.createDirPath(io, sdk ++ "/src");
359
+ try cwd.createDirPath(io, sdk ++ "/packages/core/sdk");
360
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/src/root.zig", .data = "// marker" });
361
+ try cwd.writeFile(io, .{ .sub_path = sdk ++ "/packages/core/package.json", .data = "{ \"version\": \"0.0.5\" }" });
362
+
363
+ const Fake = struct {
364
+ fn commandAvailable(context: ?*anyopaque, inner_allocator: std.mem.Allocator, inner_io: std.Io, argv: []const []const u8) bool {
365
+ _ = context;
366
+ _ = inner_allocator;
367
+ _ = inner_io;
368
+ _ = argv;
369
+ return true;
370
+ }
371
+
372
+ fn pathExists(context: ?*anyopaque, inner_io: std.Io, path: []const u8) bool {
373
+ _ = context;
374
+ _ = inner_io;
375
+ return std.mem.eql(u8, path, "src/core.ts");
376
+ }
377
+ };
378
+
379
+ var env_map = std.process.Environ.Map.init(allocator);
380
+ defer env_map.deinit();
381
+ try env_map.put("HOME", "/Users/alice");
382
+ try env_map.put("NATIVE_SDK_PATH", sdk);
383
+ var buffers: ReportBuffers = .{};
384
+ const report = try reportForCurrentHostWithProbe(allocator, io, &env_map, .{}, &buffers, .{
385
+ .command_fn = Fake.commandAvailable,
386
+ .path_fn = Fake.pathExists,
387
+ });
388
+
389
+ var found = false;
390
+ for (report.checks) |check| {
391
+ if (!std.mem.eql(u8, check.id, "ts-editor-package")) continue;
392
+ found = true;
393
+ try std.testing.expectEqual(platform_info.Status.missing, check.status);
394
+ try std.testing.expect(std.mem.indexOf(u8, check.message, "native check") != null);
395
+ }
396
+ try std.testing.expect(found);
397
+ }
398
+
321
399
  test "doctor report uses injected probes" {
322
400
  const Fake = struct {
323
401
  fn commandAvailable(context: ?*anyopaque, allocator: std.mem.Allocator, io: std.Io, argv: []const []const u8) bool {