Files
honey-biscuit-workshop/tests/probes/process.py
T
Catty Steve 84b3b7d8e8 test: add Docker-based system test infrastructure
Adds a complete pytest system test suite for the HoneyBiscuitWorkshop
CI/CD system:

- runner.sh: orchestrates build, Docker image creation, and test
  execution
- Dockerfile: Arch Linux-based test image with Python venv
- conftest.py: shared fixtures (baker_bin, run_baker, work_dir, llm_env)
- probes/: environment probes for checking users, files, packages,
  processes
- llm/: LLM-based log judgment system with caching for semantic test
  evaluation
- fixtures/: test configs and scripts for prebake, bake, and finalize
  stages
- test_prebake.py, test_bake.py, test_finalize.py: test suites for each
  pipeline stage

Also refactors finalize.yml.tmpl notification config to use a templates
system.
2026-04-24 15:54:56 +08:00

45 lines
1.3 KiB
Python

"""Process existence probes."""
import os
import subprocess
def process_running(process_name: str) -> bool:
"""Check if a process with the given name is running."""
try:
result = subprocess.run(
["pgrep", "-x", process_name],
capture_output=True,
text=True,
)
return result.returncode == 0
except FileNotFoundError:
# Fall back to /proc scan if pgrep not available
try:
for pid_dir in os.listdir("/proc"):
if pid_dir.isdigit():
try:
with open(f"/proc/{pid_dir}/comm") as f:
if f.read().strip() == process_name:
return True
except (IOError, OSError):
continue
except OSError:
pass
return False
def process_count(process_name: str) -> int:
"""Count processes with the given name."""
try:
result = subprocess.run(
["pgrep", "-c", "-x", process_name],
capture_output=True,
text=True,
)
if result.returncode == 0:
return int(result.stdout.strip())
return 0
except (FileNotFoundError, ValueError):
return 0