deploy
This commit is contained in:
72
tests/test_inspector.py
Normal file
72
tests/test_inspector.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from agent import (
|
||||
RepoFile,
|
||||
_citation,
|
||||
_recommendation,
|
||||
_redact_secrets,
|
||||
_score,
|
||||
classify_path,
|
||||
)
|
||||
|
||||
|
||||
def test_file_classification_core_categories():
|
||||
assert classify_path("src/app.py") == "source"
|
||||
assert classify_path(".github/workflows/ci.yml") == "CI/CD"
|
||||
assert classify_path("Dockerfile") == "Docker/container"
|
||||
assert classify_path("tests/test_app.py") == "tests"
|
||||
assert classify_path("README.md") == "docs"
|
||||
assert classify_path("package-lock.json") == "package/dependency"
|
||||
assert classify_path("infra/main.tf") == "infra/IaC"
|
||||
assert classify_path("scripts/deploy.sh") == "scripts"
|
||||
assert classify_path(".env.example") == "hidden/dotfiles"
|
||||
|
||||
|
||||
def test_citation_extracts_line_range_and_redacts_secret():
|
||||
f = RepoFile(
|
||||
path="config.py",
|
||||
sha="abc",
|
||||
size=50,
|
||||
category="source",
|
||||
text="SAFE=1\nAPI_KEY='supersecretvalue12345'\nEND=1",
|
||||
lines=["SAFE=1", "API_KEY='supersecretvalue12345'", "END=1"],
|
||||
)
|
||||
c = _citation(f, 2)
|
||||
assert c["path"] == "config.py"
|
||||
assert c["line_start"] == 2
|
||||
assert "supersecretvalue12345" not in c["snippet"]
|
||||
assert "<REDACTED>" in c["snippet"]
|
||||
|
||||
|
||||
def test_redact_secret_patterns():
|
||||
text = "token = ghp_abcdefghijklmnopqrstuvwxyz1234567890 and password=abc123456789xyz"
|
||||
redacted = _redact_secrets(text)
|
||||
assert "ghp_abcdefghijklmnopqrstuvwxyz" not in redacted
|
||||
assert "abc123456789xyz" not in redacted
|
||||
assert "<REDACTED>" in redacted
|
||||
|
||||
|
||||
def test_scoring_penalizes_missing_repo_capabilities():
|
||||
score = _score(
|
||||
findings=[{"severity": "high", "category": "security/config"}],
|
||||
file_paths={"src/app.py", "package.json"},
|
||||
categories={"tests": 0, "docs": 0, "CI/CD": 0},
|
||||
skipped=[],
|
||||
)
|
||||
assert 0 <= score["total"] <= 100
|
||||
assert score["sub_scores"]["security"] < 100
|
||||
assert score["sub_scores"]["testing"] < 100
|
||||
assert score["sub_scores"]["docs"] < 100
|
||||
|
||||
|
||||
def test_issue_payload_generation_contains_citations():
|
||||
rec = _recommendation(
|
||||
"medium",
|
||||
"Add .dockerignore",
|
||||
"Prevent unwanted files from entering Docker build context.",
|
||||
[{"path": ".dockerignore", "line_start": None, "line_end": None, "snippet": "No .dockerignore found."}],
|
||||
"low",
|
||||
"medium",
|
||||
["docker", "security"],
|
||||
)
|
||||
assert rec["issue_payload"]["title"] == "Add .dockerignore"
|
||||
assert "No .dockerignore found" in rec["issue_payload"]["body"]
|
||||
assert "docker" in rec["issue_payload"]["labels"]
|
||||
Reference in New Issue
Block a user