test(phase-12.1): repair live browse validation guard

This commit is contained in:
curo1305
2026-06-22 12:03:06 +02:00
parent d02d5db7c3
commit b00218e5c5
+35 -12
View File
@@ -27,6 +27,7 @@ import logging
import os import os
import re import re
import uuid as _uuid import uuid as _uuid
from contextlib import ExitStack
from typing import Optional from typing import Optional
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
@@ -199,21 +200,43 @@ async def test_nextcloud_adapter_read_only_root_metadata(capfd):
code = _stable_error_code(exc) code = _stable_error_code(exc)
pytest.skip(f"Adapter construction failed [{code}].") pytest.skip(f"Adapter construction failed [{code}].")
# Assert no byte or mutation methods are accessible on the adapter # Later phases may legitimately add byte and mutation capabilities to the
for method_name in ("get_object", "put_object", "delete_object", # adapter. Phase 12.1's invariant is behavioral: metadata browsing must not
"upload_to", "download_from", "copy", "move", # invoke any of them. Guard both the adapter boundary and its WebDAV client
"create_folder", "rename"): # so an accidental call fails before network dispatch (T-12.1-17).
assert not callable(getattr(type(adapter), method_name, None)), ( forbidden_adapter_methods = ("get_object", "put_object", "delete_object")
f"T-12.1-17: adapter exposes mutation method {method_name!r}" forbidden_client_methods = ("download_from", "upload_to", "mkdir", "clean")
guards = [
patch.object(
adapter,
method_name,
side_effect=AssertionError(
f"T-12.1-17: list_folder called forbidden adapter method {method_name!r}"
),
) )
for method_name in forbidden_adapter_methods
]
guards.extend(
patch.object(
adapter._client,
method_name,
side_effect=AssertionError(
f"T-12.1-17: list_folder called forbidden WebDAV method {method_name!r}"
),
)
for method_name in forbidden_client_methods
)
try: try:
listing = await adapter.list_folder( with ExitStack() as stack:
connection_id=connection_id, for guard in guards:
user_id=user_id, stack.enter_context(guard)
parent_ref=None, listing = await adapter.list_folder(
page_token=None, connection_id=connection_id,
) user_id=user_id,
parent_ref=None,
page_token=None,
)
except Exception as exc: except Exception as exc:
code = _stable_error_code(exc) code = _stable_error_code(exc)
pytest.fail( pytest.fail(