Skip to content

Commit e99c980

Browse files
author
anhnh2002
committed
Drop the error-keyword filter in filter_leaf_nodes; whitelist its test in .gitignore
The membership check against known components already drops every candidate that is not a component id, including error messages and malformed entries, so a separate keyword/regex check never changes the result. Remove it rather than keep dead code. tests/* is gitignored with per-file exceptions; add one for the new tests/test_leaf_selection.py so it is not tracked-but-ignored.
1 parent 813ce71 commit e99c980

3 files changed

Lines changed: 14 additions & 20 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ tests/*
4343
!tests/test_module_tree_validation.py
4444
!tests/test_ruby_analyzer.py
4545
!tests/test_processing_order_update.py
46+
!tests/test_leaf_selection.py
4647

4748
# Jupyter
4849
*.ipynb

‎codewiki/src/be/dependency_analyzer/leaf_selection.py‎

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import Dict, List, Set
2-
import re
32

43
from codewiki.src.be.dependency_analyzer.models.core import Node
54

@@ -17,11 +16,6 @@
1716

1817
OOP_TYPES = {"class", "interface", "struct"}
1918

20-
# Error strings that occasionally reach leaf-node selection instead of an
21-
# identifier. Matched on word boundaries and only for entries that are not
22-
# known components, so that names like `handleInvalidInput` survive.
23-
ERROR_MESSAGE_RE = re.compile(r"\b(error|exception|failed|invalid)\b", re.IGNORECASE)
24-
2519

2620
def compute_valid_leaf_types(components: Dict[str, Node]) -> Set[str]:
2721
"""
@@ -63,21 +57,20 @@ def filter_leaf_nodes(
6357
components: Dict[str, Node],
6458
valid_types: Set[str],
6559
) -> List[str]:
66-
"""Keep leaf nodes that are known components of a valid type."""
60+
"""Keep leaf nodes that are known components of a valid type.
61+
62+
Anything that is not a known component id (None, empty strings, error
63+
messages that occasionally reach leaf-node selection) is dropped by the
64+
membership check alone. Do not add keyword-based filtering on top of it:
65+
it would also reject identifiers such as `handleInvalidInput` or `ErrorLog`.
66+
"""
6767
keep_leaf_nodes = []
6868
for leaf_node in leaf_nodes:
69-
if not isinstance(leaf_node, str) or leaf_node.strip() == "":
70-
logger.debug(f"Skipping invalid leaf node identifier: '{leaf_node}'")
71-
continue
72-
73-
# Only reject strings that look like error messages, not identifiers
74-
# that merely contain such a word (handleInvalidInput, ErrorLog, ...).
75-
if leaf_node not in components and ERROR_MESSAGE_RE.search(leaf_node):
76-
logger.debug(f"Skipping invalid leaf node identifier: '{leaf_node}'")
69+
if not isinstance(leaf_node, str) or leaf_node not in components:
70+
logger.debug(f"Skipping unknown leaf node identifier: '{leaf_node}'")
7771
continue
7872

79-
if leaf_node in components:
80-
if components[leaf_node].component_type in valid_types:
81-
keep_leaf_nodes.append(leaf_node)
73+
if components[leaf_node].component_type in valid_types:
74+
keep_leaf_nodes.append(leaf_node)
8275

8376
return keep_leaf_nodes

‎tests/test_leaf_selection.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Tests for leaf-node identifier filtering.
22
33
Covers filter_leaf_nodes: identifiers that merely contain a word like
4-
"invalid" must survive, while strings that are actually error messages
5-
reaching leaf-node selection instead of an identifier are dropped.
4+
"invalid" must survive, while strings that are not known component ids
5+
(error messages reaching leaf-node selection, malformed entries) are dropped.
66
"""
77

88
from __future__ import annotations

0 commit comments

Comments
 (0)