tests: improve AFP endpoint inventory handler detection

This commit is contained in:
OpenAI
2026-05-31 06:11:30 +00:00
committed by Mario Fetka
parent 438a6d7289
commit 731b52765a

View File

@@ -139,13 +139,19 @@ def extract_function_bodies(text: str) -> Dict[str, Tuple[int, str]]:
def parse_dispatch(text: str, function_names: Iterable[str]) -> Dict[int, str]:
names = sorted(function_names, key=len, reverse=True)
dispatch: Dict[int, str] = {}
# Restrict the broad case scan to areas that mention AFP handler names. This
# avoids confusing non-AFP NCP cases with AFP subfunctions.
for match in DISPATCH_RE.finditer(text):
body = match.group("body")
# The AFP dispatcher contains nested switch/if blocks, so a simple
# ``case ... break;`` regex often stops at an inner break and misses the
# real handler call. Walk each AFP case from its label to the next top-level
# case/default label and search that slice instead.
labels = list(re.finditer(r"^\s*case\s+0x([0-9a-fA-F]+)\s*:", text, re.MULTILINE))
for index, label in enumerate(labels):
start = label.end()
end = labels[index + 1].start() if index + 1 < len(labels) else len(text)
body = text[start:end]
for name in names:
if name in body:
dispatch[int(match.group(1), 16)] = name
dispatch[int(label.group(1), 16)] = name
break
return dispatch
@@ -174,10 +180,22 @@ def classify_backends(body: str) -> List[str]:
def function_for_call(call_name: str, call_no: int, dispatch: Dict[int, str], bodies: Dict[str, Tuple[int, str]]) -> str:
if call_no in dispatch:
return dispatch[call_no]
# afp_call_name() returns human labels such as
# ``AFP 2.0 Get File Information``. Handler functions are named without
# the cosmetic prefix/version marker, e.g. ``afp_get_file_information``.
# Keep several conservative variants so the helper remains useful if a
# handler keeps an older shorter name.
normalized = re.sub(r"[^a-z0-9]+", "_", call_name.lower()).strip("_")
if normalized.startswith("afp_"):
normalized = normalized[4:]
without_version = normalized.replace("2_0_", "")
candidates = [
"afp_" + normalized,
"afp_" + normalized.replace("2_0_", ""),
"afp_" + without_version,
"afp_" + without_version.replace("file_information", "file_info"),
"afp_" + without_version.replace("directory", "dir"),
"afp_" + without_version.replace("netware", "netware"),
]
for candidate in candidates:
if candidate in bodies: