"""Unit tests for stockout monitoring and automatic inventory replenishment lifecycle.""" import pytest from warehouse_twin.domain.inventory import InventoryCatalog, InventoryItem from warehouse_twin.domain.task import Task, TaskPriority, TaskStatus, TaskType from warehouse_twin.domain.warehouse import WarehouseDimensions, WarehouseModel from warehouse_twin.simulation.order_generator import OrderGenerator, WorkloadConfig @pytest.fixture def test_catalog(): return InventoryCatalog( items={ "SKU-OIL-001": InventoryItem( item_id="SKU-OIL-001", name="Hydraulic Oil Filter", category="hydraulic_filters", zone="zone_a", storage_location="rack_a_01", initial_stock=10, current_stock=0, # Out of stock reserved_stock=0, minimum_stock=5, replenishment_batch=20, unit_weight_kg=1.8, ) } ) @pytest.fixture def warehouse_model(): return WarehouseModel( dimensions=WarehouseDimensions(width=60.0, depth=40.0, height=8.0), zones={}, stations={}, charging_stations={}, storage_locations={}, ) def test_stockout_detection_and_replenishment(test_catalog, warehouse_model): generator = OrderGenerator(WorkloadConfig(), test_catalog, warehouse_model) item = test_catalog.items["SKU-OIL-001"] # Stock is 0 -> should report out of stock assert item.available_quantity == 0 assert item.needs_replenishment() is True # Generate replenishment task repl_task = generator.generate_replenishment_task(item, sim_time=150.0) assert repl_task.task_type == TaskType.REPLENISHMENT assert repl_task.destination == "rack_a_01" assert repl_task.quantity == 20 assert repl_task.priority == TaskPriority.HIGH.value # Simulate delivery of replenishment task item.restock(repl_task.quantity) assert item.current_stock == 20 assert item.available_quantity == 20 assert item.needs_replenishment() is False