Files
claude-plugin/plugins/reviews/skills/audit-code/tests/test_language_detect.py
T
mroberts f5934181ec Move the code and terraform audits into the reviews plugin
Copy the standalone code-review and terraform-review skills into
plugins/reviews as audit-code and audit-terraform. The rename separates the
automated, linter-driven audits from the guided review-pr walkthrough that
already lived here.

Resolve bundled script paths through ${SKILL_DIR}, exported in a new step 0.
CLAUDE_PLUGIN_ROOT is not set in the Bash tool environment, so the obvious
substitution would have expanded to nothing and broken every collection
script invocation.

Replace the PLAN and DESIGN docs with READMEs written from the current
SKILL.md and scripts. The old docs had drifted badly: they named semgrep
where the code calls opengrep, scoped five review agents where there are
now eight, and predated Lua, PowerShell, and GitHub Actions support.

Add CONSISTENCY_NORMS to the audit-terraform agent inputs. The collection
script writes consistency_norms.json and the agent prompt declares it, but
SKILL.md never listed it, leaving the variable unsubstituted.

Drop the --ingest-verdicts instruction from both skills. review_stats.py
parses no arguments, so the ref-mode verdict template it told users to feed
back could never be read.

Point audit-terraform's smoke test at README.md and resolve its fixture
paths relative to the test file rather than an absolute home directory.

Tests: 197 passing (audit-code), 106 passing (audit-terraform).
2026-07-21 11:11:05 -05:00

136 lines
4.1 KiB
Python

from scripts.language_detect import (
detect_language, is_dep_manifest, is_gha_file, is_supported_source,
known_unsupported_language,
)
def test_known_unsupported_languages():
assert known_unsupported_language("cmd/main.go") == "Go"
assert known_unsupported_language("lib/foo.rb") == "Ruby"
assert known_unsupported_language("src/Main.java") == "Java"
assert known_unsupported_language("src/main.rs") == "Rust"
assert known_unsupported_language("src/App.kt") == "Kotlin"
def test_known_unsupported_returns_none_for_supported():
assert known_unsupported_language("src/api.py") is None
assert known_unsupported_language("src/index.ts") is None
def test_known_unsupported_returns_none_for_non_source():
assert known_unsupported_language("README.md") is None
assert known_unsupported_language("Dockerfile") is None
assert known_unsupported_language("config.yaml") is None
def test_python_file_detected():
assert detect_language("src/api.py") == "python"
def test_typescript_extensions():
assert detect_language("src/index.ts") == "typescript"
assert detect_language("src/component.tsx") == "typescript"
def test_javascript_extensions():
assert detect_language("src/index.js") == "javascript"
assert detect_language("src/component.jsx") == "javascript"
assert detect_language("src/module.mjs") == "javascript"
assert detect_language("src/legacy.cjs") == "javascript"
def test_csharp_file_detected():
assert detect_language("Program.cs") == "csharp"
def test_unsupported_source_returns_none():
assert detect_language("main.go") is None
assert detect_language("script.rb") is None
assert detect_language("Main.java") is None
def test_non_source_files_return_none():
assert detect_language("README.md") is None
assert detect_language("Dockerfile") is None
assert detect_language("config.yaml") is None
def test_is_dep_manifest_python():
assert is_dep_manifest("requirements.txt")
assert is_dep_manifest("requirements-dev.txt")
assert is_dep_manifest("pyproject.toml")
assert is_dep_manifest("poetry.lock")
assert is_dep_manifest("Pipfile.lock")
def test_is_dep_manifest_javascript():
assert is_dep_manifest("package.json")
assert is_dep_manifest("package-lock.json")
assert is_dep_manifest("yarn.lock")
assert is_dep_manifest("pnpm-lock.yaml")
def test_is_dep_manifest_csharp():
assert is_dep_manifest("MyApp.csproj")
assert is_dep_manifest("MyApp.sln")
assert is_dep_manifest("packages.config")
def test_is_supported_source():
assert is_supported_source("src/api.py")
assert is_supported_source("src/index.ts")
assert not is_supported_source("main.go")
assert not is_supported_source("README.md")
def test_lua_file_detected():
assert detect_language("src/game.lua") == "lua"
def test_lua_is_supported_source():
assert is_supported_source("src/game.lua")
def test_lua_not_in_known_unsupported():
assert known_unsupported_language("src/game.lua") is None
def test_powershell_extensions_detected():
assert detect_language("scripts/Deploy.ps1") == "powershell"
assert detect_language("module/Helpers.psm1") == "powershell"
assert detect_language("module/Helpers.psd1") == "powershell"
def test_powershell_is_supported_source():
assert is_supported_source("scripts/Deploy.ps1")
def test_powershell_not_in_known_unsupported():
assert known_unsupported_language("scripts/Deploy.ps1") is None
def test_gha_workflow_yml_detected():
assert is_gha_file(".github/workflows/ci.yml")
def test_gha_workflow_yaml_detected():
assert is_gha_file(".github/workflows/deploy.yaml")
def test_gha_actions_action_yml_detected():
assert is_gha_file(".github/actions/my-action/action.yml")
def test_non_gha_yaml_not_detected():
assert not is_gha_file("config/app.yml")
assert not is_gha_file("docker-compose.yaml")
assert not is_gha_file("README.md")
def test_gha_file_wrong_extension():
assert not is_gha_file(".github/workflows/ci.json")
def test_gha_file_windows_style_path():
assert is_gha_file(".github\\workflows\\ci.yml")