summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-12-01 16:31:43 -0700
committert <t@tjp.lol>2026-12-04 13:53:47 -0700
commit8c1c5786ebfe8dda40a70571f332e876b184ad4d (patch)
tree1116068ae630c45c1218b17fabb3d253bb8003d9 /tests
parentf7a1e30c1dfbe5fddcbfe38e89a0c5efef9fbeab (diff)
Isolate ACP via custom agent and add steering, usage, reseed, and footer updates
Replace the osascript permission dialog and settings.json permission seed with a per-thread generated custom main agent (excludeDefaultComponents, tools: [], no inherited customizations or MCP) launched with --agent, --include-default-customizations=false, and --dangerously-skip-permissions. Keep HOME unchanged (isolating via --gemini-dir only) so macOS finds the login Keychain, mark exported tools with antigravity/alwaysLoad, and require the relay to serve tools/list before the first prompt. Add ACP turn steering for queued user and workflow text at tool boundaries, preserve agent_thought_chunk thinking blocks with block-aware checkpoint hashing, report live usage_update context snapshots and deduplicated final plus steering token usage, and mount a live above-input native tool activity component for up to six non-MCP ACP calls. Support reseeding a new ACP session from history_transcript after /tree or cold resume, allow direct submissions to take over an idle session from another thread, and let extension follow-ups continue a matching warm session. Update the usage footer with startup and three-minute timer refreshes, 1w/5h labels, per-letter antigravity colors, and expired-bucket handling.
Diffstat (limited to 'tests')
-rw-r--r--tests/fake-agy.lua126
-rw-r--r--tests/tui.exp66
2 files changed, 128 insertions, 64 deletions
diff --git a/tests/fake-agy.lua b/tests/fake-agy.lua
index cd4f460..ae671c3 100644
--- a/tests/fake-agy.lua
+++ b/tests/fake-agy.lua
@@ -1,13 +1,13 @@
-- Offline agy fixture. check.lua installs this with Panto's embedded Lua shebang.
local uv, json = require('luv'), require('panto').ext.json
-local home = assert(os.getenv('HOME'))
+local profile = assert(os.getenv('HOME')) .. '/.local/share/panto-antigravity/google'
if arg[1] == '--version' then error('unexpected version check') end
if arg[1] ~= 'acp' then
assert(json.encode({table.unpack(arg)}) == json.encode({
- '--gemini_dir', home, '--sandbox', '-p', '/usage',
+ '--gemini_dir', profile, '--sandbox', '-p', '/usage',
}), 'unrecognized fake CLI invocation')
- if uv.fs_stat(home .. '/usage-failure') then os.exit(3) end
- assert(uv.cwd() == home and home:match('/google$') and uv.guess_handle(0) ~= 'tty')
+ if uv.fs_stat(profile .. '/usage-failure') then os.exit(3) end
+ assert(uv.cwd() == profile and uv.guess_handle(0) ~= 'tty')
print('Gemini\tWeekly\t73%\t2099-02-03T12:00:00Z'); return
end
@@ -25,10 +25,46 @@ local function prompt(text)
return q
end
local function finish(q, text)
+ if text=='same-session-ok' then
+ send({method='session/update',params={sessionId='test-session',update={sessionUpdate='agent_thought_chunk',content={type='text',text='fixture-visible-thinking'}}}})
+ end
send({method='session/update', params={sessionId='test-session', update={
sessionUpdate='agent_message_chunk', content={type='text', text=text},
}}})
- reply(q, {stopReason='end_turn'})
+ local function update(u) send({method='session/update',params={sessionId='test-session',update=u}}) end
+ update({sessionUpdate='usage_update',used=1330,size=1048576})
+ update({sessionUpdate='tool_call',toolCallId='native-1',name='manage_task',status='in_progress'})
+ update({sessionUpdate='tool_call_update',toolCallId='native-1',status='completed'})
+ if text=='primary-tool-ok' then update({sessionUpdate='tool_call',toolCallId='mcp-1',name='mcp_pantograph_fixture__echo',status='completed'}) end
+ reply(q, {stopReason='end_turn',usage={inputTokens=2166,outputTokens=228,thoughtTokens=117,totalTokens=2394,cachedReadTokens=900}})
+end
+
+local function load_catalog(server)
+ local input, output = assert(uv.pipe()), assert(uv.pipe())
+ local proc = assert(uv.spawn(server.command, {args=server.args, stdio={input.read, output.write, 2}}, function() end))
+ uv.fs_close(input.read); uv.fs_close(output.write)
+ local function rpc(id, method, params)
+ local line = json.encode({jsonrpc='2.0', id=id, method=method, params=params or {}}) .. '\n'
+ assert(uv.fs_write(input.write, line, -1) == #line)
+ local buf = ''
+ repeat
+ local chunk = assert(uv.fs_read(output.read, 4096, -1)); assert(chunk ~= '', 'relay closed'); buf = buf .. chunk
+ until buf:sub(-1) == '\n'
+ local r = json.decode(buf); assert(r.id == id); return r
+ end
+ assert(rpc(1, 'initialize').result.serverInfo.name == 'pantograph')
+ local tools = rpc(2, 'tools/list').result.tools
+ local schemas={}; for _,t in ipairs(tools) do assert(t._meta['antigravity/alwaysLoad']==true); schemas[t.name]=t.inputSchema end
+ assert(schemas.std__read and schemas.std__edit and schemas.fixture__echo.properties.rows.items.required[1]=='value')
+ return function()
+ assert(rpc(3, 'tools/call', {name='not_exported', arguments={}}).error.code == -32602)
+ assert(rpc(5, 'tools/call', {name='fixture__echo', arguments={rows={{value='bad'}}}}).error.code == -32602)
+ local echo=rpc(6, 'tools/call', {name='fixture__echo', arguments={rows={{value=42}}}}).result
+ assert(echo.isError==false and echo.content[1].text=='42')
+ local r = rpc(4, 'tools/call', {name='std__read', arguments={path=uv.cwd() .. '/.panto/SYSTEM.md'}}).result
+ assert(r.isError == false and r.content[1].text:find('Short answers', 1, true))
+ proc:kill('sigkill'); uv.fs_close(input.write); uv.fs_close(output.read); uv.run(); proc:close()
+ end
end
local q = request('initialize')
@@ -38,15 +74,21 @@ reply(q, {protocolVersion=1, authMethods={{id='oauth-personal'}}, agentCapabilit
q = request('authenticate'); assert(json.encode(q.params) == '{"methodId":"oauth-personal"}'); reply(q)
q = read()
local setup, resumed = q.params, q.method == 'session/resume'
-assert(#setup.mcpServers == 1 and setup.mcpServers[1].name=='pantograph' and setup._meta.disableBuiltInTools == true)
-local settings=home..'/antigravity-cli/settings.json'
-local f=assert(io.open(settings,'r')); local policy=json.decode(f:read('a')); f:close()
-if resumed or uv.fs_stat(home..'/usage-failure') then
- assert(policy.permissions.ask[1]=='mcp(pantograph/*)', 'existing settings replaced')
-else
- assert(json.encode(policy)=='{"permissions":{"allow":["mcp(pantograph/*)"]}}', 'missing scoped agy default')
- f=assert(io.open(settings,'w')); assert(f:write('{"permissions":{"ask":["mcp(pantograph/*)"]}}')); assert(f:close())
+assert(setup._meta.disableBuiltInTools == true)
+assert(arg[2]=='--agent' and arg[3]:match('^panto%-%x[%x-]+$') and arg[4]=='--include-default-customizations=false')
+assert(arg[9]=='--dangerously-skip-permissions')
+assert(arg[5]=='--gemini-dir' and arg[6]==profile)
+local af=assert(io.open(profile..'/config/agents/'..arg[3]..'.md')); local agent=af:read('a'); af:close()
+for _,line in ipairs({'name: '..arg[3],'mainAgent: true','subagent: false','excludeDefaultComponents: true','inheritCustomizations: false','inheritMcp: false','tools: []'}) do assert(agent:find('\n'..line..'\n',1,true),line) end
+local servers=json.decode(assert(agent:match('\nmcpServers: ([^\n]+)')))
+if uv.fs_stat(profile..'/no-tools') then assert(#servers==0) else assert(#servers==1 and servers[1].name=='pantograph' and servers[1].command=='/usr/bin/nc') end
+assert(#setup.mcpServers==#servers)
+local server=setup.mcpServers[1]
+if server then
+ assert(server.name==servers[1].name and server.command==servers[1].command and json.encode(server.args)==json.encode(servers[1].args) and json.encode(server.env)=='[]')
end
+local check_relay=server and not uv.fs_stat(profile..'/skip-list') and load_catalog(server)
+assert(not uv.fs_stat(profile..'/antigravity-cli/settings.json'),'extension seeded permission settings')
if resumed then assert(setup.sessionId == 'test-session' and not setup._meta.antigravity)
else assert(q.method == 'session/new' and setup._meta.antigravity.systemPrompt.append:find('Short answers', 1, true)) end
if resumed then -- Older ACP pickers may expose suffixed models instead.
@@ -72,40 +114,36 @@ if not resumed then
set_level('low')
end
-local function check_relay(server)
- local input, output = assert(uv.pipe()), assert(uv.pipe())
- local proc = assert(uv.spawn(server.command, {args=server.args, stdio={input.read, output.write, 2}}, function() end))
- uv.fs_close(input.read); uv.fs_close(output.write)
- local function rpc(id, method, params)
- local line = json.encode({jsonrpc='2.0', id=id, method=method, params=params or {}}) .. '\n'
- assert(uv.fs_write(input.write, line, -1) == #line)
- local buf = ''
- repeat
- local chunk = assert(uv.fs_read(output.read, 4096, -1)); assert(chunk ~= '', 'relay closed'); buf = buf .. chunk
- until buf:sub(-1) == '\n'
- local r = json.decode(buf); assert(r.id == id); return r
+if not servers[1] then finish(prompt('no-tools'),'no-tools-ok')
+elseif resumed then local resumed_prompt=prompt('resume'); check_relay(); finish(resumed_prompt, 'resumed-ok') elseif uv.fs_stat(profile..'/usage-failure') then
+ assert(not resumed)
+ q=request('session/prompt'); local blocks=q.params.prompt; assert(#blocks==1)
+ local text=blocks[1].text
+ assert(text:find('[User]: hello',1,true))
+ assert(not text:find('same-session-ok',1,true) and not text:find('resumed-ok',1,true),'abandoned branch leaked')
+ local current=assert(text:match('Current user request:\n([^\n]+)$'))
+ assert(not text:find('[User]: '..current,1,true),'current prompt duplicated')
+ if current~='boundary workflow notice' then assert(text:find('[Assistant]: primary-tool-ok',1,true)) end
+ if current=='branch-probe' then
+ finish(q,'branch-seed-ok'); finish(prompt('warm-probe'),'warm-after-seed-ok')
+ reply(prompt('cancel-probe'),{stopReason='cancelled'})
+ elseif current=='boundary workflow notice' then
+ assert(text:find('[User]: boundary steer',1,true) and text:find('[Tool result',1,true)); finish(q,'proceed-recovered-ok')
+ else
+ assert(current=='cold-probe' and text:find('[Assistant]: warm-after-seed-ok',1,true)); finish(q,'cold-resume-ok')
end
- assert(rpc(1, 'initialize').result.serverInfo.name == 'pantograph')
- local tools = rpc(2, 'tools/list').result.tools
- local schemas={}; for _,t in ipairs(tools) do schemas[t.name]=t.inputSchema end
- assert(schemas.std__read and schemas.std__edit and schemas.fixture__echo.properties.rows.items.required[1]=='value')
- assert(rpc(3, 'tools/call', {name='not_exported', arguments={}}).error.code == -32602)
- assert(rpc(5, 'tools/call', {name='fixture__echo', arguments={rows={{value='bad'}}}}).error.code == -32602)
- local echo=rpc(6, 'tools/call', {name='fixture__echo', arguments={rows={{value=42}}}}).result
- assert(echo.isError==false and echo.content[1].text=='42')
- local r = rpc(4, 'tools/call', {name='std__read', arguments={path=uv.cwd() .. '/.panto/SYSTEM.md'}}).result
- assert(r.isError == false and r.content[1].text:find('Short answers', 1, true))
- proc:kill('sigkill'); uv.fs_close(input.write); uv.fs_close(output.read); uv.run(); proc:close()
-end
-
-if resumed then finish(prompt('resume'), 'resumed-ok') else
+else
q = prompt('hello')
- send({id='perm', method='session/request_permission', params={sessionId='test-session',
- toolCall={title='Read local file'}, options={{kind='allow_once', optionId='once'}},
- }})
- assert(json.encode(read().result.outcome) == '{"outcome":"cancelled"}')
- check_relay(setup.mcpServers[1]); finish(q, 'primary-tool-ok')
+ send({method='session/update',params={sessionId='test-session',update={sessionUpdate='agent_message_chunk',content={type='text',text='steer-window-open'}}}})
+ while not uv.fs_stat(profile..'/steer-queued') do uv.sleep(10) end
+ send({method='session/update',params={sessionId='test-session',update={sessionUpdate='usage_update',used=8200,size=1048576}}})
+ check_relay()
+ local steer=request('session/prompt'); assert(steer.id~=q.id and steer.params.sessionId=='test-session')
+ local p=steer.params.prompt; assert(#p==2 and p[1].text=='boundary steer' and p[2].text=='boundary workflow notice','steering payload/order')
+ while not uv.fs_stat(profile..'/context-visible') do uv.sleep(10) end -- final usage must not drive the live reading
+ finish(q, 'primary-tool-ok'); reply(steer,{stopReason='end_turn',usage={inputTokens=1000,outputTokens=6,totalTokens=1006}}) -- out of request order also works
set_level('high')
finish(prompt('again'), 'same-session-ok')
+ finish(prompt('[subagents] Workflow fixture completed. Output below: marker'), 'workflow-notice-ok')
end
for _ in io.lines() do end -- keep the session alive until Panto closes stdin
diff --git a/tests/tui.exp b/tests/tui.exp
index 4f79c31..b8cdf4d 100644
--- a/tests/tui.exp
+++ b/tests/tui.exp
@@ -1,44 +1,70 @@
set timeout 12
+set stty_init "rows 32 columns 180"
log_user 0
log_file -a $env(QUOTA_LOG)
match_max 32000
spawn -noecho $env(PANTO) -m antigravity:fast -r low
proc see {pattern} {expect {
-re $pattern {}
- timeout {puts stderr "timeout awaiting $pattern: $expect_out(buffer)"; exit 1}
+ timeout {puts stderr "timeout awaiting $pattern"; exit 1}
eof {puts stderr "early exit: $expect_out(buffer)"; exit 1}
}}
-see {antigravity:}
+see {antigravity:}; see {27%}
foreach {prompt answer} {hello primary-tool-ok again same-session-ok} {
send -- $prompt; see $prompt; send -- "\r"
if {$prompt == "hello"} {
- set reply 0; set quota 0
- while {!$reply || !$quota} {
- expect {
- -exact "primary-tool-ok" {set reply 1}
- -exact "27%" {set quota 1}
- timeout {puts stderr "first turn: reply=$reply quota=$quota"; exit 1}
- eof {exit 1}
- }
- }
+ see {steer-window-open}; send -- "boundary steer"; see {boundary steer}; send -- "\r"; see {1 steering}
+ set flag [open "$env(HOME)/.local/share/panto-antigravity/google/steer-queued" w]; close $flag
+ see {8\.2k/1M ctx}; set flag [open "$env(HOME)/.local/share/panto-antigravity/google/context-visible" w]; close $flag
+ see $answer
send -- "/reasoning high"; see {/reasoning high}; send -- "\r"; see {reasoning -> high}
} else {see $answer}
}
+send -- "/fixture-notice "; see {/fixture-notice }; send -- "\r"; see {workflow-notice-ok}
send -- "\003"; expect eof; wait
set flag [open "$env(HOME)/.local/share/panto-antigravity/google/usage-failure" w]; close $flag
spawn -noecho $env(PANTO) resume -m antigravity:fast -r high
-see {antigravity:}; send -- "resume"; see {resume}; send -- "\r"
-set reply 0; set quota 0
-while {!$reply || !$quota} {
- expect {
- -exact "resumed-ok" {set reply 1}
- -exact "unavailable" {set quota 1}
- timeout {puts stderr "resume: reply=$reply quota=$quota"; exit 1}
- eof {exit 1}
- }
+see {antigravity:}; see {unavailable}; send -- "resume"; see {resume}; send -- "\r"; see {resumed-ok}
+send -- "\003"; expect eof; wait
+
+# Select an earlier answer (not the resumed tip), then cold-resume after an
+# unsuccessful turn.
+spawn -noecho $env(PANTO) resume -m antigravity:fast -r low
+see {antigravity:}; send -- "/tree "; see {/tree }; send -- "\r"; see {session tree}
+send -- "primary-tool-ok"; after 150; send -- "\r"; see {branched from}
+foreach {query answer} {branch-probe branch-seed-ok warm-probe warm-after-seed-ok cancel-probe {stopped: cancelled}} {
+ send -- $query; see $query; send -- "\r"; see $answer
+}
+send -- "\003"; expect eof; wait
+spawn -noecho $env(PANTO) resume -m antigravity:fast -r low
+see {antigravity:}; send -- "cold-probe"; see {cold-probe}; send -- "\r"; see {cold-resume-ok}
+send -- "\003"; expect eof; wait
+
+# Recreate the saved tail from the original failure using this fake home's
+# real session log: tool result, steering text, workflow text, no answer.
+set recovered 0
+foreach path [glob $env(HOME)/.local/share/panto/sessions/*/*.jsonl] {
+ set fd [open $path r]; set records [split [read $fd] "\n"]; close $fd
+ set end [lsearch -glob $records {*"text":"boundary workflow notice"*}]; if {$end < 0} continue
+ set fd [open $path w]; puts $fd [join [lrange $records 0 $end] "\n"]; close $fd
+ spawn -noecho $env(PANTO) resume [file rootname [file tail $path]] -m antigravity:fast -r low
+ see {antigravity:}; send -- "\030"; see {\[reloaded\]}; send -- "\020"; see {proceed-recovered-ok}
+ send -- "\003"; expect eof; wait; set recovered 1; break
}
+if {!$recovered} {error "no persisted steering fixture"}
+
+# Setup that never lists the relay must fail without submitting.
+set flag [open "$env(HOME)/.local/share/panto-antigravity/google/skip-list" w]; close $flag
+spawn -noecho $env(PANTO) --incognito -m antigravity:fast -r low
+see {antigravity:}; send -- "stall"; see {stall}; send -- "\r"; see {prompt not sent}
send -- "\003"; expect eof; wait
+# Also check unconditional launch flags when nothing is exported.
+set cfg [open "$env(HOME)/.panto/config.toml" a]; puts $cfg {tools=[]}; close $cfg
+set flag [open "$env(HOME)/.local/share/panto-antigravity/google/no-tools" w]; close $flag
+spawn -noecho $env(PANTO) --incognito -m antigravity:fast -r low
+see {antigravity:}; send -- "no-tools"; see {no-tools}; send -- "\r"; see {no-tools-ok}
+send -- "\003"; expect eof; wait
# xhigh exists before switching models, but not on gemini-test.
spawn -noecho $env(PANTO) --incognito -m antigravity:fast -r xhigh
see {antigravity:}; send -- "unsupported"; see {unsupported}; send -- "\r"