style: apply ruff format across the tree; refresh moved-module doc refs
Bring 14 files that predated the ruff-format run into line with the configured formatter (line-length 100); provably formatting-only (ruff format of HEAD == working tree, and ruff format is semantics-preserving). Also refresh two lim.image.tor._KEYGEN_SCRIPT doc references in tor_harness.py to lim.image.initramfs.keygen after the module moved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
# Matches lim.image.tor._KEYGEN_SCRIPT: an empty -f torrc keeps the host's
|
||||
# Matches lim.image.initramfs.keygen._KEYGEN_SCRIPT: an empty -f torrc keeps the host's
|
||||
# /etc/tor/torrc out of the run, --DisableNetwork 1 makes the keys appear
|
||||
# without ever touching the network.
|
||||
KEYGEN_TIMEOUT = 30
|
||||
@@ -30,7 +30,7 @@ def free_port() -> int:
|
||||
def generate_onion_keys(onion_dir: Path, data_dir: Path) -> str:
|
||||
"""Create v3 onion keys offline; return the .onion hostname.
|
||||
|
||||
Mirrors lim.image.tor._KEYGEN_SCRIPT, run directly on the host instead
|
||||
Mirrors lim.image.initramfs.keygen._KEYGEN_SCRIPT, run directly on the host instead
|
||||
of inside the image chroot (the tor invocation is identical).
|
||||
"""
|
||||
onion_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -39,11 +39,23 @@ def generate_onion_keys(onion_dir: Path, data_dir: Path) -> str:
|
||||
empty_torrc.write_text("")
|
||||
process = subprocess.Popen(
|
||||
[
|
||||
"tor", "-f", str(empty_torrc), "--DisableNetwork", "1",
|
||||
"--DataDirectory", str(data_dir),
|
||||
"--HiddenServiceDir", str(onion_dir),
|
||||
"--HiddenServicePort", "22 127.0.0.1:22",
|
||||
"--SocksPort", "0", "--RunAsDaemon", "0", "--Log", "notice stderr",
|
||||
"tor",
|
||||
"-f",
|
||||
str(empty_torrc),
|
||||
"--DisableNetwork",
|
||||
"1",
|
||||
"--DataDirectory",
|
||||
str(data_dir),
|
||||
"--HiddenServiceDir",
|
||||
str(onion_dir),
|
||||
"--HiddenServicePort",
|
||||
"22 127.0.0.1:22",
|
||||
"--SocksPort",
|
||||
"0",
|
||||
"--RunAsDaemon",
|
||||
"0",
|
||||
"--Log",
|
||||
"notice stderr",
|
||||
],
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
@@ -62,9 +74,7 @@ def generate_onion_keys(onion_dir: Path, data_dir: Path) -> str:
|
||||
return hostname.read_text().strip()
|
||||
|
||||
|
||||
def start_onion_service(
|
||||
torrc_path: Path, socks_port: int, log_path: Path
|
||||
) -> subprocess.Popen:
|
||||
def start_onion_service(torrc_path: Path, socks_port: int, log_path: Path) -> subprocess.Popen:
|
||||
"""Start Tor with the given torrc (service side) plus a SOCKS port.
|
||||
|
||||
The torrc carries the HiddenServiceDir/HiddenServicePort just like the
|
||||
@@ -73,9 +83,13 @@ def start_onion_service(
|
||||
"""
|
||||
return subprocess.Popen(
|
||||
[
|
||||
"tor", "-f", str(torrc_path),
|
||||
"--SocksPort", str(socks_port),
|
||||
"--Log", f"notice file {log_path}",
|
||||
"tor",
|
||||
"-f",
|
||||
str(torrc_path),
|
||||
"--SocksPort",
|
||||
str(socks_port),
|
||||
"--Log",
|
||||
f"notice file {log_path}",
|
||||
],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
@@ -98,11 +112,7 @@ def _socks5_handshake(sock: socket.socket, onion_host: str, onion_port: int) ->
|
||||
if sock.recv(2) != b"\x05\x00":
|
||||
raise RuntimeError("SOCKS5 handshake rejected.")
|
||||
host = onion_host.encode()
|
||||
request = (
|
||||
b"\x05\x01\x00\x03"
|
||||
+ bytes([len(host)]) + host
|
||||
+ struct.pack(">H", onion_port)
|
||||
)
|
||||
request = b"\x05\x01\x00\x03" + bytes([len(host)]) + host + struct.pack(">H", onion_port)
|
||||
sock.settimeout(ONION_CONNECT_TIMEOUT)
|
||||
sock.sendall(request)
|
||||
header = sock.recv(4)
|
||||
|
||||
@@ -24,9 +24,7 @@ def test_every_command_dispatches_to_its_function(monkeypatch):
|
||||
def test_needs_root_command_requests_root(monkeypatch):
|
||||
escalated = []
|
||||
monkeypatch.setattr(system, "ensure_root", lambda: escalated.append(True))
|
||||
monkeypatch.setitem(
|
||||
cli.COMMANDS, "backup", Command(lambda: None, "d", needs_root=True)
|
||||
)
|
||||
monkeypatch.setitem(cli.COMMANDS, "backup", Command(lambda: None, "d", needs_root=True))
|
||||
cli.main(["--type", "backup", "--auto-confirm"])
|
||||
assert escalated == [True]
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ def test_storage_target_derives_all_paths():
|
||||
assert target.partition_path == "/dev/sdb1"
|
||||
|
||||
|
||||
def test_single_drive_setup_command_sequence(
|
||||
fake_runner, answers, block_devices, monkeypatch
|
||||
):
|
||||
def test_single_drive_setup_command_sequence(fake_runner, answers, block_devices, monkeypatch):
|
||||
monkeypatch.setattr("lim.system.real_user", lambda: "kevin")
|
||||
answers("sdb", "N") # device name, skip overwrite
|
||||
|
||||
|
||||
@@ -58,10 +58,19 @@ def test_rsync_command_uses_delete_only_for_directories():
|
||||
directory_op = sync.SyncOperation("src/", "dst/", "backup", is_directory=True)
|
||||
file_op = sync.SyncOperation("src", "dst", "backup", is_directory=False)
|
||||
assert sync.rsync_command(directory_op) == [
|
||||
"rsync", "-abcEPuvW", "--delete", "--backup-dir=backup", "src/", "dst/"
|
||||
"rsync",
|
||||
"-abcEPuvW",
|
||||
"--delete",
|
||||
"--backup-dir=backup",
|
||||
"src/",
|
||||
"dst/",
|
||||
]
|
||||
assert sync.rsync_command(file_op) == [
|
||||
"rsync", "-abcEPuvW", "--backup-dir=backup", "src", "dst"
|
||||
"rsync",
|
||||
"-abcEPuvW",
|
||||
"--backup-dir=backup",
|
||||
"src",
|
||||
"dst",
|
||||
]
|
||||
|
||||
|
||||
@@ -95,18 +104,12 @@ def test_export_chowns_real_home_without_sudo(tmp_path, fake_runner, monkeypatch
|
||||
|
||||
sync.export_to_system()
|
||||
|
||||
chown_calls = [
|
||||
(cmd, sudo) for cmd, sudo in fake_runner.sudo_log if cmd[0] == "chown"
|
||||
]
|
||||
assert chown_calls == [
|
||||
(["chown", "-R", "kevin:kevin", str(real_home)], False)
|
||||
]
|
||||
chown_calls = [(cmd, sudo) for cmd, sudo in fake_runner.sudo_log if cmd[0] == "chown"]
|
||||
assert chown_calls == [(["chown", "-R", "kevin:kevin", str(real_home)], False)]
|
||||
assert (real_home / ".ssh/id_rsa").stat().st_mode & 0o777 == 0o600
|
||||
|
||||
|
||||
def test_execute_sync_plan_creates_folders_and_runs_rsync(
|
||||
tmp_path, fake_runner
|
||||
):
|
||||
def test_execute_sync_plan_creates_folders_and_runs_rsync(tmp_path, fake_runner):
|
||||
operation = sync.SyncOperation(
|
||||
source=str(tmp_path / "src.txt"),
|
||||
destination=str(tmp_path / "deep/nested/dst.txt"),
|
||||
|
||||
Reference in New Issue
Block a user