fix: address rpc and mcp review followups
This commit is contained in:
@@ -47,6 +47,19 @@ def test_wf_sources_mcp_auth_adapters_interpret_mcp_payload() -> None:
|
||||
assert mcp_auth_env(auth) == {"GITHUB_TOKEN": "secret"}
|
||||
|
||||
|
||||
def test_wf_sources_mcp_auth_headers_preserve_existing_authorization_case() -> None:
|
||||
auth = AuthRecord(
|
||||
connection_id="github.work",
|
||||
scheme="bearer",
|
||||
payload={
|
||||
"token": "secret",
|
||||
"headers": {"authorization": "Bearer custom"},
|
||||
},
|
||||
)
|
||||
|
||||
assert mcp_auth_headers(auth) == {"authorization": "Bearer custom"}
|
||||
|
||||
|
||||
def test_wf_sources_mcp_file_stores_keep_existing_disk_shape(tmp_path) -> None:
|
||||
auth_store = FileAuthStore(tmp_path / "auth-root")
|
||||
catalog_store = FileCatalogStore(tmp_path / "catalog-root")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from contextlib import AsyncExitStack
|
||||
from typing import Any
|
||||
|
||||
@@ -259,6 +260,41 @@ async def test_runtime_pool_reuses_unchanged_connection() -> None:
|
||||
assert created == [connection]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_pool_serializes_concurrent_session_creation() -> None:
|
||||
created: list[McpSourceConnection] = []
|
||||
release = asyncio.Event()
|
||||
|
||||
async def create_session(
|
||||
connection: McpSourceConnection, auth: AuthRecord | None
|
||||
) -> PersistentMcpSession:
|
||||
created.append(connection)
|
||||
await release.wait()
|
||||
|
||||
async def _call(tool_name: str, payload: dict[str, Any]) -> ToolCallResult:
|
||||
return ToolCallResult(outcome="ok", output={"echoed": payload["text"]})
|
||||
|
||||
return PersistentMcpSession(
|
||||
connection=connection,
|
||||
auth=auth,
|
||||
call_callback=_call,
|
||||
)
|
||||
|
||||
pool = McpRuntimePool(session_factory=create_session)
|
||||
connection = _connection()
|
||||
|
||||
first = asyncio.create_task(pool.get_session(connection, None))
|
||||
second = asyncio.create_task(pool.get_session(connection, None))
|
||||
await asyncio.sleep(0)
|
||||
release.set()
|
||||
|
||||
first_session, second_session = await asyncio.gather(first, second)
|
||||
await pool.close_all()
|
||||
|
||||
assert first_session is second_session
|
||||
assert created == [connection]
|
||||
|
||||
|
||||
def test_runtime_fingerprint_changes_when_transport_changes() -> None:
|
||||
original = _connection()
|
||||
changed = McpSourceConnection(
|
||||
|
||||
@@ -111,6 +111,45 @@ def test_model_from_schema_allows_extra_fields_and_tolerates_unknown_shapes() ->
|
||||
assert dumped["extra"] == "kept"
|
||||
|
||||
|
||||
def test_model_from_schema_preserves_complex_array_item_annotations() -> None:
|
||||
model = model_from_schema(
|
||||
"NestedArrayInput",
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": ["object", "null"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
annotation = model.model_fields["items"].annotation
|
||||
|
||||
assert str(annotation) == "list[dict[str, typing.Any] | None]"
|
||||
|
||||
|
||||
def test_model_from_schema_preserves_optional_complex_annotations() -> None:
|
||||
model = model_from_schema(
|
||||
"OptionalObjectInput",
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"metadata": {
|
||||
"type": ["object", "null"],
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
annotation = model.model_fields["metadata"].annotation
|
||||
|
||||
assert str(annotation) == "dict[str, typing.Any] | None"
|
||||
|
||||
|
||||
def test_model_from_schema_exports_from_package_root() -> None:
|
||||
from wf_sources_mcp import model_from_schema as root_model_from_schema
|
||||
from wf_sources_mcp.schema_models import model_from_schema
|
||||
|
||||
Reference in New Issue
Block a user