From 2612b305fdf51074c02c4508902d425125d44bbd Mon Sep 17 00:00:00 2001 From: pablopunk Date: Sun, 21 Jun 2026 00:24:15 +0000 Subject: [PATCH] [ai] fix: replace private _state API with public session.process:write(nil) --- lua/pi/runner.lua | 9 +++------ tests/test_pi_commands.lua | 18 ++++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/lua/pi/runner.lua b/lua/pi/runner.lua index 8bcc8cf..1c5e078 100644 --- a/lua/pi/runner.lua +++ b/lua/pi/runner.lua @@ -139,12 +139,9 @@ function M.finish(session) return end - local stdin = session.process._state and session.process._state.stdin - if stdin then - pcall(function() - stdin:close() - end) - elseif not session.process:is_closing() then + local ok, err = pcall(session.process.write, session.process, nil) + if not ok then + -- fallback: kill if write fails (process already dead) pcall(session.process.kill, session.process, 15) end end diff --git a/tests/test_pi_commands.lua b/tests/test_pi_commands.lua index 47b42f5..b125363 100644 --- a/tests/test_pi_commands.lua +++ b/tests/test_pi_commands.lua @@ -66,7 +66,12 @@ local function mock_system() _G.__pi_test_system.on_exit = on_exit return { write = function(_, data) - table.insert(_G.__pi_test_system.writes, data) + if data == nil then + _G.__pi_test_system.stdin_closed = true + _G.__pi_test_system.closing = true + else + table.insert(_G.__pi_test_system.writes, data) + end end, kill = function(_, signal) _G.__pi_test_system.killed = signal @@ -75,17 +80,6 @@ local function mock_system() is_closing = function() return _G.__pi_test_system.closing end, - _state = { - stdin = { - close = function() - _G.__pi_test_system.stdin_closed = true - _G.__pi_test_system.closing = true - end, - flush = function() - -- No-op in tests - end, - }, - }, } end ]])