44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
import contextlib
|
|
import io
|
|
import pathlib
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from loop_effects.doubles import FakeEffects
|
|
from claude_release import main
|
|
from claude_home.home import SIGNED_OUT
|
|
|
|
|
|
class ClaudeRelease(unittest.TestCase):
|
|
def run_main(self, args: list[str], fake: FakeEffects) -> tuple[int, str]:
|
|
err = io.StringIO()
|
|
with contextlib.redirect_stderr(err):
|
|
return main.main(args, pathlib.Path("/project"), fake.effects()), err.getvalue()
|
|
|
|
def test_passes_every_argument_on_to_claude_in_the_folder_it_runs_in(self):
|
|
fake = FakeEffects(on_terminal_claude=[0])
|
|
code, err = self.run_main(["--resume", "abc", "--model", "opus", "-p", "hi"], fake)
|
|
self.assertEqual((code, err, fake.made("claude_on_terminal"), fake.terminal_folders), (0, "", [["--resume", "abc", "--model", "opus", "-p", "hi"]], ["/project"]))
|
|
# The effect adds the home and the tools' PATH to the environment; the command adds nothing of its own.
|
|
self.assertEqual(fake.terminal_environments, [{}])
|
|
|
|
def test_exits_with_the_code_of_claude(self):
|
|
self.assertEqual(self.run_main([], FakeEffects(on_terminal_claude=[3]))[0], 3)
|
|
|
|
def test_opens_claude_where_nobody_is_signed_in_yet_for_the_login_typed_there(self):
|
|
fake = FakeEffects(on_terminal_claude=[0])
|
|
fake.home_unready = f"{SIGNED_OUT}; run `CLAUDE_CONFIG_DIR=/h claude` and type /login there, once"
|
|
self.assertEqual((self.run_main([], fake)[0], len(fake.made("claude_on_terminal"))), (0, 1))
|
|
|
|
def test_stops_where_the_home_cannot_be_built(self):
|
|
fake = FakeEffects()
|
|
fake.home_unready = "could not build the loop's Claude home, /h: disk full"
|
|
code, err = self.run_main(["--resume"], fake)
|
|
self.assertEqual((code, err, fake.made("claude_on_terminal")), (1, "could not build the loop's Claude home, /h: disk full\n", []))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|