From 731b52765a5faf085c16c04b9932b6d810b8d1cc Mon Sep 17 00:00:00 2001 From: OpenAI Date: Sun, 31 May 2026 06:11:30 +0000 Subject: [PATCH] tests: improve AFP endpoint inventory handler detection --- tests/afp/afp_endpoint_inventory.py | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/tests/afp/afp_endpoint_inventory.py b/tests/afp/afp_endpoint_inventory.py index 56b963e..3065752 100755 --- a/tests/afp/afp_endpoint_inventory.py +++ b/tests/afp/afp_endpoint_inventory.py @@ -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: