MCPcopy Create free account
hub / github.com/Snapchat/Valdi / check

Function check

tools/api_surface/check_api_surface.py:169–250  ·  view source on GitHub ↗

Run the API surface check. Returns exit code.

(open_source_root: Path, strict: bool = False)

Source from the content-addressed store, hash-verified

167
168
169def check(open_source_root: Path, strict: bool = False) -> int:
170 """Run the API surface check. Returns exit code."""
171 if not BASELINE_PATH.exists():
172 print(f"{RED}No baseline found at {BASELINE_PATH}{RESET}")
173 print("Run with --update to generate one.")
174 return 1
175
176 baseline = json.loads(BASELINE_PATH.read_text())
177 current = extract_api(open_source_root)
178
179 all_warnings = []
180 all_errors = []
181
182 # Interfaces
183 print(f"\n{BOLD}Checking interfaces...{RESET}")
184 w, e = _diff_interfaces(
185 baseline.get("interfaces", {}), current.get("interfaces", {})
186 )
187 all_warnings.extend(w)
188 all_errors.extend(e)
189
190 # Type aliases
191 print(f"{BOLD}Checking type aliases...{RESET}")
192 w, e = _diff_dict(baseline.get("types", {}), current.get("types", {}), "type")
193 all_warnings.extend(w)
194 all_errors.extend(e)
195
196 # Enums
197 print(f"{BOLD}Checking enums...{RESET}")
198 b_enums_flat = {}
199 c_enums_flat = {}
200 for ename, members in baseline.get("enums", {}).items():
201 for mname, mval in members.items():
202 b_enums_flat[f"{ename}.{mname}"] = mval
203 for ename, members in current.get("enums", {}).items():
204 for mname, mval in members.items():
205 c_enums_flat[f"{ename}.{mname}"] = mval
206 w, e = _diff_dict(b_enums_flat, c_enums_flat, "enum member")
207 all_warnings.extend(w)
208 all_errors.extend(e)
209
210 # Classes
211 print(f"{BOLD}Checking classes...{RESET}")
212 w, e = _diff_classes(baseline.get("classes", {}), current.get("classes", {}))
213 all_warnings.extend(w)
214 all_errors.extend(e)
215
216 # Report
217 print()
218 if all_errors:
219 print(f"{RED}{BOLD}Breaking changes detected (removals):{RESET}")
220 for msg in all_errors:
221 error(msg)
222 print()
223
224 if all_warnings:
225 print(f"{YELLOW}{BOLD}API additions/modifications detected:{RESET}")
226 for msg in all_warnings:

Callers 1

mainFunction · 0.70

Calls 10

extract_apiFunction · 0.90
printFunction · 0.85
_diff_interfacesFunction · 0.85
_diff_dictFunction · 0.85
_diff_classesFunction · 0.85
errorFunction · 0.70
warnFunction · 0.70
existsMethod · 0.65
getMethod · 0.65
extendMethod · 0.65

Tested by

no test coverage detected