Catching AI Slopsquatting and Vacuous Tests in PR Diffs Before CI
Why we added deterministic manifest checks and anti-slop rules directly to git diff parsing instead of relying only on post-merge lockfile scanners.
When an AI coding assistant writes a quick handler or prototype, it sometimes invents a plausible-looking dependency name (for instance tokiio instead of tokio or reqwests instead of requests), or drops in a placeholder test like assert!(true) just to get a green test run. Attackers routinely register those frequently hallucinated names on crates.io, npm, and PyPI, a pattern often called slopsquatting.
Traditional lockfile scanners like cargo audit help once the crate is already resolved and in Cargo.lock, usually with an advisory published days or weeks later. At PR review time, you want to catch the suspicious addition in the raw manifest diff itself before anyone runs cargo build.
1. Checking added manifest lines with zero noise on metadata
In Altanix, our diff parser extracts only added lines (+) from Cargo.toml, package.json, and requirements.txt. One subtle bug we hit while testing real-world git diffs: git's default -U3 context often omits the [dependencies] header if the table already has ten crates above the insertion point, putting [dependencies] into the hunk header comment or omitting it altogether. Parsing hunk header comments and explicitly excluding [package] keys like edition, version, and license fixed false negatives on real PR diffs.
diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,3 +24,4 @@
serde = "1.0"
+tokiio = "1.0"
Each extracted package name goes through two fast checks:
First, an offline Levenshtein edit-distance check (distance 1 or 2) against a curated set of high-volume crates and packages (tokio, serde, reqwest, axum, react, axios, requests, fastapi). Second, when registry checking is enabled in the CLI or the online scanner, an async HTTP probe against crates.io/api/v1/crates/<pkg>, registry.npmjs.org/<pkg>, or pypi.org/pypi/<pkg>/json to flag HTTP 404 phantom packages immediately.
2. Spotting vacuous tests and silent error drops in the same pass
In the same single pass over added lines (excluding documentation files), the guard checks for common AI shortcuts: tautological assertions (assert!(true), expect(true).toBe(true), assert_eq!(1, 1)), silent empty catches (catch (e) {}, except: pass), unimplemented macros left behind (todo!(), unimplemented!()), and high-entropy token prefixes (AKIA..., ghp_..., sk-proj-...).
3. Where heuristics still need human judgment
Regex and Levenshtein heuristics are intentionally fast (microseconds in Rust) and need zero LLM tokens, which makes them useful as a pre-commit or MCP gate. They do not replace compiler type checking or full lockfile verification, and small legitimate crates whose names happen to be two edits away from a top crate can still trigger a warning that a human reviewer should verify against crates.io.
Try it on your own diff or locally
You can paste a public GitHub/GitLab PR URL or raw git diff at altanix.dev/try (no login required, exports SARIF 2.1.0), or run the CLI locally via altanix ai-guard --check-registries from altanix-cli.