@native-sdk/cli 0.8.4 → 0.9.1
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 +1178 -74
- package/build.zig +715 -17
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +10 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +435 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +224 -0
- package/packages/core/sdk/core.ts +694 -22
- package/packages/core/sdk/events.d.ts +89 -0
- package/packages/core/sdk/events.ts +128 -0
- package/packages/core/src/checker.ts +936 -15
- package/packages/core/src/cli.ts +156 -3
- package/packages/core/src/contract.ts +28 -5
- package/packages/core/src/devhost.ts +1876 -16
- package/packages/core/src/devhost_journal.mjs +183 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +179 -22
- package/packages/core/src/frontend.ts +210 -34
- package/packages/core/src/infer.ts +24 -0
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +58 -5
- package/skill-data/ts-core/SKILL.md +123 -41
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +604 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +133 -4
- package/src/app_runner/ts_core_main.zig +254 -8
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +31 -11
- package/src/embed/app_exports.zig +12 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +109 -1
- package/src/embed/root.zig +8 -0
- package/src/embed/tests.zig +241 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +185 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +8 -2
- package/src/platform/linux/gtk_host.c +289 -22
- package/src/platform/linux/gtk_host.h +5 -1
- package/src/platform/linux/root.zig +109 -22
- package/src/platform/macos/appkit_host.h +24 -7
- package/src/platform/macos/appkit_host.m +686 -64
- package/src/platform/macos/cef_host.mm +400 -66
- package/src/platform/macos/root.zig +304 -47
- package/src/platform/null_platform.zig +435 -48
- package/src/platform/null_platform_tests.zig +113 -0
- package/src/platform/root.zig +19 -0
- package/src/platform/types.zig +281 -28
- package/src/platform/windows/root.zig +207 -27
- package/src/platform/windows/webview2_host.cpp +334 -51
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +53 -0
- package/src/runtime/api.zig +19 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -20
- package/src/runtime/bridge_permission_tests.zig +58 -3
- package/src/runtime/bridge_responses.zig +4 -2
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +145 -7
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +3701 -231
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +35 -10
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +86 -2
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +54 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +158 -5
- package/src/runtime/session_record.zig +215 -0
- package/src/runtime/session_replay.zig +206 -11
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/system_services.zig +170 -38
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +1067 -95
- package/src/runtime/ts_core_host_tests.zig +325 -11
- package/src/runtime/ts_ui_app.zig +953 -2
- package/src/runtime/ui_app.zig +434 -96
- package/src/runtime/ui_app_tests.zig +287 -11
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +42 -0
- package/src/runtime/view.zig +9 -0
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +189 -4
- package/src/tooling/ts_core.zig +366 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +442 -27
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//! Bridge coverage for `TsCoreHost` against a hand-written core that
|
|
2
2
|
//! replicates the transpiler's emitted ABI (rt kernel, commit walker,
|
|
3
3
|
//! `UpdateResult`/`InitResult`, wire-encoded commands and
|
|
4
|
-
//! subscriptions). Hand-encoding the wire records here pins the
|
|
4
|
+
//! subscriptions). Hand-encoding the wire records here pins the v5
|
|
5
5
|
//! byte layout independently of the rt builders that normally produce
|
|
6
6
|
//! it; the transpiled-fixture end-to-end suite (tests/ts-core) drives
|
|
7
7
|
//! the same bridge with genuinely emitted code through a full UiApp.
|
|
@@ -17,7 +17,7 @@ const ts_core_host = @import("ts_core_host.zig");
|
|
|
17
17
|
//
|
|
18
18
|
// The emitted-core ABI in miniature: a two-region kernel, a poller
|
|
19
19
|
// model, and an update that exercises every wire record. Cmd/Sub bytes
|
|
20
|
-
// are hand-encoded to the documented
|
|
20
|
+
// are hand-encoded to the documented v4 layout. Polling starts OFF so
|
|
21
21
|
// the real-executor tests below (which bind no platform timer service)
|
|
22
22
|
// never arm a timer; the e2e suite covers boot-time subscriptions
|
|
23
23
|
// through a full UiApp with live null-platform services.
|
|
@@ -159,6 +159,8 @@ const mini_core = struct {
|
|
|
159
159
|
// Unsigned-class mirrors (u64-classed arm routing).
|
|
160
160
|
ustamp_ms: u64,
|
|
161
161
|
ucode: u64,
|
|
162
|
+
db_live: bool,
|
|
163
|
+
db_live_set: u8,
|
|
162
164
|
};
|
|
163
165
|
|
|
164
166
|
pub const Msg = union(enum) {
|
|
@@ -325,6 +327,17 @@ const mini_core = struct {
|
|
|
325
327
|
stream_over_get, // 91: streaming fetch collides with buffered fetch "get"
|
|
326
328
|
get_over_stream, // 92: buffered fetch collides with streaming fetch "events"
|
|
327
329
|
fill_streams, // 93: seventeen distinct streams exceed the bridge table
|
|
330
|
+
hide_win, // 94: window_hide "player"
|
|
331
|
+
dock_off, // 95: dock_presence false
|
|
332
|
+
arm_db_live, // 96: install a live query under wire key "shared-db"
|
|
333
|
+
query_over_db_live, // 97: a one-shot query collides with that live key
|
|
334
|
+
stop_db_live_with_cancel, // 98: remove the Sub while Cmd.cancel names its key
|
|
335
|
+
arm_full_db_live_set, // 99: fill all relational slots with live keys
|
|
336
|
+
replace_full_db_live_set, // 100: replace them with one disjoint key
|
|
337
|
+
malformed_credential, // 101: reserved request with an invalid inner record
|
|
338
|
+
open_save_sink, // 102: write_file_stream "save" -> wrote/failed
|
|
339
|
+
write_save_chunk, // 103: write_file_chunk "save" -> wrote/failed
|
|
340
|
+
close_save_sink, // 104: write_file_close "save" -> wrote/failed
|
|
328
341
|
};
|
|
329
342
|
|
|
330
343
|
const stream_fill_keys = [_][]const u8{
|
|
@@ -335,8 +348,16 @@ const mini_core = struct {
|
|
|
335
348
|
"fill-16",
|
|
336
349
|
};
|
|
337
350
|
|
|
351
|
+
const db_live_set_a_keys = [_][]const u8{
|
|
352
|
+
"old-db-00", "old-db-01", "old-db-02", "old-db-03",
|
|
353
|
+
"old-db-04", "old-db-05", "old-db-06", "old-db-07",
|
|
354
|
+
"old-db-08", "old-db-09", "old-db-10", "old-db-11",
|
|
355
|
+
"old-db-12", "old-db-13", "old-db-14", "old-db-15",
|
|
356
|
+
};
|
|
357
|
+
|
|
338
358
|
pub const InitResult = struct { model: *const Model, cmd: []const u8 };
|
|
339
359
|
pub const UpdateResult = struct { model: *const Model, cmd: []const u8 };
|
|
360
|
+
var initial_model_calls: usize = 0;
|
|
340
361
|
|
|
341
362
|
fn frameCreate(value: Model) *Model {
|
|
342
363
|
const slot = rt.frameAlloc(Model, 1);
|
|
@@ -345,6 +366,7 @@ const mini_core = struct {
|
|
|
345
366
|
}
|
|
346
367
|
|
|
347
368
|
pub fn initialModel() InitResult {
|
|
369
|
+
initial_model_calls += 1;
|
|
348
370
|
return .{
|
|
349
371
|
.model = frameCreate(.{
|
|
350
372
|
.polling = false,
|
|
@@ -408,11 +430,17 @@ const mini_core = struct {
|
|
|
408
430
|
.video2_events = 0,
|
|
409
431
|
.ustamp_ms = 0,
|
|
410
432
|
.ucode = 0,
|
|
433
|
+
.db_live = false,
|
|
434
|
+
.db_live_set = 0,
|
|
411
435
|
}),
|
|
412
436
|
.cmd = cmdRequest("status.read", "status", 7, 8, "boot"),
|
|
413
437
|
};
|
|
414
438
|
}
|
|
415
439
|
|
|
440
|
+
pub fn bootCommand() []const u8 {
|
|
441
|
+
return cmdRequest("status.read", "status", 7, 8, "boot");
|
|
442
|
+
}
|
|
443
|
+
|
|
416
444
|
pub fn update(model: *const Model, msg: Msg) UpdateResult {
|
|
417
445
|
switch (msg) {
|
|
418
446
|
.toggle => {
|
|
@@ -426,6 +454,7 @@ const mini_core = struct {
|
|
|
426
454
|
return .{ .model = out, .cmd = "" };
|
|
427
455
|
},
|
|
428
456
|
.refresh => return .{ .model = model, .cmd = cmdRequest("status.read", "status", 7, 8, model.status) },
|
|
457
|
+
.malformed_credential => return .{ .model = model, .cmd = cmdRequest("core.credentials.get", "bad-credential", 7, 8, "") },
|
|
429
458
|
.pair => {
|
|
430
459
|
const first = cmdRequest("a.read", "", 7, 8, "1");
|
|
431
460
|
const second = cmdRequest("b.read", "", 7, 8, "2");
|
|
@@ -459,6 +488,9 @@ const mini_core = struct {
|
|
|
459
488
|
return .{ .model = out, .cmd = "" };
|
|
460
489
|
},
|
|
461
490
|
.save_file => return .{ .model = model, .cmd = cmdWriteFile("save", 12, 8, "notes.bin", model.status) },
|
|
491
|
+
.open_save_sink => return .{ .model = model, .cmd = cmdWriteFileStream("save", 12, 8, "notes.bin") },
|
|
492
|
+
.write_save_chunk => return .{ .model = model, .cmd = cmdWriteFileChunk("save", 12, 8, "next") },
|
|
493
|
+
.close_save_sink => return .{ .model = model, .cmd = cmdWriteFileClose("save", 12, 8) },
|
|
462
494
|
.wrote => {
|
|
463
495
|
const out = frameCreate(model.*);
|
|
464
496
|
out.saved = true;
|
|
@@ -652,6 +684,8 @@ const mini_core = struct {
|
|
|
652
684
|
.drop_get => return .{ .model = model, .cmd = cmdCancel("get") },
|
|
653
685
|
.drop_paste => return .{ .model = model, .cmd = cmdCancel("paste") },
|
|
654
686
|
.open_win => return .{ .model = model, .cmd = cmdWindowShow("player") },
|
|
687
|
+
.hide_win => return .{ .model = model, .cmd = cmdWindowHide("player") },
|
|
688
|
+
.dock_off => return .{ .model = model, .cmd = cmdDockPresence(false) },
|
|
655
689
|
.quit_app => return .{ .model = model, .cmd = cmdQuitApp() },
|
|
656
690
|
.open_chan => return .{ .model = model, .cmd = cmdChannelOpen(41, 47) },
|
|
657
691
|
.close_chan => return .{ .model = model, .cmd = cmdChannelClose(41) },
|
|
@@ -799,6 +833,27 @@ const mini_core = struct {
|
|
|
799
833
|
out.capture_events = model.capture_events + 1;
|
|
800
834
|
return .{ .model = out, .cmd = "" };
|
|
801
835
|
},
|
|
836
|
+
.arm_db_live => {
|
|
837
|
+
const out = frameCreate(model.*);
|
|
838
|
+
out.db_live = true;
|
|
839
|
+
return .{ .model = out, .cmd = "" };
|
|
840
|
+
},
|
|
841
|
+
.query_over_db_live => return .{ .model = model, .cmd = cmdDbQuery("shared-db", 7, 12, 8, "SELECT id FROM item") },
|
|
842
|
+
.stop_db_live_with_cancel => {
|
|
843
|
+
const out = frameCreate(model.*);
|
|
844
|
+
out.db_live = false;
|
|
845
|
+
return .{ .model = out, .cmd = cmdCancel("shared-db") };
|
|
846
|
+
},
|
|
847
|
+
.arm_full_db_live_set => {
|
|
848
|
+
const out = frameCreate(model.*);
|
|
849
|
+
out.db_live_set = 1;
|
|
850
|
+
return .{ .model = out, .cmd = "" };
|
|
851
|
+
},
|
|
852
|
+
.replace_full_db_live_set => {
|
|
853
|
+
const out = frameCreate(model.*);
|
|
854
|
+
out.db_live_set = 2;
|
|
855
|
+
return .{ .model = out, .cmd = "" };
|
|
856
|
+
},
|
|
802
857
|
}
|
|
803
858
|
}
|
|
804
859
|
|
|
@@ -810,8 +865,24 @@ const mini_core = struct {
|
|
|
810
865
|
}
|
|
811
866
|
|
|
812
867
|
pub fn subscriptions(model: *const Model) []const u8 {
|
|
813
|
-
if (
|
|
814
|
-
|
|
868
|
+
const timer = if (model.polling) subTimer("tick", if (model.fast) 40 else 100, 9) else "";
|
|
869
|
+
const live = if (model.db_live) subDbLive("shared-db", 7, 12, 8, "SELECT id FROM item", "item") else "";
|
|
870
|
+
const live_set = switch (model.db_live_set) {
|
|
871
|
+
1 => subDbLiveBatch(&db_live_set_a_keys),
|
|
872
|
+
2 => subDbLive("new-db", 7, 12, 8, "SELECT id FROM item", "item"),
|
|
873
|
+
else => "",
|
|
874
|
+
};
|
|
875
|
+
const parts = [_][]const u8{ timer, live, live_set };
|
|
876
|
+
var total: usize = 0;
|
|
877
|
+
for (parts) |part| total += part.len;
|
|
878
|
+
if (total == 0) return "";
|
|
879
|
+
const out = rt.frameAlloc(u8, total);
|
|
880
|
+
var at: usize = 0;
|
|
881
|
+
for (parts) |part| {
|
|
882
|
+
@memcpy(out[at..][0..part.len], part);
|
|
883
|
+
at += part.len;
|
|
884
|
+
}
|
|
885
|
+
return out;
|
|
815
886
|
}
|
|
816
887
|
|
|
817
888
|
pub fn commitModelRoot(next: *const Model) *const Model {
|
|
@@ -837,7 +908,7 @@ const mini_core = struct {
|
|
|
837
908
|
return out;
|
|
838
909
|
}
|
|
839
910
|
|
|
840
|
-
// Hand-encoded
|
|
911
|
+
// Hand-encoded v4 wire records (rt.zig's documented layout).
|
|
841
912
|
|
|
842
913
|
fn cmdNow(msg_tag: u8) []const u8 {
|
|
843
914
|
const out = rt.frameAlloc(u8, 2);
|
|
@@ -869,7 +940,7 @@ const mini_core = struct {
|
|
|
869
940
|
}
|
|
870
941
|
|
|
871
942
|
fn cmdRequest(name: []const u8, key: []const u8, ok_tag: u8, err_tag: u8, payload: []const u8) []const u8 {
|
|
872
|
-
const out = rt.frameAlloc(u8, 2 + name.len + 1 + key.len +
|
|
943
|
+
const out = rt.frameAlloc(u8, 2 + name.len + 1 + key.len + 3 + 4 + payload.len);
|
|
873
944
|
out[0] = 0x05;
|
|
874
945
|
out[1] = @intCast(name.len);
|
|
875
946
|
@memcpy(out[2..][0..name.len], name);
|
|
@@ -879,8 +950,9 @@ const mini_core = struct {
|
|
|
879
950
|
off += 1 + key.len;
|
|
880
951
|
out[off] = ok_tag;
|
|
881
952
|
out[off + 1] = err_tag;
|
|
882
|
-
|
|
883
|
-
|
|
953
|
+
out[off + 2] = 0; // raw byte request, not a generated typed service call
|
|
954
|
+
std.mem.writeInt(u32, out[off + 3 ..][0..4], @intCast(payload.len), .little);
|
|
955
|
+
@memcpy(out[off + 7 ..][0..payload.len], payload);
|
|
884
956
|
return out;
|
|
885
957
|
}
|
|
886
958
|
|
|
@@ -924,6 +996,26 @@ const mini_core = struct {
|
|
|
924
996
|
return out;
|
|
925
997
|
}
|
|
926
998
|
|
|
999
|
+
fn cmdWriteFileStream(key: []const u8, ok_tag: u8, err_tag: u8, file_path: []const u8) []const u8 {
|
|
1000
|
+
const out = rt.frameAlloc(u8, 4 + key.len + 4 + file_path.len);
|
|
1001
|
+
var off = writeRoutedHead(out, 0x2E, key, ok_tag, err_tag);
|
|
1002
|
+
off = writeLongBytes(out, off, file_path);
|
|
1003
|
+
return out;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
fn cmdWriteFileChunk(key: []const u8, ok_tag: u8, err_tag: u8, bytes: []const u8) []const u8 {
|
|
1007
|
+
const out = rt.frameAlloc(u8, 4 + key.len + 4 + bytes.len);
|
|
1008
|
+
var off = writeRoutedHead(out, 0x2F, key, ok_tag, err_tag);
|
|
1009
|
+
off = writeLongBytes(out, off, bytes);
|
|
1010
|
+
return out;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
fn cmdWriteFileClose(key: []const u8, ok_tag: u8, err_tag: u8) []const u8 {
|
|
1014
|
+
const out = rt.frameAlloc(u8, 4 + key.len);
|
|
1015
|
+
_ = writeRoutedHead(out, 0x30, key, ok_tag, err_tag);
|
|
1016
|
+
return out;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
927
1019
|
fn cmdFetch(key: []const u8, ok_tag: u8, err_tag: u8, method: u8, timeout_ms: u32, url: []const u8, headers: []const FetchHeader, body: []const u8) []const u8 {
|
|
928
1020
|
var header_bytes: usize = 0;
|
|
929
1021
|
for (headers) |h| header_bytes += 1 + h.name.len + 4 + h.value.len;
|
|
@@ -1073,6 +1165,21 @@ const mini_core = struct {
|
|
|
1073
1165
|
return out;
|
|
1074
1166
|
}
|
|
1075
1167
|
|
|
1168
|
+
fn cmdWindowHide(label: []const u8) []const u8 {
|
|
1169
|
+
const out = rt.frameAlloc(u8, 2 + label.len);
|
|
1170
|
+
out[0] = 0x21;
|
|
1171
|
+
out[1] = @intCast(label.len);
|
|
1172
|
+
@memcpy(out[2..][0..label.len], label);
|
|
1173
|
+
return out;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
fn cmdDockPresence(visible: bool) []const u8 {
|
|
1177
|
+
const out = rt.frameAlloc(u8, 2);
|
|
1178
|
+
out[0] = 0x22;
|
|
1179
|
+
out[1] = if (visible) 1 else 0;
|
|
1180
|
+
return out;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1076
1183
|
fn cmdQuitApp() []const u8 {
|
|
1077
1184
|
const out = rt.frameAlloc(u8, 1);
|
|
1078
1185
|
out[0] = 0x11;
|
|
@@ -1093,10 +1200,11 @@ const mini_core = struct {
|
|
|
1093
1200
|
}
|
|
1094
1201
|
|
|
1095
1202
|
fn cmdChannelOpen(key: f64, event_tag: u8) []const u8 {
|
|
1096
|
-
const out = rt.frameAlloc(u8, 1 + 8 + 1);
|
|
1203
|
+
const out = rt.frameAlloc(u8, 1 + 8 + 1 + 1);
|
|
1097
1204
|
out[0] = 0x15;
|
|
1098
1205
|
std.mem.writeInt(u64, out[1..][0..8], @bitCast(key), .little);
|
|
1099
1206
|
out[9] = event_tag;
|
|
1207
|
+
out[10] = 64;
|
|
1100
1208
|
return out;
|
|
1101
1209
|
}
|
|
1102
1210
|
|
|
@@ -1173,6 +1281,27 @@ const mini_core = struct {
|
|
|
1173
1281
|
return out;
|
|
1174
1282
|
}
|
|
1175
1283
|
|
|
1284
|
+
fn cmdDbQuery(key: []const u8, page_tag: u8, done_tag: u8, err_tag: u8, sql: []const u8) []const u8 {
|
|
1285
|
+
const out = rt.frameAlloc(u8, 1 + 1 + key.len + 3 + 4 + sql.len + 4);
|
|
1286
|
+
var at: usize = 0;
|
|
1287
|
+
out[at] = 0x29;
|
|
1288
|
+
at += 1;
|
|
1289
|
+
out[at] = @intCast(key.len);
|
|
1290
|
+
at += 1;
|
|
1291
|
+
@memcpy(out[at..][0..key.len], key);
|
|
1292
|
+
at += key.len;
|
|
1293
|
+
out[at] = page_tag;
|
|
1294
|
+
out[at + 1] = done_tag;
|
|
1295
|
+
out[at + 2] = err_tag;
|
|
1296
|
+
at += 3;
|
|
1297
|
+
std.mem.writeInt(u32, out[at..][0..4], @intCast(sql.len), .little);
|
|
1298
|
+
at += 4;
|
|
1299
|
+
@memcpy(out[at..][0..sql.len], sql);
|
|
1300
|
+
at += sql.len;
|
|
1301
|
+
std.mem.writeInt(u32, out[at..][0..4], 0, .little);
|
|
1302
|
+
return out;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1176
1305
|
fn subTimer(key: []const u8, every_ms: f64, msg_tag: u8) []const u8 {
|
|
1177
1306
|
const out = rt.frameAlloc(u8, 2 + key.len + 8 + 1);
|
|
1178
1307
|
out[0] = 0x01;
|
|
@@ -1182,6 +1311,50 @@ const mini_core = struct {
|
|
|
1182
1311
|
out[2 + key.len + 8] = msg_tag;
|
|
1183
1312
|
return out;
|
|
1184
1313
|
}
|
|
1314
|
+
|
|
1315
|
+
fn subDbLive(key: []const u8, page_tag: u8, done_tag: u8, err_tag: u8, sql: []const u8, table: []const u8) []const u8 {
|
|
1316
|
+
const out = rt.frameAlloc(u8, 1 + 1 + key.len + 3 + 4 + sql.len + 4 + 4 + 1 + table.len);
|
|
1317
|
+
var at: usize = 0;
|
|
1318
|
+
out[at] = 0x02;
|
|
1319
|
+
at += 1;
|
|
1320
|
+
out[at] = @intCast(key.len);
|
|
1321
|
+
at += 1;
|
|
1322
|
+
@memcpy(out[at..][0..key.len], key);
|
|
1323
|
+
at += key.len;
|
|
1324
|
+
out[at] = page_tag;
|
|
1325
|
+
out[at + 1] = done_tag;
|
|
1326
|
+
out[at + 2] = err_tag;
|
|
1327
|
+
at += 3;
|
|
1328
|
+
std.mem.writeInt(u32, out[at..][0..4], @intCast(sql.len), .little);
|
|
1329
|
+
at += 4;
|
|
1330
|
+
@memcpy(out[at..][0..sql.len], sql);
|
|
1331
|
+
at += sql.len;
|
|
1332
|
+
std.mem.writeInt(u32, out[at..][0..4], 0, .little);
|
|
1333
|
+
at += 4;
|
|
1334
|
+
std.mem.writeInt(u32, out[at..][0..4], 1, .little);
|
|
1335
|
+
at += 4;
|
|
1336
|
+
out[at] = @intCast(table.len);
|
|
1337
|
+
at += 1;
|
|
1338
|
+
@memcpy(out[at..][0..table.len], table);
|
|
1339
|
+
return out;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
fn subDbLiveBatch(keys: []const []const u8) []const u8 {
|
|
1343
|
+
var records: [effects_mod.max_db_effects][]const u8 = undefined;
|
|
1344
|
+
std.debug.assert(keys.len <= records.len);
|
|
1345
|
+
var total: usize = 0;
|
|
1346
|
+
for (keys, 0..) |key, index| {
|
|
1347
|
+
records[index] = subDbLive(key, 7, 12, 8, "SELECT id FROM item", "item");
|
|
1348
|
+
total += records[index].len;
|
|
1349
|
+
}
|
|
1350
|
+
const out = rt.frameAlloc(u8, total);
|
|
1351
|
+
var at: usize = 0;
|
|
1352
|
+
for (records[0..keys.len]) |record| {
|
|
1353
|
+
@memcpy(out[at..][0..record.len], record);
|
|
1354
|
+
at += record.len;
|
|
1355
|
+
}
|
|
1356
|
+
return out;
|
|
1357
|
+
}
|
|
1185
1358
|
};
|
|
1186
1359
|
|
|
1187
1360
|
const Host = ts_core_host.TsCoreHost(mini_core);
|
|
@@ -1309,6 +1482,20 @@ test "unkeyed requests dispatch in completion order" {
|
|
|
1309
1482
|
try std.testing.expectEqualStrings("from-a", Host.model().status);
|
|
1310
1483
|
}
|
|
1311
1484
|
|
|
1485
|
+
test "malformed credential request records reject instead of panicking" {
|
|
1486
|
+
const fx = freshChannel();
|
|
1487
|
+
defer fx.deinit();
|
|
1488
|
+
Host.init(fx);
|
|
1489
|
+
try fx.feedHostResult(boot_request_key, true, "");
|
|
1490
|
+
Host.drain(fx);
|
|
1491
|
+
|
|
1492
|
+
Host.dispatch(fx, .malformed_credential);
|
|
1493
|
+
Host.drain(fx);
|
|
1494
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
1495
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1496
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1312
1499
|
test "subscription reconcile arms, pauses, resumes, and re-arms on interval change" {
|
|
1313
1500
|
const fx = freshChannel();
|
|
1314
1501
|
defer fx.deinit();
|
|
@@ -1338,6 +1525,55 @@ test "subscription reconcile arms, pauses, resumes, and re-arms on interval chan
|
|
|
1338
1525
|
try std.testing.expectEqual(@as(u64, 40), fx.pendingTimerAt(0).?.interval_ms);
|
|
1339
1526
|
}
|
|
1340
1527
|
|
|
1528
|
+
test "a one-shot database query cannot overwrite a live subscription slot with the same wire key" {
|
|
1529
|
+
const fx = freshChannel();
|
|
1530
|
+
defer fx.deinit();
|
|
1531
|
+
Host.init(fx);
|
|
1532
|
+
|
|
1533
|
+
Host.dispatch(fx, .arm_db_live);
|
|
1534
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1535
|
+
|
|
1536
|
+
const errors_before = Host.model().errs;
|
|
1537
|
+
Host.dispatch(fx, .query_over_db_live);
|
|
1538
|
+
Host.drain(fx);
|
|
1539
|
+
try std.testing.expectEqual(errors_before + 1, Host.model().errs);
|
|
1540
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1541
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
test "Cmd.cancel leaves a live query to declarative subscription reconciliation" {
|
|
1545
|
+
const fx = freshChannel();
|
|
1546
|
+
defer fx.deinit();
|
|
1547
|
+
Host.init(fx);
|
|
1548
|
+
|
|
1549
|
+
Host.dispatch(fx, .arm_db_live);
|
|
1550
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1551
|
+
|
|
1552
|
+
// The command walk sees Cmd.cancel first, then reconciliation sees that
|
|
1553
|
+
// the committed model no longer declares the Sub. Cancel must leave the
|
|
1554
|
+
// bridge entry intact so that reconciliation can retire the engine slot.
|
|
1555
|
+
Host.dispatch(fx, .stop_db_live_with_cancel);
|
|
1556
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingDbCount());
|
|
1557
|
+
|
|
1558
|
+
// The same bridge/engine slot is immediately reusable by a one-shot read.
|
|
1559
|
+
Host.dispatch(fx, .query_over_db_live);
|
|
1560
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
test "live-query reconciliation retires stale slots before arming disjoint replacements" {
|
|
1564
|
+
const fx = freshChannel();
|
|
1565
|
+
defer fx.deinit();
|
|
1566
|
+
Host.init(fx);
|
|
1567
|
+
|
|
1568
|
+
Host.dispatch(fx, .arm_full_db_live_set);
|
|
1569
|
+
try std.testing.expectEqual(effects_mod.max_db_effects, fx.pendingDbCount());
|
|
1570
|
+
|
|
1571
|
+
// Every old key disappears at once. The final declaration contains one
|
|
1572
|
+
// query and must fit without trying to hold its sixteen predecessors too.
|
|
1573
|
+
Host.dispatch(fx, .replace_full_db_live_set);
|
|
1574
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1341
1577
|
test "timer fires dispatch the named arm with the fire time" {
|
|
1342
1578
|
const fx = freshChannel();
|
|
1343
1579
|
defer fx.deinit();
|
|
@@ -1548,6 +1784,74 @@ test "write_file routes its payload-less ok arm and err reasons" {
|
|
|
1548
1784
|
try std.testing.expectEqualStrings("io_failed", Host.model().last_err);
|
|
1549
1785
|
}
|
|
1550
1786
|
|
|
1787
|
+
test "file streams and buffered effects cannot share a public key" {
|
|
1788
|
+
const fx = freshChannel();
|
|
1789
|
+
defer fx.deinit();
|
|
1790
|
+
Host.init(fx);
|
|
1791
|
+
|
|
1792
|
+
// The buffered effect owns "save", so the sink refuses without parking a
|
|
1793
|
+
// second engine key that would make Cmd.cancel ambiguous.
|
|
1794
|
+
Host.dispatch(fx, .save_file);
|
|
1795
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1796
|
+
Host.drain(fx);
|
|
1797
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
1798
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1799
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingFileCount());
|
|
1800
|
+
try std.testing.expectError(error.EffectNotFound, fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base));
|
|
1801
|
+
|
|
1802
|
+
Host.dispatch(fx, .drop_save);
|
|
1803
|
+
Host.drain(fx);
|
|
1804
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1805
|
+
|
|
1806
|
+
// The same invariant holds in the opposite order. The rejected buffered
|
|
1807
|
+
// write does not hide the live sink, and cancel reaches that sink loudly.
|
|
1808
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1809
|
+
try fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base);
|
|
1810
|
+
try fx.feedFileResultDetailed(.{ .key = ts_core_host.file_stream_key_base, .op = .write_stream_open, .outcome = .ok });
|
|
1811
|
+
Host.drain(fx);
|
|
1812
|
+
Host.dispatch(fx, .save_file);
|
|
1813
|
+
Host.drain(fx);
|
|
1814
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
1815
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1816
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1817
|
+
|
|
1818
|
+
Host.dispatch(fx, .drop_save);
|
|
1819
|
+
Host.drain(fx);
|
|
1820
|
+
try std.testing.expectEqual(@as(i64, 3), Host.model().errs);
|
|
1821
|
+
try std.testing.expectEqualStrings("cancelled", Host.model().last_err);
|
|
1822
|
+
try std.testing.expectError(error.EffectNotFound, fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base));
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
test "a cancelling file sink rejects later chunk and close commands without orphaning callbacks" {
|
|
1826
|
+
const fx = freshChannel();
|
|
1827
|
+
defer fx.deinit();
|
|
1828
|
+
Host.init(fx);
|
|
1829
|
+
|
|
1830
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1831
|
+
try fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base);
|
|
1832
|
+
try fx.feedFileResultDetailed(.{ .key = ts_core_host.file_stream_key_base, .op = .write_stream_open, .outcome = .ok });
|
|
1833
|
+
Host.drain(fx);
|
|
1834
|
+
|
|
1835
|
+
// Cancel keeps the bridge entry until the engine's loud terminal arrives.
|
|
1836
|
+
// A command in that window must reject locally instead of overwriting the
|
|
1837
|
+
// cancellation route and queuing a second callback against the same entry.
|
|
1838
|
+
Host.dispatch(fx, .drop_save);
|
|
1839
|
+
Host.dispatch(fx, .write_save_chunk);
|
|
1840
|
+
Host.drain(fx);
|
|
1841
|
+
try std.testing.expectEqual(@as(i64, 2), Host.model().errs);
|
|
1842
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1843
|
+
|
|
1844
|
+
Host.dispatch(fx, .open_save_sink);
|
|
1845
|
+
try fx.acknowledgeFakeFileStreamOpen(ts_core_host.file_stream_key_base);
|
|
1846
|
+
try fx.feedFileResultDetailed(.{ .key = ts_core_host.file_stream_key_base, .op = .write_stream_open, .outcome = .ok });
|
|
1847
|
+
Host.drain(fx);
|
|
1848
|
+
Host.dispatch(fx, .drop_save);
|
|
1849
|
+
Host.dispatch(fx, .close_save_sink);
|
|
1850
|
+
Host.drain(fx);
|
|
1851
|
+
try std.testing.expectEqual(@as(i64, 4), Host.model().errs);
|
|
1852
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingFileCount());
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1551
1855
|
test "fetch decodes the wire record whole and routes the { status, body } ok arm by field type" {
|
|
1552
1856
|
const fx = freshChannel();
|
|
1553
1857
|
defer fx.deinit();
|
|
@@ -2467,12 +2771,14 @@ test "boot commits the model before any effects and performBoot fires the boot c
|
|
|
2467
2771
|
// The pre-effects half: the committed boot model is readable, no
|
|
2468
2772
|
// effect has been issued, and the frame arena is reset.
|
|
2469
2773
|
Host.boot();
|
|
2774
|
+
const calls_after_boot = mini_core.initial_model_calls;
|
|
2470
2775
|
try std.testing.expect(!Host.model().polling);
|
|
2471
2776
|
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
2472
2777
|
|
|
2473
|
-
// The effects half
|
|
2474
|
-
//
|
|
2778
|
+
// The effects half retrieves only the command. Re-running initialModel
|
|
2779
|
+
// here would also reset a compiled core after persistence restore.
|
|
2475
2780
|
Host.performBoot(fx);
|
|
2781
|
+
try std.testing.expectEqual(calls_after_boot, mini_core.initial_model_calls);
|
|
2476
2782
|
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
2477
2783
|
const request = fx.pendingHostAt(0).?;
|
|
2478
2784
|
try std.testing.expectEqual(boot_request_key, request.key);
|
|
@@ -2519,6 +2825,14 @@ test "window verbs bridge to the effects channel's label-addressed verbs" {
|
|
|
2519
2825
|
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().show_count);
|
|
2520
2826
|
try std.testing.expectEqualStrings("player", fx.windowActionState().lastLabel());
|
|
2521
2827
|
|
|
2828
|
+
Host.dispatch(fx, .hide_win);
|
|
2829
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().hide_count);
|
|
2830
|
+
try std.testing.expectEqualStrings("player", fx.windowActionState().lastLabel());
|
|
2831
|
+
|
|
2832
|
+
Host.dispatch(fx, .dock_off);
|
|
2833
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().dock_presence_count);
|
|
2834
|
+
try std.testing.expect(!fx.windowActionState().dock_visible);
|
|
2835
|
+
|
|
2522
2836
|
// quit_app decodes onto fx.quitApp — the graceful terminate request.
|
|
2523
2837
|
Host.dispatch(fx, .quit_app);
|
|
2524
2838
|
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().quit_count);
|