local events = {} local reports = {} -- Find the rockspec rather than naming it: the filename carries the version, -- so hardcoding it breaks this check on every release. -- -- Deliberately shells out instead of using luv: the stubs below replace -- `package.preload.luv`, and a `require("luv")` up here would cache the real -- module first and quietly defeat them. local function find_rockspec() local ls = assert(io.popen("ls -1 ./*.rockspec 2>/dev/null")) local name = ls:read("l") ls:close() return name end assert(loadfile(assert(find_rockspec(), "no .rockspec in the repo root"))) package.loaded.panto = nil package.preload.panto = function() return { ext = { on = function(name, handler) events[name] = handler end, }, } end package.loaded.luv = nil package.preload.luv = function() return { spawn = function(command, options, _) reports[#reports + 1] = { command = command, args = options.args } return { close = function() end } end, } end local getenv = os.getenv local now = 100 os.time = function() return now end os.getenv = function(name) if name == "HERDR_PANE_ID" then return "w1:p1" end return getenv(name) end local entry = assert(loadfile("panto-herdr/init.lua"))() entry.activate() events.session_start() events.user_message() events.user_message() events.tool_details({ tool_name = "read" }) events.assistant_text() events.assistant_text_complete() events.session_end() -- A new process in the same pane/source must outrank the old process's final -- sequence number instead of being ignored as stale. now = 101 events = {} entry.activate() events.session_start() events.assistant_text() events.session_ready() assert(#reports == 9) assert(reports[1].command == "herdr") assert(table.concat(reports[1].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 100000001") assert(table.concat(reports[3].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state working --seq 100000003 --message tool:read") assert(table.concat(reports[5].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 100000005") assert(table.concat(reports[6].args, " ") == "pane release-agent w1:p1 --source panto:extension --agent panto --seq 100000006") assert(table.concat(reports[7].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 101000001") assert(table.concat(reports[8].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state working --seq 101000002 --message responding") assert(table.concat(reports[9].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 101000003") print("panto-herdr self-check: ok")