Skip to content

Commit 125f38a

Browse files
hayamizclaude
andcommitted
test(background): match session-file path to record.go (TMPDIR + real user)
_session_file() hardcoded /tmp and derived the user from $USER, but record.go's sessionFilePath() uses os.TempDir() ($TMPDIR) and user.Current().Username. When $TMPDIR != /tmp or $USER is unset, the helper looked for the wrong path and 5 background tests failed even though the feature works. Mirror the implementation with $TMPDIR and a passwd lookup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 09f817a commit 125f38a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎tests/test_background.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the record --background / --kill / --status options."""
22

33
import os
4+
import pwd
45
import signal
56
import time
67
from pathlib import Path
@@ -10,9 +11,17 @@
1011

1112

1213
def _session_file():
13-
"""Return the expected session file path."""
14-
username = os.environ.get("USER") or os.environ.get("LOGNAME") or "unknown"
15-
return Path("/tmp") / f"perfmonger-{username}-session.pid"
14+
"""Return the expected session file path.
15+
16+
This must mirror sessionFilePath() in core/cmd/perfmonger/record.go:
17+
filepath.Join(os.TempDir(), "perfmonger-<user>-session.pid"), where
18+
os.TempDir() honors $TMPDIR (falling back to /tmp) and <user> is the
19+
current user's name from a passwd lookup (user.Current().Username) — not
20+
the $USER environment variable, which may be unset.
21+
"""
22+
tmpdir = os.environ.get("TMPDIR") or "/tmp"
23+
username = pwd.getpwuid(os.getuid()).pw_name
24+
return Path(tmpdir) / f"perfmonger-{username}-session.pid"
1625

1726

1827
def _cleanup_session():

0 commit comments

Comments
 (0)