lie-detector 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lie Detector contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,265 @@
1
- # Temporary Holding Version
1
+ # Lie Detector
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Find tests that pass but don't test anything.**
4
+
5
+ ![Lie Detector demo](demo/demo.gif)
6
+
7
+ Coverage tells you which lines ran. It does not tell you whether a test would
8
+ fail if the behavior changed. Lie Detector runs a small, local mutation audit
9
+ and shows the gap.
10
+
11
+ ```text
12
+ Coverage 100% Mutation 14% (7/50 killed)
13
+ Survived 43 Timeout 0 Quick findings 20
14
+ ```
15
+
16
+ The demo tests execute every line and still let 43 of 50 behavior changes pass.
17
+ That is the point.
18
+
19
+ ## Why
20
+
21
+ AI-written and coverage-driven tests often share the same shape:
22
+
23
+ - they call the function;
24
+ - they assert `true`, a snapshot, or that a mock was called;
25
+ - coverage looks great;
26
+ - a refactor breaks the behavior and the suite stays green.
27
+
28
+ Lie Detector makes that gap visible without uploading code, calling an LLM, or
29
+ requiring an API key.
30
+
31
+ **Website:** [https://selahattinozdmr.github.io/lie-detector/](https://selahattinozdmr.github.io/lie-detector/)
32
+
33
+ ## Install
34
+
35
+ Requirements: Node.js 22+, Git. Python 3.9+ is required only for the Python
36
+ adapter.
37
+
38
+ From a local checkout:
39
+
40
+ ```bash
41
+ git clone https://github.com/Selahattinozdmr/lie-detector
42
+ cd lie-detector
43
+ npm install
44
+ npm run build
45
+ node dist/cli.js --help
46
+ ```
47
+
48
+ To put the `lie-detector` command on your PATH while developing:
49
+
50
+ ```bash
51
+ npm link
52
+ lie-detector --help
53
+ ```
54
+
55
+ From npm (no checkout needed):
56
+
57
+ ```bash
58
+ npx lie-detector --help
59
+ ```
60
+
61
+ ### Claude Code skill
62
+
63
+ Copy the skill folder into your personal skills directory:
64
+
65
+ ```bash
66
+ mkdir -p ~/.claude/skills
67
+ cp -R skills/test-quality-audit ~/.claude/skills/
68
+ ```
69
+
70
+ Then ask Claude Code things like:
71
+
72
+ - "Do my tests really test anything?"
73
+ - "Run a mutation audit on this branch."
74
+ - "Why is coverage 100% but bugs still ship?"
75
+ - "Find the weakest tests in `src/pricing.ts`."
76
+
77
+ The skill only writes `.lie-detector/report.md` and `.lie-detector/report.json`
78
+ unless you explicitly approve a test edit.
79
+
80
+ ## Usage
81
+
82
+ Audit all TypeScript/JavaScript source files:
83
+
84
+ ```bash
85
+ lie-detector --all --lang ts
86
+ ```
87
+
88
+ Audit the current diff against `origin/main`:
89
+
90
+ ```bash
91
+ lie-detector --base origin/main
92
+ ```
93
+
94
+ Fast static pass, no mutants and no test execution:
95
+
96
+ ```bash
97
+ lie-detector --quick --all
98
+ ```
99
+
100
+ Machine-readable output and a CI gate:
101
+
102
+ ```bash
103
+ lie-detector --all --lang ts --json --fail-under 40
104
+ ```
105
+
106
+ Useful flags:
107
+
108
+ | Flag | Purpose |
109
+ | --- | --- |
110
+ | `--quick` | Static test-quality checks only |
111
+ | `--base <ref>` | Diff against a Git ref |
112
+ | `--all` | Ignore the diff and scan the project |
113
+ | `--lang <ts\|py>` | Force an adapter |
114
+ | `--json` | Print the JSON report to stdout |
115
+ | `--fail-under <n>` | Exit non-zero below a mutation score |
116
+ | `--test-cmd <cmd>` | Override test-command detection |
117
+ | `--max-mutants <n>` | Bound the number of mutants (default 50) |
118
+ | `--timeout <ms>` | Timeout per mutant (default 30000) |
119
+ | `--root <dir>` | Project root |
120
+
121
+ ## How it works
122
+
123
+ 1. **Diff** — finds changed source files and lines, or scans the project with
124
+ `--all`.
125
+ 2. **Mutate** — parses TypeScript/JavaScript with Babel or Python with `ast`
126
+ and generates small behavior changes on the changed lines.
127
+ 3. **Run** — writes one mutant, runs the project's test command, records the
128
+ result, and restores the original file from `.lie-detector/backup/`.
129
+ 4. **Restore** — restores in a `finally` block and on `SIGINT`/`SIGTERM`. The
130
+ tool does not commit, push, or leave mutated source behind.
131
+ 5. **Report** — writes Markdown and JSON reports and prints a terminal summary.
132
+
133
+ ### Mutation operators
134
+
135
+ TypeScript/JavaScript and Python share the same small operator set:
136
+
137
+ - comparison boundaries (`<`, `<=`, `>`, `>=`, `==`, `!=`, `===`, `!==`);
138
+ - boolean logic (`&&`/`||`, `and`/`or`);
139
+ - arithmetic (`+`, `-`, `*`, `/`, `%`, `//`);
140
+ - `return expr` → `return undefined` / `return None`;
141
+ - `if` and ternary condition negation;
142
+ - string, boolean, and numeric literals.
143
+
144
+ Only lines in the selected diff are mutated by default. Put
145
+ `lie-detector-ignore` on a line (or the line above) to skip it.
146
+
147
+ ### Quick checks
148
+
149
+ Quick mode does not run tests. It flags:
150
+
151
+ - tests with no assertion;
152
+ - tautologies such as `expect(true).toBe(true)` / `assert True`;
153
+ - self-comparisons such as `expect(x).toBe(x)` / `assert x == x`;
154
+ - snapshot-only tests;
155
+ - mock-only tests;
156
+ - weak assertions such as `toBeDefined()` or `assert x is not None`;
157
+ - empty Python tests.
158
+
159
+ ## Demo output
160
+
161
+ The repository ships two deliberately bad demos. Both have 100% line coverage
162
+ and tests that mostly assert nothing. These outputs were captured from actual
163
+ runs on 2026-12-06; timings vary by machine.
164
+
165
+ ### TypeScript demo
166
+
167
+ ```text
168
+ $ cd examples/ts-demo
169
+ $ node ../../dist/cli.js --all --lang ts
170
+
171
+ Lie Detector — mutation · ts
172
+ Coverage 100% Mutation 14% (7/50 killed)
173
+ Survived 43 Timeout 0 Quick findings 20
174
+ Duration 21.05s
175
+
176
+ Reports: .lie-detector/report.md, .lie-detector/report.json
177
+ ```
178
+
179
+ ### Python demo
180
+
181
+ ```text
182
+ $ cd examples/py-demo
183
+ $ node ../../dist/cli.js --all --lang py
184
+
185
+ Lie Detector — mutation · py
186
+ Coverage 100% Mutation 16% (8/50 killed)
187
+ Survived 42 Timeout 0 Quick findings 18
188
+ Duration 7.13s
189
+
190
+ Reports: .lie-detector/report.md, .lie-detector/report.json
191
+ ```
192
+
193
+ Run both checks yourself:
194
+
195
+ ```bash
196
+ npm run e2e
197
+ ```
198
+
199
+ The e2e script builds the CLI, runs both demos, asserts coverage 100%, mutation
200
+ at or below 30%, under 60 seconds per demo, and verifies that source hashes are
201
+ unchanged afterwards.
202
+
203
+ ### Recording
204
+
205
+ The demo GIF is generated from `demo/demo.tape` with
206
+ [VHS](https://github.com/charmbracelet/vhs). To re-record it:
207
+
208
+ ```bash
209
+ vhs demo/demo.tape
210
+ ```
211
+
212
+ ## Comparison
213
+
214
+ | Tool | Scope | Strengths | Trade-offs |
215
+ | --- | --- | --- | --- |
216
+ | **Coverage** (Istanbul, coverage.py) | Executed lines/branches | Fast, ubiquitous, good for finding dead code | Says nothing about assertion strength; 100% can hide weak tests |
217
+ | **Stryker** | JS/TS mutation testing | Mature, many mutators, parallel workers, HTML report | Heavier install/config; JS/TS only; not diff-first |
218
+ | **mutmut** | Python mutation testing | Established Python mutation workflow | Python only; slower; separate setup |
219
+ | **Lie Detector** | TS/JS + Python, diff-first | One small command, quick static checks, local-only, Markdown/JSON, restores source | Small operator set, sequential, no HTML/Action yet, not a replacement for Stryker/mutmut at scale |
220
+
221
+ Lie Detector is intentionally a lightweight first pass. Use it to find weak
222
+ tests in a diff, then reach for a full mutation framework when you need
223
+ exhaustive coverage of a large codebase.
224
+
225
+ ## Permissions and safety
226
+
227
+ - **Local-first:** no network calls, no telemetry, no API keys, no LLM calls.
228
+ - **Writes:** source files are temporarily mutated for the duration of one test
229
+ run. The original is backed up under `.lie-detector/backup/` and restored in a
230
+ `finally` block and on `SIGINT`/`SIGTERM`.
231
+ - **Reports and backups:** everything the tool writes lives under
232
+ `.lie-detector/` (`report.md`, `report.json`, `backup/`).
233
+ - **Git:** the tool never commits, pushes, creates branches, or changes remotes.
234
+ - **Trust:** run it on repositories you trust. The test command is executed with
235
+ your shell permissions.
236
+ - **Backups:** if the process is killed with `SIGKILL`, restore manually from
237
+ `.lie-detector/backup/*.bak`.
238
+
239
+ ## Limits
240
+
241
+ - TypeScript/JavaScript via Vitest or Jest; Python via pytest. Other runners
242
+ work with `--test-cmd`.
243
+ - Mutation runs are sequential in this MVP; there is no parallel worker pool.
244
+ - The built-in mutator is deliberately small. Stryker and mutmut are not
245
+ bundled.
246
+ - Equivalent mutants cannot be killed by a meaningful test; review survivors
247
+ manually before treating every one as a missing assertion.
248
+ - A timeout counts as a killed mutant, but the timeout count stays visible.
249
+ - Coverage is read from existing `coverage-summary.json` or `coverage.json`
250
+ files; the tool does not generate coverage itself.
251
+ - HTML report, GitHub Action, Docker install, and benchmark suite are not part
252
+ of the 0.1.0 MVP.
253
+
254
+ ## Development
255
+
256
+ ```bash
257
+ npm run build # compile TypeScript to dist/
258
+ npm test # Vitest suite
259
+ npm run test:py # Python unittest suite
260
+ npm run e2e # build + both demos + restore checks
261
+ ```
262
+
263
+ ## License
264
+
265
+ MIT. See [LICENSE](LICENSE).
package/dist/cli.js ADDED
@@ -0,0 +1,282 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { resolveDiff, resolveLanguage } from "./diff.js";
5
+ import { mutatePy } from "./mutators/py.js";
6
+ import { mutateTs } from "./mutators/ts.js";
7
+ import { quickScanPy } from "./quick/py.js";
8
+ import { quickScanTs } from "./quick/ts.js";
9
+ import { buildAndWrite, readCoverage, renderJson, renderTerminal, } from "./report/index.js";
10
+ import { RestoreManager } from "./restore.js";
11
+ import { detectTestCommand, runMutants } from "./runner.js";
12
+ const VERSION = "0.1.0";
13
+ function usage() {
14
+ return `lie-detector ${VERSION}
15
+
16
+ Find tests that pass but don't test anything.
17
+
18
+ Usage:
19
+ lie-detector [options]
20
+
21
+ Options:
22
+ --quick Statically analyze tests without running mutants
23
+ --base <ref> Git ref to diff against (default: merge-base origin/main, then HEAD~1)
24
+ --all Analyze all source files instead of a diff
25
+ --lang <ts|py> Force language adapter (default: auto)
26
+ --json Print JSON report to stdout
27
+ --fail-under <n> Exit non-zero when mutation score is below n
28
+ --test-cmd <cmd> Override the test command
29
+ --max-mutants <n> Maximum mutants to run (default: 50)
30
+ --timeout <ms> Timeout per mutant (default: 30000)
31
+ --root <dir> Project root (default: current directory)
32
+ --help Show this help
33
+ --version Show version
34
+
35
+ Examples:
36
+ lie-detector --all --lang ts
37
+ lie-detector --base origin/main --fail-under 40
38
+ lie-detector --quick --json
39
+ `;
40
+ }
41
+ function value(args, index, flag) {
42
+ const next = args[index + 1];
43
+ if (!next || next.startsWith("--"))
44
+ throw new Error(`${flag} requires a value`);
45
+ return next;
46
+ }
47
+ function parseNumber(raw, flag) {
48
+ const value = Number(raw);
49
+ if (!Number.isFinite(value) || value < 0) {
50
+ throw new Error(`${flag} must be a non-negative number`);
51
+ }
52
+ return value;
53
+ }
54
+ function parseArgs(args) {
55
+ const options = {
56
+ quick: false,
57
+ all: false,
58
+ lang: "auto",
59
+ json: false,
60
+ maxMutants: 50,
61
+ timeoutMs: 30_000,
62
+ root: process.cwd(),
63
+ };
64
+ for (let index = 0; index < args.length; index += 1) {
65
+ const arg = args[index];
66
+ switch (arg) {
67
+ case "--help":
68
+ case "-h":
69
+ return "help";
70
+ case "--version":
71
+ case "-v":
72
+ return "version";
73
+ case "--quick":
74
+ options.quick = true;
75
+ break;
76
+ case "--all":
77
+ options.all = true;
78
+ break;
79
+ case "--json":
80
+ options.json = true;
81
+ break;
82
+ case "--base":
83
+ options.base = value(args, index, arg);
84
+ index += 1;
85
+ break;
86
+ case "--lang": {
87
+ const lang = value(args, index, arg);
88
+ if (lang !== "ts" && lang !== "py" && lang !== "auto") {
89
+ throw new Error("--lang must be ts, py, or auto");
90
+ }
91
+ options.lang = lang;
92
+ index += 1;
93
+ break;
94
+ }
95
+ case "--fail-under":
96
+ options.failUnder = parseNumber(value(args, index, arg), arg);
97
+ index += 1;
98
+ break;
99
+ case "--test-cmd":
100
+ options.testCmd = value(args, index, arg);
101
+ index += 1;
102
+ break;
103
+ case "--max-mutants":
104
+ options.maxMutants = Math.floor(parseNumber(value(args, index, arg), arg));
105
+ index += 1;
106
+ break;
107
+ case "--timeout":
108
+ options.timeoutMs = Math.floor(parseNumber(value(args, index, arg), arg));
109
+ index += 1;
110
+ break;
111
+ case "--root":
112
+ options.root = resolve(value(args, index, arg));
113
+ index += 1;
114
+ break;
115
+ default:
116
+ if (arg.startsWith("--base=")) {
117
+ options.base = arg.slice("--base=".length);
118
+ }
119
+ else if (arg.startsWith("--lang=")) {
120
+ const lang = arg.slice("--lang=".length);
121
+ if (lang !== "ts" && lang !== "py" && lang !== "auto") {
122
+ throw new Error("--lang must be ts, py, or auto");
123
+ }
124
+ options.lang = lang;
125
+ }
126
+ else if (arg.startsWith("--fail-under=")) {
127
+ options.failUnder = parseNumber(arg.slice("--fail-under=".length), "--fail-under");
128
+ }
129
+ else if (arg.startsWith("--max-mutants=")) {
130
+ options.maxMutants = Math.floor(parseNumber(arg.slice("--max-mutants=".length), "--max-mutants"));
131
+ }
132
+ else if (arg.startsWith("--timeout=")) {
133
+ options.timeoutMs = Math.floor(parseNumber(arg.slice("--timeout=".length), "--timeout"));
134
+ }
135
+ else if (arg.startsWith("-")) {
136
+ throw new Error(`Unknown option: ${arg}`);
137
+ }
138
+ else {
139
+ throw new Error(`Unexpected argument: ${arg}`);
140
+ }
141
+ }
142
+ }
143
+ return options;
144
+ }
145
+ function matchesLanguage(filePath, lang) {
146
+ if (lang === "py")
147
+ return filePath.endsWith(".py");
148
+ if (filePath.endsWith(".d.ts"))
149
+ return false;
150
+ return /\.(ts|tsx|js|jsx|mjs|cjs)$/.test(filePath);
151
+ }
152
+ function collectQuickFindings(root, files, lang) {
153
+ const findings = [];
154
+ for (const file of files) {
155
+ if (!file.isTest || !matchesLanguage(file.path, lang))
156
+ continue;
157
+ const fullPath = join(root, file.path);
158
+ try {
159
+ if (lang === "py") {
160
+ findings.push(...quickScanPy(fullPath, root));
161
+ }
162
+ else {
163
+ findings.push(...quickScanTs(readFileSync(fullPath, "utf8"), file.path));
164
+ }
165
+ }
166
+ catch (error) {
167
+ process.stderr.write(`lie-detector: skipped quick scan for ${file.path}: ${error instanceof Error ? error.message : String(error)}\n`);
168
+ }
169
+ }
170
+ return findings;
171
+ }
172
+ function collectMutants(root, files, lang, usedAll, maxMutants) {
173
+ const mutants = [];
174
+ for (const file of files) {
175
+ if (mutants.length >= maxMutants)
176
+ break;
177
+ const fullPath = join(root, file.path);
178
+ const lines = usedAll ? undefined : file.lines;
179
+ const remaining = maxMutants - mutants.length;
180
+ try {
181
+ if (lang === "py") {
182
+ mutants.push(...mutatePy(file.path, { cwd: root, lines, maxMutants: remaining }));
183
+ }
184
+ else {
185
+ const source = readFileSync(fullPath, "utf8");
186
+ const generated = mutateTs(source, { file: file.path, lines });
187
+ mutants.push(...generated.slice(0, remaining));
188
+ }
189
+ }
190
+ catch (error) {
191
+ process.stderr.write(`lie-detector: skipped mutant generation for ${file.path}: ${error instanceof Error ? error.message : String(error)}\n`);
192
+ }
193
+ }
194
+ return mutants.slice(0, maxMutants);
195
+ }
196
+ async function main() {
197
+ const parsed = parseArgs(process.argv.slice(2));
198
+ if (parsed === "help") {
199
+ process.stdout.write(usage());
200
+ return;
201
+ }
202
+ if (parsed === "version") {
203
+ process.stdout.write(`${VERSION}\n`);
204
+ return;
205
+ }
206
+ const options = parsed;
207
+ const started = Date.now();
208
+ const root = resolve(options.root);
209
+ const diff = resolveDiff(root, {
210
+ base: options.base,
211
+ all: options.all,
212
+ lang: options.lang,
213
+ });
214
+ const language = resolveLanguage(diff.files, options.lang);
215
+ const sourceFiles = diff.sourceFiles.filter((file) => matchesLanguage(file.path, language));
216
+ const testFiles = diff.testFiles.filter((file) => matchesLanguage(file.path, language));
217
+ if (sourceFiles.length === 0) {
218
+ throw new Error(`No ${language} source files found. Try --all, or check --base / --lang.${" "}`);
219
+ }
220
+ const quickFindings = collectQuickFindings(root, diff.files, language);
221
+ let mutants = [];
222
+ let runResults = [];
223
+ let testCommand = null;
224
+ let restoreManager = null;
225
+ if (!options.quick) {
226
+ mutants = collectMutants(root, sourceFiles, language, diff.usedAll, options.maxMutants);
227
+ if (mutants.length > 0) {
228
+ testCommand = options.testCmd ?? detectTestCommand(root, language);
229
+ restoreManager = new RestoreManager(join(root, ".lie-detector", "backup"));
230
+ restoreManager.installSignalHandlers();
231
+ try {
232
+ runResults = runMutants(mutants, {
233
+ cwd: root,
234
+ testCommand,
235
+ timeoutMs: options.timeoutMs,
236
+ maxMutants: options.maxMutants,
237
+ restoreManager,
238
+ onProgress: (result, index, total) => {
239
+ if (options.json)
240
+ return;
241
+ process.stderr.write(`\r[${index + 1}/${total}] ${result.status} ${result.mutant.file}:${result.mutant.line} `);
242
+ },
243
+ });
244
+ }
245
+ finally {
246
+ restoreManager.dispose();
247
+ if (!options.json)
248
+ process.stderr.write("\n");
249
+ }
250
+ }
251
+ }
252
+ const coverage = readCoverage(root);
253
+ const outputDir = join(root, ".lie-detector");
254
+ const { report } = buildAndWrite({
255
+ root,
256
+ language,
257
+ mode: options.quick ? "quick" : "mutation",
258
+ base: diff.base,
259
+ usedAll: diff.usedAll,
260
+ durationMs: Date.now() - started,
261
+ testCommand,
262
+ coverage,
263
+ mutants: runResults,
264
+ quickFindings,
265
+ files: diff.files.map((file) => file.path),
266
+ }, outputDir);
267
+ if (options.json) {
268
+ process.stdout.write(renderJson(report));
269
+ }
270
+ else {
271
+ process.stdout.write(renderTerminal(report));
272
+ }
273
+ if (options.failUnder !== undefined &&
274
+ report.totals.mutationScore !== null &&
275
+ report.totals.mutationScore < options.failUnder) {
276
+ process.exitCode = 1;
277
+ }
278
+ }
279
+ main().catch((error) => {
280
+ process.stderr.write(`lie-detector: ${error instanceof Error ? error.message : String(error)}\n`);
281
+ process.exitCode = 1;
282
+ });