diff options
| author | t <t@tjp.lol> | 2026-11-27 08:46:14 -0700 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-11-30 08:34:38 -0700 |
| commit | 47039f21a170e29875a2676f7a2eb5a779144b74 (patch) | |
| tree | 495ffa7dab8de455a8d2ebfafd45dfcce5da52b7 /check.lua | |
Add Antigravity ACP provider for Panto
Diffstat (limited to 'check.lua')
| -rw-r--r-- | check.lua | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/check.lua b/check.lua new file mode 100644 index 0000000..97e22ad --- /dev/null +++ b/check.lua @@ -0,0 +1,94 @@ +-- 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 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"\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={}} + elseif bin == '/usr/bin/osascript' then bin, opts = '/usr/bin/false', {args={}} end + return spawn(bin, opts, cb) +end +return {name='test.signature', activate=function() + require('panto').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) 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) + -- Fake agy also runs `panto lua`, but under the isolated Google HOME. Reuse + -- the staged rocks there so the interpreter never needs a first-run install. + assert(run('/bin/mkdir', {'-p', '-m', '700', google}) == 0) + assert(run('/bin/mkdir', {'-p', google .. '/.local/share/panto'}) == 0) + assert(uv.fs_symlink(data .. '/rocks', google .. '/.local/share/panto/rocks')) + assert(sandbox({'/usr/bin/expect', root .. '/tests/tui.exp'}, 45000) == 0, 'TUI check failed') + local screen = read(home .. '/screen'):gsub('\27%[[0-9;?]*[A-Za-z]', '') + 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, follow-up and saved resume') |
