Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix: resolve Windows compatibility issues in tests and subprocess execution (#522)

dataproxb8e9ba92c759
diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.py
index b0b3c9e5..e11b0903 100644
--- a/skills/last30days/scripts/lib/env.py
+++ b/skills/last30days/scripts/lib/env.py
@@ -139,11 +139,23 @@ def _load_keychain(keys: list[str]) -> dict[str, str]:
return {}
import subprocess
- import pwd
# USER can be unset under sudo, in Docker without --env USER, or in some CI
# runners; fall back to the OS user record so lookups still match items
# stored by setup-keychain.sh (which uses $USER).
- user = os.environ.get("USER") or pwd.getpwuid(os.getuid()).pw_name
+ user = os.environ.get("USER")
+ if not user:
+ try:
+ import pwd
+ except ImportError:
+ pwd = None
+
+ if pwd is not None:
+ try:
+ user = pwd.getpwuid(os.getuid()).pw_name
+ except AttributeError:
+ user = "unknown"
+ else:
+ user = "unknown"
env: dict[str, str] = {}
for key in keys:
try:
diff --git a/skills/last30days/scripts/lib/subproc.py b/skills/last30days/scripts/lib/subproc.py
index da9e51dd..74e07d1c 100644
--- a/skills/last30days/scripts/lib/subproc.py
+++ b/skills/last30days/scripts/lib/subproc.py
@@ -85,7 +85,7 @@ def run_with_timeout(
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
else:
proc.kill()
- except (ProcessLookupError, PermissionError, OSError):
+ except (ProcessLookupError, PermissionError, OSError, AttributeError):
proc.kill()
proc.wait(timeout=5)
raise SubprocTimeout(f"Command {cmd[0]} timed out after {timeout}s")
diff --git a/tests/test_chrome_cookies.py b/tests/test_chrome_cookies.py
index 6d8ee2e9..a64eb962 100644
--- a/tests/test_chrome_cookies.py
+++ b/tests/test_chrome_cookies.py
@@ -3,6 +3,7 @@
import hashlib
import os
import sqlite3
+import shutil
import subprocess
import tempfile
from pathlib import Path
@@ -10,6 +11,8 @@ from unittest import mock
import pytest
+OPENSSL_AVAILABLE = shutil.which("openssl") is not None
+
from lib.chrome_cookies import (
CHROME_COOKIES_DB,
CHROME_IV_HEX,
@@ -162,6 +165,7 @@ class TestKeyDerivation:
# ---------------------------------------------------------------------------
[email protected](not OPENSSL_AVAILABLE, reason="openssl not installed")
class TestDecryption:
def test_decrypt_v10_roundtrip(self):
"""Encrypt then decrypt — verifies the full pipeline works."""
@@ -232,6 +236,7 @@ class TestKeychainDenied:
# ---------------------------------------------------------------------------
[email protected](not OPENSSL_AVAILABLE, reason="openssl not installed")
class TestOpensslNotFound:
def test_openssl_missing(self):
encrypted = _encrypt_value_v10("test", KNOWN_AES_KEY)
@@ -292,6 +297,7 @@ class TestUnencryptedCookies:
class TestFullExtraction:
+ @pytest.mark.skipif(not OPENSSL_AVAILABLE, reason="openssl not installed")
def test_encrypted_cookies_extracted(self, tmp_path):
"""End-to-end: create DB with real v10-encrypted values, extract them."""
auth_val = "my_auth_token_123"
@@ -330,6 +336,7 @@ class TestFullExtraction:
assert result is None
+ @pytest.mark.skipif(not OPENSSL_AVAILABLE, reason="openssl not installed")
def test_chrome130_db_version_24(self, tmp_path):
"""Chrome 130+ with db_version >= 24 strips SHA-256 prefix."""
auth_val = "token_for_chrome130"
diff --git a/tests/test_cli_v3.py b/tests/test_cli_v3.py
index e3f7bf9d..bb6c6609 100644
--- a/tests/test_cli_v3.py
+++ b/tests/test_cli_v3.py
@@ -55,6 +55,7 @@ class CliV3Tests(unittest.TestCase):
cwd=REPO_ROOT,
capture_output=True,
text=True,
+ encoding="utf-8",
check=False,
)
self.assertEqual(0, result.returncode, result.stderr)
diff --git a/tests/test_footer_nudge_suppression.py b/tests/test_footer_nudge_suppression.py
index f112a706..372beab9 100644
--- a/tests/test_footer_nudge_suppression.py
+++ b/tests/test_footer_nudge_suppression.py
@@ -49,7 +49,7 @@ class FooterNudgeSuppressionTests(unittest.TestCase):
# .claude/last30days.env above the repo on the contributor's machine.
with tempfile.TemporaryDirectory() as tmp:
return subprocess.run(
- cmd, capture_output=True, text=True, env=env, cwd=tmp,
+ cmd, capture_output=True, text=True, encoding="utf-8", env=env, cwd=tmp,
)
def test_bare_run_emits_web_promo(self):
diff --git a/tests/test_last_run_state.py b/tests/test_last_run_state.py
index 58806d11..986bb8c8 100644
--- a/tests/test_last_run_state.py
+++ b/tests/test_last_run_state.py
@@ -4,6 +4,7 @@ import os
import re
import subprocess
import sys
+import shutil
import tempfile
import unittest
from contextlib import redirect_stderr
@@ -24,6 +25,7 @@ def run_last30days(topic: str, env: dict[str, str]) -> subprocess.CompletedProce
env=env,
capture_output=True,
text=True,
+ encoding="utf-8",
check=False,
)
@@ -55,6 +57,7 @@ class LastRunStateTests(unittest.TestCase):
self.assertEqual(payload["topic"], "custom config query")
self.assertGreaterEqual(payload["total"], 0)
+ @unittest.skipIf(shutil.which("bash") is None, "bash not available")
def test_hook_reads_last_run_from_custom_config_dir(self):
with tempfile.TemporaryDirectory() as tmp:
config_dir = Path(tmp) / "custom-config"
diff --git a/tests/test_regression.py b/tests/test_regression.py
index b5f379b7..ded54b48 100644
--- a/tests/test_regression.py
+++ b/tests/test_regression.py
@@ -14,6 +14,7 @@ def run_mock_json(topic: str) -> dict:
cwd=REPO_ROOT,
capture_output=True,
text=True,
+ encoding="utf-8",
check=False,
)
if result.returncode != 0:
diff --git a/tests/test_save_raw_per_entity.py b/tests/test_save_raw_per_entity.py
index 90202280..2370ecc0 100644
--- a/tests/test_save_raw_per_entity.py
+++ b/tests/test_save_raw_per_entity.py
@@ -33,7 +33,7 @@ class PerEntitySaveFilesTests(unittest.TestCase):
*argv,
]
env = {**os.environ, "LAST30DAYS_SKIP_PREFLIGHT": "1"}
- result = subprocess.run(cmd, capture_output=True, text=True, env=env)
+ result = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", env=env)
return result, save_dir
def test_vs_mode_produces_per_entity_files(self):
diff --git a/tests/test_setup_openclaw.py b/tests/test_setup_openclaw.py
index 18a4001e..f0c0b840 100644
--- a/tests/test_setup_openclaw.py
+++ b/tests/test_setup_openclaw.py
@@ -62,7 +62,7 @@ class TestRunOpenclawSetup:
def test_openclaw_metadata_keeps_scrapecreators_optional(self):
"""OpenClaw metadata should not hard-require the ScrapeCreators key."""
skill_md = Path(__file__).parent.parent / "skills" / "last30days" / "SKILL.md"
- text = skill_md.read_text()
+ text = skill_md.read_text(encoding="utf-8")
assert "SCRAPECREATORS_API_KEY" in text
expected = (
"requires:\n"
diff --git a/tests/test_subproc.py b/tests/test_subproc.py
index c7067752..faca80cc 100644
--- a/tests/test_subproc.py
+++ b/tests/test_subproc.py
@@ -6,16 +6,39 @@ PID callback wiring, and environment inheritance.
import builtins
import os as real_os
+import platform
import unittest
from unittest.mock import patch
from lib import subproc
+IS_WINDOWS = platform.system() == "Windows"
+
+def get_shell_cmd(cmd_str: str) -> list[str]:
+ if IS_WINDOWS:
+ if cmd_str == "echo hello":
+ return ["cmd", "/c", "echo hello"]
+ elif cmd_str == "exit 3":
+ return ["cmd", "/c", "exit 3"]
+ elif cmd_str == "echo err >&2":
+ return ["cmd", "/c", "echo err 1>&2"]
+ elif cmd_str in ("sleep 10", "sleep 10 & wait"):
+ return ["powershell", "-Command", "Start-Sleep 10"]
+ elif cmd_str == "echo $LAST30DAYS_TEST_VAR":
+ return ["cmd", "/c", "echo %LAST30DAYS_TEST_VAR%"]
+ elif cmd_str == "true":
+ return ["cmd", "/c", "exit 0"]
+ elif cmd_str == "echo ok":
+ return ["cmd", "/c", "echo ok"]
+ else:
+ raise ValueError(f"No Windows command mapping for: {cmd_str}")
+ return ["sh", "-c", cmd_str]
+
class TestRunWithTimeout(unittest.TestCase):
def test_success_returns_stdout(self):
result = subproc.run_with_timeout(
- ["sh", "-c", "echo hello"],
+ get_shell_cmd("echo hello"),
timeout=5,
)
self.assertEqual(result.returncode, 0)
@@ -24,14 +47,14 @@ class TestRunWithTimeout(unittest.TestCase):
def test_nonzero_exit_returns_returncode_not_exception(self):
result = subproc.run_with_timeout(
- ["sh", "-c", "exit 3"],
+ get_shell_cmd("exit 3"),
timeout=5,
)
self.assertEqual(result.returncode, 3)
def test_captures_stderr(self):
result = subproc.run_with_timeout(
- ["sh", "-c", "echo err >&2"],
+ get_shell_cmd("echo err >&2"),
timeout=5,
)
self.assertEqual(result.stderr.strip(), "err")
@@ -39,7 +62,7 @@ class TestRunWithTimeout(unittest.TestCase):
def test_timeout_raises_subproctimeout(self):
with self.assertRaises(subproc.SubprocTimeout):
subproc.run_with_timeout(
- ["sh", "-c", "sleep 10"],
+ get_shell_cmd("sleep 10"),
timeout=1,
)
@@ -49,7 +72,7 @@ class TestRunWithTimeout(unittest.TestCase):
# Parent shell spawns a child that sleeps long.
# Without process-group cleanup, the child would orphan.
subproc.run_with_timeout(
- ["sh", "-c", "sleep 10 & wait"],
+ get_shell_cmd("sleep 10 & wait"),
timeout=1,
)
@@ -63,17 +86,25 @@ class TestRunWithTimeout(unittest.TestCase):
)
def test_env_is_passed_through(self):
+ import os
+ env = {"LAST30DAYS_TEST_VAR": "custom_value"}
+ if IS_WINDOWS:
+ for k in ("SystemRoot", "SystemDrive", "PATH", "COMSPEC", "TEMP", "TMP"):
+ if k in os.environ:
+ env[k] = os.environ[k]
+ else:
+ env["PATH"] = "/usr/bin:/bin"
result = subproc.run_with_timeout(
- ["sh", "-c", "echo $LAST30DAYS_TEST_VAR"],
+ get_shell_cmd("echo $LAST30DAYS_TEST_VAR"),
timeout=5,
- env={"LAST30DAYS_TEST_VAR": "custom_value", "PATH": "/usr/bin:/bin"},
+ env=env,
)
self.assertEqual(result.stdout.strip(), "custom_value")
def test_on_pid_callback_receives_pid(self):
seen_pids = []
subproc.run_with_timeout(
- ["sh", "-c", "true"],
+ get_shell_cmd("true"),
timeout=5,
on_pid=lambda pid: seen_pids.append(pid),
)
@@ -104,7 +135,7 @@ class TestRunWithTimeout(unittest.TestCase):
# Should not raise, callback exception is swallowed.
result = subproc.run_with_timeout(
- ["sh", "-c", "echo ok"],
+ get_shell_cmd("echo ok"),
timeout=5,
on_pid=raising_callback,
)