From cb0f506e49a233145da221f174bf3ef5fe7d6b36 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 8 Apr 2026 13:29:31 +0800 Subject: [PATCH 1/3] Fix test_sensitive_word failing on Windows Replace shell-based search (powershell Select-String / grep) with pure Python pathlib.rglob + read_text. The PowerShell implementation output relative paths while the regex expected absolute paths, causing the test to always return empty results on Windows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../mock_api/unbranded/test_unbranded.py | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/http-client-python/tests/mock_api/unbranded/test_unbranded.py b/packages/http-client-python/tests/mock_api/unbranded/test_unbranded.py index e1b32751ff3..f576368fc33 100644 --- a/packages/http-client-python/tests/mock_api/unbranded/test_unbranded.py +++ b/packages/http-client-python/tests/mock_api/unbranded/test_unbranded.py @@ -3,8 +3,6 @@ # Licensed under the MIT License. # ------------------------------------ import os -import re -from subprocess import getoutput from pathlib import Path import traceback from importlib import import_module @@ -33,21 +31,25 @@ def test_track_back(client: ScalarClient): assert "microsoft" not in track_back -def check_sensitive_word(folder: Path, word: str) -> str: - special_folders = ["__pycache__", "pytest_cache"] - if os.name == "nt": - skip_folders = "|".join(special_folders) - output = getoutput( - f"powershell \"ls -r -Path {folder} | where fullname -notmatch '{skip_folders}' | Select-String -Pattern '{word}'\"" - ).replace("\\", "/") - else: - skip_folders = "{" + ",".join(special_folders) + "}" - output = getoutput(f"grep -ri --exclude-dir={skip_folders} {word} {folder}") +_SKIP_DIRS = {"__pycache__", "pytest_cache", ".pytest_cache"} + +def check_sensitive_word(folder: Path, word: str) -> list[str]: + """Search for a word in all files under folder, return top-level subfolder names that contain it.""" result = set() - for item in re.findall(f"{folder.as_posix()}[^:]+", output.replace("\n", "")): - result.add(Path(item).relative_to(folder).parts[0]) - return sorted(list(result)) + for path in folder.rglob("*"): + if not path.is_file(): + continue + # Skip special directories + if _SKIP_DIRS & set(path.relative_to(folder).parts): + continue + try: + content = path.read_text(encoding="utf-8", errors="ignore") + except (OSError, UnicodeDecodeError): + continue + if word.lower() in content.lower(): + result.add(path.relative_to(folder).parts[0]) + return sorted(result) def test_sensitive_word(): From f66e34f2bfb47b1bac0348a7cbff79f9514c2bf5 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 8 Apr 2026 13:31:15 +0800 Subject: [PATCH 2/3] Add changelog entry Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../changes/fix-windows-sensitive-word-test-2026-4-8.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md diff --git a/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md b/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md new file mode 100644 index 00000000000..503c426321f --- /dev/null +++ b/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md @@ -0,0 +1,6 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- +Fix `test_sensitive_word` failing on Windows by replacing shell-based search with pure Python `pathlib` implementation. From 00df699b9e6badadf5420440118dfe9952dbcc6c Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 8 Apr 2026 13:32:02 +0800 Subject: [PATCH 3/3] Update fix-windows-sensitive-word-test-2026-4-8.md --- .chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md b/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md index 503c426321f..6c18a8db46e 100644 --- a/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md +++ b/.chronus/changes/fix-windows-sensitive-word-test-2026-4-8.md @@ -1,5 +1,5 @@ --- -changeKind: fix +changeKind: internal packages: - "@typespec/http-client-python" ---