Skip to content

Commit de2f03a

Browse files
authored
Merge pull request #77 from Gujiassh/fix/s-full-follow-up
Fix running background status in s_full
2 parents 1e85c99 + 49ab1e6 commit de2f03a

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

agents/s_full.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def _exec(self, tid: str, command: str, timeout: int):
351351
def check(self, tid: str = None) -> str:
352352
if tid:
353353
t = self.tasks.get(tid)
354-
return f"[{t['status']}] {t.get('result', '(running)')}" if t else f"Unknown: {tid}"
354+
return f"[{t['status']}] {t.get('result') or '(running)'}" if t else f"Unknown: {tid}"
355355
return "\n".join(f"{k}: [{v['status']}] {v['command'][:60]}" for k, v in self.tasks.items()) or "No bg tasks."
356356

357357
def drain(self) -> list:

tests/test_s_full_background.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import importlib.util
2+
import os
3+
import sys
4+
import tempfile
5+
import types
6+
import unittest
7+
from pathlib import Path
8+
9+
10+
REPO_ROOT = Path(__file__).resolve().parents[1]
11+
MODULE_PATH = REPO_ROOT / "agents" / "s_full.py"
12+
13+
14+
def load_s_full_module(temp_cwd: Path):
15+
fake_anthropic = types.ModuleType("anthropic")
16+
17+
class FakeAnthropic:
18+
def __init__(self, *args, **kwargs):
19+
self.messages = types.SimpleNamespace(create=None)
20+
21+
fake_dotenv = types.ModuleType("dotenv")
22+
setattr(fake_anthropic, "Anthropic", FakeAnthropic)
23+
setattr(fake_dotenv, "load_dotenv", lambda override=True: None)
24+
25+
previous_anthropic = sys.modules.get("anthropic")
26+
previous_dotenv = sys.modules.get("dotenv")
27+
previous_cwd = Path.cwd()
28+
spec = importlib.util.spec_from_file_location("s_full_under_test", MODULE_PATH)
29+
if spec is None or spec.loader is None:
30+
raise RuntimeError(f"Unable to load {MODULE_PATH}")
31+
module = importlib.util.module_from_spec(spec)
32+
33+
sys.modules["anthropic"] = fake_anthropic
34+
sys.modules["dotenv"] = fake_dotenv
35+
try:
36+
os.chdir(temp_cwd)
37+
os.environ.setdefault("MODEL_ID", "test-model")
38+
spec.loader.exec_module(module)
39+
return module
40+
finally:
41+
os.chdir(previous_cwd)
42+
if previous_anthropic is None:
43+
sys.modules.pop("anthropic", None)
44+
else:
45+
sys.modules["anthropic"] = previous_anthropic
46+
if previous_dotenv is None:
47+
sys.modules.pop("dotenv", None)
48+
else:
49+
sys.modules["dotenv"] = previous_dotenv
50+
51+
52+
class BackgroundManagerTests(unittest.TestCase):
53+
def test_check_returns_running_placeholder_when_result_is_none(self):
54+
with tempfile.TemporaryDirectory() as tmp:
55+
module = load_s_full_module(Path(tmp))
56+
manager = module.BackgroundManager()
57+
manager.tasks["abc123"] = {
58+
"status": "running",
59+
"command": "sleep 1",
60+
"result": None,
61+
}
62+
63+
self.assertEqual(manager.check("abc123"), "[running] (running)")
64+
65+
66+
if __name__ == "__main__":
67+
unittest.main()

0 commit comments

Comments
 (0)