Files
ai-agent/backend/test_banner_conversation.py
gabrielvidalandClaude Opus 5.5 b42063f3a1 refactor(deploy): drop the core deploy banner — the blue-green-deploy plugin's app.banner replaces it
- delete backend/deploy_status.py (DeployWatcher's 1 s file poll), GET
  /api/deploy-status, the DeployStep/DeployStatus schemas, the authz/usage
  entries and guests._deploying (guest-job delivery now waits on
  banner.is_maintenance alone)
- _attach_conversation moves to plugins/routes.py (only /api/app-banner uses
  it); its test becomes test_banner_conversation.py
- delete DeployBanner.tsx, fetchDeployStatus/useDeployStatus, the SSE
  `deploy` handler and the French strings only it used; the mock seeds its
  mid-flight deploy as an app.banner instead
- useAppBanner polls while a banner shows (6 s done/failed, 1 min running),
  so a provider's expired snapshot goes away without a webhook

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 10:54:54 +01:00

78 lines
2.7 KiB
Python

"""plugins.routes._attach_conversation: the app banner's conversation title is
resolved from the snapshot's session id (the sidecar override, else the parsed
ai-title), not trusted from the plugin — which only ever saw the override."""
import os
import tempfile
from types import SimpleNamespace
# Imported lazily: other test modules point the app's paths at a throwaway
# dir before their own (module-level) import of it, and core.config reads them
# once — importing it here at collection time would pin the defaults first.
os.environ.setdefault("TRANSCRIPTS_DIR", tempfile.mkdtemp())
SID = "f7baa782-0000-4000-8000-000000000001"
def _attach(deps, caller, snap):
from plugins.routes import _attach_conversation
_attach_conversation(deps, caller, snap)
def _owner():
from users.caller import OWNER
return OWNER
def _deps(meta: dict | None = None):
from core import config
ROOT = str(config.TRANSCRIPTS_DIR)
summaries = [
(f"{ROOT}/-home-x/{SID}.jsonl",
{"sessionId": SID, "title": "Fix the deploy banner", "endedAt": "2026-10-12T10:00:00Z"}),
(f"{ROOT}/-home-x/{SID}/subagents/agent-a.jsonl",
{"sessionId": SID, "title": "subagent", "endedAt": "2026-10-12T11:00:00Z"}),
(f"{ROOT}/-home-x/other.jsonl", {"sessionId": "other", "title": "Other"}),
]
metas = {SID: meta or {}}
return SimpleNamespace(
store=SimpleNamespace(all_summaries=lambda: summaries),
meta_store=SimpleNamespace(peek=lambda sid: metas.get(sid, {})),
)
def _snap():
return {"sessionId": SID, "convTitle": None,
"convUrl": "https://ai-agent.lab.gabvdl.xyz/conversation/x/y.jsonl"}
def test_resolves_the_parsed_title_and_conversation_id():
snap = _snap()
_attach(_deps(), _owner(), snap)
assert snap["convTitle"] == "Fix the deploy banner"
from conversations import ids
assert snap["conversationId"] == ids.uid_for_rel(f"-home-x/{SID}.jsonl")
assert snap["convUrl"] == f"/conversation/{snap['conversationId']}"
def test_a_renamed_conversation_shows_its_custom_title():
snap = _snap()
_attach(_deps({"title": "Renamed"}), _owner(), snap)
assert snap["convTitle"] == "Renamed"
def test_unknown_session_keeps_the_plugin_stamp():
snap = {"sessionId": "nope", "convTitle": "From script"}
_attach(_deps(), _owner(), snap)
assert snap["convTitle"] == "From script"
assert "conversationId" not in snap
def test_a_guest_who_cannot_see_it_gets_no_title_or_link():
from users.caller import guest_from_record
guest = guest_from_record({"id": "g1"})
snap = _snap()
_attach(_deps(), guest, snap)
assert snap["convTitle"] is None and snap["convUrl"] is None
assert "conversationId" not in snap