Skip to content

~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.

2.8 KB
Raw Blame
"""Contracts for repository-local DevSkim scan scope."""

# allow: no-sut-import — this test parses .github/workflows/devskim.yml
# directly; the "system under test" is CI configuration, not application
# code, so there is nothing under local_deep_research to import.

from pathlib import Path

import yaml


REPO_ROOT = Path(__file__).resolve().parents[2]
WORKFLOW = REPO_ROOT / ".github" / "workflows" / "devskim.yml"


def _devskim_action_step() -> dict:
    workflow = yaml.safe_load(WORKFLOW.read_text(encoding="utf-8"))
    steps = workflow["jobs"]["devskim-scan"]["steps"]
    return next(
        step
        for step in steps
        if str(step.get("uses", "")).startswith("microsoft/DevSkim-Action@")
    )


def test_repository_directory_ignores_match_absolute_scan_target():
    """The action passes an absolute workspace path to DevSkim.

    Root-relative globs such as ``tests/**`` do not match that target and let
    test-only TLS, certificate, token, and eval fixtures reach code scanning.

    Supplying ``ignore-globs`` at all also replaces the DevSkim action's own
    defaults (``**/.git/**,**/bin/**``) instead of adding to them, so those
    two are repeated in the configured list. This test catches a revert that
    either drops the ``**/`` prefix from the repository-directory globs, or
    drops the repeated ``**/.git/**``/``**/bin/**`` defaults.
    """
    raw_globs = _devskim_action_step()["with"]["ignore-globs"]
    globs = {glob.strip() for glob in raw_globs.split(",")}

    assert {
        "**/tests/**",
        "**/examples/**",
        "**/docs/**",
        "**/node_modules/**",
        "**/.git/**",
        "**/bin/**",
    } <= globs
    assert (
        not {
            "tests/**",
            "examples/**",
            "docs/**",
            "node_modules/**",
            ".git/**",
            "bin/**",
        }
        & globs
    )


def test_ds126858_weak_hash_rule_is_not_excluded():
    """DS126858 (weak/broken hash algorithm) must stay enabled.

    The rule was re-enabled (#6650) after every legitimate weak-hash use in
    the scanned tree was given a line-level ``# DevSkim: ignore DS126858``
    suppression (see .github/SECURITY_ALERTS.md). Re-adding DS126858 to
    ``exclude-rules`` here would silently disable the rule repository-wide
    again instead of relying on those targeted suppressions, so this test
    fails a revert of that change.
    """
    raw_excludes = _devskim_action_step()["with"]["exclude-rules"]
    excluded = {rule.strip() for rule in raw_excludes.split(",")}

    assert "DS126858" not in excluded


def test_ds173237_secret_rule_is_not_excluded():
    """Keep secret scanning on outside the reviewed Gitleaks allowlist IDs."""
    raw_excludes = _devskim_action_step()["with"]["exclude-rules"]
    excluded = {rule.strip() for rule in raw_excludes.split(",")}

    assert "DS173237" not in excluded