Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

tests: split ipc_tests.zig and config/loader_tests.zig by area

Claudec20e98d63efb
diff --git a/src/config/loader_fields_tests.zig b/src/config/loader_fields_tests.zig
new file mode 100644
index 0000000..a100fe3
--- /dev/null
+++ b/src/config/loader_fields_tests.zig
@@ -0,0 +1,329 @@
+//! Config field tests: ranges and derived zoom state, idle rules, window rules, laptop controls and night light.
+
+const std = @import("std");
+const keybinds = @import("keybinds.zig");
+const Action = keybinds.Action;
+const types = @import("types.zig");
+const window_rules = @import("window_rules.zig");
+const schedule_mod = @import("schedule.zig");
+const ScheduleMode = schedule_mod.ScheduleMode;
+const NightLightConfig = schedule_mod.NightLightConfig;
+const AccelProfile = types.AccelProfile;
+const applyInputKey = @import("loader_fields.zig").applyInputKey;
+const applyCompositorKey = @import("loader_fields.zig").applyCompositorKey;
+const applyIdleKey = @import("loader_fields.zig").applyIdleKey;
+const default_zoom_percents = @import("loader.zig").default_zoom_percents;
+const InputConfig = @import("loader.zig").InputConfig;
+const CompositorConfig = @import("loader.zig").CompositorConfig;
+const IdleConfig = @import("loader.zig").IdleConfig;
+const default = @import("loader.zig").default;
+const parse = @import("loader.zig").parse;
+
+test "config field parsing preserves ranges and derived zoom state" {
+ var input = InputConfig{};
+ const a = std.testing.allocator;
+ inline for (.{
+ .{ "key_repeat_delay", "1", "5000", "0", "5001" },
+ .{ "key_repeat_rate", "1", "200", "0", "201" },
+ .{ "cursor_size", "1", "256", "0", "257" },
+ }) |fixture| {
+ try applyInputKey(&input, a, fixture[0], fixture[1]);
+ try std.testing.expectEqual(try std.fmt.parseInt(u32, fixture[1], 10), @field(input, fixture[0]));
+ try applyInputKey(&input, a, fixture[0], fixture[2]);
+ try std.testing.expectEqual(try std.fmt.parseInt(u32, fixture[2], 10), @field(input, fixture[0]));
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, fixture[0], fixture[3]));
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, fixture[0], fixture[4]));
+ }
+ try applyInputKey(&input, a, "pointer_speed", "-1");
+ try std.testing.expectEqual(@as(f32, -1), input.pointer_speed);
+ try applyInputKey(&input, a, "pointer_speed", "1");
+ try std.testing.expectEqual(@as(f32, 1), input.pointer_speed);
+ try applyInputKey(&input, a, "pointer_speed_touchpad", "-1");
+ try std.testing.expectEqual(@as(f32, -1), input.pointer_speed_touchpad);
+ try applyInputKey(&input, a, "pointer_speed_touchpad", "1");
+ try std.testing.expectEqual(@as(f32, 1), input.pointer_speed_touchpad);
+ try applyInputKey(&input, a, "disable_while_typing_touchpad", "true");
+ try std.testing.expect(input.disable_while_typing_touchpad);
+ try applyInputKey(&input, a, "disable_while_typing_touchpad", "false");
+ try std.testing.expect(!input.disable_while_typing_touchpad);
+ inline for (.{ "-1.01", "1.01", "nan", "inf" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "pointer_speed", v));
+ }
+ inline for (.{ "-1.01", "1.01", "nan", "inf" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "pointer_speed_touchpad", v));
+ }
+ inline for (.{ "natural_scroll", "invert_scroll", "tap_to_click", "tap_drag", "disable_while_typing" }) |key| {
+ try applyInputKey(&input, a, key, "false");
+ try std.testing.expect(!@field(input, key));
+ try applyInputKey(&input, a, key, "true");
+ try std.testing.expect(@field(input, key));
+ }
+ try applyInputKey(&input, a, "cursor_theme", "\"custom\"");
+ defer a.free(input.cursor_theme);
+ try std.testing.expectEqualStrings("custom", input.cursor_theme);
+
+ try applyInputKey(&input, a, "accel_profile", "\"flat\"");
+ try std.testing.expectEqual(AccelProfile.flat, input.accel_profile);
+ try applyInputKey(&input, a, "accel_profile", "bezier");
+ try std.testing.expectEqual(AccelProfile.bezier, input.accel_profile);
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_profile", "\"nope\""));
+
+ try applyInputKey(&input, a, "accel_p1", "[0.0, 0.0]");
+ try std.testing.expectEqual([2]f32{ 0.0, 0.0 }, input.accel_p1);
+ try applyInputKey(&input, a, "accel_p2", "[ 0.15 , 1.0 ]");
+ try std.testing.expectEqual([2]f32{ 0.15, 1.0 }, input.accel_p2);
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[-0.1, 0.0]"));
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[1.1, 0.0]"));
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[0.0]"));
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[0.0, 0.0, 0.0]"));
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "bad"));
+
+ try applyInputKey(&input, a, "accel_max_speed", "10.0");
+ try std.testing.expectEqual(@as(f32, 10.0), input.accel_max_speed);
+ try applyInputKey(&input, a, "accel_max_speed", "25.5");
+ try std.testing.expectEqual(@as(f32, 25.5), input.accel_max_speed);
+ inline for (.{ "0", "-1", "nan", "inf" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_max_speed", v));
+ }
+
+ var c = CompositorConfig{};
+ try std.testing.expectEqual(types.DockPosition.bottom, c.dock_position);
+ inline for (.{ "top", "bottom", "left", "right" }) |value| {
+ try applyCompositorKey(&c, a, "dock_position", value);
+ try std.testing.expectEqual(std.meta.stringToEnum(types.DockPosition, value).?, c.dock_position);
+ }
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "dock_position", "center"));
+ try std.testing.expectEqual(@as(u32, 0), c.windowGap());
+ c.desktop_mode = .workspaces;
+ try std.testing.expectEqual(@as(u32, 8), c.windowGap());
+ try applyCompositorKey(&c, a, "window_gap", "0");
+ try std.testing.expectEqual(@as(u32, 0), c.windowGap());
+ c.desktop_mode = .canvas;
+ inline for (.{
+ .{ "canvas_width", "1", "100000", "0", "100001" },
+ .{ "canvas_height", "1", "100000", "0", "100001" },
+ .{ "window_gap", "0", "512", "513", "514" },
+ .{ "border_radius", "0", "128", "129", "130" },
+ .{ "dock_height", "48", "96", "47", "97" },
+ }) |fixture| {
+ try applyCompositorKey(&c, a, fixture[0], fixture[1]);
+ try std.testing.expectEqual(@as(@TypeOf(@field(c, fixture[0])), try std.fmt.parseInt(u32, fixture[1], 10)), @field(c, fixture[0]));
+ try applyCompositorKey(&c, a, fixture[0], fixture[2]);
+ try std.testing.expectEqual(@as(@TypeOf(@field(c, fixture[0])), try std.fmt.parseInt(u32, fixture[2], 10)), @field(c, fixture[0]));
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, fixture[0], fixture[3]));
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, fixture[0], fixture[4]));
+ }
+ inline for (.{ "1", "1.05", "1.5" }) |value| {
+ try applyCompositorKey(&c, a, "dock_hover_zoom", value);
+ try std.testing.expectEqual(try std.fmt.parseFloat(f32, value), c.dock_hover_zoom);
+ }
+ inline for (.{ "nan", "inf", "0.99", "1.51" }) |value| {
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "dock_hover_zoom", value));
+ }
+ inline for (.{ "camera_zoom_min", "camera_zoom_max", "inactive_opacity" }) |key| {
+ try applyCompositorKey(&c, a, key, "0.5");
+ try std.testing.expectEqual(@as(f32, 0.5), @field(c, key));
+ inline for (.{ "nan", "inf", "-0.1", "8.1" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, key, v));
+ }
+ }
+ inline for (.{ "camera_zoom_min", "camera_zoom_max" }) |key| {
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, key, "0"));
+ try applyCompositorKey(&c, a, key, "8");
+ try std.testing.expectEqual(@as(f32, 8), @field(c, key));
+ }
+ try applyCompositorKey(&c, a, "inactive_opacity", "0");
+ try std.testing.expectEqual(@as(f32, 0), c.inactive_opacity);
+ try applyCompositorKey(&c, a, "inactive_opacity", "1");
+ try std.testing.expectEqual(@as(f32, 1), c.inactive_opacity);
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "inactive_opacity", "1.01"));
+ try std.testing.expectEqual(@as(?f32, null), c.terminal_opacity);
+ try applyCompositorKey(&c, a, "terminal_opacity", "0.85");
+ try std.testing.expectEqual(@as(?f32, 0.85), c.terminal_opacity);
+ inline for (.{ "nan", "-0.1", "1.01" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "terminal_opacity", v));
+ }
+ try std.testing.expectEqual(@as(?f32, null), c.dock_opacity);
+ try std.testing.expect(!c.dock_active_highlight);
+ try applyCompositorKey(&c, a, "dock_opacity", "0.6");
+ try std.testing.expectEqual(@as(?f32, 0.6), c.dock_opacity);
+ inline for (.{ "nan", "-0.1", "1.01" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "dock_opacity", v));
+ }
+ try applyCompositorKey(&c, a, "dock_active_highlight", "true");
+ try std.testing.expect(c.dock_active_highlight);
+ try std.testing.expect(c.inactive_dim);
+ try std.testing.expectEqual(@as(f32, 0.08), c.inactive_dim_amount);
+ try applyCompositorKey(&c, a, "inactive_dim", "false");
+ try std.testing.expect(!c.inactive_dim);
+ try applyCompositorKey(&c, a, "inactive_dim_amount", "0.5");
+ try std.testing.expectEqual(@as(f32, 0.5), c.inactive_dim_amount);
+ inline for (.{ "nan", "inf", "-0.1", "0.51" }) |v| {
+ try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "inactive_dim_amount", v));
+ }
+ try applyCompositorKey(&c, a, "focus_follows_mouse", "true");
+ try std.testing.expect(c.focus_follows_mouse);
+ try applyCompositorKey(&c, a, "xwayland", "false");
+ try std.testing.expect(!c.xwayland);
+ try applyCompositorKey(&c, a, "zoom_steps", "[1, 0.75]");
+ try std.testing.expectEqual(@as(u8, 2), c.zoom_step_count);
+ try std.testing.expectEqualSlices(f32, &.{ 1, 0.75 }, c.zoom_steps[0..2]);
+ try applyCompositorKey(&c, a, "zoom_step_count", "7");
+ try applyCompositorKey(&c, a, "zoom_percents", "[20]");
+ try std.testing.expectEqual(@as(u8, 2), c.zoom_step_count);
+ try std.testing.expectEqualSlices(u8, &default_zoom_percents, c.zoom_percents);
+ try applyInputKey(&input, a, "unknown", "ignored");
+ try applyCompositorKey(&c, a, "unknown", "ignored");
+}
+
+test "idle field rules preserve optional enabled and strict unknown keys" {
+ const a = std.testing.allocator;
+ var idle = IdleConfig{};
+ try std.testing.expectEqual(@as(?bool, null), idle.enabled);
+ try applyIdleKey(&idle, a, "enabled", "false");
+ try std.testing.expectEqual(@as(?bool, false), idle.enabled);
+ try applyIdleKey(&idle, a, "enabled", "true");
+ try std.testing.expectEqual(@as(?bool, true), idle.enabled);
+ try std.testing.expectError(error.InvalidValue, applyIdleKey(&idle, a, "enabled", "null"));
+ inline for (.{ "blank_after_seconds", "suspend_after_seconds" }) |key| {
+ try applyIdleKey(&idle, a, key, "0");
+ try std.testing.expectEqual(@as(u32, 0), @field(idle, key));
+ try applyIdleKey(&idle, a, key, "4294967295");
+ try std.testing.expectEqual(std.math.maxInt(u32), @field(idle, key));
+ try std.testing.expectError(error.Overflow, applyIdleKey(&idle, a, key, "4294967296"));
+ }
+ try std.testing.expectError(error.InvalidField, applyIdleKey(&idle, a, "unknown", "ignored"));
+}
+
+test "window_rules TOML parsing and validation" {
+ const toml =
+ \\[[window_rules]]
+ \\app_id = "org.telegram.desktop"
+ \\exclude_title = "Media viewer"
+ \\output = "DP-2"
+ \\center = true
+ \\width = 900
+ \\height = 700
+ \\
+ \\[[window_rules]]
+ \\app_id = ["firefox", "chromium"]
+ \\title = "Picture-in-Picture"
+ \\opacity = 0.9
+ \\skip_taskbar = true
+ \\focus = false
+ \\
+ \\[[window_rules]]
+ \\x11_class = "Steam"
+ \\dialog = false
+ \\maximized = true
+ \\
+ \\[[window_rules]]
+ \\app_id = "foot"
+ \\decorations = "client"
+ ;
+
+ var cfg = try parse(std.testing.allocator, toml, "rules_test");
+ defer cfg.deinit();
+
+ try std.testing.expectEqual(@as(usize, 4), cfg.window_rules.len);
+
+ const r0 = cfg.window_rules[0];
+ try std.testing.expectEqualStrings("org.telegram.desktop", r0.app_id.?[0]);
+ try std.testing.expectEqualStrings("Media viewer", r0.exclude_title.?[0]);
+ try std.testing.expectEqualStrings("DP-2", r0.output.?);
+ try std.testing.expectEqual(@as(?bool, true), r0.center);
+ try std.testing.expectEqual(@as(?u32, 900), r0.width);
+ try std.testing.expectEqual(@as(?u32, 700), r0.height);
+
+ const r1 = cfg.window_rules[1];
+ try std.testing.expectEqual(@as(usize, 2), r1.app_id.?.len);
+ try std.testing.expectEqualStrings("firefox", r1.app_id.?[0]);
+ try std.testing.expectEqualStrings("chromium", r1.app_id.?[1]);
+ try std.testing.expectEqualStrings("Picture-in-Picture", r1.title.?[0]);
+ try std.testing.expectEqual(@as(?f32, 0.9), r1.opacity);
+ try std.testing.expectEqual(@as(?bool, true), r1.skip_taskbar);
+ try std.testing.expectEqual(@as(?bool, false), r1.focus);
+
+ const r2 = cfg.window_rules[2];
+ try std.testing.expectEqualStrings("Steam", r2.x11_class.?[0]);
+ try std.testing.expectEqual(@as(?bool, false), r2.dialog);
+ try std.testing.expectEqual(@as(?bool, true), r2.maximized);
+
+ const r3 = cfg.window_rules[3];
+ try std.testing.expectEqualStrings("foot", r3.app_id.?[0]);
+ try std.testing.expectEqual(window_rules.DecorationMode.client, r3.decorations.?);
+
+ // Conflict error in TOML
+ const bad_toml =
+ \\[[window_rules]]
+ \\center = true
+ \\x = 100
+ ;
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, bad_toml, "bad_rule"));
+
+ // Unknown field error
+ const bad_key =
+ \\[[window_rules]]
+ \\unknown_field = "value"
+ ;
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, bad_key, "bad_key"));
+}
+
+test "existing configs inherit laptop controls and can override or disable them" {
+ var cfg = try parse(std.testing.allocator,
+ \\[keybinds]
+ \\"super+t" = "spawn foot"
+ \\"XF86AudioMute" = "noop"
+ , "hardware");
+ defer cfg.deinit();
+ const up = try keybinds.parseKeybind("XF86AudioRaiseVolume");
+ try std.testing.expectEqual(Action.volume_up, cfg.lookupKeybind(up.modifiers, up.sym).?);
+ const mute = try keybinds.parseKeybind("XF86AudioMute");
+ try std.testing.expectEqual(Action.noop, cfg.lookupKeybind(mute.modifiers, mute.sym).?);
+}
+
+test "night_light config parsing and defaults" {
+ var def = try default(std.testing.allocator);
+ defer def.deinit();
+
+ try std.testing.expectEqual(true, def.night_light.enabled);
+ try std.testing.expectEqual(ScheduleMode.always, def.night_light.schedule);
+ try std.testing.expectEqual(@as(u32, 5000), def.night_light.temperature);
+ try std.testing.expectEqual(@as(u32, 6500), def.night_light.day_temperature);
+ try std.testing.expectEqual(@as(u16, 21 * 60), def.night_light.start);
+ try std.testing.expectEqual(@as(u16, 7 * 60), def.night_light.end);
+ try std.testing.expectEqual(@as(u16, 30), def.night_light.transition_minutes);
+ try std.testing.expectEqual(@as(?f64, null), def.night_light.latitude);
+ try std.testing.expectEqual(@as(?f64, null), def.night_light.longitude);
+
+ // Snapshot survives deinit (holds only scalars)
+ var snapshot: NightLightConfig = undefined;
+ {
+ var custom = try parse(std.testing.allocator,
+ \\[night_light]
+ \\enabled = true
+ \\schedule = "fixed"
+ \\temperature = 3400
+ \\day_temperature = 6000
+ \\start = "22:00"
+ \\end = "06:30"
+ \\transition_minutes = 45
+ \\
+ \\[[outputs]]
+ \\name = "DP-2"
+ \\night_light = false
+ \\gamma = 1.2
+ , "custom");
+ snapshot = custom.night_light;
+ try std.testing.expectEqual(true, custom.outputs[0].night_light == false);
+ try std.testing.expectApproxEqAbs(@as(f32, 1.2), custom.outputs[0].gamma, 0.001);
+ custom.deinit();
+ }
+ try std.testing.expectEqual(true, snapshot.enabled);
+ try std.testing.expectEqual(ScheduleMode.fixed, snapshot.schedule);
+ try std.testing.expectEqual(@as(u32, 3400), snapshot.temperature);
+ try std.testing.expectEqual(@as(u32, 6000), snapshot.day_temperature);
+ try std.testing.expectEqual(@as(u16, 22 * 60), snapshot.start);
+ try std.testing.expectEqual(@as(u16, 6 * 60 + 30), snapshot.end);
+ try std.testing.expectEqual(@as(u16, 45), snapshot.transition_minutes);
+}
diff --git a/src/config/loader_sections_tests.zig b/src/config/loader_sections_tests.zig
new file mode 100644
index 0000000..826236f
--- /dev/null
+++ b/src/config/loader_sections_tests.zig
@@ -0,0 +1,414 @@
+//! Config section tests: outputs, night light schedules, animations, polkit, canvas, input methods, sandboxes, the mini map, workspaces and theme layering.
+
+const std = @import("std");
+const theme_mod = @import("ui").theme;
+const keybinds = @import("keybinds.zig");
+const Action = keybinds.Action;
+const default_file = @import("default.zig");
+const anim = @import("ui").anim;
+const output_transform = @import("output_transform.zig");
+const schedule_mod = @import("schedule.zig");
+const ScheduleMode = schedule_mod.ScheduleMode;
+const output_rules = @import("loader_fields.zig").output_rules;
+const fieldHint = @import("loader_fields.zig").fieldHint;
+const themeEql = @import("loader_compare.zig").themeEql;
+const OutputConfig = @import("loader.zig").OutputConfig;
+const loadFromBytes = @import("loader.zig").loadFromBytes;
+const parse = @import("loader.zig").parse;
+
+test "output policy parses enabled and unique primary" {
+ var cfg = try parse(std.testing.allocator,
+ \\[[outputs]]
+ \\name = "DP-1"
+ \\primary = true
+ \\enabled = false
+ \\
+ \\[[outputs]]
+ \\name = "DP-2"
+ , "output_policy");
+ defer cfg.deinit();
+ try std.testing.expectEqual(false, cfg.outputs[0].enabled);
+ try std.testing.expectEqual(true, cfg.outputs[0].primary);
+ try std.testing.expectEqual(true, cfg.outputs[1].enabled);
+ try std.testing.expectEqual(false, cfg.outputs[1].primary);
+
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator,
+ \\[[outputs]]
+ \\name = "DP-1"
+ \\primary = true
+ \\
+ \\[[outputs]]
+ \\name = "DP-2"
+ \\primary = true
+ , "ambiguous_primary"));
+}
+
+test "outputs fields parse through the rule table" {
+ const a = std.testing.allocator;
+ var cfg = try parse(a,
+ \\[[outputs]]
+ \\name = "DP-1"
+ \\width = 2560
+ \\height = 1440
+ \\refresh_mhz = 144000
+ \\x = -2560
+ \\y = 0
+ \\scale = 1.33
+ \\transform = "flipped_90"
+ \\night_light = false
+ \\gamma = 1.2
+ \\
+ \\[[outputs]]
+ \\name = "DP-2"
+ \\scale = "auto"
+ , "outputs_fields");
+ defer cfg.deinit();
+ const o = cfg.outputs[0];
+ try std.testing.expectEqualStrings("DP-1", o.name);
+ try std.testing.expectEqual(@as(?i32, 2560), o.width);
+ try std.testing.expectEqual(@as(?i32, 1440), o.height);
+ try std.testing.expectEqual(@as(?i32, 144000), o.refresh_mhz);
+ try std.testing.expectEqual(@as(?i32, -2560), o.x);
+ try std.testing.expectEqual(@as(?i32, 0), o.y);
+ try std.testing.expectEqual(@as(?f32, 160.0 / 120.0), o.scale);
+ try std.testing.expectEqual(output_transform.Transform.flipped_90, o.transform);
+ try std.testing.expectEqual(false, o.night_light);
+ try std.testing.expectApproxEqAbs(@as(f32, 1.2), o.gamma, 0.001);
+ try std.testing.expectEqual(@as(?f32, null), cfg.outputs[1].scale);
+
+ inline for (.{
+ "width = 0", "height = -1", "refresh_mhz = 1.5", "x = 1.5",
+ "scale = 0.9", "scale = 3.1", "scale = \"nan\"", "scale = auto",
+ "transform = 45", "transform = \"45\"", "enabled = 1", "name = DP-1",
+ "unknown_key = 1",
+ }) |line| {
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\n" ++ line ++ "\n", "err"));
+ }
+ try std.testing.expectEqualStrings("a positive integer", fieldHint(OutputConfig, output_rules, "width"));
+ try std.testing.expectEqualStrings("an integer", fieldHint(OutputConfig, output_rules, "x"));
+ try std.testing.expectEqualStrings("a number between 0.5 and 2", fieldHint(OutputConfig, output_rules, "gamma"));
+}
+
+test "night_light sun and always schedules" {
+ var sun_cfg = try parse(std.testing.allocator,
+ \\[night_light]
+ \\enabled = true
+ \\schedule = "sun"
+ \\latitude = 51.51
+ \\longitude = -0.13
+ , "sun");
+ defer sun_cfg.deinit();
+ try std.testing.expectEqual(ScheduleMode.sun, sun_cfg.night_light.schedule);
+ try std.testing.expectApproxEqAbs(@as(f64, 51.51), sun_cfg.night_light.latitude.?, 0.001);
+ try std.testing.expectApproxEqAbs(@as(f64, -0.13), sun_cfg.night_light.longitude.?, 0.001);
+
+ var always_cfg = try parse(std.testing.allocator,
+ \\[night_light]
+ \\enabled = true
+ \\schedule = "always"
+ \\temperature = 2700
+ , "always");
+ defer always_cfg.deinit();
+ try std.testing.expectEqual(ScheduleMode.always, always_cfg.night_light.schedule);
+ try std.testing.expectEqual(@as(u32, 2700), always_cfg.night_light.temperature);
+}
+
+test "night_light validation errors" {
+ const a = std.testing.allocator;
+
+ // Unknown field
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nunknown = 1\n", "err"));
+
+ // Temperature outside 1700-10000
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\ntemperature = 1600\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\ntemperature = 10500\n", "err"));
+
+ // Day temperature outside 1700-10000
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nday_temperature = 1500\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nday_temperature = 11000\n", "err"));
+
+ // Start equals end
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nstart = \"08:00\"\nend = \"08:00\"\n", "err"));
+
+ // Transition minutes > 180
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\ntransition_minutes = 200\n", "err"));
+
+ // Transition minutes not shorter than night or day span (e.g. night span 30m, transition 30m)
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nstart = \"23:00\"\nend = \"23:30\"\ntransition_minutes = 30\n", "err"));
+
+ // Sun schedule missing coordinates
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\nlatitude = 50.0\n", "err"));
+
+ // Sun schedule coordinates out of range
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\nlatitude = 95.0\nlongitude = 0.0\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\nlatitude = 0.0\nlongitude = -190.0\n", "err"));
+
+ // Output gamma outside 0.5-2.0 or not finite
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\nname = \"DP-1\"\ngamma = 0.4\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\nname = \"DP-1\"\ngamma = 2.5\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\nname = \"DP-1\"\ngamma = \"nan\"\n", "err"));
+}
+
+test "animations config defaults and overlay" {
+ var empty = try parse(std.testing.allocator, "", "mem");
+ defer empty.deinit();
+ try std.testing.expect(empty.animations.enabled);
+ try std.testing.expectEqual(@as(f32, 1.0), empty.animations.speed);
+ try std.testing.expectEqual(anim.ReducedMotion.auto, empty.animations.reduced_motion);
+ const panel = empty.animations.targets[@intFromEnum(anim.Target.panel_slide)];
+ try std.testing.expectEqual(anim.springs.panel_slide.stiffness, panel.curve.spring.stiffness);
+
+ var cfg = try parse(std.testing.allocator,
+ \\[animations]
+ \\enabled = true
+ \\speed = 0.5
+ \\reduced_motion = "on"
+ \\
+ \\[animations.panel_slide]
+ \\spring = { damping_ratio = 0.9, stiffness = 400, epsilon = 0.001 }
+ \\
+ \\[animations.taskbar_press]
+ \\duration_ms = 120
+ \\ease = "flip_bezier"
+ \\
+ \\[animations.camera_pan]
+ \\spring = { damping_ratio = 1.0, stiffness = 300 }
+ \\decay_rate = 0.99
+ \\
+ \\[animations.window_open]
+ \\off = true
+ , "anim");
+ defer cfg.deinit();
+ try std.testing.expectEqual(@as(f32, 0.5), cfg.animations.speed);
+ try std.testing.expectEqual(anim.ReducedMotion.on, cfg.animations.reduced_motion);
+ const slide = cfg.animations.targets[@intFromEnum(anim.Target.panel_slide)].curve.spring;
+ try std.testing.expectEqual(@as(f32, 0.9), slide.damping_ratio);
+ try std.testing.expectEqual(@as(f32, 400), slide.stiffness);
+ try std.testing.expectEqual(@as(f32, 0.001), slide.epsilon);
+ const press = cfg.animations.targets[@intFromEnum(anim.Target.taskbar_press)].curve.duration;
+ try std.testing.expectEqual(@as(i64, 120), press.ms);
+ try std.testing.expectEqual(anim.Ease.flip_bezier, press.ease);
+ const pan = cfg.animations.targets[@intFromEnum(anim.Target.camera_pan)];
+ try std.testing.expectEqual(@as(f32, 300), pan.curve.spring.stiffness);
+ try std.testing.expectEqual(@as(f32, 0.5), pan.curve.spring.epsilon);
+ try std.testing.expectEqual(@as(f32, 0.99), pan.decay.rate);
+ try std.testing.expect(cfg.animations.targets[@intFromEnum(anim.Target.window_open)].curve == .off);
+}
+
+test "animations config rejects unknown targets and illegal combinations" {
+ const a = std.testing.allocator;
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.window_opne]\nspring = { stiffness = 800 }\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations]\nspeed = -1\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations]\nreduced_motion = \"maybe\"\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.panel_slide]\nspring = { damping_ratio = 1.0, stiffness = 900 }\nduration_ms = 90\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.panel_slide]\noff = true\nspring = { stiffness = 800 }\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.panel_slide]\nspring = { wobble = 1 }\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.camera_pan]\nspring = { damping_ratio = 1.0, stiffness = 500, epsilon = 0.0001 }\n", "err"));
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[animations]\nunknown = true\n", "err"));
+}
+
+test "documented default still parses with commented animations block" {
+ var cfg = try parse(std.testing.allocator, default_file.source, "default");
+ defer cfg.deinit();
+ try std.testing.expect(cfg.animations.enabled);
+ try std.testing.expectEqual(anim.ReducedMotion.auto, cfg.animations.reduced_motion);
+}
+
+test "polkit defaults and strict configuration validation" {
+ var defaults_cfg = try parse(std.testing.allocator, "", "polkit-defaults");
+ defer defaults_cfg.deinit();
+ try std.testing.expect(defaults_cfg.polkit.enable);
+ try std.testing.expectEqualStrings("/run/polkit/agent-helper.socket", defaults_cfg.polkit.helper_socket);
+ var custom = try parse(std.testing.allocator, "[polkit]\nenable = false\nhelper_socket = \"/tmp/test-helper\"\n", "polkit-custom");
+ defer custom.deinit();
+ try std.testing.expect(!custom.polkit.enable);
+ try std.testing.expectEqualStrings("/tmp/test-helper", custom.polkit.helper_socket);
+ for ([_][]const u8{ "enable = 1", "enabled = true", "helper_socket = \"\"", "helper_socket = \"relative/path\"", "unknown = false" }) |line| {
+ const content = try std.fmt.allocPrint(std.testing.allocator, "[polkit]\n{s}\n", .{line});
+ defer std.testing.allocator.free(content);
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, content, "polkit-invalid"));
+ }
+ const long_path = "[polkit]\nhelper_socket = \"/" ++ ("a" ** 107) ++ "\"\n";
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, long_path, "polkit-overlong"));
+}
+
+test "canvas screen counts default to three and reject values outside one to ten" {
+ const a = std.testing.allocator;
+ var defaults = try parse(a, "", "mem");
+ defer defaults.deinit();
+ try std.testing.expectEqual(@as(u32, 3), defaults.compositor.canvas_columns);
+ try std.testing.expectEqual(@as(u32, 3), defaults.compositor.canvas_rows);
+ var rectangular = try parse(a, "[compositor]\ncanvas_columns = 10\ncanvas_rows = 1\n", "mem");
+ defer rectangular.deinit();
+ try std.testing.expectEqual(@as(u32, 10), rectangular.compositor.canvas_columns);
+ try std.testing.expectEqual(@as(u32, 1), rectangular.compositor.canvas_rows);
+ inline for (.{ "canvas_columns", "canvas_rows" }) |key| {
+ inline for (.{ "0", "11", "-1", "1.5" }) |value| {
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[compositor]\n" ++ key ++ " = " ++ value ++ "\n", "err"));
+ }
+ }
+}
+
+test "desktop switch duration sets the camera_desktop curve unless animations override it" {
+ const a = std.testing.allocator;
+ const idx = @intFromEnum(anim.Target.camera_desktop);
+ var defaults = try parse(a, "", "mem");
+ defer defaults.deinit();
+ try std.testing.expectEqual(anim.desktopSwitchCurve(anim.default_desktop_switch_ms), defaults.animations.targets[idx].curve);
+ var slow = try parse(a, "[compositor]\ndesktop_switch_ms = 1500\n", "mem");
+ defer slow.deinit();
+ try std.testing.expectEqual(anim.desktopSwitchCurve(1500), slow.animations.targets[idx].curve);
+ var explicit = try parse(a, "[compositor]\ndesktop_switch_ms = 1500\n[animations.camera_desktop]\nduration_ms = 300\n", "mem");
+ defer explicit.deinit();
+ try std.testing.expectEqual(@as(i64, 300), explicit.animations.targets[idx].curve.duration.ms);
+ inline for (.{ "99", "3001" }) |value| {
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[compositor]\ndesktop_switch_ms = " ++ value ++ "\n", "err"));
+ }
+}
+
+test "input method environment validates supported names" {
+ for ([_][]const u8{ "none", "fcitx", "ibus" }) |name| {
+ const source = try std.fmt.allocPrint(std.testing.allocator, "[input_method]\nenv = \"{s}\"\n", .{name});
+ defer std.testing.allocator.free(source);
+ var cfg = try parse(std.testing.allocator, source, "ime-env");
+ defer cfg.deinit();
+ try std.testing.expectEqualStrings(name, @tagName(cfg.input_method.env));
+ }
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, "[input_method]\nenv = \"unknown\"", "bad-ime-env"));
+}
+
+test "sandbox_allow TOML parsing and resolution" {
+ const toml =
+ \\[[sandbox_allow]]
+ \\app_id = "com.obsproject.Studio"
+ \\engine = "org.flatpak"
+ \\allow = ["capture", "windows"]
+ \\
+ \\[[sandbox_allow]]
+ \\app_id = "org.example.App"
+ \\allow = ["clipboard", "unknown_group"]
+ ;
+ var cfg = try parse(std.testing.allocator, toml, "sandbox-test");
+ defer cfg.deinit();
+
+ try std.testing.expectEqual(@as(usize, 2), cfg.sandbox_allow.len);
+
+ const obs = cfg.sandboxAllowGroups("com.obsproject.Studio", "org.flatpak");
+ try std.testing.expect(obs.contains(.capture));
+ try std.testing.expect(obs.contains(.windows));
+ try std.testing.expect(!obs.contains(.clipboard));
+
+ const obs_wrong_engine = cfg.sandboxAllowGroups("com.obsproject.Studio", "other.engine");
+ try std.testing.expect(obs_wrong_engine.count() == 0);
+
+ const app = cfg.sandboxAllowGroups("org.example.App", "any.engine");
+ try std.testing.expect(app.contains(.clipboard));
+ try std.testing.expect(!app.contains(.capture));
+
+ try std.testing.expect(cfg.sandboxAllowGroups(null, null).count() == 0);
+
+ const bad_toml =
+ \\[[sandbox_allow]]
+ \\allow = ["clipboard"]
+ ;
+ try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, bad_toml, "bad-sandbox"));
+}
+
+test "mini map defaults and validated configuration" {
+ const a = std.testing.allocator;
+ var defaults = try parse(a, "", "mem");
+ defer defaults.deinit();
+ try std.testing.expect(defaults.compositor.mini_map_enabled);
+ try std.testing.expectEqual(.bottom_right, defaults.compositor.mini_map_position);
+ try std.testing.expectEqual(@as(u32, 1500), defaults.compositor.mini_map_hide_ms);
+ var custom = try parse(a, "[compositor]\nmini_map_enabled = false\nmini_map_position = \"bottom_center\"\nmini_map_hide_ms = 2000\n", "mem");
+ defer custom.deinit();
+ try std.testing.expect(!custom.compositor.mini_map_enabled);
+ try std.testing.expectEqual(.bottom_center, custom.compositor.mini_map_position);
+ try std.testing.expectEqual(@as(u32, 2000), custom.compositor.mini_map_hide_ms);
+ inline for (.{ "mini_map_position = \"top\"", "mini_map_hide_ms = 0", "mini_map_hide_ms = 10001", "mini_map_enabled = 1" }) |line| {
+ try std.testing.expectError(error.InvalidConfig, parse(a, "[compositor]\n" ++ line ++ "\n", "invalid"));
+ }
+}
+
+test "workspace preset is independent, overrides include noop, and mode preserves canvas bindings" {
+ var cfg = try parse(std.testing.allocator, "[keybinds]\n\"Super+q\" = \"spawn custom-canvas\"\n" ++
+ "[keybinds.workspace]\n\"Super+c\" = \"noop\"\n\"Super+F12\" = \"workspace 8\"\n", "test");
+ defer cfg.deinit();
+ const q = try keybinds.parseKeybind("Super+q");
+ const c = try keybinds.parseKeybind("Super+c");
+ const two = try keybinds.parseKeybind("Super+2");
+ try std.testing.expectEqualStrings("custom-canvas", cfg.lookupKeybind(q.modifiers, q.sym).?.spawn);
+ cfg.compositor.desktop_mode = .workspaces;
+ const monitor = try keybinds.parseKeybind("Ctrl+Alt+Delete");
+ try std.testing.expectEqual(Action.open_system_monitor, cfg.lookupKeybind(monitor.modifiers, monitor.sym).?);
+ try std.testing.expectEqualStrings("default-terminal", cfg.lookupKeybind(q.modifiers, q.sym).?.spawn);
+ try std.testing.expectEqual(Action.noop, cfg.lookupKeybind(c.modifiers, c.sym).?);
+ try std.testing.expectEqual(@as(u8, 2), cfg.lookupKeybind(two.modifiers, two.sym).?.workspace);
+ const v = try keybinds.parseKeybind("Super+v");
+ const rotate = try keybinds.parseKeybind("Super+j");
+ const swap = try keybinds.parseKeybind("Super+Shift+Right");
+ const split = try keybinds.parseKeybind("Super+Ctrl+Right");
+ try std.testing.expectEqual(Action.toggle_floating, cfg.lookupKeybind(v.modifiers, v.sym).?);
+ try std.testing.expectEqual(Action.toggle_split, cfg.lookupKeybind(rotate.modifiers, rotate.sym).?);
+ try std.testing.expectEqual(Action.swap_right, cfg.lookupKeybind(swap.modifiers, swap.sym).?);
+ try std.testing.expectEqual(Action.resize_split_right, cfg.lookupKeybind(split.modifiers, split.sym).?);
+ cfg.compositor.desktop_mode = .canvas;
+ try std.testing.expectEqual(@as(?Action, null), cfg.lookupKeybind(v.modifiers, v.sym));
+ try std.testing.expectEqualStrings("custom-canvas", cfg.lookupKeybind(q.modifiers, q.sym).?.spawn);
+ try std.testing.expectEqual(@as(?Action, null), cfg.lookupKeybind(two.modifiers, two.sym));
+}
+
+test "no base preserves legacy themes and embedded base layers config overrides" {
+ const a = std.testing.allocator;
+ const bytes = "[theme]\naccent = \"#123456\"\nfont_size = 14\n";
+ var old = try parse(a, bytes, "legacy");
+ defer old.deinit();
+ var loaded = try loadFromBytes(a, bytes, "legacy", .empty, std.testing.io);
+ defer loaded.deinit();
+ try std.testing.expect(themeEql(old.theme, loaded.theme));
+ var based = try loadFromBytes(a, "[theme]\nbase = \"rediwm-light\"\nfont_size = 14\n", "based", .empty, std.testing.io);
+ defer based.deinit();
+ try std.testing.expectEqualStrings("rediwm-light", based.theme_base);
+ try std.testing.expectEqual(@as(f32, 14), based.theme.font_size);
+ try std.testing.expect(themeEql(based.theme_defaults, based.theme_pack.?.tokens));
+ try std.testing.expectEqual(based.theme_defaults.accent, based.theme.accent);
+
+ var gold = try loadFromBytes(a, "[theme]\nbase = \"gold\"\n", "gold", .empty, std.testing.io);
+ defer gold.deinit();
+ try std.testing.expectEqual(.top, gold.compositor.taskbar_position);
+ try std.testing.expect(gold.compositor.dock_enabled);
+ try std.testing.expectEqual(@as(u32, 76), gold.compositor.dock_height);
+ var customized = try loadFromBytes(a, "[theme]\nbase = \"gold\"\n[compositor]\ntaskbar_position = \"bottom\"\ndock_enabled = false\ndock_height = 52\n", "gold", .empty, std.testing.io);
+ defer customized.deinit();
+ try std.testing.expectEqual(.bottom, customized.compositor.taskbar_position);
+ try std.testing.expect(!customized.compositor.dock_enabled);
+ try std.testing.expectEqual(@as(u32, 52), customized.compositor.dock_height);
+}
+
+test "external overlay wins over a referenced pack without pinning inherited tokens" {
+ const a = std.testing.allocator;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var arena = std.heap.ArenaAllocator.init(a);
+ defer arena.deinit();
+ const mem = arena.allocator();
+ const root = try tmp.dir.realPathFileAlloc(io, ".", mem);
+ const path = try std.fs.path.join(mem, &.{ root, "overlay.toml" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "overlay.toml", .data = "[theme]\nfont_size = 16\n" });
+ const entry = try std.fmt.allocPrintSentinel(mem, "REDIWM_THEME={s}", .{path}, 0);
+ const entries = [_:null]?[*:0]const u8{entry.ptr};
+ const env: std.process.Environ = .{ .block = .{ .slice = &entries } };
+ var cfg = try loadFromBytes(a, "[theme]\nbase = \"rediwm-light\"\nfont_size = 14\n", "test", env, io);
+ defer cfg.deinit();
+ try std.testing.expectEqual(@as(f32, 16), cfg.theme.font_size);
+ try std.testing.expectEqual(@as(f32, 14), cfg.theme_config.font_size);
+ var edited = cfg.theme;
+ edited.font_size = 17;
+ try theme_mod.saveOverlay(a, io, path, edited, cfg.theme_config);
+ const saved = try tmp.dir.readFileAlloc(io, "overlay.toml", a, .limited(4096));
+ defer a.free(saved);
+ try std.testing.expectEqualStrings("[theme]\nfont_size = 17\n", saved);
+}
diff --git a/src/config/loader_tests.zig b/src/config/loader_tests.zig
index 823e46d..aede052 100644
--- a/src/config/loader_tests.zig
+++ b/src/config/loader_tests.zig
@@ -293,708 +293,10 @@ test "input and theme reload detect every field and compare strings by content"
try std.testing.expect(inputEql(original, copy));
}
-test "config field parsing preserves ranges and derived zoom state" {
- var input = InputConfig{};
- const a = std.testing.allocator;
- inline for (.{
- .{ "key_repeat_delay", "1", "5000", "0", "5001" },
- .{ "key_repeat_rate", "1", "200", "0", "201" },
- .{ "cursor_size", "1", "256", "0", "257" },
- }) |fixture| {
- try applyInputKey(&input, a, fixture[0], fixture[1]);
- try std.testing.expectEqual(try std.fmt.parseInt(u32, fixture[1], 10), @field(input, fixture[0]));
- try applyInputKey(&input, a, fixture[0], fixture[2]);
- try std.testing.expectEqual(try std.fmt.parseInt(u32, fixture[2], 10), @field(input, fixture[0]));
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, fixture[0], fixture[3]));
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, fixture[0], fixture[4]));
- }
- try applyInputKey(&input, a, "pointer_speed", "-1");
- try std.testing.expectEqual(@as(f32, -1), input.pointer_speed);
- try applyInputKey(&input, a, "pointer_speed", "1");
- try std.testing.expectEqual(@as(f32, 1), input.pointer_speed);
- try applyInputKey(&input, a, "pointer_speed_touchpad", "-1");
- try std.testing.expectEqual(@as(f32, -1), input.pointer_speed_touchpad);
- try applyInputKey(&input, a, "pointer_speed_touchpad", "1");
- try std.testing.expectEqual(@as(f32, 1), input.pointer_speed_touchpad);
- try applyInputKey(&input, a, "disable_while_typing_touchpad", "true");
- try std.testing.expect(input.disable_while_typing_touchpad);
- try applyInputKey(&input, a, "disable_while_typing_touchpad", "false");
- try std.testing.expect(!input.disable_while_typing_touchpad);
- inline for (.{ "-1.01", "1.01", "nan", "inf" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "pointer_speed", v));
- }
- inline for (.{ "-1.01", "1.01", "nan", "inf" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "pointer_speed_touchpad", v));
- }
- inline for (.{ "natural_scroll", "invert_scroll", "tap_to_click", "tap_drag", "disable_while_typing" }) |key| {
- try applyInputKey(&input, a, key, "false");
- try std.testing.expect(!@field(input, key));
- try applyInputKey(&input, a, key, "true");
- try std.testing.expect(@field(input, key));
- }
- try applyInputKey(&input, a, "cursor_theme", "\"custom\"");
- defer a.free(input.cursor_theme);
- try std.testing.expectEqualStrings("custom", input.cursor_theme);
-
- try applyInputKey(&input, a, "accel_profile", "\"flat\"");
- try std.testing.expectEqual(AccelProfile.flat, input.accel_profile);
- try applyInputKey(&input, a, "accel_profile", "bezier");
- try std.testing.expectEqual(AccelProfile.bezier, input.accel_profile);
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_profile", "\"nope\""));
-
- try applyInputKey(&input, a, "accel_p1", "[0.0, 0.0]");
- try std.testing.expectEqual([2]f32{ 0.0, 0.0 }, input.accel_p1);
- try applyInputKey(&input, a, "accel_p2", "[ 0.15 , 1.0 ]");
- try std.testing.expectEqual([2]f32{ 0.15, 1.0 }, input.accel_p2);
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[-0.1, 0.0]"));
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[1.1, 0.0]"));
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[0.0]"));
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "[0.0, 0.0, 0.0]"));
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_p1", "bad"));
-
- try applyInputKey(&input, a, "accel_max_speed", "10.0");
- try std.testing.expectEqual(@as(f32, 10.0), input.accel_max_speed);
- try applyInputKey(&input, a, "accel_max_speed", "25.5");
- try std.testing.expectEqual(@as(f32, 25.5), input.accel_max_speed);
- inline for (.{ "0", "-1", "nan", "inf" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyInputKey(&input, a, "accel_max_speed", v));
- }
-
- var c = CompositorConfig{};
- try std.testing.expectEqual(types.DockPosition.bottom, c.dock_position);
- inline for (.{ "top", "bottom", "left", "right" }) |value| {
- try applyCompositorKey(&c, a, "dock_position", value);
- try std.testing.expectEqual(std.meta.stringToEnum(types.DockPosition, value).?, c.dock_position);
- }
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "dock_position", "center"));
- try std.testing.expectEqual(@as(u32, 0), c.windowGap());
- c.desktop_mode = .workspaces;
- try std.testing.expectEqual(@as(u32, 8), c.windowGap());
- try applyCompositorKey(&c, a, "window_gap", "0");
- try std.testing.expectEqual(@as(u32, 0), c.windowGap());
- c.desktop_mode = .canvas;
- inline for (.{
- .{ "canvas_width", "1", "100000", "0", "100001" },
- .{ "canvas_height", "1", "100000", "0", "100001" },
- .{ "window_gap", "0", "512", "513", "514" },
- .{ "border_radius", "0", "128", "129", "130" },
- .{ "dock_height", "48", "96", "47", "97" },
- }) |fixture| {
- try applyCompositorKey(&c, a, fixture[0], fixture[1]);
- try std.testing.expectEqual(@as(@TypeOf(@field(c, fixture[0])), try std.fmt.parseInt(u32, fixture[1], 10)), @field(c, fixture[0]));
- try applyCompositorKey(&c, a, fixture[0], fixture[2]);
- try std.testing.expectEqual(@as(@TypeOf(@field(c, fixture[0])), try std.fmt.parseInt(u32, fixture[2], 10)), @field(c, fixture[0]));
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, fixture[0], fixture[3]));
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, fixture[0], fixture[4]));
- }
- inline for (.{ "1", "1.05", "1.5" }) |value| {
- try applyCompositorKey(&c, a, "dock_hover_zoom", value);
- try std.testing.expectEqual(try std.fmt.parseFloat(f32, value), c.dock_hover_zoom);
- }
- inline for (.{ "nan", "inf", "0.99", "1.51" }) |value| {
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "dock_hover_zoom", value));
- }
- inline for (.{ "camera_zoom_min", "camera_zoom_max", "inactive_opacity" }) |key| {
- try applyCompositorKey(&c, a, key, "0.5");
- try std.testing.expectEqual(@as(f32, 0.5), @field(c, key));
- inline for (.{ "nan", "inf", "-0.1", "8.1" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, key, v));
- }
- }
- inline for (.{ "camera_zoom_min", "camera_zoom_max" }) |key| {
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, key, "0"));
- try applyCompositorKey(&c, a, key, "8");
- try std.testing.expectEqual(@as(f32, 8), @field(c, key));
- }
- try applyCompositorKey(&c, a, "inactive_opacity", "0");
- try std.testing.expectEqual(@as(f32, 0), c.inactive_opacity);
- try applyCompositorKey(&c, a, "inactive_opacity", "1");
- try std.testing.expectEqual(@as(f32, 1), c.inactive_opacity);
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "inactive_opacity", "1.01"));
- try std.testing.expectEqual(@as(?f32, null), c.terminal_opacity);
- try applyCompositorKey(&c, a, "terminal_opacity", "0.85");
- try std.testing.expectEqual(@as(?f32, 0.85), c.terminal_opacity);
- inline for (.{ "nan", "-0.1", "1.01" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "terminal_opacity", v));
- }
- try std.testing.expectEqual(@as(?f32, null), c.dock_opacity);
- try std.testing.expect(!c.dock_active_highlight);
- try applyCompositorKey(&c, a, "dock_opacity", "0.6");
- try std.testing.expectEqual(@as(?f32, 0.6), c.dock_opacity);
- inline for (.{ "nan", "-0.1", "1.01" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "dock_opacity", v));
- }
- try applyCompositorKey(&c, a, "dock_active_highlight", "true");
- try std.testing.expect(c.dock_active_highlight);
- try std.testing.expect(c.inactive_dim);
- try std.testing.expectEqual(@as(f32, 0.08), c.inactive_dim_amount);
- try applyCompositorKey(&c, a, "inactive_dim", "false");
- try std.testing.expect(!c.inactive_dim);
- try applyCompositorKey(&c, a, "inactive_dim_amount", "0.5");
- try std.testing.expectEqual(@as(f32, 0.5), c.inactive_dim_amount);
- inline for (.{ "nan", "inf", "-0.1", "0.51" }) |v| {
- try std.testing.expectError(error.InvalidValue, applyCompositorKey(&c, a, "inactive_dim_amount", v));
- }
- try applyCompositorKey(&c, a, "focus_follows_mouse", "true");
- try std.testing.expect(c.focus_follows_mouse);
- try applyCompositorKey(&c, a, "xwayland", "false");
- try std.testing.expect(!c.xwayland);
- try applyCompositorKey(&c, a, "zoom_steps", "[1, 0.75]");
- try std.testing.expectEqual(@as(u8, 2), c.zoom_step_count);
- try std.testing.expectEqualSlices(f32, &.{ 1, 0.75 }, c.zoom_steps[0..2]);
- try applyCompositorKey(&c, a, "zoom_step_count", "7");
- try applyCompositorKey(&c, a, "zoom_percents", "[20]");
- try std.testing.expectEqual(@as(u8, 2), c.zoom_step_count);
- try std.testing.expectEqualSlices(u8, &default_zoom_percents, c.zoom_percents);
- try applyInputKey(&input, a, "unknown", "ignored");
- try applyCompositorKey(&c, a, "unknown", "ignored");
-}
-
-test "idle field rules preserve optional enabled and strict unknown keys" {
- const a = std.testing.allocator;
- var idle = IdleConfig{};
- try std.testing.expectEqual(@as(?bool, null), idle.enabled);
- try applyIdleKey(&idle, a, "enabled", "false");
- try std.testing.expectEqual(@as(?bool, false), idle.enabled);
- try applyIdleKey(&idle, a, "enabled", "true");
- try std.testing.expectEqual(@as(?bool, true), idle.enabled);
- try std.testing.expectError(error.InvalidValue, applyIdleKey(&idle, a, "enabled", "null"));
- inline for (.{ "blank_after_seconds", "suspend_after_seconds" }) |key| {
- try applyIdleKey(&idle, a, key, "0");
- try std.testing.expectEqual(@as(u32, 0), @field(idle, key));
- try applyIdleKey(&idle, a, key, "4294967295");
- try std.testing.expectEqual(std.math.maxInt(u32), @field(idle, key));
- try std.testing.expectError(error.Overflow, applyIdleKey(&idle, a, key, "4294967296"));
- }
- try std.testing.expectError(error.InvalidField, applyIdleKey(&idle, a, "unknown", "ignored"));
+test {
+ _ = @import("loader_fields_tests.zig");
}
-test "window_rules TOML parsing and validation" {
- const toml =
- \\[[window_rules]]
- \\app_id = "org.telegram.desktop"
- \\exclude_title = "Media viewer"
- \\output = "DP-2"
- \\center = true
- \\width = 900
- \\height = 700
- \\
- \\[[window_rules]]
- \\app_id = ["firefox", "chromium"]
- \\title = "Picture-in-Picture"
- \\opacity = 0.9
- \\skip_taskbar = true
- \\focus = false
- \\
- \\[[window_rules]]
- \\x11_class = "Steam"
- \\dialog = false
- \\maximized = true
- \\
- \\[[window_rules]]
- \\app_id = "foot"
- \\decorations = "client"
- ;
-
- var cfg = try parse(std.testing.allocator, toml, "rules_test");
- defer cfg.deinit();
-
- try std.testing.expectEqual(@as(usize, 4), cfg.window_rules.len);
-
- const r0 = cfg.window_rules[0];
- try std.testing.expectEqualStrings("org.telegram.desktop", r0.app_id.?[0]);
- try std.testing.expectEqualStrings("Media viewer", r0.exclude_title.?[0]);
- try std.testing.expectEqualStrings("DP-2", r0.output.?);
- try std.testing.expectEqual(@as(?bool, true), r0.center);
- try std.testing.expectEqual(@as(?u32, 900), r0.width);
- try std.testing.expectEqual(@as(?u32, 700), r0.height);
-
- const r1 = cfg.window_rules[1];
- try std.testing.expectEqual(@as(usize, 2), r1.app_id.?.len);
- try std.testing.expectEqualStrings("firefox", r1.app_id.?[0]);
- try std.testing.expectEqualStrings("chromium", r1.app_id.?[1]);
- try std.testing.expectEqualStrings("Picture-in-Picture", r1.title.?[0]);
- try std.testing.expectEqual(@as(?f32, 0.9), r1.opacity);
- try std.testing.expectEqual(@as(?bool, true), r1.skip_taskbar);
- try std.testing.expectEqual(@as(?bool, false), r1.focus);
-
- const r2 = cfg.window_rules[2];
- try std.testing.expectEqualStrings("Steam", r2.x11_class.?[0]);
- try std.testing.expectEqual(@as(?bool, false), r2.dialog);
- try std.testing.expectEqual(@as(?bool, true), r2.maximized);
-
- const r3 = cfg.window_rules[3];
- try std.testing.expectEqualStrings("foot", r3.app_id.?[0]);
- try std.testing.expectEqual(window_rules.DecorationMode.client, r3.decorations.?);
-
- // Conflict error in TOML
- const bad_toml =
- \\[[window_rules]]
- \\center = true
- \\x = 100
- ;
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, bad_toml, "bad_rule"));
-
- // Unknown field error
- const bad_key =
- \\[[window_rules]]
- \\unknown_field = "value"
- ;
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, bad_key, "bad_key"));
-}
-
-test "existing configs inherit laptop controls and can override or disable them" {
- var cfg = try parse(std.testing.allocator,
- \\[keybinds]
- \\"super+t" = "spawn foot"
- \\"XF86AudioMute" = "noop"
- , "hardware");
- defer cfg.deinit();
- const up = try keybinds.parseKeybind("XF86AudioRaiseVolume");
- try std.testing.expectEqual(Action.volume_up, cfg.lookupKeybind(up.modifiers, up.sym).?);
- const mute = try keybinds.parseKeybind("XF86AudioMute");
- try std.testing.expectEqual(Action.noop, cfg.lookupKeybind(mute.modifiers, mute.sym).?);
-}
-
-test "night_light config parsing and defaults" {
- var def = try default(std.testing.allocator);
- defer def.deinit();
-
- try std.testing.expectEqual(true, def.night_light.enabled);
- try std.testing.expectEqual(ScheduleMode.always, def.night_light.schedule);
- try std.testing.expectEqual(@as(u32, 5000), def.night_light.temperature);
- try std.testing.expectEqual(@as(u32, 6500), def.night_light.day_temperature);
- try std.testing.expectEqual(@as(u16, 21 * 60), def.night_light.start);
- try std.testing.expectEqual(@as(u16, 7 * 60), def.night_light.end);
- try std.testing.expectEqual(@as(u16, 30), def.night_light.transition_minutes);
- try std.testing.expectEqual(@as(?f64, null), def.night_light.latitude);
- try std.testing.expectEqual(@as(?f64, null), def.night_light.longitude);
-
- // Snapshot survives deinit (holds only scalars)
- var snapshot: NightLightConfig = undefined;
- {
- var custom = try parse(std.testing.allocator,
- \\[night_light]
- \\enabled = true
- \\schedule = "fixed"
- \\temperature = 3400
- \\day_temperature = 6000
- \\start = "22:00"
- \\end = "06:30"
- \\transition_minutes = 45
- \\
- \\[[outputs]]
- \\name = "DP-2"
- \\night_light = false
- \\gamma = 1.2
- , "custom");
- snapshot = custom.night_light;
- try std.testing.expectEqual(true, custom.outputs[0].night_light == false);
- try std.testing.expectApproxEqAbs(@as(f32, 1.2), custom.outputs[0].gamma, 0.001);
- custom.deinit();
- }
- try std.testing.expectEqual(true, snapshot.enabled);
- try std.testing.expectEqual(ScheduleMode.fixed, snapshot.schedule);
- try std.testing.expectEqual(@as(u32, 3400), snapshot.temperature);
- try std.testing.expectEqual(@as(u32, 6000), snapshot.day_temperature);
- try std.testing.expectEqual(@as(u16, 22 * 60), snapshot.start);
- try std.testing.expectEqual(@as(u16, 6 * 60 + 30), snapshot.end);
- try std.testing.expectEqual(@as(u16, 45), snapshot.transition_minutes);
-}
-
-test "output policy parses enabled and unique primary" {
- var cfg = try parse(std.testing.allocator,
- \\[[outputs]]
- \\name = "DP-1"
- \\primary = true
- \\enabled = false
- \\
- \\[[outputs]]
- \\name = "DP-2"
- , "output_policy");
- defer cfg.deinit();
- try std.testing.expectEqual(false, cfg.outputs[0].enabled);
- try std.testing.expectEqual(true, cfg.outputs[0].primary);
- try std.testing.expectEqual(true, cfg.outputs[1].enabled);
- try std.testing.expectEqual(false, cfg.outputs[1].primary);
-
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator,
- \\[[outputs]]
- \\name = "DP-1"
- \\primary = true
- \\
- \\[[outputs]]
- \\name = "DP-2"
- \\primary = true
- , "ambiguous_primary"));
-}
-
-test "outputs fields parse through the rule table" {
- const a = std.testing.allocator;
- var cfg = try parse(a,
- \\[[outputs]]
- \\name = "DP-1"
- \\width = 2560
- \\height = 1440
- \\refresh_mhz = 144000
- \\x = -2560
- \\y = 0
- \\scale = 1.33
- \\transform = "flipped_90"
- \\night_light = false
- \\gamma = 1.2
- \\
- \\[[outputs]]
- \\name = "DP-2"
- \\scale = "auto"
- , "outputs_fields");
- defer cfg.deinit();
- const o = cfg.outputs[0];
- try std.testing.expectEqualStrings("DP-1", o.name);
- try std.testing.expectEqual(@as(?i32, 2560), o.width);
- try std.testing.expectEqual(@as(?i32, 1440), o.height);
- try std.testing.expectEqual(@as(?i32, 144000), o.refresh_mhz);
- try std.testing.expectEqual(@as(?i32, -2560), o.x);
- try std.testing.expectEqual(@as(?i32, 0), o.y);
- try std.testing.expectEqual(@as(?f32, 160.0 / 120.0), o.scale);
- try std.testing.expectEqual(output_transform.Transform.flipped_90, o.transform);
- try std.testing.expectEqual(false, o.night_light);
- try std.testing.expectApproxEqAbs(@as(f32, 1.2), o.gamma, 0.001);
- try std.testing.expectEqual(@as(?f32, null), cfg.outputs[1].scale);
-
- inline for (.{
- "width = 0", "height = -1", "refresh_mhz = 1.5", "x = 1.5",
- "scale = 0.9", "scale = 3.1", "scale = \"nan\"", "scale = auto",
- "transform = 45", "transform = \"45\"", "enabled = 1", "name = DP-1",
- "unknown_key = 1",
- }) |line| {
- try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\n" ++ line ++ "\n", "err"));
- }
- try std.testing.expectEqualStrings("a positive integer", fieldHint(OutputConfig, output_rules, "width"));
- try std.testing.expectEqualStrings("an integer", fieldHint(OutputConfig, output_rules, "x"));
- try std.testing.expectEqualStrings("a number between 0.5 and 2", fieldHint(OutputConfig, output_rules, "gamma"));
-}
-
-test "night_light sun and always schedules" {
- var sun_cfg = try parse(std.testing.allocator,
- \\[night_light]
- \\enabled = true
- \\schedule = "sun"
- \\latitude = 51.51
- \\longitude = -0.13
- , "sun");
- defer sun_cfg.deinit();
- try std.testing.expectEqual(ScheduleMode.sun, sun_cfg.night_light.schedule);
- try std.testing.expectApproxEqAbs(@as(f64, 51.51), sun_cfg.night_light.latitude.?, 0.001);
- try std.testing.expectApproxEqAbs(@as(f64, -0.13), sun_cfg.night_light.longitude.?, 0.001);
-
- var always_cfg = try parse(std.testing.allocator,
- \\[night_light]
- \\enabled = true
- \\schedule = "always"
- \\temperature = 2700
- , "always");
- defer always_cfg.deinit();
- try std.testing.expectEqual(ScheduleMode.always, always_cfg.night_light.schedule);
- try std.testing.expectEqual(@as(u32, 2700), always_cfg.night_light.temperature);
-}
-
-test "night_light validation errors" {
- const a = std.testing.allocator;
-
- // Unknown field
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nunknown = 1\n", "err"));
-
- // Temperature outside 1700-10000
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\ntemperature = 1600\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\ntemperature = 10500\n", "err"));
-
- // Day temperature outside 1700-10000
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nday_temperature = 1500\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nday_temperature = 11000\n", "err"));
-
- // Start equals end
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nstart = \"08:00\"\nend = \"08:00\"\n", "err"));
-
- // Transition minutes > 180
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\ntransition_minutes = 200\n", "err"));
-
- // Transition minutes not shorter than night or day span (e.g. night span 30m, transition 30m)
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nstart = \"23:00\"\nend = \"23:30\"\ntransition_minutes = 30\n", "err"));
-
- // Sun schedule missing coordinates
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\nlatitude = 50.0\n", "err"));
-
- // Sun schedule coordinates out of range
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\nlatitude = 95.0\nlongitude = 0.0\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[night_light]\nschedule = \"sun\"\nlatitude = 0.0\nlongitude = -190.0\n", "err"));
-
- // Output gamma outside 0.5-2.0 or not finite
- try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\nname = \"DP-1\"\ngamma = 0.4\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\nname = \"DP-1\"\ngamma = 2.5\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[[outputs]]\nname = \"DP-1\"\ngamma = \"nan\"\n", "err"));
-}
-
-test "animations config defaults and overlay" {
- var empty = try parse(std.testing.allocator, "", "mem");
- defer empty.deinit();
- try std.testing.expect(empty.animations.enabled);
- try std.testing.expectEqual(@as(f32, 1.0), empty.animations.speed);
- try std.testing.expectEqual(anim.ReducedMotion.auto, empty.animations.reduced_motion);
- const panel = empty.animations.targets[@intFromEnum(anim.Target.panel_slide)];
- try std.testing.expectEqual(anim.springs.panel_slide.stiffness, panel.curve.spring.stiffness);
-
- var cfg = try parse(std.testing.allocator,
- \\[animations]
- \\enabled = true
- \\speed = 0.5
- \\reduced_motion = "on"
- \\
- \\[animations.panel_slide]
- \\spring = { damping_ratio = 0.9, stiffness = 400, epsilon = 0.001 }
- \\
- \\[animations.taskbar_press]
- \\duration_ms = 120
- \\ease = "flip_bezier"
- \\
- \\[animations.camera_pan]
- \\spring = { damping_ratio = 1.0, stiffness = 300 }
- \\decay_rate = 0.99
- \\
- \\[animations.window_open]
- \\off = true
- , "anim");
- defer cfg.deinit();
- try std.testing.expectEqual(@as(f32, 0.5), cfg.animations.speed);
- try std.testing.expectEqual(anim.ReducedMotion.on, cfg.animations.reduced_motion);
- const slide = cfg.animations.targets[@intFromEnum(anim.Target.panel_slide)].curve.spring;
- try std.testing.expectEqual(@as(f32, 0.9), slide.damping_ratio);
- try std.testing.expectEqual(@as(f32, 400), slide.stiffness);
- try std.testing.expectEqual(@as(f32, 0.001), slide.epsilon);
- const press = cfg.animations.targets[@intFromEnum(anim.Target.taskbar_press)].curve.duration;
- try std.testing.expectEqual(@as(i64, 120), press.ms);
- try std.testing.expectEqual(anim.Ease.flip_bezier, press.ease);
- const pan = cfg.animations.targets[@intFromEnum(anim.Target.camera_pan)];
- try std.testing.expectEqual(@as(f32, 300), pan.curve.spring.stiffness);
- try std.testing.expectEqual(@as(f32, 0.5), pan.curve.spring.epsilon);
- try std.testing.expectEqual(@as(f32, 0.99), pan.decay.rate);
- try std.testing.expect(cfg.animations.targets[@intFromEnum(anim.Target.window_open)].curve == .off);
-}
-
-test "animations config rejects unknown targets and illegal combinations" {
- const a = std.testing.allocator;
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.window_opne]\nspring = { stiffness = 800 }\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations]\nspeed = -1\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations]\nreduced_motion = \"maybe\"\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.panel_slide]\nspring = { damping_ratio = 1.0, stiffness = 900 }\nduration_ms = 90\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.panel_slide]\noff = true\nspring = { stiffness = 800 }\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.panel_slide]\nspring = { wobble = 1 }\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations.camera_pan]\nspring = { damping_ratio = 1.0, stiffness = 500, epsilon = 0.0001 }\n", "err"));
- try std.testing.expectError(error.InvalidConfig, parse(a, "[animations]\nunknown = true\n", "err"));
-}
-
-test "documented default still parses with commented animations block" {
- var cfg = try parse(std.testing.allocator, default_file.source, "default");
- defer cfg.deinit();
- try std.testing.expect(cfg.animations.enabled);
- try std.testing.expectEqual(anim.ReducedMotion.auto, cfg.animations.reduced_motion);
-}
-
-test "polkit defaults and strict configuration validation" {
- var defaults_cfg = try parse(std.testing.allocator, "", "polkit-defaults");
- defer defaults_cfg.deinit();
- try std.testing.expect(defaults_cfg.polkit.enable);
- try std.testing.expectEqualStrings("/run/polkit/agent-helper.socket", defaults_cfg.polkit.helper_socket);
- var custom = try parse(std.testing.allocator, "[polkit]\nenable = false\nhelper_socket = \"/tmp/test-helper\"\n", "polkit-custom");
- defer custom.deinit();
- try std.testing.expect(!custom.polkit.enable);
- try std.testing.expectEqualStrings("/tmp/test-helper", custom.polkit.helper_socket);
- for ([_][]const u8{ "enable = 1", "enabled = true", "helper_socket = \"\"", "helper_socket = \"relative/path\"", "unknown = false" }) |line| {
- const content = try std.fmt.allocPrint(std.testing.allocator, "[polkit]\n{s}\n", .{line});
- defer std.testing.allocator.free(content);
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, content, "polkit-invalid"));
- }
- const long_path = "[polkit]\nhelper_socket = \"/" ++ ("a" ** 107) ++ "\"\n";
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, long_path, "polkit-overlong"));
-}
-
-test "canvas screen counts default to three and reject values outside one to ten" {
- const a = std.testing.allocator;
- var defaults = try parse(a, "", "mem");
- defer defaults.deinit();
- try std.testing.expectEqual(@as(u32, 3), defaults.compositor.canvas_columns);
- try std.testing.expectEqual(@as(u32, 3), defaults.compositor.canvas_rows);
- var rectangular = try parse(a, "[compositor]\ncanvas_columns = 10\ncanvas_rows = 1\n", "mem");
- defer rectangular.deinit();
- try std.testing.expectEqual(@as(u32, 10), rectangular.compositor.canvas_columns);
- try std.testing.expectEqual(@as(u32, 1), rectangular.compositor.canvas_rows);
- inline for (.{ "canvas_columns", "canvas_rows" }) |key| {
- inline for (.{ "0", "11", "-1", "1.5" }) |value| {
- try std.testing.expectError(error.InvalidConfig, parse(a, "[compositor]\n" ++ key ++ " = " ++ value ++ "\n", "err"));
- }
- }
-}
-
-test "desktop switch duration sets the camera_desktop curve unless animations override it" {
- const a = std.testing.allocator;
- const idx = @intFromEnum(anim.Target.camera_desktop);
- var defaults = try parse(a, "", "mem");
- defer defaults.deinit();
- try std.testing.expectEqual(anim.desktopSwitchCurve(anim.default_desktop_switch_ms), defaults.animations.targets[idx].curve);
- var slow = try parse(a, "[compositor]\ndesktop_switch_ms = 1500\n", "mem");
- defer slow.deinit();
- try std.testing.expectEqual(anim.desktopSwitchCurve(1500), slow.animations.targets[idx].curve);
- var explicit = try parse(a, "[compositor]\ndesktop_switch_ms = 1500\n[animations.camera_desktop]\nduration_ms = 300\n", "mem");
- defer explicit.deinit();
- try std.testing.expectEqual(@as(i64, 300), explicit.animations.targets[idx].curve.duration.ms);
- inline for (.{ "99", "3001" }) |value| {
- try std.testing.expectError(error.InvalidConfig, parse(a, "[compositor]\ndesktop_switch_ms = " ++ value ++ "\n", "err"));
- }
-}
-
-test "input method environment validates supported names" {
- for ([_][]const u8{ "none", "fcitx", "ibus" }) |name| {
- const source = try std.fmt.allocPrint(std.testing.allocator, "[input_method]\nenv = \"{s}\"\n", .{name});
- defer std.testing.allocator.free(source);
- var cfg = try parse(std.testing.allocator, source, "ime-env");
- defer cfg.deinit();
- try std.testing.expectEqualStrings(name, @tagName(cfg.input_method.env));
- }
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, "[input_method]\nenv = \"unknown\"", "bad-ime-env"));
-}
-
-test "sandbox_allow TOML parsing and resolution" {
- const toml =
- \\[[sandbox_allow]]
- \\app_id = "com.obsproject.Studio"
- \\engine = "org.flatpak"
- \\allow = ["capture", "windows"]
- \\
- \\[[sandbox_allow]]
- \\app_id = "org.example.App"
- \\allow = ["clipboard", "unknown_group"]
- ;
- var cfg = try parse(std.testing.allocator, toml, "sandbox-test");
- defer cfg.deinit();
-
- try std.testing.expectEqual(@as(usize, 2), cfg.sandbox_allow.len);
-
- const obs = cfg.sandboxAllowGroups("com.obsproject.Studio", "org.flatpak");
- try std.testing.expect(obs.contains(.capture));
- try std.testing.expect(obs.contains(.windows));
- try std.testing.expect(!obs.contains(.clipboard));
-
- const obs_wrong_engine = cfg.sandboxAllowGroups("com.obsproject.Studio", "other.engine");
- try std.testing.expect(obs_wrong_engine.count() == 0);
-
- const app = cfg.sandboxAllowGroups("org.example.App", "any.engine");
- try std.testing.expect(app.contains(.clipboard));
- try std.testing.expect(!app.contains(.capture));
-
- try std.testing.expect(cfg.sandboxAllowGroups(null, null).count() == 0);
-
- const bad_toml =
- \\[[sandbox_allow]]
- \\allow = ["clipboard"]
- ;
- try std.testing.expectError(error.InvalidConfig, parse(std.testing.allocator, bad_toml, "bad-sandbox"));
-}
-
-test "mini map defaults and validated configuration" {
- const a = std.testing.allocator;
- var defaults = try parse(a, "", "mem");
- defer defaults.deinit();
- try std.testing.expect(defaults.compositor.mini_map_enabled);
- try std.testing.expectEqual(.bottom_right, defaults.compositor.mini_map_position);
- try std.testing.expectEqual(@as(u32, 1500), defaults.compositor.mini_map_hide_ms);
- var custom = try parse(a, "[compositor]\nmini_map_enabled = false\nmini_map_position = \"bottom_center\"\nmini_map_hide_ms = 2000\n", "mem");
- defer custom.deinit();
- try std.testing.expect(!custom.compositor.mini_map_enabled);
- try std.testing.expectEqual(.bottom_center, custom.compositor.mini_map_position);
- try std.testing.expectEqual(@as(u32, 2000), custom.compositor.mini_map_hide_ms);
- inline for (.{ "mini_map_position = \"top\"", "mini_map_hide_ms = 0", "mini_map_hide_ms = 10001", "mini_map_enabled = 1" }) |line| {
- try std.testing.expectError(error.InvalidConfig, parse(a, "[compositor]\n" ++ line ++ "\n", "invalid"));
- }
-}
-
-test "workspace preset is independent, overrides include noop, and mode preserves canvas bindings" {
- var cfg = try parse(std.testing.allocator, "[keybinds]\n\"Super+q\" = \"spawn custom-canvas\"\n" ++
- "[keybinds.workspace]\n\"Super+c\" = \"noop\"\n\"Super+F12\" = \"workspace 8\"\n", "test");
- defer cfg.deinit();
- const q = try keybinds.parseKeybind("Super+q");
- const c = try keybinds.parseKeybind("Super+c");
- const two = try keybinds.parseKeybind("Super+2");
- try std.testing.expectEqualStrings("custom-canvas", cfg.lookupKeybind(q.modifiers, q.sym).?.spawn);
- cfg.compositor.desktop_mode = .workspaces;
- const monitor = try keybinds.parseKeybind("Ctrl+Alt+Delete");
- try std.testing.expectEqual(Action.open_system_monitor, cfg.lookupKeybind(monitor.modifiers, monitor.sym).?);
- try std.testing.expectEqualStrings("default-terminal", cfg.lookupKeybind(q.modifiers, q.sym).?.spawn);
- try std.testing.expectEqual(Action.noop, cfg.lookupKeybind(c.modifiers, c.sym).?);
- try std.testing.expectEqual(@as(u8, 2), cfg.lookupKeybind(two.modifiers, two.sym).?.workspace);
- const v = try keybinds.parseKeybind("Super+v");
- const rotate = try keybinds.parseKeybind("Super+j");
- const swap = try keybinds.parseKeybind("Super+Shift+Right");
- const split = try keybinds.parseKeybind("Super+Ctrl+Right");
- try std.testing.expectEqual(Action.toggle_floating, cfg.lookupKeybind(v.modifiers, v.sym).?);
- try std.testing.expectEqual(Action.toggle_split, cfg.lookupKeybind(rotate.modifiers, rotate.sym).?);
- try std.testing.expectEqual(Action.swap_right, cfg.lookupKeybind(swap.modifiers, swap.sym).?);
- try std.testing.expectEqual(Action.resize_split_right, cfg.lookupKeybind(split.modifiers, split.sym).?);
- cfg.compositor.desktop_mode = .canvas;
- try std.testing.expectEqual(@as(?Action, null), cfg.lookupKeybind(v.modifiers, v.sym));
- try std.testing.expectEqualStrings("custom-canvas", cfg.lookupKeybind(q.modifiers, q.sym).?.spawn);
- try std.testing.expectEqual(@as(?Action, null), cfg.lookupKeybind(two.modifiers, two.sym));
-}
-
-test "no base preserves legacy themes and embedded base layers config overrides" {
- const a = std.testing.allocator;
- const bytes = "[theme]\naccent = \"#123456\"\nfont_size = 14\n";
- var old = try parse(a, bytes, "legacy");
- defer old.deinit();
- var loaded = try loadFromBytes(a, bytes, "legacy", .empty, std.testing.io);
- defer loaded.deinit();
- try std.testing.expect(themeEql(old.theme, loaded.theme));
- var based = try loadFromBytes(a, "[theme]\nbase = \"rediwm-light\"\nfont_size = 14\n", "based", .empty, std.testing.io);
- defer based.deinit();
- try std.testing.expectEqualStrings("rediwm-light", based.theme_base);
- try std.testing.expectEqual(@as(f32, 14), based.theme.font_size);
- try std.testing.expect(themeEql(based.theme_defaults, based.theme_pack.?.tokens));
- try std.testing.expectEqual(based.theme_defaults.accent, based.theme.accent);
-
- var gold = try loadFromBytes(a, "[theme]\nbase = \"gold\"\n", "gold", .empty, std.testing.io);
- defer gold.deinit();
- try std.testing.expectEqual(.top, gold.compositor.taskbar_position);
- try std.testing.expect(gold.compositor.dock_enabled);
- try std.testing.expectEqual(@as(u32, 76), gold.compositor.dock_height);
- var customized = try loadFromBytes(a, "[theme]\nbase = \"gold\"\n[compositor]\ntaskbar_position = \"bottom\"\ndock_enabled = false\ndock_height = 52\n", "gold", .empty, std.testing.io);
- defer customized.deinit();
- try std.testing.expectEqual(.bottom, customized.compositor.taskbar_position);
- try std.testing.expect(!customized.compositor.dock_enabled);
- try std.testing.expectEqual(@as(u32, 52), customized.compositor.dock_height);
-}
-
-test "external overlay wins over a referenced pack without pinning inherited tokens" {
- const a = std.testing.allocator;
- const io = std.testing.io;
- var tmp = std.testing.tmpDir(.{});
- defer tmp.cleanup();
- var arena = std.heap.ArenaAllocator.init(a);
- defer arena.deinit();
- const mem = arena.allocator();
- const root = try tmp.dir.realPathFileAlloc(io, ".", mem);
- const path = try std.fs.path.join(mem, &.{ root, "overlay.toml" });
- try tmp.dir.writeFile(io, .{ .sub_path = "overlay.toml", .data = "[theme]\nfont_size = 16\n" });
- const entry = try std.fmt.allocPrintSentinel(mem, "REDIWM_THEME={s}", .{path}, 0);
- const entries = [_:null]?[*:0]const u8{entry.ptr};
- const env: std.process.Environ = .{ .block = .{ .slice = &entries } };
- var cfg = try loadFromBytes(a, "[theme]\nbase = \"rediwm-light\"\nfont_size = 14\n", "test", env, io);
- defer cfg.deinit();
- try std.testing.expectEqual(@as(f32, 16), cfg.theme.font_size);
- try std.testing.expectEqual(@as(f32, 14), cfg.theme_config.font_size);
- var edited = cfg.theme;
- edited.font_size = 17;
- try theme_mod.saveOverlay(a, io, path, edited, cfg.theme_config);
- const saved = try tmp.dir.readFileAlloc(io, "overlay.toml", a, .limited(4096));
- defer a.free(saved);
- try std.testing.expectEqualStrings("[theme]\nfont_size = 17\n", saved);
+test {
+ _ = @import("loader_sections_tests.zig");
}
diff --git a/src/ipc/protocol_parse_tests.zig b/src/ipc/protocol_parse_tests.zig
new file mode 100644
index 0000000..05ea7dc
--- /dev/null
+++ b/src/ipc/protocol_parse_tests.zig
@@ -0,0 +1,319 @@
+//! Action parsing tests: virtual input, screenshots, the camera and audio.
+
+const std = @import("std");
+const protocol = @import("protocol.zig");
+
+test "parse virtual input actions" {
+ const allocator = std.testing.allocator;
+
+ const r_mc = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"move_cursor\",\"params\":{\"x\":100,\"y\":200,\"output\":\"HDMI-A-1\"}}");
+ switch (r_mc) {
+ .action => |act| switch (act) {
+ .move_cursor => |p| {
+ try std.testing.expectEqual(@as(i32, 100), p.x);
+ try std.testing.expectEqual(@as(i32, 200), p.y);
+ try std.testing.expectEqualSlices(u8, "HDMI-A-1", p.output.?);
+ allocator.free(p.output.?);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_mcr = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"move_cursor_relative\",\"params\":{\"dx\":15,\"dy\":-5}}");
+ switch (r_mcr) {
+ .action => |act| switch (act) {
+ .move_cursor_relative => |p| {
+ try std.testing.expectEqual(@as(i32, 15), p.dx);
+ try std.testing.expectEqual(@as(i32, -5), p.dy);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_pb = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"pointer_button\",\"params\":{\"button\":272,\"pressed\":true}}");
+ switch (r_pb) {
+ .action => |act| switch (act) {
+ .pointer_button => |p| {
+ try std.testing.expectEqual(@as(u32, 272), p.button);
+ try std.testing.expectEqual(true, p.pressed);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_clk1 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"click\",\"params\":{\"button\":273}}");
+ switch (r_clk1) {
+ .action => |act| switch (act) {
+ .click => |p| try std.testing.expectEqual(@as(u32, 273), p.button),
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_clk2 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"click\"}");
+ switch (r_clk2) {
+ .action => |act| switch (act) {
+ .click => |p| try std.testing.expectEqual(@as(u32, 0x110), p.button),
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_sc = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"scroll\",\"params\":{\"dx\":0.0,\"dy\":15.5}}");
+ switch (r_sc) {
+ .action => |act| switch (act) {
+ .scroll => |p| {
+ try std.testing.expectEqual(@as(f64, 0.0), p.dx);
+ try std.testing.expectEqual(@as(f64, 15.5), p.dy);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_k = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"key\",\"params\":{\"keycode\":28,\"pressed\":false}}");
+ switch (r_k) {
+ .action => |act| switch (act) {
+ .key => |p| {
+ try std.testing.expectEqual(@as(u32, 28), p.keycode);
+ try std.testing.expectEqual(false, p.pressed);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_kp = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"key_press\",\"params\":{\"key\":\"Return\"}}");
+ switch (r_kp) {
+ .action => |act| switch (act) {
+ .key_press => |p| {
+ try std.testing.expectEqualSlices(u8, "Return", p.key);
+ allocator.free(p.key);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_tt = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"type_text\",\"params\":{\"text\":\"echo hello\"}}");
+ switch (r_tt) {
+ .action => |act| switch (act) {
+ .type_text => |p| {
+ try std.testing.expectEqualSlices(u8, "echo hello", p.text);
+ allocator.free(p.text);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_dg = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"drag\",\"params\":{\"from_x\":10,\"from_y\":20,\"to_x\":100,\"to_y\":200,\"button\":272}}");
+ switch (r_dg) {
+ .action => |act| switch (act) {
+ .drag => |p| {
+ try std.testing.expectEqual(@as(i32, 10), p.from_x);
+ try std.testing.expectEqual(@as(i32, 20), p.from_y);
+ try std.testing.expectEqual(@as(i32, 100), p.to_x);
+ try std.testing.expectEqual(@as(i32, 200), p.to_y);
+ try std.testing.expectEqual(@as(u32, 272), p.button);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+}
+
+test "parse screenshot action" {
+ const allocator = std.testing.allocator;
+
+ const r_sc1 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"screenshot\"}");
+ switch (r_sc1) {
+ .action => |act| switch (act) {
+ .screenshot => |p| {
+ try std.testing.expectEqual(@as(?[]const u8, null), p.output);
+ try std.testing.expectEqual(@as(?u64, null), p.window_id);
+ try std.testing.expectEqual(false, p.include_cursor);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_sc2 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"screenshot\",\"params\":{\"output\":\"WL-1\",\"window_id\":12,\"mode\":\"visible-region\",\"include_cursor\":true,\"path\":\"/tmp/shot.png\"}}");
+ switch (r_sc2) {
+ .action => |act| switch (act) {
+ .screenshot => |p| {
+ try std.testing.expectEqualSlices(u8, "WL-1", p.output.?);
+ try std.testing.expectEqual(@as(?u64, 12), p.window_id);
+ try std.testing.expectEqualSlices(u8, "visible-region", p.mode.?);
+ try std.testing.expectEqual(true, p.include_cursor);
+ try std.testing.expectEqualSlices(u8, "/tmp/shot.png", p.path.?);
+ allocator.free(p.output.?);
+ allocator.free(p.mode.?);
+ allocator.free(p.path.?);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+}
+
+test "parse camera actions" {
+ const allocator = std.testing.allocator;
+
+ const r_get = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_camera\"}");
+ switch (r_get) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.get_camera, act),
+ else => return error.TestFailed,
+ }
+
+ const r_reset = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"reset_camera\"}");
+ switch (r_reset) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.reset_camera, act),
+ else => return error.TestFailed,
+ }
+
+ const r_set = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_camera\",\"params\":{\"x\":250,\"y\":-150}}");
+ switch (r_set) {
+ .action => |act| switch (act) {
+ .set_camera => |p| {
+ try std.testing.expectEqual(@as(i32, 250), p.x);
+ try std.testing.expectEqual(@as(i32, -150), p.y);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+}
+
+test "parse audio actions" {
+ const allocator = std.testing.allocator;
+
+ const r_vol = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_master_volume\",\"params\":{\"volume\":0.5}}");
+ switch (r_vol) {
+ .action => |act| switch (act) {
+ .set_master_volume => |p| try std.testing.expectApproxEqAbs(@as(f32, 0.5), p.volume, 1e-6),
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ // Integer JSON values must also be accepted for a float field.
+ const r_vol_int = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_master_volume\",\"params\":{\"volume\":1}}");
+ switch (r_vol_int) {
+ .action => |act| switch (act) {
+ .set_master_volume => |p| try std.testing.expectApproxEqAbs(@as(f32, 1.0), p.volume, 1e-6),
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ try std.testing.expectError(error.InvalidRequest, protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_master_volume\",\"params\":{\"volume\":1.5}}"));
+
+ const r_mute = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"toggle_mute\"}");
+ switch (r_mute) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.toggle_mute, act),
+ else => return error.TestFailed,
+ }
+
+ const r_app = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_app_volume\",\"params\":{\"index\":7,\"volume\":0.8}}");
+ switch (r_app) {
+ .action => |act| switch (act) {
+ .set_app_volume => |p| {
+ try std.testing.expectEqual(@as(u32, 7), p.index);
+ try std.testing.expectApproxEqAbs(@as(f32, 0.8), p.volume, 1e-6);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_app_mute = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_app_mute\",\"params\":{\"index\":7,\"muted\":true}}");
+ switch (r_app_mute) {
+ .action => |act| switch (act) {
+ .set_app_mute => |p| {
+ try std.testing.expectEqual(@as(u32, 7), p.index);
+ try std.testing.expectEqual(true, p.muted);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_get = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_audio_state\"}");
+ switch (r_get) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.get_audio_state, act),
+ else => return error.TestFailed,
+ }
+
+ const r_stats = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_panel_stats\"}");
+ switch (r_stats) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.get_panel_stats, act),
+ else => return error.TestFailed,
+ }
+
+ const r_anims = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_animations\"}");
+ switch (r_anims) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.get_animations, act),
+ else => return error.TestFailed,
+ }
+
+ const r_reset = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"reset_panel_stats\"}");
+ switch (r_reset) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.reset_panel_stats, act),
+ else => return error.TestFailed,
+ }
+
+ const r_pinch = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"pinch\",\"params\":{\"phase\":\"begin\",\"scale\":1.2,\"fingers\":2}}");
+ switch (r_pinch) {
+ .action => |act| switch (act) {
+ .pinch => |p| {
+ try std.testing.expectEqual(protocol.GesturePhase.begin, p.phase);
+ try std.testing.expectApproxEqAbs(@as(f64, 1.2), p.scale, 1e-9);
+ try std.testing.expectEqual(@as(u32, 2), p.fingers);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_swipe = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"swipe\",\"params\":{\"phase\":\"update\",\"dx\":12,\"dy\":-4}}");
+ switch (r_swipe) {
+ .action => |act| switch (act) {
+ .swipe => |p| {
+ try std.testing.expectEqual(protocol.GesturePhase.update, p.phase);
+ try std.testing.expectApproxEqAbs(@as(f64, 12), p.dx, 1e-9);
+ try std.testing.expectApproxEqAbs(@as(f64, -4), p.dy, 1e-9);
+ },
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_time = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_anim_time\",\"params\":{\"ms\":110}}");
+ switch (r_time) {
+ .action => |act| switch (act) {
+ .set_anim_time => |p| try std.testing.expectEqual(@as(?i64, 110), p.ms),
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_clear = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_anim_time\",\"params\":{\"ms\":null}}");
+ switch (r_clear) {
+ .action => |act| switch (act) {
+ .set_anim_time => |p| try std.testing.expectEqual(@as(?i64, null), p.ms),
+ else => return error.TestFailed,
+ },
+ else => return error.TestFailed,
+ }
+
+ const r_open = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"open_start_menu\"}");
+ switch (r_open) {
+ .action => |act| try std.testing.expectEqual(protocol.Action.open_start_menu, act),
+ else => return error.TestFailed,
+ }
+}
diff --git a/src/ipc/protocol_stringify_tests.zig b/src/ipc/protocol_stringify_tests.zig
new file mode 100644
index 0000000..e3346b6
--- /dev/null
+++ b/src/ipc/protocol_stringify_tests.zig
@@ -0,0 +1,292 @@
+//! Serializer tests: responses and events, screenshots and PNG encoding, audio, performance, panel and animation stats, widget events and id envelopes.
+
+const std = @import("std");
+const protocol = @import("protocol.zig");
+
+test "stringify response" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const resp = protocol.Response{ .ok = .{ .version = "0.1.0" } };
+ try protocol.stringifyResponse(resp, bw);
+ try std.testing.expectEqualSlices(u8, "{\"Ok\":{\"Version\":\"0.1.0\"}}\n", list.items);
+}
+
+test "stringify event" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const ev = protocol.Event{ .window_closed = .{ .seq = 3, .id = 42 } };
+ try protocol.stringifyEvent(ev, bw);
+ try std.testing.expectEqualSlices(u8, "{\"WindowClosed\":{\"seq\":3,\"id\":42}}\n", list.items);
+}
+
+test "stringify screenshot response" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const sr = protocol.ScreenshotResult{
+ .width = 1920,
+ .height = 1080,
+ .format = "png",
+ .data = "SGVsbG8=",
+ .path = null,
+ .output_name = "WL-1",
+ .capture_mode = "output",
+ .frame_seq = 42,
+ };
+ const resp = protocol.Response{ .ok = .{ .screenshot = sr } };
+ try protocol.stringifyResponse(resp, bw);
+
+ const expected = "{\"Ok\":{\"Screenshot\":{\"width\":1920,\"height\":1080,\"format\":\"png\",\"data\":\"SGVsbG8=\",\"path\":null,\"output_name\":\"WL-1\",\"capture_mode\":\"output\",\"frame_seq\":42}}}\n";
+ try std.testing.expectEqualSlices(u8, expected, list.items);
+}
+
+test "encode png and base64" {
+ const allocator = std.testing.allocator;
+ const encode = @import("../screenshot/encode.zig");
+
+ var pixels: [16]u32 = undefined;
+ for (&pixels) |*p| p.* = 0xFF00FF00; // Opaque green premultiplied ARGB8888
+
+ const png_bytes = try encode.encodePng(allocator, 4, 4, &pixels, 4);
+ defer allocator.free(png_bytes);
+
+ // Verify PNG header signature
+ const sig = [_]u8{ 0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n' };
+ try std.testing.expect(png_bytes.len > sig.len);
+ try std.testing.expectEqualSlices(u8, &sig, png_bytes[0..sig.len]);
+
+ const b64 = try encode.encodeBase64(allocator, png_bytes);
+ defer allocator.free(b64);
+ try std.testing.expect(b64.len > 0);
+}
+
+test "stringify camera response and event" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+
+ const resp = protocol.Response{ .ok = .{ .camera = .{ .x = 100, .y = -50, .max_x = 1920, .max_y = 1080 } } };
+ try protocol.stringifyResponse(resp, bw);
+ try std.testing.expectEqualSlices(u8, "{\"Ok\":{\"Camera\":{\"x\":100,\"y\":-50,\"max_x\":1920,\"max_y\":1080,\"zoom_percent\":100}}}\n", list.items);
+
+ list.clearRetainingCapacity();
+ const ev = protocol.Event{ .camera_changed = .{ .seq = 7, .x = 200, .y = 100, .max_x = 1920, .max_y = 1080 } };
+ try protocol.stringifyEvent(ev, bw);
+ try std.testing.expectEqualSlices(u8, "{\"CameraChanged\":{\"seq\":7,\"x\":200,\"y\":100,\"max_x\":1920,\"max_y\":1080,\"zoom_percent\":100}}\n", list.items);
+}
+
+test "stringify audio state response" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const streams = [_]protocol.SinkInputData{
+ .{ .index = 5, .name = "Firefox", .app_id = "org.mozilla.firefox", .pid = 1234, .volume = 0.8, .muted = false },
+ };
+ const resp = protocol.Response{ .ok = .{ .audio_state = .{
+ .master_volume = 0.6,
+ .master_muted = false,
+ .default_sink = "Built-in Audio",
+ .streams = &streams,
+ } } };
+ try protocol.stringifyResponse(resp, bw);
+
+ const expected = "{\"Ok\":{\"AudioState\":{\"master_volume\":0.6,\"master_muted\":false,\"default_sink\":\"Built-in Audio\",\"streams\":[{\"index\":5,\"name\":\"Firefox\",\"app_id\":\"org.mozilla.firefox\",\"pid\":1234,\"volume\":0.8,\"muted\":false}]}}}\n";
+ try std.testing.expectEqualSlices(u8, expected, list.items);
+}
+
+test "stringify performance stats includes edge sample counters" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const resp = protocol.Response{ .ok = .{ .performance_stats = .{
+ .output_commits = 3,
+ .output_failed_commits = 1,
+ .titlebar_paints = 4,
+ .footer_paints = 2,
+ .edge_samples_attempted = 5,
+ .edge_samples_succeeded = 4,
+ .edge_samples_skipped = 9,
+ .edge_sample_ns = 1234,
+ .panel_paints = 0,
+ .panel_allocated_bytes = 0,
+ .panel_reused_bytes = 0,
+ .icon_cache_hits = 0,
+ .icon_cache_misses = 0,
+ .icon_decode_ns = 0,
+ .icon_decode_count = 0,
+ .icon_decoded_bytes = 0,
+ .icon_queue_depth_max = 0,
+ .taskbar_paints = 1,
+ .taskbar_paint_ns = 500,
+ .taskbar_raster_pixels = 640,
+ .taskbar_clock_frame_requests = 2,
+ .taskbar_clock_paints = 1,
+ .taskbar_start_paints = 0,
+ .taskbar_chip_paints = 1,
+ .taskbar_tray_paints = 0,
+ .taskbar_hover_paints = 0,
+ .taskbar_press_paints = 0,
+ .taskbar_audio_paints = 0,
+ .recent_errors_count = 0,
+ } } };
+ try protocol.stringifyResponse(resp, bw);
+
+ const expected = "{\"Ok\":{\"PerformanceStats\":{\"output_commits\":3,\"output_failed_commits\":1,\"fps\":0.0,\"frame_time_ms\":0.0,\"missed_frames\":0,\"refresh_hz\":0.0,\"titlebar_paints\":4,\"footer_paints\":2,\"edge_samples_attempted\":5,\"edge_samples_succeeded\":4,\"edge_samples_skipped\":9,\"edge_sample_ns\":1234,\"panel_paints\":0,\"panel_allocated_bytes\":0,\"panel_reused_bytes\":0,\"icon_cache_hits\":0,\"icon_cache_misses\":0,\"icon_decode_ns\":0,\"icon_decode_count\":0,\"icon_decoded_bytes\":0,\"icon_queue_depth_max\":0,\"taskbar_paints\":1,\"taskbar_paint_ns\":500,\"taskbar_raster_pixels\":640,\"taskbar_clock_frame_requests\":2,\"taskbar_clock_paints\":1,\"taskbar_start_paints\":0,\"taskbar_chip_paints\":1,\"taskbar_tray_paints\":0,\"taskbar_hover_paints\":0,\"taskbar_press_paints\":0,\"taskbar_audio_paints\":0,\"recent_errors_count\":0,\"anim_frames_scheduled\":0,\"anim_wasted_wakeups\":0,\"anim_longest_ms\":0,\"anim_speed\":1,\"anim_enabled\":true,\"anim_reduced_motion\":false}}}\n";
+ try std.testing.expectEqualSlices(u8, expected, list.items);
+
+ // Live producers add work timings; preserve the legacy fixture above.
+ var extended = resp;
+ extended.ok.performance_stats.screenshot_selection = .{ .motion_events = 500, .updates = 2, .toolbar_paints = 1, .scene_nodes_created = 19 };
+ extended.ok.performance_stats.frame_work = .{
+ .cpu_frame = .{ .samples = 3, .total_samples = 3, .avg_ms = 3, .p50_ms = 3, .p95_ms = 5, .p99_ms = 5, .max_ms = 5 },
+ };
+ list.clearRetainingCapacity();
+ try protocol.stringifyResponse(extended, bw);
+ const parsed = try std.json.parseFromSlice(std.json.Value, allocator, list.items, .{});
+ defer parsed.deinit();
+ const selection = parsed.value.object.get("Ok").?.object.get("PerformanceStats").?.object.get("screenshot_selection").?;
+ try std.testing.expectEqual(@as(i64, 500), selection.object.get("motion_events").?.integer);
+ try std.testing.expectEqual(@as(i64, 2), selection.object.get("updates").?.integer);
+ const work = parsed.value.object.get("Ok").?.object.get("PerformanceStats").?.object.get("frame_work").?;
+ try std.testing.expectEqual(@as(i64, 3), work.object.get("cpu_frame").?.object.get("samples").?.integer);
+ try std.testing.expect(!work.object.get("gpu_timing_available").?.bool);
+ try std.testing.expectEqual(@as(i64, 0), work.object.get("gpu_elapsed").?.object.get("samples").?.integer);
+}
+
+test "stringify panel stats response" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const resp = protocol.Response{ .ok = .{ .panel_stats = .{
+ .paints = 1,
+ .allocated_bytes = 4096,
+ .reused_bytes = 2048,
+ .paint_ns = 12345,
+ } } };
+ try protocol.stringifyResponse(resp, bw);
+
+ const expected = "{\"Ok\":{\"PanelStats\":{\"paints\":1,\"allocated_bytes\":4096,\"reused_bytes\":2048,\"paint_ns\":12345}}}\n";
+ try std.testing.expectEqualSlices(u8, expected, list.items);
+}
+
+test "stringify animations response" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const items = [_]protocol.AnimationData{
+ .{ .site = "start_menu.slide", .value = 0.5, .velocity = 1.25, .target = 1, .settled = false, .curve = "spring" },
+ };
+ const resp = protocol.Response{ .ok = .{ .animations = &items } };
+ try protocol.stringifyResponse(resp, bw);
+
+ const expected = "{\"Ok\":{\"Animations\":[{\"site\":\"start_menu.slide\",\"value\":0.5,\"velocity\":1.25,\"target\":1,\"settled\":false,\"curve\":\"spring\"}]}}\n";
+ try std.testing.expectEqualSlices(u8, expected, list.items);
+}
+
+test "stringify WidgetChanged event" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const ev = protocol.Event{
+ .widget_changed = .{
+ .seq = 10,
+ .time_ms = 1000,
+ .session_id = "test-session",
+ .panel = "control_center",
+ .path = "control_center/wifi",
+ .name = "wifi",
+ .widget = .{
+ .id = 1,
+ .role = "toggle",
+ .name = "wifi",
+ .path = "control_center/wifi",
+ .box = .{ .x = 10, .y = 20, .width = 30, .height = 40 },
+ .on = true,
+ },
+ },
+ };
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ try protocol.stringifyEvent(ev, bw);
+ try std.testing.expect(std.mem.indexOf(u8, list.items, "\"WidgetChanged\"") != null);
+ try std.testing.expect(std.mem.indexOf(u8, list.items, "\"control_center/wifi\"") != null);
+ try std.testing.expect(std.mem.indexOf(u8, list.items, "\"on\":true") != null);
+}
+
+test "stringify response with id envelope" {
+ const allocator = std.testing.allocator;
+ var list = std.ArrayList(u8).empty;
+ defer list.deinit(allocator);
+
+ const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
+ const resp = protocol.Response{ .ok = .handled };
+
+ try protocol.stringifyResponseWithId(.{ .integer = 42 }, resp, bw);
+ try std.testing.expectEqualSlices(u8, "{\"id\":42,\"Ok\":\"Handled\"}\n", list.items);
+
+ list.clearRetainingCapacity();
+ try protocol.stringifyResponseWithId(.{ .string = "query-1" }, resp, bw);
+ try std.testing.expectEqualSlices(u8, "{\"id\":\"query-1\",\"Ok\":\"Handled\"}\n", list.items);
+}
+
+pub fn expectJsonEqual(expected: std.json.Value, actual: std.json.Value) !void {
+ if (expected == .integer and actual == .float) return std.testing.expectEqual(@as(f64, @floatFromInt(expected.integer)), actual.float);
+ if (expected == .float and actual == .integer) return std.testing.expectEqual(expected.float, @as(f64, @floatFromInt(actual.integer)));
+ try std.testing.expectEqual(std.meta.activeTag(expected), std.meta.activeTag(actual));
+ switch (expected) {
+ .object => |obj| {
+ try std.testing.expectEqual(obj.count(), actual.object.count());
+ var it = obj.iterator();
+ while (it.next()) |entry| try expectJsonEqual(entry.value_ptr.*, actual.object.get(entry.key_ptr.*) orelse return error.TestUnexpectedResult);
+ },
+ .array => |arr| {
+ try std.testing.expectEqual(arr.items.len, actual.array.items.len);
+ for (arr.items, actual.array.items) |a, b| try expectJsonEqual(a, b);
+ },
+ .string, .number_string => |s| try std.testing.expectEqualStrings(s, if (actual == .string) actual.string else actual.number_string),
+ .integer => |i| try std.testing.expectEqual(i, actual.integer),
+ .float => |f| try std.testing.expectEqual(f, actual.float),
+ .bool => |b| try std.testing.expectEqual(b, actual.bool),
+ .null => {},
+ }
+}
+
+test "response serializers preserve baseline fields rounding and omissions" {
+ @setEvalBranchQuota(200_000);
+ const fixtures = @import("../ipc_serializer_fixtures.zig");
+ var lines = std.mem.splitScalar(u8, @embedFile("../ipc_serializers.jsonl"), '\n');
+ inline for (std.meta.fields(protocol.ResponsePayload)) |field| {
+ inline for (.{ false, true }) |populated| {
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const payload = @unionInit(protocol.ResponsePayload, field.name, fixtures.sample(field.type, populated));
+ var list: std.ArrayList(u8) = .empty;
+ try protocol.stringifyResponse(.{ .ok = payload }, protocol.BufferWriter{ .list = &list, .allocator = a });
+ const actual = try std.json.parseFromSlice(std.json.Value, a, list.items, .{});
+ const expected = try std.json.parseFromSlice(std.json.Value, a, lines.next().?, .{});
+ expectJsonEqual(expected.value, actual.value) catch |err| {
+ std.debug.print("serializer {s}, populated={}\n", .{ field.name, populated });
+ return err;
+ };
+ }
+ }
+}
diff --git a/src/ipc_tests.zig b/src/ipc_tests.zig
index 2fc78e8..27dbdc9 100644
--- a/src/ipc_tests.zig
+++ b/src/ipc_tests.zig
@@ -88,517 +88,12 @@ test "parse output transform configuration" {
try std.testing.expectError(error.InvalidRequest, protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_output_config\",\"params\":{\"output\":\"DP-1\",\"transform\":\"sideways\"}}"));
}
-test "stringify response" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const resp = protocol.Response{ .ok = .{ .version = "0.1.0" } };
- try protocol.stringifyResponse(resp, bw);
- try std.testing.expectEqualSlices(u8, "{\"Ok\":{\"Version\":\"0.1.0\"}}\n", list.items);
-}
-
-test "stringify event" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const ev = protocol.Event{ .window_closed = .{ .seq = 3, .id = 42 } };
- try protocol.stringifyEvent(ev, bw);
- try std.testing.expectEqualSlices(u8, "{\"WindowClosed\":{\"seq\":3,\"id\":42}}\n", list.items);
-}
-
-test "parse virtual input actions" {
- const allocator = std.testing.allocator;
-
- const r_mc = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"move_cursor\",\"params\":{\"x\":100,\"y\":200,\"output\":\"HDMI-A-1\"}}");
- switch (r_mc) {
- .action => |act| switch (act) {
- .move_cursor => |p| {
- try std.testing.expectEqual(@as(i32, 100), p.x);
- try std.testing.expectEqual(@as(i32, 200), p.y);
- try std.testing.expectEqualSlices(u8, "HDMI-A-1", p.output.?);
- allocator.free(p.output.?);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_mcr = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"move_cursor_relative\",\"params\":{\"dx\":15,\"dy\":-5}}");
- switch (r_mcr) {
- .action => |act| switch (act) {
- .move_cursor_relative => |p| {
- try std.testing.expectEqual(@as(i32, 15), p.dx);
- try std.testing.expectEqual(@as(i32, -5), p.dy);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_pb = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"pointer_button\",\"params\":{\"button\":272,\"pressed\":true}}");
- switch (r_pb) {
- .action => |act| switch (act) {
- .pointer_button => |p| {
- try std.testing.expectEqual(@as(u32, 272), p.button);
- try std.testing.expectEqual(true, p.pressed);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_clk1 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"click\",\"params\":{\"button\":273}}");
- switch (r_clk1) {
- .action => |act| switch (act) {
- .click => |p| try std.testing.expectEqual(@as(u32, 273), p.button),
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_clk2 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"click\"}");
- switch (r_clk2) {
- .action => |act| switch (act) {
- .click => |p| try std.testing.expectEqual(@as(u32, 0x110), p.button),
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_sc = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"scroll\",\"params\":{\"dx\":0.0,\"dy\":15.5}}");
- switch (r_sc) {
- .action => |act| switch (act) {
- .scroll => |p| {
- try std.testing.expectEqual(@as(f64, 0.0), p.dx);
- try std.testing.expectEqual(@as(f64, 15.5), p.dy);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_k = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"key\",\"params\":{\"keycode\":28,\"pressed\":false}}");
- switch (r_k) {
- .action => |act| switch (act) {
- .key => |p| {
- try std.testing.expectEqual(@as(u32, 28), p.keycode);
- try std.testing.expectEqual(false, p.pressed);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_kp = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"key_press\",\"params\":{\"key\":\"Return\"}}");
- switch (r_kp) {
- .action => |act| switch (act) {
- .key_press => |p| {
- try std.testing.expectEqualSlices(u8, "Return", p.key);
- allocator.free(p.key);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_tt = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"type_text\",\"params\":{\"text\":\"echo hello\"}}");
- switch (r_tt) {
- .action => |act| switch (act) {
- .type_text => |p| {
- try std.testing.expectEqualSlices(u8, "echo hello", p.text);
- allocator.free(p.text);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_dg = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"drag\",\"params\":{\"from_x\":10,\"from_y\":20,\"to_x\":100,\"to_y\":200,\"button\":272}}");
- switch (r_dg) {
- .action => |act| switch (act) {
- .drag => |p| {
- try std.testing.expectEqual(@as(i32, 10), p.from_x);
- try std.testing.expectEqual(@as(i32, 20), p.from_y);
- try std.testing.expectEqual(@as(i32, 100), p.to_x);
- try std.testing.expectEqual(@as(i32, 200), p.to_y);
- try std.testing.expectEqual(@as(u32, 272), p.button);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-}
-
-test "parse screenshot action" {
- const allocator = std.testing.allocator;
-
- const r_sc1 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"screenshot\"}");
- switch (r_sc1) {
- .action => |act| switch (act) {
- .screenshot => |p| {
- try std.testing.expectEqual(@as(?[]const u8, null), p.output);
- try std.testing.expectEqual(@as(?u64, null), p.window_id);
- try std.testing.expectEqual(false, p.include_cursor);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_sc2 = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"screenshot\",\"params\":{\"output\":\"WL-1\",\"window_id\":12,\"mode\":\"visible-region\",\"include_cursor\":true,\"path\":\"/tmp/shot.png\"}}");
- switch (r_sc2) {
- .action => |act| switch (act) {
- .screenshot => |p| {
- try std.testing.expectEqualSlices(u8, "WL-1", p.output.?);
- try std.testing.expectEqual(@as(?u64, 12), p.window_id);
- try std.testing.expectEqualSlices(u8, "visible-region", p.mode.?);
- try std.testing.expectEqual(true, p.include_cursor);
- try std.testing.expectEqualSlices(u8, "/tmp/shot.png", p.path.?);
- allocator.free(p.output.?);
- allocator.free(p.mode.?);
- allocator.free(p.path.?);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-}
-
-test "stringify screenshot response" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const sr = protocol.ScreenshotResult{
- .width = 1920,
- .height = 1080,
- .format = "png",
- .data = "SGVsbG8=",
- .path = null,
- .output_name = "WL-1",
- .capture_mode = "output",
- .frame_seq = 42,
- };
- const resp = protocol.Response{ .ok = .{ .screenshot = sr } };
- try protocol.stringifyResponse(resp, bw);
-
- const expected = "{\"Ok\":{\"Screenshot\":{\"width\":1920,\"height\":1080,\"format\":\"png\",\"data\":\"SGVsbG8=\",\"path\":null,\"output_name\":\"WL-1\",\"capture_mode\":\"output\",\"frame_seq\":42}}}\n";
- try std.testing.expectEqualSlices(u8, expected, list.items);
-}
-
-test "encode png and base64" {
- const allocator = std.testing.allocator;
- const encode = @import("screenshot/encode.zig");
-
- var pixels: [16]u32 = undefined;
- for (&pixels) |*p| p.* = 0xFF00FF00; // Opaque green premultiplied ARGB8888
-
- const png_bytes = try encode.encodePng(allocator, 4, 4, &pixels, 4);
- defer allocator.free(png_bytes);
-
- // Verify PNG header signature
- const sig = [_]u8{ 0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n' };
- try std.testing.expect(png_bytes.len > sig.len);
- try std.testing.expectEqualSlices(u8, &sig, png_bytes[0..sig.len]);
-
- const b64 = try encode.encodeBase64(allocator, png_bytes);
- defer allocator.free(b64);
- try std.testing.expect(b64.len > 0);
-}
-
-test "parse camera actions" {
- const allocator = std.testing.allocator;
-
- const r_get = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_camera\"}");
- switch (r_get) {
- .action => |act| try std.testing.expectEqual(protocol.Action.get_camera, act),
- else => return error.TestFailed,
- }
-
- const r_reset = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"reset_camera\"}");
- switch (r_reset) {
- .action => |act| try std.testing.expectEqual(protocol.Action.reset_camera, act),
- else => return error.TestFailed,
- }
-
- const r_set = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_camera\",\"params\":{\"x\":250,\"y\":-150}}");
- switch (r_set) {
- .action => |act| switch (act) {
- .set_camera => |p| {
- try std.testing.expectEqual(@as(i32, 250), p.x);
- try std.testing.expectEqual(@as(i32, -150), p.y);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-}
-
-test "stringify camera response and event" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
-
- const resp = protocol.Response{ .ok = .{ .camera = .{ .x = 100, .y = -50, .max_x = 1920, .max_y = 1080 } } };
- try protocol.stringifyResponse(resp, bw);
- try std.testing.expectEqualSlices(u8, "{\"Ok\":{\"Camera\":{\"x\":100,\"y\":-50,\"max_x\":1920,\"max_y\":1080,\"zoom_percent\":100}}}\n", list.items);
-
- list.clearRetainingCapacity();
- const ev = protocol.Event{ .camera_changed = .{ .seq = 7, .x = 200, .y = 100, .max_x = 1920, .max_y = 1080 } };
- try protocol.stringifyEvent(ev, bw);
- try std.testing.expectEqualSlices(u8, "{\"CameraChanged\":{\"seq\":7,\"x\":200,\"y\":100,\"max_x\":1920,\"max_y\":1080,\"zoom_percent\":100}}\n", list.items);
+test {
+ _ = @import("ipc/protocol_stringify_tests.zig");
}
-test "parse audio actions" {
- const allocator = std.testing.allocator;
-
- const r_vol = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_master_volume\",\"params\":{\"volume\":0.5}}");
- switch (r_vol) {
- .action => |act| switch (act) {
- .set_master_volume => |p| try std.testing.expectApproxEqAbs(@as(f32, 0.5), p.volume, 1e-6),
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- // Integer JSON values must also be accepted for a float field.
- const r_vol_int = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_master_volume\",\"params\":{\"volume\":1}}");
- switch (r_vol_int) {
- .action => |act| switch (act) {
- .set_master_volume => |p| try std.testing.expectApproxEqAbs(@as(f32, 1.0), p.volume, 1e-6),
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- try std.testing.expectError(error.InvalidRequest, protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_master_volume\",\"params\":{\"volume\":1.5}}"));
-
- const r_mute = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"toggle_mute\"}");
- switch (r_mute) {
- .action => |act| try std.testing.expectEqual(protocol.Action.toggle_mute, act),
- else => return error.TestFailed,
- }
-
- const r_app = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_app_volume\",\"params\":{\"index\":7,\"volume\":0.8}}");
- switch (r_app) {
- .action => |act| switch (act) {
- .set_app_volume => |p| {
- try std.testing.expectEqual(@as(u32, 7), p.index);
- try std.testing.expectApproxEqAbs(@as(f32, 0.8), p.volume, 1e-6);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_app_mute = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_app_mute\",\"params\":{\"index\":7,\"muted\":true}}");
- switch (r_app_mute) {
- .action => |act| switch (act) {
- .set_app_mute => |p| {
- try std.testing.expectEqual(@as(u32, 7), p.index);
- try std.testing.expectEqual(true, p.muted);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_get = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_audio_state\"}");
- switch (r_get) {
- .action => |act| try std.testing.expectEqual(protocol.Action.get_audio_state, act),
- else => return error.TestFailed,
- }
-
- const r_stats = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_panel_stats\"}");
- switch (r_stats) {
- .action => |act| try std.testing.expectEqual(protocol.Action.get_panel_stats, act),
- else => return error.TestFailed,
- }
-
- const r_anims = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"get_animations\"}");
- switch (r_anims) {
- .action => |act| try std.testing.expectEqual(protocol.Action.get_animations, act),
- else => return error.TestFailed,
- }
-
- const r_reset = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"reset_panel_stats\"}");
- switch (r_reset) {
- .action => |act| try std.testing.expectEqual(protocol.Action.reset_panel_stats, act),
- else => return error.TestFailed,
- }
-
- const r_pinch = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"pinch\",\"params\":{\"phase\":\"begin\",\"scale\":1.2,\"fingers\":2}}");
- switch (r_pinch) {
- .action => |act| switch (act) {
- .pinch => |p| {
- try std.testing.expectEqual(protocol.GesturePhase.begin, p.phase);
- try std.testing.expectApproxEqAbs(@as(f64, 1.2), p.scale, 1e-9);
- try std.testing.expectEqual(@as(u32, 2), p.fingers);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_swipe = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"swipe\",\"params\":{\"phase\":\"update\",\"dx\":12,\"dy\":-4}}");
- switch (r_swipe) {
- .action => |act| switch (act) {
- .swipe => |p| {
- try std.testing.expectEqual(protocol.GesturePhase.update, p.phase);
- try std.testing.expectApproxEqAbs(@as(f64, 12), p.dx, 1e-9);
- try std.testing.expectApproxEqAbs(@as(f64, -4), p.dy, 1e-9);
- },
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_time = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_anim_time\",\"params\":{\"ms\":110}}");
- switch (r_time) {
- .action => |act| switch (act) {
- .set_anim_time => |p| try std.testing.expectEqual(@as(?i64, 110), p.ms),
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_clear = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"set_anim_time\",\"params\":{\"ms\":null}}");
- switch (r_clear) {
- .action => |act| switch (act) {
- .set_anim_time => |p| try std.testing.expectEqual(@as(?i64, null), p.ms),
- else => return error.TestFailed,
- },
- else => return error.TestFailed,
- }
-
- const r_open = try protocol.parseRequest(allocator, "{\"version\":1,\"command\":\"open_start_menu\"}");
- switch (r_open) {
- .action => |act| try std.testing.expectEqual(protocol.Action.open_start_menu, act),
- else => return error.TestFailed,
- }
-}
-
-test "stringify audio state response" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const streams = [_]protocol.SinkInputData{
- .{ .index = 5, .name = "Firefox", .app_id = "org.mozilla.firefox", .pid = 1234, .volume = 0.8, .muted = false },
- };
- const resp = protocol.Response{ .ok = .{ .audio_state = .{
- .master_volume = 0.6,
- .master_muted = false,
- .default_sink = "Built-in Audio",
- .streams = &streams,
- } } };
- try protocol.stringifyResponse(resp, bw);
-
- const expected = "{\"Ok\":{\"AudioState\":{\"master_volume\":0.6,\"master_muted\":false,\"default_sink\":\"Built-in Audio\",\"streams\":[{\"index\":5,\"name\":\"Firefox\",\"app_id\":\"org.mozilla.firefox\",\"pid\":1234,\"volume\":0.8,\"muted\":false}]}}}\n";
- try std.testing.expectEqualSlices(u8, expected, list.items);
-}
-
-test "stringify performance stats includes edge sample counters" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const resp = protocol.Response{ .ok = .{ .performance_stats = .{
- .output_commits = 3,
- .output_failed_commits = 1,
- .titlebar_paints = 4,
- .footer_paints = 2,
- .edge_samples_attempted = 5,
- .edge_samples_succeeded = 4,
- .edge_samples_skipped = 9,
- .edge_sample_ns = 1234,
- .panel_paints = 0,
- .panel_allocated_bytes = 0,
- .panel_reused_bytes = 0,
- .icon_cache_hits = 0,
- .icon_cache_misses = 0,
- .icon_decode_ns = 0,
- .icon_decode_count = 0,
- .icon_decoded_bytes = 0,
- .icon_queue_depth_max = 0,
- .taskbar_paints = 1,
- .taskbar_paint_ns = 500,
- .taskbar_raster_pixels = 640,
- .taskbar_clock_frame_requests = 2,
- .taskbar_clock_paints = 1,
- .taskbar_start_paints = 0,
- .taskbar_chip_paints = 1,
- .taskbar_tray_paints = 0,
- .taskbar_hover_paints = 0,
- .taskbar_press_paints = 0,
- .taskbar_audio_paints = 0,
- .recent_errors_count = 0,
- } } };
- try protocol.stringifyResponse(resp, bw);
-
- const expected = "{\"Ok\":{\"PerformanceStats\":{\"output_commits\":3,\"output_failed_commits\":1,\"fps\":0.0,\"frame_time_ms\":0.0,\"missed_frames\":0,\"refresh_hz\":0.0,\"titlebar_paints\":4,\"footer_paints\":2,\"edge_samples_attempted\":5,\"edge_samples_succeeded\":4,\"edge_samples_skipped\":9,\"edge_sample_ns\":1234,\"panel_paints\":0,\"panel_allocated_bytes\":0,\"panel_reused_bytes\":0,\"icon_cache_hits\":0,\"icon_cache_misses\":0,\"icon_decode_ns\":0,\"icon_decode_count\":0,\"icon_decoded_bytes\":0,\"icon_queue_depth_max\":0,\"taskbar_paints\":1,\"taskbar_paint_ns\":500,\"taskbar_raster_pixels\":640,\"taskbar_clock_frame_requests\":2,\"taskbar_clock_paints\":1,\"taskbar_start_paints\":0,\"taskbar_chip_paints\":1,\"taskbar_tray_paints\":0,\"taskbar_hover_paints\":0,\"taskbar_press_paints\":0,\"taskbar_audio_paints\":0,\"recent_errors_count\":0,\"anim_frames_scheduled\":0,\"anim_wasted_wakeups\":0,\"anim_longest_ms\":0,\"anim_speed\":1,\"anim_enabled\":true,\"anim_reduced_motion\":false}}}\n";
- try std.testing.expectEqualSlices(u8, expected, list.items);
-
- // Live producers add work timings; preserve the legacy fixture above.
- var extended = resp;
- extended.ok.performance_stats.screenshot_selection = .{ .motion_events = 500, .updates = 2, .toolbar_paints = 1, .scene_nodes_created = 19 };
- extended.ok.performance_stats.frame_work = .{
- .cpu_frame = .{ .samples = 3, .total_samples = 3, .avg_ms = 3, .p50_ms = 3, .p95_ms = 5, .p99_ms = 5, .max_ms = 5 },
- };
- list.clearRetainingCapacity();
- try protocol.stringifyResponse(extended, bw);
- const parsed = try std.json.parseFromSlice(std.json.Value, allocator, list.items, .{});
- defer parsed.deinit();
- const selection = parsed.value.object.get("Ok").?.object.get("PerformanceStats").?.object.get("screenshot_selection").?;
- try std.testing.expectEqual(@as(i64, 500), selection.object.get("motion_events").?.integer);
- try std.testing.expectEqual(@as(i64, 2), selection.object.get("updates").?.integer);
- const work = parsed.value.object.get("Ok").?.object.get("PerformanceStats").?.object.get("frame_work").?;
- try std.testing.expectEqual(@as(i64, 3), work.object.get("cpu_frame").?.object.get("samples").?.integer);
- try std.testing.expect(!work.object.get("gpu_timing_available").?.bool);
- try std.testing.expectEqual(@as(i64, 0), work.object.get("gpu_elapsed").?.object.get("samples").?.integer);
-}
-
-test "stringify panel stats response" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const resp = protocol.Response{ .ok = .{ .panel_stats = .{
- .paints = 1,
- .allocated_bytes = 4096,
- .reused_bytes = 2048,
- .paint_ns = 12345,
- } } };
- try protocol.stringifyResponse(resp, bw);
-
- const expected = "{\"Ok\":{\"PanelStats\":{\"paints\":1,\"allocated_bytes\":4096,\"reused_bytes\":2048,\"paint_ns\":12345}}}\n";
- try std.testing.expectEqualSlices(u8, expected, list.items);
-}
-
-test "stringify animations response" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const items = [_]protocol.AnimationData{
- .{ .site = "start_menu.slide", .value = 0.5, .velocity = 1.25, .target = 1, .settled = false, .curve = "spring" },
- };
- const resp = protocol.Response{ .ok = .{ .animations = &items } };
- try protocol.stringifyResponse(resp, bw);
-
- const expected = "{\"Ok\":{\"Animations\":[{\"site\":\"start_menu.slide\",\"value\":0.5,\"velocity\":1.25,\"target\":1,\"settled\":false,\"curve\":\"spring\"}]}}\n";
- try std.testing.expectEqualSlices(u8, expected, list.items);
+test {
+ _ = @import("ipc/protocol_parse_tests.zig");
}
test "zoom IPC accepts only supported levels" {
@@ -692,36 +187,6 @@ test "parse wait and targeted actions" {
allocator.free(req_ps.action.wait_for.condition.panel_settled.panel);
}
-test "stringify WidgetChanged event" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const ev = protocol.Event{
- .widget_changed = .{
- .seq = 10,
- .time_ms = 1000,
- .session_id = "test-session",
- .panel = "control_center",
- .path = "control_center/wifi",
- .name = "wifi",
- .widget = .{
- .id = 1,
- .role = "toggle",
- .name = "wifi",
- .path = "control_center/wifi",
- .box = .{ .x = 10, .y = 20, .width = 30, .height = 40 },
- .on = true,
- },
- },
- };
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- try protocol.stringifyEvent(ev, bw);
- try std.testing.expect(std.mem.indexOf(u8, list.items, "\"WidgetChanged\"") != null);
- try std.testing.expect(std.mem.indexOf(u8, list.items, "\"control_center/wifi\"") != null);
- try std.testing.expect(std.mem.indexOf(u8, list.items, "\"on\":true") != null);
-}
-
test "parse state and inspection queries" {
const allocator = std.testing.allocator;
@@ -745,22 +210,6 @@ test "parse state and inspection queries" {
try std.testing.expectEqual(protocol.Request.get_runtime_info, r_runtime);
}
-test "stringify response with id envelope" {
- const allocator = std.testing.allocator;
- var list = std.ArrayList(u8).empty;
- defer list.deinit(allocator);
-
- const bw = protocol.BufferWriter{ .list = &list, .allocator = allocator };
- const resp = protocol.Response{ .ok = .handled };
-
- try protocol.stringifyResponseWithId(.{ .integer = 42 }, resp, bw);
- try std.testing.expectEqualSlices(u8, "{\"id\":42,\"Ok\":\"Handled\"}\n", list.items);
-
- list.clearRetainingCapacity();
- try protocol.stringifyResponseWithId(.{ .string = "query-1" }, resp, bw);
- try std.testing.expectEqualSlices(u8, "{\"id\":\"query-1\",\"Ok\":\"Handled\"}\n", list.items);
-}
-
test "v1 commands with params and invalid IDs" {
const allocator = std.testing.allocator;
@@ -813,50 +262,6 @@ test "IPC registry covers public variants and all routes" {
}
}
-fn expectJsonEqual(expected: std.json.Value, actual: std.json.Value) !void {
- if (expected == .integer and actual == .float) return std.testing.expectEqual(@as(f64, @floatFromInt(expected.integer)), actual.float);
- if (expected == .float and actual == .integer) return std.testing.expectEqual(expected.float, @as(f64, @floatFromInt(actual.integer)));
- try std.testing.expectEqual(std.meta.activeTag(expected), std.meta.activeTag(actual));
- switch (expected) {
- .object => |obj| {
- try std.testing.expectEqual(obj.count(), actual.object.count());
- var it = obj.iterator();
- while (it.next()) |entry| try expectJsonEqual(entry.value_ptr.*, actual.object.get(entry.key_ptr.*) orelse return error.TestUnexpectedResult);
- },
- .array => |arr| {
- try std.testing.expectEqual(arr.items.len, actual.array.items.len);
- for (arr.items, actual.array.items) |a, b| try expectJsonEqual(a, b);
- },
- .string, .number_string => |s| try std.testing.expectEqualStrings(s, if (actual == .string) actual.string else actual.number_string),
- .integer => |i| try std.testing.expectEqual(i, actual.integer),
- .float => |f| try std.testing.expectEqual(f, actual.float),
- .bool => |b| try std.testing.expectEqual(b, actual.bool),
- .null => {},
- }
-}
-
-test "response serializers preserve baseline fields rounding and omissions" {
- @setEvalBranchQuota(200_000);
- const fixtures = @import("ipc_serializer_fixtures.zig");
- var lines = std.mem.splitScalar(u8, @embedFile("ipc_serializers.jsonl"), '\n');
- inline for (std.meta.fields(protocol.ResponsePayload)) |field| {
- inline for (.{ false, true }) |populated| {
- var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer arena.deinit();
- const a = arena.allocator();
- const payload = @unionInit(protocol.ResponsePayload, field.name, fixtures.sample(field.type, populated));
- var list: std.ArrayList(u8) = .empty;
- try protocol.stringifyResponse(.{ .ok = payload }, protocol.BufferWriter{ .list = &list, .allocator = a });
- const actual = try std.json.parseFromSlice(std.json.Value, a, list.items, .{});
- const expected = try std.json.parseFromSlice(std.json.Value, a, lines.next().?, .{});
- expectJsonEqual(expected.value, actual.value) catch |err| {
- std.debug.print("serializer {s}, populated={}\n", .{ field.name, populated });
- return err;
- };
- }
- }
-}
-
fn requestCommandName(request: protocol.Request) []const u8 {
return switch (request) {
.action => |action| @tagName(action),