summaryrefslogtreecommitdiff
path: root/src/lua_runtime.zig
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-06-23 09:38:23 -0600
committert <t@tjp.lol>2026-06-23 10:53:26 -0600
commit69a1ee138bb78ad4663fe2d9e58678f7b0d07b74 (patch)
tree453d3ad42a07536220e6ca5d91b439ff57793e32 /src/lua_runtime.zig
parent538a5d926fa626a00cc3dc12c555f11f82867efd (diff)
ponytail simplifications to panto cli and lua extensiosn
Diffstat (limited to 'src/lua_runtime.zig')
-rw-r--r--src/lua_runtime.zig53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/lua_runtime.zig b/src/lua_runtime.zig
index 35247bb..56ce0db 100644
--- a/src/lua_runtime.zig
+++ b/src/lua_runtime.zig
@@ -30,6 +30,7 @@ const Allocator = std.mem.Allocator;
const panto = @import("panto");
const lua_bridge = @import("lua_bridge.zig");
const lua_event_bridge = @import("lua_event_bridge.zig");
+const panto_home = @import("panto_home.zig");
const ui_event = @import("tui_event.zig");
const c = lua_bridge.c;
@@ -1630,18 +1631,24 @@ test "yielding handler with no event loop surfaces LuaHandlerYielded" {
try testing.expect(std.mem.indexOf(u8, okText(results[0]), "LuaHandlerYielded") != null);
}
-// Integration test: requires a `$PANTO_HOME` with luv already
-// installed. Skipped if luv isn't on disk — unit tests stay offline.
+// Integration test: requires a data home with luv already installed.
+// Skipped if luv isn't on disk — unit tests stay offline.
test "scheduler: yielding handler is resumed by libuv" {
- const home_z = std.c.getenv("PANTO_HOME") orelse return error.SkipZigTest;
- const panto_home_env = std.mem.sliceTo(home_z, 0);
+ var env = try processDataHomeEnv(testing.allocator);
+ defer env.deinit();
+ const data_home = panto_home.homePath(testing.allocator, &env) catch |err| switch (err) {
+ error.NoHomeDirectory => return error.SkipZigTest,
+ else => return err,
+ };
+ defer testing.allocator.free(data_home);
+
// Check for `<home>/rocks/lua-<version>/lib/lua/5.4/luv.so`.
const manifest = @import("manifest.zig");
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
const so_path = try std.fmt.bufPrint(
&path_buf,
"{s}/rocks/lua-{s}/lib/lua/{s}/luv.so",
- .{ panto_home_env, manifest.lua_version, manifest.lua_short_version },
+ .{ data_home, manifest.lua_version, manifest.lua_short_version },
);
std.Io.Dir.cwd().access(testing.io, so_path, .{}) catch return error.SkipZigTest;
@@ -1673,12 +1680,7 @@ test "scheduler: yielding handler is resumed by libuv" {
defer rt.deinit();
// Bootstrap luarocks (so `require("luv")` works), then install
- // the scheduler. We use the real environment so the test picks
- // up the same PANTO_HOME the developer's machine has.
- var env: std.process.Environ.Map = .init(testing.allocator);
- defer env.deinit();
- try env.put("PANTO_HOME", panto_home_env);
-
+ // the scheduler from the normal data-home location.
const luarocks_runtime = @import("luarocks_runtime.zig");
// The bootstrap needs a panto executable path for the wrapper
// script; tests don't actually invoke it, so a placeholder is
@@ -1777,20 +1779,23 @@ fn findAgentToolsDir() ![]const u8 {
}
fn bootstrapRealRuntime(rt: *LuaRuntime) !*@import("luarocks_runtime.zig").LuarocksRuntime {
- const home_z = std.c.getenv("PANTO_HOME") orelse return error.SkipZigTest;
- const panto_home_env = std.mem.sliceTo(home_z, 0);
+ var env = try processDataHomeEnv(testing.allocator);
+ errdefer env.deinit();
+ const data_home = panto_home.homePath(testing.allocator, &env) catch |err| switch (err) {
+ error.NoHomeDirectory => return error.SkipZigTest,
+ else => return err,
+ };
+ defer testing.allocator.free(data_home);
+
const manifest = @import("manifest.zig");
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
const so_path = try std.fmt.bufPrint(
&path_buf,
"{s}/rocks/lua-{s}/lib/lua/{s}/luv.so",
- .{ panto_home_env, manifest.lua_version, manifest.lua_short_version },
+ .{ data_home, manifest.lua_version, manifest.lua_short_version },
);
std.Io.Dir.cwd().access(testing.io, so_path, .{}) catch return error.SkipZigTest;
- var env: std.process.Environ.Map = .init(testing.allocator);
- defer env.deinit();
- try env.put("PANTO_HOME", panto_home_env);
const luarocks_runtime = @import("luarocks_runtime.zig");
const luarocks_rt = try luarocks_runtime.bootstrap(
testing.allocator,
@@ -1799,10 +1804,24 @@ fn bootstrapRealRuntime(rt: *LuaRuntime) !*@import("luarocks_runtime.zig").Luaro
rt.L,
"/usr/bin/true",
);
+ env.deinit();
try rt.installScheduler();
return luarocks_rt;
}
+fn processDataHomeEnv(allocator: Allocator) !std.process.Environ.Map {
+ var env = std.process.Environ.Map.init(allocator);
+ errdefer env.deinit();
+
+ if (std.c.getenv("XDG_DATA_HOME")) |value| {
+ try env.put("XDG_DATA_HOME", std.mem.sliceTo(value, 0));
+ }
+ if (std.c.getenv("HOME")) |value| {
+ try env.put("HOME", std.mem.sliceTo(value, 0));
+ }
+ return env;
+}
+
// Reproduction: two REAL `std.shell` calls in one batch. shell.lua
// uses spawn + two pipes + a timeout timer (3+ libuv events per call)
// and resumes its own coroutine from a libuv callback. This exercises