@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
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
//! Tier-3 relational effect coverage: SQLite executes synchronously on the
|
|
2
|
+
//! host side, but rows and terminals remain routed, ordered Msg values.
|
|
3
|
+
|
|
4
|
+
const std = @import("std");
|
|
5
|
+
const effects_mod = @import("effects.zig");
|
|
6
|
+
const relational_store = @import("relational_store.zig");
|
|
7
|
+
|
|
8
|
+
const Msg = union(enum) { db: effects_mod.EffectDbResult };
|
|
9
|
+
const Fx = effects_mod.Effects(Msg);
|
|
10
|
+
|
|
11
|
+
fn takeResult(fx: *Fx) !effects_mod.EffectDbResult {
|
|
12
|
+
return if (fx.takeMsg()) |msg| msg.db else error.TestExpectedMsg;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test "relational effects deliver encoded pages then a done terminal" {
|
|
16
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
17
|
+
defer database.deinit();
|
|
18
|
+
var fx = Fx.init(std.testing.allocator);
|
|
19
|
+
defer fx.deinit();
|
|
20
|
+
fx.bindRelationalStore(database.binding());
|
|
21
|
+
|
|
22
|
+
fx.dbExec(.{ .key = 1, .statements = &.{
|
|
23
|
+
.{ .sql = "CREATE TABLE note(id INTEGER PRIMARY KEY, title TEXT NOT NULL);" },
|
|
24
|
+
.{ .sql = "INSERT INTO note(id,title) VALUES(?1,?2);", .params = &.{ .{ .integer = 1 }, .{ .text = "one" } } },
|
|
25
|
+
.{ .sql = "INSERT INTO note(id,title) VALUES(?1,?2);", .params = &.{ .{ .integer = 2 }, .{ .text = "two" } } },
|
|
26
|
+
}, .on_result = Fx.dbMsg(.db) });
|
|
27
|
+
const wrote = try takeResult(&fx);
|
|
28
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.exec, wrote.kind);
|
|
29
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.ok, wrote.outcome);
|
|
30
|
+
|
|
31
|
+
fx.dbQuery(.{
|
|
32
|
+
.key = 2,
|
|
33
|
+
.sql = "SELECT id,title FROM note ORDER BY id;",
|
|
34
|
+
.on_result = Fx.dbMsg(.db),
|
|
35
|
+
});
|
|
36
|
+
const page = try takeResult(&fx);
|
|
37
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.page, page.kind);
|
|
38
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.ok, page.outcome);
|
|
39
|
+
try std.testing.expectEqual(@as(u32, 2), std.mem.readInt(u32, page.bytes[0..4], .little));
|
|
40
|
+
try std.testing.expectEqual(@as(u32, 2), std.mem.readInt(u32, page.bytes[4..8], .little));
|
|
41
|
+
const done = try takeResult(&fx);
|
|
42
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.done, done.kind);
|
|
43
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.ok, done.outcome);
|
|
44
|
+
try std.testing.expectEqual(@as(usize, 0), done.bytes.len);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test "relational query pagination emits every row without truncation" {
|
|
48
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
49
|
+
defer database.deinit();
|
|
50
|
+
var fx = Fx.init(std.testing.allocator);
|
|
51
|
+
defer fx.deinit();
|
|
52
|
+
fx.bindRelationalStore(database.binding());
|
|
53
|
+
|
|
54
|
+
fx.dbQuery(.{
|
|
55
|
+
.key = 22,
|
|
56
|
+
.sql = "WITH RECURSIVE n(value) AS (VALUES(1) UNION ALL SELECT value + 1 FROM n WHERE value < 300) SELECT value FROM n;",
|
|
57
|
+
.on_result = Fx.dbMsg(.db),
|
|
58
|
+
});
|
|
59
|
+
const first = try takeResult(&fx);
|
|
60
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.page, first.kind);
|
|
61
|
+
try std.testing.expectEqual(@as(u32, 256), std.mem.readInt(u32, first.bytes[4..8], .little));
|
|
62
|
+
try std.testing.expect(first.bytes.len <= relational_store.max_page_bytes);
|
|
63
|
+
const second = try takeResult(&fx);
|
|
64
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.page, second.kind);
|
|
65
|
+
try std.testing.expectEqual(@as(u32, 44), std.mem.readInt(u32, second.bytes[4..8], .little));
|
|
66
|
+
try std.testing.expect(second.bytes.len <= relational_store.max_page_bytes);
|
|
67
|
+
const done = try takeResult(&fx);
|
|
68
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.done, done.kind);
|
|
69
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
test "relational queries reject whole results beyond the total row bound" {
|
|
73
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
74
|
+
defer database.deinit();
|
|
75
|
+
var fx = Fx.init(std.testing.allocator);
|
|
76
|
+
defer fx.deinit();
|
|
77
|
+
fx.bindRelationalStore(database.binding());
|
|
78
|
+
|
|
79
|
+
var sql_buffer: [256]u8 = undefined;
|
|
80
|
+
const sql = try std.fmt.bufPrint(
|
|
81
|
+
&sql_buffer,
|
|
82
|
+
"WITH RECURSIVE n(value) AS (VALUES(1) UNION ALL SELECT value + 1 FROM n WHERE value < {d}) SELECT value FROM n;",
|
|
83
|
+
.{relational_store.max_result_rows + 1},
|
|
84
|
+
);
|
|
85
|
+
fx.dbQuery(.{ .key = 24, .sql = sql, .on_result = Fx.dbMsg(.db) });
|
|
86
|
+
const rejected = try takeResult(&fx);
|
|
87
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.done, rejected.kind);
|
|
88
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.rejected, rejected.outcome);
|
|
89
|
+
try std.testing.expectEqual(@as(usize, 0), rejected.bytes.len);
|
|
90
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
test "relational exec rejects TEMP schema objects" {
|
|
94
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
95
|
+
defer database.deinit();
|
|
96
|
+
var fx = Fx.init(std.testing.allocator);
|
|
97
|
+
defer fx.deinit();
|
|
98
|
+
fx.bindRelationalStore(database.binding());
|
|
99
|
+
|
|
100
|
+
fx.dbExec(.{
|
|
101
|
+
.key = 25,
|
|
102
|
+
.statements = &.{.{ .sql = "CREATE TEMP TABLE session_note(id INTEGER PRIMARY KEY) STRICT;" }},
|
|
103
|
+
.on_result = Fx.dbMsg(.db),
|
|
104
|
+
});
|
|
105
|
+
const rejected = try takeResult(&fx);
|
|
106
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.exec, rejected.kind);
|
|
107
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.misuse, rejected.outcome);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
test "callback-less relational queries release staged page storage" {
|
|
111
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
112
|
+
defer database.deinit();
|
|
113
|
+
var fx = Fx.init(std.testing.allocator);
|
|
114
|
+
defer fx.deinit();
|
|
115
|
+
fx.bindRelationalStore(database.binding());
|
|
116
|
+
|
|
117
|
+
fx.dbQuery(.{
|
|
118
|
+
.key = 23,
|
|
119
|
+
.sql = "SELECT zeroblob(4096) AS payload;",
|
|
120
|
+
});
|
|
121
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
test "relational exec rolls back the whole command and reports constraint" {
|
|
125
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
126
|
+
defer database.deinit();
|
|
127
|
+
var fx = Fx.init(std.testing.allocator);
|
|
128
|
+
defer fx.deinit();
|
|
129
|
+
fx.bindRelationalStore(database.binding());
|
|
130
|
+
|
|
131
|
+
fx.dbExec(.{ .key = 3, .statements = &.{.{ .sql = "CREATE TABLE item(id INTEGER PRIMARY KEY);" }}, .on_result = Fx.dbMsg(.db) });
|
|
132
|
+
_ = try takeResult(&fx);
|
|
133
|
+
fx.dbExec(.{ .key = 4, .statements = &.{
|
|
134
|
+
.{ .sql = "INSERT INTO item(id) VALUES(?1);", .params = &.{.{ .integer = 1 }} },
|
|
135
|
+
.{ .sql = "INSERT INTO item(id) VALUES(?1);", .params = &.{.{ .integer = 1 }} },
|
|
136
|
+
}, .on_result = Fx.dbMsg(.db) });
|
|
137
|
+
const failed = try takeResult(&fx);
|
|
138
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.constraint, failed.outcome);
|
|
139
|
+
|
|
140
|
+
fx.dbQuery(.{ .key = 5, .sql = "SELECT id FROM item;", .on_result = Fx.dbMsg(.db) });
|
|
141
|
+
const page = try takeResult(&fx);
|
|
142
|
+
try std.testing.expectEqual(@as(u32, 0), std.mem.readInt(u32, page.bytes[4..8], .little));
|
|
143
|
+
_ = try takeResult(&fx);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
test "query keys replace and cancel silently while exec duplicates reject loudly" {
|
|
147
|
+
var fx = Fx.init(std.testing.allocator);
|
|
148
|
+
defer fx.deinit();
|
|
149
|
+
fx.executor = .fake;
|
|
150
|
+
|
|
151
|
+
fx.dbQuery(.{ .key = 10, .sql = "SELECT 1;", .on_result = Fx.dbMsg(.db) });
|
|
152
|
+
fx.dbQuery(.{ .key = 10, .sql = "SELECT 2;", .on_result = Fx.dbMsg(.db) });
|
|
153
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
154
|
+
fx.cancelDbQuery(10);
|
|
155
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingDbCount());
|
|
156
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
157
|
+
|
|
158
|
+
const statements = [_]effects_mod.EffectDbStatement{.{ .sql = "CREATE TABLE duplicate(id INTEGER);" }};
|
|
159
|
+
fx.dbExec(.{ .key = 11, .statements = &statements, .on_result = Fx.dbMsg(.db) });
|
|
160
|
+
fx.dbExec(.{ .key = 11, .statements = &statements, .on_result = Fx.dbMsg(.db) });
|
|
161
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
162
|
+
const rejected = try takeResult(&fx);
|
|
163
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.exec, rejected.kind);
|
|
164
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.rejected, rejected.outcome);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
test "replacing a real relational query purges its staged pages" {
|
|
168
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
169
|
+
defer database.deinit();
|
|
170
|
+
var fx = Fx.init(std.testing.allocator);
|
|
171
|
+
defer fx.deinit();
|
|
172
|
+
fx.bindRelationalStore(database.binding());
|
|
173
|
+
|
|
174
|
+
fx.dbQuery(.{
|
|
175
|
+
.key = 12,
|
|
176
|
+
.sql = "WITH RECURSIVE n(value) AS (VALUES(1) UNION ALL SELECT value + 1 FROM n WHERE value < 300) SELECT value FROM n;",
|
|
177
|
+
.on_result = Fx.dbMsg(.db),
|
|
178
|
+
});
|
|
179
|
+
fx.dbQuery(.{ .key = 12, .sql = "SELECT 2 AS value;", .on_result = Fx.dbMsg(.db) });
|
|
180
|
+
const page = try takeResult(&fx);
|
|
181
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.page, page.kind);
|
|
182
|
+
try std.testing.expectEqual(@as(u32, 1), std.mem.readInt(u32, page.bytes[4..8], .little));
|
|
183
|
+
const done = try takeResult(&fx);
|
|
184
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.done, done.kind);
|
|
185
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
test "relational effects have a dedicated bounded slot family" {
|
|
189
|
+
var fx = Fx.init(std.testing.allocator);
|
|
190
|
+
defer fx.deinit();
|
|
191
|
+
fx.executor = .fake;
|
|
192
|
+
|
|
193
|
+
for (0..effects_mod.max_db_effects) |index| {
|
|
194
|
+
fx.dbQuery(.{ .key = 100 + index, .sql = "SELECT 1;", .on_result = Fx.dbMsg(.db) });
|
|
195
|
+
}
|
|
196
|
+
try std.testing.expectEqual(effects_mod.max_db_effects, fx.pendingDbCount());
|
|
197
|
+
fx.dbQuery(.{ .key = 1_000, .sql = "SELECT 1;", .on_result = Fx.dbMsg(.db) });
|
|
198
|
+
const rejected = try takeResult(&fx);
|
|
199
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.rejected, rejected.outcome);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
test "relational pages and terminals cross the journal boundary verbatim" {
|
|
203
|
+
const Capture = struct {
|
|
204
|
+
var records: [4]effects_mod.EffectResultRecord = undefined;
|
|
205
|
+
var payloads: [4][relational_store.max_page_bytes]u8 = undefined;
|
|
206
|
+
var count: usize = 0;
|
|
207
|
+
|
|
208
|
+
fn note(_: *anyopaque, record: effects_mod.EffectResultRecord) void {
|
|
209
|
+
records[count] = record;
|
|
210
|
+
@memcpy(payloads[count][0..record.payload.len], record.payload);
|
|
211
|
+
records[count].payload = payloads[count][0..record.payload.len];
|
|
212
|
+
count += 1;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
Capture.count = 0;
|
|
216
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
217
|
+
defer database.deinit();
|
|
218
|
+
var fx = Fx.init(std.testing.allocator);
|
|
219
|
+
defer fx.deinit();
|
|
220
|
+
fx.bindRelationalStore(database.binding());
|
|
221
|
+
var context: u8 = 0;
|
|
222
|
+
fx.bindJournal(.{ .context = &context, .record_fn = Capture.note });
|
|
223
|
+
|
|
224
|
+
fx.dbQuery(.{ .key = 40, .sql = "SELECT 7 AS answer;", .on_result = Fx.dbMsg(.db) });
|
|
225
|
+
const page = try takeResult(&fx);
|
|
226
|
+
try std.testing.expectEqual(@as(usize, 1), Capture.count);
|
|
227
|
+
try std.testing.expectEqual(effects_mod.EffectResultKind.db, Capture.records[0].kind);
|
|
228
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.page, effects_mod.dbKindFromJournalCode(Capture.records[0].code).?);
|
|
229
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.ok, effects_mod.dbOutcomeFromJournalCode(Capture.records[0].code).?);
|
|
230
|
+
try std.testing.expectEqualSlices(u8, page.bytes, Capture.records[0].payload);
|
|
231
|
+
const done = try takeResult(&fx);
|
|
232
|
+
try std.testing.expectEqual(@as(usize, 2), Capture.count);
|
|
233
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.done, effects_mod.dbKindFromJournalCode(Capture.records[1].code).?);
|
|
234
|
+
try std.testing.expectEqual(effects_mod.EffectDbOutcome.ok, effects_mod.dbOutcomeFromJournalCode(Capture.records[1].code).?);
|
|
235
|
+
try std.testing.expectEqual(@as(usize, 0), done.bytes.len);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
test "replay validates relational result shape before feeding it" {
|
|
239
|
+
var fx = Fx.init(std.testing.allocator);
|
|
240
|
+
defer fx.deinit();
|
|
241
|
+
fx.executor = .fake;
|
|
242
|
+
fx.dbQuery(.{ .key = 50, .sql = "SELECT 1;", .on_result = Fx.dbMsg(.db) });
|
|
243
|
+
|
|
244
|
+
var oversized: [relational_store.max_page_bytes + 1]u8 = @splat(0);
|
|
245
|
+
try std.testing.expectError(error.ReplayDamagedRecord, fx.feedDbResult(50, .page, .ok, &oversized));
|
|
246
|
+
try std.testing.expectError(error.ReplayDamagedRecord, fx.feedDbResult(50, .page, .corrupt, ""));
|
|
247
|
+
try std.testing.expectError(error.ReplayDamagedRecord, fx.feedDbResult(50, .done, .ok, "payload"));
|
|
248
|
+
try std.testing.expectError(error.ReplayDamagedRecord, fx.feedDbResult(50, .exec, .ok, ""));
|
|
249
|
+
const bad_tag_page = [_]u8{ 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 9 };
|
|
250
|
+
try std.testing.expectError(error.ReplayDamagedRecord, fx.feedDbResult(50, .page, .ok, &bad_tag_page));
|
|
251
|
+
|
|
252
|
+
const empty_page = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
253
|
+
try fx.feedDbResult(50, .page, .ok, &empty_page);
|
|
254
|
+
try fx.feedDbResult(50, .done, .ok, "");
|
|
255
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.page, (try takeResult(&fx)).kind);
|
|
256
|
+
try std.testing.expectEqual(effects_mod.EffectDbResultKind.done, (try takeResult(&fx)).kind);
|
|
257
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingDbCount());
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
test "live relational queries invalidate by table and coalesce until flush" {
|
|
261
|
+
var database = try relational_store.Database.openMemory(std.testing.allocator);
|
|
262
|
+
defer database.deinit();
|
|
263
|
+
var fx = Fx.init(std.testing.allocator);
|
|
264
|
+
defer fx.deinit();
|
|
265
|
+
fx.bindRelationalStore(database.binding());
|
|
266
|
+
|
|
267
|
+
fx.dbExec(.{ .key = 60, .statements = &.{
|
|
268
|
+
.{ .sql = "CREATE TABLE note(id INTEGER PRIMARY KEY) STRICT;" },
|
|
269
|
+
.{ .sql = "CREATE TABLE unrelated(id INTEGER PRIMARY KEY) STRICT;" },
|
|
270
|
+
}, .on_result = Fx.dbMsg(.db) });
|
|
271
|
+
_ = try takeResult(&fx);
|
|
272
|
+
fx.dbSubscribe(.{
|
|
273
|
+
.key = 61,
|
|
274
|
+
.sql = "SELECT id FROM note ORDER BY id;",
|
|
275
|
+
.tables = &.{"note"},
|
|
276
|
+
.on_result = Fx.dbMsg(.db),
|
|
277
|
+
});
|
|
278
|
+
const initial_page = try takeResult(&fx);
|
|
279
|
+
try std.testing.expectEqual(@as(u32, 0), std.mem.readInt(u32, initial_page.bytes[4..8], .little));
|
|
280
|
+
_ = try takeResult(&fx);
|
|
281
|
+
|
|
282
|
+
fx.dbExec(.{ .key = 62, .statements = &.{.{ .sql = "INSERT INTO note(id) VALUES(1);" }}, .on_result = Fx.dbMsg(.db) });
|
|
283
|
+
fx.dbExec(.{ .key = 63, .statements = &.{.{ .sql = "INSERT INTO note(id) VALUES(2);" }}, .on_result = Fx.dbMsg(.db) });
|
|
284
|
+
_ = try takeResult(&fx);
|
|
285
|
+
_ = try takeResult(&fx);
|
|
286
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
287
|
+
fx.flushDbSubscriptions();
|
|
288
|
+
const refreshed = try takeResult(&fx);
|
|
289
|
+
try std.testing.expectEqual(@as(u32, 2), std.mem.readInt(u32, refreshed.bytes[4..8], .little));
|
|
290
|
+
_ = try takeResult(&fx);
|
|
291
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
292
|
+
|
|
293
|
+
fx.dbExec(.{ .key = 64, .statements = &.{.{ .sql = "INSERT INTO unrelated(id) VALUES(1);" }}, .on_result = Fx.dbMsg(.db) });
|
|
294
|
+
_ = try takeResult(&fx);
|
|
295
|
+
fx.flushDbSubscriptions();
|
|
296
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
297
|
+
fx.dbUnsubscribe(61);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
test "replay keeps a live relational slot parked across repeated deliveries" {
|
|
301
|
+
var fx = Fx.init(std.testing.allocator);
|
|
302
|
+
defer fx.deinit();
|
|
303
|
+
fx.executor = .fake;
|
|
304
|
+
fx.dbSubscribe(.{ .key = 70, .sql = "SELECT 1 AS value;", .tables = &.{"note"}, .on_result = Fx.dbMsg(.db) });
|
|
305
|
+
const page = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 'v', 'a', 'l', 'u', 'e' };
|
|
306
|
+
try fx.feedDbResult(70, .page, .ok, &page);
|
|
307
|
+
try fx.feedDbResult(70, .done, .ok, "");
|
|
308
|
+
try fx.feedDbResult(70, .page, .ok, &page);
|
|
309
|
+
try fx.feedDbResult(70, .done, .ok, "");
|
|
310
|
+
for (0..4) |_| _ = try takeResult(&fx);
|
|
311
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingDbCount());
|
|
312
|
+
fx.dbUnsubscribe(70);
|
|
313
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingDbCount());
|
|
314
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
//! Tier-2 record-store effect coverage: the public Zig surface remains inert
|
|
2
|
+
//! command data until Effects performs it, and every SQLite answer returns as
|
|
3
|
+
//! the same routed/journaled host-result message family used by TS cores.
|
|
4
|
+
|
|
5
|
+
const std = @import("std");
|
|
6
|
+
const effects_mod = @import("effects.zig");
|
|
7
|
+
const record_store = @import("record_store.zig");
|
|
8
|
+
|
|
9
|
+
const Msg = union(enum) { result: effects_mod.EffectHostResult };
|
|
10
|
+
const Fx = effects_mod.Effects(Msg);
|
|
11
|
+
|
|
12
|
+
fn takeResult(fx: *Fx) !effects_mod.EffectHostResult {
|
|
13
|
+
for (0..100_000) |_| {
|
|
14
|
+
if (fx.takeMsg()) |msg| return msg.result;
|
|
15
|
+
std.Thread.yield() catch {};
|
|
16
|
+
}
|
|
17
|
+
return error.TestExpectedMsg;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
test "record-store effects round-trip CRUD and preserve empty versus missing" {
|
|
21
|
+
var store = try record_store.Store.openMemory(std.testing.allocator);
|
|
22
|
+
defer store.deinit();
|
|
23
|
+
var fx = Fx.init(std.testing.allocator);
|
|
24
|
+
defer fx.deinit();
|
|
25
|
+
fx.bindRecordStore(store.binding());
|
|
26
|
+
|
|
27
|
+
fx.storeSet(.{ .key = 1, .record_key = "doc/1", .bytes = "", .on_result = Fx.hostMsg(.result) });
|
|
28
|
+
const set = try takeResult(&fx);
|
|
29
|
+
try std.testing.expect(set.ok);
|
|
30
|
+
try std.testing.expectEqual(@as(usize, 0), set.bytes.len);
|
|
31
|
+
|
|
32
|
+
fx.storeGet(.{ .key = 2, .record_key = "doc/1", .on_result = Fx.hostMsg(.result) });
|
|
33
|
+
const hit = try takeResult(&fx);
|
|
34
|
+
try std.testing.expect(hit.ok);
|
|
35
|
+
try std.testing.expectEqualSlices(u8, &.{1}, hit.bytes);
|
|
36
|
+
|
|
37
|
+
fx.storeDelete(.{ .key = 3, .record_key = "doc/1", .on_result = Fx.hostMsg(.result) });
|
|
38
|
+
try std.testing.expect((try takeResult(&fx)).ok);
|
|
39
|
+
fx.storeGet(.{ .key = 4, .record_key = "doc/1", .on_result = Fx.hostMsg(.result) });
|
|
40
|
+
const miss = try takeResult(&fx);
|
|
41
|
+
try std.testing.expect(miss.ok);
|
|
42
|
+
try std.testing.expectEqualSlices(u8, &.{0}, miss.bytes);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
test "record-store effects apply setMany atomically and page prefix scans" {
|
|
46
|
+
var store = try record_store.Store.openMemory(std.testing.allocator);
|
|
47
|
+
defer store.deinit();
|
|
48
|
+
var fx = Fx.init(std.testing.allocator);
|
|
49
|
+
defer fx.deinit();
|
|
50
|
+
fx.bindRecordStore(store.binding());
|
|
51
|
+
|
|
52
|
+
const entries = [_]Fx.StoreEntry{
|
|
53
|
+
.{ .key = "chat/1", .bytes = "one" },
|
|
54
|
+
.{ .key = "chat/2", .bytes = "two" },
|
|
55
|
+
.{ .key = "other/1", .bytes = "skip" },
|
|
56
|
+
};
|
|
57
|
+
fx.storeSetMany(.{ .key = 10, .entries = &entries, .on_result = Fx.hostMsg(.result) });
|
|
58
|
+
try std.testing.expect((try takeResult(&fx)).ok);
|
|
59
|
+
|
|
60
|
+
fx.storeScan(.{ .key = 11, .prefix = "chat/", .limit = 1, .on_result = Fx.hostMsg(.result) });
|
|
61
|
+
const page = try takeResult(&fx);
|
|
62
|
+
try std.testing.expect(page.ok);
|
|
63
|
+
var cursor: usize = 0;
|
|
64
|
+
try std.testing.expectEqual(@as(u32, 1), readU32(page.bytes, &cursor));
|
|
65
|
+
try std.testing.expectEqualStrings("chat/1", readField(page.bytes, &cursor));
|
|
66
|
+
try std.testing.expectEqualStrings("one", readField(page.bytes, &cursor));
|
|
67
|
+
try std.testing.expectEqualStrings("chat/1", readField(page.bytes, &cursor));
|
|
68
|
+
try std.testing.expectEqual(page.bytes.len, cursor);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
test "a synchronous get in the same command walk observes the preceding write" {
|
|
72
|
+
var store = try record_store.Store.openMemory(std.testing.allocator);
|
|
73
|
+
defer store.deinit();
|
|
74
|
+
var fx = Fx.init(std.testing.allocator);
|
|
75
|
+
defer fx.deinit();
|
|
76
|
+
fx.bindRecordStore(store.binding());
|
|
77
|
+
|
|
78
|
+
fx.storeSet(.{ .key = 12, .record_key = "ordered/key", .bytes = "visible", .on_result = Fx.hostMsg(.result) });
|
|
79
|
+
fx.storeGet(.{ .key = 13, .record_key = "ordered/key", .on_result = Fx.hostMsg(.result) });
|
|
80
|
+
|
|
81
|
+
const first = try takeResult(&fx);
|
|
82
|
+
const second = try takeResult(&fx);
|
|
83
|
+
try std.testing.expect(first.ok);
|
|
84
|
+
try std.testing.expect(second.ok);
|
|
85
|
+
const read = if (first.key == 13) first else second;
|
|
86
|
+
try std.testing.expect(read.ok);
|
|
87
|
+
try std.testing.expectEqualSlices(u8, "visible", read.bytes[1..]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
test "record-store effects reject bounds and absent capability loudly" {
|
|
91
|
+
var fx = Fx.init(std.testing.allocator);
|
|
92
|
+
defer fx.deinit();
|
|
93
|
+
fx.storeGet(.{ .key = 20, .record_key = "missing", .on_result = Fx.hostMsg(.result) });
|
|
94
|
+
const absent = try takeResult(&fx);
|
|
95
|
+
try std.testing.expect(!absent.ok);
|
|
96
|
+
try std.testing.expectEqualStrings("rejected", absent.bytes);
|
|
97
|
+
|
|
98
|
+
var oversized_key: [record_store.max_key_bytes + 1]u8 = undefined;
|
|
99
|
+
@memset(&oversized_key, 'k');
|
|
100
|
+
fx.storeGet(.{ .key = 21, .record_key = &oversized_key, .on_result = Fx.hostMsg(.result) });
|
|
101
|
+
const bounded = try takeResult(&fx);
|
|
102
|
+
try std.testing.expect(!bounded.ok);
|
|
103
|
+
try std.testing.expectEqualStrings("bad_key", bounded.bytes);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test "record-store requests have capacity independent of generic effects" {
|
|
107
|
+
var fx = Fx.init(std.testing.allocator);
|
|
108
|
+
defer fx.deinit();
|
|
109
|
+
fx.executor = .fake;
|
|
110
|
+
|
|
111
|
+
for (0..effects_mod.max_effects) |index| {
|
|
112
|
+
fx.hostRequest(.{
|
|
113
|
+
.key = 100 + index,
|
|
114
|
+
.name = "fixture.request",
|
|
115
|
+
.on_result = Fx.hostMsg(.result),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (0..effects_mod.max_store_effects) |index| {
|
|
119
|
+
fx.storeGet(.{
|
|
120
|
+
.key = 1_000 + index,
|
|
121
|
+
.record_key = "fixture/key",
|
|
122
|
+
.on_result = Fx.hostMsg(.result),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
try std.testing.expectEqual(
|
|
126
|
+
effects_mod.max_effects + effects_mod.max_store_effects,
|
|
127
|
+
fx.pendingHostCount(),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
fx.storeGet(.{
|
|
131
|
+
.key = 2_000,
|
|
132
|
+
.record_key = "fixture/overflow",
|
|
133
|
+
.on_result = Fx.hostMsg(.result),
|
|
134
|
+
});
|
|
135
|
+
const refused = try takeResult(&fx);
|
|
136
|
+
try std.testing.expect(!refused.ok);
|
|
137
|
+
try std.testing.expectEqualStrings("rejected", refused.bytes);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
test "record-store keys replace on reissue and cancel silently" {
|
|
141
|
+
var fx = Fx.init(std.testing.allocator);
|
|
142
|
+
defer fx.deinit();
|
|
143
|
+
fx.executor = .fake;
|
|
144
|
+
|
|
145
|
+
fx.storeGet(.{ .key = 30, .record_key = "old/key", .on_result = Fx.hostMsg(.result) });
|
|
146
|
+
fx.storeGet(.{ .key = 30, .record_key = "new/key", .on_result = Fx.hostMsg(.result) });
|
|
147
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
148
|
+
const replacement = fx.pendingHostAt(0).?;
|
|
149
|
+
try std.testing.expectEqualStrings("core.store.get", replacement.name);
|
|
150
|
+
var payload_at: usize = 4;
|
|
151
|
+
try std.testing.expectEqualStrings("new/key", readField(replacement.payload, &payload_at));
|
|
152
|
+
try std.testing.expectEqual(replacement.payload.len, payload_at);
|
|
153
|
+
try fx.feedHostResult(30, true, &.{ 1, 'n', 'e', 'w' });
|
|
154
|
+
const result = try takeResult(&fx);
|
|
155
|
+
try std.testing.expectEqual(@as(u64, 30), result.key);
|
|
156
|
+
try std.testing.expectEqualSlices(u8, &.{ 1, 'n', 'e', 'w' }, result.bytes);
|
|
157
|
+
|
|
158
|
+
fx.storeScan(.{ .key = 31, .prefix = "chat/", .on_result = Fx.hostMsg(.result) });
|
|
159
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
160
|
+
fx.cancel(31);
|
|
161
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
162
|
+
try std.testing.expectError(error.EffectNotFound, fx.feedHostResult(31, true, &.{ 0, 0, 0, 0, 0, 0, 0, 0 }));
|
|
163
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
test "draining a store terminal retires a producer preempted after enqueue" {
|
|
167
|
+
var fx = Fx.init(std.testing.allocator);
|
|
168
|
+
defer fx.deinit();
|
|
169
|
+
fx.executor = .fake;
|
|
170
|
+
|
|
171
|
+
const key = 32;
|
|
172
|
+
fx.storeGet(.{ .key = key, .record_key = "doc/32", .on_result = Fx.hostMsg(.result) });
|
|
173
|
+
try fx.feedHostResult(key, true, &.{0});
|
|
174
|
+
|
|
175
|
+
// Reconstruct the real write worker's preemption window exactly:
|
|
176
|
+
// `storeWorkerMain` publishes the terminal entry, then stores
|
|
177
|
+
// `.draining`. A consumer can acquire the queue between those two
|
|
178
|
+
// operations and observe the queued result while the slot still says
|
|
179
|
+
// `.running`. The fake feed stores first, so rewind just that state.
|
|
180
|
+
for (&fx.slots) |*slot| {
|
|
181
|
+
if (slot.kind == .store and slot.key == key) slot.state.store(.running, .release);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const result = try takeResult(&fx);
|
|
185
|
+
try std.testing.expect(result.ok);
|
|
186
|
+
try std.testing.expectEqualSlices(u8, &.{0}, result.bytes);
|
|
187
|
+
|
|
188
|
+
// Delivery is the key-freeing instant. The drain must publish the
|
|
189
|
+
// terminal state itself rather than depending on the preempted worker
|
|
190
|
+
// to resume before update handles the result.
|
|
191
|
+
for (&fx.slots) |*slot| {
|
|
192
|
+
if (slot.kind != .store or slot.key != key) continue;
|
|
193
|
+
try std.testing.expectEqual(.draining, slot.state.load(.acquire));
|
|
194
|
+
try std.testing.expect(slot.fetch_buffer == null);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
return error.TestExpectedStoreSlot;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fn readU32(bytes: []const u8, cursor: *usize) u32 {
|
|
201
|
+
const value = std.mem.readInt(u32, bytes[cursor.*..][0..4], .little);
|
|
202
|
+
cursor.* += 4;
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn readField(bytes: []const u8, cursor: *usize) []const u8 {
|
|
207
|
+
const len: usize = @intCast(readU32(bytes, cursor));
|
|
208
|
+
const field = bytes[cursor.*..][0..len];
|
|
209
|
+
cursor.* += len;
|
|
210
|
+
return field;
|
|
211
|
+
}
|
package/src/runtime/flow.zig
CHANGED
|
@@ -185,6 +185,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
185
185
|
const runtime_index = try WindowViewMethods().reserveWindow(self, window.id, window.label, window.resolvedTitle(app_info.app_name), null, true, .allow_source_less);
|
|
186
186
|
self.windows[runtime_index].activate_on_show = window.activate_on_show;
|
|
187
187
|
self.windows[runtime_index].info.focused = window.activate_on_show and window.show == .immediate;
|
|
188
|
+
self.windows[runtime_index].info.hidden = window.show == .hidden;
|
|
188
189
|
self.windows[runtime_index].main_focused = self.windows[runtime_index].info.focused;
|
|
189
190
|
self.windows[runtime_index].info.frame = window.default_frame;
|
|
190
191
|
self.windows[runtime_index].main_frame = geometry.RectF.init(0, 0, window.default_frame.width, window.default_frame.height);
|
|
@@ -444,6 +445,13 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
444
445
|
.window_id = command.window_id,
|
|
445
446
|
});
|
|
446
447
|
},
|
|
448
|
+
.tray_command => |command| {
|
|
449
|
+
try dispatchCommand(self, app, .{
|
|
450
|
+
.name = command.name,
|
|
451
|
+
.source = .tray,
|
|
452
|
+
.window_id = command.window_id,
|
|
453
|
+
});
|
|
454
|
+
},
|
|
447
455
|
.timer => |timer_event| {
|
|
448
456
|
try dispatchEvent(self, app, .{ .timer = timer_event });
|
|
449
457
|
},
|
|
@@ -1016,7 +1024,12 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
1016
1024
|
self.command_count += 1;
|
|
1017
1025
|
const enable = std.mem.eql(u8, command.value, "on");
|
|
1018
1026
|
if (!enable and !std.mem.eql(u8, command.value, "off")) return error.InvalidCommand;
|
|
1019
|
-
if (enable and !self.frame_profile.enabled)
|
|
1027
|
+
if (enable and !self.frame_profile.enabled) {
|
|
1028
|
+
self.frame_profile.reset();
|
|
1029
|
+
for (self.views[0..self.view_count]) |*view| {
|
|
1030
|
+
view.gpu_frame_profile_timestamp_ns = 0;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1020
1033
|
self.frame_profile.enabled = enable;
|
|
1021
1034
|
self.invalidateFor(.command, null);
|
|
1022
1035
|
},
|
|
@@ -45,10 +45,13 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
45
45
|
// interval, useless for drop detection). Profiling-gated;
|
|
46
46
|
// a dropped frame shows as max >> p50 on this channel.
|
|
47
47
|
if (self.frame_profile.enabled) {
|
|
48
|
-
const previous_timestamp_ns = self.views[index].
|
|
48
|
+
const previous_timestamp_ns = self.views[index].gpu_frame_profile_timestamp_ns;
|
|
49
49
|
if (previous_timestamp_ns > 0 and frame_event.timestamp_ns > previous_timestamp_ns) {
|
|
50
50
|
self.frame_profile.recordNs(.interval, frame_event.timestamp_ns - previous_timestamp_ns);
|
|
51
51
|
}
|
|
52
|
+
self.views[index].gpu_frame_profile_timestamp_ns = frame_event.timestamp_ns;
|
|
53
|
+
} else {
|
|
54
|
+
self.views[index].gpu_frame_profile_timestamp_ns = 0;
|
|
52
55
|
}
|
|
53
56
|
self.views[index].gpu_timestamp_ns = frame_event.timestamp_ns;
|
|
54
57
|
self.views[index].recordGpuSurfaceFrameInterval(frame_event.frame_interval_ns);
|
|
@@ -106,12 +109,14 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
106
109
|
// state 60 times a second.
|
|
107
110
|
const first_frame_latency_recorded = !first_frame_latency_was_recorded and self.views[index].gpu_first_frame_latency_recorded;
|
|
108
111
|
if (self.views[index].gpu_frame_nonblank != frame_event.nonblank or
|
|
112
|
+
self.views[index].gpu_occluded != frame_event.occluded or
|
|
109
113
|
self.views[index].gpu_backend != frame_event.backend or
|
|
110
114
|
first_frame_latency_recorded)
|
|
111
115
|
{
|
|
112
116
|
self.invalidateFor(.state, self.views[index].frame);
|
|
113
117
|
}
|
|
114
118
|
self.views[index].gpu_frame_nonblank = frame_event.nonblank;
|
|
119
|
+
self.views[index].gpu_occluded = frame_event.occluded;
|
|
115
120
|
self.views[index].gpu_sample_color = frame_event.sample_color;
|
|
116
121
|
self.views[index].gpu_backend = frame_event.backend;
|
|
117
122
|
self.views[index].gpu_pixel_format = frame_event.pixel_format;
|
|
@@ -307,6 +307,48 @@ test "runtime dispatches tray item commands" {
|
|
|
307
307
|
try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .label = "Missing id", .command = "app.missing-id" }}));
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
test "runtime dispatches named tray lifecycle commands with tray source" {
|
|
311
|
+
const TestApp = struct {
|
|
312
|
+
command_count: u32 = 0,
|
|
313
|
+
last_name: []const u8 = "",
|
|
314
|
+
last_source: CommandSource = .runtime,
|
|
315
|
+
last_window_id: platform.WindowId = 0,
|
|
316
|
+
|
|
317
|
+
fn app(self: *@This()) App {
|
|
318
|
+
return .{ .context = self, .name = "tray-lifecycle-command", .source = platform.WebViewSource.html("<p>Tray</p>"), .event_fn = event };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
322
|
+
_ = runtime;
|
|
323
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
324
|
+
switch (event_value) {
|
|
325
|
+
.command => |command| {
|
|
326
|
+
self.command_count += 1;
|
|
327
|
+
self.last_name = command.name;
|
|
328
|
+
self.last_source = command.source;
|
|
329
|
+
self.last_window_id = command.window_id;
|
|
330
|
+
},
|
|
331
|
+
else => {},
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
337
|
+
defer harness.destroy(std.testing.allocator);
|
|
338
|
+
var app_state: TestApp = .{};
|
|
339
|
+
try harness.start(app_state.app());
|
|
340
|
+
|
|
341
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .tray_command = .{
|
|
342
|
+
.name = "app.refresh",
|
|
343
|
+
.window_id = 3,
|
|
344
|
+
} });
|
|
345
|
+
|
|
346
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
347
|
+
try std.testing.expectEqualStrings("app.refresh", app_state.last_name);
|
|
348
|
+
try std.testing.expectEqual(CommandSource.tray, app_state.last_source);
|
|
349
|
+
try std.testing.expectEqual(@as(platform.WindowId, 3), app_state.last_window_id);
|
|
350
|
+
}
|
|
351
|
+
|
|
310
352
|
test "runtime dispatches file drop events to app and window bridge" {
|
|
311
353
|
const TestApp = struct {
|
|
312
354
|
drop_count: u32 = 0,
|