import os import tempfile import pytest from cli_memory.config import Config @pytest.fixture def temp_dir(): """Provide a temporary directory.""" with tempfile.TemporaryDirectory() as tmpdir: yield tmpdir @pytest.fixture def config(temp_dir): """Provide a Config instance.""" return Config() @pytest.fixture def sample_project_data(): """Provide sample project data.""" return { "name": "test-project", "path": "/tmp/test", "git_remote": "https://github.com/user/test.git", "tech_stack": ["python", "docker"], } @pytest.fixture def sample_command_data(): """Provide sample command data.""" return { "command": "git status", "command_type": "git", "exit_code": 0, "duration_ms": 50, "working_directory": "/home/user/project", "tags": ["git", "status"], } @pytest.fixture def sample_workflow_data(): """Provide sample workflow data.""" return { "name": "Test Workflow", "description": "A test workflow", "commands": [ {"command": "git status", "command_type": "git"}, {"command": "git add .", "command_type": "git"}, ], } @pytest.fixture def env_override(): """Provide environment variable override context.""" original_env = os.environ.copy() yield os.environ.clear() os.environ.update(original_env) @pytest.fixture def sample_docker_yaml(): """Provide sample Docker YAML content for testing.""" return """version: \"1.0\" description: Docker command patterns patterns: - name: list_containers description: List running containers patterns: - list running containers - show running containers - list containers - show all containers - docker ps template: docker ps explanation: Lists all running containers with their IDs, images, and status. - name: run_container description: Run a new container patterns: - run a container - start a new container - run docker container - docker run template: docker run -d --name {name} {image} explanation: Starts a new detached container with the specified image. - name: stop_container description: Stop a running container patterns: - stop container - stop docker container - stop running container template: docker stop {container} explanation: Stops the specified running container. """ @pytest.fixture def sample_git_yaml(): """Provide sample Git YAML content for testing.""" return """version: \"1.0\" description: Git command patterns patterns: - name: git_status description: Show working tree status patterns: - git status - check status - show changes template: git status explanation: Shows the current status of the working directory. - name: git_add description: Add file contents to index patterns: - add file - stage file - git add template: git add {file} explanation: Adds file contents to the staging area. - name: git_commit description: Commit changes patterns: - commit changes - make commit - git commit template: git commit -m \"{message}\" explanation: Records changes in the repository with a message. """ @pytest.fixture def sample_corrections_json(): """Provide sample corrections JSON for testing.""" return { "version": "1.0", "corrections": { "custom:my custom query": "echo custom command" } }