Files
cli-command-memory/tests/test_generator.py
7000pctAUTO ed5d19158f
Some checks failed
CI / test (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
feat: add more tests for generator, patterns, recorder, and search
2026-01-31 10:30:01 +00:00

115 lines
2.6 KiB
Python

"""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)