Fix running background status in s_full

Keep the reference agent's background status output readable by reporting '(running)' instead of leaking a None placeholder for unfinished tasks.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Gujiassh
2026-03-12 15:45:20 +09:00
parent 450185b952
commit 49ab1e6ff8
2 changed files with 68 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
import importlib.util
import os
import sys
import tempfile
import types
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[1]
MODULE_PATH = REPO_ROOT / "agents" / "s_full.py"
def load_s_full_module(temp_cwd: Path):
fake_anthropic = types.ModuleType("anthropic")
class FakeAnthropic:
def __init__(self, *args, **kwargs):
self.messages = types.SimpleNamespace(create=None)
fake_dotenv = types.ModuleType("dotenv")
setattr(fake_anthropic, "Anthropic", FakeAnthropic)
setattr(fake_dotenv, "load_dotenv", lambda override=True: None)
previous_anthropic = sys.modules.get("anthropic")
previous_dotenv = sys.modules.get("dotenv")
previous_cwd = Path.cwd()
spec = importlib.util.spec_from_file_location("s_full_under_test", MODULE_PATH)
if spec is None or spec.loader is None:
raise RuntimeError(f"Unable to load {MODULE_PATH}")
module = importlib.util.module_from_spec(spec)
sys.modules["anthropic"] = fake_anthropic
sys.modules["dotenv"] = fake_dotenv
try:
os.chdir(temp_cwd)
os.environ.setdefault("MODEL_ID", "test-model")
spec.loader.exec_module(module)
return module
finally:
os.chdir(previous_cwd)
if previous_anthropic is None:
sys.modules.pop("anthropic", None)
else:
sys.modules["anthropic"] = previous_anthropic
if previous_dotenv is None:
sys.modules.pop("dotenv", None)
else:
sys.modules["dotenv"] = previous_dotenv
class BackgroundManagerTests(unittest.TestCase):
def test_check_returns_running_placeholder_when_result_is_none(self):
with tempfile.TemporaryDirectory() as tmp:
module = load_s_full_module(Path(tmp))
manager = module.BackgroundManager()
manager.tasks["abc123"] = {
"status": "running",
"command": "sleep 1",
"result": None,
}
self.assertEqual(manager.check("abc123"), "[running] (running)")
if __name__ == "__main__":
unittest.main()