Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586"""A blocked prompt ends its turn cleanly: no provider request, no error.Catches the loop reporting a UserPromptSubmit block as a failed turn."""
import jsonimport unittest
from harness import Albedo, Provider, exclusive, python, text
class BlockedPromptTests(unittest.TestCase): @exclusive def test_blocked_prompt_makes_no_model_call_and_does_not_fail(self): provider = Provider(lambda request: text("should not be asked")) self.addCleanup(provider.close)
def prepare(app): config = { "hooks": { "UserPromptSubmit": [ { "hooks": [ { "type": "command", "command": "cat >/dev/null; echo NOPE >&2; exit 2", } ] } ] } } (app.home / "hooks.json").write_text(json.dumps(config))
with Albedo(provider, protocol="responses", prepare=prepare) as app: sid = app.session() with app.api( f"/sessions/{sid}/extensions", {"name": "hooks", "enabled": True} ) as response: json.load(response) app.prompt(sid, "do something").close() status = app.idle(sid) self.assertEqual(provider.requests, []) self.assertFalse(status["running"])
@exclusive def test_run_job_fires_post_tool_use_when_it_finishes(self): replies = [ python("job = run('echo', 'JOB_OUTPUT')\nawait job\nprint(job.tail())"), text("done"), ] provider = Provider(lambda request: replies.pop(0)) self.addCleanup(provider.close)
def prepare(app): hook = ( 'python3 -c "import json,sys; d=json.load(sys.stdin); ' "print(json.dumps({'hookSpecificOutput': {'additionalContext': " "'POST_SAW ' + d['tool_name'] + ' ' + str(d['tool_response']['exit_code'])}}))\"" ) config = { "hooks": { "PostToolUse": [ { "matcher": "^Bash$", "hooks": [{"type": "command", "command": hook}], } ] } } (app.home / "hooks.json").write_text(json.dumps(config))
with Albedo(provider, protocol="responses", prepare=prepare) as app: sid = app.session() with app.api( f"/sessions/{sid}/extensions", {"name": "hooks", "enabled": True} ) as response: json.load(response) app.prompt(sid, "run a job").close() app.idle(sid) second = json.dumps(provider.requests[1]["request"]["input"]) self.assertIn("JOB_OUTPUT", second) self.assertIn("POST_SAW Bash 0", second)
if __name__ == "__main__": unittest.main()