60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import io
|
|
import json
|
|
import stat
|
|
import tempfile
|
|
import textwrap
|
|
import unittest
|
|
from contextlib import redirect_stdout
|
|
from pathlib import Path
|
|
|
|
from sssf_opencode.cli import main
|
|
|
|
|
|
REPOSITORY = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class CommandLineTests(unittest.TestCase):
|
|
def test_runs_a_named_phase_and_prints_its_envelope(self):
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
worktree = Path(temp)
|
|
binary = worktree / "fake-opencode"
|
|
binary.write_text(
|
|
textwrap.dedent(
|
|
"""\
|
|
#!/usr/bin/env python3
|
|
import json
|
|
report = json.dumps({"status": "success", "summary": "done"})
|
|
print(json.dumps({"type": "step_start", "sessionID": "ses_cli"}))
|
|
print(json.dumps({"type": "text", "sessionID": "ses_cli", "part": {"text": report}}))
|
|
print(json.dumps({"type": "step_finish", "sessionID": "ses_cli", "part": {"tokens": {}}}))
|
|
"""
|
|
)
|
|
)
|
|
binary.chmod(binary.stat().st_mode | stat.S_IXUSR)
|
|
output = io.StringIO()
|
|
|
|
with redirect_stdout(output):
|
|
exit_code = main(
|
|
[
|
|
"phase",
|
|
"builder",
|
|
"implement the accepted plan",
|
|
"--worktree",
|
|
str(worktree),
|
|
"--config",
|
|
str(REPOSITORY / "factory.json"),
|
|
"--run-id",
|
|
"cli_001",
|
|
"--binary",
|
|
str(binary),
|
|
]
|
|
)
|
|
|
|
self.assertEqual(exit_code, 0)
|
|
self.assertEqual(json.loads(output.getvalue()), {"status": "success", "summary": "done"})
|
|
self.assertTrue((worktree / ".sssf/runs/cli_001/sessions.json").exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|