Files
SeedPass/src/tests/test_secret_mode.py
T
thePR0M3TH3ANandClaude Opus 5 9e0f045ccb Stop the test suite exiting 0 after 10% of its tests
`pytest src/tests` died at 123 of 1170 tests with exit code 0 -- no summary,
no coverage report, and a shell that saw success. Four tests reach code
paths that call os._exit(0), which skips interpreter finalization and takes
pytest with it.

The os._exit is deliberate and stays: some builds with native extensions
intermittently SIGSEGV during teardown after an otherwise clean shutdown,
which is why _exit_as_main_process exists. But that reasoning applies to the
real process exit, not to a function under test. Adds _terminate(), which
raises SystemExit when PYTEST_CURRENT_TEST is set and calls os._exit
otherwise, and routes the three in-process exit paths through it.

This restores a contract the tests already assumed:
test_auto_sync_triggers_post asserts `pytest.raises(SystemExit)`. It was
written when display_menu raised, and the later switch to os._exit did not
fail that test -- it killed the runner instead, which is why nobody noticed.

The suite now runs to completion: 1160 passed, 15 failed, 16 skipped, and it
exits 1 rather than claiming success.

Those 15 were always failing; they were simply never reached. Five of them
were mine, and this is the uncomfortable part: the gen_version argument
added in 2aed95a broke more FakePasswordGenerator doubles than I found,
because the earlier regression run stopped before reaching them and I
concluded "no new failures" from a truncated result. All 20 remaining
doubles now take **_, so they absorb gen_version and anything added later
rather than needing a sweep each time the real signature grows.

The other 10 are pre-existing and unrelated -- legacy-migration and
checksum-backup failures, an index0.py int-parsing bug
(`invalid literal for int() with base 10: 'temp'`), and one that needs a TTY
this environment lacks.

Determinism gate still green.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HtNMsKzzFTPURemX7tT19u
2026-07-31 22:31:19 -04:00

140 lines
4.6 KiB
Python

from pathlib import Path
from tempfile import TemporaryDirectory
from types import SimpleNamespace
from helpers import create_vault, TEST_SEED, TEST_PASSWORD
import sys
sys.path.append(str(Path(__file__).resolve().parents[1]))
from seedpass.core.entry_management import EntryManager
from seedpass.core.backup import BackupManager
from seedpass.core.manager import PasswordManager, EncryptionMode
from seedpass.core.config_manager import ConfigManager
def setup_pm(tmp_path):
vault, enc_mgr = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
cfg_mgr = ConfigManager(vault, tmp_path)
backup_mgr = BackupManager(tmp_path, cfg_mgr)
entry_mgr = EntryManager(vault, backup_mgr)
pm = PasswordManager.__new__(PasswordManager)
pm.encryption_mode = EncryptionMode.SEED_ONLY
pm.encryption_manager = enc_mgr
pm.vault = vault
pm.entry_manager = entry_mgr
pm.backup_manager = backup_mgr
pm.password_generator = SimpleNamespace(generate_password=lambda l, i, **_: "pw")
pm.parent_seed = TEST_SEED
pm.nostr_client = SimpleNamespace()
pm.fingerprint_dir = tmp_path
pm.config_manager = cfg_mgr
pm.secret_mode_enabled = True
pm.clipboard_clear_delay = 5
return pm, entry_mgr
def test_password_retrieve_secret_mode(monkeypatch, capsys):
with TemporaryDirectory() as tmpdir:
tmp = Path(tmpdir)
pm, entry_mgr = setup_pm(tmp)
entry_mgr.add_entry("example", 8)
inputs = iter(["0", "n", ""])
monkeypatch.setattr("builtins.input", lambda *a, **k: next(inputs))
called = []
monkeypatch.setattr(
"seedpass.core.manager.copy_to_clipboard",
lambda text, t: (called.append((text, t)), True)[1],
)
pm.handle_retrieve_entry()
out = capsys.readouterr().out
assert "Password:" not in out
assert "copied to clipboard" in out
assert called == [("pw", 5)]
def test_totp_display_secret_mode(monkeypatch, capsys):
with TemporaryDirectory() as tmpdir:
tmp = Path(tmpdir)
pm, entry_mgr = setup_pm(tmp)
entry_mgr.add_totp("Example", TEST_SEED)
monkeypatch.setattr(
"seedpass.core.totp.TotpManager.current_code_from_secret",
lambda *a, **k: "123456",
)
monkeypatch.setattr(
pm.entry_manager, "get_totp_time_remaining", lambda *a, **k: 30
)
monkeypatch.setattr(
"seedpass.core.manager.timed_input",
lambda *a, **k: (_ for _ in ()).throw(KeyboardInterrupt()),
)
called = []
monkeypatch.setattr(
"seedpass.core.manager.copy_to_clipboard",
lambda text, t: (called.append((text, t)), True)[1],
)
pm.handle_display_totp_codes()
out = capsys.readouterr().out
assert "123456" not in out
assert "copied to clipboard" in out
assert called == [("123456", 5)]
def test_password_retrieve_no_secret_mode(monkeypatch, capsys):
with TemporaryDirectory() as tmpdir:
tmp = Path(tmpdir)
pm, entry_mgr = setup_pm(tmp)
pm.secret_mode_enabled = False
entry_mgr.add_entry("example", 8)
inputs = iter(["0", "n", ""])
monkeypatch.setattr("builtins.input", lambda *a, **k: next(inputs))
called = []
monkeypatch.setattr(
"seedpass.core.manager.copy_to_clipboard",
lambda *a, **k: (called.append((a, k)), True)[1],
)
pm.handle_retrieve_entry()
out = capsys.readouterr().out
assert "Password:" in out
assert "copied to clipboard" not in out
assert called == []
def test_totp_display_no_secret_mode(monkeypatch, capsys):
with TemporaryDirectory() as tmpdir:
tmp = Path(tmpdir)
pm, entry_mgr = setup_pm(tmp)
pm.secret_mode_enabled = False
entry_mgr.add_totp("Example", TEST_SEED)
monkeypatch.setattr(
"seedpass.core.totp.TotpManager.current_code_from_secret",
lambda *a, **k: "123456",
)
monkeypatch.setattr(
pm.entry_manager, "get_totp_time_remaining", lambda *a, **k: 30
)
monkeypatch.setattr(
"seedpass.core.manager.timed_input",
lambda *a, **k: (_ for _ in ()).throw(KeyboardInterrupt()),
)
called = []
monkeypatch.setattr(
"seedpass.core.manager.copy_to_clipboard",
lambda *a, **k: (called.append((a, k)), True)[1],
)
pm.handle_display_totp_codes()
out = capsys.readouterr().out
assert "123456" in out
assert "copied to clipboard" not in out
assert called == []