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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
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.background_work_start()
events.turn_end()
events.agent_submission()
events.background_work_end()
events.assistant_text()
events.turn_end()
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()
events.turn_end()
assert(#reports == 12)
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 working --seq 100000005 --message background")
assert(table.concat(reports[6].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state working --seq 100000006 --message thinking")
assert(table.concat(reports[8].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 100000008")
assert(table.concat(reports[9].args, " ") == "pane release-agent w1:p1 --source panto:extension --agent panto --seq 100000009")
assert(table.concat(reports[10].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 101000001")
assert(table.concat(reports[11].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state working --seq 101000002 --message responding")
assert(table.concat(reports[12].args, " ") == "pane report-agent w1:p1 --source panto:extension --agent panto --state idle --seq 101000003")
print("panto-herdr self-check: ok")
|