fix: isolate test artifacts from production asset registry
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
- Create tests/test_utils.py with utilities for consistent test workspace management - Fix tests to use project tmp/ directory instead of system /tmp - Ensure all AssetManager instances in tests use isolated registries - Prevent contamination of production asset_registry.json during testing Key changes: - test_issue_142_asset_manager.py: Fix AssetManager() calls to use test workspaces - test_issue_144_batch_import.py: Use create_test_workspace() and get_test_asset_config() - test_issue_145_production_error_handler.py: Use test_workspace() context manager - tests/test_utils.py: New utilities for isolated test environments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -28,26 +28,7 @@ from markitect.assets.deduplicator import AssetDeduplicator
|
||||
from markitect.assets.packager import MarkdownPackager
|
||||
from markitect.assets.exceptions import AssetError, AssetManagerError
|
||||
from markitect.config_manager import ConfigurationManager
|
||||
|
||||
|
||||
@contextmanager
|
||||
def test_workspace():
|
||||
"""Create a test workspace in the project tmp directory."""
|
||||
project_root = Path(__file__).parent.parent
|
||||
temp_dir = project_root / "tmp" / "test_artifacts" / f"test_{int(time.time())}"
|
||||
temp_dir.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
yield temp_dir
|
||||
finally:
|
||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||
|
||||
|
||||
def create_test_workspace():
|
||||
"""Create a test workspace in the project tmp directory."""
|
||||
project_root = Path(__file__).parent.parent
|
||||
temp_dir = project_root / "tmp" / "test_artifacts" / f"test_{int(time.time())}"
|
||||
temp_dir.mkdir(parents=True, exist_ok=True)
|
||||
return temp_dir
|
||||
from tests.test_utils import test_workspace as test_workspace_util, create_test_workspace, get_test_asset_config
|
||||
|
||||
|
||||
class TestAssetManagerInitialization:
|
||||
@@ -78,16 +59,31 @@ class TestAssetManagerInitialization:
|
||||
|
||||
def test_manager_initialization_with_defaults(self):
|
||||
"""Test AssetManager initialization with default configuration."""
|
||||
manager = AssetManager()
|
||||
temp_dir = create_test_workspace()
|
||||
|
||||
# Should use reasonable defaults
|
||||
assert manager.storage_path.name == "assets"
|
||||
assert manager.registry_path.name == "asset_registry.json"
|
||||
assert manager.enable_deduplication is True
|
||||
try:
|
||||
# Change to temp directory to test defaults without contaminating production
|
||||
import os
|
||||
original_cwd = os.getcwd()
|
||||
os.chdir(temp_dir)
|
||||
|
||||
manager = AssetManager()
|
||||
|
||||
# Should use reasonable defaults
|
||||
assert manager.storage_path.name == "assets"
|
||||
assert manager.registry_path.name == "asset_registry.json"
|
||||
assert manager.enable_deduplication is True
|
||||
|
||||
# Verify it's using the test directory, not production
|
||||
assert str(manager.registry_path).startswith(str(temp_dir))
|
||||
|
||||
finally:
|
||||
os.chdir(original_cwd)
|
||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||
|
||||
def test_manager_creates_required_components(self):
|
||||
"""Test that AssetManager creates required component instances."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -103,12 +99,13 @@ class TestAssetManagerInitialization:
|
||||
|
||||
def test_manager_integration_with_config_manager(self):
|
||||
"""Test AssetManager integration with ConfigurationManager."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
# Create config file
|
||||
config_file = Path(temp_dir) / ".markitect.json"
|
||||
config_data = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "custom_assets"),
|
||||
"registry_path": str(temp_dir / "test_registry.json"),
|
||||
"enable_deduplication": False
|
||||
}
|
||||
}
|
||||
@@ -127,7 +124,7 @@ class TestAssetManagerHighLevelOperations:
|
||||
|
||||
def test_add_asset_with_deduplication(self):
|
||||
"""Test adding asset with automatic deduplication."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -151,7 +148,7 @@ class TestAssetManagerHighLevelOperations:
|
||||
|
||||
def test_add_duplicate_asset_detected(self):
|
||||
"""Test that duplicate assets are properly detected and handled."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -180,7 +177,7 @@ class TestAssetManagerHighLevelOperations:
|
||||
|
||||
def test_list_assets_with_metadata(self):
|
||||
"""Test listing all assets with their metadata."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -210,7 +207,7 @@ class TestAssetManagerHighLevelOperations:
|
||||
|
||||
def test_get_asset_info_by_hash(self):
|
||||
"""Test retrieving detailed asset information by content hash."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -237,7 +234,7 @@ class TestAssetManagerHighLevelOperations:
|
||||
|
||||
def test_remove_asset_by_hash(self):
|
||||
"""Test removing asset by content hash."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -269,7 +266,7 @@ class TestAssetManagerPackaging:
|
||||
|
||||
def test_create_document_package(self):
|
||||
"""Test creating complete document package with assets."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -312,7 +309,7 @@ This document has assets:
|
||||
|
||||
def test_extract_document_package_to_workspace(self):
|
||||
"""Test extracting package to workspace with proper asset linking."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -344,7 +341,7 @@ This document has assets:
|
||||
|
||||
def test_package_with_custom_options(self):
|
||||
"""Test package creation with custom options and exclude patterns."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -388,7 +385,7 @@ class TestAssetManagerErrorHandling:
|
||||
|
||||
def test_add_nonexistent_asset_raises_error(self):
|
||||
"""Test that adding non-existent asset raises appropriate error."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -405,7 +402,7 @@ class TestAssetManagerErrorHandling:
|
||||
|
||||
def test_get_info_for_nonexistent_asset_raises_error(self):
|
||||
"""Test that getting info for non-existent asset raises error."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -420,7 +417,7 @@ class TestAssetManagerErrorHandling:
|
||||
|
||||
def test_manager_logs_operations(self):
|
||||
"""Test that AssetManager logs important operations."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -454,7 +451,7 @@ class TestAssetManagerErrorHandling:
|
||||
def test_configuration_validation_errors(self):
|
||||
"""Test that invalid configuration raises appropriate errors."""
|
||||
# Invalid storage path (file instead of directory)
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
invalid_file = Path(temp_dir) / "not_a_directory.txt"
|
||||
invalid_file.write_text("This is a file")
|
||||
|
||||
@@ -474,7 +471,7 @@ class TestAssetManagerWorkflows:
|
||||
|
||||
def test_complete_document_workflow(self):
|
||||
"""Test complete workflow: add assets, create package, extract elsewhere."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -524,7 +521,7 @@ Assets:
|
||||
|
||||
def test_asset_sharing_between_packages(self):
|
||||
"""Test that assets can be shared between different packages."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
@@ -573,7 +570,7 @@ Assets:
|
||||
|
||||
def test_performance_requirements_met(self):
|
||||
"""Test that operations complete within performance requirements (<100ms)."""
|
||||
with test_workspace() as temp_dir:
|
||||
with test_workspace_util() as temp_dir:
|
||||
config = {
|
||||
"assets": {
|
||||
"storage_path": str(temp_dir / "assets"),
|
||||
|
||||
Reference in New Issue
Block a user