mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-06 22:12:12 +02:00
test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F)
Apply the same rename to surfsense_backend/tests: workspace_id fields/vars, Workspace* classes/schemas, table name searchspaces -> workspaces in raw SQL, and the API URL spellings -> /workspaces. Preserves the carve-out wire literals tests assert (Celery task names, OTel key "search_space.id").
This commit is contained in:
parent
56826a63bc
commit
ca9bd28934
124 changed files with 1269 additions and 1269 deletions
|
|
@ -18,7 +18,7 @@ from app.db import (
|
|||
DocumentType,
|
||||
SearchSourceConnector,
|
||||
SearchSourceConnectorType,
|
||||
SearchSpace,
|
||||
Workspace,
|
||||
User,
|
||||
)
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ def make_document(
|
|||
title: str,
|
||||
document_type: DocumentType,
|
||||
content: str,
|
||||
search_space_id: int,
|
||||
workspace_id: int,
|
||||
created_by_id: str,
|
||||
) -> Document:
|
||||
"""Build a Document instance with unique hashes and a dummy embedding."""
|
||||
|
|
@ -43,7 +43,7 @@ def make_document(
|
|||
content_hash=f"content-{uid}",
|
||||
unique_identifier_hash=f"uid-{uid}",
|
||||
source_markdown=content,
|
||||
search_space_id=search_space_id,
|
||||
workspace_id=workspace_id,
|
||||
created_by_id=created_by_id,
|
||||
embedding=DUMMY_EMBEDDING,
|
||||
updated_at=datetime.now(UTC),
|
||||
|
|
@ -66,35 +66,35 @@ def make_chunk(*, content: str, document_id: int) -> Chunk:
|
|||
|
||||
@pytest_asyncio.fixture
|
||||
async def seed_google_docs(
|
||||
db_session: AsyncSession, db_user: User, db_search_space: SearchSpace
|
||||
db_session: AsyncSession, db_user: User, db_workspace: Workspace
|
||||
):
|
||||
"""Insert a native Drive doc, a legacy Composio Drive doc, and a FILE doc.
|
||||
|
||||
Returns a dict with keys ``native_doc``, ``legacy_doc``, ``file_doc``,
|
||||
plus ``search_space`` and ``user``.
|
||||
plus ``workspace`` and ``user``.
|
||||
"""
|
||||
user_id = str(db_user.id)
|
||||
space_id = db_search_space.id
|
||||
space_id = db_workspace.id
|
||||
|
||||
native_doc = make_document(
|
||||
title="Native Drive Document",
|
||||
document_type=DocumentType.GOOGLE_DRIVE_FILE,
|
||||
content="quarterly report from native google drive connector",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
created_by_id=user_id,
|
||||
)
|
||||
legacy_doc = make_document(
|
||||
title="Legacy Composio Drive Document",
|
||||
document_type=DocumentType.COMPOSIO_GOOGLE_DRIVE_CONNECTOR,
|
||||
content="quarterly report from composio google drive connector",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
created_by_id=user_id,
|
||||
)
|
||||
file_doc = make_document(
|
||||
title="Uploaded PDF",
|
||||
document_type=DocumentType.FILE,
|
||||
content="unrelated uploaded file about quarterly reports",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
created_by_id=user_id,
|
||||
)
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ async def seed_google_docs(
|
|||
"native_doc": native_doc,
|
||||
"legacy_doc": legacy_doc,
|
||||
"file_doc": file_doc,
|
||||
"search_space": db_search_space,
|
||||
"workspace": db_workspace,
|
||||
"user": db_user,
|
||||
}
|
||||
|
||||
|
|
@ -136,8 +136,8 @@ async def seed_google_docs(
|
|||
async def committed_google_data(async_engine):
|
||||
"""Insert native, legacy, and FILE docs via a committed transaction.
|
||||
|
||||
Yields ``{"search_space_id": int, "user_id": str}``.
|
||||
Cleans up by deleting the search space (cascades to documents / chunks).
|
||||
Yields ``{"workspace_id": int, "user_id": str}``.
|
||||
Cleans up by deleting the workspace (cascades to documents / chunks).
|
||||
"""
|
||||
space_id = None
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ async def committed_google_data(async_engine):
|
|||
session.add(user)
|
||||
await session.flush()
|
||||
|
||||
space = SearchSpace(name=f"Google Test {uuid.uuid4().hex[:6]}", user_id=user.id)
|
||||
space = Workspace(name=f"Google Test {uuid.uuid4().hex[:6]}", user_id=user.id)
|
||||
session.add(space)
|
||||
await session.flush()
|
||||
space_id = space.id
|
||||
|
|
@ -165,21 +165,21 @@ async def committed_google_data(async_engine):
|
|||
title="Native Drive Doc",
|
||||
document_type=DocumentType.GOOGLE_DRIVE_FILE,
|
||||
content="quarterly budget from native google drive",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
created_by_id=user_id,
|
||||
)
|
||||
legacy_doc = make_document(
|
||||
title="Legacy Composio Drive Doc",
|
||||
document_type=DocumentType.COMPOSIO_GOOGLE_DRIVE_CONNECTOR,
|
||||
content="quarterly budget from composio google drive",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
created_by_id=user_id,
|
||||
)
|
||||
file_doc = make_document(
|
||||
title="Plain File",
|
||||
document_type=DocumentType.FILE,
|
||||
content="quarterly budget uploaded as file",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
created_by_id=user_id,
|
||||
)
|
||||
session.add_all([native_doc, legacy_doc, file_doc])
|
||||
|
|
@ -195,7 +195,7 @@ async def committed_google_data(async_engine):
|
|||
)
|
||||
await session.flush()
|
||||
|
||||
yield {"search_space_id": space_id, "user_id": user_id}
|
||||
yield {"workspace_id": space_id, "user_id": user_id}
|
||||
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
|
|
@ -257,7 +257,7 @@ async def seed_connector(
|
|||
):
|
||||
"""Seed a connector with committed data. Returns dict and cleanup function.
|
||||
|
||||
Yields ``{"connector_id", "search_space_id", "user_id"}``.
|
||||
Yields ``{"connector_id", "workspace_id", "user_id"}``.
|
||||
"""
|
||||
space_id = None
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ async def seed_connector(
|
|||
session.add(user)
|
||||
await session.flush()
|
||||
|
||||
space = SearchSpace(
|
||||
space = Workspace(
|
||||
name=f"{name_prefix} {uuid.uuid4().hex[:6]}", user_id=user.id
|
||||
)
|
||||
session.add(space)
|
||||
|
|
@ -287,7 +287,7 @@ async def seed_connector(
|
|||
connector_type=connector_type,
|
||||
is_indexable=True,
|
||||
config=config,
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
user_id=user.id,
|
||||
)
|
||||
session.add(connector)
|
||||
|
|
@ -297,13 +297,13 @@ async def seed_connector(
|
|||
|
||||
return {
|
||||
"connector_id": connector_id,
|
||||
"search_space_id": space_id,
|
||||
"workspace_id": space_id,
|
||||
"user_id": user_id,
|
||||
}
|
||||
|
||||
|
||||
async def cleanup_space(async_engine, space_id: int):
|
||||
"""Delete a search space (cascades to connectors/documents)."""
|
||||
"""Delete a workspace (cascades to connectors/documents)."""
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
text("DELETE FROM workspaces WHERE id = :sid"), {"sid": space_id}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ async def composio_calendar(async_engine):
|
|||
name_prefix="cal-composio",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
|
|
@ -49,7 +49,7 @@ async def composio_calendar_no_id(async_engine):
|
|||
name_prefix="cal-noid",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
|
|
@ -67,7 +67,7 @@ async def native_calendar(async_engine):
|
|||
name_prefix="cal-native",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@patch(_GET_ACCESS_TOKEN)
|
||||
|
|
@ -98,7 +98,7 @@ async def test_composio_calendar_uses_composio_service(
|
|||
await index_google_calendar_events(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
)
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ async def test_composio_calendar_without_account_id_returns_error(
|
|||
count, _skipped, error = await index_google_calendar_events(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
)
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ async def test_native_calendar_uses_google_calendar_connector(
|
|||
await index_google_calendar_events(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ async def committed_drive_connector(async_engine):
|
|||
name_prefix="drive-composio",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
|
|
@ -80,7 +80,7 @@ async def committed_native_drive_connector(async_engine):
|
|||
name_prefix="drive-native",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
|
|
@ -92,7 +92,7 @@ async def committed_composio_no_account_id(async_engine):
|
|||
name_prefix="drive-noid",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@patch(_GET_ACCESS_TOKEN)
|
||||
|
|
@ -127,7 +127,7 @@ async def test_composio_drive_indexer_uses_composio_drive_client(
|
|||
await index_google_drive_files(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
folder_id="test-folder-id",
|
||||
)
|
||||
|
|
@ -167,7 +167,7 @@ async def test_composio_connector_without_account_id_returns_error(
|
|||
count, _skipped, error, _unsupported = await index_google_drive_files(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
folder_id="test-folder-id",
|
||||
)
|
||||
|
|
@ -207,7 +207,7 @@ async def test_native_connector_uses_google_drive_client(
|
|||
await index_google_drive_files(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
folder_id="test-folder-id",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ async def composio_gmail(async_engine):
|
|||
name_prefix="gmail-composio",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
|
|
@ -49,7 +49,7 @@ async def composio_gmail_no_id(async_engine):
|
|||
name_prefix="gmail-noid",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
|
|
@ -67,7 +67,7 @@ async def native_gmail(async_engine):
|
|||
name_prefix="gmail-native",
|
||||
)
|
||||
yield data
|
||||
await cleanup_space(async_engine, data["search_space_id"])
|
||||
await cleanup_space(async_engine, data["workspace_id"])
|
||||
|
||||
|
||||
@patch(_GET_ACCESS_TOKEN)
|
||||
|
|
@ -101,7 +101,7 @@ async def test_composio_gmail_uses_composio_service(
|
|||
await index_google_gmail_messages(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
)
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ async def test_composio_gmail_without_account_id_returns_error(
|
|||
count, _skipped, error = await index_google_gmail_messages(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
)
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ async def test_native_gmail_uses_google_gmail_connector(
|
|||
await index_google_gmail_messages(
|
||||
session=session,
|
||||
connector_id=data["connector_id"],
|
||||
search_space_id=data["search_space_id"],
|
||||
workspace_id=data["workspace_id"],
|
||||
user_id=data["user_id"],
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ async def test_list_of_types_returns_both_matching_doc_types(
|
|||
db_session, seed_google_docs
|
||||
):
|
||||
"""Searching with a list of document types returns documents of ALL listed types."""
|
||||
space_id = seed_google_docs["search_space"].id
|
||||
space_id = seed_google_docs["workspace"].id
|
||||
|
||||
retriever = ChucksHybridSearchRetriever(db_session)
|
||||
results = await retriever.hybrid_search(
|
||||
query_text="quarterly report",
|
||||
top_k=10,
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
document_type=["GOOGLE_DRIVE_FILE", "COMPOSIO_GOOGLE_DRIVE_CONNECTOR"],
|
||||
query_embedding=DUMMY_EMBEDDING,
|
||||
)
|
||||
|
|
@ -40,13 +40,13 @@ async def test_list_of_types_returns_both_matching_doc_types(
|
|||
|
||||
async def test_single_string_type_returns_only_that_type(db_session, seed_google_docs):
|
||||
"""Searching with a single string type returns only documents of that exact type."""
|
||||
space_id = seed_google_docs["search_space"].id
|
||||
space_id = seed_google_docs["workspace"].id
|
||||
|
||||
retriever = ChucksHybridSearchRetriever(db_session)
|
||||
results = await retriever.hybrid_search(
|
||||
query_text="quarterly report",
|
||||
top_k=10,
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
document_type="GOOGLE_DRIVE_FILE",
|
||||
query_embedding=DUMMY_EMBEDDING,
|
||||
)
|
||||
|
|
@ -59,13 +59,13 @@ async def test_single_string_type_returns_only_that_type(db_session, seed_google
|
|||
|
||||
async def test_all_invalid_types_returns_empty(db_session, seed_google_docs):
|
||||
"""Searching with a list of nonexistent types returns an empty list, no exceptions."""
|
||||
space_id = seed_google_docs["search_space"].id
|
||||
space_id = seed_google_docs["workspace"].id
|
||||
|
||||
retriever = ChucksHybridSearchRetriever(db_session)
|
||||
results = await retriever.hybrid_search(
|
||||
query_text="quarterly report",
|
||||
top_k=10,
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
document_type=["NONEXISTENT_TYPE"],
|
||||
query_embedding=DUMMY_EMBEDDING,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@ async def test_search_google_drive_includes_legacy_composio_docs(
|
|||
async_engine, committed_google_data, patched_session_factory, patched_embed
|
||||
):
|
||||
"""search_google_drive returns both GOOGLE_DRIVE_FILE and COMPOSIO_GOOGLE_DRIVE_CONNECTOR docs."""
|
||||
space_id = committed_google_data["search_space_id"]
|
||||
space_id = committed_google_data["workspace_id"]
|
||||
|
||||
async with patched_session_factory() as session:
|
||||
service = ConnectorService(session, search_space_id=space_id)
|
||||
service = ConnectorService(session, workspace_id=space_id)
|
||||
_, raw_docs = await service.search_google_drive(
|
||||
user_query="quarterly budget",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
top_k=10,
|
||||
)
|
||||
|
||||
|
|
@ -51,13 +51,13 @@ async def test_search_files_does_not_include_google_types(
|
|||
async_engine, committed_google_data, patched_session_factory, patched_embed
|
||||
):
|
||||
"""search_files returns only FILE docs, not Google Drive docs."""
|
||||
space_id = committed_google_data["search_space_id"]
|
||||
space_id = committed_google_data["workspace_id"]
|
||||
|
||||
async with patched_session_factory() as session:
|
||||
service = ConnectorService(session, search_space_id=space_id)
|
||||
service = ConnectorService(session, workspace_id=space_id)
|
||||
_, raw_docs = await service.search_files(
|
||||
user_query="quarterly budget",
|
||||
search_space_id=space_id,
|
||||
workspace_id=space_id,
|
||||
top_k=10,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue