~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: eliminate blanket wildcards from file whitelist and block PNG snapshots (#2261)
LearningCircuit33657fa1c222
diff --git a/.file-whitelist.txt b/.file-whitelist.txtnew file mode 100644index 0000000000..3b83b94c0e--- /dev/null+++ b/.file-whitelist.txt@@ -0,0 +1,97 @@+# ============================================================================+# Allowed file patterns for git pre-commit and CI whitelist checks.+# One regex pattern per line. Lines starting with # are comments.+# Blank lines are ignored.+#+# PRINCIPLE: text source types are kept broad (low risk, high churn).+# Config, binary, and other types are path-scoped.+#+# Binary files bloat the repo — do NOT add new binary wildcards without+# maintainer approval. See CODEOWNERS.+# ============================================================================++# ---------------------------------------------------------------------------+# Text source code — kept broad (low risk)+# ---------------------------------------------------------------------------+\.py$+\.js$+\.mjs$+\.html$+\.css$+\.md$++# ---------------------------------------------------------------------------+# JSON — path-scoped+# ---------------------------------------------------------------------------+^src/local_deep_research/defaults/.*\.json$+^cookiecutter-docker/.*\.json$+^package\.json$+^package-lock\.json$+^tests/(.*/)?package\.json$+^tests/(.*/)?package-lock\.json$+^tests/settings/golden_master_settings\.json$++# ---------------------------------------------------------------------------+# YAML — path-scoped+# ---------------------------------------------------------------------------+^\.github/.*\.(yml|yaml)$+^\.semgrep/.*\.(yml|yaml)$+^bearer\.yml$+^\.hadolint\.yaml$+^\.pre-commit-config\.yaml$+^\.safety-policy\.yml$+^docker-compose.*\.(yml|yaml)$+^examples/.*/docker-compose\.yml$+^community_benchmark_results/.*\.yaml$+^cookiecutter-docker/.*\.yml$++# ---------------------------------------------------------------------------+# Shell scripts — path-scoped+# ---------------------------------------------------------------------------+^\.github/scripts/.*\.sh$+^\.pre-commit-hooks/.*\.sh$+^scripts/.*\.sh$+^tests/.*\.sh$+^docs/.*\.sh$+^examples/.*\.sh$++# ---------------------------------------------------------------------------+# Other config — explicit paths only+# ---------------------------------------------------------------------------+^src/local_deep_research/defaults/.*\.template$+^src/local_deep_research/notifications/templates/.*\.jinja2$+^unraid-templates/.*\.xml$+^pyproject\.toml$+^pdm\.lock$+^\.gitleaks\.toml$+^\.zap/rules\.tsv$++# ---------------------------------------------------------------------------+# Specific root/config files+# ---------------------------------------------------------------------------+.*\.gitkeep$+.*\.gitignore$+^\.coveragerc$+^\.secrets\.baseline$+^\.gitleaksignore$+^\.semgrepignore$+^\.trivyignore$+^\.github/CODEOWNERS$+^MANIFEST\.in$+^LICENSE$+^README$+^Dockerfile$+^\.file-whitelist\.txt$++# ---------------------------------------------------------------------------+# Binary assets — explicit paths only.+# Binary files bloat the repo; do NOT add new ones without maintainer approval.+# ---------------------------------------------------------------------------+^docs/images/Local Search\.png$+^docs/images/local_search_embedding_model_type\.png$+^docs/images/local_search_paths\.png$+^src/local_deep_research/web/static/favicon\.png$+^docs/.*\.ps1$+^src/local_deep_research/web/static/sounds/error\.mp3$+^src/local_deep_research/web/static/sounds/success\.mp3$+^installers/.*\.(bat|ps1|iss)$diff --git a/.github/CODEOWNERS b/.github/CODEOWNERSindex 276def2f9a..2542718014 100644--- a/.github/CODEOWNERS+++ b/.github/CODEOWNERS@@ -115,3 +115,20 @@/src/local_deep_research/defaults/settings/search_engines/parallel.json @scottvr @tombii @prashant-sharma-cmd @elpikola @shreydekate @LearningCircuit @hashedviking @djpetti/src/local_deep_research/defaults/settings/search_engines/scaleserp.json @scottvr @tombii @prashant-sharma-cmd @elpikola @shreydekate @LearningCircuit @hashedviking @djpetti/src/local_deep_research/defaults/settings/search_engines/serper.json @scottvr @tombii @prashant-sharma-cmd @elpikola @shreydekate @LearningCircuit @hashedviking @djpetti++# ──────────────────────────────────────────────────────────────────────+# Repository integrity guardrails — maintainer-only approval+#+# These files control what is tracked in git and what passes CI/pre-commit+# whitelist checks. Restricted to prevent re-introduction of broad+# file-type exceptions (e.g. binary wildcards) without explicit maintainer+# approval. Binary files bloat the repo and should not be added to main.+#+# IMPORTANT: these rules MUST remain the last entries in this file+# (GitHub CODEOWNERS uses last-match-wins).+# ──────────────────────────────────────────────────────────────────────+/.gitignore @LearningCircuit+/.file-whitelist.txt @LearningCircuit+/.pre-commit-hooks/file-whitelist-check.sh @LearningCircuit+/.github/scripts/file-whitelist-check.sh @LearningCircuit+/.github/CODEOWNERS @LearningCircuitdiff --git a/.github/scripts/file-whitelist-check.sh b/.github/scripts/file-whitelist-check.shindex 73f7635b23..edb1e51e65 100755--- a/.github/scripts/file-whitelist-check.sh+++ b/.github/scripts/file-whitelist-check.sh@@ -4,58 +4,21 @@# Enhanced security checks with comprehensive file type detectionset -euo pipefail-# Define allowed file extensions and specific files-ALLOWED_PATTERNS=(-"\.py$"-"\.js$"-"\.mjs$"-"\.html$"-"\.css$"-"\.json$"-"\.md$"-"\.yml$"-"\.yaml$"-"\.xml$"-"\.sh$"-"\.cfg$"-"\.ipynb$"-"\.template$"-"\.toml$"-"\.tsv$"-"\.jinja2$"-"^\.gitignore$"-"^\.gitkeep$"-".*\.gitkeep$"-".*\.gitignore$"-"^\.pre-commit-config\.yaml$"-"^\.coveragerc$"-"^\.secrets\.baseline$"-"^\.gitleaks\.toml$"-"^\.gitleaksignore$"-"^pytest\.ini$"-"^LICENSE$"-"^README$"-"^README\.md$"-"^CONTRIBUTING\.md$"-"^SECURITY\.md$"-"^Dockerfile$"-"^pyproject\.toml$"-"^pdm\.lock$"-"^package\.json$"-"^MANIFEST\.in$"-"^\.github/CODEOWNERS$"-"^\.github/.*\.(yml|yaml|md)$"-"\.semgrep/.*\.(yml|yaml)$"-"\.semgrepignore$"-"^\.trivyignore$"-"installers/.*\.(bat|ps1|iss|ico)$"-"docs/images/.*\.(png|jpg|jpeg|gif|svg)$"-"docs/.*\.ps1$"-"src/local_deep_research/web/static/sounds/.*\.mp3$"-"src/local_deep_research/web/static/favicon\.png$"-"unraid-templates/.*\.xml$"-"tests/ui_tests/playwright/tests/.*-snapshots/.*\.png$"-)++# Load allowed file patterns from shared whitelist (single source of truth)+REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo ".")"+WHITELIST_FILE="$REPO_ROOT/.file-whitelist.txt"++if [ ! -f "$WHITELIST_FILE" ]; then+ echo "❌ Missing .file-whitelist.txt — cannot run whitelist check."+ exit 1+fi++ALLOWED_PATTERNS=()+while IFS= read -r line; do+ [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue+ ALLOWED_PATTERNS+=("$line")+done < "$WHITELIST_FILE"# Get list of files to checkif [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then@@ -151,12 +114,10 @@ SAFE_FILENAME_PATTERNS=(".*enhanced.*token.*\.md$""docs/.*token.*\.md$""tests/.*\.py$"-".*test.*\.py$""\.secrets\.baseline$"".*session_passwords\.py$"".*change_password\.html$""tests/ui_tests/.*password.*\.js$"-"tests/ui_tests/playwright/tests/.*-snapshots/.*\.png$")# Check if filename looks suspicious@@ -250,7 +211,7 @@ elif echo "$file" | grep -iE "\.(log|tmp|temp|cache|bak|backup|swp|swo|DS_Store|SUSPICIOUS_FILETYPE_VIOLATIONS+=("$file (temporary/cache)")elif echo "$file" | grep -iE "\.(png|jpg|jpeg|gif|bmp|tiff|svg|ico|webp)$" >/dev/null; then# Images are suspicious unless in specific directories-if ! echo "$file" | grep -qE "(docs/|\.github/|installers/.*\.(ico|png)$|tests/ui_tests/playwright/tests/.*-snapshots/)"; then+if ! echo "$file" | grep -qE "(^docs/images/|^src/local_deep_research/web/static/favicon\.png$|^installers/.*\.ico$)"; thenSUSPICIOUS_FILETYPE_VIOLATIONS+=("$file (image file)")fielif echo "$file" | grep -iE "\.(mp3|mp4|wav|avi|mov|mkv|flv|wmv|webm|m4a|ogg)$" >/dev/null; then@@ -293,8 +254,10 @@ TOTAL_VIOLATIONS=0if [ ${#WHITELIST_VIOLATIONS[@]} -gt 0 ]; thenecho ""echo "❌ WHITELIST VIOLATIONS - File types not allowed in repository:"-echo " These files don't match any allowed file extension patterns."-echo " If these are legitimate files, add them to ALLOWED_PATTERNS in the workflow."+echo " These files don't match any pattern in .file-whitelist.txt."+echo " Binary files (images, audio, etc.) bloat the repo and should NOT be committed."+echo " Only a small set of explicitly listed binary files is allowed — store others externally."+echo " If this is a legitimate text/config file, add it to .file-whitelist.txt (requires maintainer approval)."echo ""for violation in "${WHITELIST_VIOLATIONS[@]}"; doecho " 🚫 $violation"@@ -311,8 +274,9 @@ echo " $line"donefi-echo " → Issue: File extension/type not in whitelist"-echo " → Fix: Add pattern to ALLOWED_PATTERNS or rename file"+echo " → Issue: File extension/type not in .file-whitelist.txt"+echo " → Fix: For text/config files, add pattern to .file-whitelist.txt"+echo " → Note: Binary files should NOT be added to the repo — store them externally"echo ""doneTOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + ${#WHITELIST_VIOLATIONS[@]}))@@ -532,8 +496,8 @@ echo " → Issue: Temporary/cache files should not be committed"echo " → Fix: Add to .gitignore and remove from repository";;"image file")-echo " → Issue: Image files should only be in docs/ or .github/ directories"-echo " → Fix: Move to docs/ directory or remove if unnecessary"+echo " → Issue: Binary image files bloat the repo and should NOT be committed"+echo " → Fix: Store images externally. Only a few explicitly listed images in docs/images/ are allowed";;"media file")echo " → Issue: Media files are large and rarely needed in code repos"@@ -574,16 +538,15 @@ exit 0elseecho ""echo "💡 To fix these issues:"-echo " - Remove data files and use external storage"+echo " - For text/config files: add pattern to .file-whitelist.txt (requires maintainer approval)"+echo " - For binary files (images, audio, video, archives): do NOT add to the repo"+echo " Binary files permanently bloat git history. Store them externally instead."+echo " Only a small set of explicitly listed binary files is permitted."echo " - Use environment variables for secrets"-echo " - Update whitelist for legitimate file types"-echo " - Compress large files or use Git LFS"echo " - Never hardcode research data or session IDs"echo " - Use .env.example files instead of .env"echo " - Replace absolute paths with relative paths or configs"echo " - Use DNS names instead of hardcoded IP addresses"-echo " - Remove suspicious file types (executables, archives, temp files)"-echo " - Move images/documents to appropriate directories (docs/, .github/)"echo ""echo "⚠️ SECURITY REMINDER: This is a public repository!"echo " Never commit sensitive data, API keys, or personal information."diff --git a/.gitignore b/.gitignoreindex fe773e2a19..1b0d9e2e95 100644--- a/.gitignore+++ b/.gitignore@@ -9,13 +9,25 @@!*.js!*.html!*.css-!*.json-!*.yml-!*.yaml-!*.sh-!*.cfg-!*.ipynb-!*.template+# JSON — path-scoped (root package.json whitelisted below)+!src/local_deep_research/defaults/**/*.json+!cookiecutter-docker/**/*.json++# YAML — non-root, path-scoped (.github/ and .semgrep/ whitelisted separately)+!community_benchmark_results/**/*.yaml+!cookiecutter-docker/**/*.yml+!examples/elasticsearch/docker-compose.yml++# Shell scripts — path-scoped (.github/ and .pre-commit-hooks/ whitelisted separately)+!scripts/**/*.sh+!tests/**/*.sh+!docs/**/*.sh+!examples/**/*.sh++# Templates, Jinja2, XML — explicit paths+!src/local_deep_research/defaults/.env.template+!src/local_deep_research/notifications/templates/**/*.jinja2+!unraid-templates/**/*.xml# Allow Python files everywhere except root!**/*.py@@ -42,6 +54,7 @@!MANIFEST.in!.pre-commit-config.yaml!eslint.config.mjs+!docker-compose.yml# Block JSON files in root directory (except package.json which is explicitly allowed above)@@ -59,7 +72,9 @@!bearer.yml!.trivyignore!.semgrep/-!.semgrep/**+!.semgrep/**/*.yml+!.semgrep/**/*.yaml+!.semgrep/**/*.md!.safety-policy.yml@@ -67,14 +82,18 @@.*.*/!.github/-!.github/**+!.github/**/*.yml+!.github/**/*.yaml+!.github/**/*.md+!.github/**/*.sh+!.github/**/*.py+!.github/CODEOWNERS!.gitleaksignore-# Allow installer files only in installers directory+# Allow installer files only in installers directory (text scripts only)!installers/**/*.bat!installers/**/*.ps1!installers/**/*.iss-!installers/**/*.ico# Block specific problematic directories even if they contain allowed filessrc/data/@@ -239,13 +258,24 @@ web*.pngtests/screenshots/screenshots/+# Explicitly allowed binary files — keep this list small.+# Binary files bloat the repo; do NOT add new ones without maintainer approval.+!docs/images/Local Search.png+!docs/images/local_search_embedding_model_type.png+!docs/images/local_search_paths.png+!src/local_deep_research/web/static/favicon.png+!src/local_deep_research/web/static/sounds/error.mp3+!src/local_deep_research/web/static/sounds/success.mp3+# Block mobile UI test artifacts (html/json reports, screenshot directories)tests/ui_tests/mobile/**/*.htmltests/ui_tests/mobile/**/*.jsontests/ui_tests/mobile/*-screenshots/-# Ignore cookiecutter-generated files.-docker-compose.*.yml+# Ignore cookiecutter-generated docker-compose files (root only).+/docker-compose.*.yml+!docker-compose.gpu.override.yml+!docker-compose.unraid.ymlbackup/# Security - ignore generated secret keys@@ -271,9 +301,9 @@ tests/**/*.md!tests/ui_tests/playwright/tests/*.js!tests/ui_tests/playwright/tests/helpers/!tests/ui_tests/playwright/tests/helpers/*.js-# Whitelist Playwright snapshot baselines (visual regression reference images)-!tests/ui_tests/playwright/tests/*.spec.js-snapshots/-!tests/ui_tests/playwright/tests/*.spec.js-snapshots/*.png+# NOTE: Playwright snapshot PNGs are NOT tracked in git.+# Visual regression tests use --update-snapshots to generate baselines locally.+# See: tests/ui_tests/playwright/README.md# Block Playwright authentication state (contains session cookies/tokens)tests/ui_tests/playwright/.auth/diff --git a/.pre-commit-hooks/file-whitelist-check.sh b/.pre-commit-hooks/file-whitelist-check.shindex a7d4f1909e..508a02b8b7 100755--- a/.pre-commit-hooks/file-whitelist-check.sh+++ b/.pre-commit-hooks/file-whitelist-check.sh@@ -2,58 +2,20 @@# Pre-commit hook adapted from GitHub workflow file-whitelist-check.yml# Only checks the files being committed, not all files-# Define allowed file extensions and specific files-ALLOWED_PATTERNS=(- "\.py$"- "\.js$"- "\.mjs$"- "\.html$"- "\.css$"- "\.json$"- "\.md$"- "\.yml$"- "\.yaml$"- "\.sh$"- "\.cfg$"- "\.ipynb$"- "\.template$"- "\.toml$"- "\.tsv$"- "\.jinja2$"- "^\.gitignore$"- "^\.gitkeep$"- ".*\.gitkeep$"- ".*\.gitignore$"- "^\.pre-commit-config\.yaml$"- "^\.coveragerc$"- "^\.secrets\.baseline$"- "^\.gitleaks\.toml$"- "^\.gitleaksignore$"- "^\.semgrepignore$"- "^\.trivyignore$"- "\.semgrep/.*\.(yml|yaml)$"- "^pytest\.ini$"- "^LICENSE$"- "^README$"- "^README\.md$"- "^CONTRIBUTING\.md$"- "^SECURITY\.md$"- "^Dockerfile$"- "^pyproject\.toml$"- "^pdm\.lock$"- "^package\.json$"- "^MANIFEST\.in$"- "^\.github/CODEOWNERS$"- "^\.github/.*\.(yml|yaml|md)$"- "installers/.*\.(bat|ps1|iss|ico)$"- "\.xml$"- "docs/images/.*\.(png|jpg|jpeg|gif|svg)$"- "docs/.*\.ps1$"- "src/local_deep_research/web/static/sounds/.*\.mp3$"- "src/local_deep_research/web/static/favicon\.png$"- "unraid-templates/.*\.xml$"- "tests/ui_tests/playwright/tests/.*-snapshots/.*\.png$"-)+# Load allowed file patterns from shared whitelist (single source of truth)+REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo ".")"+WHITELIST_FILE="$REPO_ROOT/.file-whitelist.txt"++if [ ! -f "$WHITELIST_FILE" ]; then+ echo "❌ Missing .file-whitelist.txt — cannot run whitelist check."+ exit 1+fi++ALLOWED_PATTERNS=()+while IFS= read -r line; do+ [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue+ ALLOWED_PATTERNS+=("$line")+done < "$WHITELIST_FILE"WHITELIST_VIOLATIONS=()LARGE_FILES=()@@ -93,6 +55,8 @@ TOTAL_VIOLATIONS=0if [ ${#WHITELIST_VIOLATIONS[@]} -gt 0 ]; thenecho ""echo "❌ WHITELIST VIOLATIONS - File types not allowed in repository:"+ echo " Binary files (images, audio, etc.) bloat the repo and should NOT be committed."+ echo " Only explicitly listed binary files are allowed — store others externally."for violation in "${WHITELIST_VIOLATIONS[@]}"; doecho " 🚫 $violation"done@@ -114,8 +78,9 @@ if [ $TOTAL_VIOLATIONS -eq 0 ]; thenelseecho ""echo "💡 To fix these issues:"- echo " - Add allowed file types to ALLOWED_PATTERNS"- echo " - Use Git LFS for large files"+ echo " - For text/config files: add pattern to .file-whitelist.txt (requires maintainer approval)"+ echo " - For binary files: do NOT add to the repo — they permanently bloat git history"+ echo " - For large files: use external storage"echo ""exit 1fidiff --git a/src/local_deep_research/web/routes/history_routes.py b/src/local_deep_research/web/routes/history_routes.pyindex 666a585634..841791322e 100644--- a/src/local_deep_research/web/routes/history_routes.py+++ b/src/local_deep_research/web/routes/history_routes.py@@ -1,6 +1,6 @@import json-from flask import Blueprint, jsonify, session+from flask import Blueprint, jsonify, request, sessionfrom loguru import loggerfrom ...constants import ResearchStatusdiff --git a/tests/security/test_repo_guardrails.py b/tests/security/test_repo_guardrails.pynew file mode 100644index 0000000000..01711bffc1--- /dev/null+++ b/tests/security/test_repo_guardrails.py@@ -0,0 +1,188 @@+"""Tests that repository integrity guardrails remain intact.++These tests verify structural invariants of the file whitelist and+CODEOWNERS that protect against accidental re-introduction of broad+file-type exceptions (especially binary wildcards).+"""++import re+from pathlib import Path++import pytest++REPO_ROOT = Path(__file__).resolve().parents[2]++# Binary extensions that MUST be path-anchored (start with ^) in the whitelist.+# Broad binary wildcards like `\.png$` permanently bloat git history.+BINARY_EXTENSIONS = {+ "png",+ "jpg",+ "jpeg",+ "gif",+ "bmp",+ "tiff",+ "webp",+ "svg",+ "ico",+ "mp3",+ "mp4",+ "wav",+ "ogg",+ "m4a",+ "webm",+ "exe",+ "dll",+ "so",+ "dylib",+ "bin",+ "zip",+ "tar",+ "gz",+ "rar",+ "7z",+ "pdf",+ "doc",+ "docx",+ "xls",+ "xlsx",+ "db",+ "sqlite",+ "sqlite3",+ "woff",+ "woff2",+ "ttf",+ "eot",+}++# These guardrail paths must be the LAST CODEOWNERS entries (last-match-wins).+CODEOWNERS_GUARDRAIL_PATHS = {+ "/.gitignore",+ "/.file-whitelist.txt",+ "/.pre-commit-hooks/file-whitelist-check.sh",+ "/.github/scripts/file-whitelist-check.sh",+ "/.github/CODEOWNERS",+}+++class TestFileWhitelistGuardrails:+ """Verify .file-whitelist.txt doesn't contain broad binary wildcards."""++ @pytest.fixture()+ def whitelist_patterns(self):+ """Load non-comment, non-empty lines from .file-whitelist.txt."""+ whitelist = REPO_ROOT / ".file-whitelist.txt"+ assert whitelist.exists(), ".file-whitelist.txt not found at repo root"+ lines = []+ for line in whitelist.read_text().splitlines():+ stripped = line.strip()+ if stripped and not stripped.startswith("#"):+ lines.append(stripped)+ return lines++ def test_binary_patterns_are_path_anchored(self, whitelist_patterns):+ """Binary extension patterns must start with ^ (path-scoped).++ A broad pattern like `\\.png$` would allow PNGs anywhere in the repo,+ defeating the purpose of the whitelist. Binary patterns must be+ anchored to specific paths, e.g. `^docs/images/specific\\.png$`.+ """+ violations = []+ for pattern in whitelist_patterns:+ # Check if this pattern matches a binary extension+ for ext in BINARY_EXTENSIONS:+ # Pattern ends with the extension (escaped dot + ext + $)+ if re.search(rf"\\\.{re.escape(ext)}\)?(\|.*)?$", pattern):+ if not pattern.startswith("^"):+ violations.append(+ f"Unanchored binary wildcard: '{pattern}' — "+ f"must start with ^ to scope to a specific path"+ )+ break+ assert not violations, (+ "Binary file patterns in .file-whitelist.txt must be path-anchored "+ "(start with ^) to prevent repo bloat.\n"+ + "\n".join(f" - {v}" for v in violations)+ )++ def test_no_broad_binary_wildcards(self, whitelist_patterns):+ """Binary extension patterns must not use .* wildcards.++ A pattern like `^docs/images/.*\\.png$` allows unlimited binary files+ in a directory. Binary files should be listed by explicit path to+ prevent repo bloat. Each new binary file should be a deliberate,+ reviewed addition.+ """+ violations = []+ for pattern in whitelist_patterns:+ for ext in BINARY_EXTENSIONS:+ if re.search(rf"\\\.{re.escape(ext)}\)?(\|.*)?$", pattern):+ if ".*" in pattern:+ violations.append(+ f"Broad binary wildcard: '{pattern}' — "+ f"uses .* which allows unlimited binary files; "+ f"list each binary file explicitly instead"+ )+ break+ assert not violations, (+ "Binary file patterns must not use .* wildcards. "+ "List each binary file by explicit path to prevent repo bloat.\n"+ + "\n".join(f" - {v}" for v in violations)+ )++ def test_whitelist_file_exists(self):+ """The shared whitelist file must exist."""+ assert (REPO_ROOT / ".file-whitelist.txt").exists()++ def test_whitelist_has_patterns(self, whitelist_patterns):+ """Whitelist must contain at least some patterns."""+ assert len(whitelist_patterns) > 10, (+ f"Whitelist only has {len(whitelist_patterns)} patterns — "+ "seems too few, file may be corrupted"+ )+++class TestCodeownersGuardrails:+ """Verify CODEOWNERS guardrail rules remain at the bottom."""++ @pytest.fixture()+ def codeowners_rules(self):+ """Load non-comment, non-empty lines from CODEOWNERS."""+ codeowners = REPO_ROOT / ".github" / "CODEOWNERS"+ assert codeowners.exists(), ".github/CODEOWNERS not found"+ rules = []+ for line in codeowners.read_text().splitlines():+ stripped = line.strip()+ if stripped and not stripped.startswith("#"):+ rules.append(stripped)+ return rules++ def test_guardrail_rules_are_last(self, codeowners_rules):+ """Guardrail CODEOWNERS entries must be the last rules in the file.++ GitHub CODEOWNERS uses last-match-wins. If someone adds a rule+ after the guardrails (e.g. `* @someone`), it would override the+ maintainer-only restriction on .gitignore and whitelist files.+ """+ last_n = codeowners_rules[-len(CODEOWNERS_GUARDRAIL_PATHS) :]+ actual_paths = {line.split()[0] for line in last_n}+ assert actual_paths == CODEOWNERS_GUARDRAIL_PATHS, (+ f"CODEOWNERS guardrail rules are not the last entries!\n"+ f"Expected last {len(CODEOWNERS_GUARDRAIL_PATHS)} rules to be: "+ f"{CODEOWNERS_GUARDRAIL_PATHS}\n"+ f"Got: {actual_paths}\n"+ "Someone may have added rules after the guardrails, which would "+ "override the maintainer-only restriction (last-match-wins)."+ )++ def test_guardrail_rules_are_maintainer_only(self, codeowners_rules):+ """Guardrail rules must be restricted to @LearningCircuit only."""+ last_n = codeowners_rules[-len(CODEOWNERS_GUARDRAIL_PATHS) :]+ for rule in last_n:+ parts = rule.split()+ path = parts[0]+ owners = parts[1:]+ if path in CODEOWNERS_GUARDRAIL_PATHS:+ assert owners == ["@LearningCircuit"], (+ f"Guardrail rule '{path}' has owners {owners} — "+ "must be restricted to @LearningCircuit only"+ )