airbyte-agent-facebook-marketing 0.1.0__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of airbyte-agent-facebook-marketing might be problematic. Click here for more details.

@@ -5,6 +5,7 @@ These tools help ensure that connectors are ready to ship by:
5
5
  - Checking that all entity/action operations have corresponding test cassettes
6
6
  - Validating that response schemas match the actual cassette responses
7
7
  - Detecting fields present in responses but not declared in schemas
8
+ - Validating replication compatibility with Airbyte source connectors
8
9
  """
9
10
 
10
11
  from collections import defaultdict
@@ -20,7 +21,9 @@ from .connector_model_loader import (
20
21
  load_connector_model,
21
22
  )
22
23
  from .testing.spec_loader import load_test_spec
23
- from .types import Action, EndpointDefinition
24
+ from .types import Action, ConnectorModel, EndpointDefinition
25
+ from .utils import infer_auth_scheme_name
26
+ from .validation_replication import validate_replication_compatibility
24
27
 
25
28
 
26
29
  def build_cassette_map(cassettes_dir: Path) -> Dict[Tuple[str, str], List[Path]]:
@@ -51,6 +54,112 @@ def build_cassette_map(cassettes_dir: Path) -> Dict[Tuple[str, str], List[Path]]
51
54
  return dict(cassette_map)
52
55
 
53
56
 
57
+ def build_auth_scheme_coverage(
58
+ cassettes_dir: Path,
59
+ auth_options: list | None = None,
60
+ ) -> Tuple[Dict[str | None, List[Path]], List[Tuple[Path, set[str]]]]:
61
+ """Build a map of auth_scheme -> list of cassette paths.
62
+
63
+ For multi-auth connectors, infers the auth scheme from the cassette's auth_config
64
+ keys using the same matching logic as the executor.
65
+
66
+ Args:
67
+ cassettes_dir: Directory containing cassette YAML files
68
+ auth_options: List of AuthOption from the connector model (for inference)
69
+
70
+ Returns:
71
+ Tuple of:
72
+ - Dictionary mapping auth_scheme names (or None for single-auth) to cassette paths
73
+ - List of (cassette_path, auth_config_keys) for cassettes that couldn't be matched
74
+ """
75
+ auth_scheme_map: Dict[str | None, List[Path]] = defaultdict(list)
76
+ unmatched_cassettes: List[Tuple[Path, set[str]]] = []
77
+
78
+ if not cassettes_dir.exists() or not cassettes_dir.is_dir():
79
+ return {}, []
80
+
81
+ for cassette_file in cassettes_dir.glob("*.yaml"):
82
+ try:
83
+ spec = load_test_spec(cassette_file, auth_config={})
84
+
85
+ # First, check if auth_scheme is explicitly set in the cassette
86
+ if spec.auth_scheme:
87
+ auth_scheme_map[spec.auth_scheme].append(cassette_file)
88
+ # Otherwise, try to infer from auth_config keys
89
+ elif spec.auth_config and auth_options:
90
+ auth_config_keys = set(spec.auth_config.keys())
91
+ inferred_scheme = infer_auth_scheme_name(auth_config_keys, auth_options)
92
+ if inferred_scheme is not None:
93
+ auth_scheme_map[inferred_scheme].append(cassette_file)
94
+ else:
95
+ # Couldn't infer - track as unmatched
96
+ unmatched_cassettes.append((cassette_file, auth_config_keys))
97
+ else:
98
+ # No auth_scheme and no auth_config - treat as None
99
+ auth_scheme_map[None].append(cassette_file)
100
+ except Exception:
101
+ continue
102
+
103
+ return dict(auth_scheme_map), unmatched_cassettes
104
+
105
+
106
+ def validate_auth_scheme_coverage(
107
+ config: ConnectorModel,
108
+ cassettes_dir: Path,
109
+ ) -> Tuple[bool, List[str], List[str], List[str], List[Tuple[Path, set[str]]]]:
110
+ """Validate that each auth scheme has at least one cassette.
111
+
112
+ For multi-auth connectors, every defined auth scheme must have coverage
113
+ unless marked with x-airbyte-untested: true.
114
+ For single-auth connectors, this check is skipped (existing cassette checks suffice).
115
+
116
+ Args:
117
+ config: Loaded connector model
118
+ cassettes_dir: Directory containing cassette files
119
+
120
+ Returns:
121
+ Tuple of (is_valid, errors, warnings, covered_schemes, unmatched_cassettes)
122
+ """
123
+ errors: List[str] = []
124
+ warnings: List[str] = []
125
+
126
+ # Skip check for single-auth connectors
127
+ if not config.auth.is_multi_auth():
128
+ return True, errors, warnings, [], []
129
+
130
+ # Get all defined auth schemes, separating tested from untested
131
+ options = config.auth.options or []
132
+
133
+ # Build auth scheme coverage from cassettes (pass options for inference)
134
+ auth_scheme_coverage, unmatched_cassettes = build_auth_scheme_coverage(cassettes_dir, options)
135
+ tested_schemes = {opt.scheme_name for opt in options if not opt.untested}
136
+ untested_schemes = {opt.scheme_name for opt in options if opt.untested}
137
+ covered_schemes = {scheme for scheme in auth_scheme_coverage.keys() if scheme is not None}
138
+
139
+ # Find missing tested schemes (errors)
140
+ missing_tested = tested_schemes - covered_schemes
141
+ for scheme in sorted(missing_tested):
142
+ errors.append(
143
+ f"Auth scheme '{scheme}' has no cassette coverage. "
144
+ f"Record at least one cassette using this authentication method, "
145
+ f"or add 'x-airbyte-untested: true' to skip this check."
146
+ )
147
+
148
+ # Warn about untested schemes without coverage
149
+ missing_untested = untested_schemes - covered_schemes
150
+ for scheme in sorted(missing_untested):
151
+ warnings.append(
152
+ f"Auth scheme '{scheme}' is marked as untested (x-airbyte-untested: true) " f"and has no cassette coverage. Validation skipped."
153
+ )
154
+
155
+ # Warn about cassettes that couldn't be matched to any auth scheme
156
+ for cassette_path, auth_config_keys in unmatched_cassettes:
157
+ warnings.append(f"Cassette '{cassette_path.name}' could not be matched to any auth scheme. " f"auth_config keys: {sorted(auth_config_keys)}")
158
+
159
+ is_valid = len(missing_tested) == 0
160
+ return is_valid, errors, warnings, sorted(covered_schemes), unmatched_cassettes
161
+
162
+
54
163
  def validate_response_against_schema(response_body: Any, schema: Dict[str, Any]) -> Tuple[bool, List[str]]:
55
164
  """Validate a response body against a JSON schema.
