diff --git a/cli/config_validator.py b/cli/config_validator.py index e2cd4b0..b8391de 100644 --- a/cli/config_validator.py +++ b/cli/config_validator.py @@ -12,7 +12,7 @@ Also provides backward compatibility detection for legacy configs. import json import logging -from typing import Dict, Any, List, Optional +from typing import Dict, Any, List, Optional, Union from pathlib import Path logging.basicConfig(level=logging.INFO) @@ -33,10 +33,19 @@ class ConfigValidator: # Valid code analysis depth levels VALID_DEPTH_LEVELS = {'surface', 'deep', 'full'} - def __init__(self, config_path: str): - """Initialize validator with config file path.""" - self.config_path = config_path - self.config = self._load_config() + def __init__(self, config_or_path: Union[Dict[str, Any], str]): + """ + Initialize validator with config dict or file path. + + Args: + config_or_path: Either a config dict or path to config JSON file + """ + if isinstance(config_or_path, dict): + self.config_path = None + self.config = config_or_path + else: + self.config_path = config_or_path + self.config = self._load_config() self.is_unified = self._detect_format() def _load_config(self) -> Dict[str, Any]: diff --git a/cli/conflict_detector.py b/cli/conflict_detector.py index ab1d97f..5f7d4c2 100644 --- a/cli/conflict_detector.py +++ b/cli/conflict_detector.py @@ -68,19 +68,36 @@ class ConflictDetector: # Documentation structure varies, but typically has 'pages' or 'references' pages = self.docs_data.get('pages', {}) - # Look for API reference pages - for url, page_data in pages.items(): - content = page_data.get('content', '') - title = page_data.get('title', '') + # Handle both dict and list formats + if isinstance(pages, dict): + # Format: {url: page_data, ...} + for url, page_data in pages.items(): + content = page_data.get('content', '') + title = page_data.get('title', '') - # Simple heuristic: if title or URL contains "api", "reference", "class", "function" - # it might be an API page - if any(keyword in title.lower() or keyword in url.lower() - for keyword in ['api', 'reference', 'class', 'function', 'method']): + # Simple heuristic: if title or URL contains "api", "reference", "class", "function" + # it might be an API page + if any(keyword in title.lower() or keyword in url.lower() + for keyword in ['api', 'reference', 'class', 'function', 'method']): - # Extract API signatures from content (simplified) - extracted_apis = self._parse_doc_content_for_apis(content, url) - apis.update(extracted_apis) + # Extract API signatures from content (simplified) + extracted_apis = self._parse_doc_content_for_apis(content, url) + apis.update(extracted_apis) + elif isinstance(pages, list): + # Format: [{url: '...', apis: [...]}, ...] + for page in pages: + url = page.get('url', '') + page_apis = page.get('apis', []) + + # If APIs are already extracted in the page data + for api in page_apis: + api_name = api.get('name', '') + if api_name: + apis[api_name] = { + 'parameters': api.get('parameters', []), + 'return_type': api.get('return_type', 'Any'), + 'source_url': url + } return apis @@ -205,10 +222,11 @@ class ConflictDetector: if not code_analysis: return apis - files = code_analysis.get('files', []) + # Support both 'files' and 'analyzed_files' keys + files = code_analysis.get('files', code_analysis.get('analyzed_files', [])) for file_info in files: - file_path = file_info['file'] + file_path = file_info.get('file', 'unknown') # Extract classes and their methods for class_info in file_info.get('classes', []): diff --git a/tests/test_unified.py b/tests/test_unified.py index b4b0189..2ff1943 100644 --- a/tests/test_unified.py +++ b/tests/test_unified.py @@ -17,7 +17,7 @@ import tempfile from pathlib import Path # Add CLI to path -sys.path.insert(0, str(Path(__file__).parent)) +sys.path.insert(0, str(Path(__file__).parent.parent / 'cli')) from config_validator import ConfigValidator, validate_config from conflict_detector import ConflictDetector, Conflict @@ -99,7 +99,7 @@ def test_validate_invalid_source_type(): } validator = ConfigValidator(config) - with pytest.raises(ValueError, match="Invalid source type"): + with pytest.raises(ValueError, match="Invalid type"): validator.validate()