import json import pytest @pytest.fixture def tmp_workspace(tmp_path): """Create a temporary workspace directory.""" ws_dir = tmp_path / "workspaces" ws_dir.mkdir() return ws_dir @pytest.fixture def tmp_templates(tmp_path): """Create a temporary templates directory with mock template data.""" tpl_dir = tmp_path / "templates" / "example" tpl_dir.mkdir(parents=True) # Create minimal template files for fallback testing (tpl_dir / "insight.json").write_text(json.dumps({"test": "template_insight"})) (tpl_dir / "diagnostic_package.json").write_text( json.dumps({"test": "template_diag"}) ) (tpl_dir / "cluster_meta.json").write_text( json.dumps( { "cluster_id": "test-cluster", "org_id": "test-org", "tidb_version": "v0.0.0", } ) ) opencode_dir = tpl_dir / ".opencode" opencode_dir.mkdir() (opencode_dir / "opencode.json").write_text(json.dumps({})) return tmp_path / "templates" @pytest.fixture def prepare_tasks(): """Create a fresh prepare_tasks dict.""" return {} @pytest.fixture def mock_jira_response(): """Mock Jira API response with raw alert data.""" raw_alert_data = { "labels": { "tidb_cluster_id": "1379661944646416054", "o11y_tenant_id": "1372813089209061633", "alertname": "HighMemoryUsage", }, "annotations": { "description": "Memory usage exceeded 90%", }, } return { "key": "O11Y-12345", "fields": { "customfield_10160": json.dumps(raw_alert_data), }, } def create_mock_clinic_response( cluster_id="1379661944646416054", tenant_id="1372813089209061633", org_id="test-org-123", cluster_name="test-tidb-cluster", version="v7.5.0", cluster_type="DEDICATED", provider="AWS", region="us-west-2", status="AVAILABLE", **kwargs, ): """Helper to create mock Clinic API response with custom values.""" return { "items": [ { "clusterID": cluster_id, "tenantID": tenant_id, "orgID": org_id, "clusterName": cluster_name, "clusterVersion": version, "clusterDeployType": cluster_type, "clusterProviderName": provider, "clusterRegionName": region, "clusterStatus": status, "clusterCreatedAt": kwargs.get( "create_timestamp", "2024-01-15T10:30:00Z" ), } ] } @pytest.fixture def mock_clinic_response(): """Mock Clinic API response with comprehensive cluster metadata.""" return create_mock_clinic_response() @pytest.fixture def mock_analysis_response(): """Mock Guardian API response.""" return { "items": [ { "analysis_uuid": "186e8947-6ed2-4553-a960-274e86e6e6bd", "jira_issue_id": "O11Y-12345", "tenant_id": "1372813089209061633", "cluster_id": "1379661944646416054", "time_range_start_ts": 1758028200, "time_range_end_ts": 1758030000, "analyzer_name": "general", "status": "COMPLETED", "created_at": "2025-07-14T10:04:58+00:00", "completed_at": "2025-07-14T10:10:00+00:00", } ], "total": 1, }