56
165
 
@@ -586,6 +695,9 @@ def validate_connector_readiness(connector_dir: str | Path) -> Dict[str, Any]:
586
695
  cassettes_dir = connector_path / "tests" / "cassettes"
587
696
  cassette_map = build_cassette_map(cassettes_dir)
588
697
 
698
+ # Validate auth scheme coverage for multi-auth connectors
699
+ auth_valid, auth_errors, auth_warnings, auth_covered_schemes, auth_unmatched_cassettes = validate_auth_scheme_coverage(config, cassettes_dir)
700
+
589
701
  validation_results = []
590
702
  total_operations = 0
591
703
  operations_with_cassettes = 0
@@ -808,7 +920,29 @@ def validate_connector_readiness(connector_dir: str | Path) -> Dict[str, Any]:
808
920
  }
809
921
  )
810
922
 
811
- success = operations_missing_cassettes == 0 and cassettes_invalid == 0 and total_operations > 0
923
+ # Validate replication compatibility with Airbyte
924
+ replication_result = validate_replication_compatibility(
925
+ connector_yaml_path=config_file,
926
+ raw_spec=raw_spec,
927
+ )
928
+
929
+ # Merge replication errors/warnings into totals
930
+ # Note: If connector is not in registry, we don't count warnings since this is expected for test connectors
931
+ replication_errors = replication_result.get("errors", [])
932
+ replication_warnings = replication_result.get("warnings", [])
933
+ total_errors += len(replication_errors)
934
+
935
+ # Only count replication warnings if the connector was found in the registry
936
+ # (i.e., there are actual validation issues, not just "not found in registry")
937
+ if replication_result.get("registry_found", False):
938
+ total_warnings += len(replication_warnings)
939
+
940
+ # Merge auth scheme validation errors/warnings into totals
941
+ total_errors += len(auth_errors)
942
+ total_warnings += len(auth_warnings)
943
+
944
+ # Update success criteria to include replication and auth scheme validation
945
+ success = operations_missing_cassettes == 0 and cassettes_invalid == 0 and total_operations > 0 and len(replication_errors) == 0 and auth_valid
812
946
 
813
947
  # Check for preferred_for_check on at least one list operation
814
948
  has_preferred_check = False
@@ -829,11 +963,26 @@ def validate_connector_readiness(connector_dir: str | Path) -> Dict[str, Any]:
829
963
  "to enable reliable health checks."
830
964
  )
831
965
 
966
+ # Build auth scheme validation result
967
+ options = config.auth.options or []
968
+ tested_schemes = [opt.scheme_name for opt in options if not opt.untested]
969
+ untested_schemes_list = [opt.scheme_name for opt in options if opt.untested]
970
+ missing_tested = [s for s in tested_schemes if s not in auth_covered_schemes]
971
+
832
972
  return {
833
973
  "success": success,
834
974
  "connector_name": config.name,
835
975
  "connector_path": str(connector_path),
836
976
  "validation_results": validation_results,
977
+ "replication_validation": replication_result,
978
+ "auth_scheme_validation": {
979
+ "valid": auth_valid,
980
+ "errors": auth_errors,
981
+ "warnings": auth_warnings,
982
+ "covered_schemes": auth_covered_schemes,
983
+ "missing_schemes": missing_tested,
984
+ "untested_schemes": untested_schemes_list,
985
+ },
837
986
  "readiness_warnings": readiness_warnings,
838
987
  "summary": {
839
988
  "total_operations": total_operations,