Skip to content

Commit ed48372

Browse files
tests: replace os.system with subprocess.run to avoid shell usage and improve safety (#45)
- Refactor git initialization in fake_memory_dir fixture to use subprocess for better error handling.
1 parent ba7465e commit ed48372

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

tests/test_migrate_openclaw.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Tests for palinode.migration.openclaw — OpenClaw MEMORY.md import."""
22
from __future__ import annotations
33

4-
import os
4+
import subprocess
55
import textwrap
66
from datetime import UTC
77
from pathlib import Path
88
from unittest.mock import patch
99

1010
import pytest
11+
import yaml as _yaml
1112

1213
from palinode.migration.openclaw import (
1314
_detect_type,
@@ -49,12 +50,23 @@ def memory_md_file(tmp_path: Path) -> Path:
4950

5051
@pytest.fixture()
5152
def fake_memory_dir(tmp_path: Path) -> Path:
53+
5254
mem = tmp_path / "palinode"
5355
mem.mkdir()
56+
5457
# Minimal git repo so the git commit call doesn't crash
55-
os.system(f"git init -q {mem} 2>/dev/null")
56-
os.system(f"git -C {mem} config user.email 'test@test.com' 2>/dev/null")
57-
os.system(f"git -C {mem} config user.name 'Test' 2>/dev/null")
58+
def run_git(args):
59+
subprocess.run(
60+
["git"] + args,
61+
stdout=subprocess.DEVNULL,
62+
stderr=subprocess.DEVNULL,
63+
check=True
64+
)
65+
66+
run_git(["init","-q",str(mem)])
67+
run_git(["-C",str(mem),"config","user.email","test@test.com"])
68+
run_git(["-C", str(mem), "config", "user.name", "Test"])
69+
5870
return mem
5971

6072

@@ -212,7 +224,6 @@ def test_migration_creates_log_file(
212224
def test_migration_frontmatter_fields(
213225
memory_md_file: Path, fake_memory_dir: Path
214226
) -> None:
215-
import yaml as _yaml
216227

217228
with patch("palinode.migration.openclaw.config") as mock_cfg:
218229
mock_cfg.memory_dir = str(fake_memory_dir)

0 commit comments

Comments
 (0)