From 58c45410e25b27cbd676cedd27e0e5bffc8fa906 Mon Sep 17 00:00:00 2001 From: George Oastler Date: Fri, 6 Nov 2026 21:50:41 +0000 Subject: [PATCH] Match workspace globs one path segment per * in the CI audit --- .github/scripts/ciaudit/test_ciaudit.py | 3 +++ .github/scripts/ciaudit/units.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/scripts/ciaudit/test_ciaudit.py b/.github/scripts/ciaudit/test_ciaudit.py index dd4dd3e..bc3fcb9 100644 --- a/.github/scripts/ciaudit/test_ciaudit.py +++ b/.github/scripts/ciaudit/test_ciaudit.py @@ -116,6 +116,9 @@ def test_jsonc_and_workspace(self) -> None: self.assertEqual(load_jsonc('{"a": "//x", /* c */ "b": [1,],}'), {"a": "//x", "b": [1]}) self.assertTrue(in_workspace("packages/a", ["packages/*", "!packages/z"])) self.assertFalse(in_workspace("packages/z", ["packages/*", "!packages/z"])) + self.assertFalse(in_workspace("captcha/integration/frameworks/vue/wrapper", ["captcha/integration/*"])) + self.assertTrue(in_workspace("captcha/integration/frameworks/vue/wrapper", ["captcha/integration/**"])) + self.assertTrue(in_workspace("captcha/integration/build-config", ["captcha/integration/*/"])) class ShellTest(unittest.TestCase): diff --git a/.github/scripts/ciaudit/units.py b/.github/scripts/ciaudit/units.py index 21e3ffb..9237b4e 100644 --- a/.github/scripts/ciaudit/units.py +++ b/.github/scripts/ciaudit/units.py @@ -261,9 +261,23 @@ def pnpm_workspace(root: Path) -> list[str] | None: return None +def workspace_glob_match(rel: str, glob: str) -> bool: + """pnpm/npm workspace glob semantics: `*` stays within one path segment, `**` spans any number. + + fnmatch alone lets `*` cross `/`, which made `captcha/integration/*` claim packages nested deeper. + """ + def match(parts: list[str], pats: list[str]) -> bool: + if not pats: + return not parts + if pats[0] == "**": + return any(match(parts[i:], pats[1:]) for i in range(len(parts) + 1)) + return bool(parts) and fnmatch.fnmatchcase(parts[0], pats[0]) and match(parts[1:], pats[1:]) + return match(rel.split("/"), glob.strip("/").split("/")) + + def in_workspace(rel: str, globs: list[str]) -> bool: inc = [g for g in globs if not g.startswith("!")] exc = [g[1:] for g in globs if g.startswith("!")] if rel == ".": return True - return any(fnmatch.fnmatch(rel, g.rstrip("/")) for g in inc) and not any(fnmatch.fnmatch(rel, g.rstrip("/")) for g in exc) + return any(workspace_glob_match(rel, g) for g in inc) and not any(workspace_glob_match(rel, g) for g in exc)