diff options
Diffstat (limited to 'check.lua')
| -rw-r--r-- | check.lua | 66 |
1 files changed, 56 insertions, 10 deletions
@@ -1,7 +1,15 @@ --- macOS: run with `panto lua check.lua`. Use the same Panto binary for the TUI and fake agy. +-- 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 sysname = uv.os_uname().sysname +local is_macos = sysname == 'Darwin' local panto = assert(uv.fs_realpath(uv.exepath())) local root = assert(uv.fs_realpath(arg[0])):match('^(.*)/') +local function which(name) + for dir in (os.getenv('PATH') or '/usr/local/bin:/usr/bin:/bin'):gmatch('[^:]+') do + local p = dir .. '/' .. name + if dir:sub(1, 1) == '/' and uv.fs_access(p, 'X') then return assert(uv.fs_realpath(p)) end + end +end local function write(path, data) local f = assert(io.open(path, 'wb')); assert(f:write(data)); assert(f:close()) end @@ -19,7 +27,9 @@ local function run(bin, args, opts, timeout) 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 tmp = assert(uv.fs_realpath(uv.os_tmpdir() or '/tmp')):gsub('/+$', '') +if #tmp > 80 then tmp = assert(uv.fs_realpath('/tmp')):gsub('/+$', '') end +local home = assert(uv.fs_mkdtemp(tmp .. '/panto-agy-XXXXXX')) local function check() dofile(root..'/tests/lifecycle.lua') local acp_mod=dofile(root..'/acp.lua'); local usage=acp_mod.usage @@ -45,9 +55,34 @@ local function check() local by,one=catalog(req,{'not.offered','std.read'}); assert(#one==1 and one[1].name=='std__read' and by.std__read and not by.fixture__echo) local configure=dofile(root..'/extensions/antigravity-acp.lua').configure assert(not pcall(configure,{providers={antigravity={protocol='antigravity-acp',save_session=true}}})) + -- Exercise the non-macOS probe path (no codesign, binary mode check, keyring env forwarding). + local linux_home = assert(uv.fs_mkdtemp(home .. '/linux-XXXXXX')) + local linux_bin = linux_home .. '/agy'; write(linux_bin, '#!/bin/sh\n'); assert(uv.fs_chmod(linux_bin, 448)) + local real_uname, real_getenv = uv.os_uname, os.getenv + local fake_env = {HOME=linux_home, PATH=linux_home, DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/1/bus', + XDG_RUNTIME_DIR='/run/user/1', GEMINI_API_KEY='secret'} + uv.os_uname = function() return {sysname='Linux'} end + os.getenv = function(k) return fake_env[k] end + local ok_linux, err_linux = pcall(function() + local linux_acp = dofile(root..'/acp.lua') + local got_bin, got_env, got_err + linux_acp.probe(function(b, _, e) got_bin, got_env = b, e end, function(e) got_err = e end) + assert(not got_err and got_bin == linux_bin, got_err) + local joined = '\n' .. table.concat(got_env, '\n') .. '\n' + assert(joined:find('\nDBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1/bus\n', 1, true) + and joined:find('\nXDG_RUNTIME_DIR=/run/user/1\n', 1, true) + and not joined:find('GEMINI_API_KEY', 1, true), 'bad Linux probe env') + assert(uv.fs_chmod(linux_bin, 464)) -- 0720 group-writable must be rejected + got_bin, got_err = nil, nil + linux_acp.probe(function(b) got_bin = b end, function(e) got_err = e end) + assert(not got_bin and got_err and got_err:find('group/world writable', 1, true), 'writable binary allowed') + end) + uv.os_uname, os.getenv = real_uname, real_getenv + assert(ok_linux, err_linux) 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 rocks = assert(os.getenv('HOME')) .. '/.local/share/panto/rocks' + if uv.fs_stat(rocks) then assert(run('/bin/cp', {'-R', rocks, data .. '/rocks'}) == 0) end 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'}, {cwd=root}) == 0) @@ -100,17 +135,28 @@ return {name='test.signature', activate=function() end} end} ]]) + local expect_bin = assert(which('expect'), 'expect is required for TUI check') local env = {'HOME=' .. home, 'QUOTA_LOG=' .. home .. '/screen', 'TMPDIR=' .. home, - 'TERM=xterm-256color', 'PATH=' .. home .. ':/usr/bin:/bin', 'PANTO=' .. panto} + 'TERM=xterm-256color', 'PATH=' .. home .. ':/usr/local/bin:/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"))]] +(literal "/usr/bin/true") (literal "/usr/bin/false") +(literal (param "EXPECT")) (literal "/bin/stty"))]] + local unshare = sysname == 'Linux' and which('unshare') + if unshare and run(unshare, {'-c', '-n', '--', '/bin/true'}, {stdio={nil, nil, nil}}) ~= 0 then unshare = nil end 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) + if is_macos then + local cmd = {'-D', 'PANTO=' .. panto, '-D', 'FAKE=' .. exe, '-D', 'EXPECT=' .. expect_bin, '-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) + elseif unshare then + local cmd = {'-c', '-n', '--'} + for _, a in ipairs(args) do cmd[#cmd+1] = a end + return run(unshare, cmd, {cwd=home, env=env, stdio=stdio}, timeout) + end + local cmd = {}; for i = 2, #args do cmd[#cmd+1] = args[i] end + return run(args[1], cmd, {cwd=home, env=env, stdio=stdio}, timeout) end local google = home .. '/.local/share/panto-antigravity/google' local function print_check(mode, args, input, diagnostic) @@ -137,7 +183,7 @@ end} assert(uv.fs_unlink(cfg..'/PROMPT.md')) print_check('diagnostic', {'--','diagnostic'}, '', true) assert(uv.fs_unlink(home..'/fixture-mode')) - local tui=sandbox({'/usr/bin/expect', root .. '/tests/tui.exp'}, 65000) + local tui=sandbox({expect_bin, 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') |
