refactor(vector-sync): clear SonarCloud gate + round-2 nits
Quality-gate fixes (new-code conditions on PR #902): - new_security_hotspots_reviewed: drop the fake "http://nextcloud" host in the manager tests to https:// (python:S5332 ×2). - new_security_rating: generate the integration test's fake app password with secrets.token_urlsafe instead of a hardcoded literal (python:S2068). - new_reliability_rating: restructure the user_manager sleep so an explicit await checkpoint lives inside the cancellation scope — await one waiter directly while watching shutdown via start_soon (python:S7490). Behaviour is unchanged: timeout, shutdown, or a provisioning ring all end the sleep. Review nits: - Move the shutdown test's fail_after(2) to wrap the whole task group so it actually bounds the task-group exit (was guarding a no-op sleep); drop the sleep(0) stub (python:S7491). - Type _wake_on's wait_fn as Callable[[], Awaitable[object]]. - Note in _wire_vector_sync_state why provision_signal is set on the singleton only, not fanned out to app.state. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
3f09453926
commit
79d9d62e6a
@@ -134,7 +134,7 @@ async def test_user_manager_wakes_on_provision_signal(mocker):
|
||||
shutdown_event,
|
||||
scanner_wake_event,
|
||||
storage,
|
||||
"http://nextcloud",
|
||||
"https://nextcloud",
|
||||
user_states,
|
||||
tg,
|
||||
provision_signal,
|
||||
@@ -163,32 +163,36 @@ async def test_user_manager_shutdown_still_breaks_sleep(mocker):
|
||||
mocker.patch(
|
||||
"nextcloud_mcp_server.vector.oauth_sync.get_settings", return_value=settings
|
||||
)
|
||||
|
||||
async def _unused_scanner(*args, **kwargs):
|
||||
# No users provisioned, so this is never called; keep a harmless stub.
|
||||
return None
|
||||
|
||||
mocker.patch(
|
||||
"nextcloud_mcp_server.vector.oauth_sync._run_user_scanner_with_scope",
|
||||
# No users provisioned, so this is never called; keep a harmless stub.
|
||||
lambda *a, **k: anyio.sleep(0),
|
||||
_unused_scanner,
|
||||
)
|
||||
|
||||
storage = _FakeStorage(set())
|
||||
shutdown_event = anyio.Event()
|
||||
|
||||
async with anyio.create_task_group() as tg:
|
||||
await tg.start(
|
||||
user_manager_task,
|
||||
None,
|
||||
shutdown_event,
|
||||
anyio.Event(),
|
||||
storage,
|
||||
"http://nextcloud",
|
||||
{},
|
||||
tg,
|
||||
ProvisionSignal(),
|
||||
)
|
||||
await anyio.sleep(0.05) # let it enter the sleep
|
||||
shutdown_event.set()
|
||||
# If shutdown didn't break the 1000s sleep, fail_after would trip.
|
||||
with anyio.fail_after(2):
|
||||
await anyio.sleep(0) # task group exit below is the real assertion
|
||||
# fail_after wraps the whole task group: if shutdown_event doesn't break the
|
||||
# 1000s sleep, the task group never exits and the 2s deadline trips.
|
||||
with anyio.fail_after(2):
|
||||
async with anyio.create_task_group() as tg:
|
||||
await tg.start(
|
||||
user_manager_task,
|
||||
None,
|
||||
shutdown_event,
|
||||
anyio.Event(),
|
||||
storage,
|
||||
"https://nextcloud",
|
||||
{},
|
||||
tg,
|
||||
ProvisionSignal(),
|
||||
)
|
||||
await anyio.sleep(0.05) # let it enter the sleep
|
||||
shutdown_event.set()
|
||||
|
||||
|
||||
# ── notify_user_provisioned no-op guard ──────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user