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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
-- macOS: run with `panto lua check.lua`. Use the same Panto binary for the TUI and fake agy.
local uv, json = require('luv'), require('panto').ext.json
local panto = assert(uv.fs_realpath(uv.exepath()))
local root = assert(uv.fs_realpath(arg[0])):match('^(.*)/')
local function write(path, data)
local f = assert(io.open(path, 'wb')); assert(f:write(data)); assert(f:close())
end
local function read(path)
local f = assert(io.open(path, 'rb')); local data = assert(f:read('a')); f:close(); return data
end
local function run(bin, args, opts, timeout)
opts = opts or {}; opts.args = args; opts.stdio = opts.stdio or {0, 1, 2}
local proc, timer, code, signal, expired
proc = assert(uv.spawn(bin, opts, function(c, s)
code, signal = c, s; proc:close(); if timer then timer:close() end
end))
if timeout then
timer = assert(uv.new_timer()); timer:start(timeout, 0, function() expired = true; proc:kill('sigkill') end)
end
uv.run(); assert(not expired and signal == 0, bin .. ' timed out or was killed'); return code
end
local home = assert(uv.fs_mkdtemp('/private/tmp/panto-agy-XXXXXX'))
local function check()
local usage=dofile(root..'/acp.lua').usage
local u={inputTokens=155,outputTokens=41,thoughtTokens=8,cachedReadTokens=55,cachedWriteTokens=10,totalTokens=196}
local v=usage(u); assert(v.input==90 and v.output==41 and v.cache_read==55 and v.cache_write==10 and v.reasoning==8)
u.totalTokens=261; assert(usage(u).input==155); u.totalTokens=99; assert(not usage(u) and not usage({}) and not usage(nil))
local catalog=dofile(root..'/catalog.lua').catalog
local req={tools={{name='std.read',description='Read',input_schema_json='{"type":"object"}'},
{name='fixture.echo',description='Echo',input_schema_json='{"type":"object"}'}}}
local _,none=catalog(req,{}); assert(#none==0)
local by,one=catalog(req,{'std.read'}); assert(#one==1 and by.std__read and not by.fixture__echo)
local cfg, data = home .. '/.panto', home .. '/.local/share/panto'
assert(run('/bin/mkdir', {'-p', cfg .. '/extensions', data}) == 0)
assert(run('/bin/cp', {'-cR', assert(os.getenv('HOME')) .. '/.local/share/panto/rocks', data .. '/rocks'}) == 0)
local source = 'paths=[' .. json.encode(root .. '/extensions') .. ']'
if os.getenv('PANTO_CHECK_ROCK') == '1' then
assert(run('luarocks', {'--lua-version','5.4','--tree',data .. '/rocks/lua-5.4.7','make','--deps-mode=none','panto-antigravity-scm-1.rockspec'}, {cwd=root}) == 0)
source = 'rocks=["panto-antigravity"]'
end
write(cfg .. '/config.toml', '[extensions]\n' .. source .. [[
[providers.antigravity]
protocol="antigravity-acp"
save_session=true
]])
write(cfg .. '/models.toml', '[antigravity.fast]\nmodel="gemini-test"\ninput=10.0\noutput=10.0\ncache_read=1.0\ncache_write=10.0\n')
write(cfg .. '/SYSTEM.md', 'Short answers.')
local exe = home .. '/agy'
assert(uv.fs_symlink(panto, home .. '/panto')) -- short, space-free shebang path
write(exe, '#!' .. home .. '/panto lua\n' .. read(root .. '/tests/fake-agy.lua'))
assert(uv.fs_chmod(exe, 448))
write(cfg .. '/extensions/signature.lua', [[
local uv = require('luv'); local spawn = uv.spawn
uv.spawn = function(bin, opts, cb)
if bin == '/usr/bin/codesign' and opts.args[4] == os.getenv('HOME') .. '/agy' then
bin, opts = '/usr/bin/true', {args={}}
end
return spawn(bin, opts, cb)
end
return {name='test.signature', activate=function()
local ext=require('panto').ext
ext.on('render_thinking_complete',function(e)
if e.text=='fixture-visible-thinking' then local f=assert(io.open(os.getenv('HOME')..'/thinking-rendered','w')); f:close() end
end)
ext.register_command{name='fixture-notice',description='Queue a workflow completion',handler=function()
ext.agent:submit('[subagents] Workflow fixture completed. Output below: marker')
end}
ext.register_tool{name='fixture.echo',description='Return a nested value.',
schema={type='object',properties={rows={type='array',minItems=1,items={type='object',properties={value={type='integer'}},required={'value'}}}},required={'rows'}},
handler=function(input)
local profile=os.getenv('HOME')..'/.local/share/panto-antigravity/google'
if input.rows[1].value==43 then
local f=assert(io.open(profile..'/tool-running','w')); f:close()
local co=coroutine.running(); local timer=uv.new_timer()
timer:start(10,10,function()
if uv.fs_stat(profile..'/return-result') then timer:close(); assert(coroutine.resume(co)) end
end)
coroutine.yield()
elseif not uv.fs_stat(profile..'/usage-failure') then ext.agent:submit('boundary workflow notice') end
return tostring(input.rows[1].value)
end}
end}
]])
local env = {'HOME=' .. home, 'QUOTA_LOG=' .. home .. '/screen', 'TMPDIR=' .. home,
'TERM=xterm-256color', 'PATH=' .. home .. ':/usr/bin:/bin', 'PANTO=' .. panto}
local profile = [[(version 1)(allow default)
(deny network-outbound (remote ip "*:*"))(deny network-bind (local ip "*:*"))
(deny process-exec)(allow process-exec (literal (param "PANTO")) (literal (param "FAKE"))
(literal "/usr/bin/true") (literal "/usr/bin/false") (literal "/usr/bin/nc")
(literal "/usr/bin/expect") (literal "/bin/stty"))]]
local function sandbox(args, timeout, stdio)
local cmd = {'-D', 'PANTO=' .. panto, '-D', 'FAKE=' .. exe, '-p', profile}
for _, a in ipairs(args) do cmd[#cmd+1] = a end
return run('/usr/bin/sandbox-exec', cmd, {cwd=home, env=env, stdio=stdio}, timeout)
end
local log = home .. '/headless.stderr'
local fd = assert(uv.fs_open(log, 'w', 384))
local code = sandbox({panto, '--incognito', '-p', '-m', 'antigravity:fast', '--', 'hello'}, 10000, {nil, 1, fd})
uv.fs_close(fd)
local google = home .. '/.local/share/panto-antigravity/google'
local stderr = read(log)
assert(code ~= 0 and stderr:find('ProviderProtocolFailed', 1, true) and not uv.fs_stat(google), stderr)
local tui=sandbox({'/usr/bin/expect', root .. '/tests/tui.exp'}, 65000)
if tui~=0 then error('TUI check failed: '..read(home..'/screen'):gsub('\27%[[0-9;?]*[A-Za-z]', ''):sub(-3500)) end
assert(uv.fs_stat(home..'/thinking-rendered'),'ACP thought did not reach the native thinking component')
local agents = assert(uv.fs_scandir(google .. '/config/agents')); assert(not uv.fs_scandir_next(agents), 'Generated agent left in private profile')
local screen = read(home .. '/screen'):gsub('\27%[[0-9;?]*[A-Za-z]', '')
assert(screen:find('1.3k/1M ctx',1,true),'expected ACP context occupancy, not summed turn inputs')
assert(screen:find('3.4k tok',1,true),'expected primary and steering usage counted exactly once')
assert(screen:find('agy native: manage_task [completed]',1,true) and not screen:find('agy native: mcp_pantograph_',1,true),'native activity missing or MCP call duplicated')
assert(screen:find('27%%%s+━'), 'expected 27% used and a filled bar in the rendered footer')
end
local ok, err = xpcall(check, debug.traceback)
assert(run('/bin/rm', {'-rf', home}) == 0)
assert(ok, err)
print('PASS: headless denial, native TUI, quota meter, model alias, primary MCP tool, permissions, native resume, /tree transcript seed, warm follow-up and cold resume')
|