feat(gui): instance unique + mutex partagé installeur (P0-7)

Protection multi-instance GUI V6 : mutex kernel nommé sur Windows (partagé
avec l'installeur Inno via AppMutex), fcntl exclusif sur POSIX (dev/test).
3 tests unitaires, self-test OK, 0 régression gui_v6 (145 passed).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 18:01:28 +02:00
parent d4891f5cfd
commit 6476fe9f98
3 changed files with 120 additions and 2 deletions

View File

@@ -0,0 +1,33 @@
import pytest
from gui_v6.single_instance import (
APP_MUTEX_NAME,
AlreadyRunningError,
SingleInstance,
)
def test_mutex_name_is_stable():
# Nom partagé avec l'installeur (Inno AppMutex). Ne pas changer sans MAJ .iss.
assert APP_MUTEX_NAME == "AivanonymAnonymisationV6"
def test_second_instance_is_rejected(tmp_path, monkeypatch):
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
first = SingleInstance()
first.acquire()
try:
with pytest.raises(AlreadyRunningError):
SingleInstance().acquire()
finally:
first.release()
def test_release_allows_reacquire(tmp_path, monkeypatch):
monkeypatch.setenv("LOCALAPPDATA", str(tmp_path))
a = SingleInstance()
a.acquire()
a.release()
b = SingleInstance()
b.acquire() # ne lève pas
b.release()