mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-13 01:32:40 +02:00
chore: ran linting
This commit is contained in:
parent
2f540ee065
commit
dbf575fbd0
23 changed files with 89 additions and 96 deletions
|
|
@ -239,7 +239,9 @@ class _AuthConfigs(_StrictFakeMixin):
|
|||
# SDK lets you have multiple, but one is enough for E2E.
|
||||
return _AuthConfigsListResult(
|
||||
items=[
|
||||
_AuthConfig(config_id="auth-config-googledrive", toolkit_slug="googledrive"),
|
||||
_AuthConfig(
|
||||
config_id="auth-config-googledrive", toolkit_slug="googledrive"
|
||||
),
|
||||
_AuthConfig(config_id="auth-config-gmail", toolkit_slug="gmail"),
|
||||
_AuthConfig(
|
||||
config_id="auth-config-googlecalendar",
|
||||
|
|
@ -289,7 +291,9 @@ class _Tools(_StrictFakeMixin):
|
|||
if slug == "GOOGLEDRIVE_GET_CHANGES_START_PAGE_TOKEN":
|
||||
return {"data": {"startPageToken": "fake-start-page-token-1"}}
|
||||
if slug == "GOOGLEDRIVE_LIST_CHANGES":
|
||||
return {"data": {"changes": [], "newStartPageToken": "fake-start-page-token-1"}}
|
||||
return {
|
||||
"data": {"changes": [], "newStartPageToken": "fake-start-page-token-1"}
|
||||
}
|
||||
if slug == "GOOGLEDRIVE_GET_ABOUT":
|
||||
# Used by ComposioService.get_connected_account_email for
|
||||
# googledrive. Returning a fake email lets the connector get a
|
||||
|
|
@ -381,7 +385,9 @@ def _extract_quoted_value(q: str, anchor: str) -> str | None:
|
|||
return after_first_quote[:second_quote_idx]
|
||||
|
||||
|
||||
def _filter_drive_files_for_query(q: str, files: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
def _filter_drive_files_for_query(
|
||||
q: str, files: list[dict[str, Any]]
|
||||
) -> list[dict[str, Any]]:
|
||||
filtered = list(files)
|
||||
|
||||
if "trashed = false" in q:
|
||||
|
|
|
|||
|
|
@ -31,7 +31,9 @@ class _FakeConfluenceHistoryConnector:
|
|||
include_comments: bool = False,
|
||||
) -> tuple[list[dict[str, Any]], None]:
|
||||
if not start_date or not end_date:
|
||||
raise ValueError("Confluence indexer fake expected start_date and end_date.")
|
||||
raise ValueError(
|
||||
"Confluence indexer fake expected start_date and end_date."
|
||||
)
|
||||
del include_comments
|
||||
return _FIXTURE["pages"], None
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,9 @@ class _FakeHttpxAsyncClient(_StrictFakeMixin):
|
|||
f"Unexpected fake Confluence OAuth code: {data.get('code')!r}"
|
||||
)
|
||||
if not data.get("client_id") or not data.get("client_secret"):
|
||||
raise ValueError("Confluence OAuth token exchange missing client creds.")
|
||||
raise ValueError(
|
||||
"Confluence OAuth token exchange missing client creds."
|
||||
)
|
||||
if "/api/v1/auth/confluence/connector/callback" not in str(
|
||||
data.get("redirect_uri", "")
|
||||
):
|
||||
|
|
|
|||
|
|
@ -37,9 +37,7 @@ def fake_embed_texts(texts: list[str]) -> list[np.ndarray]:
|
|||
if not texts:
|
||||
return []
|
||||
dim = _embedding_dim()
|
||||
return [
|
||||
np.full(shape=(dim,), fill_value=0.1, dtype=np.float32) for _ in texts
|
||||
]
|
||||
return [np.full(shape=(dim,), fill_value=0.1, dtype=np.float32) for _ in texts]
|
||||
|
||||
|
||||
def install(patches: list[Any]) -> None:
|
||||
|
|
@ -60,7 +58,10 @@ def install(patches: list[Any]) -> None:
|
|||
("app.indexing_pipeline.document_embedder.embed_text", fake_embed_text),
|
||||
("app.indexing_pipeline.document_embedder.embed_texts", fake_embed_texts),
|
||||
# Pipeline service binding (the actual call site for indexing.index)
|
||||
("app.indexing_pipeline.indexing_pipeline_service.embed_texts", fake_embed_texts),
|
||||
(
|
||||
"app.indexing_pipeline.indexing_pipeline_service.embed_texts",
|
||||
fake_embed_texts,
|
||||
),
|
||||
]
|
||||
for target, replacement in targets:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -85,18 +85,15 @@ async def _call_tool(
|
|||
raise ValueError(
|
||||
f"Unexpected Jira getAccessibleAtlassianResources args: {arguments!r}"
|
||||
)
|
||||
text = (
|
||||
f"{site['name']}\n"
|
||||
f"cloud_id: {site['cloud_id']}\n"
|
||||
f"url: {site['url']}"
|
||||
)
|
||||
text = f"{site['name']}\ncloud_id: {site['cloud_id']}\nurl: {site['url']}"
|
||||
return SimpleNamespace(content=[SimpleNamespace(text=text)])
|
||||
|
||||
if tool_name == "searchJiraIssuesUsingJql":
|
||||
jql = str(arguments.get("jql", ""))
|
||||
if issue["summary"].lower() not in jql.lower() and issue[
|
||||
"key"
|
||||
].lower() not in jql.lower():
|
||||
if (
|
||||
issue["summary"].lower() not in jql.lower()
|
||||
and issue["key"].lower() not in jql.lower()
|
||||
):
|
||||
raise ValueError(f"Unexpected Jira JQL query: {jql!r}")
|
||||
text = _issue_text(issue)
|
||||
return SimpleNamespace(content=[SimpleNamespace(text=text)])
|
||||
|
|
|
|||
|
|
@ -92,8 +92,7 @@ async def _fake_discover_oauth_metadata(
|
|||
raise NotImplementedError(f"Unexpected MCP OAuth discovery url={mcp_url!r}")
|
||||
if origin_override != handler.expected_origin_override:
|
||||
raise ValueError(
|
||||
f"Unexpected MCP OAuth origin_override for {mcp_url!r}: "
|
||||
f"{origin_override!r}"
|
||||
f"Unexpected MCP OAuth origin_override for {mcp_url!r}: {origin_override!r}"
|
||||
)
|
||||
return dict(handler.discovery_metadata)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,9 +64,11 @@ class _FakeStreamableHttpClient(_StrictFakeMixin):
|
|||
self.handler = handler
|
||||
|
||||
async def __aenter__(self) -> tuple[_FakeEndpoint, _FakeEndpoint, None]:
|
||||
return _FakeEndpoint(self.url, self.handler), _FakeEndpoint(
|
||||
self.url, self.handler
|
||||
), None
|
||||
return (
|
||||
_FakeEndpoint(self.url, self.handler),
|
||||
_FakeEndpoint(self.url, self.handler),
|
||||
None,
|
||||
)
|
||||
|
||||
async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
|
||||
del exc_type, exc, tb
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ class _StrictFakeMixin:
|
|||
class _FakeFlow(_StrictFakeMixin):
|
||||
_component_name = "Flow"
|
||||
|
||||
def __init__(self, *, redirect_uri: str | None = None, scopes: list[str] | None = None):
|
||||
def __init__(
|
||||
self, *, redirect_uri: str | None = None, scopes: list[str] | None = None
|
||||
):
|
||||
self.redirect_uri = redirect_uri
|
||||
self.scopes = scopes or []
|
||||
self.code_verifier: str | None = None
|
||||
|
|
@ -88,9 +90,7 @@ class _FakeFlow(_StrictFakeMixin):
|
|||
query = parse_qs(parsed.query)
|
||||
query["code"] = ["fake-native-drive-oauth-code"]
|
||||
query["state"] = [state]
|
||||
redirect = urlunparse(
|
||||
parsed._replace(query=urlencode(query, doseq=True))
|
||||
)
|
||||
redirect = urlunparse(parsed._replace(query=urlencode(query, doseq=True)))
|
||||
return redirect, state
|
||||
|
||||
def fetch_token(self, *, code: str, **_: Any) -> None:
|
||||
|
|
@ -213,7 +213,9 @@ class _FakeGmailUsers(_StrictFakeMixin):
|
|||
def getProfile(self, **kwargs: Any) -> _FakeRequest: # noqa: N802
|
||||
user_id = kwargs.get("userId")
|
||||
if user_id != "me":
|
||||
raise NotImplementedError(f"Unexpected fake Gmail profile userId={user_id!r}")
|
||||
raise NotImplementedError(
|
||||
f"Unexpected fake Gmail profile userId={user_id!r}"
|
||||
)
|
||||
return _FakeRequest({"emailAddress": "native-drive-e2e@surfsense.example"})
|
||||
|
||||
def messages(self) -> _FakeGmailMessages:
|
||||
|
|
@ -326,7 +328,9 @@ def _extract_quoted_value(q: str, anchor: str) -> str | None:
|
|||
return after_first_quote[:second_quote_idx]
|
||||
|
||||
|
||||
def _filter_drive_files_for_query(q: str, files: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
def _filter_drive_files_for_query(
|
||||
q: str, files: list[dict[str, Any]]
|
||||
) -> list[dict[str, Any]]:
|
||||
filtered = list(files)
|
||||
|
||||
if "trashed = false" in q:
|
||||
|
|
@ -386,14 +390,14 @@ def _calendar_event_in_range(
|
|||
parsed_max = _parse_rfc3339(time_max)
|
||||
if parsed_min and event_start < parsed_min:
|
||||
return False
|
||||
if parsed_max and event_start > parsed_max:
|
||||
return False
|
||||
return True
|
||||
return not (parsed_max and event_start > parsed_max)
|
||||
|
||||
|
||||
def _gmail_detail_to_native_message(detail: dict[str, Any]) -> dict[str, Any]:
|
||||
message_text = detail.get("messageText", "")
|
||||
encoded_body = base64.urlsafe_b64encode(message_text.encode("utf-8")).decode("ascii")
|
||||
encoded_body = base64.urlsafe_b64encode(message_text.encode("utf-8")).decode(
|
||||
"ascii"
|
||||
)
|
||||
|
||||
return {
|
||||
"id": detail.get("id"),
|
||||
|
|
@ -429,10 +433,12 @@ def install(active_patches: list[Any]) -> None:
|
|||
("app.agents.new_chat.tools.google_calendar.update_event.build", _fake_build),
|
||||
("app.agents.new_chat.tools.google_calendar.delete_event.build", _fake_build),
|
||||
("googleapiclient.http.MediaIoBaseDownload", _FakeMediaIoBaseDownload),
|
||||
("app.connectors.google_drive.client._build_thread_http", lambda credentials: None),
|
||||
(
|
||||
"app.connectors.google_drive.client._build_thread_http",
|
||||
lambda credentials: None,
|
||||
),
|
||||
]
|
||||
for target, replacement in targets:
|
||||
p = patch(target, replacement)
|
||||
p.start()
|
||||
active_patches.append(p)
|
||||
|
||||
|
|
|
|||
|
|
@ -84,8 +84,16 @@ class _FakeOneDriveClient(_StrictFakeMixin):
|
|||
if delta_link:
|
||||
folder_key = delta_link.rsplit("/", 1)[-1].removesuffix("-delta")
|
||||
if folder_key not in _ONEDRIVE_FIXTURE:
|
||||
return [], None, f"E2E OneDrive fake has no delta for folder={folder_key!r}."
|
||||
return [], f"https://graph.microsoft.com/v1.0/fake-delta/{folder_key}-delta", None
|
||||
return (
|
||||
[],
|
||||
None,
|
||||
f"E2E OneDrive fake has no delta for folder={folder_key!r}.",
|
||||
)
|
||||
return (
|
||||
[],
|
||||
f"https://graph.microsoft.com/v1.0/fake-delta/{folder_key}-delta",
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
class _FakeAsyncClient(_StrictFakeMixin):
|
||||
|
|
@ -170,7 +178,10 @@ def install(active_patches: list[Any]) -> None:
|
|||
targets = [
|
||||
("app.routes.onedrive_add_connector_route.httpx", _FakeHttpxModule()),
|
||||
("app.routes.onedrive_add_connector_route.OneDriveClient", _FakeOneDriveClient),
|
||||
("app.tasks.connector_indexers.onedrive_indexer.OneDriveClient", _FakeOneDriveClient),
|
||||
(
|
||||
"app.tasks.connector_indexers.onedrive_indexer.OneDriveClient",
|
||||
_FakeOneDriveClient,
|
||||
),
|
||||
("app.connectors.onedrive.client.httpx", _FakeHttpxModule()),
|
||||
]
|
||||
for target, replacement in targets:
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ async def _fake_exchange_code_for_tokens(
|
|||
timeout: float = 30.0,
|
||||
) -> dict[str, Any]:
|
||||
if token_endpoint != _TOKEN_URL:
|
||||
return await mcp_oauth_runtime._fake_exchange_code_for_tokens( # noqa: SLF001
|
||||
return await mcp_oauth_runtime._fake_exchange_code_for_tokens(
|
||||
token_endpoint,
|
||||
code,
|
||||
redirect_uri,
|
||||
|
|
|
|||
|
|
@ -77,9 +77,7 @@ logging.basicConfig(
|
|||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
logger = logging.getLogger("surfsense.e2e.celery")
|
||||
logger.warning(
|
||||
"*** SURFSENSE E2E CELERY WORKER — fake Composio + LLM + embeddings ***"
|
||||
)
|
||||
logger.warning("*** SURFSENSE E2E CELERY WORKER — fake Composio + LLM + embeddings ***")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ def test_extract_text_content_ignores_thinking_blocks_and_keeps_markdown_text()
|
|||
assert extract_text_content(content).strip() == markdown.strip()
|
||||
|
||||
|
||||
def test_extract_text_content_returns_empty_when_only_thinking_blocks_are_present() -> None:
|
||||
def test_extract_text_content_returns_empty_when_only_thinking_blocks_are_present() -> (
|
||||
None
|
||||
):
|
||||
content = [
|
||||
{"type": "thinking", "thinking": "No durable fact."},
|
||||
{"type": "thinking", "thinking": "Return no update."},
|
||||
|
|
|
|||
|
|
@ -141,9 +141,7 @@ class TestNormalizeDecision:
|
|||
assert _normalize_permission_decision(decision) == {"decision_type": "reject"}
|
||||
|
||||
def test_lc_envelope_reject_with_message_carries_feedback(self) -> None:
|
||||
decision = {
|
||||
"decisions": [{"type": "reject", "message": "wrong recipient"}]
|
||||
}
|
||||
decision = {"decisions": [{"type": "reject", "message": "wrong recipient"}]}
|
||||
out = _normalize_permission_decision(decision)
|
||||
assert out == {"decision_type": "reject", "feedback": "wrong recipient"}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue