From 952738858e533f78561c72cc05847ca5d88a1d34 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Wed, 29 Apr 2026 02:48:05 -0700 Subject: [PATCH] codex: address PR review feedback (#20179) --- .github/scripts/verify_tui_core_boundary.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/scripts/verify_tui_core_boundary.py b/.github/scripts/verify_tui_core_boundary.py index 5ed21bbcb9..9e6a3f8a73 100644 --- a/.github/scripts/verify_tui_core_boundary.py +++ b/.github/scripts/verify_tui_core_boundary.py @@ -47,7 +47,7 @@ CRATE_ALIAS_PATTERNS = ( ) GROUPED_USE_PATTERN = re.compile( rf"\buse{REQUIRED_TOKEN_SEPARATOR}" - rf"(?:::{TOKEN_SEPARATOR})?({IDENTIFIER})" + rf"(?:::{TOKEN_SEPARATOR})?({PATH_PREFIX}{IDENTIFIER})" rf"{TOKEN_SEPARATOR}::{TOKEN_SEPARATOR}\{{([^;]*)\}}\s*;" ) GROUPED_SELF_ALIAS_PATTERN = re.compile( @@ -114,19 +114,17 @@ def source_failures() -> list[str]: tui_manifest, workspace_dependencies(workspace_manifest) ) source_texts = [(path, path.read_text()) for path in sorted(TUI_ROOT.glob("**/*.rs"))] - codex_protocol_names = expanded_crate_aliases( - "\n".join(text for _path, text in source_texts), codex_protocol_names - ) for path, text in source_texts: + match_text = comments_as_whitespace(text) seen_locations = set() for message, patterns in FORBIDDEN_SOURCE_RULES: for pattern in patterns: - for match in pattern.finditer(text): + for match in pattern.finditer(match_text): failures.append(source_failure(path, text, match.start(), message)) seen_locations.add((match.start(), message)) - for match in protocol_reference_matches(text, codex_protocol_names): + for match in protocol_reference_matches(match_text, codex_protocol_names): key = (match.start(), CODEX_PROTOCOL_MESSAGE) if key in seen_locations: continue @@ -135,6 +133,13 @@ def source_failures() -> list[str]: return failures +def comments_as_whitespace(text: str) -> str: + def whitespace(match: re.Match[str]) -> str: + return "".join("\n" if char == "\n" else " " for char in match.group(0)) + + return re.sub(r"//[^\n]*(?:\n|$)|/\*(?:.|\n)*?\*/", whitespace, text) + + def workspace_dependencies(manifest: dict) -> dict: dependencies = manifest.get("workspace", {}).get("dependencies", {}) if isinstance(dependencies, dict): @@ -209,7 +214,7 @@ def crate_alias_pairs(text: str) -> list[tuple[str, str]]: for match in pattern.finditer(text): pairs.append((path_tail(match.group(1)), match.group(2))) for match in GROUPED_USE_PATTERN.finditer(text): - source = match.group(1) + source = path_tail(match.group(1)) body = match.group(2) for alias_match in GROUPED_SELF_ALIAS_PATTERN.finditer(body): pairs.append((source, alias_match.group(1)))