(edge: dict)
| 1427 | ) |
| 1428 | |
| 1429 | def _keep_edge(edge: dict) -> bool: |
| 1430 | if not (_is_ast_tier(edge) and edge.get("relation") == "references"): |
| 1431 | return True |
| 1432 | if _is_code_span_mention(edge) or _is_code_file_citation(edge): |
| 1433 | return True |
| 1434 | owner = source_paths.normalize(edge.get("source_file")) |
| 1435 | if owner not in parsed_sources: |
| 1436 | return True |
| 1437 | |
| 1438 | unresolved_targets = unresolved_authored_sites.get( |
| 1439 | (owner, str(edge.get("source_location") or "")), set() |
| 1440 | ) |
| 1441 | if unresolved_targets: |
| 1442 | target_sources = { |
| 1443 | source |
| 1444 | for endpoint in (edge.get("source"), edge.get("target")) |
| 1445 | if (source := node_sources.get(endpoint)) and source != owner |
| 1446 | } |
| 1447 | if any( |
| 1448 | _matches_unresolved_target(raw_target, owner, target_source) |
| 1449 | for raw_target in unresolved_targets |
| 1450 | for target_source in target_sources |
| 1451 | ): |
| 1452 | return True |
| 1453 | |
| 1454 | raw_pair = frozenset((edge.get("source"), edge.get("target"))) |
| 1455 | if raw_pair in authored_raw_pairs: |
| 1456 | desired_pair = resolved_raw_pairs.get(raw_pair) |
| 1457 | return desired_pair is None or raw_pair == desired_pair |
| 1458 | |
| 1459 | endpoint_files = { |
| 1460 | node_sources.get(edge.get("source")), |
| 1461 | node_sources.get(edge.get("target")), |
| 1462 | } |
| 1463 | endpoint_files.discard(None) |
| 1464 | targets = endpoint_files - {owner} |
| 1465 | if len(targets) == 1: |
| 1466 | target_file = targets.pop() |
| 1467 | elif edge.get("target_file"): |
| 1468 | target_path = Path(edge["target_file"]) |
| 1469 | try: |
| 1470 | target_path = target_path.relative_to(project_root) |
| 1471 | except ValueError: |
| 1472 | pass |
| 1473 | target_file = source_paths.normalize(str(target_path)) |
| 1474 | else: |
| 1475 | return True |
| 1476 | |
| 1477 | file_pair = frozenset((owner, target_file)) |
| 1478 | if (owner, target_file) not in authored_links: |
| 1479 | return False |
| 1480 | if file_pair not in desired_file_pairs: |
| 1481 | return True |
| 1482 | return raw_pair == desired_reps_by_file_pair[file_pair] |
| 1483 | |
| 1484 | result["edges"] = [edge for edge in result.get("edges", []) if _keep_edge(edge)] |
| 1485 | preserved_edges = [edge for edge in preserved_edges if _keep_edge(edge)] |
no test coverage detected