- cli/test_conv_ref.py: run() now clears AI_AGENT_OUTBOX_URL / _TOKEN before applying a test's own env. On a worker (EVOX2, the Macs) the outbox is in the environment, so the hook took the worker path and three tests failed. - useShareTarget.test.tsx: stash() takes string bodies instead of jsdom Blobs, which Node's Response can't read (it calls .stream()). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
6.4 KiB
Python
129 lines
6.4 KiB
Python
"""The conv-ref prompt hook (conv_ref.py): what counts as a conversation
|
|
reference (Gabriel's own prompts from the Nov 2026 analysis), the hub's tail
|
|
left out, the card it prints, and silence everywhere else.
|
|
``python -m unittest test_conv_ref`` from ``cli/``."""
|
|
|
|
import io
|
|
import json
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
import conv_ref
|
|
|
|
A = "01a1e40a-9907-7a32-81d4-6bfc5a8f6240"
|
|
SA = "a2533c3a-d718-4823-80d0-70bf2939ba81"
|
|
CARD = {"id": A, "sessionId": SA, "title": "Linear metadata widget", "state": "finished",
|
|
"machine": "Orus Macbook", "account": "work", "projects": ["orus"],
|
|
"endedAt": "2026-11-16T13:54:30Z", "url": f"https://ai-agent.lab.gabvdl.xyz/conversation/{A}",
|
|
"firstPrompt": "build the\nwidget", "lastAnswer": "Done: PR #15039"}
|
|
|
|
|
|
OUTBOX_ENV = ("AI_AGENT_OUTBOX_URL", "AI_AGENT_OUTBOX_TOKEN")
|
|
|
|
|
|
def run(prompt, env=None, **kw):
|
|
out = io.StringIO()
|
|
data = json.dumps({"prompt": prompt, "session_id": "11111111-0000-4000-8000-000000000000", **kw})
|
|
with mock.patch.dict(os.environ, clear=False), \
|
|
mock.patch("sys.stdin", io.StringIO(data)), mock.patch("sys.stdout", out):
|
|
# A run on a worker has its outbox in the environment (EVOX2, the
|
|
# Macs): the hook would take the worker's path. The lab's, unless a
|
|
# test says otherwise.
|
|
for k in OUTBOX_ENV:
|
|
os.environ.pop(k, None)
|
|
os.environ.update(env or {})
|
|
conv_ref.main([])
|
|
text = out.getvalue()
|
|
return json.loads(text)["hookSpecificOutput"]["additionalContext"] if text else None
|
|
|
|
|
|
class Detect(unittest.TestCase):
|
|
def test_gabriels_phrasings_talk_about_past_conversations(self):
|
|
for p in ("I reauthorized tailscale for the vpn exit node, check past conv",
|
|
"what's left on this PR ? check previous convs https://github.com/o/r/pull/14871",
|
|
"search past conversation about the improvements of the CPMS page",
|
|
"dom requested to setup email sending in a previous conversation",
|
|
"check this PR and past conv, we decided to exclude contracts linked to partners",
|
|
"check the other PR and conv that fixed the CP",
|
|
"regarde la conv précédente sur raspy1"):
|
|
self.assertTrue(conv_ref.find_refs(p)[2], p)
|
|
|
|
def test_ordinary_prompts_dont(self):
|
|
for p in ("fix the conversation page padding when a run is stopped",
|
|
"add a conversation card to the home page",
|
|
"the convex hull is wrong"):
|
|
self.assertEqual(conv_ref.find_refs(p), ([], set(), False), p)
|
|
|
|
def test_ids_links_and_prefixes(self):
|
|
ids, named, _ = conv_ref.find_refs(
|
|
f"from this conv {A} and https://ai-agent.lab.gabvdl.xyz/conversation/01a1f4e8-795c-7f66-917a-a0012337347b"
|
|
" also conv a2533c3a, contract 01a1ffff-0000-7000-8000-000000000000")
|
|
self.assertEqual(ids, ["01a1f4e8-795c-7f66-917a-a0012337347b", A, "a2533c3a",
|
|
"01a1ffff-0000-7000-8000-000000000000"])
|
|
self.assertEqual(named, {"01a1f4e8-795c-7f66-917a-a0012337347b", A, "a2533c3a"})
|
|
|
|
def test_the_own_session_and_the_hubs_tail_are_left_out(self):
|
|
own = "22222222-0000-4000-8000-000000000000"
|
|
self.assertEqual(conv_ref.find_refs(f"conv {own}", own)[0], [])
|
|
p = ("fix the deploy\n\nUse the following in this task:\n- the `ai-agent` skill — … search "
|
|
"past ones, when a past conversation already holds the context")
|
|
self.assertFalse(conv_ref.find_refs(conv_ref.own_text(p))[2])
|
|
|
|
|
|
class Hook(unittest.TestCase):
|
|
def test_silent_on_an_ordinary_prompt_and_in_a_guest_run(self):
|
|
self.assertIsNone(run("rename the button"))
|
|
self.assertIsNone(run("check past conv", env={"AIA_GUEST": "dom"}))
|
|
|
|
def test_a_phrase_gets_the_hint_with_the_lab_commands(self):
|
|
with mock.patch.object(conv_ref, "lookup_hub") as hub:
|
|
ctx = run("check past conv about the edge split")
|
|
hub.assert_not_called() # nothing to resolve
|
|
self.assertIn("ai-agent search", ctx)
|
|
self.assertIn("not a file under ~/.claude/projects", ctx)
|
|
|
|
def test_an_id_gets_its_card(self):
|
|
with mock.patch.object(conv_ref, "lookup_hub",
|
|
return_value={"cards": [CARD], "unknown": [], "ambiguous": []}) as hub:
|
|
ctx = run(f"do i have the skill locally? from this conv {A}")
|
|
self.assertEqual(hub.call_args.args[0], [A])
|
|
self.assertIn(f"• {A} “Linear metadata widget” — finished · ended", ctx)
|
|
self.assertIn("Orus Macbook · work · orus", ctx)
|
|
self.assertIn("asked: build the widget", ctx)
|
|
self.assertIn("last answer: Done: PR #15039", ctx)
|
|
|
|
def test_on_a_worker_it_asks_the_outbox_and_names_the_mcp_tools(self):
|
|
with mock.patch.object(conv_ref, "lookup_outbox",
|
|
return_value={"cards": [], "unknown": [A], "ambiguous": []}) as ob:
|
|
ctx = run(f"I did the dry run on this conv {A}",
|
|
env={"AI_AGENT_OUTBOX_URL": "http://100.1.2.3:8790", "AI_AGENT_OUTBOX_TOKEN": "t"})
|
|
self.assertEqual(ob.call_args.args[2:], ("http://100.1.2.3:8790", "t"))
|
|
self.assertIn("mcp__ai-agent__get_conversation", ctx)
|
|
self.assertIn(f"• {A}: no conversation the hub shows here", ctx)
|
|
|
|
def test_a_bare_uuid_that_is_no_conversation_says_nothing(self):
|
|
with mock.patch.object(conv_ref, "lookup_hub",
|
|
return_value={"cards": [], "unknown": [A], "ambiguous": []}):
|
|
self.assertIsNone(run(f"contract {A} has the wrong start date"))
|
|
|
|
def test_a_hub_error_never_blocks(self):
|
|
with mock.patch.object(conv_ref, "lookup_hub", side_effect=RuntimeError("hub unreachable")):
|
|
ctx = run(f"follow this conv {A}")
|
|
self.assertIn("didn't resolve", ctx)
|
|
|
|
def test_the_transcript_on_this_machine(self):
|
|
with tempfile.TemporaryDirectory() as d:
|
|
p = Path(d) / "projects" / "-Users-x-orus"
|
|
p.mkdir(parents=True)
|
|
(p / f"{SA}.jsonl").write_text("{}")
|
|
with mock.patch.dict(os.environ, {"CLAUDE_CONFIG_DIR": d}):
|
|
self.assertEqual(conv_ref.local_transcript(SA), str(p / f"{SA}.jsonl"))
|
|
self.assertIsNone(conv_ref.local_transcript("../etc"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|