Add init command and first-run guidance flow
This commit is contained in:
parent
e262b26db7
commit
706d9e2da7
2 changed files with 38 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import io
|
||||
import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
|
@ -53,6 +54,39 @@ class AmanCliTests(unittest.TestCase):
|
|||
self.assertEqual(exit_code, 2)
|
||||
self.assertIn("[FAIL] config.load", out.getvalue())
|
||||
|
||||
def test_init_command_creates_default_config(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
args = aman._parse_cli_args(["init", "--config", str(path)])
|
||||
|
||||
exit_code = aman._init_command(args)
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertTrue(path.exists())
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
self.assertIn("daemon", payload)
|
||||
|
||||
def test_init_command_refuses_overwrite_without_force(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text('{"daemon":{"hotkey":"Super+m"}}\n', encoding="utf-8")
|
||||
args = aman._parse_cli_args(["init", "--config", str(path)])
|
||||
|
||||
exit_code = aman._init_command(args)
|
||||
self.assertEqual(exit_code, 1)
|
||||
self.assertIn("Super+m", path.read_text(encoding="utf-8"))
|
||||
|
||||
def test_init_command_force_overwrites_existing_config(self):
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text('{"daemon":{"hotkey":"Super+m"}}\n', encoding="utf-8")
|
||||
args = aman._parse_cli_args(["init", "--config", str(path), "--force"])
|
||||
|
||||
exit_code = aman._init_command(args)
|
||||
self.assertEqual(exit_code, 0)
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
self.assertEqual(payload["daemon"]["hotkey"], "Cmd+m")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue