test_git counts only its own ssh-agents (#172)
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 2m35s
CI / e2e (pull_request) Successful in 3m46s

The unit tier runs under xdist, so another worker's push could start an
ssh-agent between a test's count and its check. The test sshd now tags
every session with NISSE_TEST_SSHD=<its root>, and the tests count only
agents carrying their own sshd's tag. A new test starts a foreign agent
alongside and checks it isn't counted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
This commit is contained in:
dongarandClaude Opus 5.5 committed 2026-10-27 11:52:43 +00:00
1 parent 46730c085c
commit 3632b21135
2 files changed
+48 -9

No files matched your search

+21 -1
View File
@@ -18,6 +18,21 @@ from nisse_core.execution.ssh import SSHHost
SSHD = "/usr/sbin/sshd"
# Set in every session of a local sshd, to its root directory.
SESSION_MARK = "NISSE_TEST_SSHD"
def started_by(host: SSHHost, pid: str) -> bool:
"""Whether process ``pid`` was started in a session of ``host``'s local
sshd: it carries that sshd's SESSION_MARK. A process that's gone, or
another user's, wasn't."""
mark = f"{SESSION_MARK}={host._key.parent}".encode() # the sshd root
try:
environ = Path(f"/proc/{pid}/environ").read_bytes()
except OSError:
return False
return mark in environ.split(b"\0")
def _free_port() -> int:
with socket.socket() as sock:
@@ -61,7 +76,12 @@ def local_sshd(root: Path) -> Iterator[SSHHost]:
"MaxStartups 50",
# Stands in for a provisioned build VM: sessions see the test
# runner's PATH, so its Python and tools are "installed".
f"SetEnv PATH={os.environ.get('PATH', '/usr/bin:/bin')}",
# SESSION_MARK tags every process this sshd starts, so a test
# can tell its own from another worker's (#172).
(
f"SetEnv PATH={os.environ.get('PATH', '/usr/bin:/bin')} "
f"{SESSION_MARK}={root}"
),
"",
]
)