Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ All notable changes to killdiff are recorded here. The format follows [Keep a Ch

## [Unreleased]

## [0.1.1] - 2026-11-29

### Added
- `--timeout <ms>` sets the time limit for the baseline run and each mutant run (1000 to 86400000 ms). A baseline timeout now reports the limit and names the option.
- The MCP tool `verify_diff_tests` accepts `timeoutMs` with the same bounds.
- `killdiff --version` and `-v` print the package version. Help and the MCP server read the same constant, and a test keeps it equal to `package.json`.

### Fixed
- pnpm projects: a run could rewrite the real tree through the linked `node_modules` (pnpm's pre-run install re-pointed workspace links into the sandbox, which was then deleted), and pnpm 12 refused to run tests under a linked `node_modules`. Each pnpm sandbox now rebuilds that structure, links package contents, copies pnpm state, starts tool caches empty, turns off pnpm's install-before-run check and re-points in-repo links at the sandbox copy, so mutants in directly imported workspace packages are exercised. A `.pnpm` dependency that loads a workspace package still gets the original.
- Rust and Maven: `target` folders are no longer linked into sandboxes, and `CARGO_TARGET_DIR` is always set inside the sandbox, overriding the environment and Cargo config files. Before, binaries built from a mutant could stay in a real target directory and be reused by the next build. Because every sandbox now builds from scratch, these projects run one mutant at a time and large ones may need `--timeout`.
- SARIF output and the README action example report the released version.
- Sandboxes are built and removed asynchronously, so one worker's setup cannot push another worker's run into a false timeout.
- Sandbox cleanup unlinks every link before removing the directory.

### Changed
- README now leads with the problem, a 30-second quick start with recorded output, and install options.

Expand All @@ -27,5 +38,6 @@ First public release.
- A reusable composite GitHub Action (`action.yml`).
- `killdiff --demo`: a self-contained demo on a temporary repo.

[Unreleased]: https://github.com/flipcyde101/killdiff/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/flipcyde101/killdiff/compare/v0.1.1...HEAD
[0.1.1]: https://github.com/flipcyde101/killdiff/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/flipcyde101/killdiff/releases/tag/v0.1.0
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ npx killdiff main...HEAD --sarif > killdiff.sarif

# Override the test runner explicitly
npx killdiff main...HEAD --cmd "pytest -q"

# Allow a slow suite (80 s baseline) up to 5 minutes per run
npx killdiff main...HEAD --cmd "go test ./..." --timeout 300000
```

---

## Connect to Your Coding Agent (Stdio MCP)

`killdiff mcp` exposes `verify_diff_tests` so **Antigravity**, Claude Code, Codex, Cursor, and OpenCode can verify their own newly written tests actually kill logic mutations before handing a PR back to you.
`killdiff mcp` exposes `verify_diff_tests` so **Antigravity**, Claude Code, Codex, Cursor, and OpenCode can verify their own newly written tests actually kill logic mutations before handing a PR back to you. Arguments: `range`, `testCmd`, `maxMutants` and `timeoutMs`.

```json
{
Expand All @@ -98,7 +101,7 @@ npx killdiff main...HEAD --cmd "pytest -q"
## Reusable GitHub Action

```yaml
- uses: flipcyde101/killdiff@v0.1.0
- uses: flipcyde101/killdiff@v0.1.1
with:
range: origin/main...HEAD
max-mutants: 25
Expand All @@ -111,8 +114,10 @@ npx killdiff main...HEAD --cmd "pytest -q"

- **Diff-only scope:** Parses `git diff --unified=0` so only executable code on changed lines is mutated (skips test files, comments, strings, imports, and type declarations).
- **Polyglot on Day 1:** Mutates TypeScript/JavaScript, Python, Go, and Rust across boundary (`>=`/`>`, `<=`/`<`), equality (`===`/`!==`, `==`/`!=`), logical (`&&`/`||`, `and`/`or`), boolean (`true`/`false`, `True`/`False`), and arithmetic (`+`/`-`) operators.
- **Isolated parallel sandboxes:** Never edits your real working tree. Creates ephemeral temp workspaces symlinking/junctioning `node_modules`/`.venv`/`target` for fast setup and cleans up automatically.
- **Baseline & timeout guards:** Verifies baseline tests pass before mutating, caps runs with `--max 25`, and terminates infinite-loop mutants cleanly as `TIMEOUT` (counted as killed).
- **Isolated parallel sandboxes:** killdiff applies mutants only to temporary copies and removes them afterwards, unlinking links without following them. `node_modules` and `.venv` are linked. In pnpm projects each sandbox gets its own `node_modules` structure and pnpm's install-before-run check is turned off, so state files and workspace links stay in the sandbox. Install dependencies before running killdiff.
- **Rust and Maven:** `target` folders next to `Cargo.toml` or `pom.xml` are not shared and `CARGO_TARGET_DIR` always points inside the sandbox. Every sandbox therefore builds from scratch, mutants run one at a time, and large projects may need `--timeout`.
- **Shared by design:** package contents (and, outside pnpm projects, tool caches such as `node_modules/.vite`) are links to your real install, so a test that writes there, including through a linked workspace package, writes the real files. npm and Yarn workspace packages imported through `node_modules` resolve to the unmutated originals. In pnpm projects the same applies when a dependency stored in `.pnpm` (for example a `file:` plugin with a peer dependency) loads a workspace package: it gets the original, a second copy beside the sandbox one.
- **Baseline & timeout guards:** Verifies baseline tests pass before mutating, caps runs with `--max 25`, and terminates infinite-loop mutants cleanly as `TIMEOUT` (counted as killed). The baseline limit defaults to 60 s and each mutant gets 2.5x the baseline time; `--timeout <ms>` replaces both limits, so set it comfortably above your slowest run.

---

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "killdiff",
"version": "0.1.0",
"version": "0.1.1",
"description": "Zero-config polyglot diff-only mutation tester that catches hollow AI-generated tests in seconds (CLI, stdio MCP server, and GitHub Action).",
"license": "MIT",
"type": "module",
Expand Down
15 changes: 14 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
import { getGitDiffHunks, resolveContainedPath, validateGitRange } from "./git/diff.js";
import { generateMutantsForFile } from "./mutate/operators.js";
import { detectTestCommand } from "./runner/detect.js";
import { runMutationSuite } from "./runner/sandbox.js";
import { MAX_TIMEOUT_MS, MIN_TIMEOUT_MS, runMutationSuite } from "./runner/sandbox.js";
import { formatMarkdownReport, formatSarifReport, formatTerminalReport } from "./report/format.js";
import { startMcpStdioServer } from "./mcp/server.js";
import { runDemoMutationCheck } from "./demo/fixture.js";
Expand All @@ -18,6 +18,7 @@ export interface ParsedCliArgs {
maxMutants: number;
concurrency: number;
failUnder?: number;
timeoutMs?: number;
format: "terminal" | "json" | "markdown" | "sarif";
}

Expand All @@ -34,6 +35,8 @@ Options:
--max <n> Maximum mutants to run (default: 25)
--concurrency <n> Parallel worker sandboxes (default: 4)
--fail-under <pct> Exit code 1 if mutation score is below <pct> (0-100)
--timeout <ms> Time limit for the baseline run and each mutant run
(default: 60000 baseline, 2.5x baseline per mutant)
--json Output JSON report
--markdown Output Markdown PR summary table
--sarif Output SARIF 2.1.0 report
Expand Down Expand Up @@ -101,6 +104,15 @@ export function parseCliArgs(argv: string[]): ParsedCliArgs {
parsed.concurrency = n;
explicitRunOption = true;
i++;
} else if (arg === "--timeout") {
const raw = requireVal(argv, i, "--timeout");
const n = Number(raw);
if (!/^[0-9]+$/.test(raw.trim()) || !Number.isSafeInteger(n) || n < MIN_TIMEOUT_MS || n > MAX_TIMEOUT_MS) {
throw new Error(`--timeout must be an integer number of milliseconds ${MIN_TIMEOUT_MS}..${MAX_TIMEOUT_MS}`);
}
parsed.timeoutMs = n;
explicitRunOption = true;
i++;
} else if (arg === "--fail-under") {
const n = Number(requireVal(argv, i, "--fail-under"));
if (!Number.isFinite(n) || n < 0 || n > 100) throw new Error("--fail-under must be 0..100");
Expand Down Expand Up @@ -161,6 +173,7 @@ async function main(): Promise<void> {
range: args.range ?? "working-tree",
concurrency: args.concurrency,
maxMutants: args.maxMutants,
timeoutMs: args.timeoutMs,
});
})();

Expand Down
30 changes: 27 additions & 3 deletions src/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { resolve } from "node:path";
import { getGitDiffHunks, resolveContainedPath } from "../git/diff.js";
import { generateMutantsForFile } from "../mutate/operators.js";
import { detectTestCommand } from "../runner/detect.js";
import { runMutationSuite } from "../runner/sandbox.js";
import { MAX_TIMEOUT_MS, MIN_TIMEOUT_MS, runMutationSuite } from "../runner/sandbox.js";
import type { Mutant, MutationReport } from "../types.js";
import { KILLDIFF_VERSION } from "../version.js";

export interface McpServerOptions {
input?: Readable;
output?: Writable;
workspaceDir: string;
verifyFn?: (args: { range?: string; testCmd?: string; maxMutants?: number; cwd?: string }) => Promise<MutationReport>;
verifyFn?: (args: { range?: string; testCmd?: string; maxMutants?: number; timeoutMs?: number; cwd?: string }) => Promise<MutationReport>;
}

interface JsonRpcRequest {
Expand All @@ -34,6 +34,10 @@ const TOOL_DEFINITIONS = [
range: { type: "string", description: "Git diff range (e.g. main...HEAD or HEAD~1...HEAD). Omit for unstaged working tree diff." },
testCmd: { type: "string", description: "Optional test command override (auto-detected if omitted)." },
maxMutants: { type: "number", description: "Max mutants to test (default: 25)." },
timeoutMs: {
type: "number",
description: "Time limit in ms for the baseline run and each mutant run (1000..86400000). Default: 60000 baseline, 2.5x baseline per mutant.",
},
},
},
},
Expand All @@ -52,7 +56,7 @@ function isValidJsonRpcId(v: unknown): v is string | number | null {

async function defaultVerifyDiffTests(
defaultCwd: string,
args: { range?: string; testCmd?: string; maxMutants?: number; cwd?: string }
args: { range?: string; testCmd?: string; maxMutants?: number; timeoutMs?: number; cwd?: string }
): Promise<MutationReport> {
const repoDir = args.cwd ? resolve(args.cwd) : defaultCwd;
const hunks = getGitDiffHunks(repoDir, args.range);
Expand All @@ -72,6 +76,7 @@ async function defaultVerifyDiffTests(
testCmd,
range: args.range ?? "working-tree",
maxMutants: args.maxMutants ?? 25,
timeoutMs: args.timeoutMs,
});
}

Expand Down Expand Up @@ -184,6 +189,24 @@ export function startMcpStdioServer(opts: McpServerOptions): () => void {
maxMutants = args.maxMutants;
}

let timeoutMs: number | undefined;
if (args.timeoutMs !== undefined) {
if (
typeof args.timeoutMs !== "number" ||
!Number.isInteger(args.timeoutMs) ||
args.timeoutMs < MIN_TIMEOUT_MS ||
args.timeoutMs > MAX_TIMEOUT_MS
) {
send({
jsonrpc: "2.0",
id: req.id,
error: { code: -32602, message: `Invalid params: timeoutMs must be an integer ${MIN_TIMEOUT_MS}..${MAX_TIMEOUT_MS}` },
});
return;
}
timeoutMs = args.timeoutMs;
}

try {
if (toolName !== "verify_diff_tests") {
throw new Error(`Unknown MCP tool: ${toolName}`);
Expand All @@ -192,6 +215,7 @@ export function startMcpStdioServer(opts: McpServerOptions): () => void {
range: args.range as string | undefined,
testCmd: args.testCmd as string | undefined,
maxMutants,
timeoutMs,
});
const compact = {
range: report.range,
Expand Down
3 changes: 2 additions & 1 deletion src/report/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { MutationReport } from "../types.js";
import { KILLDIFF_VERSION } from "../version.js";

function mdCodeSpan(text: string, escapeTablePipe = false): string {
const safe = escapeTablePipe ? text.replace(/\|/g, "\\|") : text;
Expand Down Expand Up @@ -67,7 +68,7 @@ export function formatSarifReport(report: MutationReport): string {
tool: {
driver: {
name: "killdiff",
version: "0.1.0",
version: KILLDIFF_VERSION,
informationUri: "https://github.com/flipcyde101/killdiff",
rules: [
{
Expand Down
Loading
Loading