test(backend): add deterministic Composio Gmail E2E fakes

This commit is contained in:
Anish Sarkar 2026-05-07 02:52:14 +05:30
parent 23a853b18e
commit f2e62a09b3
3 changed files with 114 additions and 5 deletions

View file

@ -13,6 +13,7 @@ from langchain_core.messages import AIMessage, AIMessageChunk, BaseMessage
from langchain_core.outputs import ChatGeneration, ChatGenerationChunk, ChatResult
DRIVE_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_DRIVE_001"
GMAIL_CANARY_TOKEN = "SURFSENSE_E2E_CANARY_TOKEN_GMAIL_001"
NO_RELEVANT_CONTENT_SENTINEL = "No relevant indexed content found."
NO_RELEVANT_CONTENT_QUERY = "E2E_NO_RELEVANT_CONTENT_SMOKE"
@ -36,6 +37,11 @@ def _messages_to_text(messages: list[BaseMessage]) -> str:
return "\n".join(_content_to_text(message.content) for message in messages)
def _contains_any(text: str, needles: tuple[str, ...]) -> bool:
lowered = text.lower()
return any(needle.lower() in lowered for needle in needles)
class FakeChatLLM(BaseChatModel):
@property
def _llm_type(self) -> str:
@ -57,11 +63,32 @@ class FakeChatLLM(BaseChatModel):
return NO_RELEVANT_CONTENT_SENTINEL
prompt_text = _messages_to_text(messages)
if (
"e2e-canary" in prompt_text
wants_gmail = _contains_any(
latest_human,
("gmail", "email", "message", "E2E Canary Email"),
)
wants_drive = _contains_any(
latest_human,
("drive", "file", "e2e-canary.txt"),
)
has_gmail_evidence = (
"E2E Canary Email" in prompt_text
or "fake-msg-canary-001" in prompt_text
or GMAIL_CANARY_TOKEN in prompt_text
)
has_drive_evidence = (
"e2e-canary.txt" in prompt_text
or "fake-file-canary" in prompt_text
or DRIVE_CANARY_TOKEN in prompt_text
):
)
if wants_gmail and has_gmail_evidence:
return f"Gmail content found: {GMAIL_CANARY_TOKEN}"
if wants_drive and has_drive_evidence:
return f"Drive content found: {DRIVE_CANARY_TOKEN}"
if has_gmail_evidence and not has_drive_evidence:
return f"Gmail content found: {GMAIL_CANARY_TOKEN}"
if has_drive_evidence and not has_gmail_evidence:
return f"Drive content found: {DRIVE_CANARY_TOKEN}"
return NO_RELEVANT_CONTENT_SENTINEL