Validate providers and retain complete run debugging context
This commit is contained in:
@@ -16,6 +16,35 @@ spec.loader.exec_module(setup)
|
||||
|
||||
|
||||
class DockerSetupTests(unittest.TestCase):
|
||||
def test_provider_validation_failure_preserves_saved_model(self):
|
||||
for report in ['{"healthy":false,"diagnostic":"quota exhausted","session_id":"ses_failed"}',
|
||||
'{"healthy":true}', '[]', 'not-json']:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path=Path(directory,".env")
|
||||
path.write_text("PIPELINES_DEFAULT_MODEL=fixture/previous\nCUSTOM=keep\n")
|
||||
before=path.read_bytes()
|
||||
calls=[]
|
||||
def runner(command,**kwargs):
|
||||
calls.append(command)
|
||||
out="fixture/new\n" if command[-1:]==["models"] else report
|
||||
return subprocess.CompletedProcess(command,0,stdout=out,stderr="")
|
||||
installer=setup.Setup(directory,runner=runner)
|
||||
with patch("sys.stderr"),self.assertRaises(ValueError):
|
||||
installer.validate_provider(setup.arguments(["--model","fixture/new"]))
|
||||
self.assertEqual(before,path.read_bytes())
|
||||
self.assertTrue(any("provider-check" in command for command in calls))
|
||||
|
||||
def test_unavailable_model_does_not_attempt_generation(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
Path(directory,".env").write_text("CUSTOM=keep\n")
|
||||
calls=[]
|
||||
def runner(command,**kwargs):
|
||||
calls.append(command)
|
||||
return subprocess.CompletedProcess(command,0,stdout="fixture/available\n",stderr="")
|
||||
with self.assertRaises(ValueError):
|
||||
setup.Setup(directory,runner=runner).validate_provider(setup.arguments(["--model","fixture/unavailable"]))
|
||||
self.assertFalse(any("provider-check" in command for command in calls))
|
||||
|
||||
def test_ctrl_c_exits_cleanly_and_retains_configuration(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root=Path(directory);scripts=root/"scripts";scripts.mkdir()
|
||||
@@ -25,6 +54,7 @@ class DockerSetupTests(unittest.TestCase):
|
||||
docker=root/"docker"
|
||||
docker.write_text('#!/bin/sh\ncase "$*" in *" up "*) touch "'+str(marker)+'"; exec sleep 30;; esac\n')
|
||||
docker.chmod(0o700)
|
||||
go=root/"go";go.write_text('#!/bin/sh\nexit 0\n');go.chmod(0o700)
|
||||
process=subprocess.Popen([sys.executable,str(scripts/"setup-docker.py"),
|
||||
"--ntfy-url","http://192.168.1.25:8090","--bind-address","192.168.1.25","--timezone","UTC"],
|
||||
env=dict(os.environ,PATH=str(root)+os.pathsep+os.environ["PATH"]),
|
||||
@@ -81,7 +111,11 @@ class DockerSetupTests(unittest.TestCase):
|
||||
calls.append(args)
|
||||
code, out = 0, ""
|
||||
if args[-4:] == ["auth", "list", "--format", "json"]:
|
||||
out = '[{"connections":[{"id":"fixture"}]}]' if logged else '[]'
|
||||
out = '[{"id":"fixture","connections":[{"id":"fixture"}]}]' if logged else '[]'
|
||||
if args[-1:] == ["models"]:
|
||||
out = "fixture/test-model\n"
|
||||
if "provider-check" in args:
|
||||
out = '{"healthy":true,"session_id":"ses_fixture"}'
|
||||
if args[-2:] == ["auth", "login"] and confirm == "yes":
|
||||
logged = True
|
||||
if "token" in args:
|
||||
@@ -96,8 +130,9 @@ class DockerSetupTests(unittest.TestCase):
|
||||
|
||||
args = setup.arguments([] if existing else ["--ntfy-url", "http://192.168.1.20:8090",
|
||||
"--bind-address", "192.168.1.20", "--timezone", "Europe/London"])
|
||||
installer = setup.Setup(directory, runner=runner)
|
||||
installer.run(args)
|
||||
installer = setup.Setup(directory, runner=runner, prompt=lambda _: "1")
|
||||
with patch.object(setup.lan,"detect_lan",return_value="192.168.1.20"):
|
||||
installer.run(args)
|
||||
return calls, token
|
||||
|
||||
def test_fresh_setup_wires_notifications_and_runs_container_login(self):
|
||||
@@ -133,7 +168,7 @@ class DockerSetupTests(unittest.TestCase):
|
||||
self.assertTrue(Path(directory, "secrets/ntfy-token.txt").stat().st_size)
|
||||
|
||||
def test_status_and_publication_failures_are_not_success(self):
|
||||
for failure in ["status", "sh"]:
|
||||
for failure in ["status", "sh", "provider-check"]:
|
||||
with tempfile.TemporaryDirectory() as directory, self.assertRaises(ValueError):
|
||||
self.exercise(directory, fail=failure)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user