@native-sdk/cli 0.8.4 → 0.9.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 +859 -62
- package/build.zig +543 -13
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +2 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +365 -2
- 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/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -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 +149 -0
- package/packages/core/sdk/core.ts +529 -12
- package/packages/core/sdk/events.d.ts +36 -0
- package/packages/core/sdk/events.ts +57 -0
- package/packages/core/src/checker.ts +468 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1847 -16
- package/packages/core/src/devhost_journal.mjs +181 -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 +82 -16
- package/packages/core/src/frontend.ts +204 -34
- 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/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +47 -0
- package/skill-data/ts-core/SKILL.md +80 -31
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -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 +104 -4
- package/src/app_runner/ts_core_main.zig +249 -8
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -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 +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +119 -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 +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +40 -18
- package/src/platform/macos/appkit_host.h +16 -3
- package/src/platform/macos/appkit_host.m +536 -36
- package/src/platform/macos/cef_host.mm +248 -36
- package/src/platform/macos/root.zig +244 -34
- package/src/platform/null_platform.zig +223 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +179 -15
- package/src/platform/windows/root.zig +187 -21
- package/src/platform/windows/webview2_host.cpp +293 -46
- 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 +46 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -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 +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2295 -113
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +49 -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 +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- 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 +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +788 -86
- package/src/runtime/ts_core_host_tests.zig +231 -11
- package/src/runtime/ts_ui_app.zig +499 -1
- package/src/runtime/ui_app.zig +142 -16
- package/src/runtime/ui_app_tests.zig +155 -5
- package/src/runtime/validation.zig +22 -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 +161 -4
- package/src/tooling/ts_core.zig +283 -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 +378 -23
- 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 v4
|
|
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,14 @@ 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
|
|
328
338
|
};
|
|
329
339
|
|
|
330
340
|
const stream_fill_keys = [_][]const u8{
|
|
@@ -335,8 +345,16 @@ const mini_core = struct {
|
|
|
335
345
|
"fill-16",
|
|
336
346
|
};
|
|
337
347
|
|
|
348
|
+
const db_live_set_a_keys = [_][]const u8{
|
|
349
|
+
"old-db-00", "old-db-01", "old-db-02", "old-db-03",
|
|
350
|
+
"old-db-04", "old-db-05", "old-db-06", "old-db-07",
|
|
351
|
+
"old-db-08", "old-db-09", "old-db-10", "old-db-11",
|
|
352
|
+
"old-db-12", "old-db-13", "old-db-14", "old-db-15",
|
|
353
|
+
};
|
|
354
|
+
|
|
338
355
|
pub const InitResult = struct { model: *const Model, cmd: []const u8 };
|
|
339
356
|
pub const UpdateResult = struct { model: *const Model, cmd: []const u8 };
|
|
357
|
+
var initial_model_calls: usize = 0;
|
|
340
358
|
|
|
341
359
|
fn frameCreate(value: Model) *Model {
|
|
342
360
|
const slot = rt.frameAlloc(Model, 1);
|
|
@@ -345,6 +363,7 @@ const mini_core = struct {
|
|
|
345
363
|
}
|
|
346
364
|
|
|
347
365
|
pub fn initialModel() InitResult {
|
|
366
|
+
initial_model_calls += 1;
|
|
348
367
|
return .{
|
|
349
368
|
.model = frameCreate(.{
|
|
350
369
|
.polling = false,
|
|
@@ -408,11 +427,17 @@ const mini_core = struct {
|
|
|
408
427
|
.video2_events = 0,
|
|
409
428
|
.ustamp_ms = 0,
|
|
410
429
|
.ucode = 0,
|
|
430
|
+
.db_live = false,
|
|
431
|
+
.db_live_set = 0,
|
|
411
432
|
}),
|
|
412
433
|
.cmd = cmdRequest("status.read", "status", 7, 8, "boot"),
|
|
413
434
|
};
|
|
414
435
|
}
|
|
415
436
|
|
|
437
|
+
pub fn bootCommand() []const u8 {
|
|
438
|
+
return cmdRequest("status.read", "status", 7, 8, "boot");
|
|
439
|
+
}
|
|
440
|
+
|
|
416
441
|
pub fn update(model: *const Model, msg: Msg) UpdateResult {
|
|
417
442
|
switch (msg) {
|
|
418
443
|
.toggle => {
|
|
@@ -426,6 +451,7 @@ const mini_core = struct {
|
|
|
426
451
|
return .{ .model = out, .cmd = "" };
|
|
427
452
|
},
|
|
428
453
|
.refresh => return .{ .model = model, .cmd = cmdRequest("status.read", "status", 7, 8, model.status) },
|
|
454
|
+
.malformed_credential => return .{ .model = model, .cmd = cmdRequest("core.credentials.get", "bad-credential", 7, 8, "") },
|
|
429
455
|
.pair => {
|
|
430
456
|
const first = cmdRequest("a.read", "", 7, 8, "1");
|
|
431
457
|
const second = cmdRequest("b.read", "", 7, 8, "2");
|
|
@@ -652,6 +678,8 @@ const mini_core = struct {
|
|
|
652
678
|
.drop_get => return .{ .model = model, .cmd = cmdCancel("get") },
|
|
653
679
|
.drop_paste => return .{ .model = model, .cmd = cmdCancel("paste") },
|
|
654
680
|
.open_win => return .{ .model = model, .cmd = cmdWindowShow("player") },
|
|
681
|
+
.hide_win => return .{ .model = model, .cmd = cmdWindowHide("player") },
|
|
682
|
+
.dock_off => return .{ .model = model, .cmd = cmdDockPresence(false) },
|
|
655
683
|
.quit_app => return .{ .model = model, .cmd = cmdQuitApp() },
|
|
656
684
|
.open_chan => return .{ .model = model, .cmd = cmdChannelOpen(41, 47) },
|
|
657
685
|
.close_chan => return .{ .model = model, .cmd = cmdChannelClose(41) },
|
|
@@ -799,6 +827,27 @@ const mini_core = struct {
|
|
|
799
827
|
out.capture_events = model.capture_events + 1;
|
|
800
828
|
return .{ .model = out, .cmd = "" };
|
|
801
829
|
},
|
|
830
|
+
.arm_db_live => {
|
|
831
|
+
const out = frameCreate(model.*);
|
|
832
|
+
out.db_live = true;
|
|
833
|
+
return .{ .model = out, .cmd = "" };
|
|
834
|
+
},
|
|
835
|
+
.query_over_db_live => return .{ .model = model, .cmd = cmdDbQuery("shared-db", 7, 12, 8, "SELECT id FROM item") },
|
|
836
|
+
.stop_db_live_with_cancel => {
|
|
837
|
+
const out = frameCreate(model.*);
|
|
838
|
+
out.db_live = false;
|
|
839
|
+
return .{ .model = out, .cmd = cmdCancel("shared-db") };
|
|
840
|
+
},
|
|
841
|
+
.arm_full_db_live_set => {
|
|
842
|
+
const out = frameCreate(model.*);
|
|
843
|
+
out.db_live_set = 1;
|
|
844
|
+
return .{ .model = out, .cmd = "" };
|
|
845
|
+
},
|
|
846
|
+
.replace_full_db_live_set => {
|
|
847
|
+
const out = frameCreate(model.*);
|
|
848
|
+
out.db_live_set = 2;
|
|
849
|
+
return .{ .model = out, .cmd = "" };
|
|
850
|
+
},
|
|
802
851
|
}
|
|
803
852
|
}
|
|
804
853
|
|
|
@@ -810,8 +859,24 @@ const mini_core = struct {
|
|
|
810
859
|
}
|
|
811
860
|
|
|
812
861
|
pub fn subscriptions(model: *const Model) []const u8 {
|
|
813
|
-
if (
|
|
814
|
-
|
|
862
|
+
const timer = if (model.polling) subTimer("tick", if (model.fast) 40 else 100, 9) else "";
|
|
863
|
+
const live = if (model.db_live) subDbLive("shared-db", 7, 12, 8, "SELECT id FROM item", "item") else "";
|
|
864
|
+
const live_set = switch (model.db_live_set) {
|
|
865
|
+
1 => subDbLiveBatch(&db_live_set_a_keys),
|
|
866
|
+
2 => subDbLive("new-db", 7, 12, 8, "SELECT id FROM item", "item"),
|
|
867
|
+
else => "",
|
|
868
|
+
};
|
|
869
|
+
const parts = [_][]const u8{ timer, live, live_set };
|
|
870
|
+
var total: usize = 0;
|
|
871
|
+
for (parts) |part| total += part.len;
|
|
872
|
+
if (total == 0) return "";
|
|
873
|
+
const out = rt.frameAlloc(u8, total);
|
|
874
|
+
var at: usize = 0;
|
|
875
|
+
for (parts) |part| {
|
|
876
|
+
@memcpy(out[at..][0..part.len], part);
|
|
877
|
+
at += part.len;
|
|
878
|
+
}
|
|
879
|
+
return out;
|
|
815
880
|
}
|
|
816
881
|
|
|
817
882
|
pub fn commitModelRoot(next: *const Model) *const Model {
|
|
@@ -837,7 +902,7 @@ const mini_core = struct {
|
|
|
837
902
|
return out;
|
|
838
903
|
}
|
|
839
904
|
|
|
840
|
-
// Hand-encoded
|
|
905
|
+
// Hand-encoded v4 wire records (rt.zig's documented layout).
|
|
841
906
|
|
|
842
907
|
fn cmdNow(msg_tag: u8) []const u8 {
|
|
843
908
|
const out = rt.frameAlloc(u8, 2);
|
|
@@ -869,7 +934,7 @@ const mini_core = struct {
|
|
|
869
934
|
}
|
|
870
935
|
|
|
871
936
|
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 +
|
|
937
|
+
const out = rt.frameAlloc(u8, 2 + name.len + 1 + key.len + 3 + 4 + payload.len);
|
|
873
938
|
out[0] = 0x05;
|
|
874
939
|
out[1] = @intCast(name.len);
|
|
875
940
|
@memcpy(out[2..][0..name.len], name);
|
|
@@ -879,8 +944,9 @@ const mini_core = struct {
|
|
|
879
944
|
off += 1 + key.len;
|
|
880
945
|
out[off] = ok_tag;
|
|
881
946
|
out[off + 1] = err_tag;
|
|
882
|
-
|
|
883
|
-
|
|
947
|
+
out[off + 2] = 0; // raw byte request, not a generated typed service call
|
|
948
|
+
std.mem.writeInt(u32, out[off + 3 ..][0..4], @intCast(payload.len), .little);
|
|
949
|
+
@memcpy(out[off + 7 ..][0..payload.len], payload);
|
|
884
950
|
return out;
|
|
885
951
|
}
|
|
886
952
|
|
|
@@ -1073,6 +1139,21 @@ const mini_core = struct {
|
|
|
1073
1139
|
return out;
|
|
1074
1140
|
}
|
|
1075
1141
|
|
|
1142
|
+
fn cmdWindowHide(label: []const u8) []const u8 {
|
|
1143
|
+
const out = rt.frameAlloc(u8, 2 + label.len);
|
|
1144
|
+
out[0] = 0x21;
|
|
1145
|
+
out[1] = @intCast(label.len);
|
|
1146
|
+
@memcpy(out[2..][0..label.len], label);
|
|
1147
|
+
return out;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
fn cmdDockPresence(visible: bool) []const u8 {
|
|
1151
|
+
const out = rt.frameAlloc(u8, 2);
|
|
1152
|
+
out[0] = 0x22;
|
|
1153
|
+
out[1] = if (visible) 1 else 0;
|
|
1154
|
+
return out;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1076
1157
|
fn cmdQuitApp() []const u8 {
|
|
1077
1158
|
const out = rt.frameAlloc(u8, 1);
|
|
1078
1159
|
out[0] = 0x11;
|
|
@@ -1093,10 +1174,11 @@ const mini_core = struct {
|
|
|
1093
1174
|
}
|
|
1094
1175
|
|
|
1095
1176
|
fn cmdChannelOpen(key: f64, event_tag: u8) []const u8 {
|
|
1096
|
-
const out = rt.frameAlloc(u8, 1 + 8 + 1);
|
|
1177
|
+
const out = rt.frameAlloc(u8, 1 + 8 + 1 + 1);
|
|
1097
1178
|
out[0] = 0x15;
|
|
1098
1179
|
std.mem.writeInt(u64, out[1..][0..8], @bitCast(key), .little);
|
|
1099
1180
|
out[9] = event_tag;
|
|
1181
|
+
out[10] = 64;
|
|
1100
1182
|
return out;
|
|
1101
1183
|
}
|
|
1102
1184
|
|
|
@@ -1173,6 +1255,27 @@ const mini_core = struct {
|
|
|
1173
1255
|
return out;
|
|
1174
1256
|
}
|
|
1175
1257
|
|
|
1258
|
+
fn cmdDbQuery(key: []const u8, page_tag: u8, done_tag: u8, err_tag: u8, sql: []const u8) []const u8 {
|
|
1259
|
+
const out = rt.frameAlloc(u8, 1 + 1 + key.len + 3 + 4 + sql.len + 4);
|
|
1260
|
+
var at: usize = 0;
|
|
1261
|
+
out[at] = 0x29;
|
|
1262
|
+
at += 1;
|
|
1263
|
+
out[at] = @intCast(key.len);
|
|
1264
|
+
at += 1;
|
|
1265
|
+
@memcpy(out[at..][0..key.len], key);
|
|
1266
|
+
at += key.len;
|
|
1267
|
+
out[at] = page_tag;
|
|
1268
|
+
out[at + 1] = done_tag;
|
|
1269
|
+
out[at + 2] = err_tag;
|
|
1270
|
+
at += 3;
|
|
1271
|
+
std.mem.writeInt(u32, out[at..][0..4], @intCast(sql.len), .little);
|
|
1272
|
+
at += 4;
|
|
1273
|
+
@memcpy(out[at..][0..sql.len], sql);
|
|
1274
|
+
at += sql.len;
|
|
1275
|
+
std.mem.writeInt(u32, out[at..][0..4], 0, .little);
|
|
1276
|
+
return out;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1176
1279
|
fn subTimer(key: []const u8, every_ms: f64, msg_tag: u8) []const u8 {
|
|
1177
1280
|
const out = rt.frameAlloc(u8, 2 + key.len + 8 + 1);
|
|
1178
1281
|
out[0] = 0x01;
|
|
@@ -1182,6 +1285,50 @@ const mini_core = struct {
|
|
|
1182
1285
|
out[2 + key.len + 8] = msg_tag;
|
|
1183
1286
|
return out;
|
|
1184
1287
|
}
|
|
1288
|
+
|
|
1289
|
+
fn subDbLive(key: []const u8, page_tag: u8, done_tag: u8, err_tag: u8, sql: []const u8, table: []const u8) []const u8 {
|
|
1290
|
+
const out = rt.frameAlloc(u8, 1 + 1 + key.len + 3 + 4 + sql.len + 4 + 4 + 1 + table.len);
|
|
1291
|
+
var at: usize = 0;
|
|
1292
|
+
out[at] = 0x02;
|
|
1293
|
+
at += 1;
|
|
1294
|
+
out[at] = @intCast(key.len);
|
|
1295
|
+
at += 1;
|
|
1296
|
+
@memcpy(out[at..][0..key.len], key);
|
|
1297
|
+
at += key.len;
|
|
1298
|
+
out[at] = page_tag;
|
|
1299
|
+
out[at + 1] = done_tag;
|
|
1300
|
+
out[at + 2] = err_tag;
|
|
1301
|
+
at += 3;
|
|
1302
|
+
std.mem.writeInt(u32, out[at..][0..4], @intCast(sql.len), .little);
|
|
1303
|
+
at += 4;
|
|
1304
|
+
@memcpy(out[at..][0..sql.len], sql);
|
|
1305
|
+
at += sql.len;
|
|
1306
|
+
std.mem.writeInt(u32, out[at..][0..4], 0, .little);
|
|
1307
|
+
at += 4;
|
|
1308
|
+
std.mem.writeInt(u32, out[at..][0..4], 1, .little);
|
|
1309
|
+
at += 4;
|
|
1310
|
+
out[at] = @intCast(table.len);
|
|
1311
|
+
at += 1;
|
|
1312
|
+
@memcpy(out[at..][0..table.len], table);
|
|
1313
|
+
return out;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
fn subDbLiveBatch(keys: []const []const u8) []const u8 {
|
|
1317
|
+
var records: [effects_mod.max_db_effects][]const u8 = undefined;
|
|
1318
|
+
std.debug.assert(keys.len <= records.len);
|
|
1319
|
+
var total: usize = 0;
|
|
1320
|
+
for (keys, 0..) |key, index| {
|
|
1321
|
+
records[index] = subDbLive(key, 7, 12, 8, "SELECT id FROM item", "item");
|
|
1322
|
+
total += records[index].len;
|
|
1323
|
+
}
|
|
1324
|
+
const out = rt.frameAlloc(u8, total);
|
|
1325
|
+
var at: usize = 0;
|
|
1326
|
+
for (records[0..keys.len]) |record| {
|
|
1327
|
+
@memcpy(out[at..][0..record.len], record);
|
|
1328
|
+
at += record.len;
|
|
1329
|
+
}
|
|
1330
|
+
return out;
|
|
1331
|
+
}
|
|
1185
1332
|
};
|
|
1186
1333
|
|
|
1187
1334
|
const Host = ts_core_host.TsCoreHost(mini_core);
|
|
@@ -1309,6 +1456,20 @@ test "unkeyed requests dispatch in completion order" {
|
|
|
1309
1456
|
try std.testing.expectEqualStrings("from-a", Host.model().status);
|
|
1310
1457
|
}
|
|
1311
1458
|
|
|
1459
|
+
test "malformed credential request records reject instead of panicking" {
|
|
1460
|
+
const fx = freshChannel();
|
|
1461
|
+
defer fx.deinit();
|
|
1462
|
+
Host.init(fx);
|
|
1463
|
+
try fx.feedHostResult(boot_request_key, true, "");
|
|
1464
|
+
Host.drain(fx);
|
|
1465
|
+
|
|
1466
|
+
Host.dispatch(fx, .malformed_credential);
|
|
1467
|
+
Host.drain(fx);
|
|
1468
|
+
try std.testing.expectEqual(@as(i64, 1), Host.model().errs);
|
|
1469
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1470
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1312
1473
|
test "subscription reconcile arms, pauses, resumes, and re-arms on interval change" {
|
|
1313
1474
|
const fx = freshChannel();
|
|
1314
1475
|
defer fx.deinit();
|
|
@@ -1338,6 +1499,55 @@ test "subscription reconcile arms, pauses, resumes, and re-arms on interval chan
|
|
|
1338
1499
|
try std.testing.expectEqual(@as(u64, 40), fx.pendingTimerAt(0).?.interval_ms);
|
|
1339
1500
|
}
|
|
1340
1501
|
|
|
1502
|
+
test "a one-shot database query cannot overwrite a live subscription slot with the same wire key" {
|
|
1503
|
+
const fx = freshChannel();
|
|
1504
|
+
defer fx.deinit();
|
|
1505
|
+
Host.init(fx);
|
|
1506
|
+
|
|
1507
|
+
Host.dispatch(fx, .arm_db_live);
|
|
1508
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1509
|
+
|
|
1510
|
+
const errors_before = Host.model().errs;
|
|
1511
|
+
Host.dispatch(fx, .query_over_db_live);
|
|
1512
|
+
Host.drain(fx);
|
|
1513
|
+
try std.testing.expectEqual(errors_before + 1, Host.model().errs);
|
|
1514
|
+
try std.testing.expectEqualStrings("rejected", Host.model().last_err);
|
|
1515
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
test "Cmd.cancel leaves a live query to declarative subscription reconciliation" {
|
|
1519
|
+
const fx = freshChannel();
|
|
1520
|
+
defer fx.deinit();
|
|
1521
|
+
Host.init(fx);
|
|
1522
|
+
|
|
1523
|
+
Host.dispatch(fx, .arm_db_live);
|
|
1524
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1525
|
+
|
|
1526
|
+
// The command walk sees Cmd.cancel first, then reconciliation sees that
|
|
1527
|
+
// the committed model no longer declares the Sub. Cancel must leave the
|
|
1528
|
+
// bridge entry intact so that reconciliation can retire the engine slot.
|
|
1529
|
+
Host.dispatch(fx, .stop_db_live_with_cancel);
|
|
1530
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingDbCount());
|
|
1531
|
+
|
|
1532
|
+
// The same bridge/engine slot is immediately reusable by a one-shot read.
|
|
1533
|
+
Host.dispatch(fx, .query_over_db_live);
|
|
1534
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
test "live-query reconciliation retires stale slots before arming disjoint replacements" {
|
|
1538
|
+
const fx = freshChannel();
|
|
1539
|
+
defer fx.deinit();
|
|
1540
|
+
Host.init(fx);
|
|
1541
|
+
|
|
1542
|
+
Host.dispatch(fx, .arm_full_db_live_set);
|
|
1543
|
+
try std.testing.expectEqual(effects_mod.max_db_effects, fx.pendingDbCount());
|
|
1544
|
+
|
|
1545
|
+
// Every old key disappears at once. The final declaration contains one
|
|
1546
|
+
// query and must fit without trying to hold its sixteen predecessors too.
|
|
1547
|
+
Host.dispatch(fx, .replace_full_db_live_set);
|
|
1548
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1341
1551
|
test "timer fires dispatch the named arm with the fire time" {
|
|
1342
1552
|
const fx = freshChannel();
|
|
1343
1553
|
defer fx.deinit();
|
|
@@ -2467,12 +2677,14 @@ test "boot commits the model before any effects and performBoot fires the boot c
|
|
|
2467
2677
|
// The pre-effects half: the committed boot model is readable, no
|
|
2468
2678
|
// effect has been issued, and the frame arena is reset.
|
|
2469
2679
|
Host.boot();
|
|
2680
|
+
const calls_after_boot = mini_core.initial_model_calls;
|
|
2470
2681
|
try std.testing.expect(!Host.model().polling);
|
|
2471
2682
|
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
2472
2683
|
|
|
2473
|
-
// The effects half
|
|
2474
|
-
//
|
|
2684
|
+
// The effects half retrieves only the command. Re-running initialModel
|
|
2685
|
+
// here would also reset a compiled core after persistence restore.
|
|
2475
2686
|
Host.performBoot(fx);
|
|
2687
|
+
try std.testing.expectEqual(calls_after_boot, mini_core.initial_model_calls);
|
|
2476
2688
|
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
2477
2689
|
const request = fx.pendingHostAt(0).?;
|
|
2478
2690
|
try std.testing.expectEqual(boot_request_key, request.key);
|
|
@@ -2519,6 +2731,14 @@ test "window verbs bridge to the effects channel's label-addressed verbs" {
|
|
|
2519
2731
|
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().show_count);
|
|
2520
2732
|
try std.testing.expectEqualStrings("player", fx.windowActionState().lastLabel());
|
|
2521
2733
|
|
|
2734
|
+
Host.dispatch(fx, .hide_win);
|
|
2735
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().hide_count);
|
|
2736
|
+
try std.testing.expectEqualStrings("player", fx.windowActionState().lastLabel());
|
|
2737
|
+
|
|
2738
|
+
Host.dispatch(fx, .dock_off);
|
|
2739
|
+
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().dock_presence_count);
|
|
2740
|
+
try std.testing.expect(!fx.windowActionState().dock_visible);
|
|
2741
|
+
|
|
2522
2742
|
// quit_app decodes onto fx.quitApp — the graceful terminate request.
|
|
2523
2743
|
Host.dispatch(fx, .quit_app);
|
|
2524
2744
|
try std.testing.expectEqual(@as(u32, 1), fx.windowActionState().quit_count);
|