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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149"""The composed request says each thing once, and python is its only tool,with or without an ACP editor's MCP servers.
Every extension writes its own instructions, context and tool schemas, andnothing else reads them side by side: a skill's description was sent twice(skills context and the command list), an MCP server's operations were bothnative tools and Python bindings, and the core text said there were noseparate tool calls while the request carried two dozen."""
import base64import jsonimport reimport secretsimport sysimport unittestfrom pathlib import Path
from harness import Albedo, Provider, exclusive, mcp_operations, operation_id, text
SERVER = Path(__file__).with_name("fake_mcp_server.py")
# Shorter sentences (a usage line, "Failures raise SkillsError.") may recur.SENTENCE = 60
def strings(value): """Every string in a decoded request, depth first.""" if isinstance(value, str): yield value elif isinstance(value, dict): for item in value.values(): yield from strings(item) elif isinstance(value, list): for item in value: yield from strings(item)
def repeated(texts): """Sentences of SENTENCE characters or more that appear more than once.""" seen, twice = set(), set() for value in texts: for sentence in re.split(r"(?<=[.!?])\s+|\n+", value): sentence = sentence.strip() if len(sentence) < SENTENCE: continue (twice if sentence in seen else seen).add(sentence) return sorted(twice)
class PromptTest(unittest.TestCase): def setUp(self): self.provider = Provider(lambda request: text("done")) self.addCleanup(self.provider.close) self.app = Albedo(self.provider, protocol="responses") self.app.__enter__() self.addCleanup(self.app.__exit__, None, None, None)
def request(self): session = self.app.session() self.app.prompt(session, "PROMPT_TEST_TURN").close() self.app.idle(session) return self.provider.requests[-1]["request"]
def test_python_is_the_only_tool_and_the_text_says_so(self): request = self.request() self.assertEqual([tool["name"] for tool in request["tools"]], ["python"]) self.assertIn("python is your only tool", request["instructions"])
def test_a_strict_tool_requires_every_property_it_declares(self): for tool in self.request()["tools"]: schema = tool["parameters"] if tool["strict"]: self.assertEqual( sorted(schema["required"]), sorted(schema["properties"]), tool )
def test_no_sentence_is_sent_twice(self): request = self.request() texts = [value for value in strings(request) if "PROMPT_TEST_TURN" not in value] self.assertEqual(repeated(texts), [])
# exclusive: configures a global MCP server and enables mcp for every session@exclusiveclass EditorPromptTest(unittest.TestCase): """An ACP editor's MCP servers beside configured ones: still python only, and the binding both MCP extensions describe is described once."""
def setUp(self): self.provider = Provider(lambda request: text("done")) self.addCleanup(self.provider.close)
def prepare(app): app.write_extensions( { "enabled": {"mcp": True}, "mcp": { "servers": { "fake": { "type": "stdio", "command": sys.executable, "args": [str(SERVER)], } } }, } )
self.app = Albedo(self.provider, protocol="responses", prepare=prepare) self.app.__enter__() self.addCleanup(self.app.__exit__, None, None, None)
def test_an_editor_s_servers_join_the_binding_not_the_tools(self): token = base64.urlsafe_b64encode(secrets.token_bytes(32)).rstrip(b"=") headers = {"Albedo-Attachment-Token": token.decode()} session = operation_id() editor = {"name": "editor", "command": sys.executable, "args": [str(SERVER)]} self.app.api( f"/sessions/{session}", { "kind": "acp", "workspace": str(self.app.workspace), "mcp_servers": [{**editor, "env": []}], }, method="PUT", headers={**headers, "If-None-Match": "*"}, ).close() self.app.api( f"/sessions/{session}/inputs/{operation_id()}", { "kind": "acp_prompt", "blocks": [{"type": "text", "text": "PROMPT_TEST_TURN"}], }, method="PUT", headers=headers, ).close() self.app.idle(session) request = self.provider.requests[-1]["request"] self.assertEqual([tool["name"] for tool in request["tools"]], ["python"]) self.assertEqual(mcp_operations(request), ["editor/echo", "fake/echo"]) self.assertEqual(json.dumps(request).count("await mcp.search("), 1) texts = [value for value in strings(request) if "PROMPT_TEST_TURN" not in value] self.assertEqual(repeated(texts), [])
if __name__ == "__main__": unittest.main()