From 85f6c01bb79f985bdc45daa8212a3b5576280f0d Mon Sep 17 00:00:00 2001 From: Tayar <358041433+lucastayaralvarenga-ui@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:24:51 -0300 Subject: [PATCH 1/3] save_keys: reject negative compose counts --- tests/test_save_keys.py | 10 ++++++++++ tools/save_keys.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/tests/test_save_keys.py b/tests/test_save_keys.py index d50996fe9..aa015c8a2 100644 --- a/tests/test_save_keys.py +++ b/tests/test_save_keys.py @@ -48,6 +48,16 @@ class HashFamilies(unittest.TestCase): class Resolve(unittest.TestCase): + def test_rejects_negative_compose_count(self): + with tempfile.TemporaryDirectory() as tmp: + tool = os.path.join(ROOT, "tools", "save_keys.py") + result = subprocess.run( + [sys.executable, "-I", tool, "resolve", tmp, "--dict", tmp, "--compose", "-1"], + capture_output=True, text=True, + ) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("--compose must be 0 or more", result.stderr) + def setUp(self): self.tmp = tempfile.TemporaryDirectory() self.dir = self.tmp.name diff --git a/tools/save_keys.py b/tools/save_keys.py index a5280b9cc..4d090642f 100644 --- a/tools/save_keys.py +++ b/tools/save_keys.py @@ -337,6 +337,8 @@ def main(argv=None): r.add_argument("--compose", type=int, default=0, metavar="N") r.add_argument("--out") a = ap.parse_args(argv) + if a.cmd == "resolve" and a.compose < 0: + r.error("--compose must be 0 or more") return {"collect": cmd_collect, "resolve": cmd_resolve}[a.cmd](a) or 0 From 7ee2879342814756948799514717710b7996f9fd Mon Sep 17 00:00:00 2001 From: Tayar <358041433+lucastayaralvarenga-ui@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:25:14 -0300 Subject: [PATCH 2/3] test: use a valid dictionary for compose validation --- tests/test_save_keys.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_save_keys.py b/tests/test_save_keys.py index aa015c8a2..ba61d45c4 100644 --- a/tests/test_save_keys.py +++ b/tests/test_save_keys.py @@ -51,8 +51,11 @@ class Resolve(unittest.TestCase): def test_rejects_negative_compose_count(self): with tempfile.TemporaryDirectory() as tmp: tool = os.path.join(ROOT, "tools", "save_keys.py") + words = os.path.join(tmp, "words.txt") + with open(words, "w", encoding="utf-8") as f: + f.write("SyntheticWord\n") result = subprocess.run( - [sys.executable, "-I", tool, "resolve", tmp, "--dict", tmp, "--compose", "-1"], + [sys.executable, "-I", tool, "resolve", tmp, "--dict", words, "--compose", "-1"], capture_output=True, text=True, ) self.assertEqual(result.returncode, 2, result.stderr) From 7ed1cf1e606b23b2b7539409b2db7c92dd3e7ebd Mon Sep 17 00:00:00 2001 From: Tayar <358041433+lucastayaralvarenga-ui@users.noreply.github.com> Date: Sun, 22 Nov 2026 11:40:59 -0300 Subject: [PATCH 3/3] tests: reuse the save key resolve CLI fixture --- tests/test_save_keys.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/test_save_keys.py b/tests/test_save_keys.py index ba61d45c4..906b7c6a0 100644 --- a/tests/test_save_keys.py +++ b/tests/test_save_keys.py @@ -48,19 +48,6 @@ class HashFamilies(unittest.TestCase): class Resolve(unittest.TestCase): - def test_rejects_negative_compose_count(self): - with tempfile.TemporaryDirectory() as tmp: - tool = os.path.join(ROOT, "tools", "save_keys.py") - words = os.path.join(tmp, "words.txt") - with open(words, "w", encoding="utf-8") as f: - f.write("SyntheticWord\n") - result = subprocess.run( - [sys.executable, "-I", tool, "resolve", tmp, "--dict", words, "--compose", "-1"], - capture_output=True, text=True, - ) - self.assertEqual(result.returncode, 2, result.stderr) - self.assertIn("--compose must be 0 or more", result.stderr) - def setUp(self): self.tmp = tempfile.TemporaryDirectory() self.dir = self.tmp.name @@ -156,6 +143,11 @@ class Resolve(unittest.TestCase): self.assertNotIn("Traceback", r.stderr) self.assertEqual(r.stdout, "") # refused before the resolve ran + def test_rejects_negative_compose_count(self): + result = self.resolve_cli(self.dir, "--dict", self.dict, "--compose", "-1") + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("--compose must be 0 or more", result.stderr) + def test_compose_finds_two_word_names(self): text = run(["resolve", self.jsav, "--dict", self.dict, "--compose", "50"]) self.assertIn("joaat, composed 1 more keys", text) # SprocketCount from Sprocket + Count