@rigour-labs/core 3.0.2 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gates/deprecated-apis.d.ts +55 -0
- package/dist/gates/deprecated-apis.js +724 -0
- package/dist/gates/deprecated-apis.test.d.ts +1 -0
- package/dist/gates/deprecated-apis.test.js +288 -0
- package/dist/gates/hallucinated-imports.d.ts +79 -13
- package/dist/gates/hallucinated-imports.js +434 -50
- package/dist/gates/hallucinated-imports.test.js +707 -31
- package/dist/gates/phantom-apis.d.ts +77 -0
- package/dist/gates/phantom-apis.js +675 -0
- package/dist/gates/phantom-apis.test.d.ts +1 -0
- package/dist/gates/phantom-apis.test.js +320 -0
- package/dist/gates/runner.js +37 -15
- package/dist/gates/test-quality.d.ts +67 -0
- package/dist/gates/test-quality.js +512 -0
- package/dist/gates/test-quality.test.d.ts +1 -0
- package/dist/gates/test-quality.test.js +312 -0
- package/dist/templates/index.js +31 -1
- package/dist/types/index.d.ts +348 -0
- package/dist/types/index.js +33 -0
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phantom APIs Gate
|
|
3
|
+
*
|
|
4
|
+
* Detects calls to non-existent methods/properties on known stdlib modules.
|
|
5
|
+
* AI models confidently generate method names that look correct but don't exist —
|
|
6
|
+
* e.g. fs.readFileAsync(), path.combine(), crypto.generateHash().
|
|
7
|
+
*
|
|
8
|
+
* This is the #2 most dangerous AI hallucination after package hallucination.
|
|
9
|
+
* Unlike type checkers, this gate catches phantom APIs even in plain JS, Python,
|
|
10
|
+
* and other dynamically-typed languages where the call would silently fail at runtime.
|
|
11
|
+
*
|
|
12
|
+
* Supported languages:
|
|
13
|
+
* JS/TS — Node.js 22.x builtins (fs, path, crypto, http, os, child_process, etc.)
|
|
14
|
+
* Python — stdlib modules (os, json, sys, re, datetime, pathlib, subprocess, etc.)
|
|
15
|
+
* Go — Common hallucinated stdlib patterns (strings vs bytes, os vs io, etc.)
|
|
16
|
+
* C# — Common .NET hallucinated APIs (LINQ, File I/O, string methods)
|
|
17
|
+
* Java — Common hallucinated JDK APIs (Collections, String, Stream, Files)
|
|
18
|
+
*
|
|
19
|
+
* @since v3.0.0
|
|
20
|
+
* @since v3.0.3 — Go, C#, Java pattern-based detection added
|
|
21
|
+
*/
|
|
22
|
+
import { Gate, GateContext } from './base.js';
|
|
23
|
+
import { Failure, Provenance } from '../types/index.js';
|
|
24
|
+
export interface PhantomApiCall {
|
|
25
|
+
file: string;
|
|
26
|
+
line: number;
|
|
27
|
+
module: string;
|
|
28
|
+
method: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
}
|
|
31
|
+
export interface PhantomApisConfig {
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
check_node?: boolean;
|
|
34
|
+
check_python?: boolean;
|
|
35
|
+
check_go?: boolean;
|
|
36
|
+
check_csharp?: boolean;
|
|
37
|
+
check_java?: boolean;
|
|
38
|
+
ignore_patterns?: string[];
|
|
39
|
+
}
|
|
40
|
+
export declare class PhantomApisGate extends Gate {
|
|
41
|
+
private config;
|
|
42
|
+
constructor(config?: PhantomApisConfig);
|
|
43
|
+
protected get provenance(): Provenance;
|
|
44
|
+
run(context: GateContext): Promise<Failure[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Node.js stdlib method verification.
|
|
47
|
+
* For each known module, we maintain the actual exported methods.
|
|
48
|
+
* Any call like fs.readFileAsync() that doesn't match is flagged.
|
|
49
|
+
*/
|
|
50
|
+
private checkNodePhantomApis;
|
|
51
|
+
/**
|
|
52
|
+
* Python stdlib method verification.
|
|
53
|
+
*/
|
|
54
|
+
private checkPythonPhantomApis;
|
|
55
|
+
/** Suggest the closest real method name (Levenshtein distance ≤ 3) */
|
|
56
|
+
private suggestNodeMethod;
|
|
57
|
+
private suggestPythonMethod;
|
|
58
|
+
private findClosest;
|
|
59
|
+
private levenshtein;
|
|
60
|
+
/**
|
|
61
|
+
* Go phantom API detection — pattern-based.
|
|
62
|
+
* AI commonly hallucinates Python/JS-style method names on Go packages.
|
|
63
|
+
* e.g. strings.Contains() exists, but strings.includes() doesn't.
|
|
64
|
+
*/
|
|
65
|
+
private checkGoPhantomApis;
|
|
66
|
+
/**
|
|
67
|
+
* C# phantom API detection — pattern-based.
|
|
68
|
+
* AI hallucinates Java/Python-style method names on .NET types.
|
|
69
|
+
*/
|
|
70
|
+
private checkCSharpPhantomApis;
|
|
71
|
+
/**
|
|
72
|
+
* Java/Kotlin phantom API detection — pattern-based.
|
|
73
|
+
* AI hallucinates Python/JS-style APIs on JDK classes.
|
|
74
|
+
*/
|
|
75
|
+
private checkJavaPhantomApis;
|
|
76
|
+
private escapeRegex;
|
|
77
|
+
}
|