summaryrefslogtreecommitdiff
path: root/_selfcheck.lua
blob: 8b83fa513dcc2e912929f7b455bb5ee81a7eab2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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.preload.panto = function()
   return {
      ext = {
         on = function(name, handler) events[name] = handler end,
      },
   }
end

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
os.getenv = function(name)
   if name == "HERDR_PANE_ID" then return "w1:p1" end
   return getenv(name)
end

local entry = require("panto-herdr")
entry.activate()
events.session_start()
events.user_message()
events.user_message()
events.tool_details({ tool_name = "read" })
events.assistant_text()
events.assistant_text_complete()

assert(#reports == 5)
assert(reports[1].command == "herdr")
assert(table.concat(reports[1].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 1")
assert(table.concat(reports[3].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state working --seq 3 --custom-status tool:read")
assert(table.concat(reports[5].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 5")

print("panto-herdr self-check: ok")