From ed5d19158fcfdc329826611635bbb6abcf4a4d6b Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 10:30:01 +0000 Subject: [PATCH] feat: add more tests for generator, patterns, recorder, and search --- tests/test_generator.py | 114 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/test_generator.py diff --git a/tests/test_generator.py b/tests/test_generator.py new file mode 100644 index 0000000..20417f1 --- /dev/null +++ b/tests/test_generator.py @@ -0,0 +1,114 @@ +"""Tests for CLI Command Memory script generator.""" + +import os +from cli_memory.generator import ScriptGenerator +from cli_memory.models import Workflow, Command, CommandType + + +def test_script_generator_init(): + """Test ScriptGenerator initialization.""" + generator = ScriptGenerator() + assert generator is not None + + +def test_generate_script_basic(): + """Test basic script generation.""" + generator = ScriptGenerator() + + workflow = Workflow( + id=1, + name="test-workflow", + description="A test workflow", + commands=[ + Command(command="echo hello"), + Command(command="echo world"), + ], + ) + + script_path = generator.generate_script( + workflow, + name="test-script", + include_error_handling=False, + include_logging=False, + ) + + assert script_path.endswith(".sh") + assert os.path.exists(script_path) + + with open(script_path) as f: + content = f.read() + + assert "#!/bin/bash" in content + assert "echo hello" in content + assert "echo world" in content + + +def test_generate_script_with_error_handling(): + """Test script generation with error handling.""" + generator = ScriptGenerator() + + workflow = Workflow( + id=1, + name="safe-script", + commands=[Command(command="ls -la")], + ) + + script_path = generator.generate_script( + workflow, + include_error_handling=True, + include_logging=False, + ) + + with open(script_path) as f: + content = f.read() + + assert "set -e" in content + + +def test_generate_script_with_logging(): + """Test script generation with logging.""" + generator = ScriptGenerator() + + workflow = Workflow( + id=1, + name="logged-script", + commands=[Command(command="echo test")], + ) + + script_path = generator.generate_script( + workflow, + include_error_handling=False, + include_logging=True, + ) + + with open(script_path) as f: + content = f.read() + + assert "LOG_FILE=" in content + assert "log()" in content + + +def test_list_generated_scripts(): + """Test listing generated scripts.""" + generator = ScriptGenerator() + + scripts = generator.list_generated_scripts() + assert isinstance(scripts, list) + + +def test_generate_from_commands(): + """Test generating script from command list.""" + generator = ScriptGenerator() + + commands = [ + Command(command="echo one"), + Command(command="echo two"), + ] + + script_path = generator.generate_from_commands( + commands, + name="from-commands", + ) + + assert script_path.endswith(".sh") + assert os.path.exists(script_path)