From 45f3cabe44bbdda037c5dd7a9e5fd276f8611e97 Mon Sep 17 00:00:00 2001 From: bsodfather Date: Sun, 4 Oct 2026 21:50:46 +0300 Subject: [PATCH] fix(tooling): exclude upstream SQLx from Community marker scan --- scripts/check-community-scope.py | 5 ++ tests/unit/test_check_community_scope.py | 71 ++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/scripts/check-community-scope.py b/scripts/check-community-scope.py index 9670a43..f66da89 100755 --- a/scripts/check-community-scope.py +++ b/scripts/check-community-scope.py @@ -20,6 +20,11 @@ DEFAULT_EXCLUDED_PREFIXES = { "target/", "apps/ui/node_modules/", "apps/ui/dist/", + # Vendored upstream SQLx source. Its Apache-2.0 license text (commercial) + # and upstream migration/pool wording (tenant/billing) are not Community + # product features. The prefix is intentionally narrow: only this vendored + # package is skipped, and path validation still runs before the skip. + "vendor/sqlx-core/", } ALLOW_DIRECTIVE = re.compile( diff --git a/tests/unit/test_check_community_scope.py b/tests/unit/test_check_community_scope.py index 0e7f9ca..86a1a6f 100644 --- a/tests/unit/test_check_community_scope.py +++ b/tests/unit/test_check_community_scope.py @@ -312,6 +312,77 @@ class CommunityScopeCheckTests(unittest.TestCase): self.assertFalse(truncated) self.assertEqual(scanned_bytes, 0) + def test_skips_vendored_upstream_sqlx_core_prefix(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + vendored = root / "vendor" / "sqlx-core" + (vendored / "src" / "pool").mkdir(parents=True) + (vendored / "LICENSE-APACHE").write_text( + "commercial damages or losses\n", encoding="utf-8" + ) + (vendored / "src" / "pool" / "options.rs").write_text( + "usage-based database server billing\n", encoding="utf-8" + ) + (vendored / "src" / "migrate.rs").write_text( + "tenant reference\n", encoding="utf-8" + ) + + result = self.run_checker( + root, + [ + "vendor/sqlx-core/LICENSE-APACHE", + "vendor/sqlx-core/src/pool/options.rs", + "vendor/sqlx-core/src/migrate.rs", + ], + ) + + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("Community scope check passed", result.stdout) + + def test_forbidden_markers_outside_skipped_prefix_are_rejected(self) -> None: + cases = { + "vendor/other/scope.txt": ("tenant reference\n", "tenant"), + "vendor/sqlx-core-extra/scope.txt": ("billing note\n", "billing"), + "apps/scope.txt": ("graphql transport\n", "graphql"), + "crates/scope.txt": ("commercial plan\n", "commercial"), + } + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + for relative_path, (content, marker) in cases.items(): + path = root / relative_path + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content, encoding="utf-8") + with self.subTest(relative_path=relative_path): + result = self.run_checker(root, [relative_path]) + self.assertNotEqual(result.returncode, 0) + self.assertIn( + f"{relative_path}:1: forbidden marker `{marker}`", + result.stderr, + ) + + def test_skipped_prefix_paths_are_validated_before_skip(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + vendored = root / "vendor" / "sqlx-core" + vendored.mkdir(parents=True) + target = vendored / "target.txt" + target.write_text("clean\n", encoding="utf-8") + link = vendored / "link.txt" + link.symlink_to(target) + + valid_excluded = self.run_checker(root, ["vendor/sqlx-core/target.txt"]) + self.assertEqual(valid_excluded.returncode, 0, valid_excluded.stderr) + + for raw_path in [ + "vendor/sqlx-core/missing.txt", + "vendor/sqlx-core/../other/missing.txt", + "vendor/sqlx-core/link.txt", + ]: + with self.subTest(raw_path=raw_path): + rejected = self.run_checker(root, [raw_path]) + self.assertNotEqual(rejected.returncode, 0) + self.assertIn("invalid explicit file path", rejected.stderr) + if __name__ == "__main__": unittest.main()