| name | capability-signature-detection |
| description | Code-scanning regex that looks for literal strings misses real usage: |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Capability Signature Detection
The Problem
Code-scanning regex that looks for literal strings misses real usage:
grep -rn '\.github/muscles/' .
const musclePath = path.join(brainDir, 'muscles', name);
execFileSync('node', [musclePath]);
The Solution
Detect the capability signature, not the literal text.
const hasCapability = (content) => {
const importsChildProcess = /require\(['"]child_process['"]\)|from ['"]child_process['"]/.test(content);
const callsExec = /exec(File)?Sync|spawn(Sync)?/.test(content);
return importsChildProcess && callsExec;
};
Pattern Design
Ask: "If a developer renames a path constant, would the test still find them?"
| Approach | Survives Rename? | Use When |
|---|
| Literal string match | No | String IS the contract |
| Import + call pattern | Yes | Behavior IS the contract |
| AST parsing | Yes | Complex patterns |
Examples
Find Files That Execute Node Scripts
const bad = /execFileSync\(['"]node['"],\s*\[['"]\.github/;
const good = (content) => {
const hasChildProcess = /child_process/.test(content);
const executesNode = /exec(File)?Sync\(\s*['"]node['"]/.test(content);
return hasChildProcess && executesNode;
};
Find Files That Make HTTP Requests
const bad = /fetch\(/;
const good = (content) => {
return /require\(['"](?:axios|got|node-fetch|undici)['"]\)|fetch\(|http\.request/.test(content);
};
Verification
- Rename a path variable → test still finds the file
- Add new caller with different variable name → test finds it
- False positives are acceptable if they're related capability
When to Apply
- Finding callers of internal APIs
- Security audits (who can exec, who can write files)
- Contract enforcement
- Dependency analysis
Tags
quality testing regex code-analysis