diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3f17524 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,31 @@ +# Changelog + +All notable changes to killdiff are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/). + +## [Unreleased] + +### Added +- `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`. + +### Changed +- README now leads with the problem, a 30-second quick start with recorded output, and install options. + +### Added (docs) +- This changelog and a launch post draft (`docs/launch-draft.md`). + +## [0.1.0] - 2026-11-21 + +First public release. + +### Added +- Diff-only mutation testing: mutates only executable lines changed in a git range and skips tests, comments, strings, imports and type declarations. +- Mutators for TypeScript/JavaScript, Python, Go and Rust: boundary, equality, logical, boolean and arithmetic operators. +- Isolated parallel sandboxes that never edit the working tree, with a baseline check and a timeout guard for infinite-loop mutants. +- Auto-detection of vitest, jest, pytest, `go test` and `cargo test`, plus `--cmd` to override. +- Reports for the terminal, JSON (`--json`), Markdown (`--markdown`) and SARIF 2.1.0 (`--sarif`), and a `--fail-under` gate. +- `killdiff mcp`: a stdio MCP server exposing `verify_diff_tests` for coding agents. +- 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 +[0.1.0]: https://github.com/flipcyde101/killdiff/releases/tag/v0.1.0 diff --git a/README.md b/README.md index 0dd2ec5..3c8c272 100644 --- a/README.md +++ b/README.md @@ -13,29 +13,66 @@ --- -## Catch Hollow AI Tests in Seconds (Zero Setup) +## The problem + +An AI coding agent hands back a pull request with new code and new tests. The tests pass and coverage looks fine. But a test that runs a line is not a test that checks it: if you flip `<=` to `<` in the new code and every test still passes, the tests prove nothing about that line. + +killdiff finds those hollow tests. It makes small logic changes (mutants) to **only the lines your diff touched**, reruns your tests against each one in an isolated copy of the repo, and lists every change your tests failed to notice. Because it only looks at the diff, it finishes in seconds instead of the minutes or hours a whole-repo mutation run takes. + +## 30-second quick start + +Needs Node 24 or newer and git. Nothing to configure. ```bash npx killdiff --demo ``` -Spins up a temporary git repo with a simulated refund-approval PR (`src/auth.mjs` + weak unit tests that pass baseline), mutates only the changed diff lines in parallel isolated sandboxes, and reports the mutations the tests missed (`25%` score: 3 killed, 9 survived out of 12 mutants). +The demo builds a throwaway git repo with a simulated refund-approval change (`src/auth.mjs`) and weak tests that pass, then mutates the changed lines. Real output from the v0.1.0 build (Windows 11, Node 24.19; timing varies by machine): + +```text +killdiff · range: HEAD~1...HEAD (demo) · 12 mutant(s) · 1.10s +Score: 25% (3 killed, 9 survived, 0 timeout) + Surviving mutants (tests did not fail when logic broke): + • SURVIVED [BOUNDARY] src/auth.mjs:3 (<= -> <) | if (amount <= 500 && role === 'support') return true; + • SURVIVED [EQUALITY] src/auth.mjs:3 (=== -> !==) | if (amount <= 500 && role === 'support') return true; + • SURVIVED [LOGICAL] src/auth.mjs:3 (&& -> ||) | if (amount <= 500 && role === 'support') return true; + • SURVIVED [BOOLEAN] src/auth.mjs:3 (true -> false) | if (amount <= 500 && role === 'support') return true; + • SURVIVED [BOUNDARY] src/auth.mjs:4 (>= -> >) | if (role === 'admin' && amount >= 0) return true; + • SURVIVED [EQUALITY] src/auth.mjs:4 (=== -> !==) | if (role === 'admin' && amount >= 0) return true; + • SURVIVED [LOGICAL] src/auth.mjs:4 (&& -> ||) | if (role === 'admin' && amount >= 0) return true; + • SURVIVED [BOOLEAN] src/auth.mjs:4 (true -> false) | if (role === 'admin' && amount >= 0) return true; + • SURVIVED [BOOLEAN] src/auth.mjs:5 (false -> true) | return false; +``` ---- +Nine of twelve logic changes went unnoticed, so those tests would not catch a real bug on those lines. The demo repo and its scenario are simulated; the mutation run and the numbers are real. -## Quick Start +Then point it at your own branch: ```bash -# Mutate only lines changed against main npx killdiff main...HEAD +``` -# Enforce an 80% mutation score gate in CI with Markdown PR table +## Install + +| How | Command | +|---|---| +| Run without installing | `npx killdiff main...HEAD` | +| Add to a project | `npm install --save-dev killdiff` | +| Install globally | `npm install -g killdiff` | +| From source | `git clone https://github.com/flipcyde101/killdiff && cd killdiff && npm ci && npm run build && node dist/cli.js --help` | + +killdiff has no runtime dependencies. It auto-detects vitest, jest, pytest, `go test` and `cargo test`; pass `--cmd` for anything else. + +## More examples + +```bash +# Enforce an 80% mutation score gate in CI with a Markdown PR table npx killdiff origin/main...HEAD --max 25 --fail-under 80 --markdown # Output SARIF 2.1.0 for GitHub Code Scanning npx killdiff main...HEAD --sarif > killdiff.sarif -# Override test runner explicitly +# Override the test runner explicitly npx killdiff main...HEAD --cmd "pytest -q" ``` @@ -108,6 +145,10 @@ flowchart LR - **[boxcheck](https://github.com/flipcyde101/boxcheck)**: Local DOM geometry, CSS cascade, and layout-collision oracle (CLI + MCP) over raw Node 24 WebSocket CDP. - **killdiff** *(this repo)*: Zero-config polyglot diff-only mutation tester catching hollow AI-generated tests (CLI + MCP + GitHub Action). +## Changelog + +See [CHANGELOG.md](./CHANGELOG.md). + ## License [MIT](./LICENSE) diff --git a/docs/launch-draft.md b/docs/launch-draft.md new file mode 100644 index 0000000..dd9ce1d --- /dev/null +++ b/docs/launch-draft.md @@ -0,0 +1,39 @@ +# Launch post draft (not sent) + +Status: DRAFT. Nothing here has been posted. Posting needs the owner's approval. + +## Channel 1: Hacker News (Show HN) + +**Title:** Show HN: Killdiff - mutation-test only the lines your PR changed + +**Body:** + +AI coding agents write tests that pass. Passing is not the same as checking. I kept getting PRs where the new tests ran the new code but would not fail if the logic was wrong. + +killdiff takes a git range, makes small logic changes (flip `<=` to `<`, `&&` to `||`, `true` to `false`) to only the changed lines, and reruns your tests against each one in an isolated copy of the repo. Any change your tests miss is listed as a survivor. + +Because it only touches the diff, a run takes seconds. It works on TypeScript/JavaScript, Python, Go and Rust with no config, and has no runtime dependencies. + +Try it with no setup: `npx killdiff --demo`. On the built-in demo, 9 of 12 mutants survive a test file that passes. + +It also runs as an MCP server, so an agent can check its own tests before handing work back, and as a GitHub Action with a score gate. + +Limits, so nobody is surprised: the mutators are lexical, not compiler-AST based, so StrykerJS, mutmut and cargo-mutants go deeper on a single language. killdiff trades depth for speed and for working across languages on a diff. + +Repo: https://github.com/flipcyde101/killdiff (MIT) + +## Channel 2: r/programming or r/ExperiencedDevs (short form) + +**Title:** I built a diff-only mutation tester to catch AI-written tests that check nothing + +Same body as above, trimmed to the first three paragraphs plus the repo link. + +## Channel 3: LinkedIn (portfolio angle) + +Coverage tells you a line ran. It does not tell you a test would fail if the line were wrong. I built killdiff to answer the second question for the exact lines a pull request changes, in seconds, across four languages. Open source, MIT: https://github.com/flipcyde101/killdiff + +## Before posting + +- Merge the release-polish PR so the README quick start matches the post. +- Confirm `npx killdiff --demo` works from a clean machine against the published npm version. +- Be available for a few hours after posting to answer comments. diff --git a/src/cli.ts b/src/cli.ts index c76c9d7..43c1583 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -9,9 +9,10 @@ import { formatMarkdownReport, formatSarifReport, formatTerminalReport } from ". import { startMcpStdioServer } from "./mcp/server.js"; import { runDemoMutationCheck } from "./demo/fixture.js"; import type { Mutant } from "./types.js"; +import { KILLDIFF_VERSION } from "./version.js"; export interface ParsedCliArgs { - mode: "help" | "run" | "mcp" | "demo"; + mode: "help" | "version" | "run" | "mcp" | "demo"; range?: string; testCmd?: string; maxMutants: number; @@ -21,7 +22,7 @@ export interface ParsedCliArgs { } function printHelp(): void { - console.log(`killdiff v0.1.0 - Polyglot diff-only mutation tester for hollow AI tests (CLI + MCP) + console.log(`killdiff v${KILLDIFF_VERSION} -Polyglot diff-only mutation tester for hollow AI tests (CLI + MCP) Usage: killdiff [git-range] [options] Mutate changed lines in git diff (default: unstaged diff) @@ -36,7 +37,8 @@ Options: --json Output JSON report --markdown Output Markdown PR summary table --sarif Output SARIF 2.1.0 report - -h, --help Show this help`); + -h, --help Show this help + -v, --version Show version`); } function requireVal(argv: string[], i: number, flag: string): string { @@ -63,6 +65,9 @@ export function parseCliArgs(argv: string[]): ParsedCliArgs { if (arg === "-h" || arg === "--help") { parsed.mode = "help"; return parsed; + } else if (arg === "-v" || arg === "--version") { + parsed.mode = "version"; + return parsed; } else if (arg === "mcp") { explicitMcp = true; parsed.mode = "mcp"; @@ -124,6 +129,10 @@ async function main(): Promise { printHelp(); return; } + if (args.mode === "version") { + console.log(KILLDIFF_VERSION); + return; + } if (args.mode === "mcp") { startMcpStdioServer({ workspaceDir: process.cwd() }); diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 8c88a12..39d3f3e 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -7,6 +7,7 @@ import { generateMutantsForFile } from "../mutate/operators.js"; import { detectTestCommand } from "../runner/detect.js"; import { runMutationSuite } from "../runner/sandbox.js"; import type { Mutant, MutationReport } from "../types.js"; +import { KILLDIFF_VERSION } from "../version.js"; export interface McpServerOptions { input?: Readable; @@ -103,7 +104,7 @@ export function startMcpStdioServer(opts: McpServerOptions): () => void { result: { protocolVersion: "2024-11-05", capabilities: { tools: {} }, - serverInfo: { name: "killdiff", version: "0.1.0" }, + serverInfo: { name: "killdiff", version: KILLDIFF_VERSION }, }, }); return; diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..2b6f80e --- /dev/null +++ b/src/version.ts @@ -0,0 +1,2 @@ +/** Package version, kept in step with package.json by tests/version.test.ts. */ +export const KILLDIFF_VERSION = "0.1.0"; diff --git a/tests/version.test.ts b/tests/version.test.ts new file mode 100644 index 0000000..df361b6 --- /dev/null +++ b/tests/version.test.ts @@ -0,0 +1,33 @@ +import { describe, it, expect } from "vitest"; +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { KILLDIFF_VERSION } from "../src/version.js"; +import { parseCliArgs } from "../src/cli.js"; + +const pkg = JSON.parse(readFileSync(resolve(process.cwd(), "package.json"), "utf8")); + +describe("version reporting", () => { + it("matches package.json", () => { + expect(KILLDIFF_VERSION).toBe(pkg.version); + }); + + it("parses --version and -v as version mode", () => { + expect(parseCliArgs(["--version"]).mode).toBe("version"); + expect(parseCliArgs(["-v"]).mode).toBe("version"); + expect(parseCliArgs(["main...HEAD", "--version"]).mode).toBe("version"); + }); + + it("prints only the version from the built CLI and exits 0", () => { + const cliPath = resolve(process.cwd(), "dist", "cli.js"); + const stdout = execFileSync(process.execPath, [cliPath, "--version"], { encoding: "utf8" }); + expect(stdout.trim()).toBe(pkg.version); + }); + + it("shows the same version in --help", () => { + const cliPath = resolve(process.cwd(), "dist", "cli.js"); + const stdout = execFileSync(process.execPath, [cliPath, "--help"], { encoding: "utf8" }); + expect(stdout.startsWith(`killdiff v${pkg.version} `)).toBe(true); + expect(stdout).toContain("-v, --version"); + }); +});