From 6c0e9c5a6b6d4b0aa77f084fdac5eb4f6d1f482b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 02:37:39 -0300 Subject: A ThemeFile that fails to load changes nothing: /ctl and DumpConfig keep naming the file last loaded, or none, so they always replay The request's path was taken as the theme file before the host had read it, so a file not found or not ZON left /ctl saying ThemeFile , and writing the report back failed again. The path a load succeeds with is now kept apart; a failure puts the request back to it (and watches it again), or to none. Co-Authored-By: Claude Opus 5.5 --- src/ninep/ctl.zig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/ninep/ctl.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index a4979f7d..e963da3f 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2034,6 +2034,32 @@ test "DumpConfig's whole report writes back to the root ctl, line by line, with } } +test "a ThemeFile that fails to load changes nothing: the root ctl still names the one loaded, or none" { + if (comptime !pardes.hosted) return; + const gpa = testing.allocator; + const p = try withFile(gpa, "x\n"); + defer p.deinit(); + const root_ctl = @intFromEnum(tree.TopFile.ctl); + // None loaded: a failed one leaves Theme as it was. + _ = wr(p, root_ctl, "ThemeFile /tmp/pardes-no-such-theme.zon\n"); + pardes.colors.failThemeFile(p, p.theme_file_generation, error.FileNotFound); + try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "ThemeFile") == null); + try testing.expectEqualStrings("", p.theme_file_path.get()); + // One loaded, then another that fails: still the first, on every read. + const good = "/tmp/pardes-good-theme.zon"; + _ = wr(p, root_ctl, "ThemeFile " ++ good ++ "\n"); + var custom = pardes.themes[0]; + custom.name = "good"; + var encoded: std.Io.Writer.Allocating = .init(gpa); + defer encoded.deinit(); + try std.zon.stringify.serialize(custom, .{}, &encoded.writer); + try testing.expect(pardes.colors.loadThemeFile(p, p.theme_file_generation, encoded.written(), false)); + _ = wr(p, root_ctl, "ThemeFile /tmp/pardes-bad-theme.zon\n"); + try testing.expect(!pardes.colors.loadThemeFile(p, p.theme_file_generation, ".{ .name = ", false)); + try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "ThemeFile " ++ good ++ "\n") != null); + try testing.expectEqualStrings(good, p.theme_file_path.get()); +} + test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path, which writes back" { if (comptime !pardes.hosted) return; const gpa = testing.allocator; -- cgit v1.3