b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
"""Cross-platform regression for the deferred-SIGINT re-delivery in sync-back.
|
|
|
|
``_sync_back_once`` defers a Ctrl+C that lands mid-sync, then re-delivers it once
|
|
the sync completes. It must do so via ``signal.raise_signal`` — which invokes the
|
|
handler through C ``raise()`` on every platform — and NOT via
|
|
``os.kill(os.getpid(), signal.SIGINT)``: on Windows the latter routes SIGINT (2)
|
|
to ``TerminateProcess`` and hard-kills the whole CLI instead of raising
|
|
``KeyboardInterrupt``.
|
|
|
|
Unlike ``test_file_sync_back.py`` this module does not depend on ``fcntl`` (the
|
|
locked sync body is stubbed), so it runs on Windows too — the platform the bug
|
|
actually manifests on.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import signal
|
|
|
|
from tools.environments.file_sync import FileSyncManager
|
|
|
|
|
|
def _make_manager() -> FileSyncManager:
|
|
return FileSyncManager(
|
|
get_files_fn=lambda: {},
|
|
upload_fn=lambda *a, **k: None,
|
|
delete_fn=lambda *a, **k: None,
|
|
)
|
|
|
|
|
|
def test_deferred_sigint_redelivered_via_raise_signal(tmp_path, monkeypatch):
|
|
mgr = _make_manager()
|
|
|
|
# Simulate a Ctrl+C arriving during the sync body: invoke the deferring
|
|
# handler that _sync_back_once installed, so `deferred_sigint` is populated.
|
|
def fake_locked(lock_path):
|
|
signal.getsignal(signal.SIGINT)(signal.SIGINT, None)
|
|
|
|
monkeypatch.setattr(mgr, "_sync_back_locked", fake_locked)
|
|
|
|
raised: list[int] = []
|
|
killed: list[tuple[int, int]] = []
|
|
monkeypatch.setattr(
|
|
"tools.environments.file_sync.signal.raise_signal", raised.append
|
|
)
|
|
monkeypatch.setattr(
|
|
"tools.environments.file_sync.os.kill",
|
|
lambda pid, sig: killed.append((pid, sig)),
|
|
)
|
|
|
|
mgr._sync_back_once(tmp_path / "sync.lock")
|
|
|
|
# The deferred Ctrl+C is re-delivered cross-platform via raise_signal,
|
|
assert raised == [signal.SIGINT]
|
|
# and never through os.kill(getpid, SIGINT) (which hard-kills on Windows).
|
|
assert (os.getpid(), signal.SIGINT) not in killed
|